Skip to content

[Bug]: ClaudeAdapterV2 double-triggers native resume (CLAUDE_CODE_RESUME_INTERRUPTED_TURN + empty prompt.offer), spawning a phantom wake turn #41099

Closed

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. Run a Claude Code thread where the last turn fails or is interrupted with an unanswered user message at the tail of the saved Claude transcript (for example, a turn rejected with a 5-hour usage_limit_reached error), and let the idle Claude CLI process close (or reopen on resume).
  2. Click Resume on the thread (turnInput.resume === true, introduced in feat(server): resume stopped provider threads natively #36526).
  3. Observe the Claude Agent SDK protocol frames on the freshly opened --resume process.

Expected behavior

ClaudeAdapterV2 triggers a single resumed turn on the reopened Claude CLI process. When that turn completes (or fails), the session returns to idle with an empty wakeBuffers and no spurious "Background task completed." continuation queued.

Actual behavior

ClaudeAdapterV2 triggers two back-to-back turns on the same resumed CLI process:

  1. queryRunner.open (apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts:1591-1596) launches Claude CLI with CLAUDE_CODE_RESUME_INTERRUPTED_TURN=1 and CLAUDE_CODE_RESUME_REASON=user_resume. Because the transcript ends on an unanswered user turn, Claude Code CLI immediately auto-starts a resume turn (command_lifecycle: started with a CLI-generated command_uuid, resume_reason: "user_resume").
  2. startTurn (ClaudeAdapterV2.ts:13644-13650 and 13981-13987) also unconditionally sends prompt.offer with an empty user message ({ role: "user", content: [] }, uuid: promptUuid) whenever Ref.get(activeTurn) === context, without checking whether the CLI already started an auto-resume turn. Claude CLI queues this second prompt (command_lifecycle: queued).
  3. Because ClaudeAdapterV2.ts:13739-13742 sets promptEcho: "confirmed" for turnInput.resume, T3 Code settles the active run on Turn 1's result and clears activeTurn to null.
  4. Immediately afterward (0ms later), Claude CLI dequeues and runs T3 Code's own empty content: [] Turn 2 while activeTurn === null.
  5. handleSdkMessageFrame routes Turn 2 into bufferWakeMessage (ClaudeAdapterV2.ts:10176-10384), buffers its assistant + result frames in wakeBuffers, logs orchestration-v2.claude-wake-turn-detected, and queues a phantom "Background task completed." continuation run.

When combined with a usage limit on the resumed account, that phantom wake stays queued and keeps hasPendingBackgroundWork() permanently true (ClaudeAdapterV2.ts:14441-14454), blocking switching to another Claude account or provider 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." even though no run is active and no Stop button exists.

Impact

Major degradation or frequent failure

Version or commit

Observed on 0.1.10-nightly.20261114.4695; verified unchanged on main @ dd19bce8 (Claude Code CLI 2.1.322).

Environment

Linux x86_64 (t3 serve), Claude Code CLI 2.1.322, claude-opus-5-5.

Logs or stack traces

22:01:03.441Z OUT query.open            resume="eeb1834c-..." (with CLAUDE_CODE_RESUME_INTERRUPTED_TURN=1)
22:01:03.444Z IN  command_lifecycle     command_uuid="f8c700f1-..." state="started"   # CLI auto-resume turn
22:01:03.446Z OUT prompt.offer          uuid="1bd837e8-..." message={role:"user", content:[]}
22:01:03.457Z IN  command_lifecycle     command_uuid="1bd837e8-..." state="queued"    # queued behind auto-resume
22:01:03.479Z IN  system/status         status="requesting" user_message_uuids=["142b9059-..."]
22:01:03.640Z IN  assistant             model="<synthetic>" api_error="usage_limit_reached" resume_reason="user_resume" user_message_uuids=["142b9059-..."]
22:01:03.645Z IN  result                is_error=true api_error="usage_limit_reached" # closes activeTurn
22:01:03.647Z IN  command_lifecycle     command_uuid="f8c700f1-..." state="cancelled"
22:01:03.647Z IN  command_lifecycle     command_uuid="1bd837e8-..." state="started"   # T3's own empty prompt starts while activeTurn === null
22:01:03.655Z IN  system/init           # triggers orchestration-v2.claude-wake-turn-detected -> queues "Background task completed."
22:01:03.657Z IN  system/status         status="requesting" user_message_uuids=["1bd837e8-..."]
22:01:03.928Z IN  assistant             model="<synthetic>" api_error="usage_limit_reached" user_message_uuids=["1bd837e8-..."]
22:01:03.929Z IN  result                is_error=true api_error="usage_limit_reached" # stays in wakeBuffers -> hasPendingBackgroundWork() = true
22:01:03.930Z IN  command_lifecycle     command_uuid="1bd837e8-..." state="cancelled"

Workaround

Cancel the phantom queued "Background task completed." run via t3_queue(action: "cancel"), which invokes onRunEndedWithoutStarting (retireOfferedWake) and flushes wakeBuffers.


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

Happy to open a focused PR with a failing-first unit test in ClaudeAdapterV2.test.ts if maintainers would like one (holding off for now to respect open-PR review capacity).

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