Files
orca/docs/reference/remote-wire-compatibility.md
T
Brennan Benson fd9125ea8c feat(native-chat): Codex structured native chat restructure (#16729)
* feat(native-chat): port structured Codex sessions from restructure-recovery

Rebuilds the desktop structured native-chat implementation from
brennanb2025/native-chat-restructure-recovery (tip 4e31c08db3) on top of
current main as a single commit, scoped to the local Codex path.

Ported:
- Structured agent-session core: durable record store + single-writer lease,
  canonical journal, agent-session wire host/attach/eviction/subscribers,
  `agentSession.*` RPC surface (registered via ALL_RPC_METHODS; host-side
  mobile allowlist included for wire compat), pty write gate, transcript
  additions, and the Codex app-server adapter/launch resolution.
- Renderer: NativeChatStructuredSession view/composer stack, structured
  launch path with the single-flight guard, local structured session tabs
  sync, activation gate + structured inventory (read-only
  `agentSession.handoffStatus` probe), agent-session tabs in the tab strip,
  AI-vault structured session activation, and the settings pane with the
  parent Experimental Chat UI toggle plus the nested "Use updated structured
  native chat" toggle. New sessions require both flags, agent codex, no
  prompt, and a local non-WSL, non-Windows-host execution host
  (structured-native-chat-availability).
- Fixes 72c013cea6 (verified Codex launch recovery), 8ddbaf5e3d (defer
  native terminal view switching affordances), and 4e31c08db3 (release the
  launch gate after a visibility retry) with their regression tests,
  including the third-launch-after-retry guard case.
- Cross-version agent-session wire test + CI lane, packaging entries
  (proper-lockfile, agent-tooling asar excludes), and the wire-compat doc
  section.

Deliberately not ported: mobile/ changes, the Claude structured runtime
(only the claude-transcript-branch-proof and claude-structured-owner-identity
leaf modules remain, backing the kept TUI-recovery arms), the terminal↔chat
adoption/handoff flow (`agentSession.adoptTerminal`/`requestHandoff`, the
handoff request engine, TUI adoption machinery, orca-runtime adoption
methods), renderer switching affordances and their dead leftovers, the
hook/subagent-status refactor cluster, and unrelated branch changes. The
crash-during-acquisition recovery path (restart handoff adjudication,
restore/reverse re-acquire, lease schema handoff keys) is kept because every
plain direct launch depends on it; a trimmed handoff coordinator exposes
only status/restore/close.

Branch edits that targeted files main has since split (ipc/pty.ts,
worktrees.ts, rpc/methods/terminal.ts, useIpcEvents, pty-connection,
store/slices/terminals.ts, runtime-types, web preload) were re-applied to
the split modules, preserving main's newer logic (Windows CIM fallback,
browser tab close rework, cold-restore resume flow, dispatcher threading).

Known seam: the mobile clipboard image-provenance CONSUMER gate ships
(agentSession.send refuses unproven mobile image refs with
agent_session_image_untrusted) but the producer hunk in
rpc/methods/clipboard.ts stays with the unported mobile cluster, so mobile
image sends into structured chat fail closed until that side ports.

* fix(native-chat): trust only authenticated local image uploads

* fix(build): preserve Windows process-tree patch application

* test(windows): include process creation time in addon fixture

* fix(build): run windows-process-tree node-gyp from the physical package dir

gyp expands the node-addon-api dependency by probing node, whose cwd
resolves to the package's physical directory in the store, so the emitted
target is a store-relative ../../../../node-addon-api@... hop. gyp then
resolves that hop against the rebuild cwd; from the node_modules
symlink/junction it escapes the store and configure fails with
"node_addon_api.gyp not found" (run 32999886072).

Rebuild from realpath(package dir) so both bases agree, matching how the
package manager itself runs native install scripts. The regression test
replays gyp's expansion+resolution against the planned cwd and fails
without the fix.

* fix(native-chat): keep chat tabs visible through terminal closes and empty-worktree launches

Two proven blockers in the native Codex tab contract:

closeTerminalTab pre-empted the canonical unified close. With one terminal
left it deactivated the worktree on a terminal/editor/browser-only check,
blanking a workspace that still held a renderable agent-session tab; with
two or more it pre-picked a successor from terminal entities only,
re-stamping the group active before closeUnifiedTab's MRU/neighbor repair
could land on the chat tab. Successor choice now defers to the unified
contract whenever the terminal has a unified row, and deactivation is
gated on the unified renderable count (matching leaveWorktreeIfEmpty),
with the legacy pre-pick kept only for terminals without a unified row.

A structured session created on an empty worktree was published into the
host's headless group while preserveLocalLayout froze the local layout,
leaving the tab in store but permanently off screen. A preserveLocalLayout
owner now always takes client-owned placement — repairing a rendered
leaf whose group record is missing, or materializing a rendered group on a
truly empty worktree — and applies the client-derived layout repair while
still rejecting host-authored layout.

Regression tests drive the real store through closeTerminalTab (git
worktree and folder workspace) and the real snapshot applier for the
empty-worktree adoption states; all fail without the fixes.

* fix(native-chat): close stale turns and retry rejected sends

* fix(native-chat): retire hosted rows on structured tab activation

* fix(native-chat): preserve rpc defaults across main merge

* chore: format remote wire compatibility guide

* test(native-chat): cover retry after unconfirmed send

* fix(native-chat): reload outbox on session switch

* docs(settings): disclose structured chat platform limits

* fix(native-chat): await Codex launch-home preparation

* fix(codex): align child-process allowlist with async trust bridge

* test(identity): update inventory for tab surface refactor

* fix(windows): preserve process-tree CRLF patch sources

* fix(native-chat): anchor an unmatched chat echo where it was sent (#16117)

* fix(native-chat): anchor an unmatched chat echo where it was sent

The reported symptom was old user messages replaying below every new turn, so the
conversation read as scrambled. The cause was not that the echo failed to match a
transcript row. Claude consumes a mid-turn send through a `queued_command`
attachment and writes no `type:"user"` record for it, so some echoes can never
match, and no amount of matching will change that. The cause was WHERE an
unmatched echo rendered: buildMobileNativeChatTransientData appended every pending
item after the entire transcript, so it re-read below each turn that landed
afterwards.

Render each echo directly after the transcript row it was sent against, using the
baseline the send already captures. An unmatched echo is then at worst a duplicate
in the right position rather than a scrambled one, and it stays visible. Echoes
sharing an anchor keep send order; a send with no baseline, or one whose anchor
folding dropped, still falls back to the tail.

Deliberately NOT fixed by deleting the echo. Inferring from send ordering that an
echo can never match, then removing it, loses the user's own text for a message
the agent did receive, and it cannot fire in the common case anyway - measured
drain groups are 1,017 of size 1 against 55 larger. It also escalates an existing
gap: the count pass has no baseline-tail guard, unlike the glue pass, while
`messages` is a 40-row window that head-trims, resets on reconnect and grows at
the front on loadEarlier, so a false landing there would license deleting a
DIFFERENT outstanding message.

That count-pass gap is real and left for a separate change; anchoring makes its
worst case a duplicate in place rather than a scrambled conversation.

* fix(native-chat): preserve folded echo anchors

* fix(native-chat): preserve forward-folded echo anchors

* fix(native-chat): keep leading folded echoes in place

* fix(workspace-cleanup): show git status for every row (#16690)

* fix(native-chat): refuse structured chat on every Windows execution path

canUseStructuredNativeChat only refused win32 when a project runtime
resolved, so folder-workspace keys (and other keys with no project
runtime) failed open into structured chat on Windows. Fail closed on
win32 unconditionally after the host check, matching the settings copy:
local macOS/Linux only; Windows/WSL/SSH stay on terminal chat.

* fix(native-chat): restore runtime refusals behind the win32 gate

506d375de3 replaced the project-runtime checks with a bare platform test,
so a WSL or repair-required runtime resolution would no longer refuse
structured chat off-win32. Keep the unconditional win32 refusal and
re-run the runtime resolution after it, so the gate does not depend on
the resolver's own platform guard. Tests inject WSL and repair-required
resolutions on darwin/linux and fail against the regressed gate.

* fix structured session journal durability

* fix structured tab active pointer after restart

* fix(native-chat): await optional lease renewal callbacks

* refactor(skills): extract install error messages

* fix(agent-session): harden recovery ownership

* fix(native-chat): retain panes across tab activation

* fix(native-chat): address round-one review findings

* test(native-chat): align integration coverage after main merge

* fix(native-chat): harden round-two reliability

* fix(native-chat): harden round-three reliability

* fix(native-chat): close round-four recovery gaps

* fix(native-chat): separate bounded journal key forms

* fix(native-chat): reset outbox error in render on session switch

The switch effect adjusted error state after the sessionId prop changed,
tripping react-doctor's no-adjust-state-on-prop-change on the changed-code
gate and flashing the old session's banner for a frame. Reset it with the
render-time previous-value guard instead.

* fix(native-chat): invalidate stale outbox settlements

* test(native-chat): restore settled-error session-switch regression

a6e2379bd1 replaced this test with the in-flight settlement race test,
leaving the render-time error reset unpinned: deleting the reset block
still passed the whole native-chat suite. Keep both scenarios pinned;
they are distinct (settled error clears on switch vs stale settlement
invalidated in the commit-to-passive window).

* test(wire): make release checkouts race safe

* test(wire): pin cross-process checkout single-flight and importer specifier contract

* test(wire): harden release checkout lifecycle

* fix(build): drop CR-byte residue from windows-process-tree patch

The two trailing CR bytes on the patch's deletion lines are a proven
no-op: pnpm hashes patches CRLF-normalized (both forms hash to the
lockfile's 946ffb2b) and materializes this package without applying the
patch in either form, so the load-bearing build edits come solely from
applyWindowsProcessTreeBuildFixes() (#16947), which handles both source
EOL forms. Restore byte-identity with main and repin the contract test
to the post-#16947 reality: LF-only patch bytes plus lockfile hash sync.

* fix(native-chat): skip empty startup recovery
2026-08-28 16:45:58 -07:00

12 KiB

Remote wire compatibility

Orca's remote-server feature pairs a desktop client to a remote Orca runtime, and users update the two independently. Mixed versions are the normal state, not an edge case. This page is the contract for changing anything a paired client and host exchange: the runtime RPC envelope, the terminal binary stream, and the content either side publishes over them.

src/shared/protocol-version.ts says when to bump RUNTIME_PROTOCOL_VERSION. This page covers the changes that do not bump it and are therefore easy to get wrong.

Rule 1 — a new optional JSON field on an existing frame is safe

Every JSON payload is parsed with a decoder that ignores unknown keys (zod .strip() on RPC params, JSON.parse on stream frames). An older peer that has never heard of the field simply does not read it.

Safe:

// host adds a field; older clients ignore it
encodeTerminalStreamJson({ kind, cols, rows, hiddenOutputReason })

The field is safe only for as long as every reader treats it as optional. The moment a newer client requires it, that client is broken against every host that predates the field — which is the same defect as removing a field, just discovered later. If new behavior depends on the field being present, that is Rule 2: negotiate it, or make the reader fall back.

Rule 2 — a new stream opcode is NOT safe; negotiate it

decodeTerminalStreamFrame returns null for an opcode it does not know, and runtime-rpc.ts drops that frame without an error:

const frame = decodeTerminalStreamFrame(bytes)
if (!frame) {
  return // silently dropped — the sender never learns
}

So a new opcode sent to an older peer does not fail loudly. It vanishes, and the feature behind it appears to hang. Input sent under a new opcode is swallowed.

A new opcode must be announced in the subscribe handshake and sent only after the peer confirms it. The existing pattern is SetOutputPaused (opcode 16):

  • the client advertises support in the Subscribe frame's capabilities;
  • the host echoes capabilities: { outputPause: 1 } on the subscribed event;
  • the client sends opcode 16 only after that echo (stream.supportsOutputPause);
  • the host only acts on opcode 16 when it negotiated it (stream.supportsOutputPause).

Reuse an existing opcode with a new optional payload field (Rule 1) whenever that expresses the change; reach for a new opcode only when framing genuinely differs.

Opcode numbers are permanent. See the Ack = 13 and ClaimViewport = 14 comments in src/shared/terminal-stream-protocol.ts for why a shipped number cannot be reused even if the feature behind it is removed.

Rule 3 — changing what the host publishes breaks old clients with no wire change

The frame shape can be untouched and the skew still real, because clients react to frame content. PR #12641 is the worked example: the host stopped synthesizing a finished agent status, and clients running older code saw different content in an identical frame.

Treat these as wire changes even though nothing in the codec moves:

  • a field the host stops populating (an old client reading it now sees undefined);
  • a value whose meaning, units, or nullability changes;
  • content the host stops synthesizing, trims, or starts deriving from a new source;
  • a frame the host stops sending, or starts sending, on an existing path.

If old clients cannot interpret the new projection correctly, gate it behind a runtime capability the same way Rule 2 gates an opcode.

Enforcement

tests/e2e/cross-version-wire/cross-version-terminal-wire.unit.test.ts runs the real host RPC methods and the real renderer multiplexer from two builds against each other — current working tree against the newest release tag, in both skew directions — over one scripted terminal journey (subscribe, input, hide/reveal snapshot, drop, reconnect).

Run it with:

pnpm exec vitest run --config config/vitest.config.ts tests/e2e/cross-version-wire/cross-version-terminal-wire.unit.test.ts

It fails when a frame is refused by the receiving build's decoder (Rule 2), when the observed frame sequence changes (Rule 3), or when published snapshot content or negotiated capabilities differ from the contract. Adding an optional field keeps it green (Rule 1); making a client depend on that field turns the new-client/old-host pairing red.

tests/e2e/cross-version-wire/cross-version-agent-session-wire.unit.test.ts pairs the same two builds over the structured agentSession.* surface. Because a released build cannot name a capability string its own source never contains, the old side's advertised list and registered method names are read from the extracted checkout rather than hand-written. It covers the three skews that surface can fail on:

  • an old client — advertising only what the baseline build defines — is told the whole surface does not exist and reaches no host method;
  • a new client against the old dispatcher gets method_not_found on every method, and can see the absence during negotiation instead of by calling;
  • a cursor survives a host restart: the client's fence is refused as stale with the live one attached, and resuming from the held cursor replays only what it missed.

Run it with:

pnpm exec vitest run --config config/vitest.config.ts tests/e2e/cross-version-wire/cross-version-agent-session-wire.unit.test.ts

The harness covers the terminal stream and the structured agent-session surface. It does not cover the session-tab sync channel, legacy agent-session publications, file or Git RPCs, mobile/E2EE framing, or the relay transport. A change on those paths still needs its own reasoning against the three rules above.

Worked example: agentWait on terminal and worker reads

terminal.show, orchestration.workerShow and orchestration.federationShow carry an optional agentWait naming a pane parked on a prompt only a human can answer. It is Rule 1 — a new optional field — but it has a second state that Rule 1 alone does not describe, and getting that wrong turns a skew into a false "nothing is blocked".

  • present object — this pane is waiting, with the evidence that proved it.
  • present null — the host evaluated this pane and nothing proves a wait.
  • absent — the host never evaluated it: it predates the field, the worker identity was unverifiable, the pane was unreadable, or the agent probe did not answer in time.

A new client against an old host sees the field absent, which is why absence must read as unknown and never as not waiting. Collapsing absent into null at any hop — including a convenience ?? null in an RPC handler — makes an old or unreachable peer indistinguishable from a healthy idle worker, which is the exact failure the field exists to remove.

An old client against a new host ignores the key, as Rule 1 allows. New members added to RuntimeTerminalWaitBlockedReason are also Rule 1: no consumer switches exhaustively on it, and both the CLI and worker-start interpolate it as an opaque string.

Known debt: JSON-RPC errors drop Node's string code

An error raised on an SSH host crosses the relay as JSON-RPC, and ssh-channel-multiplexer rebuilds it with the TRANSPORT's numeric code. Node's string code — 'ENOENT', 'EACCES' — does not survive, so a caller on this side cannot ask what kind of failure it was.

isENOENT in src/main/ipc/filesystem-path-containment.ts pays for that by also matching Node's canonical message text, which is what makes remote worktree creation work. The cost is that a host can make an unrelated failure read as "absent" by putting that sentence in a message.

The exit is Rule 1: carry the original string code in a new optional field on the error payload and read that instead. An old host omits it and the message match still covers them; once hosts that send it are the floor, the message match can be deleted rather than lived with at its ~10 call sites. Narrowing isENOENT back to .code without doing this reinstates the bug — the transport has already overwritten it.

Known hazard: clients ignore host-published failure fields on client-placed pages

RuntimeMobileSessionBrowserTab — the browser tab a host publishes on the session-tab sync channel — permits placement, loadError and certificateFailure together. But for a tab whose placement.kind is 'client' the engine runs in the client's own app: the failure is raised by the local guest webview, and the host has no view of it (RuntimeBrowserClientPage, what the registry actually publishes from, carries neither field). Clients from this version on therefore refuse host ownership of both records for client-placed pages (web-session-tabs-sync.ts, the placement?.kind !== 'client' carve-outs) — without that, each metadata snapshot deletes the locally recorded failure and the page's failure overlay disappears mid-navigation.

The hazard is forward-facing and Rule 3 shaped. A host that later starts publishing loadError or certificateFailure for a client-placed page reaches these clients as content they silently drop, so the host would see no error and no effect. Publishing it has to be capability-gated, with the carve-out narrowed to clients that did not negotiate the capability. Note the cross-version harness does not exercise the session-tab sync channel, so nothing fails if this is forgotten — this note is the only record.

A related carve-out covers title, url, loading, canGoBack and canGoForward (resolveMirroredBrowserPageContent), and for those the hazard is already live rather than forward-facing: the host does publish them, from a RuntimeBrowserClientPage it can only learn about second-hand through the client's own browser.clientHost.pageMetadata calls. Its copy therefore starts at the registry defaults ('Browser', the create-time url), and while those publishes are failing it never leaves them.

That copy is not simply behind, though, and a client must not treat it as such. When a lease reattaches, the host refreshes the page from the client host's own inventory (runtime-browser-client-page-recovery.ts), which reads the live guest — so it can be strictly fresher than a local row whose pane is unmounted and whose metadata publisher was disposed with it. A client that ignores the host url is relying on its own guest to re-answer on remount, which ClientHostedBrowserPagePane's mount-time syncNavigation is what makes true.

These five are therefore refused only by the client whose guest actually runs the page: placement.browserHostClientId is compared against this client's own host id (readBrowserClientHostId). Main stamps that id into the guest-hosting window's additionalArguments at creation, and the preload reads it back out of its own argv — the answer has to be there before the first snapshot is interpreted, which is earlier than any IPC handler a renderer could wait on. Every other viewer — a second desktop, the web client, which installs no page renderer at all, the dashboard pop-out, which is deliberately left unstamped — keeps tracking the host, which is the only reason a mirrored viewer shows anything but its first snapshot forever. Improving what a second client sees still means fixing the publish, not the carve-out; the carve-out no longer stands in the way of it.

The two failure fields above are deliberately left on the looser placement?.kind !== 'client' predicate. It is unobservable today — the host publishes neither field for a client-placed page at all, so a mirror has nothing to take either way. If the capability-gated publish this section anticipates ever lands, narrow them the same way rather than by placement kind: a mirror should take a failure it cannot otherwise see, and only the hosting client should refuse it.