Skip to content

fix(gateway): preserve selected context for recorder-owned worker turns - #196487

Merged
steipete merged 4 commits into
mainfrom
openclaw/fix-ten-main-ci-failures
Nov 11, 2026
Merged

steipete merged 4 commits into
mainfrom
openclaw/fix-ten-main-ci-failures

Conversation

@RomneyDa

@RomneyDa RomneyDa commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

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 54bfcd8fd601618108b65f6637beb3f611f2e28e fails 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 54bfcd8fd601618108b65f6637beb3f611f2e28e passed 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.

Synthetic fixture / metric, per 10 reads A1 A2 B
36.46 GiB database: median wall ms 5,654.770 5,193.767 2,254.635
36.46 GiB database: median CPU ms 7,901.310 7,804.229 3,538.797
36.46 GiB database: sampled allocation bytes 1,918,488,448 1,920,660,000 65,857,648
Near-full 2.25 MB database: median wall ms 403.680 370.070 415.680
Near-full 2.25 MB database: median CPU ms 955.265 799.130 657.001

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 3c8559082f88113e0891dca8fb3c6be6cceaea69 has both original PR head 6e5f6f0d588fdd184011ff5f6996ad9b39d3a189 and validated head 68aac2cee3de4944e5d2bf2eb792608c6faff107 as 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.

RomneyDa and others added 2 commits November 10, 2026 06:35
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
@clawsweeper

clawsweeper Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added the gateway Gateway runtime label Nov 10, 2026
@RomneyDa
RomneyDa marked this pull request as ready for review November 10, 2026 06:35
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 10, 2026
@clawsweeper

clawsweeper Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Use 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.

  • Before: Preparation hydrates all 67 messages.
  • After: Preparation hydrates only the 3 active messages, without persisting the input before approval.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The focused patch is coherent and preserves existing ownership; evidence covers production readers and in-process worker orchestration rather than the complete shipped flow.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the ordinary contributor proof gate; supplied focused regressions and synthetic production-reader measurements support hydration behavior but do not establish a completed Gateway-to-worker flow.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Starting a worker turn can load inactive transcript branches and unnecessarily increase preparation memory and CPU.
Reason: The repair restores the existing active-context contract using existing owners, and maintainer-authored direction records the measured latency tradeoff.

Regression provenance

Possible 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
Reviewed head: 3c8559082f88113e0891dca8fb3c6be6cceaea69

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied evidence does not demonstrate a real Gateway worker turn completing through policy approval, recorder persistence, and remote launch.
Agent review details

How this fits together

Gateway 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]
Loading

Technical review

Best 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

  • Worker context selection and persistence ordering keeps the original intent (d7aaafe: Prepared-image policy inspection requires recorder persistence to wait until approval; the patch preserves this ordering while correcting the resulting reader selection.)
  • Admission and detached-context tests keeps the original intent (e212ede: Restore missing canonical-admission refusal and align tests with deferred persistence; this patch retains that refusal and simplifies instrumentation for the repaired reader.)
  • Selected transcript footprint keeps the original intent (aa7eabb: Avoid retaining inactive worker history while preserving active context; the supplied provenance establishes this intent, although creation-era local blob inspection was unavailable.)
  • Synthetic context fixture keeps the original intent (3e342f3: Provide persisted synthetic context for allocation measurement; the added inactive-entry parameter preserves the existing default workload.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Josh Avant: Raw commit d7aaafe adds src/gateway/worker-environments/worker-turn-user-message.ts:275 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: d7aaafe92edf; files: src/gateway/worker-environments/worker-turn-user-message.ts)
  • Ayaan Zaidi: Raw commit e212ede adds src/gateway/worker-environments/worker-turn-user-message.ts:281 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: e212edede209; files: src/gateway/worker-environments/worker-turn-user-message.ts)

PR surface

Source +2, Tests -7, Docs +2, Other +94. Total +91 across 6 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 10 8 +2
Tests 2 6 13 -7
Docs 1 3 1 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 2 97 3 +94
Total 6 116 25 +91

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Unnecessary inactive-history hydration increases worker preparation memory and CPU, with impact concentrated in branched sessions.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-11-10T07:05:08.429Z sha 6e5f6f0 :: needs maintainer review before merge. :: none

Reviewed November 11, 2026, 11:57 AM ET / 16:57 UTC (Revision 2).

@Yigtwxx Yigtwxx left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]>
@steipete

Copy link
Copy Markdown
Contributor

The adopted head 3c8559082f88113e0891dca8fb3c6be6cceaea69 preserves the original repair and contributor history, with a complete tree identical to the validated 68aac2cee3de4944e5d2bf2eb792608c6faff107. The body contains the focused tests, synthetic measurements and limitations. The previous review has no open items.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation scripts Repository scripts labels Nov 11, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 11, 2026
@clawsweeper clawsweeper Bot removed clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 11, 2026
@steipete
steipete merged commit ebf6c06 into main Nov 11, 2026
143 of 144 checks passed
@steipete
steipete deleted the openclaw/fix-ten-main-ci-failures branch November 11, 2026 17:28
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

leonongoing added a commit to leonongoing/openclaw that referenced this pull request Nov 12, 2026
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.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 12, 2026
…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]>
RomneyDa added a commit that referenced this pull request Nov 12, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants