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
15 changes: 7 additions & 8 deletions src/agent_comms/acp_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,24 +137,23 @@ def needs_refresh(self) -> bool:
return False


@dataclass(frozen=True)
class UnavailableCursorObservation(CursorObservation):
class StaleCursorObservation(CursorObservation, declared_name=None):
"""A cursor observation that requires a refresh."""

@property
def needs_refresh(self) -> bool:
return True


@dataclass(frozen=True)
class UnavailableCursorObservation(StaleCursorObservation):
@property
def status(self) -> str:
return "unavailable"


@dataclass(frozen=True)
class EmptyCursorObservation(CursorObservation):
@property
def needs_refresh(self) -> bool:
# Absence of a durable projection does not settle an original proof.
return True

class EmptyCursorObservation(StaleCursorObservation):
@property
def status(self) -> str:
return "none"
Expand Down
18 changes: 9 additions & 9 deletions src/agent_comms/cli_bridges/runtime_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,19 @@ def finish(self, update: CompletedItem) -> tuple[ClosedDraft, FinishedItem]:
return ClosedDraft(self.started_at), FinishedItem(turn_id=update.turn_id, item_id=update.item_id, events=update.events)


class NoPrefixDraft(DraftAccumulator):
class ImmutableDraftAccumulator(DraftAccumulator):
"""A draft accumulator that accepts no appended text."""

def append(self, update: AppendDraftItem) -> tuple[RuntimeUpdate, ...]:
return ()


class NoPrefixDraft(ImmutableDraftAccumulator):
"""No observed prefix; retain no per-item state so the instance can be shared."""

def __init__(self) -> None:
super().__init__(UnrecordedEventTime())

def append(self, update: AppendDraftItem) -> tuple[RuntimeUpdate, ...]:
"""Drop the suffix: without an observed prefix it cannot form a whole item."""
return ()


NO_PREFIX = NoPrefixDraft()

Expand Down Expand Up @@ -151,7 +154,7 @@ class ParagraphDraft(TextDraft):
separator = "\n\n"


class ClosedDraft(DraftAccumulator):
class ClosedDraft(ImmutableDraftAccumulator):
"""Completed snapshots reject overlapping older starts and late suffixes."""

def restarted(self, replacement: DraftAccumulator) -> DraftAccumulator:
Expand All @@ -163,9 +166,6 @@ def started(self, update: StartedItem) -> tuple[RuntimeUpdate, ...]:
def activity(self, update: ActiveItem) -> tuple[RuntimeUpdate, ...]:
return ()

def append(self, update: AppendDraftItem) -> tuple[RuntimeUpdate, ...]:
return ()


@dataclass
class ThreadOutput(activity.ThreadOutput):
Expand Down
28 changes: 17 additions & 11 deletions src/agent_comms/coordination/obligation_states.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,15 @@ def validate_acknowledgement(self, acknowledgement) -> None:
raise CoordinationError("publication acknowledgement exists iff published")


class PendingResponse(Retryable, Pending, ResponseState):
class UnpublishedResponseState(ResponseState, declared_name=None):
"""A response state that has not yet been published."""

def require_nonpublication(self) -> None:
pass


class PendingResponse(Retryable, Pending, UnpublishedResponseState):

def require_preparation(self) -> None:
pass

Expand All @@ -122,12 +126,16 @@ def successors(cls):
return PublishingResponse, DeferredResponse, SilentResponse, FailedResponse


class PublishingResponse(Publishing, ResponseState):
class PublicationResponseState(ResponseState, declared_name=None):
"""A response state that participates in publication intent validation."""

def validate_intent(self, intent) -> None:
if intent is None:
raise CoordinationError("publishing and published obligations require intent")


class PublishingResponse(Publishing, PublicationResponseState):

def require_publishing(self) -> None:
pass

Expand All @@ -139,10 +147,7 @@ def successors(cls):
return PublishedResponse, FailedResponse


class DeferredResponse(Retryable, Deferred, ResponseState):

def require_nonpublication(self) -> None:
pass
class DeferredResponse(Retryable, Deferred, UnpublishedResponseState):

@classmethod
def resume_response(
Expand All @@ -164,7 +169,12 @@ def successors(cls):


@dataclass(frozen=True)
class PublishedResponse(Published, RequiresIntent, Successful, ResponseState):
class PublishedResponse(
Published,
RequiresIntent,
Successful,
PublicationResponseState,
):
message_id: MessageId
seq: int

Expand All @@ -183,10 +193,6 @@ def published_message_id(self):
def publication_seq(self):
return self.seq

def validate_intent(self, intent) -> None:
if intent is None:
raise CoordinationError("publishing and published obligations require intent")

def published_reference(self) -> MessageReference:
return MessageReference(self.seq, self.message_id)

Expand Down
44 changes: 16 additions & 28 deletions src/agent_comms/execution/child_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,8 +725,16 @@ def fork_failure(self, interrupted_consequence: Callable[[], str]) -> str:
return interrupted_consequence()


class UnsuccessfulChildOutcome(ChildOutcome, declared_name=None):
"""A child process outcome that did not exit cleanly with code zero."""

@property
def successful(self) -> bool:
return False


@dataclass(frozen=True)
class SignaledOutcome(InterruptedForkOutcome):
class SignaledOutcome(UnsuccessfulChildOutcome, InterruptedForkOutcome):
signal_number: int

def report_stopped(self, report: Callable[[], None], stop_exits: frozenset[int]) -> None:
Expand All @@ -736,13 +744,9 @@ def report_stopped(self, report: Callable[[], None], stop_exits: frozenset[int])
def summary(self) -> str:
return f"stopped by {signal.Signals(self.signal_number).name}"

@property
def successful(self) -> bool:
return False


@dataclass(frozen=True)
class TimedOutOutcome(InterruptedForkOutcome):
class TimedOutOutcome(UnsuccessfulChildOutcome, InterruptedForkOutcome):
termination: ChildOutcome

def report_shutdown(self, report_timeout: Callable[[], None]) -> None:
Expand All @@ -752,10 +756,6 @@ def report_shutdown(self, report_timeout: Callable[[], None]) -> None:
def summary(self) -> str:
return f"timed out; {self.termination.summary}"

@property
def successful(self) -> bool:
return False


class _StopStage(ABC):
"""One phase of retiring a process group: graceful termination, then forced kill."""
Expand Down Expand Up @@ -846,17 +846,13 @@ def report_forced(self, report: Callable[[str], None]) -> None:


@dataclass(frozen=True)
class FailedToStartOutcome(ChildOutcome):
class FailedToStartOutcome(UnsuccessfulChildOutcome, ChildOutcome):
error: str

@property
def summary(self) -> str:
return f"failed to start: {self.error}"

@property
def successful(self) -> bool:
return False


@dataclass(frozen=True)
class ChildResult:
Expand Down Expand Up @@ -1402,6 +1398,10 @@ async def exchange(
class SynchronousProcess(ChildProcess):
"""Identity-checked process control; each subclass supplies synchronous reaping."""

async def wait(self) -> ChildOutcome:
await self.platform.wait_exited(self.identity)
return self.reap()

def __init__(self, identity: ProcessIdentity):
super().__init__(identity)
self._retirement_lock = threading.Lock()
Expand Down Expand Up @@ -1517,10 +1517,6 @@ def require_stop_authority(self) -> None:
def reap(self) -> ChildOutcome:
return DetachedExitOutcome()

async def wait(self) -> ChildOutcome:
await self.platform.wait_exited(self.identity)
return self.reap()


class SpawnedProcess(SynchronousProcess):
"""A launched process handle; surviving the launcher does not preserve its parent."""
Expand Down Expand Up @@ -1607,10 +1603,6 @@ def reap(self) -> ChildOutcome:
"""Collect the owned child's actual exit; stop grace belongs to its stop plan."""
return ChildOutcome.from_returncode(self.process.wait())

async def wait(self) -> ChildOutcome:
await self.platform.wait_exited(self.identity)
return self.reap()

def close_streams(self) -> None:
for stream in (self.process.stdin, self.process.stdout, self.process.stderr):
if stream is not None:
Expand Down Expand Up @@ -1807,17 +1799,13 @@ def submit[T, **P](


@dataclass(frozen=True)
class DetachedExitOutcome(ChildOutcome):
class DetachedExitOutcome(UnsuccessfulChildOutcome, ChildOutcome):
"""Exit observed; a non-parent cannot claim an exit code."""

@property
def summary(self) -> str:
return "exited; status unavailable"

@property
def successful(self) -> bool:
return False


class ChildCommand(DeclaredFamily, affix="Command"):
"""Internal child entrypoints decode once through their declaration owner."""
Expand Down
11 changes: 6 additions & 5 deletions src/agent_comms/execution/input_drain.py
Original file line number Diff line number Diff line change
Expand Up @@ -1066,10 +1066,14 @@ async def resume(self, maintenance: MaintenanceIngress) -> None: ...
async def finish_original(self, inputs: InputDrain) -> None: ...


class NoDrainTurn(DrainTurn):
class UnstartedDrainTurn(DrainTurn):
"""A drain turn that has not started an original input to finish."""

async def finish_original(self, inputs: InputDrain) -> None:
pass


class NoDrainTurn(UnstartedDrainTurn):
def opened(self) -> DrainTurn:
return AwaitingDrainTurn(TurnInbox())

Expand All @@ -1081,15 +1085,12 @@ async def resume(self, maintenance: MaintenanceIngress) -> None:


@dataclass(frozen=True)
class AwaitingDrainTurn(DrainTurn):
class AwaitingDrainTurn(UnstartedDrainTurn):
inbox: TurnInbox

def is_open(self) -> bool:
return True

async def finish_original(self, inputs: InputDrain) -> None:
pass

def opened(self) -> DrainTurn:
return self

Expand Down
19 changes: 10 additions & 9 deletions src/agent_comms/execution/provider_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,15 @@ def parse(cls, text: str, reasoning: str = "") -> ParsedThinking:
return cls(thinking="\n\n".join(parts), visible=remaining.strip())


class ToolRoundAllowedContent(PiContent, declared_name=None):
"""A Pi content block permitted inside a tool round."""

def require_tool_round_allowed(self) -> None:
pass


@dataclass(frozen=True)
class TextContent(PiContent):
class TextContent(ToolRoundAllowedContent):
def text_parts(self) -> tuple[str, ...]:
return (self.text,)

Expand All @@ -170,8 +177,6 @@ def assistant_transcript(self, position: int, timestamp: float):
text_signature: Annotated[
PiField[str | PiOmitted], WireName("textSignature")
] = PiOmitted()
def require_tool_round_allowed(self) -> None:
pass


@property
Expand All @@ -180,16 +185,14 @@ def final_text(self) -> str:


@dataclass(frozen=True)
class ThinkingContent(PiContent):
class ThinkingContent(ToolRoundAllowedContent):
def assistant_transcript(self, position: int, timestamp: float):
return [ThinkingTranscript(self.thinking, position=position, timestamp=timestamp)]

thinking: str = ""
thinking_signature: Annotated[
PiField[str | PiOmitted], WireName("thinkingSignature")
] = PiOmitted()
def require_tool_round_allowed(self) -> None:
pass


@property
Expand All @@ -198,7 +201,7 @@ def final_text(self) -> str:


@dataclass(frozen=True)
class ToolCallContent(PiContent, declared_name="toolCall"):
class ToolCallContent(ToolRoundAllowedContent, declared_name="toolCall"):
def tool_calls(self) -> tuple[ToolCallContent, ...]:
return (self,)

Expand All @@ -211,8 +214,6 @@ def assistant_transcript(self, position: int, timestamp: float):
id: ToolCallId
name: str
arguments: object
def require_tool_round_allowed(self) -> None:
pass



Expand Down
12 changes: 7 additions & 5 deletions src/agent_comms/execution/turn_phase.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,16 @@ class PreparingPhase(TurnPhase):
label = "Preparing input"


class IdlePhase(ActivityWord, TurnPhase):
busy = False
class NonFollowupTurnPhase(TurnPhase, declared_name=None):
"""A turn phase that does not accept follow-up prompts."""

def accepts_followup(self) -> bool:
return False


class IdlePhase(ActivityWord, NonFollowupTurnPhase):
busy = False

def can_cancel(self) -> bool:
return False
activity_state = ActivityState.IDLE
Expand Down Expand Up @@ -275,9 +279,7 @@ def stall_message(self, budget: float) -> str:
)


class SettlingStatsPhase(TurnPhase):
def accepts_followup(self) -> bool:
return False
class SettlingStatsPhase(NonFollowupTurnPhase):
label = "Finishing native statistics"


Expand Down
Loading
Loading