Skip to content

fix: stop lost cancellations, false success, and stuck Codex compaction - #117902

Merged
steipete merged 2 commits into
mainfrom
codex/inference-stress-round3-20260801
Aug 2, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/inference-stress-round3-20260801

Conversation

@steipete

@steipete steipete commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes issues where users running inference, switching models, cancelling chats, delegating work, or manually compacting Codex sessions could see orphaned tools, stale or falsely successful run status, missing timeout notifications, lost delegated replies, duplicate mutating calls, permanently sleeping requesters, or a /compact command that never answers.

Related: #117731

Why This Change Was Made

Record and consume each authoritative fact at its existing owner: route and provider cancellation, run/session lifecycle identity, exact fallback handoff, stable child-task identity, native Codex thread subscriptions, and tool-result presence. Consolidate duplicate mock-provider completion scans and remove redundant abort/terminal adapters; preserve fail-closed handoff checks and existing config, protocol, provider, and storage contracts.

User Impact

  • Cancelled tools and approval handlers stop immediately, including custom streams and Anthropic Vertex.
  • Global timeout subscribers receive their terminal events, and old aborts or completions cannot overwrite a reset/newer session.
  • Streaming OpenAI Chat Completions and Responses report provider failures once instead of silently marking failed runs successful.
  • Delegated source replies retain their exact session-bound authority during model fallback, and spawn → steer → yield reliably wakes the requester.
  • Empty or image-only tool results count as completed across OpenAI, Anthropic, and Codex/WebSocket transports rather than replaying a mutating tool.
  • Ordinary Codex sessions retain their native thread subscription, so manual /compact completes and goal context remains available afterward.
  • Runtime-pair QA waits for durable message-tool completion before collecting parity evidence.
  • Production delta: 171 added / 229 deleted = 58 fewer production lines; regression/harness coverage is counted separately.

Evidence

  • Seven remote focused Vitest shards across Codex, mock providers, agent streams, lifecycle/session ownership, HTTP streaming, fallback handoffs, and requester wakeups; the gateway shard passed 572 tests, the Codex shard 271 tests.
  • Additional focused native-compaction/thread-cleanup proof: 170 Codex tests passed, including the new default-legacy-engine subscription regression.
  • Mock runtime-pair stress: 12 scenarios × OpenClaw/Codex = 24 passing cells, including the formerly failing native /compact and durable group-message parity cases.
  • Fault injection: 10/10 passed across empty/reasoning-only responses, replay-safe reads versus mutating writes, Anthropic thinking failures, tool-loop circuit breakers, in-flight gateway restart, memory-flush recovery, tool search, and stranded message finals.
  • Real provider verification: 6 scenarios × OpenClaw/Codex = 12 passing cells against live openai/gpt-5.4, covering streaming, tool vocabulary, approvals, goal follow-through, delegated work, and model-switch continuity.
  • Full remote pnpm check:changed passed: whole-project typecheck, zero-warning core/plugin/script lint across roughly 24,000 files, dependency/plugin/storage/architecture guards, and zero runtime import cycles. Full private-QA production build passed. Independent structured autoreview: clean; no accepted/actionable findings.
  • Exact formerly failing CI transport reproduced and repaired: pnpm openclaw qa run --repo-root . --qa-profile smoke-ci --scenario group-visible-reply-tool passes through the real Telegram plugin + Crabline local Telegram provider; the same scenario also passes OpenClaw/Codex parity over QA-channel. Session identity is derived from the actual active transport, not a hardcoded channel.
  • Upstream Codex contracts inspected directly at source revision fbf666fa9875d0157816be3b7a20c63161d77ec5: native turn and callback cancellation (codex-rs/app-server/src/bespoke_event_handling.rs:156-203, codex-rs/app-server/src/outgoing_message.rs:469-496), empty tool outputs (codex-rs/protocol/src/models.rs:1925-1970), subscribed-only compaction notifications (codex-rs/app-server/src/request_processors/thread_processor.rs:876-900,1867-1878, codex-rs/app-server/src/request_processors/thread_lifecycle.rs:320-332), and dynamic-tool completion ordering (codex-rs/core/src/tools/handlers/dynamic.rs:196-245).

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime agents Agent runtime and tooling extensions: qa-lab extensions: codex size: L maintainer Maintainer-authored PR labels Aug 2, 2026
@steipete
steipete marked this pull request as ready for review August 2, 2026 08:13
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Aug 2, 2026
@clawsweeper

clawsweeper Bot commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed August 2, 2026, 4:47 AM ET / 08:47 UTC.

ClawSweeper review

What this changes

This PR changes agent, gateway, QA, and Codex app-server lifecycle handling so cancellation, terminal results, delegated replies, empty tool outputs, and native /compact remain bound to the correct run or thread.

Merge readiness

⛔ Blocked until stronger real behavior proof is added - 5 items remain

Keep this PR open for explicit maintainer review. The exact head contains focused lifecycle-owner repairs and the author supplied materially stronger terminal proof, but this reviewer cannot complete the repository-required direct Codex dependency check: ../codex is absent and the partial checkout cannot retrieve missing objects because DNS access to GitHub is unavailable. The maintainer label also requires human handling rather than cleanup automation.

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

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The branch has substantial reported regression and live-run evidence, but independent exact-head Codex-contract verification is still a merge gate for this review.
Proof confidence 🦐 gold shrimp (3/6) Needs stronger real behavior proof before merge: The PR body and follow-up comment provide redacted after-fix terminal output and report live-provider and QA runs, but this reviewer cannot independently verify the required direct Codex contract or all missing partial-clone objects in the current environment. 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 🦐 gold shrimp (3/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Needs proof Needs stronger real behavior proof before merge: The PR body and follow-up comment provide redacted after-fix terminal output and report live-provider and QA runs, but this reviewer cannot independently verify the required direct Codex contract or all missing partial-clone objects in the current environment. 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 6 items Exact-head lifecycle ownership changes: The reviewed PR head routes in-flight Codex requests through a signal combining the upstream callback signal with the route-owned cancellation signal, so a retired route can cancel pending tools and approvals before the terminal notification arrives.
Exact-head compaction subscription repair: The Codex cleanup path now bases persistent-thread retention on the active connection context engine rather than the raw attempt parameter, while the accompanying regression test covers the default legacy engine path described in the PR evidence.
Session identity owner repair: The patch records a lifecycle start timestamp on each run context and restores that run-owned timestamp on later terminal events, preventing an overlapping newer run in the same session from supplying the older run's identity.
Findings None None.
Security None None.

How this fits together

Agent and gateway runtime paths turn provider streams and channel requests into session-bound lifecycle events, tool calls, and replies. The Codex extension bridges those runs to the Codex app server, including the thread subscription that receives native compaction progress and completion.

flowchart LR
  Input[Provider and channel requests] --> Runtime[Agent and gateway runtime]
  Runtime --> Lifecycle[Run and session lifecycle]
  Runtime --> Tools[Tool and delegation handling]
  Runtime --> Codex[Codex app-server bridge]
  Codex --> Threads[Thread subscriptions and compaction]
  Lifecycle --> Output[Terminal events and user-visible replies]
  Tools --> Output
Loading

Decision needed

Question Recommendation
Should a maintainer complete the direct Codex-source contract check and exact-head merge/proof refresh before accepting these lifecycle changes? Complete the exact-head contract review: Inspect the cited Codex revision locally, confirm the subscription and cancellation contracts against this head, then proceed only with the remaining checks green.

Why: The repository policy explicitly requires the acting reviewer to inspect the sibling Codex implementation for this Codex-facing behavior, and this read-only environment cannot supply that dependency checkout or retrieve the missing promisor objects.

Before merge

  • Add real behavior proof - Needs stronger real behavior proof before merge: The PR body and follow-up comment provide redacted after-fix terminal output and report live-provider and QA runs, but this reviewer cannot independently verify the required direct Codex contract or all missing partial-clone objects in the current environment. 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.
  • Resolve merge risk (P1) - Merging changes to cancellation, run identity, and Codex thread subscriptions can still leave a session stale or a request permanently waiting if the direct Codex callback and subscription contracts differ from the assumptions encoded in the patch.
  • Resolve merge risk (P1) - One exact-head compact check remains in progress, and the PR is behind current main; refresh the merge and proof state after that check completes rather than assuming the reported remote run applies unchanged.
  • Complete next step (P2) - This maintainer-labeled PR requires direct dependency-contract and exact-head merge/proof review, not an automated repair job.
Agent review details

Security

None.

PR surface

Source -41, Tests +429, Other +22. Total +410 across 27 files.

View PR surface stats
Area Files Added Removed Net
Source 16 188 229 -41
Tests 10 487 58 +429
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 22 0 +22
Total 27 697 287 +410

Review metrics

None.

Stored data model

Persistent data-model change detected: persistent cache schema: src/agents/embedded-agent-runner/stream-resolution.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Verify the owner-boundary contract before merge (recommended)
    Confirm the exact Codex callback and subscribed-connection behavior, then rerun the focused cancellation, lifecycle, and compaction proof on the mergeable head.
  2. Pause for a narrow follow-up
    If direct dependency review exposes uncertainty, retain the proven non-Codex fixes and move the unresolved subscription behavior to a separately evidenced change.

Technical review

Best possible solution:

Complete an exact-head, direct inspection of upstream Codex revision fbf666fa9875d0157816be3b7a20c63161d77ec5 alongside the focused lifecycle and compaction proof, then merge only if the current three-way result preserves the run-owned cancellation and terminal-event invariants.

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

Yes, at source level with medium confidence: the exact head includes focused regression coverage for route cancellation, lifecycle terminal ownership, stream cancellation, requester wakeup, empty tool results, and persistent Codex thread retention. This environment cannot run or fully inspect the dependent Codex runtime needed to establish the complete current-head reproduction path.

Is this the best way to solve the issue?

Unclear: the patch follows the repository's preferred owner-boundary approach by carrying cancellation and lifecycle facts from their producers, but the direct Codex protocol/runtime contract must be inspected before confirming this is the best complete repair.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P1: The patch targets active agent and channel workflows where cancellation, replies, or compaction can otherwise remain stalled or report the wrong terminal state.
  • merge-risk: 🚨 session-state: The diff changes session-bound lifecycle timestamps, run identity, and delegated completion handoff state.
  • merge-risk: 🚨 availability: The diff changes cancellation and terminal-event paths that can leave tools, HTTP responses, or compaction requests waiting indefinitely.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The PR body and follow-up comment provide redacted after-fix terminal output and report live-provider and QA runs, but this reviewer cannot independently verify the required direct Codex contract or all missing partial-clone objects in the current environment. 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:

  • Exact-head lifecycle ownership changes: The reviewed PR head routes in-flight Codex requests through a signal combining the upstream callback signal with the route-owned cancellation signal, so a retired route can cancel pending tools and approvals before the terminal notification arrives. (extensions/codex/src/app-server/turn-router.ts:395, a78e8c6520a7)
  • Exact-head compaction subscription repair: The Codex cleanup path now bases persistent-thread retention on the active connection context engine rather than the raw attempt parameter, while the accompanying regression test covers the default legacy engine path described in the PR evidence. (extensions/codex/src/app-server/run-attempt-cleanup.ts:88, a78e8c6520a7)
  • Session identity owner repair: The patch records a lifecycle start timestamp on each run context and restores that run-owned timestamp on later terminal events, preventing an overlapping newer run in the same session from supplying the older run's identity. (src/infra/agent-events.ts:625, 7879adf64410)
  • Related work provenance: A related inference lifecycle repair was merged as commit 7c1d5dc and is contained in tag release-publish/10a390ed7fa8-20260802; it overlaps this PR but does not prove the newer head is merged. (src/infra/agent-events.ts:625, 7c1d5dc7ef58)
  • Required dependency-review blocker: Repository policy requires this reviewer to inspect the sibling Codex source directly before issuing a Codex verdict. The sibling checkout is absent; attempting to read additional partial-clone objects also failed because github.com DNS resolution is unavailable.
  • Current-main status: The PR head is not an ancestor of the checked-out current main, so this work is neither implemented on main nor eligible for an obsolete-PR cleanup close. (a78e8c6520a7)

Likely related people:

  • steipete: The same contributor authored the directly related merged inference lifecycle repair and both commits on this PR; the exact-head source attributes the current lifecycle-owner changes to that work. (role: recent area contributor; confidence: medium; commits: 7c1d5dc7ef58, 7879adf64410, a78e8c6520a7; files: extensions/codex/src/app-server/turn-router.ts, extensions/codex/src/app-server/run-attempt-cleanup.ts, src/gateway/openai-http.ts)

Rank-up moves

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

  • Provide or enable an independently inspectable sibling Codex checkout at the cited revision for the exact-head review.
  • Refresh the current merge/head proof after the remaining compact check completes, with redacted runtime evidence if the head changes.

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 (1 earlier review cycle)
  • reviewed 2026-08-02T08:22:40.711Z sha 7879adf :: needs real behavior proof before merge. :: none

@steipete

steipete commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

Exact-head maintainer proof and ClawSweeper follow-through

Reviewed head: a78e8c6520a7e0db85b4fe8018652c1716ecaf32.

Direct upstream Codex contract proof

I inspected the complete local sibling checkout at upstream Codex revision fbf666fa9875d0157816be3b7a20c63161d77ec5 directly; this does not rely on OpenClaw wrappers, generated schemas, prior bot reviews, or memory:

  • thread_processor.rs:876-900 removes the connection subscription on thread/unsubscribe.
  • thread_processor.rs:1867-1878 starts native compaction with load_thread + Op::Compact; it does not resubscribe the caller.
  • thread_lifecycle.rs:320-332 addresses progress only to subscribed_connection_ids. This explains the reproduced pre-fix 60-second /compact hang and proves why retaining the canonical default-thread subscription is the correct owner-boundary repair.
  • outgoing_message.rs:469-496 removes pending request callbacks on cancellation.
  • dynamic.rs:196-245 emits a dynamic-tool started item before awaiting the tool response and emits completion afterward. This proves why observing a visible message during tool execution cannot serve as durable completion evidence.
  • models.rs:1925-1970 permits empty tool-output text/content; result-item presence, not nonempty rendering, owns completion.

Redacted real-behavior terminal proof

paired mock: 12 scenarios × openclaw,codex = 24 passing cells
fault injection: 10 passed, 0 failed
live openai/gpt-5.4: 6 scenarios × openclaw,codex = 12 passing real-provider cells
native Codex /compact + active goal context: both runtime cells passed
exact Telegram smoke: channelDriver=crabline channel=telegram
[qa-suite] scenario pass (1/1): group-visible-reply-tool
[qa-suite] run complete: passed=1 failed=0 skipped=0 total=1
QA-channel message parity: openclaw passed; codex passed; runtime pair passed
full pnpm check:changed: exitCode=0, total=11m0s
whole-project TypeScript: passed
core/plugin/script lint: 0 warnings, 0 errors, ~24,000 files
runtime import cycles: 0
private QA production build: exitCode=0, total=3m14s
structured autoreview: clean; no accepted/actionable findings
production: +171/-229 = -58 LOC

Rank-up moves and review clarification

  1. Complete checkout + direct Codex review: satisfied by the maintainer's complete checkout with ../codex present and personally inspected; exact files, pinned upstream revision, dependency behavior, reviewed head, and validated native scripts/pr review artifacts are recorded above. ClawSweeper's isolated runner lacked DNS/Git objects and a sibling checkout, but that infrastructure limitation does not apply to this maintainer review.
  2. Redacted native-compaction/live artifacts: satisfied by the terminal proof above, the PR-body scenario matrix, focused original-order regressions, and remote Testbox evidence. No API keys or provider credentials are printed.

The bot's “persistent cache schema” classification is a false positive on src/agents/embedded-agent-runner/stream-resolution.test.ts: this changes provider-stream cancellation tests only. There is no database schema, migration, SQLite version, persistent cache, protocol, config, or public API change.

Exact-head hosted CI is being monitored before native scripts/pr prepare-run / merge-run.

@steipete

steipete commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

Final maintainer decision for current head a78e8c6520a7e0db85b4fe8018652c1716ecaf32:

  • Exact-head CI run https://github.com/openclaw/openclaw/actions/runs/30740153291 completed GREEN, including all four QA smoke profiles and the corrected Telegram/Crabline group-message lane.
  • The latest ClawSweeper rank-up request to refresh merge/head proof after the compact check is satisfied: current head is unchanged, hosted checks are green, native /compact passed paired runtime proof, and the exact native scripts/pr review artifacts are validated.
  • The request to make ClawSweeper's isolated runner independently mount ../codex cannot be fulfilled from this PR/task because that runner lacks its own sibling checkout/DNS access; it is an infrastructure limitation outside the change. The maintainer-side complete checkout does contain ../codex, and I personally inspected the pinned upstream source and linked the exact files/lines in the preceding proof comment.
  • Maintainer instruction explicitly authorizes autonomous test/PR/land; no product-owner, config, protocol, database-schema, or security-policy decision is pending.
  • The apparent persistent-cache/schema flag is false: only provider-stream tests and runtime lifecycle code changed; no schema/migration/config files are modified.

Proceed through repository-native prepare/merge once GitHub REST rate-limit reset permits its required hosted-gate API read.

@steipete
steipete merged commit 0138f5b into main Aug 2, 2026
126 checks passed
@steipete
steipete deleted the codex/inference-stress-round3-20260801 branch August 2, 2026 09:04
@steipete

steipete commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

abdulrahman305 pushed a commit to qenex-ai/openclaw that referenced this pull request Aug 2, 2026
* origin/main:
  fix: stop lost cancellations, false success, and stuck Codex compaction (openclaw#117902)
  fix(cli): reject incomplete hosted video downloads (openclaw#117893)
  refactor(board): remove duplicate in-memory store (openclaw#117353)
  refactor: consolidate Teams and error helpers (openclaw#117907)
  fix(msteams): cancel unread Graph error response bodies (openclaw#117664)
  fix(imessage): rewind the recovery cursor when chat.db is replaced at the same path (openclaw#117788)
  feat(browser): relay CDP compat for Puppeteer clients (chrome-devtools-mcp) (openclaw#117915)
ZYV5ge added a commit to ZYV5ge/openclaw that referenced this pull request Aug 2, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 3, 2026
…on (openclaw#117902)

* fix(inference): preserve cancellation, lifecycle, and Codex completion ownership

* test(qa): settle visible replies on the active channel transport
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 3, 2026
* origin/main:
  fix: stop lost cancellations, false success, and stuck Codex compaction (openclaw#117902)
  fix(cli): reject incomplete hosted video downloads (openclaw#117893)
  refactor(board): remove duplicate in-memory store (openclaw#117353)
  refactor: consolidate Teams and error helpers (openclaw#117907)
  fix(msteams): cancel unread Graph error response bodies (openclaw#117664)
  fix(imessage): rewind the recovery cursor when chat.db is replaced at the same path (openclaw#117788)
  feat(browser): relay CDP compat for Puppeteer clients (chrome-devtools-mcp) (openclaw#117915)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling extensions: codex extensions: qa-lab gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: L 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