fix(server): return delegated waits on pending approvals #20037
main fromrefs/pull/20037/head·merged by juliusmarminge View on GitHubA child waiting for approval could leave both agents blocked inside delegate_task(mode="wait"). The wait now returns the oldest live approval identity for that task's own unfinished run, while the child keeps running and later delivers its normal completion.
Only requestId, approval kind, and runId are exposed. Existing approval holders keep decision authority; callers must inspect the fresh full request because a persisted record can outlive its provider callback. This change adds no async approval notices or approval responder.
Thanks @gustavonline for the original implementation. This maintainer takeover preserves the contributor history and merges pinned main b2fa5d3, consolidates tests, and reduces ownership selection to one private helper.
Verification at a9abaa4:
- 48 → 41 tests across three existing files; 414 net test lines removed. Incoming main adds one replay case, so all 42 current cases pass fresh on this head. The regression fails with the original wait predicates and passes when restored.
- Scoped lint, formatting, contracts and server typechecks pass.
- Real Codex CLI 0.163.0 parent/child acceptance on Linux Node 24, fresh on this merged head: a 120-second wait returned in 5.4 seconds with
status=running,hasPendingQuestion=false, identity-onlypendingApproval, andwaitTimedOut=false. The parent asked once, and the harmless fixture command remained unexecuted until the external client approved it through public RPC. The child then completed; one normal completion notification was acknowledged by the parent. - Independent Opus and Sol whole-PR reviews: both clear after three parallel review rounds, including the full main-integrated diff. The first round corrected the existing result-type docs and strengthened the legacy fixture without adding cases.
Before/after and live-provider evidence. The test server used disposable state and was stopped after verification. No browser, Electron, Windows, macOS, iOS, Android, relay/tunnel, or real-provider cancellation/restart acceptance is claimed. Deterministic integration covers ownership/filtering, initial retry, legacy fallback, oldest approval, resolution, cancellation and completion deduplication. A failed completion-wake upgrade can still delay delivery; that recovery limitation predates this change.
CI: the single authorized read at 2026-10-20 00:20 UTC reports MERGEABLE, no failed checks, and CodeRabbit pending. Full test/typecheck/build workflows are absent from that snapshot, so this is CI pending, not a full-CI pass. The coordinator owns the final sweep and landing; no watchers, repeat polls, or unchanged-head review requests.
Tests: GPT-6-Astra; implementation and live verification: GPT-6.1-Sol; independent reviews: Claude Opus 5.5 and GPT-6-Sol. Harnesses: Codex and Claude Code through T3 Code.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
Approvability#
Verdict: Approved at
1babdc3Macroscope's review found this PR approvable — This is a narrowly scoped delegated-wait bug fix that reports approval identity and returns control without deciding approvals, cancelling child work, or changing defaults. Extensive unit and integration coverage exercises ownership, stale-request, cancellation, retry, and eventual completion behavior.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).Warning
Review limit reached#
Only developers with an assigned seat can use this organization's usage-based review budget, and seats here are assigned manually. Ask an admin to assign a seat, or change the review continuation mode in Billing.
Next included review available in 1 minute.
View limit details
-
Limit details: You’ve used all 10 included reviews currently available.
Review configuration:
⚙️ Run configuration
-
- Configuration used: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Advanced
- Run ID:
10420c79-ae24-4d1f-89bb-9da1b1b0aa75
📥 Commits
-
Reviewing files that changed from the base of the PR and between a9abaa42fd0ccb4344bd2e5aa8afe31aab4e28c3 and 929a50084aed9193deeff70c89c0707e91706a46.
📒 Files selected for processing: 6
-
apps/server/src/mcp/OrchestratorMcpService.tsapps/server/src/mcp/OrchestratorMcpToolkit.integration.test.tsapps/server/src/mcp/toolkits/orchestrator/tools.tsdocs/orchestration-v2/orchestrator-mcp-server.mdpackages/contracts/src/orchestratorMcp.test.tspackages/contracts/src/orchestratorMcp.ts
-
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
-
⚙️ Run configuration
-
- Configuration used: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Advanced
- Run ID:
d320b4ec-b4d9-426f-92d8-aecec636cde7
📥 Commits
-
Reviewing files that changed from the base of the PR and between 1f7aa2b2f02ced24290cf1b677ad21b70d58df19 and a9abaa42fd0ccb4344bd2e5aa8afe31aab4e28c3.
📒 Files selected for processing: 6
-
apps/server/src/mcp/OrchestratorMcpService.tsapps/server/src/mcp/OrchestratorMcpToolkit.integration.test.tsapps/server/src/mcp/toolkits/orchestrator/tools.tsdocs/orchestration-v2/orchestrator-mcp-server.mdpackages/contracts/src/orchestratorMcp.test.tspackages/contracts/src/orchestratorMcp.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
-
📝 Walkthrough
-
Delegated task results now include metadata for the oldest qualifying pending approval. Initial and streaming waits end when such an approval appears. The contract, tool descriptions, documentation, and integration tests describe or verify this behavior.
Changes: Delegated task approvals
Layer / File(s) Summary Pending approval result contract
packages/contracts/src/orchestratorMcp.ts,packages/contracts/src/orchestratorMcp.test.ts,apps/server/src/mcp/toolkits/orchestrator/tools.ts,docs/orchestration-v2/orchestrator-mcp-server.mdThe delegated-task result contract adds nullable approval metadata. Contract tests and documentation describe the metadata, supported approval kinds, and requirement to read the current request from the child thread. Approval ownership by task run
apps/server/src/mcp/OrchestratorMcpService.ts,apps/server/src/mcp/OrchestratorMcpToolkit.integration.test.tsThe service selects the oldest pending live approval associated with an active child run. Integration tests cover request filtering, task ownership, legacy ownership fallback, and timestamp ordering. Wait, status, and completion flow
apps/server/src/mcp/OrchestratorMcpService.ts,apps/server/src/mcp/OrchestratorMcpToolkit.integration.test.tsTask responses expose qualifying approvals, and initial and streaming waits end when one appears. Integration tests cover cancellation, resolution, completion, and parent continuation delivery. Priority: ➖ Normal
Estimated code review effort: 3 (Moderate) | ~25 minutes
Change: Bug fix
Sequence Diagram(s)#
sequenceDiagram participant ChildRun as Child task run participant Service as OrchestratorMcpService participant Caller as delegate_task caller participant ChildThread as Child thread ChildRun->>Service: Provide active run approval status Service->>Caller: Return pendingApproval and end wait Caller->>ChildThread: Read the current approval requestSuggested labels:
size:LSuggested reviewers:
bil0000
Merge Risk: ⚪ Minimal · up to
a9aba-
Delegated task waits now return early when the child task has a pending approval. The result reports only the approval's identity, so the parent can see the request without gaining authority to decide it. Pending approvals remain visible because the loader keeps their nodes when it trims settled leaf nodes. No outstanding defects were identified, and the change appears ready to merge.
Security architecture risk: 🔵 Low · up to
a9aba-
The change reports an approval’s identity without giving the parent permission to approve it. Task ownership checks remain in place. Recovery after interruption and compatibility with independently updated clients were not fully established.
Retained concerns No architecture-level concerns identified.
Security review details
-
Security Blast Radius
- inferred — In the inspected task APIs, newly exposed approval metadata is bounded to an app-owned task belonging to the caller’s parent thread and qualifying unfinished runs in that task’s child thread. Supplying a foreign task identifier does not bypass the parent-task ownership check.
Trust Boundaries and Controls
- observed — The new result transfers identifiers, not an approval payload or approval capability. Existing pending-request tools list and read user questions, and their responder dispatches the question-response command rather than an approval decision. The inspected path therefore preserves the separation between observing an approval and authorizing the requested action.
Resilience and Maintainability Implications
- observed — Incomplete waits promote later completion delivery before returning, but dispatch failures are logged without failing the wait result. This failure handling predates the PR. Successful approval-to-completion delivery is covered by source assertions; replay after failed promotion or restart was not established.
-
Pre-merge checks:
3 · 1-
Failed checks: 1 warningCheck name Status Explanation Resolution Description check The description clearly explains the problem, implementation, limitations, and verification results. However, it omits the required section headings and does not provide a triaged issue or discussion … Add the required Problem, Change, Scope and approval, and Verification headings. In Scope and approval, link the triaged issue or maintainer discussion and include the explicit approval comment, or explain why this focused fix qualifies for… Passed checks: 3 passed-
Check name Status Explanation Title check The title clearly and concisely describes the main change: delegated waits now return when pending approvals exist. Linked Issues check Check skipped because no linked issues were found for this pull request. Out of Scope Changes check Check skipped because no linked issues were found for this pull request.
Full details: Description check
-
Explanation
The description clearly explains the problem, implementation, limitations, and verification results. However, it omits the required section headings and does not provide a triaged issue or discussion link with explicit maintainer approval of the scope.
Resolution
Add the required Problem, Change, Scope and approval, and Verification headings. In Scope and approval, link the triaged issue or maintainer discussion and include the explicit approval comment, or explain why this focused fix qualifies for an exemption. Keep the existing verification details under Verification.
-
✨ Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
-
I verified this PR at
1babdc3682with real Codex CLI parent/child sessions, combined with the local approval-notice patch 8b0623408e offered on #15082, on main81493efb71(which includes #19630).- A
mode: "wait"delegation returned in about four seconds against a 120-second budget:status: "running",hasPendingQuestion: false, apendingApprovalidentifying the live command request and its run, andwaitTimedOut: false. The parent asked the user once. After the test client approved the harmless fixture command, the child completed and the parent received its completion wake. - Async delegation woke an idle parent. Two successive command approvals produced two distinct notices, then normal completion delivery. Resolving an approval while the parent was active cancelled the queued notice before delivery.
- Stop while the parent was active cancelled the queued notice and live child request, interrupted the child, and marked completion delivery disposed. No approval or completion message subsequently woke that parent.
The combined branch passed 104 focused server/contract/client tests plus both MCP toolkit integration tests (106 total), and scoped repository TypeScript/Effect checks. Approval decisions above came from the test client, through the same public RPC used by clients; the parent was not given approval authority. This was one-host provider/API acceptance, not interactive web, Electron, native-mobile, or remote acceptance.
For the sign-in remainder of #15082: an actual delegation to a configured Codex instance with an empty auth home returned
provider_unavailableand explicitcodex logininstructions to the parent before creating a child. That preflight case already reaches the caller. A sign-in flow that pauses an existing child still needs a concrete reproducer; internalauth_refreshdoes not establish one.Verification performed with GPT-6.1-Sol through the Codex harness.
- A
juliusmarminge assignedjuliusmarminge
Taking over this one for maintainer batch scheduler-tasks-05. I will preserve your commits, reduce the tests to focused behavioral proof, rebuild the remaining implementation against current conventions, and run independent reviews. The change will stay on this PR; landing remains with the coordinator. Thanks @gustavonline for identifying the blocked-wait approval path.
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:L
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
juliusmarminge merged this6f89154
juliusmarminge closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes