Skip to content

fix(codex): let delivered final replies finish without false cancellation - #174490

Open
quqi1599 wants to merge 1 commit into
openclaw:mainfrom
quqi1599:fix/codex-final-reply-settlement
Open

quqi1599 wants to merge 1 commit into
openclaw:mainfrom
quqi1599:fix/codex-final-reply-settlement

Conversation

@quqi1599

Copy link
Copy Markdown
Contributor

Related: #111019
Related approach: #111020

What Problem This Solves

Fixes successful final message-tool replies being recorded as user-canceled turns in the native Codex conversation. This polluted later conversation context and was observed alongside repeated incorrect explanations that earlier replies had failed to send.

User Impact

Ordinary final replies can finish with a successful native tool result and native turn/completed, rather than a false interruption marker. Real cancellation and sessions_yield keep their existing behavior.

The session remains occupied during a bounded completion grace of up to ten seconds after the terminal tool batch settles. If Codex does not finish in that window, the existing interrupt fallback still runs and can still leave an interruption marker. No new configuration or migration is required.

Why This Change Was Made

After confirmed final source delivery, retain the native turn briefly instead of immediately interrupting its enclosing tool call. Use one absolute timer; native completion and attempt teardown clear it. The fallback checks cancellation and an already-received native terminal before interrupting. Existing sibling-result admission, steering cancellation, delivery deduplication, and yield cleanup stay with their current owners.

This is an independently implemented, narrower alternative to the bounded-native-completion approach already proposed in #111020, based on current main. It deliberately leaves the issue's sessions_yield case open and does not add new post-final request-admission policy or an immediate-inbound grace bypass. Existing steering rejection/queue fallback remains in force during the wait.

Evidence

  • Live shipped-version reproduction and sanitized channel/native-log correlation: codex: clean final:true / sessions_yield close interrupts the turn, writing a false "user interrupted" marker into the thread rollout #111019 (comment)
  • Before the fix, two added production-path regressions failed on the unwanted turn/interrupt after successful delivery. Afterward, natural completion, real cancellation during grace, and bounded fallback pass through runCodexAppServerAttempt with protocol fixtures.
  • Five focused files: 83 tests passed, approximately 46 seconds total runner wall time. Covers the attempt boundary, failed-sibling completion in both orders, yield handoff, native cleanup, source delivery, and post-final output projection. The final controller-only rerun also passes all 44 cases.
  • Codex package typecheck, targeted test typecheck with repository ambient declarations, type-aware lint, formatting, and git diff --check pass.
  • Independent autoreview found no actionable P0–P2 findings with full lifecycle source context. Simplification kept the existing release operation shared between the yield path and the final-reply timeout; production growth is limited to the grace timer and its cleanup.
  • Personally inspected Codex's interruption contract: handle_task_abort persists interruption guidance; TurnInterruptParams has no clean-completion reason field.

Validation limits: the new source was tested against deterministic protocol fixtures, not a live model or a live messaging account. Broad suites and CI duration remain for PR CI. The installed production gateway and native history were not modified.

AI assistance disclosure: implemented and reviewed with Codex assistance. Maintainer edits are enabled.

@clawsweeper

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

@quqi1599
quqi1599 marked this pull request as ready for review October 16, 2026 17:35
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation extensions: codex size: S labels Oct 16, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 16, 2026
@clawsweeper

clawsweeper Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

The PR gives Codex ten seconds to finish naturally after a confirmed final source reply before falling back to interruption.

Example: The message tool successfully sends "Synthetic final reply." with final:true.

  • Before: OpenClaw immediately interrupts Codex, which can persist a false user-interruption marker.
  • After: Codex can complete naturally within ten seconds; cancellation and timeout fallback still interrupt.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The repair is focused and source-grounded, but required real-client proof is absent, an existing test hangs, and completion policy awaits an owner decision.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🦪 silver shellfish (2/6) 1 actionable review finding remain.

Product

Kind: Bug fix · Worth it: Needs a maintainer decision · Fix scope: Partial
User problem: Later Codex turns can treat successfully delivered replies as canceled because native history contains false interruption records.
Reason: The defect merits repair, but the bounded wait changes existing completion behavior and covers only the final-message portion of the linked issue.

Merge readiness

⛔ Blocked before merge - 3 items remain

Keep open: this PR addresses a confirmed current-release defect, but it breaks an existing durable-history test and needs an owner decision on completion timing.

Priority: P1
Reviewed head: 08d7059dbf2b693c2b21d787b066d31014cf3433
Owner decision: Required. See Decision needed.

Decision needed

  • Question: Should final source delivery keep the native turn live for up to ten seconds, permitting further native work and delaying queued inbound messages, while sessions_yield retains immediate interruption?
  • Recommendation: Accept bounded final-reply completion: Accept the documented ten-second grace and queued-inbound behavior for this focused repair, with yield remaining separately tracked.
  • Why: This changes the lifecycle owner's immediate-completion contract, and neither this PR nor the linked discussion records maintainer approval of that tradeoff.

Before merge

  • Add real behavior proof - The supplied after-fix evidence exercises runCodexAppServerAttempt with protocol fixtures and a mocked message tool, rather than the real Codex client; the linked live logs establish the before-fix failure only. Provide redacted terminal output or logs from patched OpenClaw showing successful native completion without turn/interrupt or an abort marker, plus cancellation and bounded fallback controls; redact IPs, API keys, phone numbers, and non-public endpoints. After adding proof, update the PR body, then request a new review with @clawsweeper re-review. The PR author or someone with repository write access can request it.
  • Update the durable-history fixture for deferred completion (P2) - This test freezes setTimeout and then waits for turn/interrupt after successful message delivery. The introduced grace timer cannot fire because the test never advances it, and native completion is supplied only after the blocked wait. Exact-head CI consequently times out this case after 120 seconds. Update the fixture to supply natural turn completion, or explicitly advance the grace timer when testing fallback, while retaining its same-thread history-coverage assertions.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.

Findings

  • [P2] Update the durable-history fixture for deferred completion — extensions/codex/src/app-server/run-attempt.durable-context.test.ts:246-249

Tests

  • Missing end-to-end proof: Show patched OpenClaw completing a delivered final reply through the real Codex app-server without an interrupt marker, with cancellation and deadline-fallback controls.
Agent review details

How this fits together

The Codex plugin consumes message-delivery results and native lifecycle notifications, then settles the OpenClaw attempt and its native conversation.

flowchart TD
  A[Confirmed final delivery] --> B[Lifecycle controller]
  B --> C[Completion grace]
  C --> D[Native turn completion]
  C --> E[Timeout interruption]
  D --> F[Attempt settlement]
  E --> F
Loading

Technical review

Best possible solution:

Use bounded native completion for confirmed source replies while preserving cancellation, yield custody, and same-thread history coverage.

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

Current-main terminal release and personally inspected Codex interruption handling establish the failure path, corroborated by current stable-version logs; no reviewer-run reproduction was performed.

Is this the best way to solve the issue?

The existing lifecycle controller is the appropriate owner, and the focused change preserves yield handoff, but timeout fallback still produces native interruption history.

Full review comments:

  • [P2] Update the durable-history fixture for deferred completion — extensions/codex/src/app-server/run-attempt.durable-context.test.ts:246-249
    This test freezes setTimeout and then waits for turn/interrupt after successful message delivery. The introduced grace timer cannot fire because the test never advances it, and native completion is supplied only after the blocked wait. Exact-head CI consequently times out this case after 120 seconds. Update the fixture to supply natural turn completion, or explicitly advance the grace timer when testing fallback, while retaining its same-thread history-coverage assertions.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.95

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Confirmed final-source completion changes intended behavior with a stated reason (7a5529f: Finish confirmed source replies without another model request or visible confirmation; the PR explains that immediate interruption corrupts native history.)
  • Exact native interruption before yield custody transfer keeps the original intent (66e67a0: Join the exact native turn's stop before another parent turn starts or subscription custody transfers.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

PR surface

Source +30, Tests +101, Docs +10. Total +141 across 7 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 4 53 23 +30
Tests 2 106 5 +101
Docs 1 10 0 +10
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 169 28 +141

Review metrics

Metric Value Why it matters
Production versus test changes Production +53/-23 lines; tests +106/-5 lines Production growth adds the completion timer and cleanup within existing owners; the added attempt scenarios distinguish natural completion, cancellation, and deadline fallback.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #111019
Summary: This PR is a narrower candidate for the canonical terminal-release defect; the other open candidate does not establish safe supersession.

Members:

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

Labels

Label changes:

No label changes.

Label justifications:

  • P1: Successful replies on the current stable release can leave misleading interruption state in persistent native conversations and affect subsequent replies.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 16, 2026, 1:54 PM ET / 17:54 UTC.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation extensions: codex P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S 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.

1 participant