Skip to content

Conversation

@ammar-agent
Copy link
Collaborator

Fixes race condition where parallel bash_output tool calls on the same process could both read from the same offset before either updates the read position, resulting in duplicate output being returned.

Root Cause

When disableParallelToolUse is false (our default), Claude can issue multiple bash_output calls in a single response. Without serialization, both calls would:

  1. Read pos.outputBytes = 0
  2. Start async readOutput(0)
  3. Both read same content
  4. Both set pos.outputBytes to same final value

Fix

  • Add per-process AsyncMutex (using existing codebase pattern from StreamManager) to serialize getOutput() calls
  • Clean up readPositions and outputLocks maps during cleanup() to prevent stale state

Test

Added test case that calls getOutput() twice in parallel and verifies combined output contains each line exactly once (no duplicates).

Generated with mux

…tput

Fixes race condition where parallel bash_output tool calls on the same
process could both read from the same offset before either updates the
read position, resulting in duplicate output being returned.

Root cause: When disableParallelToolUse is false (our default), Claude
can issue multiple bash_output calls in a single response. Without
serialization, both calls would:
1. Read proc.outputBytesRead = 0
2. Start async readOutput(0)
3. Both read same content
4. Both set proc.outputBytesRead to same final value

Fix: Add outputLock (AsyncMutex) to BackgroundProcess to serialize
getOutput() calls. Also consolidate all per-process state (outputBytesRead,
outputLock) into the BackgroundProcess object so cleanup is automatic
when the process is removed from the processes map - no separate maps
to keep in sync.

_Generated with mux_
@ammario ammario merged commit 62829be into main Dec 11, 2025
33 of 35 checks passed
@ammario ammario deleted the bash-output-y852 branch December 11, 2025 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants