Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/agent_comms/agent_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ def acknowledge_direct_turn_inputs(
bridge: type[HarnessSession],
) -> None: ...

@abstractmethod
def ignore_direct_turn_inputs(
self,
thread: Thread,
origins: tuple[Message, ...],
*,
bridge: type[HarnessSession],
) -> None: ...


class TurnTranscriptSink:
"""Per-turn transcript publisher for backends whose history lives in ``ExternalTranscript``."""
Expand Down Expand Up @@ -448,6 +457,16 @@ def acknowledge_turn_inputs(
"""Record model-context delivery acknowledgements when a backend starts origins."""
del acknowledger, thread, origins

@classmethod
def ignore_turn_inputs(
cls,
acknowledger: TurnInputAcknowledger,
thread: Thread,
origins: tuple[Message, ...],
) -> None:
"""Settle non-waking direct-inbox origins without starting a model turn."""
del acknowledger, thread, origins

async def context_for_input(self, thread, context):
return context

Expand Down
17 changes: 17 additions & 0 deletions src/agent_comms/cli_bridges/harness_delivery_states.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ def evidence(self, recorded: type[Outcome]) -> tuple[type[Outcome], MonitorEvide
def consumed_progress(self, progress: DeliveryProgress) -> DeliveryProgress:
return progress

def claim_handoff(self, state: AssignmentState) -> tuple[type[AssignmentState], ...]:
return state.harness_handoff()

def claim_steps(self, state: AssignmentState) -> tuple[type[AssignmentState], ...]:
return ()

Expand All @@ -106,6 +109,20 @@ class UnrecordedMonitor(MonitorEvidence):
pass


@dataclass(frozen=True)
class IgnoredMonitor(MonitorEvidence):
"""This recipient's direct-inbox backend dismissed a non-waking message without running a turn."""

def consumed_progress(self, progress: DeliveryProgress) -> DeliveryProgress:
return progress.ignored()

def claim_handoff(self, state: AssignmentState) -> tuple[type[AssignmentState], ...]:
return ()

def claim_steps(self, state: AssignmentState) -> tuple[type[AssignmentState], ...]:
return state.harness_ignore()


@dataclass(frozen=True)
class ReceivingMonitor(MonitorEvidence):
total: int
Expand Down
13 changes: 13 additions & 0 deletions src/agent_comms/comms.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,19 @@ def acknowledge_direct_turn_inputs(
bridge=bridge,
)

def ignore_direct_turn_inputs(
self,
thread: Thread,
origins: tuple[Message, ...],
*,
bridge: type[HarnessSession],
) -> None:
self.messaging.ignore_direct_turn_inputs(
thread,
origins,
bridge=bridge,
)

def __init__(self, root: CommsRoute) -> None:
super().__init__(root)
self.goals = Goals(self.root, self.registry, self.bus, self.agents)
Expand Down
7 changes: 7 additions & 0 deletions src/agent_comms/coordination/assignment_states.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,10 @@ def harness_delivery(self) -> tuple[type[AssignmentState], ...]:
"""Steps when that harness confirms the message started; a settled claim keeps its state."""
return ()

def harness_ignore(self) -> tuple[type[AssignmentState], ...]:
"""Steps when a direct-inbox backend dismisses a non-waking message without running a turn."""
return ()

def preengagement(self, disposition: type[AssignmentState]) -> AssignmentState:
if self.execution_id is not None or disposition not in self.successors():
raise IdentityConflict("preengagement transition is not declared")
Expand Down Expand Up @@ -342,6 +346,9 @@ def wake_frame(self, source: Delivered, obligation: ResponseObligation | None) -
def requires_selected_triage(self) -> bool:
return True

def harness_ignore(self) -> tuple[type[AssignmentState], ...]:
return (IgnoredAssignment,)

@property
def mode(self):
return BoundedTriageWake()
Expand Down
2 changes: 1 addition & 1 deletion src/agent_comms/coordination/tables/harness_deliveries.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def settle_claims(self, assignments: AssignmentStore, db: sqlite3.Connection) ->
native queue, then took the steps this outcome proves. Each phase reads the claim as it
stands, so a claim accepted after the attempt ends where one that existed before it
would; a claim already settled keeps its state."""
for steps in (lambda state: state.harness_handoff(), self.monitor.claim_steps):
for steps in (self.monitor.claim_handoff, self.monitor.claim_steps):
assignments.settle_harness_inputs(db, self.recipient_lookup, (self.reference,), steps)

def begin(self, assignments: AssignmentStore, db: sqlite3.Connection) -> bool:
Expand Down
13 changes: 13 additions & 0 deletions src/agent_comms/execution/antigravity_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,19 @@ def acknowledge_turn_inputs(
bridge=AntigravityAcpSession,
)

@classmethod
def ignore_turn_inputs(
cls,
acknowledger: TurnInputAcknowledger,
thread: Thread,
origins: tuple[Message, ...],
) -> None:
acknowledger.ignore_direct_turn_inputs(
thread,
origins,
bridge=AntigravityAcpSession,
)

@classmethod
def turn_transcript_sink(
cls,
Expand Down
65 changes: 39 additions & 26 deletions src/agent_comms/execution/input_drain.py
Original file line number Diff line number Diff line change
Expand Up @@ -1512,12 +1512,45 @@ async def drain_private_inbox(self, session_id: AcpSessionId) -> None:
await self._drain_private_if_changed(session_id, private_root)
WakeScheduleCheck(session_id=session_id, inputs=self).schedule()

def _partition_direct_inbox(
self,
owner: Thread,
messages: tuple[Message, ...],
displayed: DisplayBasis,
aliases: Mapping[str, str],
) -> tuple[Message, ...]:
"""Split direct-inbox messages into waking turns vs non-waking posts.

Non-waking messages are settled as ignored and marked displayed immediately.
Waking messages stay unmarked until ``TurnProgress.input_started`` records durable
``HarnessDelivery``, so a restart before the turn starts never drops them.
"""
waking = tuple(
message
for message in messages
if message.sender != owner.name
and message.role.response_policy(message).direct_wake_for(
message, owner.name, aliases
)
)
waking_seqs = frozenset(message.seq for message in waking)
non_waking = tuple(message for message in messages if message.seq not in waking_seqs)
if non_waking:
dismissed = tuple(message for message in non_waking if message.sender != owner.name)
if dismissed:
owner.backend.ignore_turn_inputs(self.comms, owner, dismissed)
self.comms.bus.reads.mark_displayed(
owner.name,
displayed.select(tuple(message.seq for message in non_waking)),
)
return waking

async def _steer_direct_inbox(self, session_id: AcpSessionId, thread: Thread) -> None:
turn = (await self.effects.turns.active_backend_turn(session_id)).turn
if not turn.has_source():
return

def capture_pending() -> tuple[tuple[Thread, tuple[Message, ...], DisplayBasis], ...]:
def capture_pending() -> tuple[tuple[Thread, tuple[Message, ...]], ...]:
if self.comms.owners.maintenance.read().turn_pending:
return ()
snapshot = self.comms.registry.snapshot()
Expand All @@ -1528,25 +1561,13 @@ def capture_pending() -> tuple[tuple[Thread, tuple[Message, ...], DisplayBasis],
messages = tuple(sorted(inbox.page.messages, key=lambda item: item.seq))
if not messages:
return ()
waking = tuple(
message
for message in messages
if message.sender != owner.name
and message.role.response_policy(message).starts_turn_for(
message, owner.name, snapshot.aliases
)
)
waking = self._partition_direct_inbox(owner, messages, inbox.displayed, snapshot.aliases)
if not waking:
self.comms.bus.reads.mark_displayed(owner.name, inbox.displayed)
return ()
return ((owner, waking, inbox.displayed),)
return ((owner, waking),)

for owner, waking, displayed in await Coordination.run_worker(capture_pending):
placed = await DirectDeliveredInput.deliver_direct(self, session_id, owner, waking)
if placed:
await Coordination.run_worker(
partial(self.comms.bus.reads.mark_displayed, owner.name, displayed)
)
for owner, waking in await Coordination.run_worker(capture_pending):
await DirectDeliveredInput.deliver_direct(self, session_id, owner, waking)

async def drain_direct_inbox(self, session_id: AcpSessionId, thread: Thread) -> None:
if self.background_wakes_disabled:
Expand All @@ -1572,15 +1593,7 @@ def capture() -> tuple[ScheduledTurn, ...]:
messages = tuple(sorted(inbox.page.messages, key=lambda item: item.seq))
if not messages:
return ()
self.comms.bus.reads.mark_displayed(owner.name, inbox.displayed)
waking = tuple(
message
for message in messages
if message.sender != owner.name
and message.role.response_policy(message).starts_turn_for(
message, owner.name, snapshot.aliases
)
)
waking = self._partition_direct_inbox(owner, messages, inbox.displayed, snapshot.aliases)
return tuple(
ScheduledTurn.incoming(message, aliases=snapshot.aliases)
for message in waking
Expand Down
11 changes: 11 additions & 0 deletions src/agent_comms/execution/selected/triage.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class InvalidTriageDecision(ValueError):

class SelectedTriage(DeclaredFamily, affix="SelectedTriage"):
family_discriminator = "decision"
suppresses_reply: ClassVar[bool] = False

@classmethod
def output_values(cls) -> dict[str, str]:
Expand Down Expand Up @@ -85,6 +86,14 @@ def recognizes(cls, text: str) -> bool:
return False
return True

@classmethod
def suppresses_channel_reply(cls, text: str) -> bool:
"""Whether this text is a bounded IGNORE verdict rather than a channel reply."""
try:
return cls.parse(text).suppresses_reply
except InvalidTriageDecision:
return False

@classmethod
@abstractmethod
def proves_source(cls, evidence: tuple[HistoricalNativeInput, ...]) -> bool: ...
Expand All @@ -101,6 +110,8 @@ async def continue_turn(

@dataclass(frozen=True)
class IgnoreSelectedTriage(SelectedTriage, declared_name="IGNORE"):
suppresses_reply = True

@classmethod
def proves_source(cls, evidence: tuple[HistoricalNativeInput, ...]) -> bool:
return True
Expand Down
18 changes: 15 additions & 3 deletions src/agent_comms/execution/turn_progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
from agent_comms.execution.native_turn_context import ContextObserved
from agent_comms.execution.publication_measurements import PublicationMeasurements
from agent_comms.execution.runtime_observations import AgentEventConsumer, NativeMetadataObservation
from agent_comms.execution.selected.triage import SelectedTriage
from agent_comms.execution.turn_failure import ModelRequestFailed, NoTurnFailure, TurnFailure
from agent_comms.execution.turn_lease import TurnState
from agent_comms.execution.turn_phase import NativePhaseChanged, PublishingPhase
from agent_comms.execution.turn_progress_reads import ProgressGoalAccount, ProgressTurn
from agent_comms.messaging.channel_targets import CommandTarget
from agent_comms.messaging.messages import AlertKind, NoticeRole
from agent_comms.messaging.send_result import SendResult
from agent_comms.nominal.field_codec import AcpSessionId
Expand Down Expand Up @@ -156,6 +158,15 @@ async def report_sends(self, results: Iterable[SendResult]) -> None:
for text in result.notices:
await self.consume(events.Notice(text=text))

def _publishable_reply_targets(self, text: str) -> tuple[str, ...]:
if SelectedTriage.suppresses_channel_reply(text):
return tuple(
target
for target in self.turn.reply_targets
if not CommandTarget.named(target).suppresses_ignore_reply
)
return self.turn.reply_targets

def publish_progress(self, progress: str) -> tuple[SendResult, ...]:
"""Join the committed notice and consume its streamed text together."""
results: tuple[SendResult, ...] = ()
Expand All @@ -166,7 +177,7 @@ def publish_progress(self, progress: str) -> tuple[SendResult, ...]:
# final reply contains only subsequent assistant text.
results = tuple(self.comms.messaging.send(
self.thread_name, target, progress, role=NoticeRole()
) for target in self.turn.reply_targets)
) for target in self._publishable_reply_targets(progress))
self.reply_parts.clear()
if progress:
self.transcript_sink.on_committed_progress(
Expand Down Expand Up @@ -308,9 +319,10 @@ def record_publication() -> None:
with ExitStack() as publications:
publications.callback(record_publication)
if self.reply_parts:
for target in self.turn.reply_targets:
reply = "".join(self.reply_parts)
for target in self._publishable_reply_targets(reply):
published.append(self.comms.messaging.send(
self.thread_name, target, "".join(self.reply_parts)
self.thread_name, target, reply
))
self.comms.agents.recover_completed_turn(self.turn_lease, self.thread.backend)
return tuple(published)
Expand Down
2 changes: 2 additions & 0 deletions src/agent_comms/messaging/channel_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ def direct_names(self) -> tuple[str, ...]:

guidance_scope = ""
default_audience = MessageAudience.DIRECT
suppresses_ignore_reply: ClassVar[bool] = False

@abstractmethod
def display_history(self, views: HistoryViews, project: Checkout) -> ConversationHistoryView:
Expand Down Expand Up @@ -568,6 +569,7 @@ def accepts_batch(self, seq: int) -> bool:
return seq > 0
kind = "channel"
default_audience = MessageAudience.COLLECTIVE
suppresses_ignore_reply: ClassVar[bool] = True

sigil = "#"
route: ClassVar[ReplyRoute] = ChannelReply()
Expand Down
27 changes: 27 additions & 0 deletions src/agent_comms/messaging/message_bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@
from agent_comms.messaging.read_basis import (
AnonymousViewer,
ChannelDisplayScope,
Conversation,
DisplayBasis,
DisplayedConversation,
DisplayViewer,
ListedDeliveries,
NamedViewer,
ReadCursor,
SenderDisplayScope,
)
from agent_comms.messaging.recorded_bus import RecordedBus
from agent_comms.messaging.read_ledger import ReadDocument, ReadLedger
from agent_comms.messaging.read_selection import CapturedSelection
from agent_comms.messaging.routing import DeliveryScope
Expand Down Expand Up @@ -253,6 +257,29 @@ def mark_read_through(
)
self.reads.mark_displayed(canonical, displayed)

def mark_messages_displayed(self, name: str, messages: Sequence[Message]) -> None:
"""Advance the read ledger for exactly these delivered messages without skipping others."""
deliveries = tuple(message for message in messages if message.seq > 0)
if not deliveries:
return
with self.snapshot(NamedViewer(name)) as (basis, source):
canonical = basis.require_viewer()
delivery = DeliveryScope.capture(canonical, basis.registry, basis.catalog)
grouped: dict[Conversation, list[int]] = {}
for message in deliveries:
conversation = delivery.read_key(message.sender, message.target, basis.registry)
grouped.setdefault(conversation, []).append(message.seq)
displayed = DisplayBasis(
canonical,
basis.registry.require(canonical).incarnation.wire_birth,
tuple(
DisplayedConversation(conversation, tuple(sorted(set(sequences))))
for conversation, sequences in grouped.items()
),
RecordedBus(source.identity),
)
self.reads.mark_displayed(canonical, displayed)

def channels(self) -> Sequence[str]:
return list(self.channel_declarations())

Expand Down
7 changes: 7 additions & 0 deletions src/agent_comms/messaging/notification_progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ def model_consumed(self, proof: ShownToModelProgress) -> DeliveryProgress:
"""The first proof that the message entered the model's context, at its own time."""
return proof

def ignored(self) -> DeliveryProgress:
"""A non-waking dismissal only settles a still-pending claim; other states keep their proof."""
return self


class ConsumedDelivery(SettledDelivery):
"""The harness or native runtime proved the message entered the model's context."""
Expand Down Expand Up @@ -240,6 +244,9 @@ def is_queued(self) -> bool:
def model_consumed(self, proof: ShownToModelProgress) -> DeliveryProgress:
return self.proof.model_consumed(proof)

def ignored(self) -> DeliveryProgress:
return IgnoredProgress(self.proof)


class PassiveProgress(ContextualProgress):
label = "Passive"
Expand Down
Loading
Loading