Skip to content

fix: prevent context overflow during long tool turns - #189810

Merged
roboclaw-bot merged 3 commits into
mainfrom
roboclaw/team-r13-compaction-overflow
Oct 31, 2026
Merged

roboclaw-bot merged 3 commits into
mainfrom
roboclaw/team-r13-compaction-overflow

Conversation

@roboclaw-bot

@roboclaw-bot roboclaw-bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Long tool-heavy turns can exceed the model window before turn-end maintenance runs. In the Contributor PRs cron incident on 2026-10-31 20:28–20:30Z, request 7 reached 1,000,188 tokens against a 1,000,000-token window. The surfaced “Auto-compaction failed” label did not establish that compaction had run.

User Impact

Hard context-window admission now runs by default at provider request boundaries, using conservative projected context and the existing 20,000-token reserve floor (capped for small windows). The optional soft threshold retains its disabled default and configured reserve. Unsafe replay or unsettled tools still prevent recovery compaction; surfaced overflow messages now identify a mid-turn window overflow. Manual compaction is unchanged.

Why This Change Was Made

Lead policy decision: a request already projected beyond the model window guarantees a 400 and cannot advance the turn. Reuse the existing provider-bound estimator, boundary signal, and compaction/retry owner instead of sending that request. The recovery safety gate remains authoritative, including parked Code Mode handling.

No new compactor, configuration option, state owner, or test-line allocation. Simplification consolidated duplicated retry fixtures and removed redundant fixture casts/identity overrides. Whole-PR production delta: +4 lines; tests and case fixtures: −13 lines (ratchet-scoped tests: 0).

Evidence

  • Red on rebased base 75d8b08f450d: the real Responses reply/session/attempt flow sent an over-window request to the deterministic local provider (HTTP 400).
  • Green: the same tool-loop boundary compacts before the next request, completes the turn with zero over-window submissions, and answers the next turn without repeating compaction. The existing completions summary-timeout case remains covered.
  • Focused Bun runs, timeout-wrapped, one worker: boundary guards, measured/opaque provider accounting, unsafe replay/Code Mode recovery, overflow presentation, prompt-prefix stability, and attempt siblings passed. The presentation cases use supported source-only E2E mode and make no built-runtime claim.
  • Targeted TypeScript, file-scoped lint/format, test-line ratchet, config-doc generation/check, and git diff --check passed.
  • CI repair: regenerated the help-text hash with the canonical generator, preserved real exports in the shared settings mock, and supplied the existing 8,192-token model window to four tool-flow fixtures. The cache-prefix fixture uses a 192k window so eight conservatively priced truncated results fit; its 32k result cap is unchanged. Dedicated small-window budget tests remain unchanged; all tool assertions remain intact.
Focused validation timings
Modified test owner Selected cases Vitest wall time
Real reply/provider compaction 2 13.09s
Attempt context guards 11 46.99s
Mid-turn recovery integration 11 20.58s
Source-only reply overflow presentation 2 61.11s
Tool-search/abort boundaries (CI repair) 10 8.03s
Code Mode continuation (CI repair) 1 6.20s
Configured MCP lifecycle (CI repair) 2 8.59s
Yield settlement (CI repair) 12 9.60s
Context-engine/prefix boundaries (CI repair) 25 11.41s

Cold source preparation is included where reported; CI-repair rows show Vitest time (wrapper totals: 13.17s, 40.32s, 43.92s, 14.82s, 17.63s). Exact-head CI completed successfully; see the run below.

  • Fresh local autoreview against 75d8b08f450d: scoped-clean, complete, no P0–P2 findings. The full review of 8b534ce48cea and a fresh scoped-clean follow-up on the final one-line prefix-fixture repair cover the published changes; reviewed inputs matched the task checkout byte for byte. The reviewer assessed unchanged estimator internals through the supplied caller contract and boundary tests; canonical generation/check independently verified the generated hash.
  • Exact-head CI: passed on 4c776fadc9dfde8b1f0d5c846fe4a1f2be848215 — CI run 41249411930.

Requested by @steipete

Work sessions

Discussion, implementation and verification

Co-authored-by: steipete [email protected]

Enforce hard window admission through existing provider-bound precheck recovery while retaining replay-safety gates.

Co-authored-by: steipete <[email protected]>
@clawsweeper

clawsweeper Bot commented Oct 31, 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 docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling size: L labels Oct 31, 2026
@roboclaw-bot
roboclaw-bot marked this pull request as ready for review October 31, 2026 22:15
@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. labels Oct 31, 2026
@roboclaw-bot
roboclaw-bot enabled auto-merge (squash) October 31, 2026 22:48
@roboclaw-bot
roboclaw-bot merged commit e44b8f4 into main Oct 31, 2026
125 checks passed
@roboclaw-bot
roboclaw-bot deleted the roboclaw/team-r13-compaction-overflow branch October 31, 2026 22:52
@roboclaw-bot

Copy link
Copy Markdown
Collaborator Author

Merged via squash auto-merge.

roboclaw-bot added a commit that referenced this pull request Nov 1, 2026
Revert e44b8f4 (#189810), which
introduced unconditional provider-bound pressure checks and overflow copy
changes across eight failed jobs in scheduled full CI 41252475393.

Restore the previous opt-in behavior, fixtures, recovery copy and docs as
one clean inverse. Real Gateway child-result tests fail before rollback,
as does the runner prompt-cache integration. Accepted rollback risk:
long tool turns can again overflow with the optional precheck disabled.

Co-authored-by: steipete <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 1, 2026
* fix: prevent context overflow during long tool turns

Enforce hard window admission through existing provider-bound precheck recovery while retaining replay-safety gates.

Co-authored-by: steipete <[email protected]>

* test: align tool fixtures with hard context admission

* test: fit prefix fixture within context admission

---------

Co-authored-by: steipete <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 1, 2026
Revert fe5a903 (openclaw#189810), which
introduced unconditional provider-bound pressure checks and overflow copy
changes across eight failed jobs in scheduled full CI 41252475393.

Restore the previous opt-in behavior, fixtures, recovery copy and docs as
one clean inverse. Real Gateway child-result tests fail before rollback,
as does the runner prompt-cache integration. Accepted rollback risk:
long tool turns can again overflow with the optional precheck disabled.

Co-authored-by: steipete <[email protected]>
steipete added a commit that referenced this pull request Nov 1, 2026
)

* fix(agents): compact long tool turns and publish current context totals

Start client maintenance at 75% of the active context window while preserving
provider and native compaction ownership. Check every prepared request against
the hard window using nominal occupancy, calibrated tool-result estimates, and
provider-measured context plus pending additions.

Publish current context through the existing guarded session writer and let
final ordered accounting supersede intermediate snapshots. Retire downstream
mixed-counter repairs; invalidate old prompt-only freshness stamps without a
schema change or new configuration.

Preserve the working 32k prompt-cache fixture and repair impossible lifecycle
fixture windows from the reverted admission rollout. Include red-on-parent
long-turn/accounting regressions and repair the cold native-auth test setup.

Related: #189810, #189891, #189888, #164551.
Co-authored-by: Alex Mittell <[email protected]>
Co-authored-by: Vincent Koc <[email protected]>

* fix(agents): complete nominal context admission and accounting cutover

* fix(agents): share lexical pricing with compaction summary fitting

* test(agents): align context consumers and isolate announce state

* test: await archive and steering fixture handoffs

Join the database lifecycle before raw archive fixture seeding, and wait for
runtime steering admission before releasing the held document request.
Preserve the existing behavior assertions and allocate exact regression lines.

Archive admission passes 17/17; steering passes 6/6. The CI assertions did not
reproduce locally, but diagnostic probes exposed the asynchronous fixture
handoffs. Fresh Codex review found no actionable findings.

---------

Co-authored-by: Alex Mittell <[email protected]>
Co-authored-by: Vincent Koc <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 2, 2026
…claw#190017)

* fix(agents): compact long tool turns and publish current context totals

Start client maintenance at 75% of the active context window while preserving
provider and native compaction ownership. Check every prepared request against
the hard window using nominal occupancy, calibrated tool-result estimates, and
provider-measured context plus pending additions.

Publish current context through the existing guarded session writer and let
final ordered accounting supersede intermediate snapshots. Retire downstream
mixed-counter repairs; invalidate old prompt-only freshness stamps without a
schema change or new configuration.

Preserve the working 32k prompt-cache fixture and repair impossible lifecycle
fixture windows from the reverted admission rollout. Include red-on-parent
long-turn/accounting regressions and repair the cold native-auth test setup.

Related: openclaw#189810, openclaw#189891, openclaw#189888, openclaw#164551.
Co-authored-by: Alex Mittell <[email protected]>
Co-authored-by: Vincent Koc <[email protected]>

* fix(agents): complete nominal context admission and accounting cutover

* fix(agents): share lexical pricing with compaction summary fitting

* test(agents): align context consumers and isolate announce state

* test: await archive and steering fixture handoffs

Join the database lifecycle before raw archive fixture seeding, and wait for
runtime steering admission before releasing the held document request.
Preserve the existing behavior assertions and allocate exact regression lines.

Archive admission passes 17/17; steering passes 6/6. The CI assertions did not
reproduce locally, but diagnostic probes exposed the asynchronous fixture
handoffs. Fresh Codex review found no actionable findings.

---------

Co-authored-by: Alex Mittell <[email protected]>
Co-authored-by: Vincent Koc <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling 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. docs Improvements or additions to documentation gateway Gateway runtime size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant