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
7 changes: 2 additions & 5 deletions src/agent_comms/cli_bridges/codex_rollout.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
32 changes: 12 additions & 20 deletions src/agent_comms/cli_bridges/runtime_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand Down Expand Up @@ -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)

Expand Down
20 changes: 8 additions & 12 deletions src/agent_comms/execution/tracked_turn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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:
Expand All @@ -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):
Expand Down
43 changes: 27 additions & 16 deletions src/agent_comms/planning/goal_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -322,26 +331,25 @@ 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,
)


@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)
Expand Down Expand Up @@ -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."""

Expand All @@ -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()))
15 changes: 8 additions & 7 deletions src/agent_comms/registry/thread_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -523,17 +527,14 @@ 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."""

def is_archived(self) -> bool:
return True

def is_vacant(self) -> bool:
return True

def in_view(self, visibility: RosterVisibility) -> bool:
return visibility.archived

Expand Down
6 changes: 2 additions & 4 deletions src/agent_comms/storage/private_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Loading