Repository navigation
fix(agents): harness history moves only at compaction - #203559
Conversation
resolveAgentHarnessHistoryLimits (Plugin SDK) kept its own contextTokenBudget x 8 byte cut, so Codex, Agents API and Muse reads dropped the oldest turns on each attempt. It now returns the embedded runner's shared guard plus its tool-result omission. The budget argument stays accepted but is deprecated and ignored; bundled callers stop passing it. Co-authored-by: obviyus <[email protected]>
|
🦞👀 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 changesThis PR replaces token-scaled history limits in Codex, Agents API, and Muse with the embedded runner’s shared resource guard. Example: A Codex mirrored-history read contains 43 messages totaling about 1.3 MB with the default 128,000-token budget.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it addresses a remaining harness-history defect, follows the merged embedded-runtime repair, and introduces no concrete correctness defect found in this review. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherBundled agent harnesses read the session owner’s transcript projection for hooks, continuity, or native-session transfer before preparing backend input. flowchart TD
A[Session transcript] --> B[Session model context reader]
C[Shared resource guard] --> B
B --> D[Codex continuity and hooks]
B --> E[Agents API preparation]
B --> F[Muse session transfer]
Technical reviewBest possible solution: Reuse the existing shared hydration guard while preserving session admission, tool-frame handling, and backend-native context ownership. Do we have a high-confidence way to reproduce the issue? Current-main source exposes the budget-scaled clipping path, and the supplied base/head/mutation regression results target it directly; no target code was executed during this read-only review. Is this the best way to solve the issue? This is a small repair at the existing policy owner, with all bundled callers migrated and no new state or parallel implementation; the resource guard and backend-specific projections still bound history. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 93f30cb0645a. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource -15, Tests -73, Docs +2. Total -86 across 12 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. Review metrics
LabelsLabel 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 Reviewed November 22, 2026, 12:01 PM ET / 17:01 UTC. |
|
Pre-push note: |
|
Landed as 45b96ba. Bug: plugin harness history reads (Codex, Agents API, Muse) cut the oldest turns at contextTokenBudget x 8 bytes on every attempt. Fix: resolveAgentHarnessHistoryLimits returns the embedded runner's shared 16 MiB guard; its budget argument is deprecated and ignored. Proof: the Codex history test is red on base (25 of 43 messages) and green on head, and red again when the old cap is restored. |
Result: plugin harnesses (Codex app-server, Agents API, Muse) now read session history with the same guard as the embedded runner. Their history keeps everything since the latest compaction and only grows between compactions. Follow-up to openclaw#203536. ## What Problem This Solves `resolveAgentHarnessHistoryLimits` (Plugin SDK) still computed its own byte cap: `contextTokenBudget × 8`. Each Codex hook/continuity read, Agents API prompt-hook read and Muse session transfer therefore cut the oldest turns once history passed 8 bytes per budget token. Reasoning, images and tool payloads reach that size far below the token budget. Each new attempt reread and cut the history again, so it was rewritten outside compaction. This is the same class openclaw#203536 fixed for the embedded runner. ## Why This Change Was Made - `resolveAgentHarnessHistoryLimits` now returns `resolveEmbeddedSessionContextLimits({})` (16 MiB / 10,000 events) plus its existing `toolResultOverflow: "omit"`. There is one owner for the bound, and the duplicate budget-based computation is gone. - The export keeps its name and signature. Its `contextTokenBudget` argument is still accepted, but it is **deprecated and ignored** (documented in the doc comment and in `docs/plugins/sdk-agent-harness/attempt-runtime.md`). - Bundled callers stop passing it. Codex drops the `contextTokenBudget` argument from `readCodexMirroredSessionHistoryMessages` / `readMirroredSessionHistoryMessages`. Agents API drops the limits from its history-reuse scope key: the limits are now constant, so a budget change no longer forces a fresh read. Muse calls it with no argument. - No schema, protocol or dependency change. Tests that asserted the removed budget cut are deleted or rewritten: - Codex `session-history.test.ts`: the budget-128 cut and budget-512 omission tests are replaced by the regression test below. - `run-attempt.bounded-continuity.test.ts`: the "assistant-only bounded suffix" case is kept. Its user turn is now larger than the 16 MiB guard, so it still covers the fallback past the guard. - Agents API: the "new budget" retry case is removed, and the pinned `maxBytes: 256_000` assertion is removed. ## Evidence Regression test through the Codex harness history consumer (`readCodexMirroredSessionHistoryMessages`): 1.3 MB of history, which is past the old default-budget cut and far below compaction. Two consecutive reads with a new turn appended between them. - Base `319099fbfe2d`: red, `expected … to have a length of 43 but got 25` (the oldest turns were cut). - Head: green. All 43 messages are returned, and the second read extends the first one exactly. - Mutation: head with the harness cap set back to `128_000 × 8` is red again (the same 25-message cut). Tests: the touched test files plus every test file that imports a changed source (25 files), oxfmt/oxlint on the changed files, and `pnpm check:changed`. ## What Changes for Users Codex, Agents API and Muse sessions with reasoning, screenshots or large tool output keep their whole history (and the provider cache prefix) until compaction. Before, old turns dropped silently on each attempt. ## Merge danger Two-way door. A revert restores the budget-based cut. Third-party plugins that pass a budget get the shared guard; their call still compiles. Co-authored-by: Ayaan Zaidi <[email protected]>
…am ratchet output (#203978) The baseline ratchet job now has real heap headroom, streams every check's output while it runs, and fails a stuck run after 12 minutes. Fixes #203945 Fixes #203921 ## Problem 1. `checks-fast-baseline-ratchets` hung for 18-47 minutes with no log (#203559, #203919). The database-worker inventory walks every source file of the tree (24,427 files). The native TypeScript client keeps each AST node it creates in a per-file cache for the whole snapshot. The walks created 27.9M nodes, so the live heap after GC reached 4,071 MiB (head) and 3,890 MiB (base) against the 4,096 MiB `--max-old-space-size` cap. Near the cap, V8 spends almost all time in garbage collection, which looks like a hang. 2. The worktree source scan used `rg -g <glob>`. A positive `-g` glob overrides ignore rules, so local runs also scanned ignored build bundles (24 MB of minified JavaScript, which is why the issue saw an out-of-memory error with `--base HEAD`). The scan also skipped the 3 tracked hidden `.boundary-stubs` files, so the head file set never matched the base (CI log: head 24,423 vs base 24,426 files) and an empty diff analyzed the base a second time. 3. `scripts/ci-baseline-ratchets.mts` held each check's output in memory until the check exited. The step had only the 60-minute job limit. A stuck check printed nothing. 4. `check-docs` went red on `main` after #203914. That PR merged at 04:19:29Z through the maintainer-role bypass of the "Require OpenClaw CI gate" ruleset while `openclaw/ci-gate` was still pending (rule suite 5298779737: required status check "pending", result "bypass"). Its `check-docs` job failed at 04:21:17Z, 108 s after the merge. `check-docs` runs on that path and feeds `ci-gate`, the formatter config includes the file and there is no merge queue, so the gap is the bypass merge before CI finished. #203927 already reformatted the file; scheduled `main` CI has `check-docs` green again (run 45118053016). ## Solution - `containsTrigger()` in `scripts/lib/native-typescript.mts`: from the raw text of each file, collect the positions of the tokens that a walk can act on, plus every backslash, because an escape can spell a token (`\u0045`, identity escapes) or hide one in the raw text (a newline escape before `DELETE` reads as the token `nDELETE`). A walk goes into a node only when its source span holds such a position. Pruned subtrees are never created. - Apply it to the five whole-tree walks: - `database-worker-compat.mts`: specifier/binding collection (`import`/`export` tokens, whole import/export declarations) and reference discovery (candidate names and `import`). - `personal-credential-writer-guard.mts`: declaration/specifier collection (approved files stay whole), dynamic-import binding (`import`), and sink/reference inspection (candidate names, `type`, Kysely writer methods, SQL write verbs, `import`, `export`). Token sets are recomputed when the name set grows between files, as before. - Type subtrees are skipped in the walks that do not already skip them; they hold no value declarations or specifiers. - `loadInventorySources()` uses `--hidden --type-add/--type` instead of `-g`, so the worktree file set equals Git membership. - `ci-baseline-ratchets.mts` streams each line with a `[check]` prefix as it arrives and keeps the `[ok]`/`::error` result line and the timing summary. - `ci.yml`: `timeout-minutes: 12` on the "Run baseline ratchets" step. 14 green PR runs on 2026-11-23 took 174-305 s (median about 182 s) for this step. - Regression test: a raw authority-table write whose SQL verb is spelled next to an escape (a `\u` escape, an identity escape, and newline or tab escapes before the verb) inside a nested block is still rejected. It fails when the escape positions are removed. ## Evidence Same machine, same tree (e58ca10), live heap measured after a forced GC at each analysis phase: | | before | after | |---|---|---| | head peak live heap | 4,071 MiB | 3,320 MiB | | base peak live heap | 3,890 MiB | 3,270 MiB | | AST nodes created (head) | 27,871,206 | 18,342,788 | | headroom under the 4,096 MiB cap (head) | 25 MiB | 776 MiB | | `check:database-worker-ratchet --base HEAD`, empty diff | 116 s, base analyzed again | 63 s, base reused | - Inventory rows are byte-identical before and after, for head and base. - Intermediate analysis facts are equal: compat names 15,077, aliases 296,647, namespaces 484, references 1,829,544, compiler symbol queries 1,856,156 (base). Guard: references 18,473, command nodes 17,464, protected declarations 110, binding names 17,543, handled imports 7,855, edges 177, identical sink sets. The only head-mode deltas come from the edited analyzer files themselves (two new import specifiers). - Forced hang, local, same step command under `timeout 20` with a `pnpm` stub whose database-worker check prints one phase line and sleeps: before, the phase line appeared at 20.03 s (only at shutdown); after, at 0.20 s. Both exit 124 and leave no child process. - Tests: `database-worker-compat`, `personal-credential-writer-guard` (both files), `check-database-worker-ratchet`, `native-typescript`, `ci-baseline-ratchets`, `ci-workflow-guards`: 471 passed, 8 skipped (first head); guard and compat suites again on the final head: 215 passed. ## Repository setting (not applied) The bypass merge in item 4 is possible because ruleset 19130959 ("Require OpenClaw CI gate") gives `RepositoryRole` 2 a `bypass_mode: always`. GitHub cannot limit a bypass to completed red checks, and the override flow (`landpr --admin-override`) needs a bypass. `landpr` already refuses any pending check, so the remaining gap is a bare admin merge or the web "bypass rules" button. The only settings change that closes it is removing that bypass actor, which also blocks every `landpr --admin-override` merge for `MAIN-ALSO` reds. Default: keep the ruleset unchanged and land overrides only through `landpr`. No settings change is made here. Co-authored-by: Ayaan Zaidi <[email protected]>
…am ratchet output (openclaw#203978) The baseline ratchet job now has real heap headroom, streams every check's output while it runs, and fails a stuck run after 12 minutes. Fixes openclaw#203945 Fixes openclaw#203921 ## Problem 1. `checks-fast-baseline-ratchets` hung for 18-47 minutes with no log (openclaw#203559, openclaw#203919). The database-worker inventory walks every source file of the tree (24,427 files). The native TypeScript client keeps each AST node it creates in a per-file cache for the whole snapshot. The walks created 27.9M nodes, so the live heap after GC reached 4,071 MiB (head) and 3,890 MiB (base) against the 4,096 MiB `--max-old-space-size` cap. Near the cap, V8 spends almost all time in garbage collection, which looks like a hang. 2. The worktree source scan used `rg -g <glob>`. A positive `-g` glob overrides ignore rules, so local runs also scanned ignored build bundles (24 MB of minified JavaScript, which is why the issue saw an out-of-memory error with `--base HEAD`). The scan also skipped the 3 tracked hidden `.boundary-stubs` files, so the head file set never matched the base (CI log: head 24,423 vs base 24,426 files) and an empty diff analyzed the base a second time. 3. `scripts/ci-baseline-ratchets.mts` held each check's output in memory until the check exited. The step had only the 60-minute job limit. A stuck check printed nothing. 4. `check-docs` went red on `main` after openclaw#203914. That PR merged at 04:19:29Z through the maintainer-role bypass of the "Require OpenClaw CI gate" ruleset while `openclaw/ci-gate` was still pending (rule suite 5298779737: required status check "pending", result "bypass"). Its `check-docs` job failed at 04:21:17Z, 108 s after the merge. `check-docs` runs on that path and feeds `ci-gate`, the formatter config includes the file and there is no merge queue, so the gap is the bypass merge before CI finished. openclaw#203927 already reformatted the file; scheduled `main` CI has `check-docs` green again (run 45118053016). ## Solution - `containsTrigger()` in `scripts/lib/native-typescript.mts`: from the raw text of each file, collect the positions of the tokens that a walk can act on, plus every backslash, because an escape can spell a token (`\u0045`, identity escapes) or hide one in the raw text (a newline escape before `DELETE` reads as the token `nDELETE`). A walk goes into a node only when its source span holds such a position. Pruned subtrees are never created. - Apply it to the five whole-tree walks: - `database-worker-compat.mts`: specifier/binding collection (`import`/`export` tokens, whole import/export declarations) and reference discovery (candidate names and `import`). - `personal-credential-writer-guard.mts`: declaration/specifier collection (approved files stay whole), dynamic-import binding (`import`), and sink/reference inspection (candidate names, `type`, Kysely writer methods, SQL write verbs, `import`, `export`). Token sets are recomputed when the name set grows between files, as before. - Type subtrees are skipped in the walks that do not already skip them; they hold no value declarations or specifiers. - `loadInventorySources()` uses `--hidden --type-add/--type` instead of `-g`, so the worktree file set equals Git membership. - `ci-baseline-ratchets.mts` streams each line with a `[check]` prefix as it arrives and keeps the `[ok]`/`::error` result line and the timing summary. - `ci.yml`: `timeout-minutes: 12` on the "Run baseline ratchets" step. 14 green PR runs on 2026-11-23 took 174-305 s (median about 182 s) for this step. - Regression test: a raw authority-table write whose SQL verb is spelled next to an escape (a `\u` escape, an identity escape, and newline or tab escapes before the verb) inside a nested block is still rejected. It fails when the escape positions are removed. ## Evidence Same machine, same tree (9e3b3a0), live heap measured after a forced GC at each analysis phase: | | before | after | |---|---|---| | head peak live heap | 4,071 MiB | 3,320 MiB | | base peak live heap | 3,890 MiB | 3,270 MiB | | AST nodes created (head) | 27,871,206 | 18,342,788 | | headroom under the 4,096 MiB cap (head) | 25 MiB | 776 MiB | | `check:database-worker-ratchet --base HEAD`, empty diff | 116 s, base analyzed again | 63 s, base reused | - Inventory rows are byte-identical before and after, for head and base. - Intermediate analysis facts are equal: compat names 15,077, aliases 296,647, namespaces 484, references 1,829,544, compiler symbol queries 1,856,156 (base). Guard: references 18,473, command nodes 17,464, protected declarations 110, binding names 17,543, handled imports 7,855, edges 177, identical sink sets. The only head-mode deltas come from the edited analyzer files themselves (two new import specifiers). - Forced hang, local, same step command under `timeout 20` with a `pnpm` stub whose database-worker check prints one phase line and sleeps: before, the phase line appeared at 20.03 s (only at shutdown); after, at 0.20 s. Both exit 124 and leave no child process. - Tests: `database-worker-compat`, `personal-credential-writer-guard` (both files), `check-database-worker-ratchet`, `native-typescript`, `ci-baseline-ratchets`, `ci-workflow-guards`: 471 passed, 8 skipped (first head); guard and compat suites again on the final head: 215 passed. ## Repository setting (not applied) The bypass merge in item 4 is possible because ruleset 19130959 ("Require OpenClaw CI gate") gives `RepositoryRole` 2 a `bypass_mode: always`. GitHub cannot limit a bypass to completed red checks, and the override flow (`landpr --admin-override`) needs a bypass. `landpr` already refuses any pending check, so the remaining gap is a bare admin merge or the web "bypass rules" button. The only settings change that closes it is removing that bypass actor, which also blocks every `landpr --admin-override` merge for `MAIN-ALSO` reds. Default: keep the ruleset unchanged and land overrides only through `landpr`. No settings change is made here. Co-authored-by: Ayaan Zaidi <[email protected]>
Result: plugin harnesses (Codex app-server, Agents API, Muse) now read session history with the same guard as the embedded runner. Their history keeps everything since the latest compaction and only grows between compactions. Follow-up to #203536.
What Problem This Solves
resolveAgentHarnessHistoryLimits(Plugin SDK) still computed its own byte cap:contextTokenBudget × 8. Each Codex hook/continuity read, Agents API prompt-hook read and Muse session transfer therefore cut the oldest turns once history passed 8 bytes per budget token. Reasoning, images and tool payloads reach that size far below the token budget. Each new attempt reread and cut the history again, so it was rewritten outside compaction. This is the same class #203536 fixed for the embedded runner.Why This Change Was Made
resolveAgentHarnessHistoryLimitsnow returnsresolveEmbeddedSessionContextLimits({})(16 MiB / 10,000 events) plus its existingtoolResultOverflow: "omit". There is one owner for the bound, and the duplicate budget-based computation is gone.contextTokenBudgetargument is still accepted, but it is deprecated and ignored (documented in the doc comment and indocs/plugins/sdk-agent-harness/attempt-runtime.md).contextTokenBudgetargument fromreadCodexMirroredSessionHistoryMessages/readMirroredSessionHistoryMessages. Agents API drops the limits from its history-reuse scope key: the limits are now constant, so a budget change no longer forces a fresh read. Muse calls it with no argument.Tests that asserted the removed budget cut are deleted or rewritten:
session-history.test.ts: the budget-128 cut and budget-512 omission tests are replaced by the regression test below.run-attempt.bounded-continuity.test.ts: the "assistant-only bounded suffix" case is kept. Its user turn is now larger than the 16 MiB guard, so it still covers the fallback past the guard.maxBytes: 256_000assertion is removed.Evidence
Regression test through the Codex harness history consumer (
readCodexMirroredSessionHistoryMessages): 1.3 MB of history, which is past the old default-budget cut and far below compaction. Two consecutive reads with a new turn appended between them.2754763da236: red,expected … to have a length of 43 but got 25(the oldest turns were cut).128_000 × 8is red again (the same 25-message cut).Tests: the touched test files plus every test file that imports a changed source (25 files), oxfmt/oxlint on the changed files, and
pnpm check:changed.What Changes for Users
Codex, Agents API and Muse sessions with reasoning, screenshots or large tool output keep their whole history (and the provider cache prefix) until compaction. Before, old turns dropped silently on each attempt.
Merge danger
Two-way door. A revert restores the budget-based cut. Third-party plugins that pass a budget get the shared guard; their call still compiles.