[Bug] ReferenceError: classifyHandoffIfNeeded undefined in concurrent Task subagent completion
Bug Description
Bug Report: ReferenceError When Multiple Task Subagents Complete Concurrently
Description
Claude Code v2.1.29 throws ReferenceError: classifyHandoffIfNeeded is not defined when multiple Task tool subagents complete concurrently, incorrectly marking successfully executed
tasks as failed.
Environment
- Claude Code Version: 2.1.29
- Platform: macOS (Darwin 23.4.0, arm64)
- Installation Method: Homebrew cask
Symptoms
- Tasks report failed status despite successfully completing all steps and producing valid output
- Error message: classifyHandoffIfNeeded is not defined
- Error only appears in queue-operation notifications, not in agent execution logs
- Sequential task execution works reliably
- Concurrent task execution (≤1 minute apart) triggers the error
Root Cause
The Task tool completion handler calls classifyHandoffIfNeeded() from a lazily-initialized module. When multiple subagents complete concurrently, the function is invoked before the
module finishes loading, causing a ReferenceError.
Evidence
Timing Analysis
Same session, identical parameters, only difference is concurrency:
┌──────────┬────────────┬──────────┬─────────┬────────────────┐
│ Agent ID │ Start Time │ End Time │ Status │ Execution Mode │
├──────────┼────────────┼──────────┼─────────┼────────────────┤
│ a4f3f5e │ 09:21:41 │ 09:26:43 │ FAILED │ Concurrent │
├──────────┼────────────┼──────────┼─────────┼────────────────┤
│ a694bc3 │ 09:22:22 │ 09:25:44 │ FAILED │ Concurrent │
├──────────┼────────────┼──────────┼─────────┼────────────────┤
│ adf02d4 │ 09:25:55 │ 09:28:46 │ SUCCESS │ Sequential │
└──────────┴────────────┴──────────┴─────────┴────────────────┘
Error Message
<task-notification>
<task-id>a694bc3</task-id>
<status>failed</status>
<summary>Agent "Decision-critic SQL vs code fix" failed: classifyHandoffIfNeeded is not defined</summary>
</task-notification>
Reproduction Steps
- Start a Claude Code session
- Launch two Task tool subagents in rapid succession (within ~1 minute)
- Allow both agents to execute and complete around the same time
- Observe ReferenceError in task-notification for one or both tasks
Impact
- Correctness: Successfully executed tasks incorrectly marked as failed
- Data Loss: Valid task output is discarded
- Workflow: Concurrent task execution is unreliable
Workaround
Execute Task subagents sequentially—wait for one to complete before starting another.
Suggested Labels
bug task-tool race-condition concurrency
---
Environment Info
- Platform: darwin
- Terminal: ghostty
- Version: 2.1.29
- Feedback ID: 89d36a7a-7580-401d-9765-d36417e12cd0
Errors
[{"error":"Error: Failed to initialize LSP server plugin:jdtls-lsp:jdtls: LSP server 'plugin:jdtls-lsp:jdtls': startupTimeout is not yet implemented. Remove this field from the configuration.\n at _ (/$bunfs/root/claude:2142:32620)\n at processTicksAndRejections (native:7:39…
Note: Content was truncated.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗