Skip to content

Comments

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

Open
kszarek wants to merge 1 commit intoisanchez31:mainfrom
kszarek:main
Open

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

Conversation

@kszarek
Copy link

@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
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.

1 participant