Skip to content

fix: agent answers previous request after transient retry - #165593

Closed
Baumus wants to merge 3 commits into
openclaw:mainfrom
Baumus:fix/165463-preserve-current-request
Closed

Baumus wants to merge 3 commits into
openclaw:mainfrom
Baumus:fix/165463-preserve-current-request

Conversation

@Baumus

@Baumus Baumus commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Related: #165463
Alternative to #165540 for the observed fenced-history case.

What Problem This Solves

Fixes: after a transient same-model retry, an agent can answer an earlier task because the rebuilt model input no longer contains the current user request.

User Impact

The retry receives the current request and can continue the active task. A missing request fails visibly. The retry still avoids persisting another user turn or replaying settled tools.

Why This Change Was Made

PR #165540 changes the Codex renderer so it retains the admitted user message if that message reaches projected history. The observed retry had a different input: projected history ended at the earlier task, and the current prompt was only the generic continuation instruction.

Rebuilt history Effect of #165540 alone This PR
Contains Task B Retains Task B Also supplies Task B in the retry prompt
Ends at Task A, as observed Has no Task B row to retain Supplies the original Task B request in the retry prompt

The source explains the gap: the Codex history reader passes the admission receipt into a fenced read, and the SQLite context read limits rows to before the admitted turn. #165540's test supplies Task B directly in a fake assembly and returns no admission receipt, so it does not exercise this fenced case. This is a source-level explanation of the observed missing input, not a completed isolated live fault-injection reproduction.

This PR puts the original request in the shared transient retry prompt, independent of whether projected history contains the admitted row. If #165540 also lands, Codex may see Task B twice; maintainers should choose one approach or deduplicate the combined path.

Evidence

The sanitized live report records two cases: an overload before any output, and one after on-topic progress plus a read-only tool call. In both, the first model input contained Task B; the retry input contained no Task B and the agent answered Task A. Task A/B are placeholders; no private task content, transcript, identity, path, session ID, endpoint, or credential is included here.

After-fix live observation from a natural overload on the installed release with the equivalent one-file hotfix (read-only analysis; raw logs are withheld):

2026-10-05 15:26 CEST  gateway: transient same-model retry (overloaded)
first Codex attempt: current request present; assistant items=0; tool calls=0
retry Codex attempt: original model input retained verbatim;
                     added request label + continuation instruction
retry outcome: assistant items=7; Codex terminal event=task_complete

The first attempt had no completed action to replay. This shows request retention and a completed real Codex retry for the before-output case. It does not establish that the final answer was semantically on-task, or prove recovery after partial progress. No private prompt, transcript, identity, path, session ID, endpoint, or credential is published.

The complete focused prompt-state and recovery test files passed (2 Vitest shards, 86.86 s), including the corrected output-limit assertion and the mocked after-progress overload case. Formatting, lint, and TypeScript core checks passed. A controlled, injected live overload after the fix has not been run.

@clawsweeper

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

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS labels Oct 5, 2026
@Baumus
Baumus marked this pull request as ready for review October 5, 2026 13:34
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 5, 2026
@clawsweeper

clawsweeper Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed October 5, 2026, 11:26 AM ET / 15:26 UTC (Revision 3).

ClawSweeper review

What this changes

The agent runner includes the original request in transient retry prompts, retains instructions to preserve completed work, and rejects an empty request.

Merge readiness

⛔ Blocked before merge - 2 items remain

This focused fix remains useful: current main still replaces the request with generic continuation text, and neither related alternative has merged. No introduced correctness defect was found, but the supplied live evidence does not yet establish the central answering and continuation behavior.

Likely related people: Peter Steinberger and changeroa are routing candidates from merged retry-path history; source-line introduction remains unverified.

Priority: P1
Reviewed head: ee0517578c26e6fd22786f734114ecd6252580c1

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The patch is focused and source-supported, with useful partial live evidence that does not yet prove its complete recovery claim.
Proof confidence 🦐 gold shrimp (3/6) Needs stronger real behavior proof before merge: The shared retry-prompt owner has positive real Codex evidence from a natural before-output overload with an equivalent hotfix: the request remained present and the retry completed. The contributor explicitly leaves an on-task answer and continuation after partial progress without repeated completed actions unproven. No stored-data contract changes. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Needs proof Needs stronger real behavior proof before merge: The shared retry-prompt owner has positive real Codex evidence from a natural before-output overload with an equivalent hotfix: the request remained present and the retry completed. The contributor explicitly leaves an on-task answer and continuation after partial progress without repeated completed actions unproven. No stored-data contract changes. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 11 items Verified introduced change: The pinned base-to-head delta changes only prompt state, the transient recovery call, and their focused tests. The checkout is the original PR head, rather than the separately recorded GitHub test merge.
Current main still needs request retention: Fetched main retains the raw-model exception but otherwise activates only the generic continuation prompt. It does not contain this PR's request-bearing continuation option.
Continuation and persistence controls: The changed path adds the original request while retaining the existing continuation instruction, internal-prompt flag, and suppression of another persisted user turn. Dispatch consumes that override and skips prepared-user submission for internal prompts; raw model runs retain their existing original-prompt behavior.
Findings None None.
Security None None.

How this fits together

The embedded agent runner builds model input and recovers interrupted attempts. Its retry prompt and conversation history determine which task the model continues and which completed actions it can see.

flowchart TD
  A[Current user request] --> B[Agent attempt]
  B --> C[Transient failure]
  C --> D[Retry recovery]
  A --> E[Request and continuation prompt]
  D --> E
  F[Conversation history] --> G[Model retry]
  E --> G
  G --> H[Continued answer]
Loading

Before merge

  • Add real behavior proof - Needs stronger real behavior proof before merge: The shared retry-prompt owner has positive real Codex evidence from a natural before-output overload with an equivalent hotfix: the request remained present and the retry completed. The contributor explicitly leaves an on-task answer and continuation after partial progress without repeated completed actions unproven. No stored-data contract changes. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Complete next step (P2) - Add after-fix evidence showing an on-task answer and recovery after partial progress without repeating completed actions. Redacted terminal output, logs, or a diagnostic recording are suitable; remove private prompts, credentials, identifiers, and endpoints. Update the PR body to trigger re-review automatically; if needed, ask a maintainer to comment @clawsweeper re-review.
Agent review details

Security

None.

PR surface

Source +11, Tests +31. Total +42 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 13 2 +11
Tests 2 31 0 +31
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 44 2 +42

Review metrics

None.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #165463
Summary: This PR is a candidate repair for the dashboard retry report; related PRs address overlapping reconstruction or distinct pre-enqueue recovery paths.

Members:

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

Technical review

Best possible solution:

Keep the current request visible through the existing retry owner while preserving completed-work context and avoiding another persisted user turn.

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

Yes, source establishes the missing-input path: generic continuation replaces the original request while the admission-fenced history can exclude it. This review did not execute a failing current-main run.

Is this the best way to solve the issue?

Yes, retaining the request in the existing continuation prompt is a narrow repair that covers history missing the admitted row; live evidence must still establish correct continuation after partial progress.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 68f038c9467c.

Labels

Label changes:

No label changes.

Label justifications:

  • P1: Reported overload recovery produces successful-looking answers to an earlier task in ordinary dashboard conversations.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The shared retry-prompt owner has positive real Codex evidence from a natural before-output overload with an equivalent hotfix: the request remained present and the retry completed. The contributor explicitly leaves an on-task answer and continuation after partial progress without repeated completed actions unproven. No stored-data contract changes. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • changeroa: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

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

  • Add redacted after-fix evidence showing an on-task answer and continuation after partial progress without repeating a completed action.

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 (2 earlier review cycles)
  • reviewed 2026-10-05T13:42:54.051Z sha 1f21e1f :: needs real behavior proof before merge. :: [P2] Update the output-limit recovery assertion for the new option
  • reviewed 2026-10-05T14:09:46.252Z sha 0531b45 :: needs real behavior proof before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Oct 5, 2026

@Yigtwxx Yigtwxx 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.

Reviewed head ee0517578c2. The body's central claim is a source reading, and #165540 depends on the opposite reading, so I measured it on the real Codex projection path. Short version: the claim holds. The same fence also hides the current turn's progress, which matters for the second incident in #165463.

1. Fenced history drops the admitted request (measured)

Probe (temporary test file next to run-attempt.context-engine.test.ts, not committed): createSqliteParams-style SQLite target, a real UserTurnTranscriptRecorder from loadUserTurnTranscriptRecorderFactoryForTest(), Task A persisted with persistApproved(), then Task B persisted as the admitted turn. Codex attempt, no context engine, skipPreparedUserTurnMessage: true, prompt = the continuation text. I read the turn/start input text. There are two arms: the real recorder (fenced), and the same recorder with getAdmissionReceipt returning undefined, which is the shape #165540's test uses.

head fenced (production recorder) receipt undefined
main 0907ac29619 Task B absent Task B absent
#165540 5e621df90ef Task B absent Task B present

The fence cuts at seq < beforeRawSeq, and beforeRawSeq is the admitted user row itself (session-transcript-read-fence.ts:227, session-accessor.sqlite-model-context.ts:504). The repo already relies on this: the admitted-continuation scenario in run-attempt.plugin-refresh.test.ts:191-199 injects the persisted admitted message into pluginRuntimeRefreshMessages explicitly. It does not expect history to carry it.

2. The fence also hides the current turn's progress

The cut is at the admitted row, so everything the failed attempt wrote after it is excluded as well. I ran the same probe with an assistant message appended after Task B and the prompt shaped exactly like this PR's retry prompt (Current user request:\n${prompt}\n\n${CONTINUATION_PROMPT}):

{"hasTaskA":true,"hasTaskB":true,"hasProgress":false,"headerCount":2}

<conversation_context>
[user]
Task A: list the open invoices
</conversation_context>

Current user request:
Current user request:
Task B: summarize the migration plan

Continue the current task from the existing transcript, preserving completed work. If an action was interrupted, inspect its state before deciding whether to retry it. Do not restart the task or repeat completed actions.

The appended message was PROGRESS: sent the migration summary to the team channel, and it does not reach the model. For a retry that renders the bounded continuity projection (the trace in #165463 carried conversation_context), this PR restores Task B. The model still cannot see what the failed attempt already did. That is the issue's second incident, where a progress message and a tool call came before server_overloaded. On main the model answers the wrong task. With this PR it answers the right task, but it is told not to repeat actions it cannot see, so a non-idempotent action from the first attempt (a sent message, a write) can run twice. I did not run that end to end; the probe shows only the model input.

Two ways to close it:

  • (a) State in the body that the fix targets the before-output case (incident 1) and track incident 2 separately.
  • (b) For internal retries, read history through the latest settled entry of the current turn instead of stopping at the admitted row. That fixes the request and the progress at the history owner, and the prompt text would not need to change.

A smaller point: the header is printed twice, because the Codex renderer already prefixes Current user request:. Labelling the inline block Original user request: avoids the stacked header.

3. Other bare continuation producers are unchanged

includeCurrentUserRequest: true is passed only from the transient path (attempt-recovery.ts:464 on this head). These sites still activate the bare continuation, and under the same fence they would produce the same Task-B-less input:

I did not drive these with the Codex harness, so I am not claiming each one is reachable there. I'm listing them so the scope is an explicit choice. If option (b) above is taken, all of them are covered at once. If the prompt-side approach stays, making the request part of every internal continuation inside session-prompt-state.ts would cover them with one change instead of a flag per caller.

4. Stale invariant comment

attempt-recovery.ts:390 still says "never resubmit the original user request" (added in #139397). The request is now resubmitted inside the internal prompt, though it is not persisted. The comment should say that, so the next reader does not treat this PR as a violation.

Relation to the sibling PRs

#165540 #165593 (this) #165626
Change Codex history keeps the admitted message on internal prompts Transient retry prompt carries the request Codex turn/start -32001 replays the original prompt
Production fenced path, Task B no change (measured) restored not applicable: returns retry() before continueFromCurrentTranscript
Current-turn progress visible to the retry no no not applicable (turn never accepted)
git merge-tree vs main and pairwise clean clean clean

#165626 is orthogonal and composes with this PR. If #165540 and this PR both land, the receipt-less path shows Task B twice (once in history, once in the prompt).

steipete added a commit that referenced this pull request Oct 8, 2026
Carry the current request and settled attempt snapshots through the optional
harness continuation contract. Codex projects completed work alongside its
admission-fenced history; later plugin refreshes retain the same facts.

Builds on #165593 by @Baumus. Regression and fresh-machine Gateway fault
injection cover overloads before work and after a completed read.

Fixes #165463

Co-authored-by: Baumus <[email protected]>
@steipete

steipete commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Thank you @Baumus. Your fix and tests were the starting point for #166868, merged as be4c0b1 with you credited as co-author. That PR restores the current request on same-model overload retries and also carries the failed attempt's completed tool results through an optional host-owned continuation, so the retry neither answers the previous task nor re-runs completed tools. Closing this one as superseded by #166868.

@steipete steipete closed this Oct 8, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 8, 2026
…6868)

Carry the current request and settled attempt snapshots through the optional
harness continuation contract. Codex projects completed work alongside its
admission-fenced history; later plugin refreshes retain the same facts.

Builds on openclaw#165593 by @Baumus. Regression and fresh-machine Gateway fault
injection cover overloads before work and after a completed read.

Fixes openclaw#165463

Co-authored-by: Baumus <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XS status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants