Skip to content

fix(codex): avoid duplicate subagents after yielded fanout - #118644

Merged
vincentkoc merged 1 commit into
mainfrom
codex/beta8-current-main-validation-20260803
Aug 3, 2026
Merged

vincentkoc merged 1 commit into
mainfrom
codex/beta8-current-main-validation-20260803

Conversation

@vincentkoc

Copy link
Copy Markdown
Member

What Problem This Solves

Fixes an issue where Codex app-server users could launch duplicate subagents and time out when a turn spawned children and yielded for their completion.

The accepted child launches were visible in the tool result, but result middleware could remove those structured details before the run attempt recorded continuation evidence. The yielded turn was then treated as replay-safe and the parent prompt ran again.

Why This Change Was Made

Record accepted sessions_spawn evidence from the sanitized execution result before presentation middleware runs, then carry it through the Codex event projector into the normal subagent continuation and replay-safety paths.

This keeps the fix inside the Codex app-server bridge while matching the existing embedded-agent runtime contract.

User Impact

Codex turns that yield after spawning subagents now wait for the accepted children and resume with their results instead of replaying the parent prompt and launching duplicates.

Evidence

  • Before: the exact subagent-fanout-synthesis Codex cell timed out after 90 seconds with six tool calls and duplicate alpha/beta launches.

  • After: Blacksmith Testbox tbx_01kz3nngvx2st4cjwdd7ks9ggy, run https://github.com/openclaw/openclaw/actions/runs/30809157173:

    • targeted Codex lint passed
    • 149 focused Codex tests passed
    • OpenClaw and Codex runtime-pair fanout cells both passed
    • pnpm check:changed passed for extensions, extensionTests, and docs
  • Fresh autoreview: no accepted/actionable findings; overall correctness 0.98.

  • Direct Codex contract checked: turn/steer accepts input only for the matching active turn, so OpenClaw must preserve accepted child-launch evidence and wait rather than replaying the parent prompt.

  • AI-assisted; I reviewed and understand the implementation and proof.

@vincentkoc vincentkoc self-assigned this Aug 3, 2026
@vincentkoc
vincentkoc force-pushed the codex/beta8-current-main-validation-20260803 branch from d364260 to e33d8bb Compare August 3, 2026 11:35
@vincentkoc
vincentkoc marked this pull request as ready for review August 3, 2026 11:36
@clawsweeper clawsweeper Bot added rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. 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. labels Aug 3, 2026
@clawsweeper

clawsweeper Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 3, 2026, 7:42 AM ET / 11:42 UTC.

ClawSweeper review

What this changes

The branch records accepted sessions_spawn results before result middleware can remove their structured details, then carries that child-session evidence into Codex yielded-turn continuation and replay-safety results.

Merge readiness

⚠️ Needs maintainer review before merge - 3 items remain

Keep this PR open for maintainer handling. The source-level path and focused tests are coherent, but OpenClaw policy requires direct inspection of the sibling Codex source before any Codex verdict, proof-sufficiency claim, or merge recommendation; ../codex is absent in this read-only review environment.

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

Review scores

Measure Result What it means
Overall readiness 🌊 off-meta tidepool No calibrated PR rating is issued because repository policy prohibits a Codex verdict until sibling Codex source is inspected directly.
Proof confidence 🌊 off-meta tidepool Not applicable: This is a repository-member PR, so the external-contributor proof gate does not apply; the PR body nevertheless reports a focused Testbox fanout run, pending the required direct Codex-contract inspection.
Patch quality 🌊 off-meta tidepool No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This is a repository-member PR, so the external-contributor proof gate does not apply; the PR body nevertheless reports a focused Testbox fanout run, pending the required direct Codex-contract inspection.
Evidence reviewed 5 items Pre-middleware capture: The branch snapshots the sanitized raw tool result before middleware, then extracts accepted child-spawn evidence from that snapshot so presentation middleware cannot erase the continuation fact.
Continuation ownership: The shared requester-yield owner consumes accepted child spawns by run id and child session key before rearming yielded requester completion delivery, so the proposed telemetry is on the relevant continuation boundary.
Replay-safety projection: The branch makes accepted child spawns part of Codex replay-side-effect evidence and includes them in the projected attempt result; its focused tests cover middleware detail stripping and yield continuation projection.
Findings None None.
Security None None.

How this fits together

The Codex extension bridges Codex app-server tool calls into OpenClaw tools, applies result middleware, and projects the outcome into the embedded-agent run result. When a parent turn yields after launching child sessions, that result determines whether OpenClaw waits for those children or may replay the parent turn.

flowchart LR
  A[Codex parent turn] --> B[OpenClaw dynamic tools]
  B --> C[Result middleware]
  C --> D[Codex event projector]
  D --> E[Embedded run result]
  E --> F{Yielded turn}
  F --> G[Wait for child sessions]
  F --> H[Replay only when safe]
Loading

Decision needed

Question Recommendation
Can a maintainer provide or perform the required direct sibling-Codex protocol inspection for this exact head before it is merged? Re-review with sibling Codex source: Use an environment containing ../codex to inspect the active-turn protocol and validate this replay-safety boundary before merging.

Why: The repository policy explicitly prohibits a Codex verdict, proof-sufficiency claim, or merge recommendation without that direct source inspection; the review environment lacks ../codex.

Before merge

  • Resolve merge risk (P1) - The patch changes yielded-turn continuation and replay safety, but the required direct verification of the Codex active-turn protocol is unavailable because sibling ../codex source is missing from this review environment.
  • Complete next step (P2) - This protected, member-authored Codex PR needs the repository-required direct upstream protocol inspection rather than an automated repair or close action.
Agent review details

Security

None.

PR surface

Source +28, Tests +58. Total +86 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 31 3 +28
Tests 2 60 2 +58
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 91 5 +86

Review metrics

Metric Value Why it matters
Production vs test delta production +31/-3, tests +60/-2 The production growth adds one telemetry fact across the tool bridge and projector, while focused regression tests cover both middleware stripping and yield replay safety.

Merge-risk options

Maintainer options:

  1. Verify the upstream protocol before merge (recommended)
    Inspect the matching Codex active-turn implementation and merge only if its turn-steering contract requires preserving accepted child-spawn evidence through this bridge.
  2. Pause for owner confirmation
    Keep this PR open until a Codex-area owner records the direct protocol evidence required by repository policy.

Technical review

Best possible solution:

Verify the active-turn and yielded-continuation protocol directly against sibling Codex source, then retain this narrow telemetry-preservation fix if that contract confirms OpenClaw must wait rather than replay the parent turn.

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

No high-confidence local runtime reproduction was run. The source and focused branch tests establish the suspected middleware-stripping path, but direct Codex protocol confirmation is unavailable in this environment.

Is this the best way to solve the issue?

Unclear. Capturing accepted spawn evidence before presentation middleware is the narrow owner-boundary repair suggested by the source, but repository policy requires direct Codex-source validation before it can be judged the best solution.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P1: Replay of a yielded parent after accepted child launches can duplicate subagents and prevent an active agent workflow from completing.
  • add merge-risk: 🚨 session-state: The branch changes the recorded child-session facts used to decide yielded-turn continuation and replay safety.
  • add rating: 🌊 off-meta tidepool: Overall readiness is 🌊 off-meta tidepool; proof is 🌊 off-meta tidepool and patch quality is 🌊 off-meta tidepool.

Label justifications:

  • P1: Replay of a yielded parent after accepted child launches can duplicate subagents and prevent an active agent workflow from completing.
  • merge-risk: 🚨 session-state: The branch changes the recorded child-session facts used to decide yielded-turn continuation and replay safety.
  • rating: 🌊 off-meta tidepool: Overall readiness is 🌊 off-meta tidepool; proof is 🌊 off-meta tidepool and patch quality is 🌊 off-meta tidepool.

Evidence

What I checked:

  • Pre-middleware capture: The branch snapshots the sanitized raw tool result before middleware, then extracts accepted child-spawn evidence from that snapshot so presentation middleware cannot erase the continuation fact. (extensions/codex/src/app-server/dynamic-tools.ts:655, e33d8bb8dd60)
  • Continuation ownership: The shared requester-yield owner consumes accepted child spawns by run id and child session key before rearming yielded requester completion delivery, so the proposed telemetry is on the relevant continuation boundary. (src/agents/subagent-registry-requester-yield.ts:41, 757d22020362)
  • Replay-safety projection: The branch makes accepted child spawns part of Codex replay-side-effect evidence and includes them in the projected attempt result; its focused tests cover middleware detail stripping and yield continuation projection. (extensions/codex/src/app-server/event-projector.ts:403, e33d8bb8dd60)
  • Feature-history provenance: The current Codex spawn path appears to build on Jason (Json)'s searchable session-spawn repair and Peter Steinberger's later app-server/steering refactor. (extensions/codex/src/app-server/dynamic-tools.ts:417, e5798e547770)
  • Required Codex-contract check unavailable: Repository policy requires the reviewer to inspect sibling ../codex source for the exact protocol/runtime behavior before issuing a Codex verdict. That sibling checkout is absent, and this read-only environment cannot clone it. (AGENTS.md:13, 757d22020362)

Likely related people:

  • Peter Steinberger: Commit e5798e5 refactored the Codex app-server boundary and deferred spawn-agent steering that this continuation path relies on. (role: recent app-server and steering refactor author; confidence: high; commits: e5798e547770; files: extensions/codex/src/app-server/event-projector.ts, extensions/codex/src/app-server/dynamic-tools.ts)
  • Jason (Json): Commit f79d842 introduced closely related Codex session-spawn handling. (role: session-spawn behavior contributor; confidence: medium; commits: f79d84202904; files: extensions/codex/src/app-server/dynamic-tools.ts)

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.

@vincentkoc

Copy link
Copy Markdown
Member Author

Maintainer decision: proceed with this owner-boundary fix.

I completed the required direct sibling Codex inspection against @openai/codex 0.146.0 (rust-v0.146.0, commit e363b08c9175ac1cbe5893615dd2cb9ddf95043b):

  • ../codex/codex-rs/app-server/src/request_processors/turn_processor.rs:920-980: turn/steer loads the thread, requires the expected active turn id, and rejects no-active-turn or mismatched-turn requests.
  • ../codex/codex-rs/core/src/session/mod.rs:3920-4000: steering is accepted only while the matching task/turn remains active; accepted input is queued on that active task.
  • ../codex/codex-rs/app-server-protocol/src/protocol/v2/turn.rs:175-196: TurnSteerParams requires the expected active turn id.
  • ../codex/codex-rs/app-server-protocol/src/protocol/v2/shared.rs:105-110: the protocol explicitly distinguishes non-steerable active turns.

That contract confirms the replay-safety boundary: once OpenClaw has accepted child launches and yielded the parent turn, it must preserve those launch facts and settle through the existing requester-continuation path. Replaying the parent prompt is not a valid substitute for steering the completed/yielded turn and causes the duplicate launches reproduced by the QA scenario.

ClawSweeper rank-up moves:

  • Direct upstream protocol inspection: completed above.
  • Codex-area owner/maintainer decision: approved for merge after the existing exact-head gates.

No additional code change is warranted. The patch already passed the OpenClaw/Codex fanout runtime pair, 149 focused tests, check:changed, fresh full-branch autoreview, and hosted CI on e33d8bb8dd60fc3bb8bbd40be35c52b84c4f84df.

@vincentkoc
vincentkoc merged commit 8895b0c into main Aug 3, 2026
152 of 155 checks passed
@vincentkoc
vincentkoc deleted the codex/beta8-current-main-validation-20260803 branch August 3, 2026 11:45
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash.

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

Labels

extensions: codex maintainer Maintainer-authored PR 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: 🌊 off-meta tidepool PR readiness rating does not apply to this item. size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant