Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): a delegated task waiting for an approval notifies its idle parent #35433

Openjuliusmarmingewants to merge 2 commits intomain fromrefs/pull/35433/headopened View on GitHub

juliusmarmingecommented

Cause: DelegatedTaskQuestionReactor only handled runtime requests of kind user_input, in its live path (runtime-request.updated), its run-end catch-up path and its subagent-settled cancel path. Separately, Orchestrator.isStaleQuestionWake only kept a queued delegated-task notice alive while a pending user_input request matched it, so even a reactor fix produced 0 notices. Fix: the reactor now also handles provider approval kinds (the ProviderRequestKind set, the same set OrchestratorMcpService.pendingTaskApproval treats as approvals). Only pending live approvals raise a notice, matching pendingTaskApproval and the catch-up path. An approval that cannot be answered live (for example the message-capability command request in the existing question test) is still skipped. For approvals, wakeParent queues an advisory notice that names the task, request kind, requestId and child threadId. It says the parent agent cannot approve it and should tell the user or task_cancel and relaunch the task. Its summary reads 'Delegated task "…" needs approval'. Approval notices reuse the message:delegated-task-question:: id, so the existing cancelQueuedWakes logic cancels them once the approval resolves or the task settles. isStaleQuestionWake now matches by request id and pending status, not by kind. No new regex or parser.

Fixes pingdotgg/t3code#22925

Reproduction on main

On origin/main f03db4fbef: started T3CODE_DEV_SEED=0 vp run dev (fresh database) and added a scratch git project. Ran node apps/server/src/bin.ts thread start --provider claudeAgent --model claude-haiku-5-5 with a prompt telling the parent to call delegate_task once (mode async, same provider instance, runtimeMode approval-required) for a child that runs the Bash command date > stamp.txt, then end its turn without polling. Observed in the dev database (read-only) and the web UI: the parent's only run completed at 17:20:02 after replying with the childThreadId. The subagent was app_owned, running, completionWake=always. The child raised a command runtime request at 17:20:03 that stayed pending. At 17:26:43 the parent still had only its two original messages and one run: no notification message and no queued or new run. The parent's UI showed the 'Subagent needs approval' banner with Approve/Decline while the parent agent stayed idle. A unit test added to Orchestrator.control-reads.test.ts (idle parent, async child with a pending live command request, expect one delegated_task notice) fails on main with 0 notices, and passes when the request kind is switched to user_input.

Evidence

Run the parent with one async MCP delegation, let its turn finish, then raise the child's command approval for date > stamp.txt. Leave approval unanswered. Real web client: Chromium, 1280×800, light theme, fresh synthetic data on both commits.

BeforeAfter
f03db4fbefd9a1ed3a06
Before: parent stays idle with approval pendingAfter: parent receives an update and replies
Before recordingAfter recording

Scenario driver. The approval remains unanswered in both captures. The base parent has one run and no approval notice; the fixed parent receives one notice and starts a second turn.

AI-assisted; verified with the tests and tools listed above.

Not shown:

  • Live-provider behavior and approval kinds other than command were not exercised.

Tests

Reproduced first: vp test run src/orchestration-v2/Orchestrator.control-reads.test.ts -t approval in apps/server failed on the repro branch (expected +0 to equal 1). After the fix: vp test run src/orchestration-v2/Orchestrator.control-reads.test.ts src/orchestration-v2/SteeringCompletion.integration.test.ts: 88/88 passed. vp run check:changed: format, lint, knip, graphql, typecheck (3 packages) and tests (4 files, 32 tests) all passed.

Not in this change

  • The reactor and its message/command ids are still named 'question' (DelegatedTaskQuestionReactor, delegated-task-question:*). They were not renamed, to keep ids stable and the diff minimal.
  • Orchestrator's task-completion cleanup (dismissing pending questions via thread.user-input.dismiss) only covers user_input requests. Pending approvals on a finished task are left alone, as before.
  • No new eval case was added for the new advisory notice text under evals/.

AI-assisted; verified with the tests and tools listed above.

    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    2. Approvability

      Verdict: Approved at d9a1ed3

      Macroscope's review found this PR approvable — Delegated tasks waiting for live approval now notify their parent, with obsolete queued notices removed. The change preserves user-controlled approval and existing task lifecycle guards.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    3. Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire5.0 KiB5.0 KiB0 B (0.0%)6.8 KiB✅
      CodexThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      CodexLive turn WebSocket wire1.2 KiB1.2 KiB0 B (0.0%)2.0 KiB✅
      CodexLive turn WebSocket decoded21.5 KiB21.5 KiB0 B (0.0%)24.4 KiB✅
      CodexLive turn messages110 (0.0%)8✅
      ClaudeTotal thread wire5.0 KiB5.0 KiB0 B (0.0%)6.8 KiB✅
      ClaudeThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      ClaudeLive turn WebSocket wire1.2 KiB1.2 KiB0 B (0.0%)2.0 KiB✅
      ClaudeLive turn WebSocket decoded21.9 KiB21.9 KiB0 B (0.0%)24.4 KiB✅
      ClaudeLive turn messages110 (0.0%)8✅

      Other scenarios

      All 64 scenario measurements match main.

      All 64 scenario measurements
      ProviderScenarioMetricMain baselineThis PRImpactPR ceiling
      Codexshort turn resumeWebSocket decoded10.5 KiB10.5 KiB0 B (0.0%)12.7 KiB✅
      Codexshort turn resumeWebSocket messages220 (0.0%)2✅
      Codexlong turn running, cold openHTTP decoded281.7 KiB281.7 KiB0 B (0.0%)302.7 KiB✅
      Codexlong turn running, cold openrows75750 (0.0%)75✅
      Codexlong turn running, history pageHTTP decoded92.4 KiB92.4 KiB0 B (0.0%)107.4 KiB✅
      Codexlong turn running, history pagerows75750 (0.0%)75✅
      Codexlong turn finished, cold openHTTP decoded381.5 KiB381.5 KiB0 B (0.0%)410.2 KiB✅
      Codexlong turn finished, cold openrows1511510 (0.0%)151✅
      Codexlong turn finished, socket cold openWebSocket decoded381.6 KiB381.6 KiB0 B (0.0%)410.2 KiB✅
      Codexlong turn finished, socket cold openWebSocket messages220 (0.0%)2✅
      Codexlong turn finished, socket cold openrows1511510 (0.0%)151✅
      Codexlong turn finished, work pageHTTP decoded186.2 KiB186.2 KiB0 B (0.0%)200.2 KiB✅
      Codexlong turn finished, work pagerows1501500 (0.0%)150✅
      Codexidle thread resumeWebSocket decoded65 B65 B0 B (0.0%)200 B✅
      Codexidle thread resumeWebSocket messages110 (0.0%)1✅
      Codexfleet shell snapshotHTTP decoded41.6 KiB41.6 KiB0 B (0.0%)53.7 KiB✅
      Codexfleet shell snapshotrows27270 (0.0%)27✅
      Codexfleet shell subscribeWebSocket decoded65 B65 B0 B (0.0%)200 B✅
      Codexfleet shell subscribeWebSocket messages110 (0.0%)1✅
      Codexfleet shell resume checkHTTP decoded18 B18 B0 B (0.0%)100 B✅
      Codexfleet shell resume checkrows0000✅
      Codexstale shell reloadHTTP decoded41.6 KiB41.6 KiB0 B (0.0%)53.7 KiB✅
      Codexstale shell reloadrows27270 (0.0%)27✅
      Codexstale shell resumeWebSocket decoded140 B140 B0 B (0.0%)400 B✅
      Codexstale shell resumeWebSocket messages220 (0.0%)2✅
      Codexstale todo list cold openHTTP decoded72.4 KiB72.4 KiB0 B (0.0%)83.0 KiB✅
      Codexstale todo list cold openrows75750 (0.0%)75✅
      Codexstale todo list cold opennodes220 (0.0%)4✅
      Codexstale todo list cold opensubagents220 (0.0%)4✅
      Codexstale todo list cold openplans110 (0.0%)2✅
      Codexstale todo list cold openproviderTurns110 (0.0%)2✅
      Codexstale todo list cold opencheckpoints110 (0.0%)2✅
      Claudeshort turn resumeWebSocket decoded10.6 KiB10.6 KiB0 B (0.0%)12.7 KiB✅
      Claudeshort turn resumeWebSocket messages220 (0.0%)2✅
      Claudelong turn running, cold openHTTP decoded283.3 KiB283.3 KiB0 B (0.0%)302.7 KiB✅
      Claudelong turn running, cold openrows75750 (0.0%)75✅
      Claudelong turn running, history pageHTTP decoded93.4 KiB93.4 KiB0 B (0.0%)107.4 KiB✅
      Claudelong turn running, history pagerows75750 (0.0%)75✅
      Claudelong turn finished, cold openHTTP decoded384.2 KiB384.2 KiB0 B (0.0%)410.2 KiB✅
      Claudelong turn finished, cold openrows1511510 (0.0%)151✅
      Claudelong turn finished, socket cold openWebSocket decoded384.3 KiB384.3 KiB0 B (0.0%)410.2 KiB✅
      Claudelong turn finished, socket cold openWebSocket messages220 (0.0%)2✅
      Claudelong turn finished, socket cold openrows1511510 (0.0%)151✅
      Claudelong turn finished, work pageHTTP decoded188.1 KiB188.1 KiB0 B (0.0%)200.2 KiB✅
      Claudelong turn finished, work pagerows1501500 (0.0%)150✅
      Claudeidle thread resumeWebSocket decoded66 B66 B0 B (0.0%)200 B✅
      Claudeidle thread resumeWebSocket messages110 (0.0%)1✅
      Claudefleet shell snapshotHTTP decoded42.2 KiB42.2 KiB0 B (0.0%)53.7 KiB✅
      Claudefleet shell snapshotrows27270 (0.0%)27✅
      Claudefleet shell subscribeWebSocket decoded66 B66 B0 B (0.0%)200 B✅
      Claudefleet shell subscribeWebSocket messages110 (0.0%)1✅
      Claudefleet shell resume checkHTTP decoded18 B18 B0 B (0.0%)100 B✅
      Claudefleet shell resume checkrows0000✅
      Claudestale shell reloadHTTP decoded42.2 KiB42.2 KiB0 B (0.0%)53.7 KiB✅
      Claudestale shell reloadrows27270 (0.0%)27✅
      Claudestale shell resumeWebSocket decoded140 B140 B0 B (0.0%)400 B✅
      Claudestale shell resumeWebSocket messages220 (0.0%)2✅
      Claudestale todo list cold openHTTP decoded73.4 KiB73.4 KiB0 B (0.0%)83.0 KiB✅
      Claudestale todo list cold openrows75750 (0.0%)75✅
      Claudestale todo list cold opennodes220 (0.0%)4✅
      Claudestale todo list cold opensubagents220 (0.0%)4✅
      Claudestale todo list cold openplans110 (0.0%)2✅
      Claudestale todo list cold openproviderTurns110 (0.0%)2✅
      Claudestale todo list cold opencheckpoints110 (0.0%)2✅

      Baseline: 0cd6a73 · PR result: d9a1ed3 · Source CI: success

      Scenario and decoded snapshot size

      10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

      • Codex decoded thread snapshot: 108.5 KiB
      • Claude decoded thread snapshot: 108.8 KiB

      Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

    4. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Explain Change →

      No actionable comments were generated in the recent review.

      Walkthrough

      The delegated-task reactor now notifies parent runs about eligible child approval requests. The orchestrator also treats wakes matching pending requests of any kind as current.

      Changes: Delegated approval notifications

      Layer / File(s)Summary
      Approval request notifications and cleanup
      apps/server/src/orchestration-v2/DelegatedTaskQuestionReactor.ts
      The reactor recognizes approval requests alongside user_input requests. It sends approval-specific notices and includes approvals in catch-up handling and settled-task cleanup.
      Pending approval wake handling
      apps/server/src/orchestration-v2/Orchestrator.ts, apps/server/src/orchestration-v2/Orchestrator.control-reads.test.ts
      A matching pending request of any kind keeps a wake current. The test checks that a pending child approval produces one parent notification with the request ID, delegated task, and child thread.

      Estimated code review effort: 2 (Simple) | ~15 minutes

      Change: Bug fix · Severity of issue fixed: High

      Sequence Diagram(s)

      sequenceDiagram
        participant ChildRuntime
        participant DelegatedTaskQuestionReactor
        participant ParentRun
        ChildRuntime->>DelegatedTaskQuestionReactor: Submit pending live approval request
        DelegatedTaskQuestionReactor->>ParentRun: Send approval notice with child-thread link

      Possibly related issues

      • pingdotgg/t3code#21935: This issue concerns approval requests that remain pending after a delegated task is interrupted or cancelled; this change includes approval requests in settled-task cleanup.

      Possibly related PRs

      • pingdotgg/t3code#20928: This PR also routes delegated-child approval requests to the parent and adds approval-specific messages.
      • pingdotgg/t3code#25680: This PR changes delegated-task wake cleanup and stale-wake checks, which this change extends to approval requests.

      Suggested labels: bugfix

      Suggested reviewers: flamboh, t3dotgg

      Merge Risk: Minimal · up to d9a1e

      Delegated child approval requests now notify an idle parent, and no concrete merge-blocking issue remains in the reviewed changes.

      Pre-merge checks: Passed 4

      Check nameStatusExplanation
      Title checkPassedThe title names the main change: a delegated task that waits for an approval now notifies its idle parent. It uses the conventional commit form, and it matches the raw summary, the PR objectives, and …
      Linked Issues checkPassedIssue #22925 requires that a parent receive a notice when an async delegated child waits on an approval after the parent's turn ends. The notice must link the child thread, and the parent must be able…
      Out of Scope Changes checkPassedAll changes in the whole-PR diff (merge base f03db4fb to head d9a1ed3a) serve the approval-notice objective. DelegatedTaskQuestionReactor.ts adds approval handling in its three paths: live, catch-up a…
      Description checkPassedThe description covers the required template sections in substance. Problem: the reactor handled only user_input requests, and isStaleQuestionWake kept notices alive only for pending user_input reques…
      Full details: Title check

      Explanation

      The title names the main change: a delegated task that waits for an approval now notifies its idle parent. It uses the conventional commit form, and it matches the raw summary, the PR objectives, and linked issue #22925. The title is 78 characters, which is within a normal length for a conventional commit subject.

      Full details: Linked Issues check

      Explanation

      Issue #22925 requires that a parent receive a notice when an async delegated child waits on an approval after the parent's turn ends. The notice must link the child thread, and the parent must be able to tell the user or stop and relaunch the child. The diff covers this in apps/server/src/orchestration-v2/DelegatedTaskQuestionReactor.ts. notifiesParent() now admits ProviderRequestKind approval kinds as well as user_input. The live path (runtime-request.updated) returns early only for non-live pending approvals. For approvals, wakeParent builds advisory text that names the task, request kind, requestId and childThreadId. The text states that the parent cannot approve, and it directs the parent to tell the user or use task_cancel and relaunch. The summary reads 'Delegated task "..." needs approval'. The catch-up and settled-cancel paths also use notifiesParent(), so pending approvals are handled there too. In apps/server/src/orchestration-v2/Orchestrator.ts, isStaleQuestionWake no longer requires kind === user_input. It matches on pending status and the message id, so a queued approval notice stays current while its request is pending. The PR states that a regression test in Orchestrator.control-reads.test.ts reproduces the 0-notice failure on main and passes after the fix. I did not run the tests. The result rests on the reviewed diff and the PR's reported test results. The PR's real-app evidence section is unfinished, but that does not affect the coding requirement. Issue #21935 (stale approvals after interrupt) is context only and is not required here.

      Full details: Out of Scope Changes check

      Explanation

      All changes in the whole-PR diff (merge base f03db4fb to head d9a1ed3a) serve the approval-notice objective. DelegatedTaskQuestionReactor.ts adds approval handling in its three paths: live, catch-up and settled cancel. It also adds the advisory text and the approval summary. Orchestrator.ts removes the user_input-only restriction in isStaleQuestionWake, which is needed so approval notices remain valid. The regression test in Orchestrator.control-reads.test.ts supports the change. The changes to comments and the summary are small and tied to the same behavior. The PR's 'Not in this change' items (renaming question ids, finished-task dismissal of approvals, and the eval case) are explicit deferrals. They are not unrelated changes. No change was found that is unconnected to issue #22925.

      Full details: Description check

      Explanation

      The description covers the required template sections in substance. Problem: the reactor handled only user_input requests, and isStaleQuestionWake kept notices alive only for pending user_input requests, so approval waits produced zero parent notices. Change: the reactor now handles provider approval kinds, queues an advisory notice for pending live approvals, and isStaleQuestionWake matches by request id and pending status. Scope: it links issue pingdotgg/t3code#22925 as the bug report. Verification: it gives a reproduction on main, a failing-then-passing focused test, the exact test commands with results, and before/after screenshots and recordings. It also states what was not shown, namely live-provider behavior and non-command approval kinds. The title is a conventional commit title in the expected form, although the template's example is a plain-language title. Minor gaps: the template asks for a conventional commit title, and the description does not state the title; the PR title in the objectives reads as conventional. The 'Not in this change' section is extra but useful. The model and harness line for the AI-assisted work is present as 'AI-assisted' but does not name the model and harness, which the template requests. The description is complete enough to pass.

      Finishing Touches

      Generate unit tests (beta)

      • Commit to this branch
      • Create a new PR
      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
      Recent review info

      Run configuration

      Commits

      Reviewing files that changed from the base of the PR and between 0cd6a73433c3b9c1e328560d591fd297e72d7ef9 and d9a1ed3a06b0888b30246e6c2b0fd5e77d17f43e.

      Files selected for processing: 3

      • apps/server/src/orchestration-v2/DelegatedTaskQuestionReactor.ts
      • apps/server/src/orchestration-v2/Orchestrator.control-reads.test.ts
      • apps/server/src/orchestration-v2/Orchestrator.ts
      Files with no reviewable changes: 1

      • apps/server/src/orchestration-v2/Orchestrator.ts

      Limit details: You’ve used all 10 included reviews currently available.

    5. tanstack-source added labelsbug

    6. The nested delegation report in #22925 describes a grandchild’s approval card appearing on the root thread. Would you prefer to verify that case in this PR or track it separately?

      The behavior I’d verify is that only the grandchild’s direct parent gets an advisory wake. The user can still approve from the root. If that approval resolves before the wake starts, the queued notice should be dropped. If the wake has already started, the notice should direct the agent to take no action once the request is resolved.

Sign in to join this conversation.