Stage launches tasks through harness connections and records their execution.
server/internal/execution defines the shared contract. Harness adapters
translate their native protocols, options and session state.
- Keep Stage lean. Stage owns logical project groups, tasks, trees, schedules, journals, acceptance and durable handoff. Each harness connection owns its workspace catalog and sessions. The harness also owns worktrees, branches, archive, models, UI and processes. Stage uses read-only evidence to group workspaces for navigation. Harness boundary · Workspace ownership and routing
- Use generic code and declared policy. Stage reads descriptors and capabilities to make its decisions. Each adapter validates and translates its own options. Harness-specific operations and display data use declared actions and facts. The boundary tests enforce where harness names can appear. Harness foundation
- Scope every session. A session is
{connectionId, externalSessionId}. Parents, task events and journal provenance use the connection of the session they describe. A bare external ID carries no connection identity. - Pin exact destinations. Select a connection and one exact workspace under ADR 0010. Stage revalidates the pair before launch. Planning backlog can omit the workspace, or the connection too: a task with no connection is backlog any agent can claim, and Stage launches it only once a connection and workspace are chosen (ADR 0019). Group membership supplies project context and navigation.
- Attribute the caller independently of the destination. Agent tools
accept
callerSession. A harness can declare a native per-call metadata key (OpenCode supplies its session ID in MCP metadata) or a session environment variable. HTTP MCP can useStage-Caller-Sessionand the CLI can useSTAGE_CALLER_SESSION. The launch's journal instructions carry the descriptor's caller hint. Stage records the caller's session on created work and journal entries. Agent interface - Two ways to run a task. Stage launches it into a harness connection and observes the session, or an agent runs it outside Stage and reports (agent-run). In both, Stage owns the task, its tree, journal, acceptance and handoff, and the harness owns any session. For an agent-run task Stage launches and observes nothing; the agent's reports set its state. A task need not name a connection to be claimed. Agent-run tasks
The main server composes coordinator, observe and discovery in
internal/engine. The coordinator owns launch, link repair, handoff and
PollTask and its apply path. Observation selects the watch set, runs beside
the adapters and ingests samples on the main server. Discovery reads workspace
inventory and filesystem evidence and owns full sync.
Stage records the admitted actor when it claims a launch. Handoffs and adapter outcomes link to the recorded attempt, including across process restarts. Dependency release links to the latest current prerequisite acceptance. Scheduled launches derive their source from the spawned task's creation event. Harness observations record automation with the verified connection and session. Notifications receive that same attribution from the committed transition. Work attribution
The ordered module list in internal/harnesses/modules.go supplies the
registry and API list. Each harness.Module provides a descriptor,
Compose(context.Context, harness.Ports), a public settings validator and
any environment or legacy secret declarations. Serve and the worker compose
the same modules in registry order, subject to the machine's hosting policy.
The descriptor declares process requirements, session locality, launch identity, caller attribution, wrapper origins, state reasons, closure signals and attention policy. It also supplies connection fields and actions, disconnect availability, session and discovery hints, and link policy.
localProcesses requires a profile that permits those processes (Claude
Code and Codex). OpenCode and T3 connect to services. All four declare
machine-local sessions. Cloud session locality is independent of process
requirements. Machine profiles
linkSchemes lists the harness's native URL schemes, such as T3's
t3code. The registry checks them for valid lowercase syntax, uniqueness
and reserved names. Reply Markdown allows standard web, FTP, email, phone,
Stage and relative links. Harness links gain a destination after the host
loads and validates the descriptors. Script URLs stay blocked.
Descriptor API
A setup package implements harness.Connector for its machine and kind.
A connector supplies an in-memory summary, status, configure, run and
disconnect. Status includes a common phase, facts and an optional fix,
plus harness details. The API attaches full-sync time, error and progress as
sync. Hosts render declared settings and actions or use a registered setup
panel. The API exposes the same setup routes on each machine.
Connection API
Display probes add facts to a connected status from the harness's own API,
inside the setup package. Each call is bounded, and the result is cached
for harness.FactsTTL (one minute): status reads reuse it, refreshes
included, and the check action probes again. A failed or slow probe becomes a bad fact, never a status
error. The Stage MCP fact reports the server stage setup registers
(harness.StageMCPName): Claude Code claude mcp get stage from the
home folder, Codex mcpServerStatus/list for that server, and OpenCode
GET /api/mcp without a location, beside its version and login
checks. mcp list is not used because it health-checks every server.
Connected is ok. Not configured is warn, and when the status has no
other fix, the fix names the matching setup command for the machine's CLI
(harness.Ports.CLI). The phase does not change. T3 has no such fact,
because it configures MCP for each provider. Codex also reports usage from
account/rateLimits/read for a ChatGPT login: primary and secondary windows
in Codex's words (5h limit, Weekly limit), the percent used and the
reset time in the machine's local time. The fact is warn at 80% and bad
at 100%. A failed usage read omits the usage facts.
Compose takes machine-bound ports. Settings.Get reads a public JSON
object by kind and Settings.Save applies a partial update. Omitted fields
keep their values. Null resets a setting to its module default. Secrets
addresses opaque values by kind and key. The local placement can commit
a settings patch and secret edit together. Setup owns settings types and
credential formats. Identity reads, switches or stamps an instance and
supplies the evidence Stage stored for continuity checks. The module also
receives its data directory, profile, environment, binary lookup and logger.
It installs adapters through the install port and returns the connector and
optional cleanup for its client resources.
Stage seeds no default harness or connection. A connector is available before a connection exists. The first successful pair or connect creates the connection through the identity port. Automatic-completion preferences belong to that connection.
An identity is unique per machine and kind. A stable identity such as a T3 environment ID revives its retired connection on the same machine. When an address is insufficient, as with OpenCode, the module proves continuity from stored evidence and selects the connection to revive. A stable-identity module may also declare a moved-retire predicate. Stage evaluates it using both connector summaries when the old machine is reachable.
Replacing an instance retires its connection. Tasks, sessions and workspace records remain on it as history. Edit a backlog task or schedule and select an exact workspace on the new connection to run future work there. Serve follows connection changes and runs release and schedule runners per active connection, plus one ready pass that marks released members ready whatever their connection (a member with no connection reads ready, since Stage cannot launch it). Connection storage and lifecycle
execution.Adapter embeds four roles. machine.Connections resolves the
full adapter or a narrow role from the connection's machine. The local
adapter and remote proxy implement the same contract.
Health reports availability, a reason, instance identity and the check
time. It is independent of session outcomes. Features describes models,
options, permissions, modes and supported operations with reasons when
unavailable. ModeLabel names the mode selector in the harness's words.
A workspace-scoped catalog uses WorkspaceFeatures with the selected
catalog row's native workspace ID and directory. It may change an
action's availability but keeps every action Features declares, in
order (execution.ScopedActions, checked in each adapter's tests): task
sessions read their session actions from it.
Capabilities API
Workspaces reports harness project IDs, directories, timestamps,
availability and import evidence. The adapter marks paths on its machine's
filesystem. Discovery uses that machine's Ops.Inventory to enrich those
paths, refreshes stored workspaces and organizes new rows into project groups.
A row the harness will not start a session in carries BlockedReason in the
harness's words. A harness whose folder trust depends on Git layout declares
a TrustRule (its trust records and reason) instead, and Ops.Inventory sets
BlockedReason when no record covers the folder: a record on the checkout's
main root (the main working tree of a linked worktree), else on the folder or
an ancestor up to the checkout top, or up to the filesystem root outside a
checkout. A blocked row stays listed and grouped but is not an eligible
destination (see discovery). Failed inventory
reads leave the last stored inventory in place. Full sync guards against
concurrent runs per connection, reports progress and records successful sync
for the active connection. Workspace discovery
Observe returns the current snapshot for a scoped session. Attention
lists sessions the harness surfaces to Stage, such as sessions waiting on
the user. Stage never binds such a session to a task: a session tracks its
own work by creating and claiming a task
(ADR 0022).
Stage records one scoped session per confirmed or linked launch attempt. A session a former adoption recorded before it ever ran keeps attempt 0 (migration 0064 left those tasks as ordinary tasks). Restarting clears the current pointer while the launch is pending and preserves earlier rows. Session history reads the latest stored observation for each recorded ref. All task interaction targets the current session.
Launch starts execution from a frozen intent and reconciles a prior
dispatch when the launch policy permits it. Stop interrupts a session
when its operation is available. The harness performs the native command
against the scoped session.
Use execution.As[T](role) to reach a trait and check the corresponding
operation or descriptor policy before dispatch. execution/optional.go
registers LinkResolver, SessionNamer,
WorkspaceFeatures, Correlator, EventSource, Interactive, Actor,
WorkspaceAdder and DirectoryBrowser. A local adapter implements
the Go interface. A partial adapter, such as a worker proxy, must also
declare that trait in the connection's current ready snapshot. Unknown traits
are ignored. Channel negotiation also scopes each request and harness kind.
| Error | Meaning |
|---|---|
Rejected |
The launch certified that no execution started. Stage returns the task to Backlog for repair. Other launch failures leave the attempt unconfirmed. |
Refused |
Stage declines to track a session that a registered harness wraps. The API returns 409 session_refused naming the harness that follows it. |
Invalid |
The answer does not fit a pending interaction request. Nothing was sent. The API returns 400 and the worker channel uses invalid_answer. |
Busy |
The session cannot take a message now. Nothing was sent. The API returns 409 session_busy with the reason and the channel uses busy. |
ErrUnavailable, ErrNotFound and ErrNoReply preserve their meaning
over the channel (unavailable, not_found, no_reply). An absent
trait or operation returns operation_unavailable. Only an adapter that
can certify rejection may return Rejected after dispatch.
Manual starts, schedules and automatic starts in trees run by Stage share the coordinator. A launch claim pins the verified destination and accepted dependency inputs. Reconciliation verifies the pinned workspace on the same connection.
execution.Intent carries the request ID, connection, external project,
directory, title, prompt, execution configuration and images. Tasks and
schedules store executionConfig. Model, permission and mode are opaque
adapter keys. The selected model's options and the harness-wide options
share one namespace. Option kinds are choice, boolean and text.
A choice takes a declared value, a boolean takes true or false, and text takes
a nonempty trimmed string. Omit an option to use its default. A dependsOn
condition must hold for a dependent selection. Capabilities.Valid checks
the declarations and ValidateConfig checks selections.
An option the harness has no setting for (the adapter decides, such as a
worktree flag or Claude Code's continueIn) is Fixed: it needs a
Default, an omitted option means that default, and forms show it
selected instead of "Harness default". ValueNotes explain a choice's
values in the harness's words (forms show the note while the value
applies). UnavailableValues lists values the option can't take now with
the reason (never the default); ValidateConfig refuses them with it.
Every worktree option is Fixed with default off.
The adapter owns worktree creation. T3 declares worktree, baseRef and
branch, with the last two applying to a worktree launch. Claude Code and
OpenCode offer a worktree option and choose the base themselves. Codex
runs in the selected checkout. Handoff carries a predecessor's reported
branch as context.
Launch receives the immutable intent and an adapter-owned, versioned JSON
checkpoint. Save the checkpoint durably before each external effect and
stop if the save fails. Checkpoints contain references and non-secret identity
only. For multi-step creation, persist the identifiers needed to reconcile
each step before dispatch. Supply images through the intent. On a worker,
launch.image fetches each image by index and checkpoint.save calls the
coordinator's SaveCheckpoint. After the launch call stops waiting, the
channel refuses further saves with call_ended.
- Reserved (default) uses a deterministic or checkpointed identity to reconcile the same session and input on replay.
- Correlated covers a harness that assigns the session ID and whose
create operation cannot safely be repeated. Stage appends
execution.LaunchMarker(requestId)to the prompt, records the dispatch and callsLaunchonce. Recovery usesexecution.Correlatorto find the session by that marker. If none is found, the attempt stays unconfirmed and supports explicit linking. The correlator is required for launch.
The claim transaction creates a prepared attempt. Stage freezes the prompt, journal instructions, config, images and destination before calling the adapter. Interrupted preparation with no frozen intent returns the task to Backlog. Attempts without enough identity for safe recovery require linking.
A lost reply or timeout after dispatch leaves the attempt Launch unconfirmed. Recovery retries with backoff (5 seconds to 1 minute), including after restart, through the checkpoint or correlation policy. When the harness returned a session but Stage could not persist the observation or confirmation, the attempt retains the error, backoff and reported session. Task detail can open that session or display its resume command. Once storage recovers, a retry can record the session.
A per-task lock serializes reconciliation and manual attachment. Database revision checks reject stale checkpoints and attachments. The server data-dir lock prevents concurrent owners of the same database.
An optional LinkResolver translates a pasted ID, URL or command.
Preview verifies the pinned destination, current environment, top-level
session and ownership. Attachment rechecks those facts and the attempt
revision. The repair attaches the existing session without dispatching
launch or granting acceptance.
Task API
Only acceptance releases dependencies. Handoff is always on
(ADR 0017): the launch claim pins each
need's immutable accepted result, even if the source harness is
offline or the source task is later reopened. The coordinator builds the
blocks from Stage storage and records them per attempt. They include the
accepted evidence, cached reply excerpt, journal references and any reported
branch, worktree or session link. Excerpts preserve truncation and
run provenance. The budget per need is min(4000, max(1000, 8000 / sources))
Unicode characters. Retries reuse the stored blocks. A storage error aborts
launch preparation.
Every launch adds separate journal instructions, including launches of
tasks without needs. They identify the task and tree at launch, the connection, the
agent transport and caller hint. They ask the agent to refresh task and tree
context, read relevant notes and journal progress and outcomes, and to
report the task (report_task, stage task done|fail) if they finish it
or continue it in another session or app. A task whose review is required
at launch adds that a done report leaves it done for a person
(ADR 0026). Retries reuse the instruction
block. Handoff API
Observation contains scoped session and project identity, activity, child and
archive flags, the reported directory and branch, links and a bounded reply. A normalized state is running, needs_input, done,
failed, interrupted, cancelled or idle. The descriptor must declare
any stateReason. Only running and needs_input are active. For example,
owner_exited requires interrupted and means that an execution owner exited without reporting a
result. A missing, offline or malformed snapshot provides no evidence of
failure or completion.
A Reply has itemId, runId, text, truncated and updatedAt.
Acceptance uses the IDs to identify the cached reply and its execution.
Links can carry a web address, a native address and a resume command.
Hosts choose where to open a session through Links.executionDestination.
Without a destination, the task UI offers to copy Links.command and names
the machine when more than one is configured. Both placements read links
from the stored observation. An unconfirmed attempt can retain the reported
command when that write fails. Acceptance and handoff retain their captured
session link (web first, then native).
Usage is optional, cumulative and best effort. It carries turns, uncached
input tokens, cache read and write tokens, output tokens, finished-turn
working time (0 when unknown) and the harness's reported cost (null if
absent). Stage keeps the last reported usage when an update omits it and
does not estimate cost. The Session tab shows the usage of the selected attempt.
DataChangedAt is optional: when the harness last pushed a change to
session data Stage reads on demand (the native queue and usage). Only an
event source or bridge sets it. A poll leaves it unset and Stage keeps the
last one; an older value never moves it back, and a push whose snapshot is
stale still advances it. Task detail exposes it as sessionPush.
Task detail opens on the Task tab. The Session tab shows the current session
and links to recorded attempts. Only the current session can receive requests
or messages. Its composer selects the declared steer and queue operations
while a turn runs and send after it ends. The Recent activity panel reads
bounded harness activity and polls while the current turn runs or waits for
input with the tab visible. The native queue under the composer follows
the same cadence when queueManage is available. When the harness pushes
data changes (sessionPush), each change re-reads the queue and activity,
and while the stream is live the queue's timer falls back to 30 seconds to
cover missed events and reconnects. Activity keeps its five-second timer:
message parts are not pushed. Past attempts use the
recorded observation and read activity by that attempt's reference.
The main server builds the desired watch set per machine. It lists each connection's attention eligibility and the external session IDs to read with their cadence. It sends the whole set at attachment and whenever the set changes. The latest generation in a server epoch replaces the previous set. A server restart starts a new epoch. Removing a watch cancels its work and discards late results from that watch.
The same runner serves the local machine in process and runs inside each worker. Each connection has independent observation work. Fast polling and attention discovery use a five-second interval. Stale sessions, including unaccepted done tasks awaiting a late closure, are read every minute. Polling reconciles missed events. Full sync still refreshes inventory. Launch reconciliation and explicit fresh reads keep their request/response paths. ADR 0008 D11
An EventSource streams observations to the connection's local runner.
The stream retries after five seconds, with the last error exposed in
status until recovery. The attention loop reads sessions from the adapter
and refreshes previously watched ones. It also follows discovered active
sessions after they leave the feed, including active attention samples in
the outbox when the worker restarts. For unowned sessions, the default
notify policy (OpenCode and T3) surfaces waiting rows, and after startup
can send an inbox event and push for transitions into needs_input, done
or failed. Claude Code's silent policy surfaces waiting rows and the
needs-input count. Waiting rows have no Track action.
Local samples, worker batches and external pushes converge on the main
server's observation ingest rules. Ingest looks up the task by scoped session
and delegates to the coordinator's apply path, also used by PollTask.
Unowned sessions follow attention policy, and launches reconcile their own
sessions. Apply verifies the session and descriptor policy, stores the
observation and applies the transition. The harness's updatedAt orders
snapshots first. When it ties, Stage uses the sample capture time or the
time the main received a bridge push. Bridge task events still use the
harness timestamp. An idle observation leaves a known task state in place.
An observation of a task whose current attempt has an agent claim is
stored and changes nothing else (Takeover), and so is one of
the execution in which the task's own session self-reported
(Self-report).
The worker seals records with contiguous cursors and sends one batch at a time. The server commits each record with its durable effects or permanent disposition and acknowledges the committed prefix. Replay after a lost acknowledgement leaves task transitions, journals and durable notifications recorded once. Replay keeps the sample times, and transient notifications follow commit. A reported gap asks for a fresh sample of the watch set. Worker channel · Worker observation files
A closure carries a signal from the harness, such as Claude Code, Codex or
OpenCode archived, or T3 settled. A descriptor maps a declared
signal to acceptance provenance, a journal event and the toggle and result
copy. With no declared closure, the connection has no auto-complete option.
Inference requires per-connection autoComplete, a task review of
optional (ADR 0026: review required leaves
the task done for a person) and a successful execution recorded as
done. An idle observation can still carry a closure, in which
case inference checks the stored task state. Stage infers completion once
per execution. Acceptance snapshots are durable and release dependencies.
Inferred completion
A wrapper declares wraps.origins for the markers it leaves in sessions
run through it (T3 leaves t3-code in Claude Code and T3 Code in
Codex). Each origin has one owner in the registry. Adapters report the
raw Observation.origin, including across the worker channel. Stage
refuses tracking through the wrapped harness in preview, link repair and
polling, and omits those sessions from attention. The reason names the
wrapper: "This Claude Code session was started by
T3. Stage follows it through T3."
A harness that records origin can also declare an attribution origin variable. When resolving a caller, a wrapped harness's session variable yields to the wrapper's variable or a wrapped origin, unless a declared precedence condition owns the session.
A bridge or hook may push snapshots for an existing connection to
POST /api/connections/{id}/observations. The handler checks the
connection and sends each observation to observe.Service.Ingest for the
same validation and descriptor policy as adapter events. Each result
is ingested, ignored or invalid with a reason where applicable.
A pushed snapshot needs updatedAt. Timestamps more than five minutes
ahead of the server are invalid. A bridge can push for any active
connection while its worker is offline or incompatible. Polling continues
to reconcile lost events.
Observation API
An agent-run task runs outside Stage
(ADR 0016). An agent in any harness, in
any number of sessions or subagents, or an app outside Stage reads the
task or tree through the CLI, MCP or HTTP, claims it, works it and reports
done or failed. Stage launches no session, takes no launch claim and
freezes no launch inputs for it. The coordinator
serializes claims, reports and releases with launches on the per-task lock
and publishes their transitions like any other. The claim records the
caller session and grants no destination. It is exclusive by default
(ADR 0025): another
session's claim is refused with claim_held naming the holder, while
reports and release stay open to anyone. A claim with no note or report
for STAGE_CLAIM_STALE_AFTER (default 2h) reads stale on read; Stage never
releases it on its own. Stage records the branch, worktree, pull request,
commit and labelled links an agent reports, and the reporter it names
(label, harness name, session URL), and verifies none of them
(ADR 0007).
Who works an agent-run task is the claim's caller session plus its
free-form reporter, and the other sessions listed on the open claim
(ADR 0016):
attach_session lists a subagent or another session, and so does a claim
or report from a caller not yet listed, in the same transaction. A listed
session resolves the claim's task in its context and claims the exclusive
claim as its own. The reporter covers harnesses Stage has no connection
for: the CLI and stdio MCP fill it from a detected harness session
variable's descriptor (name and session id) when no connection resolves
the caller. Core never names a harness for it.
A report is the one way an agent finishes a task, its own included
(ADR 0016). A done report
completes the task by default, through the same acceptance transaction as
a person's (completeTx), with the summary as the accepted reply. Its
dependents get that snapshot in their handoff like any accepted result. A
report also takes a done task that is not completed, one its
Stage-launched session finished or one reported for review: from another
session it claims the current attempt without a state change, so later
observations of that session no longer move the task; from the task's own
session it is a self-report. Agents have no preview or complete;
people complete in the app.
Review policy (ADR 0026) decides whether a
report or an inferred completion finishes work without a person. A tree
has review (optional by default, or required); a task inherits it or
sets its own, and a standalone task is optional unless set. With review
required, an agent's done report (an agent principal, or any report that
names a caller session) records its note and event and ends the claim but
leaves the task done, and the response says reviewRequired; inferred
completion skips the task. A person completes it in the app, or reports
it there (State: Completed, "finished elsewhere"), which is the review. The setting changes
in any state; it decides at the report or the inference.
Agent-run tasks API
A report whose caller session is the task's current session, with no
claim on the attempt, is a self-report: Stage records the outcome and
keeps following the session. The report stores an ended self_report
claim with the session's executionId from its stored observation; it
never sets agentRun. ApplyObservation stores an observation of that
execution and returns before any transition or inferred completion, so
the rest of the reporting turn neither moves the task back to running nor
infers a completion the report left for review. A new execution (a
follow-up turn) moves the task as usual and may infer completion. A
stale stored observation (the reporting turn not yet observed) leaves
nothing held: that turn's samples then move the task as usual.
InferCompletion and the report lock the task row, so a self-report and
an inferred completion of one attempt cannot both complete it; a done
self-report on completed work only adds its note.
ADR 0016
Ready work is what an agent may take
(ADR 0025): backlog tasks
run by agent (standalone, or members of a tree run by agent whose needs
are completed) that read ready, are not closed and have no open claim,
oldest ready first. Tasks and trees run by Stage never list. list_ready
(stage next, GET /api/tasks/ready) reads it for a project, a tree or
the caller session's project; with none it answers project_required.
claim_next (stage next --claim) takes the first one: each candidate is
claimed under its per-task lock and rechecked in the claim's transaction,
and one another caller took is skipped, so two callers never take the
same task. stage tree next ID lists a tree's ready members with their
briefs.
A person hands work to an agent with Hand to agent
(ADR 0027): it sets a standalone
backlog task to run by agent (a backlog member through its tree, after a
confirm), then offers the pickup text or the task's pickup brief
(GET /api/tasks/:id?brief=1, built by the coordinator from the claim
brief's task block, the accepted handoffs and a claim line for the task's
state) or the tree brief. The Dashboard reads ready work run by agent as
Ready for pickup and open claims past their stale time as Stale claims,
both from Task JSON (runBy, readiness, agentRun.staleAt), with no
extra route. agentRun.lastNote (the latest note since the claim) and
agentInbox.notes (the agent's own notes) are derived on read from the
journal.
Claim, ready and tree briefs and launch journal blocks name the CLI the
agent's machine has and give the HTTP address and routes
(ADR 0028). A worker reports its machine's
CLI name in the channel connect (Stage-Worker-CLI); the hub keeps it with
the session, and machine.Set.AgentCLI reads it. The coordinator's
cliOn uses it for the launch's connection machine, and for a brief, the
request's forwarding machine (db.ActingMachine), else the server's CLI
name; httpAPIOn picks the address the same way. The pickup brief
(GET /api/tasks/:id?brief=1) opens with a <stage-interfaces> block
and, unless the task is completed, ends with the claim brief's
<stage-agent-run> block, for an agent with no Stage skill; the tree
brief opens with the same interfaces block.
Claiming a Stage-launched task that is running or needs input, or
reporting on it from another session or with no caller session, takes its
session over (a self-report does not). From then on the attempt belongs to the
agent's reports: ApplyObservation stores each observation of the
session for history and returns before any transition or inferred
completion while the task's agentRun is set (a claim on the current
launch attempt, open or ended by a report). The harness keeps the
session; Stage neither stops nor archives it. A new launch attempt is not
covered by the claim, so a later Start observes its own session as usual.
A released claim no longer covers the attempt, and the task returns to
backlog, which observations do not move.
An agent working a claimed task asks the user with a needs_input report
(ADR 0016): a question,
optional options and a requestId. Under the task lock the coordinator
stores it (one pending per task), records it as a task note, keeps the
claim open and moves the task to needs_input; the transition drives the
usual needs-input notification, push and dashboard row. The question is
served as a session request (Kind: "question", id q<id>, one
question answer with the options and a free-text answer), so the app's
Requests panel and list_requests read it with no harness behind it.
Requests and Respond take this path first whenever the task has an
open agent claim. An answer (a person, through the human-only respond
route, ADR 0021) is stored with a
conditional update, recorded as a task note and moves the task back to
running; a revision guard keeps the first answer. A done or failed
report, or a release, withdraws a pending question. The session Stage
launched for a task, which Stage keeps following when it reports
(self-report), is refused (self_session_question): it asks through its
harness, whose request Stage shows, unless it claims the task first. The agent reads the
answer and any notes people left since the claim from task detail's
agentInbox; wait_task with question or messageAfter returns on
them. A message is a plain task note, never a send_message.
Agent questions API
A tree is run by Stage or by an agent (ADR 0023),
chosen when planning; members follow their tree. Run by Stage, the release
runner launches each member whose needs are completed. Run by agent, its
launchable set excludes the tree's members and the automatic launch claim
refuses them; released members read ready instead, with a readiness episode
and notification, for an agent to claim (ready work). A standalone task's
runBy launches nothing either way; run by agent, its backlog reads ready
for agents to pull. Start stays available for a person
or an agent. Switching a tree back to Stage resumes automatic launches on
the next reconcile; member claims stay open. claim_task refuses a backlog
member of a tree run by Stage (tree_run_by_stage): the agent switches the
tree first.
Schedules have runBy too (ADR 0024).
Run by Stage, the schedule runner of the schedule's connection fires it and
launches the task it spawns through the coordinator. Run by agent, one
connection-independent runner fires it: the spawned task waits in backlog,
run by agent, for an agent to claim, and nothing launches it (a person can
still Start it when the schedule names a connection and workspace). The
next fire skips while that task waits, is claimed or needs input.
A task or schedule may name no harness connection
(ADR 0019). Such a task has no
workspace and an empty execution config. Start and Start ready answer
destination_required before any launch claim, no connection's release
pass launches it, and observation and discovery skip it. Once its needs
are completed it reads ready for a person or agent. Claim, report and
release work as for any task. A launch whose prompt is blank sends the
title. A schedule with no connection is always paused and never fires.
The harness authoring guide covers where to implement each extension. Stage-wide features work across harnesses or degrade through declared capabilities.
Use a typed operation when Stage branches on availability.
execution.Op covers launch, stop, reply, attention, images,
respond, send, steer, queue, queueManage, queueEdit, queueReorder, activity, sessionRename, workspaceAdd and directoryBrowse.
Every adapter declares each operation and a reason when unavailable.
For example, images gates image fields and image delivery in the API
and MCP. The remote proxy passes the declarations through and drops
operations Stage no longer knows (adopt, opening and sessionSearch,
removed by ADR 0022) when an older
worker still declares them.
execution.SessionNamer is an optional role gated by the sessionRename
operation: RenameSession(ctx, ref, title) gives a session a new name in
its harness. Stage calls it only after a task's title changes (PATCH /api/tasks/:id, whatever the caller: UI, MCP or CLI), for the task's
current session. The coordinator runs the rename in the background with a 10 s
timeout. Renames of one task run in order, each with the title current
when it runs, so the last edit names the session. A declared-unavailable
operation is skipped. Any other failure (the harness or worker is
unreachable, its declaration cannot be read, or the rename fails) appends
a system journal note, "Could not rename the session: ",
and never fails the update. The harness owns the name; Stage stores
nothing about it.
Each harness names a session at launch from the task title, and renames it with its own interface:
| Harness | Name at launch | Rename |
|---|---|---|
| T3 | t3_thread_launch title. |
t3_thread_update {threadId, action: "rename", title, clientRequestId} (fresh key per rename, retried with the same key). |
| Codex | thread/name/set right after thread/start; a failure leaves Codex's preview. |
thread/name/set {threadId, name}. |
| OpenCode | POST /api/session title. |
PATCH /api/session/{id} {title} (204). Available when OpenAPI advertises session.update with a title; otherwise unavailable with a version reason. |
| Claude Code | claude --bg -n <title>. |
Unavailable: "Claude Code has no rename interface." |
On workers the operation requires both the sessionNamer trait on the
connection and the adapter.sessionRename request kind. An older worker
declares it unavailable ("Update Stage on the worker machine...") and
keeps its other operations. Task update
execution.WorkspaceAdder is the optional role behind the workspaceAdd
operation (ADR 0012). The adapter
declares Capabilities.WorkspaceSources; each source has typed input
fields (text, choice, boolean, path), optional confirmation text
and availability. ValidateWorkspaceSources rejects duplicate or unstable
IDs, missing labels, unavailable sources without a reason and an available
operation without an available source. Stage then drops the sources and
reports the operation unavailable.
AddWorkspace receives the source ID, input already validated against the
source fields, the caller's requestId and the confirmation. It returns
the added workspace's native ID and root, Existing, a message and facts.
*execution.Invalid is a 400. *execution.Busy (the harness changed
nothing; retry) is a 409 harness_busy. *execution.OutcomeUncertain, a lost worker
reply or the 5-minute deadline is a 504 outcome_uncertain; the caller
retries with the same requestId. After success Stage refreshes the
connection's inventory, resolves the row by native ID and root, and records
a workspace_added project event.
On workers the operation requires the workspaceAdder trait and the
adapter.workspaceAdd request kind, negotiated on the existing channel.
T3 (T3 workspace sources) adds folders, clones and
new projects. OpenCode adds existing folders (Adding folders).
Codex trusts folders (Codex adapter). Claude Code declares
the source trust (Trust in Claude Code).
Workspace add API
execution.DirectoryBrowser is the optional role behind the
directoryBrowse operation. It lets a person pick a declared path field's
value from the harness host's folders instead of typing it. Browse takes
BrowseRequest{Path, ShowHidden}, where an empty Path means the adapter's
default start. It returns BrowseResult{Path, Parent, Entries, Truncated}:
the cleaned folder, its parent ("" at /), and child folders only, each
with its name and absolute path. Files are never listed.
execution.Listing gives every adapter the same result: dot-named folders
only with ShowHidden, sorted by name ignoring case, at most 500
(MaxDirectoryEntries, then Truncated). Browsing reads only. It never
persists a project, writes a harness file, or runs on behalf of an agent.
*execution.Invalid (a missing folder, a file, an unreadable folder) is a
400 with the harness's words. *execution.BrowseUnavailable is a 409
operation_unavailable with the adapter's reason. Any other failure is a
502 directory_browse_failed. On workers the operation needs the
directoryBrowser trait and the adapter.directoryBrowse request kind;
BrowseUnavailable crosses the channel as unsupported and keeps its
reason. An older worker without the kind declares the operation
unavailable ("Update Stage on the worker machine…").
| Harness | directoryBrowse |
|---|---|
| Claude Code | Unavailable: "Type the path." |
| Codex | fs/readDirectory; the default start is the host user's home (Codex adapter) |
| OpenCode | fs.list, anchored to a listed project (OpenCode folder browsing) |
| T3 | Unavailable: "T3 does not expose folder browsing to Stage; type the path." |
The route is GET /api/connections/{id}/directories and only people may
use it (API). In the UI, a path input offers
Browse… when its connection declares the operation
(harnesses).
ADR 0014 defines the session surface.
The Interactive trait exposes pending requests and answers behind
respond and delivers messages behind send, steer and queue.
An approval takes an option and may accept text
for a designated option. A question group takes answers keyed by question
ID, using option labels or custom text when allowed. An input takes free
text. A preview can describe the command, path, URL or input the request
acts on. A request that is no longer pending returns ErrNotFound (404).
A successful follow-up records a task timeline entry. Only people send,
respond and change the queue; agents read requests, activity and the queue
(ADR 0021). Claude Code supplies both operations, with responses requiring
its hook receiver. T3 supplies both for its questions and messages
(T3 interaction). OpenCode supplies both for its
permissions, the forms Stage can show and messages
(OpenCode interaction). Codex supplies both for
command, file-change and permission approvals on tracked active threads and
messages to an idle thread (Codex adapter). A harness that can wait on requests
it can't list declares unlistedRequests on its descriptor with where to
answer them. The app shows that guidance in the Session composer when a
needs-input session lists none. Interaction API
Interactive.Send receives a Message.Delivery. send (also empty)
starts a new turn after the previous one ends. steer
injects into a running turn. queue admits a message during a running
turn for the harness to deliver as the next turn. The coordinator checks
the corresponding operation. Adapters return Invalid for an unsupported
delivery and Busy with guidance when the turn state does not fit
(409 session_busy). A permanent refusal is 409 session_refused.
A successful delivery records its mode and attribution in a timeline
event. Stage keeps the message text in the dispatch only. Workers relay
send on adapter.send and steer and queue on adapter.deliver.
The legacy send channel accepts only the send mode.
QueueManager uses queueManage to list the current session's native
queue, cancel a pending message or promote one to a steer. The harness
keeps the messages and their order. Stage returns previews capped at 2000
runes and the harness's creation time and source when known. A message
that has left the queue returns ErrNotFound (404). Writes refuse the
caller's own task and record successful actions without message text.
Workers relay these calls through adapter.queue and cap previews before
encoding the response. Older workers report update guidance for the operation.
A preview the harness or Stage shortened carries Truncated.
QueueEditor (queueEdit) replaces a queued message's whole text in place,
keeping its ID and position. QueueReorderer (queueReorder) moves a
message before another queued message, or to the end with no target.
Conflict semantics follow the harness: there is no revision or
precondition, so the last write wins, and a write races only with
dispatch. A message that has left the queue returns ErrNotFound (404).
A move target that has left returns Busy (409 session_busy), and a
move to the current position succeeds. Blank text is rejected before the
adapter (400), as is a move before itself. Edit from full text only: the
UI disables Edit for a truncated preview. Writes refuse the caller's own
task and record text-free timeline events. Workers relay both through
adapter.queueChange; workers without it report update guidance.
ActivityReader reads bounded recent activity for the current session or
a recorded attempt behind that session connection's activity operation.
Stage passes the recorded ref and keeps no activity items. The adapter returns the
last N items in chronological order, the current plan, changed files,
model and optional harness details. The coordinator validates kinds and
statuses and enforces the item, title, text and details limits.
Workers relay the query through adapter.activity, bounding the result
before encoding it. Older workers without the channel kinds report their
update guidance in the connection operations.
First answer wins (ADR 0018):
tasks.state_revision counts real state transitions, and a send or
respond with expectedStateRevision is guarded. The coordinator takes the
task's lock, re-reads it and requires needs_input at that revision, not
yet answered (answered_revision), else 409 already_answered. It holds
the lock through the harness call and the record, which sets
answered_revision in the same write as the event, then observes the
session after unlocking. Without the revision nothing is locked or
required. Answers race only through Stage (people, ADR 0021):
an answer typed directly in the harness cannot be prevented, and the
loser's later send queues behind it or is Busy. Send, respond and queue
writes record the target as Cause.TaskID and no caller session.
A declared action is a harness-owned operation Stage relays. execution.Action
carries the target, stable ID, caller policy, availability, confirmation
and input schema. Connectors own connection actions, including setup.
Capabilities.Actions describes session and project actions. Project
actions use the exact workspace on the selected connection, including a
listed row its harness will not launch in (an action may fix that) or has
archived (restoring it is one), and Stage refreshes the connection's
inventory after one succeeds or ends uncertain (best effort). A harness
whose project actions depend on the workspace (T3's archive state)
declares their availability through WorkspaceFeatures, keeping every
other action. Project actions change the
harness's project only: Stage group titles stay as they are. Stage resolves that scope, checks caller policy and schema, and
reaches the owner through execution.As[execution.Actor]. The owner
validates semantic input. ActionRequest.confirmed tells the owner the
caller sent Stage-Action-Confirmed: 1 (MCP run_action confirmed); an
owner may require it, as Claude Code's trust does.
Workers advertise the actor trait and receive adapter.act.
A lost reply leaves the outcome uncertain. Stage does not replay the action.
A session's observation can carry actions: {id, available, reason, confirm} per
declared session action, in the harness's vocabulary (already archived,
still running). An available state's confirm is the confirmation the
action needs for this session now, replacing the declared one (an action
that would interrupt a running turn). Stage applies them (execution.ApplyActionStates): the task's
action list reads the last stored observation, and dispatch reads the fresh
observation it takes before Act, refusing with 409
operation_unavailable and the harness's reason, or 400 when the state
carries a confirm and the caller sent no Stage-Action-Confirmed: 1.
The app shows the applied confirm like a declared one. A state never makes
an unavailable action available; an older worker that omits states leaves the
declarations as they are, and the harness still refuses an invalid request.
A session's observation can also carry operations: {op: {available, reason}} for the message operations send, steer and queue
(execution.SessionOps), when that session can't take one now although
the connection can (it continues in another app, or is moving there).
Stage stores it with the observation and serves it on task detail as
sessionOperations (execution.SessionOperations: other operations
dropped, a blank reason filled in). The composer narrows the connection's
operations with it: a refused delivery shows disabled with the reason
before anyone types, the draft reads only, and the session's open or
resume button and Session actions sit beside the reason. A state never
makes an unavailable operation available. A harness that reports none
(an older worker, or one with nothing to say) leaves delivery as declared
(ADR 0008 P2). The adapter's Busy on Send stays the backstop for a stale
page, agents and the API; Stage doesn't refuse a message from the stored
observation itself.
A session action from the task's own session is 403
self_action_forbidden (ADR 0011):
closing a session can infer completion.
Each session action is user-triggered, by a person or an agent, never automatic. Archiving or settling a session in its harness flows through observation and inferred completion unchanged: the action itself never completes a task.
| Harness | Session actions | Harness call | Unavailable when |
|---|---|---|---|
| Claude Code | none | ||
| Codex | archive "Archive in Codex" |
thread/archive {threadId} |
archived |
| OpenCode | archive "Archive in OpenCode" |
PATCH /api/session/{id} {archived: true} (session.update) |
archived; the service's spec lacks session.update with archived |
| T3 | settle "Settle in T3", archive "Archive in T3" |
t3_thread_organize {threadId, action} |
settle: settled, archived, running or waiting for an answer; archive: archived |
| Harness | Project actions | Harness call | Unavailable when |
|---|---|---|---|
| Claude Code | trust "Trust in Claude Code" |
described with its adapter | |
| Codex | none | ||
| OpenCode | rename "Rename in OpenCode" (name) |
PATCH /api/project/{id} {name} (project.update) |
the global project; the service's spec lacks project.update with name |
| T3 | rename "Rename in T3" (title), archive "Archive in T3", restore "Restore in T3", remove "Remove from T3" |
t3_project_update {projectId, title} or {projectId, archived}; t3_project_delete {projectId} |
archive: archived; restore: not archived; all: T3 no longer lists the project or its list fails |
Renames, archives and restores are open to people and agents. T3's remove is destructive and user-only, so it needs confirmation.
Each confirms first. T3's archive does not settle a thread, so only Settle
in T3 can infer completion; its confirmation says so. The harness's own
refusals (Codex RPC errors, T3 orchestration errors) return 409
action_busy with its message.
A successful session action records a redacted journal event. Dispatch runs
outside the journal transaction, so a storage retry cannot repeat the action.
execution.Fact carries display data in status, observations or action
results. Stage filters malformed or duplicate facts and clears unsafe links.
Actions and facts API
internal/machine hosts adapters, connectors and local operations. A machine
has an ID, online status, a hosting profile and Ops. machine.Set
tracks the local machine and joined workers. machine.Connections resolves
an adapter or role using the connection's machine and its registered kind.
A retired connection returns connection_retired. An unhosted or
disallowed connection returns connection_unavailable with the reason.
Machine.Allows is the hosting decision shared by setup, the connector
index and adapter lookup. The local machine uses its profile. Remote
machines use the worker's advertised profile and available setups. A worker
that allows local processes but lacks a setup reports the reason to update
it. Before the first profile arrives, availability is unknown and requests
report offline or starting as appropriate. A disallowed setup route returns
409 harness_unavailable with the fix. Serve and workers compose only
allowed modules.
machine.Local hosts machine 1 in process. serve/localmachine.go
composes its modules. Setup uses Local.Install(old, next, adapter) to
install or move a connection's adapter (nil uninstalls). Connection change
hooks wake the engine and resync runners.
machine.LocalOps enriches filesystem-local inventory with absolute
canonical paths, Git metadata including the common directory for linked
worktrees, and checkout import eligibility. Claude Code uses
checkoutTop and Codex inCheckout. Stage stores the evidence and resolves
project identity on the main server. Raw WorkspaceInfo.OriginRemote can
contain credentials and is kept out of client responses.
Workspace evidence
A joined machine is a remote.Machine on the main server. Its worker
serves remote.Host over the authenticated channel, dispatching calls to
a machine.Local and its ops. The worker has no Stage database. The
server keeps the store, task state and acceptance.
Worker channel
- Adapter and ops calls. The proxy scopes calls to ready connections
and advertised traits. It forwards inventory enrichment as
ops.inventorywith{workspaces}, and caches health for five seconds within a ready snapshot. The launch intent travels without image bytes. The worker calls back for images and checkpoint saves. - Observation. A worker with both negotiated observation kinds accepts
observe.watchand sendsobserve.batchindependently of command calls. Its runner polls and subscribes beside the adapters. Stream errors are visible in status and logs. - Setup.
remote.Connectorproxiesconnector.*status and mutations. The worker composes only kinds the server advertises that its profile allows.setup.snapshotsupplies public settings and active connection identity for the selected kinds.setup.settings.get({kind}),setup.settings.save({kind, patch}),setup.identity.*andsetup.status.erroruse the authenticated machine. Active identity reads usesetup.identity.activeIdentityand connection checks usesetup.identity.exists. The main server stores public settings, identity and sync status. Credentials stay in the worker'scredentials.json(mode0600, deleted on join and leave). A secret entered during setup can reach the worker through the intended configure or run call. The worker restores adapters from its local public settings cache and reconciles with the main server on reconnect. Pair and connect use the same retirement and revival rules as local setup and wake sync and scheduling when ready.
Offline, negotiating and incompatible workers report availability reasons
immediately. A worker with a valid cache and watch set keeps observing across
a channel outage and worker restart. The main server keeps the last applied
state until it ingests new evidence. A new launch is refused with
connection_unavailable.
A dispatched attempt stays unconfirmed and retries through its saved
checkpoint or correlation policy when the worker returns. Only a worker
adapter's certified rejection can return a dispatched task to Backlog.
The machine JSON round-trip tests cover the adapter contract, setup ports
and ops. The internal/engine contract suite exercises local adapters
and remote proxies through a real worker.Run and a loopback channel
(remote/remotetest). Cases cover lost replies, restarts during launch,
offline reads and acceptance, failed and late checkpoint saves, images and
traits. Fake harnesses cover deterministic two-step launch, a correlated
harness with assigned IDs and a hosted harness that pushes, loses its
owner and answers interaction. API tests cover immutable handoff and
journal context, destination repair and link ownership and revisions.
workersetup tests run over a real channel and store. They cover Claude Code
and Codex setup and launch against their fakes, including stored resume
commands and disconnect, OpenCode credentials on the worker, T3 pairing and
caller machine scoping. Profile tests cover workers without local
processes and harnesses an older server omits.
The T3 adapter maps a T3 environment's projects and threads to a connection.
The adapter sends a root workspaceStrategy by default and a worktree
strategy with baseRef and branch when worktree is enabled. A ref
starting with origin/ or upstream/ sets startFromOrigin. A worktree with no base ref is rejected.
Checkpoints pin the OAuth authentication session namespace, environment, deterministic thread ID and upload references. Re-pairing cannot replay the old namespace. A known thread can still be read in the same verified environment after re-pairing. A conflicting launch reply is held for explicit linking. Uploaded images stay with uncertain attempts and may be discarded on certified rejection. T3 tests cover namespace rotation and failed checkpoint saves.
Settlement or an idle thread with a prior run reads done when no active
work takes precedence. A thread that has never run stays idle. The newest run supplies the observed state and end time, skipping
cancelled or rolled-back runs that never started, such as queued follow-ups.
Settlement reports a settled closure and grants acceptance only through
inferred completion. Settle in T3 and Archive in T3 relay
t3_thread_organize (Actions and facts); the
observation's action states mirror T3's own refusals.
T3's project actions relay its project management over MCP
(server/internal/t3/project_actions.go) on the T3 project behind a
workspace row. The Stage group keeps its title.
- Rename sets T3's title (
t3_project_update {projectId, title}). - Archive and restore set
archived(t3_project_update). T3 keeps the threads and files. Archive confirms first. An archived row stays a project action target, so it can be restored from Stage. - Remove calls
t3_project_delete {projectId}and never sendsforce. It is destructive and user-only, and it confirms: "Remove this project from T3? T3 keeps the files on disk. A project with threads can't be removed; archive it instead." T3 refuses a project with threads (archived threads included); Stage relays that as "T3 can't remove a project with threads. Archive it instead." (400), since T3's own wording names the force flag. - Availability. The adapter implements
WorkspaceFeatures: it lists T3's projects and marks Archive unavailable on an archived project ("Already archived in T3.") and Restore on any other ("Not archived in T3."). When T3 no longer lists the project, or the list fails, all four are unavailable, and the capabilities still answer, since launches read them too. Rename and remove work on archived projects, as in T3. - Refusals. T3's other refusals are 400 with its message; "The project was not found." is 404.
- Lost replies.
t3_project_updatewith only a title orarchivedsets values, so the client retries it once on a closed connection. A transport failure on either call lists again: an update the listing shows, or a project it no longer lists after remove, succeeds. Otherwise the outcome is uncertain (502).
T3 implements Interactive, ActivityReader and QueueManager over its MCP. Stage
declares the operations from tools/list: t3_pending_request for
respond, t3_thread_send and t3_thread_read for delivery, and
t3_thread_read for activity, and t3_queue plus t3_thread_read for
queueManage. queueEdit and queueReorder also need edit and
reorder in the t3_queue action enum. A missing tool or action gives an
Update T3 reason.
-
Native queue.
t3_queuelists pending runs in send order and handlescancelandpromote_to_steer. Promotion targets the active run reported byt3_thread_read. Its list omits timestamps and source and cuts text at 1,000 characters withtruncated. -
Edit and reorder (verified on t3 0.1.13 with a live Codex turn).
editreplacestextand keeps attachments, ID and position; blank text fails with "cannot be edited to an empty message" (Invalid).reordertakesbeforeRunId,nullfor the end. "Run X is not queued." means the moved run left (ErrNotFound); "Queue target X is not queued." means the target left, or is the run itself or the active run (Busy). A move to the current position fails natively with "Command produced no domain events.", which Stage reports as success. T3 accepts edits and moves while the queue is held after an interrupt. -
Requests.
t3_pending_requestlists a thread's pending user-input requests; each is read and becomes onequestionrequest. Questions keep their ID, header, prompt and multi-select, arecustomunless T3 disallows free answers, and their options keep label, description and preview. A request answered while Stage reads it is left out. T3 reports no request time, socreatedAtis when this Stage process first listed the request (in memory: a restart resets it to the next listing). T3's MCP neither lists nor answers permission requests: they are answered in T3, and the descriptor declaresunlistedRequests("Approve permission requests in T3."). So a T3 task can readneeds_inputwith no answerable requests: it waits on a permission request, and Open in T3 is the way to approve it. -
Respond. Stage answers by option label or one custom text. The adapter sends T3's option value for a valued option and checks the answers by T3's client rules (every question, arrays only for multi-select, custom text only where allowed) before sending. A misfit answer, an option or text without answers, or T3 refusing the answer is
*Invalid(400). A request already answered, expired, unknown, or on a missing thread isErrNotFound(404). -
Send, steer and queue.
t3_thread_sendtakes modequeuefor Send after the turn ends or Queue during an active turn. Steer uses modesteerduring an active turn. T3 decides whether it can accept the message at delivery time. The message'sRequestIDis T3'sclientRequestId: the coordinator sets a freshstage-send:<random>per API call, and T3 returns the first send's message and run for a repeat, so a send lost on a closed connection is retried once. A thread with any pending request takes no message (*Busy, 409session_busy: answer its questions first, or approve its permission request in T3). A native refusal keeps T3's message (session_refused). If the turn ends before T3 can steer, its refusal issession_busy. -
Recent activity. A bounded
t3_thread_readactivity page supplies local timeline items, the latest visible todo list and changed-file paths with counts where reported. Thread details include provider instance, model, runtime and interaction modes, branch and worktree. T3-backed Claude Code and Codex threads use this same contract. -
Permission approval follow-up. Before using the WebSocket
thread.approval.respondAPI, verify its availability and stable contract, how Stage's paired credential can authenticate, how pending approvals are discovered and correlated, and which decisions can be safely relayed with stale-request and replay handling. -
Live check (2026-11-28, local T3 from source at
9f83ba58, throwaway scratch thread): an idle send reporteddelivery: started; a send while a turn ran reportedqueuedand ran as the next run only after that run completed; a repeat with the sameclientRequestIdreturned the same message and run; a send while the thread waited on a question was accepted by T3 asqueued(Stage refuses it first with*Busy, so the question is answered before the next turn); answering the question by option label (T3 takes the label when the option has no value) resumed the turn and the queued message ran after it; a send to the archived thread failedthread_not_sendable("is archived and cannot receive messages"). T3 deduplicates per MCP client (its message id embeds the client), so the ID covers retries from one Stage connection. -
On T3 0.1.13, Stage's full-access OAuth client sent to a scratch thread in
full-accessruntime anddefaultinteraction mode, steered and queued in an active turn, and read a bounded activity page. That client also answered a scratch thread's question inplanmode. A pending command approval appeared in activity and was absent from the question list. The Session header shows the reported provider instance, model and runtime mode.
T3 implements WorkspaceAdder over its MCP with Stage's mcp-client token
(server/internal/t3/workspace_add.go). It declares three sources:
| Source | Input | T3 calls |
|---|---|---|
folder "Existing folder" |
path (required), title (defaults to the folder name), createIfMissing |
t3_project_create {title, workspaceRoot, createWorkspaceRootIfMissing} |
clone "Clone repository" |
remoteUrl (required), destination (required, new or empty), title |
t3_project_clone {remoteUrl, destinationPath}, then t3_project_create on the returned cwd |
new "New project" |
title (required) |
t3_project_create {title}: T3 makes a Git repository in its projects folder |
- Paths. Paths must be absolute on the T3 host;
~and relative paths are refused before T3 is called. Paths are compared cleaned, as T3 resolves them. - Existing targets.
t3_project_createhas no request ID, so every source lists projects first. A folder or clone destination T3 already registered returnsExisting: truewithout a call. An archived T3 project there is refused: restore it in T3. T3's duplicate error ("The workspace is already registered to a project.") lists again and returns the match. - Refusals. A T3 tool error is
*Invalidwith T3's message. T3 reports a missing folder only as "The operation could not be completed."; Stage adds a hint to create it. A clone into a non-empty destination suggests Existing folder, for a checkout an earlier request cloned. A register failure after a clone names the checkout. - Lost replies. A transport failure lists again. A folder at the
requested root is returned. After a clone, the register is retried once.
For
new, exactly one project with that title that was not in the first list is returned. Otherwise the outcome is uncertain (504). T3's clone has no timeout, so a clone that outlasts the 5-minute deadline is uncertain too. A retry then gets the non-empty destination refusal. - New projects. A retry of
newafter a 504 can create a second project, because T3 adds a suffix to a taken folder name (name-2).commitError(T3 created the project but not its first commit) is a warn fact.
Stage connects to an existing OpenCode V2 service using its URL and optional
HTTP Basic credentials. It checks the required operations and worktree, session
and prompt request schemas in /openapi.json. If a requirement is missing,
the error names the reported version and operation. Any version that meets
those requirements can connect. The live suite below records the tested
binary and should run again when a release changes behavior Stage relies on.
OpenCode owns project inventory, workspace strategy, model selection and agent policy.
An empty execution config uses its defaults. An exact workspace provides the model
catalog, variants and visible primary agents. Pass workspaceId to scope the
capabilities endpoint on that connection. Its launch option worktree
(boolean, default off) asks OpenCode to create the worktree using its
default base. Stage verifies the resulting inventory entry, project and
directory. Permission overrides and image delivery report a reason when
unavailable. Archive in OpenCode relays PATCH /api/session/{id}
(session.update with archived, checked softly in /openapi.json: a
service without it keeps connecting and declares the action unavailable;
Actions and facts).
Rename in OpenCode, a project action, sets the project's name with
PATCH /api/project/{id} {name} (project.update, checked softly in the
spec like session.update; server/internal/opencode/project_actions.go).
The Stage group keeps its title. OpenCode's catch-all global project
can't be renamed. A 404 is not found, a 400 relays OpenCode's message, and
a lost reply checks the project listing for the new name, else the outcome
is uncertain. An archived OpenCode project lists no actions: verification
refuses it with "Archived in OpenCode. Unarchive it there, then refresh."
(400).
Every location-scoped OpenCode request (/api/location, /api/model,
/api/agent with location[directory]) builds that location on first load,
and building it persists the directory as a project and clears its archive
(OpenCode 2.3.2, Project.resolve with persist). So Stage verifies a bound
directory with pure reads only: GET /api/project?archived=true (the project
must be listed and not archived) and GET /api/worktree?projectID= (the
directory must be the project's canonical directory or a listed worktree).
Workspaces, Features and verification never call /api/location. The
workspace catalog reads /api/model and /api/agent with the location only
after verification passes, when the project exists unarchived and the read
can neither create nor unarchive it. Launch passes the location for its own
directory. Only an explicit add calls /api/location.
OpenCode declares one workspace source, folder
("Existing folder", a required path: "Absolute path on the OpenCode
host"). OpenCode v2 has no create-project endpoint. Its location side
effect is the add: GET /api/location?location[directory]=<dir> for an
existing directory resolves and persists the project, and clears an
archived time. This behavior is undocumented. It was read from OpenCode's
bundled source (the @opencode/Location and @opencode/Project modules
of @opencode/cli 2.3.2) and checked once against a throwaway
opencode serve with temporary HOME and XDG directories. The fake in
server/internal/opencode/workspace_add_test.go pins it.
The source and workspaceAdd are available when /openapi.json has
location.get (project.list is already required). Otherwise both say
"This OpenCode version cannot add folders (location.get is missing)."
The adapter requires an absolute path and cleans it. It lists projects
(GET /api/project?archived=true), calls the location, then lists them
again. The location's project must be listed, unarchived, and its resolved
checkout must be the project's canonical directory or a saved worktree
(GET /api/worktree?projectID=). Stage gets that project's row (its ID
and canonical root). existing is true when the project was listed and
unarchived before the call.
| Folder | OpenCode 2.3.2 | Stage |
|---|---|---|
| Plain folder, no VCS | Its own project (vcs unset, canonical is the folder) |
A row of its own. Not importable, so it groups standalone. |
| Repository checkout | The repository's project | The project's row |
| Subfolder, linked worktree, symlink | The repository's project; a linked worktree also gets a worktree row | The project's row at its canonical root. The message names the folder OpenCode keeps under it. |
| Git repository with no commit or remote | The catch-all global project |
400: "OpenCode files this folder under its global project. Give the repository a commit or a remote, then add it again." |
| Missing folder | 404 LocationNotFoundError |
400: "Folder not found on the OpenCode host." |
| A file | 500 | 502 |
A lost or unreadable location answer, or a failed listing after the
location answered, is an uncertain outcome (504): OpenCode may have saved
the project, and retrying with the same requestId is safe.
directoryBrowse is available when /openapi.json has fs.list (GET /api/fs/list). Otherwise it says "This OpenCode version cannot list folders
(fs.list is missing). Type the path."
OpenCode 2.3.2 (checked on a throwaway opencode serve with temporary
HOME and XDG directories) lists the direct children of an absolute
path: files and folders, hidden ones included.
Entry paths are relative to the request's location. Folders end in /.
A request without location[directory] resolves the default location (the
service's working directory) and saves it as a project the first time, even
when it lists another path. A request naming an existing project's folder
saves nothing new. A listed path is never saved.
So every listing names a location: the most recently active listed project
that is not archived and not global (archived projects are skipped
because a location request restores them). The default start is that
project's parent folder. If its folder is gone (404
LocationNotFoundError), the next listed project anchors, up to five. With
no usable project, Browse is unavailable: "OpenCode lists no projects yet.
Type the path." A missing path or a file is 404 FileNotFoundError, and
Stage answers 400 "Folder not found on the OpenCode host: ." The
fake in server/internal/opencode/directory_browse_test.go pins this.
Stage saves the frozen intent, reserved IDs and an attempt marker before dispatch. The three external effects are worktree creation, session creation and prompt admission. The adapter performs only the steps the launch options need.
| Lost response | Recovery |
|---|---|
| Worktree creation | Hold the attempt for explicit session linking. OpenCode can suffix the requested name and records the directory before running setup. An inventory entry alone cannot prove success. |
| Session creation | Read the reserved ID and verify the attempt marker, project, directory and top-level status. A missing or conflicting identity stays unconfirmed. |
| Prompt admission | Check the pending inbox, then the delivered message by ID, text and marker. Confirmed admission waits for execution evidence. |
The live suite found that duplicate session creation returned the first session, even with different arguments. Concurrent submissions of the same message ID produced one pending input. After delivery, resubmission returned the original input and woke a new execution interval with no additional model call in the tested case. Recovery therefore reads the original admission instead of sending the prompt again.
Stage polls active execution, pending permissions and forms, and the session's busy and idle times. A new active execution takes precedence over the previous outcome. Inconsistent snapshots are retried. Terminal replies use completed assistant text from that execution, bounded to 4,000 characters. A pasted ID or a matching OpenCode web-client session URL resolves to the session. Browsers and desktop hosts use the configured web-client destination. User acceptance and offline handoff use Stage's stored evidence.
OpenCode declares the V2 session operations per workspace.
respond requires the OpenAPI permission decision and form answer
reply bodies. steer and queue require their respective prompt delivery
values. send requires the prompt delivery contract and uses its default
on an idle session. activity requires session.diff alongside the
session and message reads. queueManage requires inbox listing,
deletion and an update schema that accepts delivery: steer. Missing optional operations show an update
reason. The connection and its other operations stay available.
queueEdit and queueReorder are unavailable: OpenCode 2.3.2's inbox
update changes only delivery, silently ignores other fields such as text
or position, and the inbox keeps enqueue order (verified live).
- Requests.
GET /api/session/{id}/permissionthenGET /api/session/{id}/form, in OpenCode's order. A request whose session or ID prefix (per,frm_) does not match fails the read, and a missing session isErrNotFound. OpenCode reports no request time, socreatedAtis zero.- A permission is an
approvalwith OpenCode's options:once"Allow once",always"Always allow" with thesavepatterns when supplied, andreject"Deny". OpenCode saves rules when it supplies patterns. The Deny text is sent as correction feedback and OpenCode rejects the run's sibling asks. Its title is OpenCode's description of the action ("Run shell commands"), or "Permission required: " for an action OpenCode does not describe. Its detail is the request's message. Its preview is the resource list. - A form is a
questionrequest when Stage can show every field: a string (its options, custom text where allowed, free text without options), a multiselect, a boolean (Yes or No) or a number. Each field is a question keyed by its field key. The agent's question tool (metadata.kindquestion) is titled "OpenCode asks" or "OpenCode asks N questions"; other forms keep their title. A form with a condition (when), a hidden or an external field is not listed, and the descriptor'sunlistedRequestssays to answer it in OpenCode.
- A permission is an
- Respond. The request ID prefix picks the endpoint, and Stage re-reads
the session's list first: a request no longer listed is
ErrNotFound. A permission takes one of its options, with text only on Deny (POST .../permission/{id}/reply {decision, message?}). A form takes answers by field key: option labels become option values, Yes or No a boolean, a number its value; fields left out stay unanswered and OpenCode checks required ones (POST .../form/{id}/reply {answer}). An answer that does not fit is*Invalid(400) before anything is sent. OpenCode answering 404 or 410, or 409 for a settled form, isErrNotFound(404). A rejected answer (400 or 422) is*Invalidwith OpenCode's message. - Send, Steer and Queue.
POST /api/session/{id}/promptsends text. Stage checks active turns and pending permissions and forms before the prompt. Send omitsdeliveryand starts a new turn while idle. Steer passesdelivery: "steer"to join a running turn. Queue passesdelivery: "queue"for the native next turn. A mismatched mode or pending request returns*Busy(409session_busy). The OpenCode endpoint has no expected-turn field, so the session can change after the check. Stage derives the ID from the session and request ID for native deduplication. It checks the original ID in the inbox or messages if a retry arrives after the state changed. - Activity. Stage reads recent
/messagepages (up to three pages of 100 messages) and shows at most the requested number of supported items. Reasoning displays a title. Tool inputs supply previews, and the latest completed todo tool call in the window supplies the plan./diffsupplies the latest turn's file counts, grouped by path.Session.Infosupplies the model, agent, variant and cumulative cost and token counts. The OpenCode header shows agent, model and variant, and the shared Usage panel shows the reported totals. Stage reads the view on demand.
OpenCode's native inbox supports listing, deleting and changing a message
to steer to wake session execution. Stage checks the inbox before
cancelling because OpenCode acknowledges a DELETE for an absent item.
A message consumed between that check and DELETE can still produce a
success response. Workers use adapter.requests,
adapter.respond, adapter.send, adapter.deliver, adapter.activity
and adapter.queue. Inbox and usage events stamp the session's data
change (OpenCode push), and bounded polling reconciles.
The Session header shows the reported agent, model and variant.
OpenCode is an execution.EventSource over its V2 event stream
(server/internal/opencode/events.go): GET /api/event
(event.subscribe), which streams events of every location. Stage
subscribes with one repeated types query per event: session status and
idle, execution started, succeeded, failed and interrupted, permission
asked and replied, form created, replied and cancelled, session archived
and unarchived, and session.renamed when advertised. It adds the data
events session.inbox.enqueued, session.inbox.cancelled,
session.inbox.delivered, session.inbox.delivery.changed and
session.usage.updated only when all five are advertised. The stream is
available when OpenAPI advertises event.subscribe and its types
parameter lists every one of the status events except session.renamed.
Otherwise Events returns at once and the connection is polled only, with
no stream error.
- Wake-ups. An event is a wake-up, not evidence. Stage reads the
session
data.sessionIDnames (data.form.sessionIDfor a created form) throughObserve, the same snapshot polling takes, and passes it to the local runner. Events of other types, events with no valid session ID, heartbeat comments and repeatedserver.connectedframes are ignored. - Data changes. A data event also sets the pushed snapshot's
DataChangedAtto when Stage received the latest such event for that session. The snapshot comes fromObserve, so its usage is theSession.Infototals, never the event's own numbers. A failed read drops the stamp; the 30-second queue fallback covers it. - Coalescing. The stream reader never waits on a read: it marks the session, and one worker observes each marked session in turn, once however many events named it meanwhile (at most 256 sessions waiting; more are left to polling). A failed read is skipped.
- Reconnects. The stream is volatile: a slow consumer overflows and
fails it, and events during a disconnection are missed. A failure frame
(
event: effect/http-api/stream/failure), any other named event, a first frame other thanserver.connected, invalid JSON, the end of the stream, 45 seconds without a frame (OpenCode sends a heartbeat every 15 seconds) or no response within 20 seconds return an error. The runner calls again after five seconds, and polling reconciles what the stream missed.
Workers serve it through adapter.events and the eventSource trait.
The stamp travels in the observation through the worker outbox.
Minimum data event contract, verified on OpenCode 2.3.2 (Linux amd64,
TestLiveOpenCodeQueueManagement and TestLiveOpenCodeUsageEvents):
event.subscribelists all five data event types in itstypesenum.- Each frame is unnamed
data:JSON withtypeanddata.sessionID(ses_…). Stage reads nothing else from it. The inbox events also carrydata.inboxIDand a per-sessiondurable.seq, andsession.usage.updatedcarries cumulativecostandtokens. - OpenCode emits
session.inbox.enqueuedfor every prompt, including the launch prompt and an idle Send (deliverysteer), thensession.inbox.deliveredwhen a turn takes it. Cancel emitssession.inbox.cancelled, and promotion emitssession.inbox.delivery.changed.session.usage.updatedfollows each finished step, andSession.Infoalready reports those totals. Session.Info.time.updatedadvances on enqueue and usage but not on cancel, so it cannot stand in for these events.
Run STAGE_TEST_OPENCODE=/absolute/path/to/opencode mise run opencode:live. Include STAGE_TEST_T3 (T3 executable) and STAGE_TEST_FX (upstream scripts/mobile-behavior/fake-fx.ts) to exercise a real T3 to OpenCode to T3 tree with both predecessor services disconnected in turn.
The test starts foreground loopback servers with temporary homes, repositories and
databases. A scripted local model supplies success, failure and interruptible runs.
The standalone CLI requires Basic authentication. The suite also tests an existing
service exposed through a no-auth loopback proxy.
The verified Linux amd64 binary reported 2.3.0, SHA-256
2e0e4656521ca56e5ba16a00d48429958b8105b3fa6466710a4350e68759381f.
The source reference was df46f6931da0c934a59d375ac44525846f21c718.
TestLiveOpenCodeInteractive (the interaction gate) was added later and
verified on 2.3.2 (Linux amd64, SHA-256
e6543f6e5c39c40971ba38afd1819ac852c29ac735b5a89065d3d148d47f27ad), with
the rest of the suite: a bash permission (asked by config) answered Allow
once, the question tool's form answered, and a message sent twice with one
request ID while a turn runs, delivered once after that turn ends.
Fault injection covers every launch checkpoint, lost HTTP responses, racing Stage
retries, failed worktree setup, session identity collisions and server reconnect.
The suite also checks input requests, the web-client route and offline
acceptance. No provider account or production service is required.
STAGE_TEST_OPENCODE=/absolute/path/to/opencode mise run opencode:workflow starts a scratch Stage server and OpenCode with a local scripted model. It verifies connection setup, model selection, native MCP task and journal provenance, create-and-claim (a context preview of an external OpenCode session, a task created and claimed as that session, and the session's context naming the claimed task), a clock-driven schedule and restart recovery through the public interfaces. It requires Python 3.9 or newer.
internal/claudecode drives the claude CLI; Claude's per-user daemon owns
the sessions, worktrees, models and login (ADR 0005).
Claude Code has no HTTP API. Kind claude, local processes required, machine sessions, stable identity
(the configDirectory from claude auth status --json), launch
correlated, closure archived (claude rm). Setup (internal/claudecodesetup): the command
setting, a connect action and disconnect (api.md),
stored per machine in harness_settings with the config directory the
connection was made with; serve composes it only where the machine allows
hosted harnesses. On a worker (workersetup) it runs on that machine, with
that machine's claude, login and daemon, when the worker allows local
harnesses (the worker service, or stage worker run --local-harnesses);
its settings live on the main server's harness_settings row for that
machine (Remote machines). The resume command then has
to run on that machine.
- Running claude. Stage clears the variables a Claude or T3 process sets
for its own session (
CLAUDECODE,CLAUDE_PID,CLAUDE_AGENT_SDK_VERSION,CLAUDE_CODE_SESSION_*,CLAUDE_CODE_CHILD_*,CLAUDE_CODE_ENTRYPOINT,CLAUDE_CODE_EXECPATH,CLAUDE_CODE_MESSAGING_*,CLAUDE_JOB_DIR,CLAUDE_BG_BACKEND,T3CODE_*,T3_*) and keeps Claude's settings (CLAUDE_CONFIG_DIR, provider variables). It adds the usual tool folders toPATH: the first launch starts Claude's daemon, and every background session inherits that launch's environment. On Linux, whensystemd-run --user --scopeworks (probed once), a launch runs in its own transient scope, so the daemon it may start is not in Stage's service cgroup and outlives a Stage restart. - Launch. In the project folder:
claude --bg -n <title> [--model M] [--effort E] [--permission-mode P] [-w stage-<requestId>] [--settings <file|json>] -- <prompt>(the prompt carries the launch marker;--keeps a prompt starting with-from reading as a flag).-wfollows the launch optionworktree(boolean, default off); Claude makes the worktree from its own default base, and the per-attempt name keeps a retry from reusing an earlier attempt's worktree. Claude takes one--settings: the hooks file, which carries the image root's read rule (Images). Without hooks it is inline JSON with the read rule for images, else none. Earlier settings paths keep their original set of events and receive the current listener address when it changes. An unsupported config, an image type outside PNG, JPEG, GIF or WebP, a missing folder or executable, images without an image root, and Claude'sWorkspace not trustedrefusal areRejected(the task returns to backlog with the reason; trusting a folder is done in Claude). Exit 0 printsbackgrounded · <short>; the session list maps the short id to the session within 5 seconds. Anything else is uncertain. - Images are files Claude reads with its Read tool, kept out of the
user's repository (ADR 0007 decision 10).
Before running claude, Stage writes them to the image root,
<data dir>/claude/images/stage-<requestId>/(a worker's own data dir on a worker; the setup passes the root to the adapter and the hook receiver; folders0700, files0600, named<n>-<name>.<ext>with the name kept to[A-Za-z0-9._-]and the extension from the type). The launch's settings allowRead(//<image root>/**)(permissions.allow;//is an absolute path), so Claude reads them without a permission prompt in any mode, from the project folder or a worktree, and appendsImages attached to this task (open each with the Read tool):with one<n>. <name>: <path>line each, after the marker. No--add-dir: Claude refuses an added folder it does not trust (ADR 0005 E8). A rejected launch removes its folder; an uncertain one keeps it. Each launch with images removes image folders older than 30 days (best effort); Claude keeps what it read in the transcript. Without an image root (no data dir)imagesis unavailable with a reason. The adapter cleans up the legacy<project>/.claude/stage-imagesdirectory on launch and first workspace discovery. Cleanup removes Stage'sstage-*folders and.gitignore, then the directory if empty. - Correlate. Background sessions listed in the launch folder (or its
per-attempt worktree,
<folder>/.claude/worktrees/stage-<requestId>) and the transcripts of those folders, matched by the marker in the first prompt. Several matches are uncertain; none is not found. - Observe. One
claude agents --json --allread per tick, shared by every session of the connection (reused for 2 seconds), plus the transcript (<projectsDirectory>/<cwd with / and . as ->/<uuid>.jsonl, else any project folder). Background sessions map bystate:workingrunning,blockedneeds_input,donedone,failedfailed,stoppedinterrupted; a terminal, IDE or SDK session bystatus. Aworkingsession withstatus: idlewhose transcript shows its turn over is done: Claude keepsstate: workingwhen the agent ends its turn still waiting on something (an agent "waiting for Stage updates", seen live with Claude Code 2.1.332 in #551), and nothing runs. Not listed: idle with its reply when the transcript exists, else not found. An unreadable list is an error, never a state. - Removal closure.
claude rmdrops a session from the list and keeps its transcript; the hourly idle reap keeps the entry and its state. A session not listed whose transcript's last turn ran in the background (sessionKind: "bg") and ended (turn_duration) isclosed: archived(provenanceharness_archived; toggle "Complete tasks when removed in Claude Code"), so a done task completes (inferred completion). A terminal session leaving the list,rmmid-turn and a refusedrmare not closures. A removed session stays linkable (archivedfalse): it can be resumed. The project is the session's cwd, or its repository for a Claude worktree. The reply is the last assistant text of the current turn, bounded to 4,000 characters, shown once the session is not running; best effort.executionIdis the current turn's prompt. - Origin. An observation's
originis the entrypoint of the transcript's first typed prompt (cli,sdk-cli,t3-code, ...), raw. The adapter reports this value for Stage's wrapping check. Wrapping policy - Stop is
claude stop <short>, for background sessions only. Attention lists every session Claude lists as waiting for its user: ablockedbackground session (also one the daemon retired after an hour idle; attach wakes it) and a terminal, IDE or SDK session with statuswaiting. The attention loop filters out wrapped sessions by origin. Thesilentpolicy shows waiting rows and the needs-input count, with no Track action. A finished discovered background session stays watched untilclaude rm; the adapter reuses a parsed transcript while its size and modification time are unchanged. Links:commandisclaude attach <short>while Claude lists the background session; none for a terminal, IDE or SDK session whose process runs (it is answered where it runs: a resume would open a second client on it); elsecd <cwd> && claude --resume <uuid>. Links to resolve: a UUID or the 8-character id, also inside a pastedclaude attachor--resumecommand. - Push (ADR 0005 decision 16): the
adapter is an
execution.EventSource. The machine's hook receiver (claudecode.Hooks, opened with the first adapter, kept until shutdown) listens on127.0.0.1and writes<state dir>/hooks-settings-v1.json(<data dir>/claudeon the main server,<worker dir>/claudeon a worker; runtime.md): one Claude HTTP hook per event (Stop,StopFailure,Notification,PermissionRequest,SessionEnd,UserPromptSubmit,PostToolUse,PostToolBatch) with a bearer token. Every launch passes the file with--settings. An observation hook receives 204 and wakes Events, which reads the session list (one read taken after the hook, shared) and transcript, again after 250 ms, 500 ms, 1 s and 2 s until the list shows what the event announces (Stop, StopFailure, SessionEnd: not running; PermissionRequest, apermission_promptNotification: needs input; UserPromptSubmit: running), and pushes the last observation (one session at a time, four at once, the newest hook wins). The local runner receives it for Stage ingest. Polling covers sessions Stage did not launch, copies, sessions that wake after the listener moves, and sessions whose hooks are blocked by policy (allowedHttpHookUrls,disableAllHooks,allowManagedHooksOnly). Replacing or removing the adapter (connect, the command setting, disconnect) ends its subscription and clears pending deliveries. The setup status reportsdetails.events(api.md). - Usage from the transcript (ADR 0005
decision 17): turns are the typed user prompts on the main chain (the
current one included;
origin.kindhuman, or no origin in-pand SDK sessions), not a background subagent'stask-notificationor apeermessage, though each starts model work; tokens count every assistant message once (deduped by message id plus request id, the largest value of each channel), sidechains and<transcript without .jsonl>/subagents/*.jsonlincluded,<synthetic>messages skipped; working time sums the main chain'sturn_durationrecords (finished turns). No cost: Claude records none for a background session. None before the first turn or without a transcript. - Inventory uses the state file's project map and the exact folder paths
on Claude's current native session roster. On the owning machine, Stage
reads
~/.claude.jsonby default or.claude.jsoninside an explicitCLAUDE_CONFIG_DIR. A fresh state object can omit the project map. Managed worktrees are excluded, and machine evidence still limits automatic import to Git checkout roots. Missing or malformed state and roster failures keep the last successful inventory. See discovery.claude --bgrefuses an untrusted folder ("Workspace not trusted"), and Agent SDK runs (T3, for example) record folders without trusting them, so every row carries Claude's trust as aTrustRule: the project keys whosehasTrustDialogAcceptedis JSONtrue, matched verbatim as Claude looks them up. This mirrors Claude Code 2.1.332's background trust check. Trust is keyed on the canonical repository root (a linked worktree's main checkout), then on the nearest record from the folder up to the checkout top, or up to the filesystem root outside a checkout. Afalserecord does not stop a trusted ancestor. Untrusted rows stay listed with "Not trusted in Claude Code. Use Trust in Claude Code, or run claude in this folder once and accept the trust prompt." The home folder is trusted one interactive session at a time, so it gets its own reason unless a record above it covers it. A truthyCLAUDE_CODE_SANDBOXED(1,true,yes,on) trusts every folder. Not mirrored: Claude's fallback for a record reached through a symlinked launch path. Stage launches with the folder as the working directory, so only the real path matters. - Trust in Claude Code (ADR 0012
decision 8). Claude has no project or trust API; its documented fix is
projects["<folder>"].hasTrustDialogAccepted: truein the state file. Stage keepsclaude --bglaunches, which need it. The workspace sourcetrust(inputpath, an absolute existing folder on the adapter's machine) and the project actiontruston a row Claude does not trust share one code path; both are labelled "Trust in Claude Code", allow people and agents, and run only with the confirmation (confirmed: true, orStage-Action-Confirmed: 1for the action, which reaches the adapter asActionRequest.confirmed): "Claude Code will trust this folder. Its .claude settings, hooks and MCP servers will run in Claude sessions there." Nothing writes automatically.- Target: the folder's canonical path (symlinks resolved), the key Claude looks up. Refused: home (its trust is session-only), the filesystem root and home's ancestors (a record there trusts every folder below, home included), Claude-managed worktrees, and a missing state file.
- Existing: Claude already trusts the folder (the inventory trust rule,
settled by
machine.Opsevidence the setup injects, orCLAUDE_CODE_SANDBOXED) and the folder has its own project entry, so Claude lists it. Nothing is written. A folder trusted only through an ancestor or its main checkout gets its own record, so it is listed. - The project action is available only on a row Claude does not trust
(
FeaturesForWorkspace); otherwise "Claude Code already trusts this folder." - Safe write, mirroring Claude Code 2.1.332: Claude saves its state under
a proper-lockfile lock (the directory
<state file>.lock, touched every 5s, stale after 10s) and mergesprojectsfrom disk under it. Stage takes the same lock (a stale one is taken over; a live holder past 12s answers busy), reads the raw bytes, and patches only that key: the value, or one inserted member laid out like its neighbors (a missing entry is Claude's minimal{"hasTrustDialogAccepted": true}, the shape its runner writes). A semantic check proves nothing else changed. It writes a temp file beside the real file (through a symlinked state file), fsyncs it, keeps the file mode, and renames only if the hash, size and mtime still match the read. Three changed reads answer busy (409harness_busyfrom the add route,action_busyfrom the action); nothing was written, so a retry is safe. - The result names the folder; a person's response adds a "Trust record" fact naming the key and file.
- Features. Models: Claude's default,
opus,sonnet,haiku,fable(aliases for the latest). Harness-wide optioneffort(lowtomax) and launch optionworktree(boolean, default off; Claude starts the worktree from origin's default branch and names the branch, so there is no base ref or branch option). Permissions:manual,acceptEdits,auto,plan,dontAsk,bypassPermissions. Images and send are available.workspaceAddoffers the sourcetrust, and the project actiontrustis scoped per folder (FeaturesForWorkspacechanges only its availability; the session actionopenDesktopstays declared); both are unavailable without the machine evidence the setup injects. Unavailable with reasons: respond without the hook receiver (no state folder, or it could not open). - Follow-ups (ADR 0005 decision 18,
E12). Send reads the session list fresh (one send at a time) and
takes a message only for a listed background session that is
done,workingbut idle after its turn (as in Observe), orblockedon a finished turn (nowaitingFor, status notwaiting, the transcript's turn over). ElseBusywith what to do: working, a permission prompt or question, stopped, failed, removed or interactive (with the resume command where one helps), or a folder that is gone. A live process is stopped first (claude stop <short>), and Send waits until the list shows no pid and the process is gone; thenclaude --bg --resume <uuid> -- <text>in the session's folder, with no other flag, wakes the same session with its saved options (hooks included), and Send waits briefly for it to run. A copy (another id printed, or "started a copy") is stopped and removed and the send isBusy; a failed wake after the stop is an error (the session stays resumable). While a send delivers (at most 15 s) the session'sstoppedentry observes as running, so a blocked session stopped to wake records no interrupted. Text only, at most 32 KiB. - Steering and queueing (ADR 0014).
A background session launched with Stage's versioned settings can take
messages while its fresh roster entry shows a working turn. Stage keeps
at most eight pending messages per session, up to 32 KiB each. After a
tool runs,
PostToolUseorPostToolBatchsupplies the oldest pending steer asadditionalContextfor Claude's next model request. An eligibleStoptakes the oldest pending message, of either mode, as ablockreason. A Stop withstop_hook_activeset or an empty list passes through. Earlier launches and sessions without the version marker return Busy with the resume command. A finished turn returns Busy with guidance to Send. Session end or observed removal clears pending messages. A Stage restart loses messages still awaiting a hook. A blocked or missing receiver leaves Claude Code's own session controls available.queueManageis unavailable. The adapter has no native inbox for Stage to read, cancel or promote. Claude Code hook reference - Activity reads the transcript on the server or worker that runs Claude Code. It returns a bounded feed of messages, reasoning titles and tools, with Bash commands and file changes identified. It also returns the latest TodoWrite plan, counts from Edit and Write patches, the latest model and available permission mode, effort and worktree metadata. The Session view uses this for current and past attempts.
- Approvals and questions (ADR 0005
decision 8, E11). The push receiver (
claudecode.Hooks, above) also holds eachPermissionRequesthook naming a tool (its hook timeout is 3600 s, the others 5 s) after nudging, with its tool, input and suggestions in memory. With no receiver, respond is unavailable ("Answer in Claude Code"). A hook request stays open until the user answers in Stage, the session list shows the session no longer waiting (answered in Claude), a newer request of the session supersedes it, Claude closes it (timeout, process end) or the receiver closes; each of those answers 204 (no decision) and Claude keeps its own prompt, which the user can always answer with the resume command. Requests are memory only. Requests lists a waiting session's open hooks:AskUserQuestionas a question (every questioncustom, Claude's "Other"), any other tool as an approval titled by tool (Bash: "Run a command" with the command; Edit/Write: the file path; WebFetch: the URL; else the JSON input) with optionsallow,always:<i>for each suggestion Stage can describe (allow rules, directory access, accept edits; the label names the rule and where Claude writes it) anddeny(textOption). Respond re-reads the session list first (not waiting:ErrNotFound, the hook is released), then answers:{"behavior":"allow"}, the suggestion verbatim asupdatedPermissions,{"behavior":"deny","message": "Denied in Stage: <reason>"}(no reason: "Denied in Stage."), or for a questionallowwithupdatedInput= the tool input plusanswers({<question>: <labels joined by ", ">}). A late answer on a hook Claude already settled is ignored by Claude. - Claude Desktop (ADR 0005
decision 19). Where Claude Desktop can exist (macOS, x64 or Arm Windows,
x64 or Arm Linux, with the adapter's state folder,
<StateDir>/desktop), the adapter declares the fixed launch optioncontinueIn(choice "Continue in":cli"Claude Code CLI" ordesktop"Claude Desktop", with a note ondesktopthat Claude Code can't start a Desktop session, so Stage starts it in the CLI and moves it after the first turn). Desktop is the default once handoff is ready: the machine check passes (CheckDesktopHost),authMethodclaude.ai, and Claude Code 2.1.285 or later (2.1.334 on Arm Windows, 2.1.335 on Linux). The machine check: on macOSClaude.appin/Applicationsor~/Applications; on Windows%LOCALAPPDATA%\AnthropicClaude\claude.exeor a registeredclaude://protocol; on Linux what Claude Code itself requires: no/.dockerenv, noSSH_CONNECTION/SSH_CLIENT/SSH_TTY, a registeredclaude://handler (xdg-mime query default x-scheme-handler/claudefrom the system folders, exit 0 and a non-empty answer), andDISPLAYorWAYLAND_DISPLAYin the CLI's environment. A user service usually starts before the graphical session exports those to the systemd user manager, so when the CLI's environment has neither, the adapter readssystemctl --user show-environment(read-only) and, where the manager has a display, passes itsDISPLAY,WAYLAND_DISPLAY,XAUTHORITY,XDG_SESSION_TYPE,XDG_CURRENT_DESKTOPandDBUS_SESSION_BUS_ADDRESS(those the CLI's environment lacks) to the handler query and toclaude --desktop. The check is cached 5 minutes. Otherwise the default isclianddesktopis unavailable with the first unmet reason ("Not available in Docker.", "Not available over SSH.", "Not installed where Claude Code runs.", "Needs a graphical desktop session where Claude Code runs.", "Needs a claude.ai login.", "Needs Claude Code 2.1.335 or later." with the platform's version). An omitted option takes the default on every launch path (agents, schedules, pins). The user session actionopenDesktop("Open in Claude Desktop", no declared confirm; a session whose turn it would interrupt adds one, below) is declared only once ready. Elsewhere neither exists andValidateConfigrejectsdesktop. The checks run where the adapter runs, a worker's own machine for a worker connection, and the Claude Code setup status shows them as the fact "Claude Desktop" ("Available" or the reason), whichstage harness claudeprints asdesktop. The CLI can't start a Desktop session with a prompt, so adesktoplaunch is the usual background launch plus apending-<uuid>marker (also after Correlate). When an observation (Observe or a hook push) shows a pending session's turn over, the adapter hands it off once, in the background: a live process is stopped (claude stop, as Send does: Claude doesn't move a session still running in the background), thenclaude --desktop --resume <uuid>runs in its folder; success needs exit 0 and "Opening session" in the output. Success leavesopen-<uuid>, failurefailed-<uuid>with the reason, never retried automatically (the user action can retry). The observation carries the factcontinueIn("Continue in": "Claude Desktop after this turn", "Moving to Claude Desktop", "Claude Desktop", or a warning "Couldn't open in Claude Desktop: "). The automatic handoff never interrupts a turn: it waits while a background turn runs or waits on a prompt Stage doesn't hold. Park: a first turn that stops on a prompt never ends, so when an observation shows a pending sessionblockedon a prompt whose PermissionRequest hook Stage holds, the adapter parks it once: it checks a fresh session list still shows it waiting, writesparked-<uuid>(the park time), and answers the hook{"behavior":"deny","message":<park message>}, which tells the model to end its turn at once with a short reply restating the question or the action it needs approved. The hook registers before its nudge, so the read the hook wakes sees it. A prompt answered first (in Stage, or in Claude: the list no longer shows it waiting) is not parked and the marker stayspending. While parked the session readsrunninguntil Claude takes the denial (a blocked state with no held prompt), the parked request is never listed, and the turn's end (oftenblocked,idle, nowaitingFor: a reply that asks, ADR 0005 E13) runs the handoff above. If Claude asks again, that prompt stays answerable in Stage and Claude, the marker's time is cleared (no timeout), and the session moves once that turn ends (or the action moves it now, below); a session parks only once. A park whose turn hasn't ended after 2 minutes becomesfailed-<uuid>("Claude didn't end its turn when asked. Open in Claude Desktop now interrupts it."). Without a held prompt (Stage restarted, an adopted or tracked session, hooks off) or in a terminal session nothing is parked. The action (one at a time per session, with the handoff and park) works on any listed Claude session at any time, except a terminal or other app's ("This Claude session runs in a terminal or another app.") and a parked one while Claude still takes the denial (Busy: "Moving to Claude Desktop once Claude ends its turn."). On a session whose turn is over it runs the same handoff, with no confirm, and recordsopen-<uuid>; on an open session it reopens it. On a session waiting on a held prompt (never parked) it recordspending, parks it and answers "Moving to Claude Desktop. Claude ends its turn and restates what it needs; answer it there." (or, answered first, "The prompt was answered first. The session moves to Claude Desktop when the turn ends."). Move now: on a background session that works, waits on a prompt Stage doesn't hold, or asked again after its park, it interrupts: the observation's action state is available withconfirm("Claude is mid-turn. Opening it in Claude Desktop stops the turn now, like Esc: the running tool call or open prompt is dropped. Reply in Claude Desktop to continue."), so Stage requiresStage-Action-Confirmed(and the adapter refusesInvalidwithout it). Confirmed, it runsclaude stop, waits until the process is gone (as Send does), drops queued deliveries, runsclaude --desktop --resume <uuid>and recordsopen-<uuid>("Interrupted the turn and opened in Claude Desktop. Reply there to continue; Stage keeps following it."). The session then readsinterrupted, as after Stop; nothing can send "continue" into Desktop, so the user's reply there continues it. A failed stop moves and records nothing ("Couldn't stop the turn: …"). A failure after the stop leaves the session stopped and resumable:failed-<uuid>with the reason, theclaude attachcommand kept, 409operation_unavailable("Stopped the turn, but Claude Desktop didn't open: . The session is stopped; use Open in Claude Desktop to try again."), and the retry, its turn now over, needs no confirm. Once open, Linkscommandisclaude --desktop --resume <uuid>, and the observation reports send, steer and queue unavailable ("This session continues in Claude Desktop; reply there."), so the composer reads only before anyone types; Send returns the sameBusyas the backstop. Stage keeps observing the session list and transcript. While the session is moving (parked, a handoff or Move now running, or pending with its first turn over so the handoff starts now) the observation reports them unavailable with "Moving to Claude Desktop. Reply there once it opens.", and Send, steer and queue return thatBusy: a message would race the handoff. A pending session whose first turn still runs takes steer and queue as before (a queued message only delays the handoff until it is delivered), and a failed handoff stays in the CLI and takes messages. - Health is
claude auth status --json, reused for 30 seconds: unavailable when logged out or when Claude reports another config directory than the connection's. - Attribution. Agents read
CLAUDE_CODE_SESSION_ID. Its precedence owns a background session (CLAUDE_CODE_SESSION_KIND=bg, which may carry a stale wrapper variable from the daemon). Itsoriginvariable isCLAUDE_CODE_ENTRYPOINT: inside a Claude process a wrapping harness runs (its variable set, or the entrypoint one of itswrapsorigins) the wrapper's variable names the caller.
Tests: parser tests on the captured fixtures (claudecode/testdata,
including hooks/), the hook receiver and requests with the fake sending
hooks as Claude does (claudetest Ask), the adapter and setup against a
fake claude CLI (claudecode/claudetest, a
real executable with a state file), and TestContractClaude* in
internal/engine with the real adapter in process and behind a worker
channel. STAGE_TEST_CLAUDE=/absolute/path/to/claude mise run claude:live
runs the adapter against the real CLI with your login and haiku: it marks
two scratch folders trusted in Claude's state file, launches a reply,
sends it a follow-up from Stage (same session, no copy, the new reply),
then removes it with claude rm and checks the closure, an image it must name
the color of (manual permissions, no prompt), a permission prompt it allows
from Stage through the hook, another it stops,
a worktree session (launch option worktree), then removes the sessions
newest first (claude rm; when Claude keeps a worktree for its commit,
it deletes the scratch worktrees and retries) and purges the folders
(claude purge). Claude
processes rewrite the state file, so a trust entry removed by hand can come
back; the purge is what removes them.
internal/codex drives the Codex app-server daemon over WebSocket on its
unix control socket; internal/codexsetup is its connection setup. Design
and live gate evidence: ADR 0006.
Codex owns threads, models, login and project trust. Stage stores no Codex
credentials and never edits Codex's files; it changes Codex's config only
through the app server, when a person or agent trusts a folder
(ADR 0012). On a worker (workersetup) the
setup runs on that machine, with that machine's codex, login and daemon,
when the worker allows local harnesses; its settings live on the main
server's harness_settings row for that machine
(Remote machines), and the resume command runs there.
-
Client. One connection per adapter, opened lazily. When the daemon is down the client runs
daemon start(at most once per 30 s), else reports the daemon down. Every failure isexecution.ErrUnavailablewith the problem; an unknown method names the method and asks for a Codex update. -
Inventory. Workspaces are the projects Codex trusts (
config/read), local to the machine; a directory inside a Git checkout is importable (the machine's ops decide,ImportInCheckout; trust a project in Codex to list it). No launch options: a session runs in the project checkout. -
Workspace add. One source,
trust("Trust folder"): an absolutepathon the Codex host and the confirmation "Codex will trust this folder: it applies the folder's Codex project config. This also applies to the Codex CLI." The adapter cleans the path and requiresfs/getMetadatato report a directory. A folderconfig/readalready trusts isexisting. Otherwiseconfig/batchWriteupserts key pathprojectswith{<path>: {trust_level: "trusted"}}: the path stays one key (an unquotedprojects.<path>.trust_levelkey path splits on dots), and other projects and fields are kept. A prioruntrustedentry becomes trusted. The write sends the user layer'sexpectedVersionand retries once onconfigVersionConflict.configLayerReadonlyandconfigValidationErrorare invalid input with Codex's message;okOverriddenadds a warn fact; a lost reply isOutcomeUncertain. Stage re-readsconfig/read: a folder a higher layer keeps untrusted is invalid input naming the override. Codex's experimentalproject/*API (create, import, list) is a future option; Stage does not use it. -
Folder browsing.
directoryBrowselists a folder withfs/readDirectory {path}(read only; checked on a throwaway 0.172.0 app server). The default start is the host user's home: the daemon serves a local socket and runs as the adapter's user. Codex returns entry names with their resolved kind (a symlink to a folder is a folder; a broken one is left out). A missing folder, a file or an unreadable folder is invalid input with Codex's OS error. A daemon without the method declares Browse unavailable: "This Codex version cannot list folders (fs/readDirectory is missing). Type the path." -
Launch (
reserved). Validation rejects before any effect (an unknown option such asworktree, missing directory, non-image attachment, invalid option or permission).thread/start, checkpoint the thread id, best-effortthread/name/set, thenturn/startwithclientUserMessageIdset to the request id. Replay reads the checkpointed thread: a first turn carrying the client id (or the prompt) is the admission, no turn starts it, a first turn whose user message is not recorded yet stays uncertain, any other turn fails. Stage then unsubscribes; the turn keeps running. For a moment afterturn/startCodex answersthread/turns/listwith -32601 "list_turns is not supported yet", then may show the turn in progress on a thread it reports not running (codex-cli 0.172.0, live in #551): the launch's observation retries both for up to 10 s, so a started launch is confirmed instead of failing into a replay. -
Observation.
thread/read:activeis running or needs_input (the waiting flags); the last turn's outcome is done, failed or interrupted; an in-progress turn on a thread the daemon unloaded, or a system error, has no terminal evidence and is an error. For a moment after everyturn/startand unsubscribe (launch and send) Codex reports the threadidleand lists the new turn in progress orinterruptedwithoutcompletedAt; a real interrupt hascompletedAt(codex-cli 0.172.0, live in #555, gate g11). Observe rereads such a snapshot for up to 500 ms; an unclosed interrupt that persists reads interrupted. Archive closes the session (archivedclosure). The reply is the final answer, 4,000 characters. -
Archive. Archive in Codex relays
thread/archive(Actions and facts); unavailable once archived. -
Push.
execution.EventSource: the daemon broadcasts thread status, archive and turn completion for every thread. Stage reads each thread and passes the observation to the local runner.Attentionlists loaded threads waiting on input. -
Interaction (
execution.Interactive). The runner passes tracked sessions toTrackedEventSourceon the adapter's machine. On Codex 0.172 or later it subscribes to a tracked thread with an active turn (running or waiting) usingthread/resume {threadId, excludeTurns: true}. This attaches to the existing turn and replays its pending requests with their daemon-wide JSON-RPC IDs. Stage passes no configuration overrides and starts no turn. It unsubscribes when the thread is idle and reattaches to active threads after a connection drop.- Requests. Command, file-change and permission approvals are
held in memory on the subscription by thread and JSON-RPC ID.
serverRequest/resolvedremoves a request, including when a Codex client answered first. Turn completion and connection loss clear their pending approvals. The command preview shows the exact command, working directory and reason when present. Stage offers Codex'savailableDecisionsin order. The plain decisions areaccept,acceptForSession,declineandcancel. TheacceptWithExecpolicyAmendmentandapplyNetworkPolicyAmendmentdecisions carry Codex's proposed rules. File changes show paths and counts when matching file item metadata arrives, or direct the user to the resume command to review the diff. Permission requests show the requested profile with turn, session and denial choices. - Respond. Stage sends the result on the subscribed connection.
Command and file approvals take
{decision}. Permission approvals take{permissions, scope}, with an empty permission profile for denial. An invalid option is*Invalid. An absent request isErrNotFound. Stage leaves experimental questions, MCP elicitations and other server requests for the Codex client. The legacyapplyPatchApprovalandexecCommandApprovalmethods are outside the v2 event path Stage uses. - Send. Stage checks for an idle thread with a finished turn,
reuses its held subscription or resumes it, then rechecks the
thread immediately before
turn/start. A running turn is*Busy("Codex is working. Steer instead."). An archived thread is*Refused(409session_refused) with Codex's unarchive command. Stage passes the request ID asclientUserMessageIdand reconciles a retry against the newest finished turn's user messages. The coordinator assigns a fresh ID per API call. Codex 0.172 accepts repeated native IDs and has no atomic idle precondition forturn/start. If another Codex client starts a turn between the final read and the write, the daemon can accept the input in that turn. - Steer. Stage reads the thread's status and its newest turn ID
with
thread/readandthread/turns/list(no turn items), then passesexpectedTurnIdandclientUserMessageIdto stableturn/steer. Reviews and compactions report busy with guidance to wait. An ended or replaced turn reports busy with guidance to send. - Queue and queue management. Codex keeps its message queue in
the daemon, but
thread/queue/*(add, list, update, delete, reorder, start) requires theexperimentalApicapability as of 0.172, and ADR 0014 excludes experimental APIs. Queue declares “Codex's queue API is experimental, so Stage cannot queue messages yet.” Queue management declares “Codex's queue API is experimental, so Stage cannot list or manage queued messages yet.” See the ADR 0014 follow-up for native behavior and races. - Availability. Stage checks the methods needed by Send, Steer and Activity per daemon connection without targeting a thread. The live gate verifies Codex 0.172.
Links carry
command(cd <dir> && codex resume <id>), which task rows, notifications and task detail offer as Copy resume command. - Requests. Command, file-change and permission approvals are
held in memory on the subscription by thread and JSON-RPC ID.
-
Activity (
execution.ActivityReader).thread/items/listreads the newest page, including for read-only attempts. Stage displays supported items oldest first: user and Codex messages, reasoning summary titles, command previews with status and exit code, file paths, MCP tools and plans. Only completed file edits contribute to file totals. The latest plan item in the page supplies the checklist or proposed plan text. Codex's live plan updates and token usage are outside this view.thread/readsupplies the model and reasoning effort. Effective approval policy and sandbox come from the resumed thread when loaded. Unloaded and archived threads can return history without resuming. -
References.
ResolveLinktakes a thread id or acodex resumecommand and refuses ephemeral and subagent threads. An observation'soriginis the thread's originator, raw; the coordinator refuses a thread another harness wraps (T3'sT3 Code: Stage follows it through T3). -
Attribution. Agents read
CODEX_THREAD_ID. Codex declares anorigin(no variable): inside a Codex process a wrapping harness runs, the wrapper's variable names the caller.
The fake daemon (codex/codextest) speaks the same subset over a temp
socket; internal/engine/contract_codex_test.go runs the execution
contract on it in both placements, and codex/testdata holds sanitized
fixtures from the live gates. The fake also resumes threads (replaying
their pending server requests), takes client replies to server requests
and broadcasts serverRequest/resolved to subscribers. mise run codex:live
launches a read-only scratch thread, steers it, answers a replayed approval,
sends to the idle thread, and verifies native activity and retry behavior.
The raw protocol gates run
with STAGE_CODEX_GATES=1 go test -tags codexlive -run TestLiveGate ./internal/codex/. These gates use the signed-in account and delete their
scratch threads afterwards.