Repository navigation
refactor(agents): unify context limits and compaction recovery - #117149
Conversation
|
Codex review: needs real behavior proof before merge. Reviewed July 31, 2026, 9:41 PM ET / August 1, 2026, 01:41 UTC. ClawSweeper reviewWhat this changesThe branch consolidates context-budget planning, tool-result truncation, and timeout/overflow compaction recovery into shared agent-runtime helpers while removing redundant worker and maintenance code. Merge readiness⛔ Blocked until real behavior proof from a real setup is added - 5 items remain Keep this PR open for maintainer review. The consolidation is directionally sound and no concrete patch defect emerged from the inspected recovery, worker, and transcript-maintenance paths, but this maintainer-labeled refactor changes session recovery and availability-critical behavior without independently inspectable after-fix runtime proof. Likely related people: Peter Steinberger ( Priority: P2 Review scores
Verification
How this fits togetherEmbedded agent runs accumulate transcript and tool-result state, then compact or trim that state when prompt limits or timeouts occur. The changed code prepares shared compaction inputs for context engines, adopts the resulting transcript, and retries the agent run or surfaces a recovery outcome. flowchart LR
A[Agent conversation] --> B[Transcript and tool results]
B --> C[Prompt limit or timeout]
C --> D[Shared compaction recovery]
D --> E[Context engine]
E --> F[Transcript adoption and maintenance]
F --> G[Retry or visible recovery outcome]
Decision needed
Why: The remaining gate is acceptance of behavioral-equivalence proof for session and availability-sensitive recovery paths, rather than a mechanical code repair that automation can safely choose. Before merge
Agent review detailsSecurityNone. PR surfaceSource -1046, Tests +23. Total -1023 across 15 files. View PR surface stats
Review metricsNone. Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Retain the single shared recovery owner, but merge only after maintainers have terminal evidence that overflow and timeout recoveries preserve successor-session identity, transcript maintenance, and retry behavior on the exact head. Do we have a high-confidence way to reproduce the issue? Not applicable: this is a behavioral-equivalence refactor rather than a report of a new discrete defect. The relevant proof is exercising the existing overflow and timeout recovery paths on the PR head. Is this the best way to solve the issue? Yes, conditionally: sharing the construction of compaction runtime context and successor-transcript adoption is a cleaner owner boundary than keeping parallel timeout and overflow copies. The remaining concern is proof that the unified path preserves both existing recovery contracts. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against a0c98de0af86. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
* commit '475ea69f2c356104f4b601f4976788081e79b8b4': refactor(agents): consolidate context budgets and compaction recovery (openclaw#117149) fix(net-policy): redact sig and x-* auth params in URLs and bodies (openclaw#116957) refactor(agents): remove duplicate generated-media delivery fallbacks (openclaw#117150) refactor(reply): unify turn lifecycle state ownership (openclaw#117145) fix(ui): preserve emoji agent avatar initials (openclaw#104912) refactor(auto-reply): unify command and directive ownership (openclaw#117143)
* origin/main: (3706 commits) refactor(ui): unify filtered session list ownership (openclaw#117158) refactor(agents): consolidate context budgets and compaction recovery (openclaw#117149) fix(net-policy): redact sig and x-* auth params in URLs and bodies (openclaw#116957) refactor(agents): remove duplicate generated-media delivery fallbacks (openclaw#117150) refactor(reply): unify turn lifecycle state ownership (openclaw#117145) fix(ui): preserve emoji agent avatar initials (openclaw#104912) refactor(auto-reply): unify command and directive ownership (openclaw#117143) refactor(plugins): consolidate descriptor and startup ownership (openclaw#117146) fix(messages): reply actions leak citation markers and reply/poll answers draw the no-reply fallback (openclaw#116909) fix(slack): let durable ingress retry transient thread lookups (openclaw#117135) refactor(doctor): consolidate shipped state migration ownership (openclaw#117142) fix(ai): Codex stream shows internal parser text on a malformed frame (openclaw#116966) fix: guard every migrated session accessor path (openclaw#117140) fix(terminal): measure unicode display width consistently (openclaw#117062) fix(openai): clear ChatGPT SSE fallback per session (openclaw#117123) fix(mistral): reject incomplete streamed tool terminals (openclaw#117137) fix(ai): preserve structured chat content and refusals (openclaw#117136) fix(doctor): persist normalized agent roster (openclaw#117115) fix(signal): avoid replay after ambiguous quote delivery errors (openclaw#117134) fix(cron): reject disabled delivery accounts when scheduling (openclaw#116899) ...
* commit '7e78de747b8a64d52f30aee948b697bf4c528691': (359 commits) refactor(ui): replace duplicated locale bundles with canonical translation memory (openclaw#117157) fix(ui): retire stale Gateway event-log observers (openclaw#117169) fix(agents): keep subagent status consistent after restart and large fan-outs (openclaw#117141) refactor(ui): unify filtered session list ownership (openclaw#117158) refactor(agents): consolidate context budgets and compaction recovery (openclaw#117149) fix(net-policy): redact sig and x-* auth params in URLs and bodies (openclaw#116957) refactor(agents): remove duplicate generated-media delivery fallbacks (openclaw#117150) refactor(reply): unify turn lifecycle state ownership (openclaw#117145) fix(ui): preserve emoji agent avatar initials (openclaw#104912) refactor(auto-reply): unify command and directive ownership (openclaw#117143) refactor(plugins): consolidate descriptor and startup ownership (openclaw#117146) fix(messages): reply actions leak citation markers and reply/poll answers draw the no-reply fallback (openclaw#116909) fix(slack): let durable ingress retry transient thread lookups (openclaw#117135) refactor(doctor): consolidate shipped state migration ownership (openclaw#117142) fix(ai): Codex stream shows internal parser text on a malformed frame (openclaw#116966) fix: guard every migrated session accessor path (openclaw#117140) fix(terminal): measure unicode display width consistently (openclaw#117062) fix(openai): clear ChatGPT SSE fallback per session (openclaw#117123) fix(mistral): reject incomplete streamed tool terminals (openclaw#117137) fix(ai): preserve structured chat content and refusals (openclaw#117136) ...
* commit '6938f7dddb63bad59862c014c427d63f0a41a6f4': (368 commits) fix: allow gateway service commands for named profiles (openclaw#116314) fix(plugins): invalidate bundled artifact locations after metadata refresh (openclaw#117041) fix(ollama): honor model requests and pull completion contracts (openclaw#117171) fix(agents): prevent fallback after stale lifecycle abort (openclaw#117168) fix(telegram): confirm polling before long poll (openclaw#116970) fix(tlon): wire autoDiscoverChannels through the settings-store round-trip (openclaw#114949) fix(gateway): yield before post-ready background work (openclaw#117083) fix(ui): keep canvas lease renewals lifecycle-owned and timer-safe (openclaw#117173) fix(teams): restore the official square product icon (openclaw#117170) refactor(ui): replace duplicated locale bundles with canonical translation memory (openclaw#117157) fix(ui): retire stale Gateway event-log observers (openclaw#117169) fix(agents): keep subagent status consistent after restart and large fan-outs (openclaw#117141) refactor(ui): unify filtered session list ownership (openclaw#117158) refactor(agents): consolidate context budgets and compaction recovery (openclaw#117149) fix(net-policy): redact sig and x-* auth params in URLs and bodies (openclaw#116957) refactor(agents): remove duplicate generated-media delivery fallbacks (openclaw#117150) refactor(reply): unify turn lifecycle state ownership (openclaw#117145) fix(ui): preserve emoji agent avatar initials (openclaw#104912) refactor(auto-reply): unify command and directive ownership (openclaw#117143) refactor(plugins): consolidate descriptor and startup ownership (openclaw#117146) ...
* commit 'fb6c4cf5b748d913839d0fe23dbcbbf89804b882': refactor(agents): consolidate context budgets and compaction recovery (openclaw#117149) fix(net-policy): redact sig and x-* auth params in URLs and bodies (openclaw#116957) refactor(agents): remove duplicate generated-media delivery fallbacks (openclaw#117150) refactor(reply): unify turn lifecycle state ownership (openclaw#117145) fix(ui): preserve emoji agent avatar initials (openclaw#104912) refactor(auto-reply): unify command and directive ownership (openclaw#117143)
* commit '5148236bbe050f6c05ee59190986a7215b41ce1c': (359 commits) refactor(ui): replace duplicated locale bundles with canonical translation memory (openclaw#117157) fix(ui): retire stale Gateway event-log observers (openclaw#117169) fix(agents): keep subagent status consistent after restart and large fan-outs (openclaw#117141) refactor(ui): unify filtered session list ownership (openclaw#117158) refactor(agents): consolidate context budgets and compaction recovery (openclaw#117149) fix(net-policy): redact sig and x-* auth params in URLs and bodies (openclaw#116957) refactor(agents): remove duplicate generated-media delivery fallbacks (openclaw#117150) refactor(reply): unify turn lifecycle state ownership (openclaw#117145) fix(ui): preserve emoji agent avatar initials (openclaw#104912) refactor(auto-reply): unify command and directive ownership (openclaw#117143) refactor(plugins): consolidate descriptor and startup ownership (openclaw#117146) fix(messages): reply actions leak citation markers and reply/poll answers draw the no-reply fallback (openclaw#116909) fix(slack): let durable ingress retry transient thread lookups (openclaw#117135) refactor(doctor): consolidate shipped state migration ownership (openclaw#117142) fix(ai): Codex stream shows internal parser text on a malformed frame (openclaw#116966) fix: guard every migrated session accessor path (openclaw#117140) fix(terminal): measure unicode display width consistently (openclaw#117062) fix(openai): clear ChatGPT SSE fallback per session (openclaw#117123) fix(mistral): reject incomplete streamed tool terminals (openclaw#117137) fix(ai): preserve structured chat content and refusals (openclaw#117136) ...
* commit '55215cd9edd2b585cbaee5481d5352aabf7e4399': (368 commits) fix: allow gateway service commands for named profiles (openclaw#116314) fix(plugins): invalidate bundled artifact locations after metadata refresh (openclaw#117041) fix(ollama): honor model requests and pull completion contracts (openclaw#117171) fix(agents): prevent fallback after stale lifecycle abort (openclaw#117168) fix(telegram): confirm polling before long poll (openclaw#116970) fix(tlon): wire autoDiscoverChannels through the settings-store round-trip (openclaw#114949) fix(gateway): yield before post-ready background work (openclaw#117083) fix(ui): keep canvas lease renewals lifecycle-owned and timer-safe (openclaw#117173) fix(teams): restore the official square product icon (openclaw#117170) refactor(ui): replace duplicated locale bundles with canonical translation memory (openclaw#117157) fix(ui): retire stale Gateway event-log observers (openclaw#117169) fix(agents): keep subagent status consistent after restart and large fan-outs (openclaw#117141) refactor(ui): unify filtered session list ownership (openclaw#117158) refactor(agents): consolidate context budgets and compaction recovery (openclaw#117149) fix(net-policy): redact sig and x-* auth params in URLs and bodies (openclaw#116957) refactor(agents): remove duplicate generated-media delivery fallbacks (openclaw#117150) refactor(reply): unify turn lifecycle state ownership (openclaw#117145) fix(ui): preserve emoji agent avatar initials (openclaw#104912) refactor(auto-reply): unify command and directive ownership (openclaw#117143) refactor(plugins): consolidate descriptor and startup ownership (openclaw#117146) ...
* origin/main: (3706 commits) refactor(ui): unify filtered session list ownership (openclaw#117158) refactor(agents): consolidate context budgets and compaction recovery (openclaw#117149) fix(net-policy): redact sig and x-* auth params in URLs and bodies (openclaw#116957) refactor(agents): remove duplicate generated-media delivery fallbacks (openclaw#117150) refactor(reply): unify turn lifecycle state ownership (openclaw#117145) fix(ui): preserve emoji agent avatar initials (openclaw#104912) refactor(auto-reply): unify command and directive ownership (openclaw#117143) refactor(plugins): consolidate descriptor and startup ownership (openclaw#117146) fix(messages): reply actions leak citation markers and reply/poll answers draw the no-reply fallback (openclaw#116909) fix(slack): let durable ingress retry transient thread lookups (openclaw#117135) refactor(doctor): consolidate shipped state migration ownership (openclaw#117142) fix(ai): Codex stream shows internal parser text on a malformed frame (openclaw#116966) fix: guard every migrated session accessor path (openclaw#117140) fix(terminal): measure unicode display width consistently (openclaw#117062) fix(openai): clear ChatGPT SSE fallback per session (openclaw#117123) fix(mistral): reject incomplete streamed tool terminals (openclaw#117137) fix(ai): preserve structured chat content and refusals (openclaw#117136) fix(doctor): persist normalized agent roster (openclaw#117115) fix(signal): avoid replay after ambiguous quote delivery errors (openclaw#117134) fix(cron): reject disabled delivery accounts when scheduling (openclaw#116899) ...
What Problem This Solves
Long-running agent sessions currently maintain overlapping context-budget, tool-result truncation, worker planning, context-engine lifecycle, and overflow/timeout recovery policies. This duplication makes context-limit repairs harder to reason about and increases the risk that otherwise equivalent recovery paths preserve different session, cancellation, or token-budget facts.
Why This Change Was Made
Consolidate the existing context and compaction owner boundaries without changing public configuration or third-party context-engine contracts. Expensive planning remains isolated on real worker threads; retired worker messages are rejected; provider fallback, quarantine, background maintenance, Unicode/CJK-safe hard limits, append-only transcript recovery, and compaction summaries retain their established behavior.
This maintainer-requested, AI-assisted cleanup removes 1,046 net handwritten production lines (1,021 additions and 2,067 deletions), while adding direct regression coverage for every live worker request and the retired pruning request.
User Impact
Agent conversations continue to recover from long-context overflow, timeout pressure, oversized tool output, provider failures, and compaction retries with the same visible outcomes and transcript protections. No public configuration, plugin API, storage schema, or provider protocol changes are introduced.
Evidence
tbx_01kyxdf9veseyqgwkxbhkcaev6(amber-barnacle-d7d5), workflow https://github.com/openclaw/openclaw/actions/runs/30676985086.autoreview --mode uncommitted --stream-engine-output; clean, zero actionable findings (confidence 0.95).pnpm check:changed: passed in 3m28s; zero unused exports, both production/test type-checks and both 245-rule lint shards passed, alongside formatting, plugin/API boundaries, schema/storage, cycle, and security invariant guards.git diff --check: passed.pnpm build: passed in 2m55s; all nine unified bundle invocations, packaged worker/runtime, public plugin SDK declarations, CLI-bootstrap guard, and production Control UI build passed.pnpm openclaw --versionreturnedOpenClaw 2026.7.2 (a1b41d5).53f771c64651aa7b89cdb1dde38b6297d492a345: https://github.com/openclaw/openclaw/actions/runs/30678270158.After-fix runtime recovery proof
Ran the real
runEmbeddedAgentintegration harness against exact PR head53f771c64651aa7b89cdb1dde38b6297d492a345on isolated Blacksmith Testboxtbx_01kyxganx5a1j0qadptmfqnrkz(https://github.com/openclaw/openclaw/actions/runs/30678827882). This exercises the production embedded run loop and real session/transcript owner boundaries with controlled provider/compaction responses; it is not a unit call into the extracted helper.Actual redacted terminal output, retaining every executed scenario and omitting unrelated pattern-skipped cases:
Observable invariants asserted inside those full-run scenarios:
context overflow detected (attempt 1/3); attempting auto-compaction,auto-compaction succeeded, and no returned error. The same caller-owned session manager survives both attempts; an already-persisted inbound user turn continues from its transcript without duplicating persistence.test-sessiontorotated-session; the retry and post-compaction maintenance both userotated-sessionand/tmp/rotated-session.json; runtime settings staymode=degradedwithdegradedReason=context_overflow; the session-change callback receivesrotated-session, and the after-compaction hook receivespreviousSessionId=test-sessionplus the successor session. A separate scenario proves a partial SQLite session target still resolves its top-level successor id.timeout_recovery, forces the 200,000-token budget compaction, reports 80,000 tokens afterward, performs exactly two embedded attempts, preserves prompt-cache facts, and returns without error. Channel, thread, message, sender, provider, model, and account context are retained.test-sessiontorotated-timeout-session; its after-compaction hook observes/tmp/rotated-timeout-session.json,tokenCount=70,previousSessionId=test-session, andsessionId=rotated-timeout-session; post-compaction side effects run exactly once.exitCode: 0; its backing lease workflow can display cancellation during normal Blacksmith session cleanup.