Skip to content

[Bug]: Claude parents get delegated-task and command notices only after their running turn ends #39441

Closed

Description

@Alb11747

What happened

On a Claude parent, a delegated-task completion (or command notice) that arrives while the parent's turn is running becomes a queued run. The parent only hears about it after its turn ends. On a Codex parent, the same notice is steered into the running turn.

This was reported as #36454, which was closed as not planned because it couldn't be reproduced. That close comment itself shows the Claude case failing. The bug still happens on current main, so this is a fresh report with steps.

Diagnosis

ClaudeAdapterV2 declares activeSteeringInterruptsTools: true (ClaudeAdapterV2.ts:597 on 38bac70). When that flag is set, the orchestrator does not steer notices into a running turn (Orchestrator.ts:7666), so the notice waits as a queued run.

The flag was set because Claude steers used to cancel in-flight tools (#21895). #39018 fixed that on 2026-11-19: steers are now written with priority next and read at the tool boundary, and #21895 is closed. The flag looks stale now. Clearing it for Claude should let notices reach the running turn like they do on Codex, but someone who knows #39018's delivery path should confirm that.

Steps to reproduce

No provider login is needed. Save the test below as apps/server/src/orchestration-v2/ClaudeNoticeSteering.repro.test.ts on main, then:

cd apps/server
vp test run src/orchestration-v2/ClaudeNoticeSteering.repro.test.ts

It runs the same parent turn and delegated-task completion through the real Orchestrator, EventSink and EffectWorker with a fake adapter. The two cases differ only in the declared capabilities (CodexProviderCapabilitiesV2 vs ClaudeProviderCapabilitiesV2).

Result on main at 38bac70, 3 runs out of 3:

✓ codex: a delegated-task completion steers into the running parent turn
× claude: a delegated-task completion steers into the running parent turn
  actual:   { steeredIntoRunningTurn: 0, queuedRuns: 1 }
  expected: { steeredIntoRunningTurn: 1, queuedRuns: 0 }
Tests  1 failed | 1 passed (2)

In a real app:

  1. A Claude parent calls delegate_task (async) to a child that fails quickly, for example a Codex child while the ChatGPT usage limit is spent.
  2. The parent keeps working, or runs a long foreground wait.
  3. The child fails within seconds, but the parent isn't told until its own turn ends.
ClaudeNoticeSteering.repro.test.ts
import { assert, it } from "@effect/vitest";
import {
  CommandId,
  EventId,
  MessageId,
  NodeId,
  ProjectId,
  ProviderDriverKind,
  ProviderInstanceId,
  ProviderThreadId,
  ProviderTurnId,
  ThreadId,
  type OrchestrationV2DomainEvent,
} from "@t3tools/contracts";
import * as DateTime from "effect/DateTime";
import * as Effect from "effect/Effect";
import * as Fiber from "effect/Fiber";
import * as Queue from "effect/Queue";
import * as Stream from "effect/Stream";
import { ClaudeProviderCapabilitiesV2 } from "./Adapters/ClaudeAdapterV2.ts";
import { CodexProviderCapabilitiesV2 } from "./Adapters/CodexAdapterV2.ts";
import * as EffectWorker from "./EffectWorker.ts";
import * as EventSink from "./EventSink.ts";
import * as Orchestrator from "./Orchestrator.ts";
import * as ProviderAdapterRegistry from "./ProviderAdapterRegistry.ts";
import * as ProviderReplayHarness from "./testkit/ProviderReplayHarness.ts";
import { checkpointWorkspace } from "@t3tools/provider-testing/replayWorkspace";
import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter";

// #36106: a delegated-task notice should reach the parent's running turn on every provider
// that supports active steering. Fake adapter; only the declared capabilities differ.
it.effect.each([
  { provider: "codex", capabilities: CodexProviderCapabilitiesV2 },
  { provider: "claude", capabilities: ClaudeProviderCapabilitiesV2 },
] as const)(
  "$provider: a delegated-task completion steers into the running parent turn",
  ({ provider, capabilities }) =>
    Effect.gen(function* () {
      const driver = ProviderDriverKind.make(provider);
      const instanceId = ProviderInstanceId.make(provider);
      const modelSelection = { instanceId, model: "test-model" };
      const cwd = yield* checkpointWorkspace(`claude-notice-steering-${provider}`);
      const events = yield* Queue.unbounded<ProviderAdapter.ProviderAdapterV2Event>();
      const started: ProviderAdapter.ProviderAdapterV2TurnInput[] = [];
      const steered: ProviderAdapter.ProviderAdapterV2SteerInput[] = [];
      const adapter: ProviderAdapter.ProviderAdapterV2["Service"] = {
        instanceId,
        driver,
        getCapabilities: () => Effect.succeed(capabilities),
        planSelectionTransition: () => Effect.succeed({ type: "apply_on_next_turn" }),
        openSession: (input) =>
          Effect.gen(function* () {
            const now = yield* DateTime.now;
            return {
              instanceId,
              driver,
              providerSessionId: input.providerSessionId,
              providerSession: {
                id: input.providerSessionId,
                driver,
                providerInstanceId: instanceId,
                status: "ready",
                cwd,
                model: modelSelection.model,
                capabilities,
                createdAt: now,
                updatedAt: now,
                lastError: null,
              },
              events: Stream.fromQueue(events),
              ensureThread: ({ threadId }) =>
                Effect.succeed({
                  id: ProviderThreadId.make(`provider-thread:${threadId}`),
                  driver,
                  providerInstanceId: instanceId,
                  providerSessionId: input.providerSessionId,
                  appThreadId: threadId,
                  ownerNodeId: null,
                  nativeThreadRef: { driver, nativeId: "native-thread", strength: "strong" },
                  nativeConversationHeadRef: null,
                  status: "idle",
                  firstRunOrdinal: null,
                  lastRunOrdinal: null,
                  handoffIds: [],
                  forkedFrom: null,
                  createdAt: now,
                  updatedAt: now,
                }),
              resumeThread: ({ providerThread }) => Effect.succeed(providerThread),
              startTurn: (turn) =>
                Effect.gen(function* () {
                  started.push(turn);
                  yield* Queue.offer(events, {
                    type: "provider_turn.updated",
                    driver,
                    providerTurn: {
                      id: ProviderTurnId.make(`provider-turn:${turn.attemptId}`),
                      providerThreadId: turn.providerThread.id,
                      nodeId: turn.rootNodeId,
                      runAttemptId: turn.attemptId,
                      nativeTurnRef: {
                        driver,
                        nativeId: `native:${turn.attemptId}`,
                        strength: "strong",
                      },
                      ordinal: turn.providerTurnOrdinal,
                      status: "running",
                      startedAt: now,
                      completedAt: null,
                    },
                  });
                }),
              steerTurn: (turn) => Effect.sync(() => void steered.push(turn)),
              interruptTurn: () => Effect.void,
              respondToRuntimeRequest: () => Effect.void,
              readThreadSnapshot: () => Effect.die("unused"),
              rollbackThread: () => Effect.die("unused"),
              forkThread: () => Effect.die("unused"),
            };
          }),
      };
      yield* Effect.gen(function* () {
        const orchestrator = yield* Orchestrator.OrchestratorV2;
        const worker = yield* EffectWorker.OrchestrationEffectWorkerV2;
        const threadId = ThreadId.make(`thread:notice-${provider}`);
        const watch = (predicate: (event: OrchestrationV2DomainEvent) => boolean) =>
          orchestrator.streamDomainEvents.pipe(
            Stream.filter(predicate),
            Stream.take(1),
            Stream.runDrain,
            Effect.forkScoped,
          );
        yield* orchestrator.dispatch({
          type: "thread.create",
          commandId: CommandId.make("create"),
          threadId,
          projectId: ProjectId.make("project:notice"),
          title: "Parent",
          modelSelection,
          runtimeMode: "full-access",
          interactionMode: "default",
          branch: null,
          worktreePath: cwd,
          createdBy: "user",
          creationSource: "web",
        });
        yield* orchestrator.dispatch({
          type: "message.dispatch",
          commandId: CommandId.make("first"),
          threadId,
          messageId: MessageId.make("message:first"),
          text: "Delegate the review, then keep working.",
          attachments: [],
          dispatchMode: { type: "start_immediately" },
          createdBy: "user",
          creationSource: "web",
        });
        const running = yield* watch(
          (event) => event.type === "provider-turn.updated" && event.payload.status === "running",
        );
        yield* worker.drain();
        yield* Fiber.join(running);
        const parent = started[0]!;

        // The delegated child finishes while the parent turn is still running.
        const messageId = MessageId.make("message:notice");
        const taskId = NodeId.make("task:child");
        const projection = yield* orchestrator.getThreadProjection(threadId);
        const parentRun = projection.runs.find((run) => run.id === parent.runId)!;
        const now = yield* DateTime.now;
        yield* (yield* EventSink.EventSinkV2).write({
          events: [
            {
              id: EventId.make("notice:cohort"),
              type: "run.updated",
              threadId,
              runId: parent.runId,
              occurredAt: now,
              payload: {
                ...parentRun,
                delegatedCompletion: {
                  disposition: "open",
                  nextGeneration: 2,
                  delivery: { generation: 1, messageId, taskIds: [taskId] },
                },
              },
            },
            {
              id: EventId.make("notice:task"),
              type: "subagent.updated",
              threadId,
              runId: parent.runId,
              nodeId: taskId,
              occurredAt: now,
              payload: {
                id: taskId,
                threadId,
                runId: parent.runId,
                parentNodeId: parent.rootNodeId,
                origin: "app_owned",
                createdBy: "agent",
                driver,
                providerInstanceId: instanceId,
                providerThreadId: null,
                childThreadId: null,
                nativeTaskRef: null,
                prompt: "Review the change",
                title: "Review",
                model: null,
                completionWake: "always",
                completionDelivery: { state: "claimed", observedByRunId: null },
                status: "failed",
                result: "Usage limit reached.",
                startedAt: now,
                completedAt: now,
                updatedAt: now,
              },
            },
          ],
        });
        yield* orchestrator.dispatch({
          type: "message.dispatch",
          commandId: CommandId.make("notice"),
          threadId,
          messageId,
          text: "Delegated task finished",
          attachments: [],
          dispatchMode: { type: "queue_after_active" },
          createdBy: "agent",
          creationSource: "server",
          delegatedCompletion: { parentRunId: parent.runId, generation: 1, taskIds: [taskId] },
        });
        yield* worker.drain();

        const after = yield* orchestrator.getThreadProjection(threadId);
        assert.deepEqual(
          {
            steeredIntoRunningTurn: steered.length,
            queuedRuns: after.runs.filter((run) => run.status === "queued").length,
          },
          { steeredIntoRunningTurn: 1, queuedRuns: 0 },
        );
        assert.equal(steered[0]?.runId, parent.runId);
      }).pipe(
        Effect.provide(
          ProviderReplayHarness.layerWithRegistry(
            { name: `claude-notice-steering-${provider}` },
            ProviderAdapterRegistry.layerSingle(adapter),
            { runEffectWorker: false },
          ),
        ),
      );
    }),
);

Version

main at 38bac70. Live reports on 0.1.7 (#36106) and 0.1.10 (in #36454).

Environment

Linux, desktop app with local server. The repro test is provider-independent.

Evidence

Related issues

#36454 (closed as not planned; this replaces it), #36106 (closed, no repro), #21895 (fixed by #39018).

Fix applied or workaround

None upstream. Workaround: the parent can poll task_status, or end its turn sooner.

Filed by

Claude Opus 5.5 (T3 Code, Claude Code harness) on behalf of Alb11747.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions