Skip to content

t3_queue_reorder can't move a message ahead of queued automatic completion deliveries #25646

Closed as not planned

Description

@juliusmarminge

What happened

t3_queue_reorder won't move a queued message ahead of any queued automatic completion delivery:

t3_queue_reorder({ threadId: "mcp:launch:870f4a9a-16a6-4ff8-a844-a7c824708e01:issue-dispatcher-v1",
  queuedRunId: "…issue-dispatcher-v1:ordinal:4329", beforeRunId: "…issue-dispatcher-v1:ordinal:4223" })
→ orchestration_error: "Queued messages cannot be reordered ahead of automatic completion delivery."

(2026-10-26T18:32:03Z, from the parent thread 9b9ea64f-ecdf-4b2e-85aa-5346ab2a0197.) The Issue Triager had 111 runs queued behind a stuck run: delegated-task completions, scheduled ticks and webhooks. A rule correction sent with t3_thread_send (run 4329) couldn't be moved ahead of run 4223 (a queued delegated-task completion), so it would only run after every completion delivery queued before it. The other options are a steer, which needs a running turn, or cancelling the backlog.

Expected

A user or agent can move a queued message to the front, ahead of automatic completion deliveries. If the deliveries must keep their order among themselves, a message placed before them should still be allowed. If this stays refused, the error should say how to get a message in first.

Where

apps/server/src/orchestration-v2/Orchestrator.ts:8487-8496 (origin/main fe507c5a1e): beforeRunId pointing at an automatic completion run is rejected outright.

Activity

  1. added
    bug
    on Oct 26, 2026
  2. Dropje97 commented on Nov 8, 2026

    @Dropje97

    Same root cause seen without reorder: on a thread whose agent keeps delegating, every t3_thread_send with
    mode: "queue" waited until a moment with no queued completion. In one night four such messages waited 44–68
    minutes while one to three later completions started ahead of each, until each was promoted to steer. orchestrator-mcp-server.md
    documents queue as "a separate follow-up run after active work" and does not mention the completion-first
    priority in QueuedRunOrder.ts. A sentence there (and in the t3_queue/t3_thread_send descriptions) would help

    Investigated by Claude Code (claude-opus-5-5) for the user; the event-log replay is in the user's local evidence.

  3. juliusmarminge commented on Nov 12, 2026

    @juliusmarminge
    MemberAuthor

    I tried to reproduce this on the current build and could not.

    On origin/main dbfbe39 I added a test to apps/server/src/orchestration-v2/runtimeLayer.test.ts that runs the real OrchestratorV2 layer on SQLite. It creates a thread, starts a run, records an open delegated completion on that run and queues its completion message (delegatedCompletion set, created by the server), then queues a user message ('Rule correction'). It then dispatches queued-run.reorder { runId: correction, beforeRunId: completion }. On main the dispatch fails with OrchestratorDispatchError, cause 'Queued messages cannot be reordered ahead of automatic completion delivery.', the reporter's exact error. Command: vp test run src/orchestration-v2/runtimeLayer.test.ts -t "moves a queued message ahead" from apps/server. I did not reproduce it in a running app. The dev Replay provider speaks generic ACP and cannot call delegate_task. Getting a completion queued, not steered, behind a busy parent would take a real provider and timing I cannot control. So this is reported as not reproduced in a real run, even though the same server code path fails in the test.

    Closing as not planned. If it still happens for you, reply with the exact steps and the version you are on and it will be looked at again.

  4. Dropje97 commented on Nov 12, 2026

    @Dropje97

    Could this be reconsidered for the case in my November 8 comment? It does not involve reorder.

    Rechecked on main 4fd40e1a16 with the real SQLite runtime layer and a stub provider:

    1. A run is active. The user, or a coordinator agent through t3_thread_send with mode: "queue", queues a ruling.
    2. While that run is still active, a delegated child finishes, and its completion message is queued after the ruling.
    3. The active run ends and the queue resumes. Nothing is reordered.

    The completion starts first and the earlier ruling stays queued. QueuedRunOrder.ts ranks automatic completions ahead of queue position and ordinal, and its unit test expects exactly that. On a coordinator thread with many children, every new completion overtakes the ruling again. Here four queued messages waited 44–68 minutes in one night, and builders acted on a reviewer's result before the ruling their coordinator had queued for it.

    Your test queues the completion before the correction and then checks that reorder is rejected, so it does not cover this order. Could a message that was queued before a completion keep its place, or could a sender mark a queued message to go ahead of completions?

    Reproduction (appended to runtimeLayer.test.ts; fails on main for both senders)
    it.layer(layerTest)("delivery order research", (it) => {
      it.effect.each(["user", "parent"] as const)(
        "starts an earlier queued %s ruling before a later child completion without reorder",
        (sender) =>
          Effect.gen(function* () {
            const orchestrator = yield* Orchestrator.OrchestratorV2;
            const sink = yield* EventSink.EventSinkV2;
            const threadId = ThreadId.make(`research-order:${sender}`);
            const rulingId = MessageId.make(`${threadId}:ruling`);
            const completionId = MessageId.make(`${threadId}:completion`);
            const taskId = NodeId.make(`${threadId}:reviewer`);
            yield* orchestrator.dispatch({
              type: "thread.create",
              commandId: CommandId.make(`${threadId}:create`),
              threadId,
              projectId: ProjectId.make(`${threadId}:project`),
              title: "Queue delivery reproduction",
              modelSelection,
              runtimeMode: "full-access",
              interactionMode: "default",
              branch: null,
              worktreePath: process.cwd(),
              createdBy: "user",
              creationSource: "web",
            });
            yield* orchestrator.dispatch({
              type: "message.dispatch",
              commandId: CommandId.make(`${threadId}:active`),
              threadId,
              messageId: MessageId.make(`${threadId}:active`),
              text: "Build while the reviewer works.",
              attachments: [],
              dispatchMode: { type: "start_immediately" },
              createdBy: "user",
              creationSource: "web",
            });
            const active = (yield* orchestrator.getThreadProjection(threadId)).runs[0]!;
            const now = yield* DateTime.now;
            const activeWithDelivery = {
              ...active,
              delegatedCompletion: {
                disposition: "open" as const,
                nextGeneration: 2,
                delivery: { messageId: completionId, generation: 1, taskIds: [taskId] },
              },
            };
            yield* sink.write({
              events: [
                {
                  id: EventId.make(`${threadId}:cohort`),
                  type: "run.updated",
                  threadId,
                  runId: active.id,
                  occurredAt: now,
                  payload: activeWithDelivery,
                },
              ],
            });
            yield* orchestrator.dispatch({
              type: "message.dispatch",
              commandId: CommandId.make(`${threadId}:ruling`),
              threadId,
              messageId: rulingId,
              text: "Coordinator ruling: wait before acting on the review.",
              attachments: [],
              dispatchMode: { type: "queue_after_active" },
              createdBy: sender === "user" ? "user" : "agent",
              creationSource: sender === "user" ? "web" : "mcp",
              ...(sender === "parent" ? { senderThreadId: ThreadId.make("coordinator") } : {}),
            });
            yield* orchestrator.dispatch({
              type: "message.dispatch",
              commandId: CommandId.make(`${threadId}:completion`),
              threadId,
              messageId: completionId,
              text: "Reviewer finished.",
              attachments: [],
              dispatchMode: { type: "queue_after_active" },
              createdBy: "agent",
              creationSource: "server",
              delegatedCompletion: { parentRunId: active.id, generation: 1, taskIds: [taskId] },
            });
            const queued = yield* orchestrator.getThreadProjection(threadId);
            const ruling = queued.runs.find((run) => run.userMessageId === rulingId)!;
            const completion = queued.runs.find((run) => run.userMessageId === completionId)!;
            assert.equal(ruling.status, "queued");
            assert.equal(completion.status, "queued");
            assert.isBelow(ruling.ordinal, completion.ordinal);
            yield* sink.write({
              commandId: CommandId.make(`${threadId}:finish`),
              events: [
                {
                  id: EventId.make(`${threadId}:finished`),
                  type: "run.updated",
                  threadId,
                  runId: active.id,
                  occurredAt: now,
                  payload: {
                    ...activeWithDelivery,
                    status: "completed",
                    startedAt: now,
                    completedAt: now,
                  },
                },
              ],
            });
            yield* orchestrator.dispatch({
              type: "queue.resume",
              commandId: CommandId.make(`${threadId}:resume`),
              threadId,
            });
            const after = yield* orchestrator.getThreadProjection(threadId);
            const started = after.runs.find(
              (run) => run.status === "starting" || run.status === "running",
            );
            assert.equal(
              started?.userMessageId,
              rulingId,
              "a later automatic completion overtook the queued ruling without any reorder",
            );
          }),
      );
    });

    Produced with Claude Code (Claude Opus 5.5), with Codex (gpt-6.1-sol) for research.

  5. Dropje97 commented on Nov 12, 2026

    @Dropje97

    One more case of the same ordering, seen on a coordinator thread today, where the message that gets overtaken is the child's own report:

    1. While its parent is busy, a delegated child sends its report to the parent with t3_thread_send, so the report is queued, and then the child ends its turn.
    2. The completion notice for that turn is queued on the parent after the report.
    3. When the parent's run ends, the completion notice starts first; the report waits until no completion is queued.

    The parent sees the child's turn end without the report, acts on that, and then handles the same event a second time when the report starts, 1–8 minutes after the notice and up to 25 minutes after the child sent it. On that one thread, 12 child messages today started after a completion notice that was queued later than they were; in several cases it was the notice for the same child's turn. A child's report cannot be meant to follow the notice of its own later turn end, so here the order is plainly wrong, not just a policy choice.

    Produced with Claude Code (Claude Opus 5.5).

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions