Repository navigation
fix(agents): avoid false compaction after mid-turn precheck - #117963
Conversation
|
Codex review: needs maintainer review before merge. Reviewed August 3, 2026, 9:09 AM ET / 13:09 UTC. ClawSweeper reviewWhat this changesThe PR lets a mid-turn tool-result precheck continue an unchanged transcript when persisted truncation has nothing left to shorten, while excluding successful tool-progress continuations from the recovery retry budget. Merge readinessKeep open for maintainer review. Current main still turns the exact persisted no-op truncation result into synthetic overflow and compaction; this branch replaces that with a transcript continuation and correctly preserves the bounded retry budget for genuine recovery. The remaining question is intentional product behavior: accept one provider attempt after the heuristic cannot change persisted history, or redesign the two context views together. Priority: P2 Review scores
Verification
How this fits togetherThe embedded agent runner sends prompts built from persisted session history and can preflight context pressure after tool output. The preflight either trims stored tool results, triggers compaction recovery, or—under this PR—continues the current transcript so the provider can make the authoritative context decision. flowchart LR
A[Tool result added] --> B[Mid-turn context precheck]
B --> C[Persisted transcript truncation]
C --> D{Anything to trim?}
D -->|Yes| E[Retry with trimmed history]
D -->|No| F[Continue current transcript]
F --> G[Provider attempt]
G --> H[Provider overflow recovery]
G --> I[Normal agent progress]
Decision needed
Why: The patch is mechanically narrow and preserves the existing recovery cap for no-progress paths, but choosing provider rejection over immediate compaction defines the product behavior for disagreement between the in-memory estimate and persisted transcript. Before merge
Agent review detailsSecurityNone. PR surfaceSource +191, Tests +134. Total +325 across 9 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Accept the narrow persisted-no-op continuation if provider rejection is the intended authority after recovery cannot alter stored history; keep the retry classification limited to successful tool progress and track any broader alignment of in-memory prompt estimation with persisted transcript state separately. Do we have a high-confidence way to reproduce the issue? Yes—source reproducible. Current main maps the persisted "no oversized or aggregate tool results" outcome to synthetic overflow and compaction; the PR's focused tests model the unchanged-transcript continuation and subsequent provider-overflow fallback, though this read-only review did not execute them. Is this the best way to solve the issue? Unclear pending maintainer intent. The patch is the narrowest maintainable repair for false compaction and repairs the prior retry-budget issue, but it intentionally leaves the estimate-versus-persisted-state mismatch in place. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 096c929ecf6e. LabelsLabel 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
HistoryReview history (5 earlier review cycles)
|
fa849c6 to
660abe5
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
660abe5 to
2523566
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 252356679d
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Merged via squash.
|
* origin/main: (57 commits) fix(media): fall back when providers return empty output (#118660) fix(nextcloud-talk): allow bounded parallel room deliveries (#118692) test(state): reuse current agent database fixture (#118677) fix(scripts): bound check-file-utils git lookup (#111582) fix(slack): scope interactive conversation bindings safely (#118662) fix(agents): avoid false compaction after mid-turn precheck (#117963) fix(ui): show original filename on chat history attachment cards instead of managed UUID suffix (#118628) fix(whatsapp): preserve terminal retry exhaustion lifecycle (#118659) fix(doctor): audit every agent workspace (#111840) fix(release): skip unavailable Buzz on frozen candidates (#118670) fix(ui): surface onboarding and pairing clipboard failures (#118651) fix(config): stop plugin schemas rejecting the channel key core writes (#117992) test(memory): isolate wiki plugin fixtures (#118654) fix(line): clear default access token when removing account (#118055) feat: enable rich setup controls in custodian chat (#114631) test(ui): reuse responsive browser fixtures (#118655) chore(tui): stabilize queued-turn admission in Gateway PTY test (#118638) fix(xai): classify exhausted credits as billing (#118615) fix(otel): fail closed when configured TLS material is invalid (#118648) fix(cli): preserve gateway request errors in health JSON (#118645) ...
…#117963) * fix(agents): avoid false compaction after mid-turn precheck * fix(agents): preserve retry budget for tool progress
* origin/main: (57 commits) fix(media): fall back when providers return empty output (openclaw#118660) fix(nextcloud-talk): allow bounded parallel room deliveries (openclaw#118692) test(state): reuse current agent database fixture (openclaw#118677) fix(scripts): bound check-file-utils git lookup (openclaw#111582) fix(slack): scope interactive conversation bindings safely (openclaw#118662) fix(agents): avoid false compaction after mid-turn precheck (openclaw#117963) fix(ui): show original filename on chat history attachment cards instead of managed UUID suffix (openclaw#118628) fix(whatsapp): preserve terminal retry exhaustion lifecycle (openclaw#118659) fix(doctor): audit every agent workspace (openclaw#111840) fix(release): skip unavailable Buzz on frozen candidates (openclaw#118670) fix(ui): surface onboarding and pairing clipboard failures (openclaw#118651) fix(config): stop plugin schemas rejecting the channel key core writes (openclaw#117992) test(memory): isolate wiki plugin fixtures (openclaw#118654) fix(line): clear default access token when removing account (openclaw#118055) feat: enable rich setup controls in custodian chat (openclaw#114631) test(ui): reuse responsive browser fixtures (openclaw#118655) chore(tui): stabilize queued-turn admission in Gateway PTY test (openclaw#118638) fix(xai): classify exhausted credits as billing (openclaw#118615) fix(otel): fail closed when configured TLS material is invalid (openclaw#118648) fix(cli): preserve gateway request errors in health JSON (openclaw#118645) ...
…allbackReason=no oversized or aggregate tool results` This backports openclaw/openclaw#117963 to current OpenClaw 2026.7.1-2 used by ClawX.
…allbackReason=no oversized or aggregate tool results` This backports openclaw/openclaw#117963 to current OpenClaw 2026.7.1-2 used by ClawX.
What Problem This Solves
Fixes an issue where tool-heavy runs could enter compaction even though the saved session had no tool output left to shorten.
The failure happens when the mid-turn estimate chooses tool-result truncation, but persisted truncation reports
no oversized or aggregate tool results. OpenClaw currently converts that no-op into a synthetic context overflow and compacts without first receiving a provider rejection.Why This Change Was Made
The narrow change treats only that exact already-capped result as a handled no-op. OpenClaw continues once from the current transcript without changing history; empty-session and truncation-error cases retain the existing compaction fallback.
The retry also preserves prompt-cache identity and carries the latest MCP App view across the early retry. A genuine provider context rejection still enters the normal compaction recovery path.
User Impact
Affected tool-heavy turns should avoid an unnecessary compaction and cache-prefix break when persisted truncation is already a no-op.
Truly oversized requests still compact after the provider rejects them.
Evidence
The focused tests cover unchanged persisted history, one continuation, duplicate-turn suppression, stable prompt-cache identity, MCP App view preservation, and genuine provider-overflow recovery.
node scripts/run-vitest.mjs src/agents/embedded-agent-runner/run/attempt-prompt-preflight.test.ts— 7 passednode scripts/run-vitest.mjs src/agents/embedded-agent-runner/run.overflow-compaction.loop.test.ts— 41 passed on Node 24git diff --checkRisks
This is intentionally narrow and does not remove the two-view mismatch that caused the bad routing decision.
no oversized or aggregate tool resultsreason.