fix(agent): resolve critical race conditions and resource leaks in SubTurn

- Fix turnState hierarchy corruption when SubTurns recursively call runAgentLoop
  by checking context for existing turnState before creating new root
- Fix deadlock risk in deliverSubTurnResult by separating lock and channel operations
- Fix session rollback race in HardAbort by calling Finish() before rollback
- Fix resource leak by closing pendingResults channel in Finish() with panic recovery
- Add thread-safety documentation for childTurnIDs and isFinished fields
- Move globalTurnCounter to AgentLoop.subTurnCounter to prevent ID conflicts
- Improve semaphore acquisition to ensure release even on early validation failures
- Document design choice: ephemeral sessions start empty for complete isolation
- Add 5 new tests: hierarchy, deadlock, order, channel close, and semaphore
This commit is contained in:
Administrator
2026-03-16 22:37:21 +08:00
parent 9d761b7f5b
commit 6b5d7e3fd7
5 changed files with 347 additions and 67 deletions
+2
View File
@@ -56,3 +56,5 @@ dist/
!web/backend/dist/
web/backend/dist/*
!web/backend/dist/.gitkeep
.claude/