Repository navigation
feat(codex): fork upstream-linked sessions at a message via thread/fork - #111149
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3f72ecb94a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const localPrefixTexts = visibleUserEntries | ||
| .slice(0, userMessageOrdinal + 1) | ||
| .map((entry) => localMessageText(entry.message.content)); | ||
| const turns = await listCodexUpstreamTurns(params.control, params.threadId); |
There was a problem hiding this comment.
Align fork mapping with bounded imported history
When an adopted Codex thread exceeds the import limits, transcript-mirror.ts:42-44,242-261 retains only the newest 200 messages/512 KiB, but this code treats that retained tail as ordinal zero and compares it against the upstream thread from its first turn. Consequently, any fork from a message in a truncated imported session reports drift-mismatch before reaching the selected upstream message, even though the visible tail is valid. Map using persisted mirror identities or align the local tail against the corresponding upstream suffix.
Useful? React with 👍 / 👎.
| if (reviewMode || hiddenNestedReviewTurn) { | ||
| continue; |
There was a problem hiding this comment.
Keep review messages consistent between import and fork mapping
For threads containing a review span before the selected message, this skips the upstream userMessage, while transcript-mirror.ts:172-199 imports every userMessage in that same span as an ordinary visible local user entry. The next visible local ordinal therefore compares the review prompt against a later upstream prompt and every such fork fails with drift-mismatch; either exclude these messages during import or consume the corresponding local entry while resolving the boundary.
Useful? React with 👍 / 👎.
|
Codex review: needs real behavior proof before merge. Reviewed July 19, 2026, 2:46 AM ET / 06:46 UTC. Summary PR surface: Source +800, Tests +634, Other +3. Total +1437 across 19 files. Reproducibility: not applicable. This PR adds support for a previously rejected upstream-owned-session fork path rather than repairing an established current behavior contract. The reported focused tests provide source-level coverage, but no final-head live Codex app-server run is included. Review metrics: 2 noteworthy metrics.
Stored data model Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Proof guidance:
Risk before merge
Maintainer options:
Next step before merge
Maintainer decision needed
Security Review detailsBest possible solution: Retain the generic core capability with the Codex-specific implementation, but land only after an owner accepts the public SDK contract and final-head live proof demonstrates an adopted Codex session fork through the next resumed turn. Do we have a high-confidence way to reproduce the issue? Not applicable: this PR adds support for a previously rejected upstream-owned-session fork path rather than repairing an established current behavior contract. The reported focused tests provide source-level coverage, but no final-head live Codex app-server run is included. Is this the best way to solve the issue? Yes, conditionally: delegating an upstream-owned fork through a generic harness capability is cleaner than having core import Codex behavior, but maintainers must first accept the resulting public SDK contract and verify the state transition in a real app-server session. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against aaacee8166cd. Label changesLabel justifications:
Evidence reviewedPR surface: Source +800, Tests +634, Other +3. Total +1437 across 19 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
Review history (3 earlier review cycles)
|
3f72ecb to
26f1934
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 26f1934b19
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| binding: { | ||
| threadId, | ||
| cwd: forkedThread.cwd ?? "", | ||
| model: response.model, | ||
| modelProvider: response.modelProvider ?? undefined, |
There was a problem hiding this comment.
Preserve the fork's supervision connection in the binding
With the default stdio configuration, the catalog forks on the user-home supervision connection (extensions/codex/src/session-catalog.ts:238-239), while ordinary harness runs default to the agent home (extensions/codex/src/app-server/config.ts:603-605). This binding omits the connectionScope: "supervision", source/fingerprint, and native-ownership fields required by extensions/codex/src/app-server/session-binding.ts:178-186,233-257, so the first message in the newly forked session tries to resume the user-home thread from the agent-home app server; the resume rejection is then handled by clearing the binding and starting a fresh thread, severing the canonical fork lineage.
Useful? React with 👍 / 👎.
| const localPrefixTexts = visibleUserEntries | ||
| .slice(0, userMessageOrdinal + 1) | ||
| .map((entry) => localMessageText(entry.message.content)); |
There was a problem hiding this comment.
Match mirrored messages using their canonical upstream text
When a post-adoption turn is decorated with OpenClaw workspace or inbound context, the visible transcript retains the user's original content while the exact text sent to Codex is stored as __openclaw.upstreamUserText by extensions/codex/src/app-server/transcript-mirror.ts:446-452. Building the comparison prefix only from message.content therefore compares the undecorated local text with the decorated upstream userMessage, causing drift-mismatch for otherwise valid fork points; use the persisted upstream text for identity verification while retaining the visible content for editorText.
Useful? React with 👍 / 👎.
|
ClawSweeper status: review started. I am starting a fresh review of this pull request: feat(codex): fork upstream-linked sessions at a message via thread/fork This is item 1/1 in the current shard. Shard 0/1. This placeholder means the worker is alive and reading the current context. I will edit this same comment with the actual review when the claws are done clicking. Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e6fdaa7eac
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| "A message before the fork point contains images or attachments that cannot be verified across OpenClaw and Codex. Fork from a text-only span instead.", | ||
| ); | ||
| } | ||
| if (display.text !== localText) { |
There was a problem hiding this comment.
Match against the imported prompt representation
When an adopted thread contains a prompt with leading/trailing whitespace or more than 64 KiB of text, its local entry is trimmed or truncated by extensions/codex/src/app-server/transcript-mirror.ts:90-103, while userMessageDisplay retains the raw upstream text. This exact comparison therefore returns drift-mismatch for that entry and every later fork point even though the transcript was imported from the same thread. Preserve canonical upstream text during import or compare using the same projection.
Useful? React with 👍 / 👎.
…nd orphan archival
e6fdaa7 to
5f9a3f3
Compare
|
Merged via squash.
|
…rk (openclaw#111149) * feat(codex): fork upstream-linked sessions at a message via thread/fork * fix(gateway): fail closed for rewind and branch switch on upstream-linked sessions * fix(codex): fail closed on first-message forks, image-only prompts, and orphan archival * fix(codex): baseline retained history and reject paginated threads on upstream fork * fix(codex): validate the full fork prefix and fail closed across crash windows * fix(codex): treat all non-text inputs as unverifiable in fork drift checks * fix(codex): support first-message forks as empty-history upstream cuts * fix(codex): reject source-id reuse and unverifiable hidden inputs in fork boundaries * refactor(codex): materialize upstream forks from verified thread read-back * fix(codex): satisfy strict type lanes and knip for upstream fork
…rk (openclaw#111149) * feat(codex): fork upstream-linked sessions at a message via thread/fork * fix(gateway): fail closed for rewind and branch switch on upstream-linked sessions * fix(codex): fail closed on first-message forks, image-only prompts, and orphan archival * fix(codex): baseline retained history and reject paginated threads on upstream fork * fix(codex): validate the full fork prefix and fail closed across crash windows * fix(codex): treat all non-text inputs as unverifiable in fork drift checks * fix(codex): support first-message forks as empty-history upstream cuts * fix(codex): reject source-id reuse and unverifiable hidden inputs in fork boundaries * refactor(codex): materialize upstream forks from verified thread read-back * fix(codex): satisfy strict type lanes and knip for upstream fork
What Problem This Solves
sessions.fork(#110660) rejects sessions whose conversation is owned by an external agent harness — for Codex-app-server-backed sessions the canonical history lives in Codex rollout files addressed by threadId, so a local-mirror fork would diverge from the authoritative context. Fork from a message bubble therefore did not work for adopted/Continue Codex sessions. Final follow-up agreed in #110660.Why This Change Was Made
AgentHarness.sessionForkcapability: core resolves it from the harness registry by upstream kind (single-match, fail-closed) and delegates the entire fork; core imports no plugin code. The Codex plugin registers the implementation.codex-rs/tui/src/app_backtrack.rs:473-544): ordinal walk over visible turn-initial user messages with steer/review-span skips, full-prefix text verification against the local transcript, and fail-closed handling of anything unverifiable (images, skills, mentions, hidden semantic inputs), in-progress turns, and drifted text. First-message cuts fork withbeforeTurnIdof the first turn — a valid empty-history fork (verified:thread_fork_innerhas no minimum-turn guard). Paginated-history threads are rejected with a clear message (upstream forbids forking them:method_not_found("paginated_threads is not supported yet")).thread/fork+ experimentalbeforeTurnId(the shared client already negotiatesexperimentalApi), pinned to the connection fingerprint that owns the thread. Because an older app-server could silently drop the experimental field and copy full history, the forked thread is read back and its tail verified against the expected retained boundary; mismatches archive the fork and fail with a version message. A response reusing the source thread id is rejected outright and never archived.thread/rollbackis deprecated). Covered by tests including the previously masked capability-registered case.scripts/plugin-sdk-surface-report.mjswith rationale). Protocol unchanged.User Impact
"Fork from here" now works on Codex-backed (adopted/Continue) sessions in every surface that calls
sessions.fork: it forks the real Codex thread at the chosen message, creates a new OpenClaw session whose history is imported from that fork, and binds it for the next turn. Unsupported cases fail with precise, actionable errors (steered messages, in-progress turns, image-bearing spans, paginated threads, old Codex versions) instead of generic failures.Evidence
codex-rscheckout:app-server-protocol/src/protocol/v2/thread.rs:495-626(fork params/response, experimental gating),common.rs:494-499,app-server/src/request_processors/thread_processor.rs:3702+(fork mechanics, paginated rejection, no empty-fork guard),core/src/thread_rollout_truncation.rs:162-235(before/after truncation asymmetry),tui/src/app_backtrack.rs:473-544(reference cut algorithm).node scripts/run-vitest.mjs src/gateway/server-methods/sessions-rewind.test.ts— 20 tests: capability delegation, typed failure pass-through, rewind/switch rejection for upstream links (with and without a registered capability), non-upstream paths unchanged.node scripts/run-vitest.mjs extensions/codex/src/app-server/upstream-fork-boundary.test.ts extensions/codex/src/app-server/upstream-session-fork.test.ts— 15 tests: ordinal/prefix/steer/review/in-progress/drift/unverifiable-input/first-turn/paginated boundaries; verified import, version-skew read-back mismatch → archive + typed failure, source-id reuse rejection, compensation, fresh-target materialization.pnpm tsgo:core+pnpm tsgo:extensionsgreen locally; oxlint/oxfmt clean;pnpm plugin-sdk:surface:checkgreen after the ledger update.gpt-5.6-sol) drove the design here — findings on cut semantics, marker baselines, crash ordering, drift-guard completeness, and version skew were each verified againstcodex-rsand fixed (or, for first-message forks, corrected back per upstream evidence); the final cycle on the import-based design reported no actionable findings.