Skip to content

fix: avoid compaction from expired Anthropic runtime context - #186304

Merged
steipete merged 3 commits into
mainfrom
fix/compaction-bytes
Oct 27, 2026
Merged

steipete merged 3 commits into
mainfrom
fix/compaction-bytes

Conversation

@steipete

@steipete steipete commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Closes #185044. Thanks @travellingsoldier85 for the report.

What Problem This Solves

Fixes premature compaction after tool rounds renew temporary Anthropic runtime context, even when the effective model context remains below the configured byte guard.

User Impact

Long tool-driven turns keep their useful history without unnecessary compaction. Stored transcripts remain append-only, and raw storage and history-read bounds stay unchanged. No configuration or migration is required.

Why This Change Was Made

The byte-pressure owner now discounts only runtime-context body bytes proven expired by the current direct Anthropic API-key route. It retains envelope bytes and all history outside the bounded read. Preflight, manual compaction, the retry latch, and fallback-window selection use the same accounting semantics. OAuth, proxy routes, persistent updates, and ordinary history retain their existing byte charge.

Evidence

Reproduced through an isolated macOS Gateway using a deterministic Anthropic-compatible SSE relay: a 30-KB ingress envelope and ten real read tool rounds. The stored carriers and serialized wire payload remain intact.

Measurement Base Fixed
Raw active bytes 399,239 399,144
Bytes used by compaction guard 399,239 92,354
Configured guard 204,800 204,800
Summarizer requests / saved compaction boundaries 4 / 1 0 / 0

The fixed ten-tool turn completed in 5.027s. Its request carried 341,828 serialized message bytes and 34,168 effective bytes after clear_at. A 0.139s follow-up retained all ten tool results; all 49 prior transcript rows were byte-identical. Real Ollama qwen3:8b inference also passed through the Gateway before and after the fix (one read, expected terminal reply; 11.900s / 4.125s). These timings are observations, not a performance comparison.

Focused tests: 88 passed across eight files/five shards (862.96s, including cold compilation); the final fixture cleanup also passes the six-case regression rerun (115.68s). The new preflight regression fails on the original code and passes with the fix; controls cover non-clearing API routes, OAuth, proxies, persistent updates, and genuine user history. Production and touched-test types, lint, formatting, docs links, and all seven affected ratchets pass. Full build passes (15m42s). Isolated Codex review is clean at P0–P2.

Production LOC: +215/-26 (net +189); tests: +206/-1 (net +205). The added bounded reader shares current-route classification and conservative accounting across the pressure consumers; the same expiration classifier serves fallback sizing. Storage retains its existing raw counters.

Limitations: macOS local proof only; no live Anthropic API call. Rows outside the bounded accounting read remain conservatively charged. Wire bandwidth and disk footprint are unchanged.

Hosted reviews completed on 49a326c: GitHub Codex and ClawSweeper reported no findings; ClawSweeper lists no before-merge items and rates the supplied proof sufficient.

CI at handoff (2026-10-27 21:33 UTC): run 40581738226 has 20 successful checks and 28 queued jobs, with no failed checks. The required openclaw/ci-gate remains pending. Landing awaits that gate.

Preserve append-only replay and raw storage limits while using the current Anthropic route to discount cleared runtime-context bodies for compaction and fallback windows. Refs #185044; thanks @travellingsoldier85 for the report.
@clawsweeper

clawsweeper Bot commented Oct 27, 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.

@steipete
steipete marked this pull request as ready for review October 27, 2026 20:51
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling labels Oct 27, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-27T20:53:25.752718Z 49a326c Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug 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. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. 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-repro Preliminary submission classification; full source review pending. labels Oct 27, 2026
@clawsweeper

clawsweeper Bot commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR excludes expired temporary Anthropic runtime-context bodies from compaction pressure and fallback-window sizing.

Example: An Anthropic tool-driven turn renews a 30-KB runtime-context envelope across ten read calls with a 204,800-byte guard.

  • Before: The supplied Gateway reproduction charged 399,239 bytes and issued four summarizer requests.
  • After: The fixed reproduction charged 92,354 bytes, issued no summarizer requests, and retained all ten tool results.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, useful repair with matching Gateway evidence, distinct regression controls, and no actionable finding; provider proof uses a deterministic relay.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The supplied PR evidence maps the changed accounting owner to an isolated macOS Gateway using an Anthropic-compatible SSE relay and ten real read-tool rounds: fixed pressure stays below the guard, summarizer requests disappear, and the follow-up retains every tool result; live Anthropic service behavior was not exercised.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Long tool-driven Anthropic turns lose useful active history because expired temporary context triggers premature compaction.
Reason: The maintainer-authored direction addresses the reporter's accepted accounting alternative without changing persisted replay, configuration, or storage limits.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it addresses a confirmed compaction-accounting bug still present on main, preserves intentional append-only replay, and introduces no actionable defect found in this review.

Priority: P2
Reviewed head: 49a326ceaa8680c59635cd7f7638ff65d7aa7f3c

Before merge

None.

Findings

None.

Agent review details

How this fits together

Transcript accounting and the selected provider route feed compaction admission and context assembly, which produce either a compaction request or a bounded model-history view while retaining stored replay.

flowchart TD
  A[Stored transcript] --> B[Raw byte accounting]
  A --> C[Bounded history read]
  D[Current Anthropic route] --> E[Expired body classification]
  C --> E
  B --> F[Compaction pressure]
  E --> F
  F --> G[Compaction admission]
  E --> H[Fallback context window]
Loading

Technical review

Best possible solution:

Use shared, route-aware expiration accounting for compaction decisions while preserving transcript bytes and raw acquisition limits.

Do we have a high-confidence way to reproduce the issue?

Current-main source establishes renewal, provider-side expiration, and raw-byte admission; the supplied Gateway comparison exercises the reported interaction, although this read-only review ran no product code.

Is this the best way to solve the issue?

The change fixes the accounting owner rather than deleting intentional replay carriers, shares expiration semantics with fallback sizing, and conservatively preserves existing behavior on other routes.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 577ab8628f35.

Provenance checked

  • Anthropic runtime-context renewal and append-only replay keeps the original intent (46ab36a: Preserve the stable prompt prefix and retained thinking while renewing temporary facts after user-role tool results; the later Responses repair deliberately preserved Anthropic renewal.)
  • Byte-pressure admission and bounded context changes intended behavior with a stated reason (17cc94a: Continue replies with a deterministic bounded history view when byte compaction declines, preserving stored history and retry suppression.)
  • Manual compaction pressure propagation keeps the original intent (5b7749a: Give owning context engines the same configured byte-pressure information during manual recovery as automatic preflight.)
  • Additional fallback costs and native Codex ownership keeps the original intent (6db8577: Bound fresh native seeds while avoiding ordinary-turn host compaction and accounting for additional media costs.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 17cc94a adds src/context-engine/bounded-context.ts:35 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 17cc94a953e7; files: src/context-engine/bounded-context.ts)

PR surface

Source +189, Tests +205, Docs +6. Total +400 across 12 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 7 215 26 +189
Tests 3 206 1 +205
Docs 2 7 1 +6
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 12 428 28 +400

Review metrics

Metric Value Why it matters
Production versus regression coverage Production +215/-26; tests +206/-1 The growth supplies one shared pressure reader and expiration classifier, migrates the affected consumers, and covers distinct route and fallback boundaries.

Labels

Label changes:

  • add P2: The bug prematurely compacts or omits useful history in tool-heavy Anthropic sessions with an explicitly configured byte guard.
  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: The bug prematurely compacts or omits useful history in tool-heavy Anthropic sessions with an explicitly configured byte guard.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

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.

Reviewed October 27, 2026, 5:08 PM ET / 21:08 UTC.

@steipete
steipete merged commit b296e41 into main Oct 27, 2026
227 of 235 checks passed
@steipete
steipete deleted the fix/compaction-bytes branch October 27, 2026 22:41
@steipete

steipete commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor Author

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

Inherited failure details: check-lint-core-2 reported five eslint(curly) errors in ui/src/pages/chat/chat-content-column.browser.test.tsx and ui/src/pages/new-session/draft-body.browser.test.tsx; openclaw/ci-gate failed downstream. These files are outside this PR. The five statements are fixed on main by 8b2b0997. The exception was verified against CI run 40581738226, attempt 1, and its actual tested merge. No CI rerun or PR branch push was performed.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 28, 2026
…w#186304)

* fix: ignore expired runtime context in compaction pressure

Preserve append-only replay and raw storage limits while using the current Anthropic route to discount cleared runtime-context bodies for compaction and fallback windows. Refs openclaw#185044; thanks @travellingsoldier85 for the report.

* test: simplify compaction pressure accounting stub

* test: acknowledge declined compaction latch writes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

1 participant