Skip to content

fix(codex): deliver native child results after parent yields - #156247

Merged
vincentkoc merged 11 commits into
mainfrom
fix/native-completion-custody-20260923
Sep 23, 2026
Merged

vincentkoc merged 11 commits into
mainfrom
fix/native-completion-custody-20260923

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

What problem this solves

Native Codex children can finish after their parent yields, but completion callbacks still use the expired authority of the admitting turn. Results then fail to persist or resume the requester, including during Gateway restart drain. A thread-scoped wait snapshot can also overwrite a newer assignment for the same child.

User impact

Accepted native child work keeps the authority needed to record its result and resume the same requester. Revoked or replaced requesters remain blocked. Execution holds end after terminal persistence and the first handoff, so delivery retries do not keep a restart open.

Custom detached adapters must implement the documented optional transitionTaskAssignment operation before accepting native exact-assignment work. Registration now checks the captured adapter, including reused runtimes, and gives an upgrade error before submitting a turn. Existing unguarded calls retain their behavior.

Why this change was made

The host issues completion custody for each accepted assignment and separates requester continuation from Gateway execution ownership. Events and transitions carry an immutable task receipt; only an acknowledged commit can advance it. The canonical transition checks that receipt around asynchronous planning. Codex owns release and recovery across child events, parent turns, and cleanup.

This removes transient caller capture, thread-only wait mutation of successor assignments, and unsafe core-store fallback for guarded custom adapters. Transition contracts now live in their existing leaf type module, removing the introduced import cycle.

Net production change: +856 lines for the completion owner and exact-commit adapter boundary. Tests/fixtures: +2,399; documentation: +37. No new configuration, schema version, dependency, or concurrency limit.

Evidence

  • Final candidate: ec2f407aa79b9b9e44f04009b15fc1d6f212ef20, based on b6340c7947bd989d19e02d277ebf25949e2454a2.
  • Follow-up Linux proof: production-identical 1230323 passes typed harness lint, Gateway test types and the packaged build (324.6 seconds); clean checkout, 50-file source manifest, frozen lockfile and embedded build revision verified. Nine real Gateway authority cases pass at f23f29e, followed only by mechanical lint corrections. At identical production revisions, 378 sibling tests across 12 files, the Copilot attempt suite, core/plugin production types, affected core/plugin test graphs and SDK surface checks pass. The transition-contract cycle repair also passes the full architecture check.
  • Original candidate Linux proof: 1,024 tests across 35 files; native changed-surface gates, SDK surface check, and packaged build passed at 473a407. Tests ran in a verified detached candidate checkout, separate from the workflow bootstrap revision.
  • Real Linux deployment at 473a407: native update succeeded with matching source, dist and serving build, no final doctor/plugin errors, and no remaining update lease. A native child completed 14 seconds after its parent yielded; a distinct parent turn resumed and returned its result. The task recorded delivered and the parent pending-input count returned to zero, within the five-minute probe without a resend. A later read-only observation found 13 additional delivered native tasks, no new authority/persistence errors and no Gateway restarts. This is live proof of the original custody repair; it does not claim the later source commits are deployed.
  • Direct dependency inspection at openai/codex 4147824: completion lifecycle in codex-rs/core/src/session/mod.rs:3714-3794; active-turn child admission in codex-rs/core/src/tools/handlers/multi_agents/spawn.rs:46-148; thread-scoped wait contract in codex-rs/app-server-protocol/src/protocol/event_mapping.rs:219-249, codex-rs/app-server-protocol/src/protocol/v2/item.rs:321-340, and codex-rs/core/src/tools/handlers/multi_agents/wait.rs:109-158.
  • Independent Codex review of the follow-up changes at 8044ef8: no actionable P0-P2 findings. Subsequent test-only corrections supply the canonical no-media JSON value, narrow optional recorder input, follow typed-lint conventions, and extract the unchanged Copilot native-failure fixture into its existing test-support module; production and assertions are unchanged.

Storage and upgrade compatibility

No database migration is needed. Against the merge base, both canonical schema SQL files, schema-version declarations, task SQLite reader/writer and receipt helpers have identical Git blobs. The TaskRecord and TaskPersistenceReceipt declarations are also unchanged. The existing receipt helper freezes existing identity fields; completion custody is process-owned, not a new stored record.

The flagged detached-task-runtime-contract.ts change adds an optional adapter operation and progress detail parameter. That parameter uses the existing TaskRecord.detail / detail_json field and unchanged SQLite serializer. It does not add a table, column, version, persisted enum or backfill. Custom adapter capability admission is the separately documented runtime compatibility requirement above.

Upgrade proof: the native updater took the affected existing installation from b6340c7 to 473a407, completed doctor with zero errors/warnings, and the pre-existing 945-task cohort remained readable. A real post-yield native child was then persisted and delivered. Later commits change admission validation, transition type placement and tests; the storage contract remains identical. This is upgrade/readability proof, not a claim that historical failed deliveries were replayed.

Review follow-through

The new Gateway harness exercises the actual announcement, input writer, dispatcher and AgentSession queue injector. Nine scenarios cover live, revoked and replaced owners at direct input staging, recorder resolution and compaction retry. Positive cases prove real persistence/injection. Negative cases prove no execution/injection, pending input or transcript change, and join request cleanup before checking dedupe. No pre-seeded successful reply is used.

The custom-adapter requirement is checked before every native registration, including cached runtime owners. Tests cover supported/core adapters, unsupported and retired owners, cleanup after rejection, and unchanged generic/Copilot behavior.

Release context: fix native Codex child completions being lost after parent yield or during Gateway restart drain. Changelog is release-owned.

Follow-ups: native next-wave delivery-obligation settlement remains a separate investigation; this repair preserves the existing visible-final policy and does not count yield or child admission as delivery. Copilot native assignment projection and native updater copy/progress performance use separate paths. Historical failed deliveries are not bulk replayed by this repair.

Additional CI follow-up: stabilize the existing three-layout config audit fixture against its independently running file watcher. One CI job observed an environment-generation conflict during include reread; the write was rolled back. The affected config/reloader/operation code is unchanged by this PR. The adjacent test fixture already supports disabling independent watch notifications while retaining real managed writes and journals. This does not justify weakening the production generation guard.

Retain accepted native child completion ownership beyond the admitting turn and through Gateway restart drain. Bind event persistence, task transitions, history recovery, and delivery to the original assignment receipt, releasing execution holds after terminal persistence and the first handoff.

Keep thread-only wait snapshots from mutating successor assignments. Document the optional exact-assignment transition contract for custom detached runtimes.

Release-note: Fix native Codex child completions lost after parent yield or during Gateway restart drain.
@vincentkoc vincentkoc self-assigned this Sep 23, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review September 23, 2026 05:56
@clawsweeper

clawsweeper Bot commented Sep 23, 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 docs Improvements or additions to documentation agents Agent runtime and tooling extensions: codex plugin: file-transfer size: XL labels Sep 23, 2026
@clawsweeper

clawsweeper Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 23, 2026, 3:23 AM ET / 07:23 UTC (Revision 4).

ClawSweeper review

What this changes

Preserves authority to persist and deliver Codex child results after the parent yields, binds updates to the accepted assignment, and checks custom adapter support before admission.

Merge readiness

✅ Ready for maintainer review

The repair remains necessary on inspected main. No blocking correctness finding remains; the supplied authority and upgrade evidence addresses the earlier concerns.

Priority: P1
Reviewed head: ec2f407aa79b9b9e44f04009b15fc1d6f212ef20

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A coherent repair with relevant runtime, authority-boundary, and upgrade evidence and no identified blocking defect.
Proof confidence 🐚 platinum hermit (4/6) ✨ media proof bonus Sufficient (linked_artifact): The supplied Linux observation demonstrates post-yield persistence and requester resumption at 473a407; the inspected production-path harness and reported nine-case run cover revoked and replaced authority before final effects. Existing schemas and serialization are unchanged, supported by the reported 945-task upgrade/readability check. Actions logs could not be independently opened because their redirect is blocked.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (linked_artifact): The supplied Linux observation demonstrates post-yield persistence and requester resumption at 473a407; the inspected production-path harness and reported nine-case run cover revoked and replaced authority before final effects. Existing schemas and serialization are unchanged, supported by the reported 945-task upgrade/readability check. Actions logs could not be independently opened because their redirect is blocked.
Evidence reviewed 10 items Pinned introduction boundary: Reviewed the merge-base-to-head introduced changes. The supplied test merge is stale, so endpoint drift was not treated as PR-owned removal or regression.
Still necessary on main: Inspected main's completion delivery still lacks retained completion custody and compares the task ID rather than the captured assignment receipt. No verified merged replacement was established, and no released-fix claim is made.
Authority and final effects: The completion owner retains the existing operator authority, checks requester lifecycle and Gateway identity, and separates execution holds from delivery lifetime. The Gateway harness exercises nine live/revoked/replaced cases across input staging, recorder resolution, and compaction retry; negative cases assert no injection, pending input, or transcript mutation.
Findings None None.
Security None None.

How this fits together

The Codex plugin translates native child-agent events into OpenClaw task records and requester continuations. Gateway authority and task ownership checks determine whether a completed result may be persisted and delivered.

flowchart TD
  A[Parent admits child work] --> B[Retained completion authority]
  C[Codex child events] --> D[Exact assignment check]
  B --> D
  D --> E[Persist task result]
  E --> F[Recheck requester authority]
  F --> G[Resume requester]
  F --> H[Reject revoked or replaced owner]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +856, Tests +2399, Docs +37. Total +3292 across 51 files.

View PR surface stats
Area Files Added Removed Net
Source 23 1141 285 +856
Tests 27 2830 431 +2399
Docs 1 37 0 +37
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 51 4008 716 +3292

Review metrics

Metric Value Why it matters
Authority boundary coverage 9 scenarios across 3 final-effect boundaries The harness checks allowed, revoked, and replaced owners at input staging, recorder resolution, and compaction retry.
Production versus test growth production +856, tests and fixtures +2,399 The stated production growth implements retained completion ownership and exact-assignment settlement; tests cover lifecycle and authority failures.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/tasks/detached-task-runtime-contract.ts. Migration or upgrade compatibility proof is recorded; maintainers should verify it before merge.

Technical review

Best possible solution:

Keep completion authority scoped to the original live requester and exact assignment, with execution holds ending after persistence and the first handoff.

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

Yes, from source: let a native child finish after its admitting parent yields; inspected main lacks independent completion custody. This review did not execute a current-main reproduction.

Is this the best way to solve the issue?

Yes. The patch extends the existing authority and task-transition owners, preserves assignment identity through recovery, and avoids bypassing custom adapters.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P1: The reported failure loses native child results after parent yield and prevents the requester workflow from continuing.
  • merge-risk: 🚨 compatibility: Custom detached adapters must implement exact-assignment transitions before native admission; the member-authored discussion documents this tradeoff, early rejection, and preserved legacy calls.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (linked_artifact): The supplied Linux observation demonstrates post-yield persistence and requester resumption at 473a407; the inspected production-path harness and reported nine-case run cover revoked and replaced authority before final effects. Existing schemas and serialization are unchanged, supported by the reported 945-task upgrade/readability check. Actions logs could not be independently opened because their redirect is blocked.
  • proof: sufficient: Contributor real behavior proof is sufficient. The supplied Linux observation demonstrates post-yield persistence and requester resumption at 473a407; the inspected production-path harness and reported nine-case run cover revoked and replaced authority before final effects. Existing schemas and serialization are unchanged, supported by the reported 945-task upgrade/readability check. Actions logs could not be independently opened because their redirect is blocked.

Evidence

What I checked:

  • Pinned introduction boundary: Reviewed the merge-base-to-head introduced changes. The supplied test merge is stale, so endpoint drift was not treated as PR-owned removal or regression. (ec2f407aa79b)
  • Still necessary on main: Inspected main's completion delivery still lacks retained completion custody and compares the task ID rather than the captured assignment receipt. No verified merged replacement was established, and no released-fix claim is made. (src/plugin-sdk/agent-harness-task-runtime.ts:192, dc063e7bc043)
  • Authority and final effects: The completion owner retains the existing operator authority, checks requester lifecycle and Gateway identity, and separates execution holds from delivery lifetime. The Gateway harness exercises nine live/revoked/replaced cases across input staging, recorder resolution, and compaction retry; negative cases assert no injection, pending input, or transcript mutation. (src/gateway/server.native-completion-authority.test.ts:214, ec2f407aa79b)
  • Existing storage contract preserved: The introduced diff leaves both canonical schema SQL files and schema-version declarations unchanged. TaskRecord and TaskPersistenceReceipt retain their existing fields; the unchanged receipt helper freezes assignment identity, and progress detail uses the existing serializer. (src/tasks/task-registry-records.ts:188, ec2f407aa79b)
  • Documented adapter compatibility tradeoff: The MEMBER author's captured body and follow-up explicitly document that custom detached adapters need transitionTaskAssignment for native exact-assignment work. Registration checks the captured owner before child submission, including cached runtimes; unsupported registrations release custody, while unguarded legacy calls remain supported. This bounded compatibility requirement is already addressed in the discussion and docs. Public docs: docs/plugins/sdk-runtime/background-work.md. (docs/plugins/sdk-runtime/background-work.md:308, ec2f407aa79b)
  • Captured runtime and upgrade proof: The supplied snapshot reports a Linux upgrade from b6340c7 to 473a407 with 945 existing tasks readable, followed by a child completing 14 seconds after parent yield and a distinct requester turn receiving its result. It separately reports nine final-effect authority scenarios passing at f23f29e and subsequent mechanical/test-only corrections. The linked Actions job currently reports cancelled; its log redirect was blocked by the reviewer's network allowlist, so individual stage results were not independently replayed or verified from logs. (473a407f8d0d)

Likely related people:

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

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 (3 earlier review cycles)
  • reviewed 2026-09-23T06:05:21.125Z sha 473a407 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-23T06:56:49.670Z sha 1230323 :: blocked before merge. :: none
  • reviewed 2026-09-23T07:08:34.081Z sha ec2f407 :: needs maintainer review before merge. :: none

@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

Please review exact head 1230323ebb11e049cce433943dc983d4cc020165. Both prior rank-up requests are addressed: nine real Gateway final-effect scenarios cover direct staging, recorder resolution and compaction retry for live/revoked/replaced owners; unsupported custom task adapters now fail before native registration, including cached runtime owners. The PR body records the Linux build/type/test evidence, real post-yield deployment proof at the original candidate, and separately scoped follow-ups.

@clawsweeper

clawsweeper Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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 Sep 23, 2026
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

Please review exact head ec2f407aa79b9b9e44f04009b15fc1d6f212ef20. Since the completed 1230323 review, the only source change extracts the unchanged Copilot native-failure fixture into its existing test-support module; production and assertions are unchanged.

The PR body now explicitly supplies the requested storage/upgrade compatibility proof. Both canonical schema SQL files, schema-version declarations, task SQLite reader/writer and receipt helpers have identical Git blobs against b6340c7; TaskRecord and TaskPersistenceReceipt declarations are unchanged. expectedTask reuses existing identity fields, custody is process-local, and progress detail uses the existing detail_json serializer (src/tasks/task-registry.store.kernel.ts:148,209; src/tasks/task-registry-records.ts:188). No migration/backfill is needed. The adapter capability requirement is a separate documented runtime compatibility decision; unguarded legacy calls remain supported.

Observed upgrade proof: the native updater completed b6340c7 to 473a407 on the affected existing installation, doctor reported zero errors/warnings, the existing 945-task cohort remained readable, and a native child completed after parent yield and was persisted/delivered. The final merged-main deployment is still pending. Independent storage audit agrees with this classification.

@clawsweeper

clawsweeper Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@vincentkoc
vincentkoc enabled auto-merge (squash) September 23, 2026 07:31
@vincentkoc
vincentkoc merged commit 4875b96 into main Sep 23, 2026
384 of 387 checks passed
@vincentkoc
vincentkoc deleted the fix/native-completion-custody-20260923 branch September 23, 2026 07:39
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash auto-merge.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 24, 2026
…w#156247)

* fix(codex): deliver native child results after parent yields

Retain accepted native child completion ownership beyond the admitting turn and through Gateway restart drain. Bind event persistence, task transitions, history recovery, and delivery to the original assignment receipt, releasing execution holds after terminal persistence and the first handoff.

Keep thread-only wait snapshots from mutating successor assignments. Document the optional exact-assignment transition contract for custom detached runtimes.

Release-note: Fix native Codex child completions lost after parent yield or during Gateway restart drain.

* fix(tasks): keep transition contracts independent of execution

* test(tasks): isolate legacy dispatch from native settlement

* fix(codex): validate task settlement before native admission

* test(tasks): prove native completion authority at final effects

* test(tasks): pass context to completion authority scenarios

* test(tasks): settle completion request owners before assertions

* test(copilot): complete task runtime capability fixture

* test(tasks): match completion harness runtime contracts

* test(tasks): align authority harness with typed lint

* test(copilot): extract native task failure fixture
@roboclaw-bot roboclaw-bot mentioned this pull request Sep 24, 2026
2 of 8 tasks
zeroaltitude added a commit to zeroaltitude/openclaw that referenced this pull request Sep 26, 2026
…on case

main made CodexNativeSubagentMonitor.registerParent async (Promise<
ParentRegistrationHandle>). This branch's direct-authority cases still used
the handle synchronously (TS2339 on bindTurn/unregister; 6 runtime failures
on the integration tree). Await the registration and each unregister.

'evicts the oldest pending direct spawn evidence instead of refusing the
newest' fails on this branch before and after this change: main reworked
native admission custody (openclaw#156247), so its buffering premise no longer
holds. It is it.skip'd with a pointer to openclaw-7vub rather than guessed at.

Verified: tsgo:extensions:test clean; file 34 passed, 1 skipped.

Co-Authored-By: Tank (claude-opus-5-5) <[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 docs Improvements or additions to documentation extensions: codex extensions: copilot gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. plugin: file-transfer proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL 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.

1 participant