Skip to content

fix(agents): keep the settled-turn finalizer within its budget bound - #204028

Merged
obviyus merged 1 commit into
mainfrom
fix/settled-finalizer-bound
Nov 23, 2026
Merged

obviyus merged 1 commit into
mainfrom
fix/settled-finalizer-bound

Conversation

@obviyus

@obviyus obviyus commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

Result: the settled-turn finalizer again builds its summary request within eight bytes per context token, so a screenshot-heavy cut-off turn sends a bounded request with the user's request in view. Scheduled main CI has been red on settled-turn-finalization.incomplete.test.ts since #203536, and this change fixes it. Normal attempts keep the #203536 behavior: all history since the latest compaction, with no per-attempt slide.

What Problem This Solves

#203536 changed resolveEmbeddedSessionContextLimits to a fixed 16 MiB guard for every operation. The settled-tool finalizer (#178300, #184704) also takes its bound from that owner. It answers for its turn alone under its own cache key, and it relied on the old contextTokenBudget × 8 bound to replace screenshot bodies with short notices before it dropped the turn's request. At 16 MiB the omission never fired, so the finalizer sent every screenshot body.

Measured in the failing test (10 screenshots, 64k context window, bound 524,288 B):

Build Finalizer request Tool-result bodies
6198f78b^ 472,487 B 4 of 10 replaced by notices (77,339 B → 429 B each)
6198f78b (#203536) 780,415 B all 10 kept, 77,339 B each
this head 472,487 B 4 of 10 replaced by notices

Why This Change Was Made

  • The fix is in the existing owner, resolveEmbeddedSessionContextLimits, which already special-cased the finalizer. For operation: "settled-tool-finalization", it returns min(16 MiB, max(1 KiB, contextTokenBudget × 8)) with toolResultOverflow: "omit". Every other operation keeps the fixed 16 MiB guard.
  • The finalizer's cut cannot break an append-only prefix, because it is a separately keyed side request. Normal attempts, recovery and compaction reads are unchanged.
  • The 512 KiB test limit is unchanged.
  • The attempt-history-prepare.test.ts budget case that fix(agents): move the model-context history window only at compaction #203536 deleted is restored. It covers the finalizer omitting a body under a small budget.
  • Docs: docs/concepts/compaction.md names the finalizer as the one exception to the history guard.

Evidence

  • settled-turn-finalization.incomplete.test.ts: passes on 6198f78b^, fails on 6198f78b (expected 780415 to be less than 524288) and fails on main. It passes on this head. The request sizes in the table came from a temporary per-message size log in scratch copies; the log is not committed.
  • fix(agents): move the model-context history window only at compaction #203536's prefix-journey step (screenshot chat) passes on all 5 transports on this head.
  • The targeted tests pass: every test file that imports session-context-limits or one of its callers. pnpm check:changed and oxfmt/oxlint pass on the changed files.

Merge danger

Two-way door. The change touches only the finalizer's bound. A revert restores the oversized finalizer request.

#203536 gave every operation the fixed 16 MiB history guard, so the settled-tool
finalizer stopped omitting screenshot bodies and sent 780,415 B where its
64k-window bound is 524,288 B. The finalizer answers for its turn under its own
cache key, so it again stays within eight bytes per budget token and omits
result bodies first. Normal attempts keep the fixed guard.

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

clawsweeper Bot commented Nov 23, 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 agents Agent runtime and tooling size: S labels Nov 23, 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. labels Nov 23, 2026
@obviyus
obviyus merged commit 6963e4f into main Nov 23, 2026
126 checks passed
@obviyus
obviyus deleted the fix/settled-finalizer-bound branch November 23, 2026 10:29
@obviyus

obviyus commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator Author

Landed as 6963e4f. Bug: #203536 gave the settled-turn finalizer the fixed 16 MiB history guard, so it stopped omitting screenshot bodies (780,415 B against a 524,288 B bound). Fix: the finalizer alone again uses min(16 MiB, budget x 8) with tool-result omission; normal attempts keep the fixed guard. Proof: settled-turn-finalization.incomplete is green on 6198f78^, red on 6198f78 and main, and green here (472,487 B). The prefix journey passes on all 5 transports.

tideclaw-bot pushed a commit that referenced this pull request Nov 24, 2026
…1766)

(cherry picked from commit 9156690)

Release adaptation: Keep the stable full-prefix test. Exercise in-budget and omitted tool results using stable’s 16 MiB cap; stable no longer sizes this context from contextTokenBudget.

Companion audit: #204028, #203901, #202306 and #203536 are separate finalizer-budget, custody, project-transfer and context-window changes; not dependencies of the timestamp guard.

Co-authored-by: RomneyDa <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 24, 2026
…penclaw#204028)

Result: the settled-turn finalizer again builds its summary request within eight bytes per context token, so a screenshot-heavy cut-off turn sends a bounded request with the user's request in view. Scheduled `main` CI has been red on `settled-turn-finalization.incomplete.test.ts` since openclaw#203536, and this change fixes it. Normal attempts keep the openclaw#203536 behavior: all history since the latest compaction, with no per-attempt slide.

## What Problem This Solves

openclaw#203536 changed `resolveEmbeddedSessionContextLimits` to a fixed 16 MiB guard for every operation. The settled-tool finalizer (openclaw#178300, openclaw#184704) also takes its bound from that owner. It answers for its turn alone under its own cache key, and it relied on the old `contextTokenBudget × 8` bound to replace screenshot bodies with short notices before it dropped the turn's request. At 16 MiB the omission never fired, so the finalizer sent every screenshot body.

Measured in the failing test (10 screenshots, 64k context window, bound 524,288 B):

| Build | Finalizer request | Tool-result bodies |
|---|---|---|
| `d67eac7f^` | 472,487 B | 4 of 10 replaced by notices (77,339 B → 429 B each) |
| `d67eac7f` (openclaw#203536) | **780,415 B** | all 10 kept, 77,339 B each |
| this head | 472,487 B | 4 of 10 replaced by notices |

## Why This Change Was Made

- The fix is in the existing owner, `resolveEmbeddedSessionContextLimits`, which already special-cased the finalizer. For `operation: "settled-tool-finalization"`, it returns `min(16 MiB, max(1 KiB, contextTokenBudget × 8))` with `toolResultOverflow: "omit"`. Every other operation keeps the fixed 16 MiB guard.
- The finalizer's cut cannot break an append-only prefix, because it is a separately keyed side request. Normal attempts, recovery and compaction reads are unchanged.
- The 512 KiB test limit is unchanged.
- The `attempt-history-prepare.test.ts` budget case that openclaw#203536 deleted is restored. It covers the finalizer omitting a body under a small budget.
- Docs: `docs/concepts/compaction.md` names the finalizer as the one exception to the history guard.

## Evidence

- `settled-turn-finalization.incomplete.test.ts`: passes on `d67eac7f^`, fails on `d67eac7f` (`expected 780415 to be less than 524288`) and fails on `main`. It passes on this head. The request sizes in the table came from a temporary per-message size log in scratch copies; the log is not committed.
- openclaw#203536's prefix-journey step (screenshot chat) passes on all 5 transports on this head.
- The targeted tests pass: every test file that imports `session-context-limits` or one of its callers. `pnpm check:changed` and oxfmt/oxlint pass on the changed files.

## Merge danger

Two-way door. The change touches only the finalizer's bound. A revert restores the oversized finalizer request.

Co-authored-by: Ayaan Zaidi <[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 size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant