Skip to content

fix(agents): continue timeout recovery from compacted transcript - #124000

Merged
steipete merged 1 commit into
mainfrom
fix/autoqa-refill-compaction-outcomes-v2
Aug 15, 2026
Merged

steipete merged 1 commit into
mainfrom
fix/autoqa-refill-compaction-outcomes-v2

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Closes #123989

AI-assisted change; the patch and proof were reviewed end to end.

What Problem This Solves

Fixes an issue where an embedded agent turn that timed out under high context pressure could successfully compact its session and then receive the original persisted user request again. The model could restart completed work, repeat expensive tools, or duplicate side effects instead of continuing from the compacted transcript.

Why This Change Was Made

Timeout recovery now uses the session prompt-state owner's existing compacted-transcript continuation transition, which overflow recovery already uses. The shared recovery input carries that owner once, and overflow recovery no longer adopts the same compacted successor a second time.

The repair is internal and deliberately leaves timeout/cancel/tool-execution/run-budget exclusions, hooks, token accounting, retry caps, final payload projection, provider routing, protocols, configuration, persistence shape/schema, public APIs, and security boundaries unchanged.

Sibling Codex source was inspected at 57f42a81131ccf5933e7ec5dc659c381eeb5d72b:

This confirms the host must send a continuation after adopting the compacted transcript; resending the original prompt would create another user instruction.

Production LOC: +3/-3 (net 0) | Tests: +22/-5 (net +17)

User Impact

Agents recovering from a high-context prompt timeout now continue the work already represented in the compacted transcript. Users should no longer see the original request replayed or completed work repeated by this recovery path.

Evidence

Baseline: origin/main at 295f2c0212fd759fabd5e80cecfd00fc324bb441
PR head: 5c8f9defc84ba6df6ffdc6795eec762c160bddfc

Before fix, retaining the new boundary regression while removing only the four production hunks produced:

runEmbeddedAgent timeout recovery composition
× adopts a compacted transcript and retries with a continuation prompt
AssertionError: expected 'hello' to contain 'Continue from the current transcript'
Tests: 1 failed | 64 passed (65)

Red Testbox: https://github.com/openclaw/openclaw/actions/runs/31862701555

After fix:

  • 82/82 focused tests pass across timeout recovery, the complete run-loop integration, and overflow/compaction composition.
  • The boundary test persists the first user turn, injects high-pressure timeout recovery, adopts the rotated compacted transcript, verifies the retry prompt is a continuation rather than hello, and verifies one visible final payload.
  • Timeout/cancel, compaction-timeout, tool-execution-timeout, and aggregate-run-budget exclusions remain green.
  • Hooks, retry caps, token accounting, auth-profile rotation, visible final payload preservation, and overflow single-adoption siblings remain green.
  • Source-blind isolated validation passed the named scenario and all 82 tests with zero failures or skips.
  • Targeted oxfmt passed all seven files.
  • Path-scoped check:changed passed core/core-test types, changed-file lint (0 findings), dependency/plugin/storage/webhook/pairing guards, dead-code, and runtime import cycles (0 cycles).
  • Fresh Codex autoreview on the rebased branch: clean, no accepted/actionable findings; patch correctness confidence 0.97.

Green Testbox / changed gate: https://github.com/openclaw/openclaw/actions/runs/31862811933

No changelog edit: release generation owns CHANGELOG.md.

@clawsweeper

clawsweeper Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added the agents Agent runtime and tooling label Aug 15, 2026
@steipete steipete self-assigned this Aug 15, 2026
@steipete
steipete marked this pull request as ready for review August 15, 2026 04:03
@openclaw-barnacle openclaw-barnacle Bot added the maintainer Maintainer-authored PR label Aug 15, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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. labels Aug 15, 2026
@clawsweeper

clawsweeper Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 15, 2026, 12:09 AM ET / 04:09 UTC.

ClawSweeper review

What this changes

The PR makes timeout-triggered transcript compaction prepare the compacted session’s continuation prompt before retrying an embedded agent turn.

Regression provenance

Possible regression — probable (reproduction; reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open: current main still retries timeout compaction without invoking the prompt-state continuation transition. The patch routes that recovery through the existing owner and adds an entrypoint regression test; no code finding was identified, but its stated Codex contract could not be independently inspected because the required sibling checkout is unavailable.

Priority: P2
Reviewed head: 5c8f9defc84ba6df6ffdc6795eec762c160bddfc
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch is focused and source-supported, with a useful boundary regression; the remaining Codex-source verification is a reviewer-environment gap rather than a contributor-proof failure.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR is not subject to the external-contributor proof gate; its body additionally supplies before-and-after Testbox evidence for the changed retry path.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR is not subject to the external-contributor proof gate; its body additionally supplies before-and-after Testbox evidence for the changed retry path.
Evidence reviewed 7 items Current-main defect: After successful timeout compaction, current main adopts the successor and arms the retry guard but returns without calling the prompt-state continuation preparation.
Canonical owner transition: The session prompt-state owner waits for persistence and replaces a persisted external prompt with an internal continuation prompt; this is the transition timeout recovery omitted.
Sibling recovery behavior: Overflow recovery already adopts before maintenance and uses the same continuation preparation before retry; current main redundantly adopts the compacted transcript a second time, which this PR removes.
Findings None None.
Security None None.

How this fits together

Embedded agent runs persist session prompt state and retry after failures. When high context pressure triggers compaction, the retry must continue the adopted transcript rather than submit the original user request again.

flowchart LR
  A[User turn] --> B[Embedded agent run]
  B --> C[Prompt timeout]
  C --> D[Transcript compaction]
  D --> E[Prompt-state continuation]
  E --> F[Retry attempt]
  F --> G[Final response]
Loading

Decision needed

Question Recommendation
Should this PR wait for direct inspection of the pinned Codex turn-start and compaction source before it is considered fully proven? Verify the pinned Codex contract: Inspect the cited Codex source at the PR’s pinned revision, then retain the focused host-side fix if turn-start input is confirmed to be a fresh user operation.

Why: The PR explicitly relies on that external runtime contract, and repository policy requires the acting reviewer to inspect it directly; this read-only host lacks the sibling checkout needed to do so.

Before merge

  • Resolve merge risk (P1) - The PR’s cross-runtime Codex rationale cannot be independently verified on this review host because the required sibling Codex checkout is absent; OpenClaw source and the supplied Testbox evidence support the host-side repair, but the dependency contract remains a maintainer verification gap.
Agent review details

Security

None.

PR surface

Source +14, Tests +3. Total +17 across 7 files.

View PR surface stats
Area Files Added Removed Net
Source 5 22 8 +14
Tests 2 3 0 +3
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 25 8 +17

Review metrics

Metric Value Why it matters
Production versus test LOC production +3/-3 (net 0); tests +22/-5 (net +17) The repair preserves the bug-fix net-neutral production constraint while adding focused owner and entrypoint regression coverage.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #123989
Summary: This PR is a focused candidate repair for the linked timeout-compaction prompt replay bug.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep one prompt-state-owned continuation transition for every successfully adopted compacted transcript, with exactly one adoption per overflow recovery, after the pinned Codex interaction contract is checked on an equipped review host.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep one prompt-state-owned continuation transition for every successfully adopted compacted transcript, with exactly one adoption per overflow recovery, after the pinned Codex interaction contract is checked on an equipped review host.

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

Yes—current main’s timeout path omits the existing continuation transition, and the PR-head boundary test directly asserts the resulting retry prompt after a persisted user turn and successful compaction.

Is this the best way to solve the issue?

Unclear—the owner-boundary repair is the narrowest OpenClaw solution and matches overflow recovery, but the PR’s explicit Codex contract rationale still needs direct source verification.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 45a575769240.

Labels

Label changes:

  • add P2: The patch addresses a bounded embedded-agent recovery defect that can replay completed work after timeout-triggered compaction.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored PR is not subject to the external-contributor proof gate; its body additionally supplies before-and-after Testbox evidence for the changed retry path.

Label justifications:

  • P2: The patch addresses a bounded embedded-agent recovery defect that can replay completed work after timeout-triggered compaction.
  • 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: This maintainer-authored PR is not subject to the external-contributor proof gate; its body additionally supplies before-and-after Testbox evidence for the changed retry path.

Evidence

What I checked:

Likely related people:

  • scotthuang: Current main blame attributes the continuation transition and surrounding recovery composition to the same area commit. (role: current prompt-state and recovery contributor; confidence: high; commits: dd67c3bdf09c; files: src/agents/embedded-agent-runner/run/session-prompt-state.ts, src/agents/embedded-agent-runner/run/attempt-recovery.ts, src/agents/embedded-agent-runner/run/overflow-context-recovery.ts)

Rank-up moves

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

  • Verify the PR body’s pinned Codex source references on a review host with the required sibling checkout.

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.

@steipete

Copy link
Copy Markdown
Contributor Author

Rank-up move applied: I personally inspected the required sibling ../codex checkout at 57f42a81131ccf5933e7ec5dc659c381eeb5d72b.

  • codex-rs/core/src/compact.rs:59-65 defines mid-turn compaction around the last real user message.
  • codex-rs/core/src/compact.rs:342-378 rebuilds and atomically replaces compacted history while retaining collected user messages and the summary.
  • codex-rs/core/src/session/turn.rs:435-460 runs mid-turn compaction and continues the same turn.
  • codex-rs/core/src/compact_remote.rs:304-320 applies the same last-user placement to remote compaction.
  • codex-rs/app-server/src/request_processors/turn_processor.rs:512-565 maps every turn/start input and submits it as a fresh Op::UserInput.

That contract confirms the host-side invariant: after OpenClaw adopts a successful compacted transcript, resending the original persisted prompt would create another user instruction. The retry must use the prompt-state owner's continuation prompt. The PR body links these exact public source ranges. No skip is needed for this rank-up move, and no code change follows from the verification.

@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready proof for head 5c8f9defc84ba6df6ffdc6795eec762c160bddfc:

Focused proof command:

pnpm test src/agents/embedded-agent-runner/run.overflow-compaction.test.ts src/agents/embedded-agent-runner/run.timeout-context-recovery.test.ts src/agents/embedded-agent-runner/run.shared-integration.test.ts -- --reporter=verbose

Changed gate command was path-scoped to the seven PR files through node scripts/check-changed.mjs -- <paths> on Blacksmith Testbox.

Known proof gaps: none for this bounded host-owned invariant. No live external provider is required; the defect and repair are deterministic at the embedded run-loop/model-boundary composition.

@steipete
steipete merged commit e530b58 into main Aug 15, 2026
254 checks passed
@steipete
steipete deleted the fix/autoqa-refill-compaction-outcomes-v2 branch August 15, 2026 04:27
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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 P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS 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.

[Bug]: Timeout compaction retry replays the original persisted prompt

1 participant