Repository navigation
refactor(codex): centralize native completion delivery - #206447
Conversation
Use the core completion obligation for native result ownership, consumption, retry and retirement. Keep Codex receipt correlation and binding persistence in the adapter.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs changes before merge. What this changesThis PR moves native Codex completion ownership, retries, consumption, and retirement into the core completion obligation. Example: A Codex parent finishes while a native child is still running.
Review scores
ProductKind: Refactor · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Needs changes before merge - 5 items remain Keep open: this maintainer-approved consolidation remains useful, but grandchild recovery and several diff-caused CI failures need repair before merge. Reviewed head: Before merge
Findings
Provenance
Agent review detailsHow this fits togetherThe Codex monitor translates native completion events and receipts into core lifecycle operations; the plugin retains native correlation and binding persistence. flowchart LR
A[Codex events and receipts] --> B[Native monitor]
B --> C[SDK completion registration]
C --> D[Core completion obligation]
D --> E[Requester delivery]
D --> F[Native binding adapter]
Technical reviewBest possible solution: Keep the approved core owner and native adapters, while restoring fresh-custody recovery and migrating affected tests through supported SDK fixtures. Do we have a high-confidence way to reproduce the issue? This is an ownership refactor; main's duplicate lifecycle is source-confirmed, and candidate recovery failures are supported by source tracing and exact-head CI annotations. Is this the best way to solve the issue? The approved SDK seam fits the existing ownership boundary, but failed native observation must preserve recovery through a fresh registration rather than retain unusable custody. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 2b15ecec6bba. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceAcceptance criteria:
What I checked:
PR surfaceSource +168, Tests +235, Docs +12. Total +415 across 15 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 27, 2026, 2:08 AM ET / 07:08 UTC. |
|
Merged via squash auto-merge.
|
…restoration-ci-189390-20261127 * commit '6feeb50a3f14fbf0aa5167d342f186dc4d67fc18': (9846 commits) fix: stop 2026-11-17 main Git checkouts from half-switching on a schema update (#206341) refactor(codex): centralize native completion delivery (#206447) fix(subagents): finish claimed stops after session rotation (#206405) fix: let owners fork a chat with exec after a subagent or exec completion (#206483) test(cli): gate agent --local cold-start processes and workers (#206466) perf(ci): skip baseline inventory when line-cap debt is empty (#189909) refactor(test): share core process-result fixtures (#174149) refactor(ci): reuse canonical budget flag parsing (#189480) fix: recover Codex chats after oversized requests (#206475) fix(agents): skip the bootstrap ritual in one-shot runs (#206477) fix(test): preserve stack coordinates in redacted failure reports (#152384) fix(gateway): return consistent unavailable response guidance (#191933) fix: preserve emphasis in Markdown table row labels (#205349) fix(nextcloud-talk): keep webhook spool helpers private (#206470) perf(plugins): overlay native receipts once per visible root (#206464) fix: keep GitHub comment approvals alive and skip repeat approval on the session PR (#206129) perf(config): retain one snapshot for unchanged validation results (#206465) refactor(test): reuse canonical secret fixture cleanup (#189492) refactor(subagents): own descendant Stop cancellation (#206444) refactor(subagents): keep announce cleanup action type private (#206407) ...
* commit 'fd681ab8786e062045fa5ec6261b1b06f60832eb': (2115 commits) fix: keep doctor --fix pending checks from creating SQLite sidecars (#206485) fix(ci): update iOS screenshot reducer gate (#206497) fix: keep chat photo previews sharp within their byte limits (#206461) fix: let agents use short Workboard card IDs fix(tui): run provider sign-in in the local TUI (#200605) improve(config): reduce repeated directory checks for larger agent rosters (#206494) perf(test): reuse the Periphery producer workflow snapshot (#189681) fix(ci): keep locale assets within the installed package budget (#206492) fix: preserve failed Apple chat messages across partial history pages (#205404) improve: avoid merging unrelated settings for agent directory lookups (#206489) fix: show typing while a queued follow-up turn runs (#201920) fix: stop 2026-11-17 main Git checkouts from half-switching on a schema update (#206341) refactor(codex): centralize native completion delivery (#206447) fix(subagents): finish claimed stops after session rotation (#206405) fix: let owners fork a chat with exec after a subagent or exec completion (#206483) test(cli): gate agent --local cold-start processes and workers (#206466) perf(ci): skip baseline inventory when line-cap debt is empty (#189909) refactor(test): share core process-result fixtures (#174149) refactor(ci): reuse canonical budget flag parsing (#189480) fix: recover Codex chats after oversized requests (#206475) ...
* commit 'fd681ab8786e062045fa5ec6261b1b06f60832eb': (923 commits) fix: keep doctor --fix pending checks from creating SQLite sidecars (#206485) fix(ci): update iOS screenshot reducer gate (#206497) fix: keep chat photo previews sharp within their byte limits (#206461) fix: let agents use short Workboard card IDs fix(tui): run provider sign-in in the local TUI (#200605) improve(config): reduce repeated directory checks for larger agent rosters (#206494) perf(test): reuse the Periphery producer workflow snapshot (#189681) fix(ci): keep locale assets within the installed package budget (#206492) fix: preserve failed Apple chat messages across partial history pages (#205404) improve: avoid merging unrelated settings for agent directory lookups (#206489) fix: show typing while a queued follow-up turn runs (#201920) fix: stop 2026-11-17 main Git checkouts from half-switching on a schema update (#206341) refactor(codex): centralize native completion delivery (#206447) fix(subagents): finish claimed stops after session rotation (#206405) fix: let owners fork a chat with exec after a subagent or exec completion (#206483) test(cli): gate agent --local cold-start processes and workers (#206466) perf(ci): skip baseline inventory when line-cap debt is empty (#189909) refactor(test): share core process-result fixtures (#174149) refactor(ci): reuse canonical budget flag parsing (#189480) fix: recover Codex chats after oversized requests (#206475) ...
* refactor(codex): centralize native completion delivery Use the core completion obligation for native result ownership, consumption, retry and retirement. Keep Codex receipt correlation and binding persistence in the adapter. * fix(agents): preserve native receipts across duplicate observers * fix(plugin-sdk): guard absent completion context resolver * refactor(agents): clarify completion attempt waiting * fix(agents): keep completion fixtures on the test SDK boundary * fix(agents): share completion custody across native clients * fix(codex): release idle transport before completion readiness * test(codex): use issued scope in parent continuation fixture * fix(codex): retain cancelling child until process cleanup * test(codex): await completed idle-thread ownership release
…06080) (cherry picked from commit 47027a2) Release adaptation: No source or test changes from main. Stable already carries prerequisite #206014 as 2940130, so the monitor and both regressions apply cleanly. Later same-file #206447 (a9569e9) centralizes completion delivery; it is not needed for the native-turn and contextual-receipt guards and is not included. Co-authored-by: RomneyDa <[email protected]>
Fixes #206438
What Problem This Solves
Maintainers currently have to update two completion lifecycles: the shared subagent policy and the Codex plugin's separate ownership, retry, and receipt state. This cutover makes native Codex completions use the existing core completion obligation from 206383.
User Impact
Native child results keep their current routing, cancellation, retry delays, and persisted binding format. The plugin keeps Codex-specific receipt correlation; core owns whether a completion is pending, consumed, retrying, or retiring. No configuration or migration is required.
Why This Change Was Made
registerAgentHarnessCompletionextends the existing completion SDK subpath. The adapter reports completion and consumed receipts, supplies native readiness and persistence effects, and consumes the core handle's recorded facts. The duplicate plugin delivery map, flags, timers, counters, and attempt joining are removed. The existing obligation lifecycle is shared by the ordinary announce flow and the native registration; its policy remains in the owner established by 206383. Its lifecycle implementation is split into a sibling module to stay inside the existing source-size limit, with all callers migrated and no compatibility re-export.The operator explicitly approved this narrow SDK extension and core-owner integration in chat. The approval covers the first completion-delivery/receipt cutover; unrelated model, admission, cancellation, and history machinery is deferred.
Native receipts do not identify the child turn. The plugin therefore retains path aliases, predecessor ordering, and result correlation instead of moving Codex wire parsing into core. The inspected upstream source is Codex commit
414782450952a196bbb64b1605a458c2531c47b6:codex-rs/app-server-protocol/src/protocol/v2/item.rs(CollabAgentToolCall,CollabAgentState,RawResponseItemCompletedNotification),codex-rs/protocol/src/models.rs(AgentMessage), andcodex-rs/core/src/context/{subagent_notification,inter_agent_completion_message}.rs.Native detached results retain their six existing retry delays; persisted registry completions retain their existing expiry/backoff policy. These are different persistence mechanisms under the same completion owner. Consumed results never re-enter delivery while bookkeeping retries. Ownership uses the logical agent/requester/assignment across replacement client contexts. If observation discovers unavailable custody, core releases that observation and preserves the durable assignment for fresh recovery.
Ownership map
All abbreviated filenames below are
extensions/codex/src/app-server/native-subagent-<name>.ts.completion-delivery,delivery-receiptsassignment,notification,notification-routing,turn-observationhistory-recovery,recovery-coordinator,retryretrystill has production consumers.history-owner,pending-assignments,assignment-storeassignment-inventoryadmission-custody,model-input,model-lookup,model-sourceparent-owner,monitor-types,monitor,monitor-runtimecancellation-selection,cancellation-result,cancellation-wait,close-ownersubmission,submission-call,submission-ownerrosterAgentHarness.readNativeSubagentsadapter; unchanged.extensions/codex/test-api.tsand read-onlyextensions/copilot/src/tool-bridge.tsuse the existing SDK session-key predicate for tool context; neither needs a new core-state reader in this slice.Mechanical caller updates
subagent-announce.ts: import the shared obligation factory from its lifecycle module.native-subagent-monitor-types.ts: replace plugin-owned delivery fields with the completion handle type.native-subagent-monitor.test-support.ts,native-subagent-monitor.live.test.ts, andshared-client-lifetime.test-support.ts: construct real host-issued scopes through the existing private test SDK.plugin-test-runtime.tsprovides a test-only factory reexport and remains excluded from production JS/declarations.native-subagent-inventory.test.ts: remove assertions for the already-ignoredexpectedRequesterdelivery argument; keep all requester/result and recovery assertions.run-attempt-parent-continuation.test.ts: use the same host-issued test scope and remove the ignored delivery argument expectation.native-subagent-monitor.test.ts: await completed ownership release, rather than only the start of unsubscribe; keep the exact-once and non-reusability assertions.native-subagent-assignment-inventory.ts,native-subagent-parent-owner.ts, andnative-subagent-submission-owner.ts: consume the handle's recorded completion facts.native-subagent-monitor.ts: reset the completion handle when a native assignment resumes.Related contributor work
Related and overlapping: 194748 and 194764 by @dubr1k; 200947 by @shannon0430. This PR does not copy their unmerged patches or claim their separate fixes. After landing, each PR will receive the landed link and a specific supersession assessment; unresolved restart and retirement-policy work will remain explicit.
Evidence
277b251bfa80c863e4408607bce9b372eddc24c9, including 206383. Campaign baseline:df78bb4a3ac.test-api.ts: 9,957 → 9,799 lines (158 removed). Subagent-mentioning lines: 463 → 460. Direct imports of core subagent internals: 0 → 0.nativeCompletionDelivered,completionDeliveryAbandoned,completionDeliveryAttempt,completionDeliveryTimer,deliveryOwnerKey): 40 → 0, measured withgit grep -c.3c178af4e45cc286bd5f3e0c6d883dbabb6d4427, followed by branch reviews of the handoff-order repair at264c15706de4064a627044df7dd4ab56afa763cf, the production CI repair atecc87edc7c8454741086a5cca389753b5f8e9bab, and the final test-only synchronization ate79e8a308f77dab0a1bbf3947620c6d3b97eb6df; all found no actionable findings, with unchanged owner/custody/source context supplied.264c15706de4(same files plus the shared lifecycle). Clone SLOC 6 → 0; score 38.84 → 41.19 with expanded coverage, so this is not an aggregate complexity reduction. NativedeliverAttempt(CC 29) disappears; nativeapplyReceiptsCC 15 → 12; sharedattemptis CC 33 and the enclosing lifecycle is CC 63 (the scanner includes nested callbacks). Existing receipt matcher CC 11 and SDK delivery CC 26 are unchanged. The final repair adds one native cancellation-owner guard.buildRequesterCompletionDeliveryResult,hasMessagingToolDeliveryToSource, andisDirectMessageDeliveryTargetreexports insubagent-announce-completion-delivery.ts, plus the first two exports insubagent-announce-obligation.ts.pnpm plugin-sdk:surface:checkon the same Testbox reproducespublic exports 3931 > 3930on the pinned base; this branch retains 3,931 public exports. The added registration and test issuer are private-local. The public ratchet failure is pre-existing.registerAgentHarnessCompletioncontract on the existing completion subpath.pnpm plugin-sdk:api:diffand its--require-acknowledgement --acknowledge ff7b090finvocation passed on the Testbox with No Plugin SDK API changes; no new public barrel export is added.264c15706de4; all inventory cases, SDK tests and receipt-contention cases passed before that adapter-order repair. The full subagent/native run confirmed 2,101 passing tests across 173 files (one skipped file/test) before its Testbox lease ended; its remaining result is unknown. The replacement allocation queued and was stopped, so PR CI supplies broad proof under the coordinator's standing rule. The API acknowledgement check passed with no public API changes.264c15706de4exposed two obsolete parent-continuation fixture cases and a real descendant-Stop regression. The fixture now uses the host-issued test scope. The adapter retains a cancellation-requested child without a completion scope until the existing cancellation owner settles its process. CI atecc87edc7c84passes all three cases. Its remaining native idle-pool failure observed unsubscribe start before ownership release finished; the final test-only change waits for that actual completion without relaxing any assertion. Current-head CI owns the final broad proof.e79e8a308f77dab0a1bbf3947620c6d3b97eb6df, including the previously failing Codex shard's real-process Stop, parent continuation, native completion, and idle-pool cleanup cases. Native preparation records the same head; GitHub CI gates remain enforced for merge.The documented main failure
preserves routed native Stop authority … (consumed-session)was not reached by the interrupted full Testbox suite. No passing full-suite claim is made.