Skip to content

[Bug]: usageLimitHoldsQueue stalls buffered provider wake replays, deadlocking provider/account switches with no Stop button #41100

Closed as not planned

Description

@SoulSniper-V2

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 a Claude thread whose active run fails with a usage_limit error (e.g. 5-hour limit reached) while a buffered provider wake continuation (isBufferedProviderNotification(message) === true, such as "Background task completed.") is queued right behind it (e.g. from [Bug]: ClaudeAdapterV2 double-triggers native resume (CLAUDE_CODE_RESUME_INTERRUPTED_TURN + empty prompt.offer), spawning a phantom wake turn #41099, or from a background-task completion arriving as the turn hits the usage limit).
  2. In the composer, switch to a different Claude account or another provider (context handoff) and send a message (or try to configure the thread to another provider instance).

Expected behavior

Buffered provider wake notifications (isBufferedProviderNotification) should not be held by usageLimitHoldsQueue, because replaying already-buffered output sends no new prompt to the rate-limited provider — matching the existing comment and exemption for providerFailed 40 lines lower in Orchestrator.ts:2627-2640. Once the buffered wake drains (or if the user switches away from the rate-limited provider), switching to another account or provider succeeds cleanly.

Actual behavior

In apps/server/src/orchestration-v2/Orchestrator.ts:2576-2585, startNextQueuedRun checks usageLimitHoldsQueue(...) and returns early before reaching lines 2626-2640 (// A buffered wake prompts nothing: it replays output the CLI already produced.):

// Orchestrator.ts:2576-2585
// A limited provider would fail and consume every waiting message.
if (
  usageLimitHoldsQueue(
    projection,
    queuedRun.providerInstanceId,
    options?.userStarted === true ? undefined : yield* DateTime.now,
  )
) {
  return;
}

Because usageLimitHoldsQueue does not exempt isBufferedProviderNotification(queuedMessage):

  1. The queued buffered wake run stays stuck in status: "queued" (startedAt: null) until the usage limit resets.
  2. The provider session's wakeBuffers is never drained, so hasPendingBackgroundWork() (ClaudeAdapterV2.ts:14441-14454) keeps returning true indefinitely (and ProviderSessionManager defers idle release because of it).
  3. Switching away from the exhausted account (context handoff or thread.model-selection.set) is rejected at Orchestrator.ts:8449-8460 and 4810-4819 with:

    The previous provider is still running background agents or commands, and switching would end them. Wait for them to finish, or press Stop, then send the message again.

  4. Because activeRunId is null, the UI displays the Send button rather than a Stop button — leaving the user with no way in the UI to press Stop and no way to switch off the rate-limited account.

(Distinct from #32296, which is about switching while real background work is actively running, and from #33859, which only filters empty zero-turn task-notification results in hasPendingBackgroundWork. Often triggered in practice by #41099.)

Impact

Blocks work completely

Version or commit

Observed on 0.1.10-nightly.20261114.4695; verified unchanged on main @ dd19bce8.

Environment

Linux x86_64 (t3 serve), switching between two Claude Code provider instances after one hits its 5-hour usage limit.

Logs or stack traces

OrchestrationV2DispatchCommandError: The previous provider is still running background agents or commands, and switching would end them. Wait for them to finish, or press Stop, then send the message again.
    at Orchestrator.dispatchMessage (Orchestrator.ts:8453)

Workaround

Cancel the stuck queued continuation run via t3_queue(action: "cancel"), which triggers onRunEndedWithoutStarting and clears wakeBuffers, allowing the provider switch to proceed.


Investigated and reported with Gemini 4 Neon (via Devin ACP in T3 Code).

Happy to open a focused PR with a failing-first test once ready, if maintainers would like one (holding off for now to respect open-PR review capacity).

Activity

  1. juliusmarminge commented on Nov 22, 2026

    @juliusmarminge
    Member

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

    Commit a09738f (origin/main). The full UI flow needs a Claude account that hits its real 5-hour limit while a background-task wake is buffered, and no VM has first-party Claude OAuth, so I did not run it in the app. I reproduced the core defect with the real orchestrator layer instead: a new runtimeLayer.test.ts case ('starts a provider wake queued behind a run that hit its usage limit') creates a thread, starts a user run, queues a provider wake (createdBy agent, creationSource provider, notification background_task, 'Background task completed.'), writes a usage_limit error turn item and a failed run, then calls resumeQueuedRuns. On main the wake run stays status 'queued' (assertion: expected 'queued' to equal 'starting'). The same scenario with a provider_error failure (the existing case from #38035) starts the wake. Skipping usageLimitHoldsQueue for buffered provider notifications in startNextQueuedRun makes the new test pass (reverted, not pushed). The knock-on effects (wakeBuffers never drain, hasPendingBackgroundWork stays true, the context-handoff/model-selection switch is refused, no Stop button because activeRunId is null) come from reading the code and were not seen in a run.

    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.

  2. SoulSniper-V2 commented on Nov 23, 2026

    @SoulSniper-V2
    Author

    Thanks for the repro test, Julius. Following up with what I can add after #41120 merged.

    `#41120` removes one way to get a buffered wake queued behind a usage-limited run (the phantom wake after Resume), but it does not touch `usageLimitHoldsQueue`. On current `main` (`65b2e6d`) `startNextQueuedRun` still calls `usageLimitHoldsQueue` (`Orchestrator.ts` ~L2578) before the `isBufferedProviderNotification` handling (~L2638), so the case from your `runtimeLayer.test.ts` repro (a provider wake queued behind a `usage_limit` failed run) should still stay `queued`. Another way to get there is a background task completing just as the turn hits the limit.

    On my side the visible effect was: after a Claude account hit its 5-hour limit, switching to another account/provider was refused with "The previous provider is still running background agents or commands…", with Send shown instead of Stop. Version 0.1.10-nightly.20261114.4695. I haven't re-run that exact flow on a post-#41120 build, so I can't say how often it still happens in the app.

    Would you reopen this? If it's useful I'm happy to send a PR (the one-line exemption plus your test), but I have two PRs open already, so I'll only do it if you ask.

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