diff --git a/src/agent_comms/cli_bridges/codex_rollout.py b/src/agent_comms/cli_bridges/codex_rollout.py index f9e86fe4d0..7908bae5ed 100644 --- a/src/agent_comms/cli_bridges/codex_rollout.py +++ b/src/agent_comms/cli_bridges/codex_rollout.py @@ -17,18 +17,15 @@ RolloutState, ) from agent_comms.cli_bridges.history import CodexHistory, JsonLinesFile, OfflineHistory -from agent_comms.cli_bridges.runtime_updates import RuntimeUpdate +from agent_comms.cli_bridges.runtime_updates import RuntimeUpdate, UnpublishedRuntimeUpdate from agent_comms.nominal.field_codec import StoredSessionId @dataclass(frozen=True) -class HistoricalInstruction(RuntimeUpdate): +class HistoricalInstruction(UnpublishedRuntimeUpdate): """Where one instruction of the source session is, so its exact text can be read later.""" source: CodexRolloutProvenance - def publish(self, output) -> None: - pass - def add_to(self, history) -> None: history.instructions.add(self.source) diff --git a/src/agent_comms/cli_bridges/runtime_updates.py b/src/agent_comms/cli_bridges/runtime_updates.py index 11dc129be3..3c853c6995 100644 --- a/src/agent_comms/cli_bridges/runtime_updates.py +++ b/src/agent_comms/cli_bridges/runtime_updates.py @@ -403,6 +403,13 @@ def coalesced(updates: list[RuntimeUpdate]) -> list[RuntimeUpdate]: return list(reversed(kept)) +class UnpublishedRuntimeUpdate(RuntimeUpdate): + """A runtime update whose publish step is a no-op.""" + + def publish(self, output: ThreadOutput) -> None: + pass + + class StatusUpdate(RuntimeUpdate): """Reader phases decide when current activity is published.""" @@ -546,70 +553,55 @@ def write(self, transcript: ExternalTranscript, records: tuple[FinishedItem, ... @dataclass(frozen=True) -class HiddenItem(RuntimeUpdate): +class HiddenItem(UnpublishedRuntimeUpdate): """Conversation the live view does not show, because the thread shows it another way (a bus delivery) or because only the person's own prompts are shown; history keeps it.""" events: tuple[TranscriptEvent, ...] - def publish(self, output: ThreadOutput) -> None: - pass - def add_to(self, history: ImportBuffer) -> None: history.add(self.events) @dataclass(frozen=True) -class Summarized(RuntimeUpdate): +class Summarized(UnpublishedRuntimeUpdate): """The harness replaced everything before this point with a summary (compaction).""" text: str - def publish(self, output: ThreadOutput) -> None: - pass - def add_to(self, history: ImportBuffer) -> None: history.summarize(self.text) @dataclass(frozen=True) -class SessionFacts(RuntimeUpdate): +class SessionFacts(UnpublishedRuntimeUpdate): """Which session this is, where it ran and its title; a later fact replaces an earlier one.""" source_id: str = "" project: str = "" title: ThreadText = NoThreadText() - def publish(self, output: ThreadOutput) -> None: - pass - def add_to(self, history: ImportBuffer) -> None: history.describe(self) @dataclass(frozen=True) -class EarlierRequest(RuntimeUpdate): +class EarlierRequest(UnpublishedRuntimeUpdate): """The newest request before the selected history, looked up only if that history has none.""" find: Callable[[], str] = field(compare=False) - def publish(self, output: ThreadOutput) -> None: - pass - def add_to(self, history: ImportBuffer) -> None: if not history.latest_request: history.latest_request = self.find()[: history.limits.per_message] @dataclass(frozen=True) -class HistoryNotice(RuntimeUpdate): +class HistoryNotice(UnpublishedRuntimeUpdate): """Something about the source that an imported conversation should say it left out.""" text: str - def publish(self, output: ThreadOutput) -> None: - pass - def add_to(self, history: ImportBuffer) -> None: history.notices.add(self.text) diff --git a/src/agent_comms/execution/tracked_turn.py b/src/agent_comms/execution/tracked_turn.py index 25bc198c86..b1769e08c9 100644 --- a/src/agent_comms/execution/tracked_turn.py +++ b/src/agent_comms/execution/tracked_turn.py @@ -98,22 +98,21 @@ def keep_response(self) -> TrackedTerminal: def require_response(self, parts: list[str]) -> str: ... -class EmptyAnswerTrackedTerminal(TrackedTerminal): - """An observed empty final is a model outcome, not a missing native response.""" +class NotificationIgnoringTerminal(TrackedTerminal): + """A tracked terminal that leaves its state unchanged on notification events.""" def notification(self, parts: list[str]) -> TrackedTerminal: return self + +class EmptyAnswerTrackedTerminal(NotificationIgnoringTerminal): + """An observed empty final is a model outcome, not a missing native response.""" + def require_response(self, parts: list[str]) -> str: raise NativeEmptyAnswer() -class PendingTrackedTerminal(TrackedTerminal): - def notification(self, parts): - # A following bus message cannot answer an already completed request, - # but neither can it erase a final answer still owed after a tool round. - return self - +class PendingTrackedTerminal(NotificationIgnoringTerminal): def require_response(self, parts): raise NativePiUnavailable("Native Pi has no unique authoritative completed response") @@ -162,7 +161,7 @@ def keep_response(self): return NotifiedTrackedTerminal(self.text) -class NotificationTrackedTerminal(TrackedTerminal): +class NotificationTrackedTerminal(NotificationIgnoringTerminal): """Notice handling cannot answer or revise the original requested task.""" def answered(self, text: str) -> TrackedTerminal: @@ -174,9 +173,6 @@ def empty_answer(self) -> TrackedTerminal: def tool_round(self): return self - def notification(self, parts): - return self - class NotifiedTrackedTerminal(NotificationTrackedTerminal, AnsweredTrackedTerminal): def later_input(self, parts): diff --git a/src/agent_comms/planning/goal_actions.py b/src/agent_comms/planning/goal_actions.py index 973242077e..5c61704dad 100644 --- a/src/agent_comms/planning/goal_actions.py +++ b/src/agent_comms/planning/goal_actions.py @@ -293,24 +293,33 @@ def change(self, goal: Goal, ctx: GoalActionContext) -> Goal: return super().change(goal, ctx) +class ActivatingGoalAction(TransitionGoalAction, declared_name=None): + """A goal transition action whose next state is active.""" + + def next_state(self, goal: Goal, ctx: GoalActionContext) -> GoalState: + return ActiveGoal() + + @dataclass(frozen=True, kw_only=True) class ActiveGoalAction( - GoalReportAction, ModelInvocable, OwnerInvocable, RuntimeInvocable, OwnerControlInvocable, + ActivatingGoalAction, + GoalReportAction, + ModelInvocable, + OwnerInvocable, + RuntimeInvocable, + OwnerControlInvocable, PeerInvocable, ): @classmethod async def after_update(cls, scheduler: object, session_id: object) -> None: await scheduler.schedule_goal(session_id) - def next_state(self, goal: Goal, ctx: GoalActionContext) -> GoalState: - return ActiveGoal() - def before_transition(self, goal: Goal, ctx: GoalActionContext) -> None: ctx.goals.resume_goal_generation(goal.id, ctx.thread.executing) @dataclass(frozen=True, kw_only=True) -class CompliedGoalAction(TransitionGoalAction, OwnerInvocable): +class CompliedGoalAction(ActivatingGoalAction, TransitionGoalAction, OwnerInvocable): """The teammate complied, so a unit its chokehold paused works again. The compliant answer is a witness the way an order is: a generation an interruption left unresolved continues as a fresh order continues it (continue_work), where a status-only resume is refused. @@ -322,9 +331,6 @@ def require_order(self, goal: Goal, ctx: GoalActionContext) -> None: """Lifting the heartbeat's hold restores the goal it paused. Its problems may close during the hold, and that must not keep this unit, or the units after it, held.""" - def next_state(self, goal: Goal, ctx: GoalActionContext) -> GoalState: - return ActiveGoal() - def before_transition(self, goal: Goal, ctx: GoalActionContext) -> None: ctx.goals.comply_goal_generation( goal.id, ComplianceDecision(self.witness), ctx.thread.executing, @@ -332,16 +338,18 @@ def before_transition(self, goal: Goal, ctx: GoalActionContext) -> None: @dataclass(frozen=True, kw_only=True) -class StandbyGoalAction(GoalReportAction, ModelInvocable, RuntimeInvocable): +class StandbyGoalAction( + ActivatingGoalAction, + GoalReportAction, + ModelInvocable, + RuntimeInvocable, +): wait_for: tuple[str, ...] = () reviewed_inputs: tuple[Annotated[InputKey, InputKeyText], ...] = () def complete_wait(self, ctx: GoalActionContext) -> None: pass - def next_state(self, goal: Goal, ctx: GoalActionContext) -> GoalState: - return ActiveGoal() - def prepare(self, goals: GoalActionStore, name: str, actor: type) -> GoalAction[Goal]: ctx = GoalActionContext(goals, goals.require_thread(name), actor) self.expect.check(ctx) @@ -513,7 +521,13 @@ def required_block_reason(reason: str | None) -> str: @dataclass(frozen=True, kw_only=True) -class RetryGoalAction(TransitionGoalAction, ModelInvocable, OwnerInvocable, RuntimeInvocable): +class RetryGoalAction( + ActivatingGoalAction, + TransitionGoalAction, + ModelInvocable, + OwnerInvocable, + RuntimeInvocable, +): """Retry a blocked goal: the unit itself, its teammate or the owner; authorize_retry fences every attempt against the unresolved one.""" @@ -528,9 +542,6 @@ async def submit_checkpoint[Authority]( ) -> GoalDeclaration: return await source.retry_goal_control(authority, goal) - def next_state(self, goal: Goal, ctx: GoalActionContext) -> GoalState: - return ActiveGoal() - def require_transition(self, goal: Goal, state: GoalState, ctx: GoalActionContext) -> None: """A blocked goal leaves its state machine only through the attempt ledger's retry.""" ctx.goals.authorize_goal_retry(goal.id, RetryDecision(RetryDecisionId.mint())) diff --git a/src/agent_comms/registry/thread_status.py b/src/agent_comms/registry/thread_status.py index 3e3de261be..09ebed6f46 100644 --- a/src/agent_comms/registry/thread_status.py +++ b/src/agent_comms/registry/thread_status.py @@ -398,13 +398,17 @@ class IdleThreadStatus(ActiveThreadPresence): pass -class StoppedPresence(Visible, ThreadStatus, declared_name=None): - def is_stopped(self) -> bool: - return True +class VacantThreadStatus(ThreadStatus, declared_name=None): + """A thread status representing a vacant thread slot.""" def is_vacant(self) -> bool: return True + +class StoppedPresence(Visible, VacantThreadStatus, declared_name=None): + def is_stopped(self) -> bool: + return True + def registered(self, thread: PresenceThread, last_seen: float) -> ThreadStatus: """Stopped never keeps a process binding, so a stored stop still bound is a fence whose host has not completed the session.""" @@ -523,7 +527,7 @@ def restored(self) -> ThreadStatus: return self -class ArchivedThreadStatus(OrphansHolds, ThreadStatus): +class ArchivedThreadStatus(OrphansHolds, VacantThreadStatus): def require_checkout_adoption(self) -> None: """Only retired declarations can surrender their checkout grants.""" @@ -531,9 +535,6 @@ def require_checkout_adoption(self) -> None: def is_archived(self) -> bool: return True - def is_vacant(self) -> bool: - return True - def in_view(self, visibility: RosterVisibility) -> bool: return visibility.archived diff --git a/src/agent_comms/storage/private_path.py b/src/agent_comms/storage/private_path.py index 773cda80ed..fc015c814e 100644 --- a/src/agent_comms/storage/private_path.py +++ b/src/agent_comms/storage/private_path.py @@ -196,14 +196,14 @@ def created_stream( class NonBlockingFilesystemRole(PrivateRole, declared_name=None): """A filesystem role opened with O_NONBLOCK.""" + permissions = 0o600 + @classmethod def kind_flags(cls) -> int: return os.O_NONBLOCK class PrivateFileRole(NonBlockingFilesystemRole): - permissions = 0o600 - @classmethod def accepts_kind(cls, mode: int) -> bool: return stat.S_ISREG(mode) @@ -246,8 +246,6 @@ def accepts_kind(cls, mode: int) -> bool: class PrivateSocketRole(NonBlockingFilesystemRole): - permissions = 0o600 - @classmethod def accepts_kind(cls, mode: int) -> bool: return stat.S_ISSOCK(mode)