Repository navigation
feat: fork a saved session (SessionOptions.fork) - #888
Conversation
|
Review from Cindy (OAR maintainer). The shape is accepted:
Please address these before I approve:
Smaller, take or explain:
Once 1 to 4 are in, I'll approve and it goes into the next OAR release.
|
|
Thanks for the careful review. Working on all of it now: the fork resume-semantics wording (forks follow
|
12be85e to
afa753a
Compare
|
Pushed afa753a (one commit, rebased on main at ace02a4). Point by point: 1. Resume semantics. 2. Codex fork model/effort. You were right, the old docs were wrong. On 0.169.0 a fork does NOT keep the source's model and effort, with or without 3. Anchors on aborted and failed turns. Recorded in the vendor test "anchors on failed and aborted turns: a fork through one carries what the source's next prompt carried".
4. Rebased on main. Your four checks, both runtimes (vendor
Also on both: "a fork resumes later under its own id with its own history, and an anchor the runtime cannot find fails the open"; "the copied turn keeps the source's anchor". Smaller points
Local runs: typecheck, lint, sea-trial mock (19 passed, 1 skipped) pass;
|
afa753a to
32f6e38
Compare
|
Rebased onto main 2b11517 (after v0.115.0). The only conflict was the experiments/README.md index, where the new OpenCode entry and the session fork entry now both stand. No code changes. Typecheck passes; the fork tests and the touched suites (79 tests) pass; oxlint is clean on the changed files.
|
2b9978a to
6b30e61
Compare
SessionOptions.fork with resume opens a NEW native session that starts as
a copy of the saved one, optionally cut after a turn (fork.through), and
leaves the source untouched. Session.id reports the copy's id.
- claude: --resume <source> --fork-session --session-id <OAR's new id>,
plus the hidden --resume-session-at=<assistant uuid> for through. The
open reads the fork's id back from claude's private get_status answer
and fails unless it is the id OAR assigned. The anchor is the uuid of
the turn's last root assistant message; an aborted turn gets none (a
fork through an interrupted tool_use loses the saved interruption).
--fork-session stays refused in launchArgs (reason now points to
SessionOptions.fork); with a fork, --resume-session-at is refused too.
- codex: thread/fork { threadId, lastTurnId?, excludeTurns, ... }; the
anchor is the turn id. lastTurnId arrived in codex 0.143.0 (bisected
over the generated app-server schemas), so through on an older or
unreported version is runtime_outdated before anything is sent. A fork's
token totals stay unreported: its total includes the source's turns
and codex sends no re-report to baseline it, and a fork runs the
configured default model and effort unless they are given (0.169.0).
- Other options follow resume semantics (claude: resumedSessionOptions);
name names the copy; codex fork instruction timing is untested.
- Every other runtime, morph and scriptedRuntime declare and refuse
"fork" (new RefusableSessionOption). fork without resume, or a blank or
NUL through, is refused before anything starts.
- Hosts read the anchor from the root turn_ended event's new forkAnchor,
or ViewTurn.forkAnchor in the session view; never from native frames.
Evidence: unit tests, and a vendor test against claude 2.1.323 and codex
0.169.0 with a scripted provider covering four checks per runtime: the
new id is the runtime's own report, the source transcript is
byte-identical, a fork through the first turn carries exactly that
turn's history, and a fork through the last turn equals a whole fork; plus experiments/session-fork.ts on a
real claude login (fork through "remember APPLE" of APPLE/BANANA answers
APPLE; the source transcript is unchanged).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-authored-by: bytemain <[email protected]>
6b30e61 to
0a9a170
Compare
|
Re-review at 0a9a170. Sorry for the delay: your 11-17 update answered everything and I did not come back to it. Full local check passes on this head (typecheck, lint, unit tests, mock sea-trial 19 passed). An independent review also ran My four points
Blocker: Claude anchors on turns whose last root assistant message is a
So "a failed turn's anchor is the synthetic API Error message" holds only for API-error failures, but it is stated generally in Fix, either of these:
Either way, add vendor cases for Smaller, take or explain
Once the blocker is fixed, I'll approve, and it goes into the next OAR release.
|
--resume-session-at keeps the history through a message and nothing after it, so a fork through a tool_use drops the saved tool_result and claude answers the call with "[Tool result missing due to internal error]". That is not limited to aborts: an outputSchema turn completes on its StructuredOutput call, and an error_max_turns turn stops after a tool call. A claude turn now names no forkAnchor when its last root assistant message holds a tool_use block, or a root tool_result follows it (new optional `user` hook on the stream-json projection profile). An API-error failure keeps its anchor on the synthetic API Error message. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A child.write throw (EPIPE) on the get_status readback is now a refusal like any other, so the open still kills the process before rejecting. A get_status error response (2.1.323 answers an unknown control request with "Unsupported control request subtype") fails the fork open with claude's words: the fork fails closed, since Session.id could not be confirmed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… narrow docs New sea-trial/vendor/session-fork-cases.vendor.test.ts (scripted provider, shared fixtures moved to support/session-fork.ts), run here on claude 2.1.323 and codex 0.169.1: - both: a fork of a source still open in another live Session copies its saved turns, and the source goes on without the fork's turns; - claude: an outputSchema turn (StructuredOutput) and an error_max_turns turn name no anchor, and a fork through their tool_use carries "[Tool result missing due to internal error]" where the source's next prompt carried the result; - claude: name names the copy, the source keeps its own (session_title_changed); - claude: after a manual compaction, a fork through an earlier turn fails the open with "No message found", one through a later turn forks; - codex: a manual compaction turn and a goal continuation turn carry anchors and a fork through either carries what the source's next prompt carried, so those anchors are kept; - codex: a fork reports no token totals for its whole Session. The codex model and effort case now also forks without a config override. Docs: "a failed turn's anchor is the API Error message" now holds for API-error failures only; codex.md narrows what was run (forks on 0.169.0 and 0.169.1 only, older releases ignoring lastTurnId is reasoned); the get_status fail-closed behavior and the untested cases (source mid-turn) are stated. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks for the careful re-review. Pushed e8eb9c9, 6cfef9d and e6b8d7e on top of 0a9a170. Point by point: Blocker. Fixed the safe way. A Claude turn gets no anchor when its last root assistant message holds a Unverified anchors. Codex manual compaction and goal continuation turns: shown to work on 0.169.1. A fork through either carries what the source's next prompt carried, so the anchors stay and are pinned by vendor assertions. Claude compacted source: a fork through a turn before a manual compaction fails the open with
Source still open. Vendor case added on both runtimes: the fork copies the saved turns and the source keeps going without the fork's turns. A source that is mid-turn is documented as untested. Codex token totals. Docs now say a Codex fork reports no token totals for its whole Session, and a vendor case checks two fork turns. Local: typecheck and lint pass;
|
|
Approved and merged at e6b8d7e. Thanks, Simon, and for the vendor cases: they pinned exactly the right things. Checked here:
The anchor rule reads right to me: no anchor past a root
Written by Cindy, an AI agent maintaining OAR.
|
<!-- stamp:review:v1 --> <sup><img src="https://api.raft.build/api/avatars/pixel/bXVn.svg" width="16" height="16" align="absmiddle" alt=""> <b>Cindy</b> from open-agent-runtime opened this pull request through Stamp</sup><br><sup><a href="https://stamp.build/review?receipt=prc_9ca5c5e14797297ac929e3d33fabeeec"><picture><source media="(prefers-color-scheme: dark)" srcset="https://stamp.build/assets/brand/stamp-glyph-dark.d907ffcadb44.svg"><img src="https://stamp.build/assets/brand/stamp-glyph-light.58a2c10ed108.svg" width="13" height="12" align="absmiddle" alt=""></picture> View in Stamp →</a></sup> --- <!-- /stamp:review:v1 --> Forking a saved session, Gemini quota notices with reset times on Antigravity, and bounded native queries. **One breaking change for hosts that consume the session view:** content that arrives outside a turn no longer joins a running turn (#953, below). ## Breaking: content outside turns stays outside them (#953) Root text or tool updates can arrive after a native turn has ended, with no new start (Antigravity 1.5.10 and 1.5.11, an OpenCode own-reply sample). OAR used to show such a session as running indefinitely while there was no active turn to abort. Now the status fold keeps it idle with `activity: { since, lastEventAt }`, and the view keeps that content in its own message, `ViewMessage` `kind: "activity"`. A later prompt or verified native start opens a new turn without moving earlier activity into it. Late tool updates still amend their original entry, and process exit closes unresolved tools. Consumers of `reduceSessionView` need a branch for `kind: "activity"` (type `ViewActivity`), and must replay a preceding start or a full checkpoint when they rebuild a running session. ## `SessionOptions.fork` (#888), feature With `resume`, `fork` opens a new native session that starts as a copy of a saved one, optionally cut after a given turn (`fork.through`), and leaves the source untouched. `Session.id` is the copy's id (new type `SessionFork`). The root `turn_ended` event carries `forkAnchor` when the runtime has a usable cut point, and `reduceSessionView` puts it on `ViewTurn.forkAnchor`, so a host can offer "branch from here" without reading native frames. - Claude: `--resume <source> --fork-session --session-id <new id>`, so OAR assigns the copy's id, with `through` as `--resume-session-at`. There is no `forkAnchor` on an aborted turn, or when the turn's last root assistant message holds a tool call or is followed by a tool result. `--fork-session` and, with a fork, `--resume-session-at` stay refused in `launchArgs`. - Codex: `thread/fork` with `lastTurnId`; the copy's id is the thread id Codex returns. `through` needs codex 0.143.0 or later and is `runtime_outdated` before anything is sent on older versions or when Codex does not report its version. A Codex fork reports no token totals, because its total includes the source's turns. - Every other runtime declares `fork` in `refusedSessionOptions` (new `RefusableSessionOption`). ## Antigravity: Gemini quota notices, whole-turn usage and credits (#982), fix agy 1.5.12 can end a refused turn with a normal `end_turn` whose whole output is its "Individual quota reached ... Resets in 4h12m." notice. OAR now reports that turn as `failure: "quota"` with `resetsAt`, but only when the entire native output is that exact notice and the reply carries no usage; quoting the notice inside an answer stays `completed`. A prompt RPC error carrying the same sentence also supplies `resetsAt`. The reset has the precision of the smallest unit agy prints, so a retry at that time can still be refused. - Token totals now come from the prompt reply, which covers every model call in the turn (two calls of 108 tokens report 216). Input is `totalTokens - outputTokens`, including cache reads; thought tokens count inside output; a reported zero cache write stays zero. - When every model group is used up, the account snapshot now includes `credits` from agy's own `/credits` answer: `{ available, balance }`, with `balance` a decimal string. Absent means OAR did not ask or could not read a number. - The antigravity page records that `usage_update.used` is the current context size on 1.5.12 with a real Gemini account (#981). ## Codex: quota reset times (#962), fix Codex quota failures now carry `resetsAt` from the current turn's exhausted window when it is attributable to this session's root turn, and from the provider body preserved in a remote-compaction HTTP 400. Conflicting resets, child-thread activity and streamed failures that lost the body stay without one. ## Native queries are bounded and clean up after themselves (#978), fix The shared query deadline now covers startup, the native read and cleanup. An owned child process tree is stopped even when startup finishes late; at the deadline the caller returns while shutdown finishes; a completed read keeps its value if only cleanup is slow. This fixes droid and its tools staying alive after `authStatus()` returned `unknown` against a stalled Factory peer, and the same ownership gap in several model and skill readers, including Cursor while its SDK subprocess starts. OpenCode model listing applies the deadline to its version probe too and rejects an invalid budget before starting. Login subprocesses get the same process-tree shutdown, and Antigravity `logout()` keeps a successful native logout when the status check after it fails. ## Process cleanup when a runtime runs as another user (#963, #964), fix Contributed by builder (airwing). With a `sudo -u <worker>` wrapper as the runtime command, signalling the worker's processes gets `EPERM`. That is no longer a failed cleanup: Codex's abort cleanup reports those processes as `SessionCleanup.foreign`. On POSIX, OAR no longer waits forever for output pipes that a leftover background process holds open after the root exits: it closes its ends after 2 s and names them in the `exited` reason, leaves unread data to a busy reader, and stops watching after a further 60 s. ## `dispose()` after a native exit (#979), fix If the native process exits on its own before the host calls `dispose()` (seen on Pi RPC), `dispose()` now resolves at once instead of never answering. Concurrent callers share one disposal. ## Claude: `userInvocable` only from the skill's own command (#950), fix `true` now needs the skill's own entry in Claude's command list. A duplicated name, or a project skill shadowed by a builtin command, stays unknown, and `false` is claimed only for user and project settings skills. ## Also - Docs: runtime pages and specs now keep what the code cannot say, and refer to the code for the rest (#971, #973, #977). Fork and turn-control refusals are complete on every page (#970, #972). An `OAR_<RUNTIME>_BIN` override is the only candidate when it is non-empty (#980). OpenCode v1 automatic compaction over ACP is documented (#969). Kimi docs match current adapter behaviour (#957). November 18 runtime version check recorded (#967). - harbor, the long-run test host: channel rules travel in the appended system prompt, so they survive compaction (#968). - CI: the Antigravity ACP baseline moves to 1.5.11 (#956). Tests: clearer diagnostics and fewer flakes for Antigravity, Kimi, Grok, Pi, shell children and startup refusals (#949, #951, #952, #954, #959, #960, #961, #966). - README: dsh-engine-switch added to projects using OAR (#974). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Cindy <[email protected]> Co-authored-by: xxchan <[email protected]>
What
SessionOptions.fork(withresume) opens a NEW native session that starts as a copy of a saved one, optionally cut after a given turn (fork.through), and leaves the source untouched.Session.idreports the copy's id.Hosts get the cut point without parsing native frames: the root
turn_endedevent carriesforkAnchor, andreduceSessionViewstamps it onViewTurn.forkAnchor.Use case: Kaze shows "Branch in new chat" under each reply of chats it runs on Claude Code and Codex through OAR (Codex style fork from any turn).
Why
--fork-sessionwas refused, and why that still holdsruntime-matrix.mdandclaude/launch-args.tsrefused--fork-sessionbecause a fork runs under a new native id thatSession.idwould not report. This PR keeps that guarantee:--resume <source> --fork-session --session-id <new uuid>(claude 2.1.323 accepts--session-idtogether with--fork-sessionand runs the fork under exactly that id), soSession.idis the fork's id.--fork-sessionstays refused inlaunchArgsfor every run, fork or not (the reason now points toSessionOptions.fork). With a fork,--resume-session-atinlaunchArgsis refused too, since it would silently overridethrough. Runs without a fork behave exactly as before.Runtimes
--resume-session-at=<uuid>forthrough(hidden flag; the anchor is the uuid of the turn's last root assistant message). Unknown anchor fails the open with claude's own message.thread/fork { threadId, lastTurnId?, excludeTurns: true, ... }; the anchor is the turn id.lastTurnIdarrived in codex 0.143.0 (bisected over generated app-server schemas), sothroughon an older or unreported version isruntime_outdatedbefore anything is sent. A codex fork reports no token totals: its total includes the source's turns and codex sends no re-report to baseline it (0.169.0).morphandscriptedRuntimedeclareforkinrefusedSessionOptions(newRefusableSessionOption) and refuse it atsession().Verification
pnpm test: all pass except 3 intests/release-only-workflow.test.ts, which fail identically on cleanorigin/mainon this machine.tests/claude/claude-session-fork.test.ts,tests/codex/codex-session-fork.test.ts,tests/session-view-fork-anchor.test.ts, plus refusal tests.sea-trial/vendor/session-fork.vendor.test.tsagainst real CLIs on the scripted provider (claude 2.1.323, codex 0.169.0): the fork's provider request holds only turn 1, a whole copy holds both, source and fork each resume with their own history, a bad anchor fails.experiments/session-fork.ts: two turns (APPLE, BANANA), fork through turn 1 answers APPLE only, fork id differs, source transcript unchanged and still answers APPLE and BANANA.Not tested live: codex with a real login, and the codex version floor.
Notes for review
SessionOptionslikeresume, refusals declared per runtime. Happy to change the shape if the maintainers prefer a separate method.🤖 Generated with Claude Code