Skip to content

fix: use Map keyed by callID to prevent race condition in command restoration#11

Merged
isanchez31 merged 1 commit intoisanchez31:mainfrom
kszarek:main
Feb 26, 2026
Merged

fix: use Map keyed by callID to prevent race condition in command restoration#11
isanchez31 merged 1 commit intoisanchez31:mainfrom
kszarek:main

Conversation

@kszarek
Copy link
Contributor

@kszarek kszarek commented Feb 22, 2026

Summary

Fix a race condition where concurrent bash tool invocations could overwrite each other's original command, causing the wrong command to be displayed in the UI after execution. The plugin stores the original command in tool.execute.before to restore it in tool.execute.after for UI display. Previously, a single shared variable was used, so if two bash commands ran concurrently, the second command's before hook would overwrite the first command's original value before its after hook could restore it.

Changes

  • Replace let lastOriginalCommand: string | undefined with const originalCommands = new Map<string, string>() in src/index.ts
  • Update tool.execute.before to store commands using originalCommands.set(input.callID, command)
  • Update tool.execute.after to retrieve and delete using originalCommands.get(input.callID) and originalCommands.delete(input.callID)
  • Add test "restores correct command for concurrent bash calls" in test/plugin.test.ts

Testing

  • All existing tests pass (bun test)
  • New tests added (concurrent execution test)
  • Tested manually on Linux / macOS (not tested manually)

Related Issues

Closes #

…toration

- Replace lastOriginalCommand with originalCommands Map
- Store commands by callID in tool.execute.before
- Retrieve and delete by callID in tool.execute.after
- Add test for concurrent command execution
@isanchez31 isanchez31 merged commit faadd47 into isanchez31:main Feb 26, 2026
3 checks passed
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