Skip to content

fix(agents): avoid false compaction after mid-turn precheck - #117963

Merged
osolmaz merged 2 commits into
openclaw:mainfrom
osolmaz:osolmaz/midturn-precheck-noop
Aug 3, 2026
Merged

osolmaz merged 2 commits into
openclaw:mainfrom
osolmaz:osolmaz/midturn-precheck-noop

Conversation

@osolmaz

@osolmaz osolmaz commented Aug 2, 2026 •

Copy link
Copy Markdown
Member

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 passed
  • node scripts/run-vitest.mjs src/agents/embedded-agent-runner/run.overflow-compaction.loop.test.ts — 41 passed on Node 24
  • git diff --check
  • Final Codex review: no actionable regressions found

Risks

This is intentionally narrow and does not remove the two-view mismatch that caused the bad routing decision.

  • A real overflow now incurs one provider rejection before normal recovery.
  • The handled no-op is restricted to the exact no oversized or aggregate tool results reason.
  • Other truncation failures continue using the existing compaction fallback.
  • Mid-turn precheck remains opt-in and disabled by default.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S maintainer Maintainer-authored PR labels Aug 2, 2026
@clawsweeper clawsweeper Bot added 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. P2 Normal backlog priority with limited blast radius. labels Aug 2, 2026
@clawsweeper

clawsweeper Bot commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 3, 2026, 9:09 AM ET / 13:09 UTC.

ClawSweeper review

What this changes

The 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 readiness

⚠️ Ready for maintainer review - 4 items remain

Keep 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
Reviewed head: f3f27321f8e760be7549b34d0c086c16e3c83af5
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch is focused, addresses the prior retry-limit concern, and has targeted shared-run coverage; merge readiness now depends on the maintainer’s recovery-policy choice.
Proof confidence 🌊 off-meta tidepool Not applicable: The PR author is a repository MEMBER, so the external-contributor real-behavior-proof gate does not apply; the supplied body and checks report focused after-fix harness coverage.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The PR author is a repository MEMBER, so the external-contributor real-behavior-proof gate does not apply; the supplied body and checks report focused after-fix harness coverage.
Evidence reviewed 6 items Current main takes the false-compaction path: When truncation produces no replacements, current main unconditionally changes the route to compact-only and creates the synthetic preemptive-overflow error; it has no no-op continuation branch.
PR isolates the changed recovery boundary: The branch recognizes only the authoritative persisted result "no oversized or aggregate tool results", returns handled truncation with zero changes, and leaves history untouched so normalization can continue from the current transcript.
Retry accounting preserves the prior review invariant: The outer loop records only the normalized early-retry kind; the new helper removes a counted attempt solely for a mid-turn zero-truncation continuation with at least one non-error tool result. Other retries remain counted.
Findings None None.
Security None None.

How this fits together

The 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]
Loading

Decision needed

Question Recommendation
Should mid-turn preflight defer to one provider attempt when persisted tool-result truncation reports that there is nothing left to shorten, rather than compacting the session from a synthetic overflow? Land the narrow continuation: Treat the persisted no-op as evidence that local recovery cannot help, continue once from the current transcript, and retain normal compaction only for an actual provider overflow.

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

  • Resolve merge risk (P1) - This deliberately changes recovery semantics: when persisted truncation cannot change history, the provider receives one attempt that the in-memory heuristic predicted could exceed context; only a real provider rejection enters normal compaction.
  • Resolve merge risk (P1) - Successful no-op continuations no longer consume the global recovery limit, so maintainers need to accept tool-result success as the canonical progress fact for this narrow path.
  • Complete next step (P2) - A maintainer must choose the intended recovery policy before merge; there is no discrete remaining mechanical defect for an automated repair lane.
Agent review details

Security

None.

PR surface

Source +191, Tests +134. Total +325 across 9 files.

View PR surface stats
Area Files Added Removed Net
Source 5 204 13 +191
Tests 4 135 1 +134
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 9 339 14 +325

Review metrics

Metric Value Why it matters
Production versus test delta production +73 net (86 added, 13 deleted); tests +253 net (254 added, 1 deleted) The production growth creates an explicit retry-budget owner boundary and is paired with direct helper and shared-run coverage for the new continuation semantics.

Stored data model

Persistent data-model change detected: serialized state: src/agents/embedded-agent-runner/run.midturn-precheck-retry.test-support.ts, serialized state: src/agents/embedded-agent-runner/run/attempt-prompt-preflight.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Land with the bounded continuation (recommended)
    Merge the retry-budget path after confirming maintainers want a successful tool result to exempt only this no-op transcript continuation from recovery counting.
  2. Pause for a unified preflight design
    Keep the PR open but do not merge until the owner decides whether the in-memory estimate and persisted session should be reconciled at the preflight boundary.

Technical review

Best 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.

Labels

Label justifications:

  • P2: The change repairs a bounded agent-session compaction path without evidence of an emergency availability or data-loss regression.
  • merge-risk: 🚨 session-state: Merging changes whether a persisted agent transcript is compacted or retried unchanged after a mid-turn context precheck.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The PR author is a repository MEMBER, so the external-contributor real-behavior-proof gate does not apply; the supplied body and checks report focused after-fix harness coverage.

Evidence

What I checked:

Likely related people:

  • joshavant: Current main blames the relevant preflight, normalization, and outer-loop retry behavior to this recent agent-runner change. (role: recent area contributor; confidence: high; commits: d0439b9ce0f4; files: src/agents/embedded-agent-runner/run-loop.ts, src/agents/embedded-agent-runner/run/attempt-prompt-preflight.ts, src/agents/embedded-agent-runner/run/attempt-normalization.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Confirm the intended authority when preflight estimation and persisted transcript recovery disagree.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (5 earlier review cycles)
  • reviewed 2026-08-02T10:51:18.901Z sha fa849c6c45b2ea1d36108bf55956b54dcdbf07e8 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-03T08:42:20.903Z sha 660abe5cfc94eaa5dda8106f1b4ddbb76109c044 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-03T09:17:53.043Z sha 660abe5cfc94eaa5dda8106f1b4ddbb76109c044 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-03T10:12:39.115Z sha 2523566 :: found issues before merge. :: [P2] Keep no-op continuations out of the global retry budget
  • reviewed 2026-08-03T13:02:20.844Z sha f3f2732 :: needs maintainer review before merge. :: none

@osolmaz
osolmaz force-pushed the osolmaz/midturn-precheck-noop branch from fa849c6 to 660abe5 Compare August 3, 2026 08:12
@osolmaz

osolmaz commented Aug 3, 2026

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Aug 3, 2026
@osolmaz osolmaz self-assigned this Aug 3, 2026
@osolmaz
osolmaz force-pushed the osolmaz/midturn-precheck-noop branch from 660abe5 to 2523566 Compare August 3, 2026 09:59
@osolmaz
osolmaz marked this pull request as ready for review August 3, 2026 09:59

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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 clawsweeper Bot added merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 3, 2026
@osolmaz

osolmaz commented Aug 3, 2026

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added 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 rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 3, 2026
@osolmaz
osolmaz merged commit f7434f9 into openclaw:main Aug 3, 2026
129 of 137 checks passed
@osolmaz
osolmaz deleted the osolmaz/midturn-precheck-noop branch August 3, 2026 13:38
@osolmaz

osolmaz commented Aug 3, 2026

Copy link
Copy Markdown
Member Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Aug 3, 2026
* 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)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 4, 2026
…#117963)

* fix(agents): avoid false compaction after mid-turn precheck

* fix(agents): preserve retry budget for tool progress
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 4, 2026
* 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)
  ...
z0gSh1u added a commit to ValueCell-ai/ClawX that referenced this pull request Aug 25, 2026
…allbackReason=no oversized or aggregate tool results`

This backports openclaw/openclaw#117963 to current OpenClaw 2026.7.1-2 used by ClawX.
z0gSh1u added a commit to ValueCell-ai/ClawX that referenced this pull request Aug 25, 2026
…allbackReason=no oversized or aggregate tool results`

This backports openclaw/openclaw#117963 to current OpenClaw 2026.7.1-2 used by ClawX.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. 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

Development

Successfully merging this pull request may close these issues.

1 participant