Skip to content

fix(codex): serialize native completion handoffs and accept yielded input - #194757

Open
dubr1k wants to merge 7 commits into
openclaw:mainfrom
dubr1k:fix/native-completion-delivery-order-upstream
Open

dubr1k wants to merge 7 commits into
openclaw:mainfrom
dubr1k:fix/native-completion-delivery-order-upstream

Conversation

@dubr1k

@dubr1k dubr1k commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Native subagent completions can collide on the parent thread or report failed delivery when a successful parent consumes the result and yields again.

User Impact

Completion handoffs to the same parent run one at a time and wait while a sibling still owns native execution. A successful optional native handoff that yields again is acknowledged without requiring an immediate visible answer; visible-reply requirements, errors, and aborts remain failures.

Why This Change Was Made

Serialize the existing delivery attempts per physical parent and defer admission while a live child retains the native subscription. Keep retry and custody checks at their existing owners. When the last live sibling settles, immediately wake only handoffs that were waiting for a sibling; ordinary transport failure backoff is preserved. The direct-response classifier recognizes the narrow native completion family’s successful yielded input separately from delivery of a user-visible final answer.

Evidence

  • Separate regressions fail on the base for early admission while a sibling is running, concurrent terminal-child handoffs, and rejection of a successfully consumed native yielded input.
  • 36 focused tests pass across completion contention, monitor delivery, parent retention, and direct-response classification, including all six native-follow-up custody scenarios and both deferred handoffs before advancing the retry clock. Negative cases cover another completion family, a required visible reply, aborted input, and an error.
  • Core and Codex production and test TypeScript checks, targeted lint, formatting, pre-commit hooks, and a justified test-line allocation pass. Independent scoped local review found no actionable P0–P2 defects; the root additionally inspected the full response classifier and retry/custody paths.
  • Tests exercise the repository’s native app-server and direct Gateway-dispatch fixtures. This current-main source head has not been exercised against a live model.

Follow-up: deliver through an idle retained parent

At 099560d04, a live sibling no longer blocks a completion when the retained parent subscription is idle and available for a warm continuation. A cold resume remains deferred while sibling protection is active; a blocked attempt does not exhaust the completion retry budget. The original implementation failed the warm-sibling regression (no delivery); the revised implementation passes it. Four focused suites passed 32 tests before the final structural adjustment, followed by 3 affected tests, targeted lint and commit checks. Independent scoped review found no P0-P2 findings; the reviewer did not execute code. Live Gateway/native Codex validation for this exact revision is still outstanding.

CI test-line allocation

feee756dc adds a separate 38-line allocation for the warm-sibling and cold-resume regression coverage, preserving the tests and global baseline. On the exact failing CI merge tree the test-line ratchet was 6,582,927 / 6,582,889 before the allocation and passed at 6,582,927 / 6,582,927 after it. Exact-head CI is rerunning.

Wake after interrupted or removed siblings

At a10617a87, a waiting completion is retried when the last live sibling becomes resumable or is removed, including while its previous delivery attempt is still settling. The retry retains parent serialization and current custody checks; success does not trigger a duplicate, and shutdown retains detached delivery. The real-monitor regressions failed before this change and pass after it. Forty focused tests, extension typecheck, targeted lint, format, line-cap and test-lines checks passed; independent scoped review found no actionable P0-P2 findings. These are synthetic tests; exact-head live Gateway and model qualification remain outstanding.

Live backport qualification found an unresolved delivery path

A real-model test of the separately adapted OpenClaw 2026.11.1 Mac backport, not this exact PR head, found a remaining failure with two concurrent native children. The fast child completed while the slow child was still running; the parent continuation attempted cold resume, hit the protected-background cleanup timeout, and the fast completion was retired without delivery. The slow completion was later delivered. This evidence supersedes any inference that the synthetic warm-sibling regression proves production delivery across the full Gateway path. Root cause and exact-head applicability are under investigation; the exact PR head still needs live qualification.

Live qualification update: exec context and protected relay

On the separately adapted 2026.11.1 Mac runtime, the first failed handoff differed only in the creation-time developer instructions: the direct native completion omitted the current session exec-state hint. A local candidate reconstructed that hint from current agent/session settings without granting execution authority. In a real two-child test, the fast result reached the parent while the slow child was still running, and the slow result arrived later. The candidate is not yet part of this PR.

The same candidate did not fix the separately installed server runtime with bundled Codex 0.164.0: its protected-continuation preflight rejected the fast completion because there was no current parent-local inference relay. The server candidate was reverted; the preflight was not bypassed. The exact upstream head has not been tested live, and server-side delivery across this path remains unresolved.

Live server backport follow-up

Further diagnosis found that the configured bundled Codex executable and the plugin capture were byte-identical but had distinct paths, so the existing managed-inference ownership check did not recognize the configured binary. A separately adapted release candidate checks the exact bundled executable contents and retains the protected-context guard. In a real-model server run with the bundled Codex 0.164.0, the fast child result reached the same parent while the slow child was still running, then the slow result arrived; a separate same-child followup also completed. No 502 was observed in the test window. A Mac release backport also passed the parallel-child live scenario. These deployed release backports are not this PR head; source changes and exact-head live qualification are still pending.

Security review: server attestation candidate withdrawn

Independent review found that the release candidate compared the executable only after spawning it, which does not attest the executable actually running, and synchronously hashed large binaries on the Gateway event loop. The candidate has been reverted on the server; the prior successful server live run therefore does not establish that the currently deployed server is fixed. Review also identified a remaining delivery gap if exec policy changes while a sibling is active: cold resume must preserve and retry the completion without granting stale authority. This PR head has not been live-qualified for those cases.

Managed bundled runtime follow-up

The server now uses OpenClaw's existing managed launcher with preferInstalled: false, rather than trusting a configured executable after spawn. The original relay ownership and context checks remain in place. The actual packaged Codex 0.164.0 process was checked, and separately adapted release backports passed live parallel-child and same-child followup scenarios on the server; the Mac release backport passed the parallel-child scenario. The exact upstream PR head is not the deployed release backport. A policy change while another child remains active can still force a protected cold preflight and leave completion recovery blocked; that case remains under investigation.

Live policy-change counterexample

A subsequent live server test changed the test session exec host from gateway to sandbox while two native children were running. Both children finished; the continuation correctly rejected the changed tool policy, but recovery retired both results without delivering them. This remains an open defect in the separately patched release runtime. A safe fix needs owner-issued proof that the whole admitted Gateway run did not send a native turn before allowing a retry; generic preflight errors and absent observed output are not sufficient. The managed bundled server path and ordinary parallel-child/steer tests pass, but they do not cover this failure.

Current exec-state context for completion turns

bfa927fe9 carries the current session exec hint into native completion turns from the admitted session and agent configuration; tool execution still uses the current authority and policy. Heavy prompt/runtime helpers are loaded only on the relevant completion path. This addresses the observed unchanged-policy fingerprint mismatch, but does not resolve the documented policy-change counterexample.

Focused validation: 29 session-preparation tests and 14 prompt-prefix stability tests passed; core typecheck, targeted lint, formatting, test-line and line-cap ratchets passed. An independent static review found an eager-loading concern, which was addressed with lazy imports; it did not rerun the tests or perform a live test. Separate installed 2026.11.1 backports passed the live ordinary parallel-child scenarios on Mac and server, but are not this source head. Exact-head live qualification and the policy-change recovery issue remain open.

CI follow-up: corrected the agent configuration fixture to use agents.entries; the previously failing core test typecheck stripe and all 29 session-preparation tests pass locally at 5726bcd6e. Hosted CI is pending.

@clawsweeper

clawsweeper Bot commented Nov 7, 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 extensions: codex size: S labels Nov 7, 2026
@dubr1k
dubr1k marked this pull request as ready for review November 7, 2026 19:14
@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. labels Nov 7, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. 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 Nov 8, 2026
@clawsweeper

clawsweeper Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: stale review; fresh review needed.

Summary
The latest durable ClawSweeper review was for head b0e44648d4cb867dd8ff57d51911e400a2311341, but the PR head is now 5726bcd6e7d759b4960390c8227516dc1cc81570. Its old verdict and PR readiness labels are no longer current.

Next step
Comment @clawsweeper re-review when the current head is ready; pushes after the first review are not reviewed automatically.

Review history (1 earlier review cycle)
  • reviewed 2026-11-08T05:37:02.523Z sha b0e4464 :: needs real behavior proof before merge. :: [P1] Preserve completion delivery through protected warm parents

@clawsweeper clawsweeper Bot removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Nov 8, 2026
obviyus added a commit that referenced this pull request Nov 25, 2026
Root cause: extensions/codex/src/app-server/event-projector-tool-transcript.ts:601-608 (on main) `synthesizeMissingToolResults` already records confirmed retained command ids as neutral "still running" results, but still counts them as missing tool results, so a silent turn (no visible answer) with a confirmed running native command is failed with the missing-result error.

Fixes #196061. Related: #156764 (added the neutral retained-command record), #194757 (separate continuation path).

Thanks @aatreya for the report and the fix.

## What Problem This Solves
A Codex turn that starts a native background command, gets it confirmed by `thread/backgroundTerminals/list`, and then ends silently (`NO_REPLY`) was marked failed with "OpenClaw recorded a native Codex tool.call without a matching tool.result before the turn completed." That failure skips the normal retention of the live thread, so the next user message is rejected with "Codex thread … still has background work after waiting for cleanup; stop its running work and retry", and the session stays stuck even after the command finishes.

## Fix
Confirmed retained command ids are excluded from missing-result error selection and counting. Their neutral running records are unchanged. Genuinely missing results still fail, and a mix of running and missing calls reports only the missing ones.

## Evidence
Built Gateway (secretless Docker) running the native Codex harness against a stand-in app-server that follows the Codex app-server protocol: the turn starts a background command that stays running, the inventory confirms it, the turn ends with `NO_REPLY`; then a follow-up message, the command's native completion, and a "continue" message. Main twice, this branch twice, plus controls. Observed lines: #196062 (comment)

| Scenario | main | this PR |
|---|---|---|
| silent turn + running command (x2) | turn fails with missing-result error; follow-up rejected ("still has background work…"); after completion still rejected | turn not failed; follow-up answered on the same live thread; after completion the next message runs |
| silent turn + truly missing result | missing-result error | same |
| silent turn + running + missing | missing-result error, `missingToolResultCount=2` | missing-result error for the one missing call |
| visible answer + running command | unchanged | unchanged |

The proof drives the session through `openclaw agent`, which requires a result, so this PR's silent first turn shows that CLI's standard "No answer was returned" notice rather than the missing-result failure. Channel turns such as Discord accept the silence.

Regression test: `native background outcome: silent retained` fails on main's projector and passes here.

The takeover commit drops the test-line allocation file and folds the regression into the existing table (production +8/-3, tests +7/-3).

## Merge danger
Two-way door: classification only, no stored state, config or contract changes; a revert fully undoes it. Blast radius: Codex harness turns that end without a visible answer while a confirmed native command is still running.

Co-authored-by: Ayaan Zaidi <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 26, 2026
Root cause: extensions/codex/src/app-server/event-projector-tool-transcript.ts:601-608 (on main) `synthesizeMissingToolResults` already records confirmed retained command ids as neutral "still running" results, but still counts them as missing tool results, so a silent turn (no visible answer) with a confirmed running native command is failed with the missing-result error.

Fixes #196061. Related: #156764 (added the neutral retained-command record), #194757 (separate continuation path).

Thanks @aatreya for the report and the fix.

## What Problem This Solves
A Codex turn that starts a native background command, gets it confirmed by `thread/backgroundTerminals/list`, and then ends silently (`NO_REPLY`) was marked failed with "OpenClaw recorded a native Codex tool.call without a matching tool.result before the turn completed." That failure skips the normal retention of the live thread, so the next user message is rejected with "Codex thread … still has background work after waiting for cleanup; stop its running work and retry", and the session stays stuck even after the command finishes.

## Fix
Confirmed retained command ids are excluded from missing-result error selection and counting. Their neutral running records are unchanged. Genuinely missing results still fail, and a mix of running and missing calls reports only the missing ones.

## Evidence
Built Gateway (secretless Docker) running the native Codex harness against a stand-in app-server that follows the Codex app-server protocol: the turn starts a background command that stays running, the inventory confirms it, the turn ends with `NO_REPLY`; then a follow-up message, the command's native completion, and a "continue" message. Main twice, this branch twice, plus controls. Observed lines: #196062 (comment)

| Scenario | main | this PR |
|---|---|---|
| silent turn + running command (x2) | turn fails with missing-result error; follow-up rejected ("still has background work…"); after completion still rejected | turn not failed; follow-up answered on the same live thread; after completion the next message runs |
| silent turn + truly missing result | missing-result error | same |
| silent turn + running + missing | missing-result error, `missingToolResultCount=2` | missing-result error for the one missing call |
| visible answer + running command | unchanged | unchanged |

The proof drives the session through `openclaw agent`, which requires a result, so this PR's silent first turn shows that CLI's standard "No answer was returned" notice rather than the missing-result failure. Channel turns such as Discord accept the silence.

Regression test: `native background outcome: silent retained` fails on main's projector and passes here.

The takeover commit drops the test-line allocation file and folds the regression into the existing table (production +8/-3, tests +7/-3).

## Merge danger
Two-way door: classification only, no stored state, config or contract changes; a revert fully undoes it. Blast radius: Codex harness turns that end without a visible answer while a confirmed native command is still running.

Co-authored-by: Ayaan Zaidi <[email protected]>

(cherry picked from commit 9e2de2c)
Co-authored-by: RomneyDa <[email protected]>
Co-authored-by: vincentkoc <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 26, 2026
…196062)

Root cause: extensions/codex/src/app-server/event-projector-tool-transcript.ts:601-608 (on main) `synthesizeMissingToolResults` already records confirmed retained command ids as neutral "still running" results, but still counts them as missing tool results, so a silent turn (no visible answer) with a confirmed running native command is failed with the missing-result error.

Fixes openclaw#196061. Related: openclaw#156764 (added the neutral retained-command record), openclaw#194757 (separate continuation path).

Thanks @aatreya for the report and the fix.

## What Problem This Solves
A Codex turn that starts a native background command, gets it confirmed by `thread/backgroundTerminals/list`, and then ends silently (`NO_REPLY`) was marked failed with "OpenClaw recorded a native Codex tool.call without a matching tool.result before the turn completed." That failure skips the normal retention of the live thread, so the next user message is rejected with "Codex thread … still has background work after waiting for cleanup; stop its running work and retry", and the session stays stuck even after the command finishes.

## Fix
Confirmed retained command ids are excluded from missing-result error selection and counting. Their neutral running records are unchanged. Genuinely missing results still fail, and a mix of running and missing calls reports only the missing ones.

## Evidence
Built Gateway (secretless Docker) running the native Codex harness against a stand-in app-server that follows the Codex app-server protocol: the turn starts a background command that stays running, the inventory confirms it, the turn ends with `NO_REPLY`; then a follow-up message, the command's native completion, and a "continue" message. Main twice, this branch twice, plus controls. Observed lines: openclaw#196062 (comment)

| Scenario | main | this PR |
|---|---|---|
| silent turn + running command (x2) | turn fails with missing-result error; follow-up rejected ("still has background work…"); after completion still rejected | turn not failed; follow-up answered on the same live thread; after completion the next message runs |
| silent turn + truly missing result | missing-result error | same |
| silent turn + running + missing | missing-result error, `missingToolResultCount=2` | missing-result error for the one missing call |
| visible answer + running command | unchanged | unchanged |

The proof drives the session through `openclaw agent`, which requires a result, so this PR's silent first turn shows that CLI's standard "No answer was returned" notice rather than the missing-result failure. Channel turns such as Discord accept the silence.

Regression test: `native background outcome: silent retained` fails on main's projector and passes here.

The takeover commit drops the test-line allocation file and folds the regression into the existing table (production +8/-3, tests +7/-3).

## Merge danger
Two-way door: classification only, no stored state, config or contract changes; a revert fully undoes it. Blast radius: Codex harness turns that end without a visible answer while a confirmed native command is still running.

Co-authored-by: Ayaan Zaidi <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 29, 2026
Root cause: extensions/codex/src/app-server/event-projector-tool-transcript.ts:601-608 (on main) `synthesizeMissingToolResults` already records confirmed retained command ids as neutral "still running" results, but still counts them as missing tool results, so a silent turn (no visible answer) with a confirmed running native command is failed with the missing-result error.

Fixes #196061. Related: #156764 (added the neutral retained-command record), #194757 (separate continuation path).

Thanks @aatreya for the report and the fix.

## What Problem This Solves
A Codex turn that starts a native background command, gets it confirmed by `thread/backgroundTerminals/list`, and then ends silently (`NO_REPLY`) was marked failed with "OpenClaw recorded a native Codex tool.call without a matching tool.result before the turn completed." That failure skips the normal retention of the live thread, so the next user message is rejected with "Codex thread … still has background work after waiting for cleanup; stop its running work and retry", and the session stays stuck even after the command finishes.

## Fix
Confirmed retained command ids are excluded from missing-result error selection and counting. Their neutral running records are unchanged. Genuinely missing results still fail, and a mix of running and missing calls reports only the missing ones.

## Evidence
Built Gateway (secretless Docker) running the native Codex harness against a stand-in app-server that follows the Codex app-server protocol: the turn starts a background command that stays running, the inventory confirms it, the turn ends with `NO_REPLY`; then a follow-up message, the command's native completion, and a "continue" message. Main twice, this branch twice, plus controls. Observed lines: #196062 (comment)

| Scenario | main | this PR |
|---|---|---|
| silent turn + running command (x2) | turn fails with missing-result error; follow-up rejected ("still has background work…"); after completion still rejected | turn not failed; follow-up answered on the same live thread; after completion the next message runs |
| silent turn + truly missing result | missing-result error | same |
| silent turn + running + missing | missing-result error, `missingToolResultCount=2` | missing-result error for the one missing call |
| visible answer + running command | unchanged | unchanged |

The proof drives the session through `openclaw agent`, which requires a result, so this PR's silent first turn shows that CLI's standard "No answer was returned" notice rather than the missing-result failure. Channel turns such as Discord accept the silence.

Regression test: `native background outcome: silent retained` fails on main's projector and passes here.

The takeover commit drops the test-line allocation file and folds the regression into the existing table (production +8/-3, tests +7/-3).

## Merge danger
Two-way door: classification only, no stored state, config or contract changes; a revert fully undoes it. Blast radius: Codex harness turns that end without a visible answer while a confirmed native command is still running.

Co-authored-by: Ayaan Zaidi <[email protected]>

(cherry picked from commit 9e2de2c)

Co-authored-by: RomneyDa <[email protected]>

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

agents Agent runtime and tooling extensions: codex P1 High-priority user-facing bug, regression, or broken workflow. size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant