Repository navigation
fix(gateway): preserve selected context for recorder-owned worker turns - #196487
Conversation
Restore selected-branch hydration and reject persisted recorder input without canonical admission. Align fork and GitHub spawn coverage with their current contracts. Co-authored-by: RomneyDa <[email protected]>
OpenClaw-Publication: e33dfa2b-36b0-403d-a890-da74799ab312
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesUse selected conversation context for recorder-owned worker input while preserving persistence after policy approval. Example: A recorder-owned worker turn has 3 active messages and 64 inactive messages.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Regression provenancePossible regression — suspected (reviewed change). No predecessor PR is attributed. Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored PR addresses a remaining current-main hydration defect with a focused repair and no actionable code findings. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherGateway worker preparation reads session history, prepares policy-visible input, and hands approved input to the recorder and worker launcher. flowchart TD
A[Worker turn input] --> B[Input context owner]
B --> C[Selected transcript reader]
C --> D[Prompt and policy preparation]
D --> E[Policy approval]
E --> F[Recorder persistence]
F --> G[Worker launch]
Technical reviewBest possible solution: Reuse the existing selected-context reader for recorder-owned preparation and keep all writes with the recorder after approval. Do we have a high-confidence way to reproduce the issue? Current-main source directly shows unpersisted recorder input taking the full-history reader; the PR reports the focused regression failing on the exact parent with 67 loaded messages, including 64 inactive messages, but no target code was executed during this review. Is this the best way to solve the issue? The patch is the smallest complete runtime repair: change reader selection using existing recorder ownership, retain the writable path for recorder-less input, and preserve existing cancellation, admission, and commit fences. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 1d72ad079047. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +2, Tests -7, Docs +2, Other +94. Total +91 across 6 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes: No label changes. Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (1 earlier review cycle)
Reviewed November 11, 2026, 11:57 AM ET / 16:57 UTC (Revision 2). |
Yigtwxx
left a comment
There was a problem hiding this comment.
The production change reads cleanly: fresh recorder-owned turns now take the same selected-branch openModelContextAsync view that admitted and suppressed turns already used, and the new hasPersisted() && !admission refusal is the same condition src/agents/harness/context-engine-turn-begin.ts:14 already treats as "a committed turn must supply its receipt". Two notes, one about coordination and one about a side effect worth stating.
The spawn-test hunk overlaps #196271 and pins less of #196206
server.sessions.create-worktree-spawn.test.ts:250-335 is the same stale-expectation repair that roboclaw-bot's #196271 (opened earlier, still open) makes for #196206. Both rewrite the test title and the if (!worktree) block, so whichever lands second will conflict.
The two versions also differ in what they prove. Here, the ["github", false] row becomes a success case, but nothing ties the child's working directory to its own worktree: child.worktree.repoRoot === otherRepository shows a worktree record exists, and readReadme(child.spawnedCwd) returns the same README whether spawnedCwd is the session worktree or the shared clone itself. #196206's invariant is "keep project sessions out of shared clones". #196271 asserts exactly that with managedWorktrees.findLiveByOwner("session", childKey), spawnedCwd/sessionRoot equal to the owned worktree path, and spawnedCwd not equal to otherRepository. It also adds the ["github", undefined] row for the omitted-intent case #196206 calls out. The row here still carries label: "Rejected project child" and the restricted.git URL while it is now expected to be accepted, which reads oddly.
Dropping this hunk and letting #196271 own the test, or taking its assertions, avoids both the conflict and the weaker pin.
Context-engine bootstrap maintenance on these turns is now memory-only
readWorkerTurnInputContext hands the selected-branch manager to bootstrapHarnessContextEngine (worker-turn-prompt.ts:144-166), which runs maintenance with reason: "bootstrap" and that sessionManager (context-engine-lifecycle.ts:160-161). fromSelectedEntries builds the manager without a persistence target, so runContextEngineMaintenance classifies it as caller memory (context-engine-maintenance.ts:264-267, getSessionTarget() === undefined) and a rewrite stays in that in-memory copy. Before this PR, a fresh recorder turn (no receipt yet, not suppressed) took the openAsync(transcriptTarget) branch, so the same rewrite went to the transcript.
No bundled context engine implements maintain, and admitted turns already behave this way, so I read this as consistent rather than a bug. It is still a behavior change for third-party engines that rely on bootstrap maintenance in cloud worker turns, so one sentence in the PR body would make it an explicit choice instead of something found later.
Adopt the original repair from #196487 while preserving its branch history. Carry forward the independently validated context reader, focused regression proof, documentation, and synthetic timing/allocation measurements. The final tree matches 68aac2c exactly. Keep the current admission and unrelated Gateway test repairs already landed through #196702 and #196889. No runtime source change was added in adoption. Co-authored-by: RomneyDa <[email protected]>
|
The adopted head @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
Integrate the production reader and footprint contract from upstream openclaw#196487 (ebf6c06). Recorder-owned input prepares only the selected conversation branch while persistence remains behind policy approval. Reject persisted recorders without a canonical admission and retain strict inactive-branch counts.
…ns (openclaw#196487) * fix(gateway): preserve selected context for recorder-owned worker turns Restore selected-branch hydration and reject persisted recorder input without canonical admission. Align fork and GitHub spawn coverage with their current contracts. Co-authored-by: RomneyDa <[email protected]> * fix(gateway): preserve selected context for recorder-owned worker turns OpenClaw-Publication: e33dfa2b-36b0-403d-a890-da74799ab312 * fix(gateway): avoid inactive transcript hydration before policy approval --------- Co-authored-by: RomneyDa <[email protected]> Co-authored-by: Peter Steinberger <[email protected]>
Expose the exact prepared image snapshot to input policy hooks across embedded, CLI, and Gateway worker runners. Reuse CLI prepared input across retries and isolate hook mutations from submitted input. Release adaptation: retain the existing hook type owner and runtime generation scope. Include the required missing-admission refusal from #196702, selected-branch recorder hydration from #196487, and deferred context-admission assertions from #197210. Do not import unrelated session rewind, prompt continuity, or cold-start owners. Selected source commits: (cherry picked from commit d7aaafe) (partial companion from commit e212ede) (partial companion from commit ebf6c06) (partial companion from commit eafa247) Co-authored-by: obviyus <[email protected]> Co-authored-by: Peter Steinberger <[email protected]> Co-authored-by: RomneyDa <[email protected]>
Related: #194545
What Problem This Solves
Gateway worker turns with recorder-owned input hydrate inactive transcript branches while preparing context. The intentional persistence-order correction in #196337 moved recording behind policy approval but left unpersisted recorder input selecting the full writable history reader.
User Impact
Worker preparation loads selected model context without decoding inactive message bodies. Input still persists only after policy approval. No schema, dependency, configuration, or persistence-policy change.
Why This Change Was Made
This preserves @RomneyDa’s original selected-context repair and branch history. The original admission and unrelated Gateway test repairs have already been superseded on main through #196702 and #196889; their current-main versions remain intact. This update adds the focused proof, documentation, and measurements below.
The recorder owns the subsequent write, so preparation can use the existing selected-context reader. Recorder-less inputs retain the writable reader. The footprint contract remains strict: three loaded entries and zero inactive entries, with no persistence before the policy gate. Detached-context tests preserve cancellation, admission, stale-authority, and policy-block behavior.
The simplification removes the test helper's two-reader dispatch. Production grows by two lines from an ownership comment and formatter layout; tests shrink by seven lines. The measurement script and fixture parameter provide repeatable A/A timing and allocation evidence.
Evidence
Exact main parent
54bfcd8fd601618108b65f6637beb3f611f2e28efails the recorder footprint on Node and pinned Bun: 67 loaded entries including 64 inactive. Node passes all 48 focused tests after the fix. Pinned Bun passes 46 detached-context/media tests plus both footprint tests in a separate stable invocation. An earlier combined invocation refused the footprint subprocess after formatting changed source during execution; that setup refusal is not counted as passing proof.Fresh Codex autoreview of the adopted tree is scoped-clean through P2.
pnpm check:changed --staged --base 54bfcd8fd601618108b65f6637beb3f611f2e28epassed production/test types, ratchets, and changed core/script lint. Its benchmark type error was fixed using inferred reader return types, followed by a passing scripts-typecheck replay. The remaining 57 production/32 full-tree export failures match the exact-parent signatures and are being repaired separately.Synthetic measurements compare the previous full-history reader (A1/A2 controls) with selected context (B). Five interleaved triplets of ten reads exclude seeding, imports, and warmup and require identical model-context digests. CPU covers the process; sampled allocation covers collected main-thread allocation, excluding worker/native SQLite allocation. Allocation uses a separate instrumented run.
The large fixture has 5,001 session records, 1,322 populated transcripts and 232,816 events. Its target contains 25,600 inactive entries; hydrated entries fall from 26,801 to 1,201. Versus A2, wall time falls 56.59%, CPU 54.66%, and sampled allocation 96.57%; A/A wall drift is 8.9% and CPU drift 1.2%.
The near-full case retains a latency tradeoff: B is 12.32% slower than A2 and 2.97% slower than A1, with 9.08% A/A wall drift and lower CPU. An earlier heavily loaded local run showed +22.3% versus A2 (+11.1% versus A1, roughly 10% A/A drift). These results do not claim a universal latency improvement.
Adoption commit
3c8559082f88113e0891dca8fb3c6be6cceaea69has both original PR head6e5f6f0d588fdd184011ff5f6996ad9b39d3a189and validated head68aac2cee3de4944e5d2bf2eb792608c6faff107as parents. Its complete Git tree is identical to the validated tree (8dd9af4ca0c4b8ead7bb1340337faf20fba15490), so the local tests and measurements apply to unchanged source. Exact-head CI and ClawSweeper on the adopted head remain required before landing.The first large seeding command omitted the canonical offline writer's maintenance-stop steps and stopped at a checkpoint guard. This was a task setup error. Read-only checks established the committed size/counts above; subsequent normal reader opening, digest checks, measurement and asynchronous closing all passed on validated head
68aac2cee3de4944e5d2bf2eb792608c6faff107. No duplicate large seed or forced checkpoint was used. The remote allocation was stopped after successful measurement.The runner used ext4; btrfs is not covered. This changed reader queries session-scoped SQLite data and does not enumerate workspace files. These are warm reader-owner measurements, not end-to-end Gateway or model latency.