Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): a held or unread delegated message tells its owner #48230

ClosedAlb11747(GitHub profile, opens in a new tab)wants to merge 3 commits intomain fromrefs/pull/48230/headopened View on GitHub

Problem

A delegated task's message can sit in its child thread's held queue indefinitely, and the task's owner is never told (#39511). task_cancel on another of the child's tasks stops the child, and Stop holds every queued turn. The held task then goes idle, nothing wakes its owner, and only a person's message or Resume in the child releases it. If the child is later settled (since #19665 subagents settle with their parent), the message is cancelled unread, and the result reads only "Child task ended with status cancelled.", which looks like work that ran and stopped.

Change

  • DelegatedTaskHoldReactor sends the owner one notice per held run. It is a delegated-task update like the question notices, and the orchestrator drops it as stale once the task ends, its delivery is disposed or the run is no longer held. A later hold of the same run after its notice was dropped gets a new notice.
  • The notice suggests a plain send to an idle child (it starts ahead of the hold, and held agent messages follow when it completes), since mode: "restart" needs a running turn.
  • The reactor takes its event cursor when it starts, through a new OrchestratorV2.domainEventsFromNow, so holds made by startup recovery before activation are not missed.
  • subagentResultForRun: a delegated message cancelled before its run started now says the child never read it, and whether it was held or cancelled when the child's thread settled.

This replaces #47979, which stopped after I pushed over the maintainer pipeline that had taken it over. It keeps that pipeline's refactor (refactor(server): name the stale-wake check for both task notices, by @juliusmarminge) as its own commit and adds the fixes for the review findings there.

Scope

Bug fix for #39511. Both gaps sit on the same path: the hold gives no signal, and settlement then cancels the held message without saying so.

Verification

New tests in DelegatedCompletionDelivery.test.ts (held delegated messages) and subagentProjection.test.ts:

  • a held follow-up wakes its owner once, including after a wake-policy change during the hold;
  • an owner's send into an already-held queue wakes it too (the send receipt says only "queued");
  • a hold made before server activation still wakes its owner;
  • a run held again after its notice was dropped gets a new notice;
  • a follow-up settled unread says it never ran;
  • a message cancelled before its run started says it was never read.

With the fix, both files pass (83/83). With the fix's sources reset to the base commit (tests kept), all 6 new tests fail. With the reactor and orchestrator from the commit before the last one, the activation and re-hold tests fail. vp run typecheck and vp run check:changed pass. Not checked: the full scenario (stop, then settle after a server update) in a real client.

Claude Opus 5.5 via Claude Code; earlier review by GPT-6.2 Sol.

🤖 Generated with Claude Code

    1. chatgpt-codex-connector[bot](GitHub profile, opens in a new tab)commented
      Codex Review Summary: ✅ Completed

      This comment shows the latest Codex review activity on this pull request.

      ReviewStatusCommitReview trigger
      📝 Code Review✅ Completed 2026-12-03T12:30:46.108151Z4a2565bPR opened
      ℹ️ About Codex in GitHub

      Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

      • Open a pull request for review
      • Mark a draft as ready
      • Comment "@codex review" or "@codex security review".

      Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

    2. tanstack-source added labelsbug

    3. Closing: Alb11747 already has 3 or more open PRs here, which is the limit for contributors who are not vouched.

      Once one of them is merged or closed, open this again. See the open PR limit.

    4. Approvability

      Verdict: Approved at 4a2565b

      Macroscope's review found this PR approvable — Held delegated tasks now notify their owners, and cancelled unread messages explain what happened. Notifications follow the existing queued-wake pattern, with deduplication and stale-notice cancellation, without directly releasing child queues.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    5. 💡 Codex Review

      Here are some automated review suggestions for this pull request.

      Reviewed commit: 4a2565bcde

      ℹ️ About Codex in GitHub

      Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

      • Open a pull request for review
      • Mark a draft as ready
      • Comment "@codex review".

      If Codex has suggestions, it will comment; otherwise it will react with 👍.

      Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

      @@ -378,4 +391,5 @@
      378391 report ??
      379392 (run.status === "completed"
      380393 ? "Child task completed without an assistant result."
      381- : `Child task ended with status ${run.status}.`),
      394+ : run.status === "cancelled" && run.startedAt === null
      395+ ? unreadMessageResult(run, projection)

      P2 Badge Exclude promoted steers before reporting a message as unread

      When a queued delegated follow-up is promoted to Steer, dispatchQueuedMessagePromoteToSteer cancels its unstarted queued run and passes the same message to dispatchSteerIntoRun on the active run. The cancelled stub therefore satisfies this predicate even when the provider reads the message as steering input. Its task result now falsely says the message was never read and asks the owner to send it again, which can duplicate work. Exclude promoted/rebound messages, or verify actual prompt delivery, before emitting the unread/resend result.

      Useful? React with 👍 / 👎.

      @@ -0,0 +24,21 @@
      24+ {
      25+ readonly start: () => Effect.Effect<void, never, Scope.Scope>;
      26+ readonly handle: (event: OrchestrationV2DomainEvent) => Effect.Effect<void>;
      27+ }
      28+>()("t3/orchestration-v2/DelegatedTaskHoldReactor") {}
      29+
      30+const make = Effect.gen(function* () {
      31+ const engine = yield* Orchestrator.OrchestratorV2;
      32+ const projections = yield* ProjectionStore.ProjectionStoreV2;
      33+
      34+ // One notice per held run, whatever else updates the task (a replayed command is a no-op).
      35+ // The orchestrator cancels a queued notice once its run is released, so a cancelled notice
      36+ // means this is a later hold of the same run, which gets a notice of its own.
      37+ const noticeKey = Effect.fnUntraced(function* (ownerThreadId: ThreadId, base: string) {
      38+ for (let hold = 1; ; hold++) {
      39+ const key = hold === 1 ? base : `${base}:${hold}`;
      40+ const { messages } = yield* projections.getThreadRecords(ownerThreadId, ["messages"], {
      41+ messageIds: [MessageId.make(`message:delegated-task-held:${key}`)],
      42+ });
      43+ const runId = messages[0]?.runId;
      44+ if (runId === undefined || runId === null) return key;

      P2 Badge Check stale command receipts before reusing a notice key

      If a hold is released before its notice dispatch acquires the owner's lock, dispatchMessage drops the stale notice by committing only thread.metadata-updated, creating an accepted command receipt but no notice message or run. If the same child run is held again before starting, this branch returns the same key, and dispatchCommandWithReceipt replays that accepted receipt instead of issuing another notice. The owner therefore gets no warning for the new hold. Account for receipt-only stale dispatches when selecting the next notice generation, not only cancelled notice runs.

      Useful? React with 👍 / 👎.

Sign in to join this conversation.