Skip to content

[Bug]: After resuming a usage-limited thread on another account, its queued messages still start on the limited account #24430

Closed

Description

@Allyx890

Before submitting

  • I searched existing issues and did not find a duplicate.
  • I included enough detail to reproduce or investigate the problem.

Area

apps/server

Steps to reproduce

  1. Have two provider instances of the same driver (for example two Claude accounts, A and B).
  2. On account A, start a run and queue a follow-up message behind it.
  3. The run stops on a usage limit. T3 holds the queue, as intended.
  4. In the composer, pick account B and press Resume. The client sends the manual continuation with B's model selection, then queue.resume.
  5. The continuation runs and completes on B.

A failing test on main (d53873b) that drives the same commands is attached below. Its last step dispatches queue.resume to start the queue. In the app the continuation's end starts it instead: handleRunUpdate calls the same startNextQueuedRun.

Expected behavior

The follow-up does not start on account A while A is out of quota. It either follows the thread to account B, which the user just chose, or stays held.

Actual behavior

The follow-up starts on account A, the account that is out of quota, and the thread's selection switches back to A. The test fails with:

AssertionError: queued message starting on the limited account; thread is now on codex: expected true to be false

Cause, as far as I can tell:

  • queuedRunModelSelection keeps the selection the message was queued with. Only monitor notifications follow the current selection.
  • usageLimitHoldsQueue(projection, A) only looks at the latest executed run. Once the continuation on B completes, that run is no longer a failed usage_limit run, so nothing protects A any more. The guard's own comment says this is the case it exists for: "A limited provider would fail and consume every waiting message."

Starting on A also detaches B's session, because it is a provider switch. In the app, the follow-up will then most likely fail on the same usage limit. The thread ends up limited again on A, after the user explicitly moved it off A.

I found this in the code and confirmed it with the test below. I have not reproduced it end to end in the UI.

Impact

Major degradation or frequent failure

Version or commit

main @ d53873b

Environment

Windows 11, T3 Code desktop 0.1.2, Claude provider with several account instances. The test uses the Codex test instances in runtimeLayer.test.ts.

Logs or stack traces

Failing test (apps/server/src/orchestration-v2/runtimeLayer.test.ts, "usage-limit recovery" layer)
diff --git a/apps/server/src/orchestration-v2/runtimeLayer.test.ts b/apps/server/src/orchestration-v2/runtimeLayer.test.ts
index 9f0edb83..9d0ca62b 100644
--- a/apps/server/src/orchestration-v2/runtimeLayer.test.ts
+++ b/apps/server/src/orchestration-v2/runtimeLayer.test.ts
@@ -6040,6 +6040,160 @@ it.layer(layerTest)("usage-limit recovery", (it) => {
       }),
   );
 
+  it.effect(
+    "does not send queued messages to the limited account after resuming on another one",
+    () =>
+      Effect.gen(function* () {
+        const orchestrator = yield* Orchestrator.OrchestratorV2;
+        const events = yield* EventSink.EventSinkV2;
+        const threadId = ThreadId.make("resume-other-account");
+        const projectId = ProjectId.make("resume-other-account:project");
+        const now = yield* DateTime.now;
+        yield* seedProject({
+          projectId,
+          title: "Resume project",
+          workspaceRoot: process.cwd(),
+          defaultModelSelection: modelSelection,
+          createdAt: DateTime.formatIso(now),
+        });
+        yield* orchestrator.dispatch({
+          type: "thread.create",
+          commandId: CommandId.make("resume-other-account:create"),
+          threadId,
+          projectId,
+          title: "Limited thread",
+          modelSelection,
+          runtimeMode: "full-access",
+          interactionMode: "default",
+          branch: null,
+          worktreePath: null,
+          createdBy: "user",
+          creationSource: "web",
+        });
+        for (const [key, dispatchMode] of [
+          ["start", { type: "defer_start" }],
+          ["queue", { type: "queue_after_active" }],
+        ] as const) {
+          yield* orchestrator.dispatch({
+            type: "message.dispatch",
+            commandId: CommandId.make(`resume-other-account:${key}`),
+            threadId,
+            messageId: MessageId.make(`resume-other-account:${key}`),
+            text: key === "start" ? "Start work." : "Follow up.",
+            attachments: [],
+            dispatchMode,
+            createdBy: "user",
+            creationSource: "web",
+          });
+        }
+        const [source, queued] = (yield* orchestrator.getThreadProjection(threadId)).runs as [
+          OrchestrationV2Run,
+          OrchestrationV2Run,
+        ];
+        // The limit stops the run and holds the queue behind it.
+        yield* events.write({
+          events: [
+            {
+              id: EventId.make("resume-other-account:hold"),
+              type: "run.updated",
+              threadId,
+              occurredAt: now,
+              payload: { ...queued, queueHeld: true },
+            },
+            {
+              id: EventId.make("resume-other-account:stop"),
+              type: "run.updated",
+              threadId,
+              occurredAt: now,
+              payload: { ...source, status: "failed", completedAt: now },
+            },
+            {
+              id: EventId.make("resume-other-account:error"),
+              type: "turn-item.updated",
+              threadId,
+              occurredAt: now,
+              payload: {
+                id: TurnItemId.make("resume-other-account:error"),
+                type: "error",
+                threadId,
+                runId: source.id,
+                nodeId: source.rootNodeId,
+                providerThreadId: null,
+                providerTurnId: null,
+                nativeItemRef: null,
+                parentItemId: null,
+                ordinal: 2,
+                status: "failed",
+                title: "Usage limit reached",
+                startedAt: now,
+                completedAt: now,
+                updatedAt: now,
+                failure: {
+                  class: "usage_limit",
+                  message: "Plan limit reached.",
+                  code: "usageLimitExceeded",
+                  retryable: null,
+                  resetAt: DateTime.formatIso(DateTime.add(now, { hours: 2 })),
+                },
+              },
+            },
+          ],
+        });
+
+        // Composer Resume after picking another account: continue, then resume the queue.
+        yield* orchestrator.dispatch({
+          type: "message.dispatch",
+          commandId: CommandId.make("resume-other-account:continue"),
+          threadId,
+          messageId: MessageId.make("resume-other-account:continue"),
+          manualContinuationOfRunId: source.id,
+          modelSelection: { ...modelSelection, instanceId: alternateInstanceId },
+          text: "Continue where you left off.",
+          attachments: [],
+          dispatchMode: { type: "start_immediately" },
+          createdBy: "user",
+          creationSource: "web",
+        });
+        yield* orchestrator.dispatch({
+          type: "queue.resume",
+          commandId: CommandId.make("resume-other-account:queue-resume"),
+          threadId,
+        });
+        const resumed = yield* orchestrator.getThreadProjection(threadId);
+        const continuation = resumed.runs.find(
+          (run) => run.id !== source.id && run.id !== queued.id,
+        )!;
+        assert.equal(continuation.providerInstanceId, alternateInstanceId);
+
+        // The continuation finishes normally on the other account.
+        const done = yield* DateTime.now;
+        yield* events.write({
+          events: [
+            {
+              id: EventId.make("resume-other-account:continued"),
+              type: "run.updated",
+              threadId,
+              occurredAt: done,
+              payload: { ...continuation, status: "completed", completedAt: done },
+            },
+          ],
+        });
+        // The thread's next start, as when the continuation's end starts the queue.
+        yield* orchestrator.dispatch({
+          type: "queue.resume",
+          commandId: CommandId.make("resume-other-account:queue-resume-after"),
+          threadId,
+        });
+
+        const after = yield* orchestrator.getThreadProjection(threadId);
+        const followUp = after.runs.find((run) => run.id === queued.id)!;
+        assert.isFalse(
+          followUp.status !== "queued" && followUp.providerInstanceId === modelSelection.instanceId,
+          `queued message ${followUp.status} on the limited account; thread is now on ${after.thread.modelSelection.instanceId}`,
+        );
+      }),
+  );
+
   it.effect.each([
     "resume",
     "queued-resume",

Run: vp test run src/orchestration-v2/runtimeLayer.test.ts -t "limited account after resuming" (in apps/server).

Workaround

Before pressing Resume on the other account, cancel the queued messages and send them again once the thread is on the new account.

Activity

  1. juliusmarminge commented on Oct 24, 2026

    @juliusmarminge
    Member

    Duplicate of #21705: after a successful continuation on account B, queued work starts on still-limited account A and switches the thread back. That issue already tracks the usage-limit hold being cleared by another account’s successful run; this report adds a focused failing-test example.

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