Repository navigation
fix: compact at 80% on every route - #204180
Conversation
One compaction trigger: resolveCompactionThreshold now uses 80% of the window (capped by window minus reserve), and the request-boundary soft trigger for ChatGPT V2 and warm text compaction calls it instead of its own 90% literal. This moves V2/warm compaction from 90% to 80% and client maintenance from 75% to 80%, leaving headroom for the summary request on ~200k windows. 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. |
|
Landed in 412df90. Bug: since #204111, request-boundary compaction (ChatGPT V2 and warm text) started at 90%, and client maintenance at 75%. At 90% the warm summary request could run out of room on ~200k windows. Fix: one trigger at 80% (capped by window minus reserve), owned by |
|
Codex review: needs maintainer review before merge. What this changesThis PR gives client maintenance and request-boundary compaction one shared 80% trigger while preserving the reserve cap. Example: A built-in session has a 200,000-token window and a 20,000-token reserve.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored PR makes a focused compaction-policy correction absent from current main; no introduced correctness or security defect was found. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe embedded runner prices prepared provider requests, schedules compaction through the session owner, and resumes inference using the compacted history. flowchart TD
A[Prepared provider request] --> B[Context pressure calculation]
C[Shared compaction threshold] --> B
B --> D[Native checkpoint]
B --> E[Warm text summary]
D --> F[Session transcript owner]
E --> F
F --> G[Resumed inference]
Technical reviewBest possible solution: Keep the existing shared threshold owner, reserve cap, hard-window admission, and compaction writers. Do we have a high-confidence way to reproduce the issue? Source confirms the divergent triggers, but the claimed warm-summary exhaustion on approximately 200k windows has no supplied failing runtime trace. Is this the best way to solve the issue? The smallest coherent correction is to reuse the existing threshold calculation at the request boundary; the diff does that without adding machinery or changing fallback ownership. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 646a2d565817. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +9, Tests +41, Docs +3. Total +53 across 10 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 23, 2026, 1:11 PM ET / 18:11 UTC. |
…and transport owners (#204292) ## Result Pull request CI now selects every test whose runtime imports reach a changed file under `src/agents/`, `src/auto-reply/reply/agent-runner*`, `packages/agent-core/src/harness/compaction/` or `packages/ai/src/transports/`, directly or transitively. Replaying the file lists of #204111 and #204180 now selects the four tests that first failed on scheduled `main` (#204252). **Cost, read this first:** for these owners the transitive closure covers almost the whole runtime suite. A PR that touches them now runs a full-suite-sized Node plan, about 21x to 105x the previous predicted test time. Exact numbers are below. The plan stays inside the existing row cap and per-job time objective. Nothing is capped or dropped. Closes #204252. ## Why the tests were missed PR CI uses `selectionMode: "aggressive"` (`scripts/ci-build-manifest.mjs`). In `resolveBoundedChangedTestTargetPlan`, aggressive mode walks reverse imports to **depth 2**, and only to **depth 1** when the changed module has 20 or more direct importers (the hub cutoff). There are no owner-list routes for these files and no shard owner list filters them. The tests are simply too far away: | Changed owner | Import distance to the missed tests | |---|---| | `src/auto-reply/reply/agent-runner-memory.ts` | 3 (agent-runner tests) | | `src/agents/compaction.ts` | 5 (agent-runner), 7 (prompt-cache) | | `src/agents/embedded-agent-runner/run/request-boundary-compaction.ts` | 5 (agent-runner), 10 (prompt-cache) | | `src/agents/embedded-agent-runner/run/attempt-prompt-submit.ts` | 7 (prompt-cache), 9 (agent-runner) | | `packages/ai/src/transports/anthropic-messages.ts` | 6 (prompt-cache), 8 (agent-runner) | | `packages/agent-core/src/harness/compaction/summarization-completion.ts` | 6-7 | `session-context-accounting.gateway.integration.test.ts` is not reached within 10 imports of any compaction owner. It is reached only through the full closure, which runs through the Gateway into the runner. ## Fix The PR plan owner (`resolveChangedNodeTestTargets`) passes `transitiveOwners` to the bounded target walk. For a changed file that matches, the walk has no depth limit and no hub cutoff. All other paths keep the two-import walk. `docs/ci/scope-and-routing/node-test-lanes.md` describes the rule. ## Selection growth (replayed through the PR planner, hybrid backend, 130-row cap) | Replay | Before: tests / jobs / predicted test-seconds (max job) | After | |---|---|---| | #204111 (31 files) | 300 / 14 / 1,767 s (228 s) | 12,562 / 131 / 36,859 s (469 s) | | #204180 (9 files) | 22 / 5 / 351 s (140 s) | 12,405 / 131 / 36,673 s (468 s) | - The closure is nearly the whole runtime inventory. An unbounded walk from `request-boundary-compaction.ts` alone reaches 12,397 test files. - 48 of the last 200 first-parent commits on `main` (24%) touch these owners. At the replayed size, each PR push of that kind adds about 35,000 predicted test-seconds. - Shard budget: the plans stay at the compact Node row cap (130 rows plus one dist row) and below the 480-second per-job objective (max 469 s). They use the full PR row envelope that the registration budget already allows, so concurrent PRs of this kind compete for the same rows. - I tested no smaller rule that still selects the four tests. A walk depth of 10 already selects 2,401-7,129 tests (13,797-26,905 s) and still misses the Gateway integration test. ## Evidence - New test in `test/scripts/ci-changed-node-test-plan.integration.test.ts`. For 7 changed owners from #204111 and #204180, it asserts that the plan selects the four named tests and **every** test in the owner's unbounded runtime-import closure. It fails on `main` and passes on this head. - Replay script results above, on `main` and on this head. - One existing fixture expectation changed: `ci-changed-node-test-plan.selection.test.ts` used a `src/agents/example` source to pin the depth-two stop; it now expects the distant consumer. - Planner and workflow tests (13 files, 1,573 tests): all pass except `ci-changed-node-test-plan.test.ts` "retains precise process ownership (github)", which fails the same way on `main` (`expected 120 to be less than or equal to 60`). It is not caused by this change. - `pnpm check:changed`: pass. - CI on the head: green except 3 checks that fail the same way on scheduled main at the base (see the Maintainer override comment). Local ClawSweeper: patch is correct, no findings. Co-authored-by: Ayaan Zaidi <[email protected]>
…nd a declared behavior set (#204346) ## Result PR CI for agent, compaction, prompt and transport owners goes from a full-suite plan back to a bounded one, about 13x smaller. It still selects the four tests that #204252 was about. | Replay (PR planner, hybrid, 130-row cap) | Before (#204292) | After | |---|---|---| | #204111 (31 files) | 12,562 tests / 131 jobs / 36,859 s | **967 tests / 21 jobs / 2,881 s** (max job 271 s) | | #204180 (9 files) | 12,405 / 131 / 36,673 s | **302 / 14 / 1,393 s** (max job 250 s) | Both replays select `embedded-agent-runner.prompt-cache.test.ts`, `agent-runner-required-maintenance.pending-input.test.ts`, `agent-runner-compaction-fallback.test.ts` and `session-context-accounting.gateway.integration.test.ts`. ## Change For a changed source file under `src/agents/`, `src/auto-reply/reply/agent-runner*`, `packages/agent-core/src/harness/compaction/` or `packages/ai/src/transports/`, the aggressive PR plan now selects: 1. the normal two-import walk, as for every other file; 2. every transitive importer test **in the changed file's own directory**. A file directly in a package root (for example `src/agents/compaction.ts`) skips this step, because that directory is the whole package (1,795 tests for `src/agents/`); 3. a **declared behavior set**: every `*prompt-cache*` and `*compaction*` test under `src/` and `packages/` (118 files), plus `agent-runner-required-maintenance.pending-input.test.ts` and `session-context-accounting.gateway.integration.test.ts`. A test-only edit under these owners runs itself and does not pull in the declared set. Full mode (manual and hourly) is unchanged and still walks every importer. ## Decision recorded The follow-up asked for "importers within the same package". With the package root as the scope, #204111 selects 2,424 tests / 7,519 s, which misses the target of about 1,200 tests / 3,700 s. I used the changed file's directory instead, which meets the target. Coverage given up: cross-directory transitive importers, outside the declared set, of a file under these owners. The hourly full plan still runs them. This is reversible: widening the scope is a one-line change. | Variant | #204111 | #204180 | |---|---|---| | Declared set only | 369 / 1,888 s | 135 / 1,035 s | | **Same directory + declared (this PR)** | **967 / 2,881 s** | **302 / 1,393 s** | | Same package root + declared | 2,424 / 7,519 s | 308 / 1,393 s | | #204292 (unbounded) | 12,562 / 36,859 s | 12,405 / 36,673 s | ## Evidence - `ci-changed-node-test-plan.integration.test.ts`: for 7 owners from #204111 and #204180, the plan selects the four named tests and every same-directory importer test. - `ci-changed-node-test-plan.selection.test.ts`: the fixture case again expects the two-import stop for a distant consumer in another directory (the pre-#204292 expectation). - Planner, project and workflow tests (11 files): 1,322 passed. `pnpm check:changed`: pass. ## Coverage decision and closing loop - The maintainer accepted the same-directory scope as the coverage contract for these owners. The local review asked for this decision. - **Closing loop:** when a scheduled red traces to a green PR through a cross-directory importer, the fix PR adds that importer test to the owner's declared set. The declared sets grow only from real misses. - **Measurement:** 24 h after merge, compare agent-core PR rows and wall time with the #204292 numbers above. Co-authored-by: Ayaan Zaidi <[email protected]>
Related: openclaw#204111 ## What Problem This Solves Automatic compaction started at two different points. Client maintenance started at 75% of the context window. Since openclaw#204111, the request-boundary compaction (ChatGPT V2 checkpoint and the warm text summary on every other route) started at 90%, a side effect of reusing the V2 trigger. No measurement supported 90%. At 90%, the warm summary request (the full window plus an appended instruction and the summary output, thinking included) can run out of room on ~200k windows and silently fall back to the cold summarizer. ## User Impact All built-in routes now compact at the same point: the smaller of 80% of the window and the window minus the compaction reserve. On a 200k window, compaction starts at 160,000 tokens. - ChatGPT V2 and the warm text route move from 90% to 80% (180,000 → 160,000 on 200k). The summary request keeps 20% headroom. - Client maintenance moves from 75% to 80% (150,000 → 160,000 on 200k; 750,000 → 800,000 on 1M). - The reserve cap is unchanged. Manual `/compact`, overflow recovery and native Codex / Claude CLI policies are unchanged. Request shape is unchanged. ## Why This Change Was Made `resolveCompactionThreshold` already owns the client trigger. It now uses 0.8, and the request-boundary soft trigger calls it (capped by the reserve-based prompt budget, as before) instead of keeping its own `0.9`. One trigger, one owner. Docs that stated 75% or 90% now state 80%, with recomputed examples. ## Evidence - New test (`request-boundary-compaction.chatgpt-v2.test.ts`, both `native-checkpoint` and `text` variants): on a 200k window the client threshold is 160,000, the boundary sends no compaction request at 159,000, and sends one at 160,000. - Red on base (`6d8b616e5305`): the client threshold is 150,000; with that assertion removed, both variants send no request at 160,000 (base triggers at 180,000). - Green on this branch. - Updated threshold tables in the agent-core `shouldCompact` test, `setup.test.ts` and the refusal compaction test (now derived from the owner, not a hard-coded ratio). - Targeted local run: the touched tests plus every test file that imports a changed source. ## Merge danger Two-way door: a revert restores 75% / 90%. No stored state, config or contract changes. Blast radius: when every built-in agent session compacts (slightly later for client maintenance, earlier for ChatGPT V2 and warm text compaction). Co-authored-by: Ayaan Zaidi <[email protected]>
…and transport owners (openclaw#204292) ## Result Pull request CI now selects every test whose runtime imports reach a changed file under `src/agents/`, `src/auto-reply/reply/agent-runner*`, `packages/agent-core/src/harness/compaction/` or `packages/ai/src/transports/`, directly or transitively. Replaying the file lists of openclaw#204111 and openclaw#204180 now selects the four tests that first failed on scheduled `main` (openclaw#204252). **Cost, read this first:** for these owners the transitive closure covers almost the whole runtime suite. A PR that touches them now runs a full-suite-sized Node plan, about 21x to 105x the previous predicted test time. Exact numbers are below. The plan stays inside the existing row cap and per-job time objective. Nothing is capped or dropped. Closes openclaw#204252. ## Why the tests were missed PR CI uses `selectionMode: "aggressive"` (`scripts/ci-build-manifest.mjs`). In `resolveBoundedChangedTestTargetPlan`, aggressive mode walks reverse imports to **depth 2**, and only to **depth 1** when the changed module has 20 or more direct importers (the hub cutoff). There are no owner-list routes for these files and no shard owner list filters them. The tests are simply too far away: | Changed owner | Import distance to the missed tests | |---|---| | `src/auto-reply/reply/agent-runner-memory.ts` | 3 (agent-runner tests) | | `src/agents/compaction.ts` | 5 (agent-runner), 7 (prompt-cache) | | `src/agents/embedded-agent-runner/run/request-boundary-compaction.ts` | 5 (agent-runner), 10 (prompt-cache) | | `src/agents/embedded-agent-runner/run/attempt-prompt-submit.ts` | 7 (prompt-cache), 9 (agent-runner) | | `packages/ai/src/transports/anthropic-messages.ts` | 6 (prompt-cache), 8 (agent-runner) | | `packages/agent-core/src/harness/compaction/summarization-completion.ts` | 6-7 | `session-context-accounting.gateway.integration.test.ts` is not reached within 10 imports of any compaction owner. It is reached only through the full closure, which runs through the Gateway into the runner. ## Fix The PR plan owner (`resolveChangedNodeTestTargets`) passes `transitiveOwners` to the bounded target walk. For a changed file that matches, the walk has no depth limit and no hub cutoff. All other paths keep the two-import walk. `docs/ci/scope-and-routing/node-test-lanes.md` describes the rule. ## Selection growth (replayed through the PR planner, hybrid backend, 130-row cap) | Replay | Before: tests / jobs / predicted test-seconds (max job) | After | |---|---|---| | openclaw#204111 (31 files) | 300 / 14 / 1,767 s (228 s) | 12,562 / 131 / 36,859 s (469 s) | | openclaw#204180 (9 files) | 22 / 5 / 351 s (140 s) | 12,405 / 131 / 36,673 s (468 s) | - The closure is nearly the whole runtime inventory. An unbounded walk from `request-boundary-compaction.ts` alone reaches 12,397 test files. - 48 of the last 200 first-parent commits on `main` (24%) touch these owners. At the replayed size, each PR push of that kind adds about 35,000 predicted test-seconds. - Shard budget: the plans stay at the compact Node row cap (130 rows plus one dist row) and below the 480-second per-job objective (max 469 s). They use the full PR row envelope that the registration budget already allows, so concurrent PRs of this kind compete for the same rows. - I tested no smaller rule that still selects the four tests. A walk depth of 10 already selects 2,401-7,129 tests (13,797-26,905 s) and still misses the Gateway integration test. ## Evidence - New test in `test/scripts/ci-changed-node-test-plan.integration.test.ts`. For 7 changed owners from openclaw#204111 and openclaw#204180, it asserts that the plan selects the four named tests and **every** test in the owner's unbounded runtime-import closure. It fails on `main` and passes on this head. - Replay script results above, on `main` and on this head. - One existing fixture expectation changed: `ci-changed-node-test-plan.selection.test.ts` used a `src/agents/example` source to pin the depth-two stop; it now expects the distant consumer. - Planner and workflow tests (13 files, 1,573 tests): all pass except `ci-changed-node-test-plan.test.ts` "retains precise process ownership (github)", which fails the same way on `main` (`expected 120 to be less than or equal to 60`). It is not caused by this change. - `pnpm check:changed`: pass. - CI on the head: green except 3 checks that fail the same way on scheduled main at the base (see the Maintainer override comment). Local ClawSweeper: patch is correct, no findings. Co-authored-by: Ayaan Zaidi <[email protected]>
…nd a declared behavior set (openclaw#204346) ## Result PR CI for agent, compaction, prompt and transport owners goes from a full-suite plan back to a bounded one, about 13x smaller. It still selects the four tests that openclaw#204252 was about. | Replay (PR planner, hybrid, 130-row cap) | Before (openclaw#204292) | After | |---|---|---| | openclaw#204111 (31 files) | 12,562 tests / 131 jobs / 36,859 s | **967 tests / 21 jobs / 2,881 s** (max job 271 s) | | openclaw#204180 (9 files) | 12,405 / 131 / 36,673 s | **302 / 14 / 1,393 s** (max job 250 s) | Both replays select `embedded-agent-runner.prompt-cache.test.ts`, `agent-runner-required-maintenance.pending-input.test.ts`, `agent-runner-compaction-fallback.test.ts` and `session-context-accounting.gateway.integration.test.ts`. ## Change For a changed source file under `src/agents/`, `src/auto-reply/reply/agent-runner*`, `packages/agent-core/src/harness/compaction/` or `packages/ai/src/transports/`, the aggressive PR plan now selects: 1. the normal two-import walk, as for every other file; 2. every transitive importer test **in the changed file's own directory**. A file directly in a package root (for example `src/agents/compaction.ts`) skips this step, because that directory is the whole package (1,795 tests for `src/agents/`); 3. a **declared behavior set**: every `*prompt-cache*` and `*compaction*` test under `src/` and `packages/` (118 files), plus `agent-runner-required-maintenance.pending-input.test.ts` and `session-context-accounting.gateway.integration.test.ts`. A test-only edit under these owners runs itself and does not pull in the declared set. Full mode (manual and hourly) is unchanged and still walks every importer. ## Decision recorded The follow-up asked for "importers within the same package". With the package root as the scope, openclaw#204111 selects 2,424 tests / 7,519 s, which misses the target of about 1,200 tests / 3,700 s. I used the changed file's directory instead, which meets the target. Coverage given up: cross-directory transitive importers, outside the declared set, of a file under these owners. The hourly full plan still runs them. This is reversible: widening the scope is a one-line change. | Variant | openclaw#204111 | openclaw#204180 | |---|---|---| | Declared set only | 369 / 1,888 s | 135 / 1,035 s | | **Same directory + declared (this PR)** | **967 / 2,881 s** | **302 / 1,393 s** | | Same package root + declared | 2,424 / 7,519 s | 308 / 1,393 s | | openclaw#204292 (unbounded) | 12,562 / 36,859 s | 12,405 / 36,673 s | ## Evidence - `ci-changed-node-test-plan.integration.test.ts`: for 7 owners from openclaw#204111 and openclaw#204180, the plan selects the four named tests and every same-directory importer test. - `ci-changed-node-test-plan.selection.test.ts`: the fixture case again expects the two-import stop for a distant consumer in another directory (the pre-openclaw#204292 expectation). - Planner, project and workflow tests (11 files): 1,322 passed. `pnpm check:changed`: pass. ## Coverage decision and closing loop - The maintainer accepted the same-directory scope as the coverage contract for these owners. The local review asked for this decision. - **Closing loop:** when a scheduled red traces to a green PR through a cross-directory importer, the fix PR adds that importer test to the owner's declared set. The declared sets grow only from real misses. - **Measurement:** 24 h after merge, compare agent-core PR rows and wall time with the openclaw#204292 numbers above. Co-authored-by: Ayaan Zaidi <[email protected]>
Related: #204111
What Problem This Solves
Automatic compaction started at two different points. Client maintenance started at 75% of the context window. Since #204111, the request-boundary compaction (ChatGPT V2 checkpoint and the warm text summary on every other route) started at 90%, a side effect of reusing the V2 trigger. No measurement supported 90%. At 90%, the warm summary request (the full window plus an appended instruction and the summary output, thinking included) can run out of room on ~200k windows and silently fall back to the cold summarizer.
User Impact
All built-in routes now compact at the same point: the smaller of 80% of the window and the window minus the compaction reserve. On a 200k window, compaction starts at 160,000 tokens.
/compact, overflow recovery and native Codex / Claude CLI policies are unchanged. Request shape is unchanged.Why This Change Was Made
resolveCompactionThresholdalready owns the client trigger. It now uses 0.8, and the request-boundary soft trigger calls it (capped by the reserve-based prompt budget, as before) instead of keeping its own0.9. One trigger, one owner. Docs that stated 75% or 90% now state 80%, with recomputed examples.Evidence
request-boundary-compaction.chatgpt-v2.test.ts, bothnative-checkpointandtextvariants): on a 200k window the client threshold is 160,000, the boundary sends no compaction request at 159,000, and sends one at 160,000.0828443372be): the client threshold is 150,000; with that assertion removed, both variants send no request at 160,000 (base triggers at 180,000).shouldCompacttest,setup.test.tsand the refusal compaction test (now derived from the owner, not a hard-coded ratio).Merge danger
Two-way door: a revert restores 75% / 90%. No stored state, config or contract changes. Blast radius: when every built-in agent session compacts (slightly later for client maintenance, earlier for ChatGPT V2 and warm text compaction).