picoclaw/pkg
Administrator e20ff43f8b fix(agent): resolve subturn deadlocks, panics and context retry state
This commit addresses several critical concurrency and state management bugs within the SubTurn execution and delivery logic.

1. Fix Goroutine Leak & Deadlock in deliverSubTurnResult:
   - Replaced non-blocking select with a safe blocking select that listens to `resultChan` and a new `<-parentTS.Finished()` channel.
   - This ensures results are not arbitrarily dropped when the channel is full (preventing orphaned valid results), while also guaranteeing the child goroutine safely unblocks and exits if the parent finishes execution early.

2. Prevent "Send on Closed Channel" Fatal Panics:
   - Removed `close(pendingResults)` and `drainPendingResults` from `turnState.Finish()`.
   - The pendingResults channel is now naturally garbage collected, completely eliminating the race condition panic when a child attempts delivery at the exact moment the parent finishes.
   - Added a `defer recover()` failsafe inside deliverSubTurnResult to gracefully emit Orphan events in extreme edge cases.

3. Fix Truncation Recovery Prompt Drop:
   - Fixed the runTurn truncation retry logic by introducing an explicit `promptAlreadyAdded` boolean.
   - Ensures that the dynamically generated `recoveryPrompt` is correctly injected into the LLM history sequence on subsequent iterations, adhering to API roles without duplicating arrays.

4. Test Suite Stabilization:
   - Fixed TestDeliverSubTurnResultNoDeadlock to accurately wait for deterministic deliveries instead of racing timeouts.
   - Replaced defunct closed-channel tests with TestFinishedChannelClosedState matching the new Finished() mechanism.
   - Fixed the Finish(true) parameter in TestGrandchildAbort_CascadingCancellation to correctly validate Context cascade behavior.
   - All tests now pass cleanly without hanging or emitting false positives.
2026-03-18 13:10:36 +08:00
..
agent fix(agent): resolve subturn deadlocks, panics and context retry state 2026-03-18 13:10:36 +08:00
auth feat(auth): add Anthropic OAuth setup-token login (#926) 2026-03-06 19:58:23 +08:00
bus Removed the old heavy logic 2026-03-08 18:22:15 +01:00
channels bug fix: gateway should not start when gateway server is not running (#1562) 2026-03-17 19:07:36 +08:00
commands feat: add /clear command to clear chat history (#1266) 2026-03-09 16:39:33 +08:00
config Merge upstream/main into feat/subturn-poc 2026-03-17 21:55:20 +08:00
constants refactor: replace bool map with set-style map for internal channels (#472) 2026-02-19 11:48:17 +01:00
credential feat(credential): part1 add AES-GCM encryption, SecureStore, and onboard ke… (#1521) 2026-03-16 14:06:32 +08:00
cron feat(cron): add execution lifecycle logging (#1185) 2026-03-06 20:46:52 +08:00
devices refactor: cleanup dead code and turn on dead code detection in CI (#515) 2026-02-24 21:52:25 +08:00
fileutil refactor(pkg): move atomic file write to dedicated fileutil package 2026-02-24 23:57:13 +08:00
gateway feat: add web gateway hot reload and polling state sync (#1684) 2026-03-17 18:46:00 +08:00
health refactor gateway/helpers and add server.pid to health (#1646) 2026-03-17 09:35:52 +08:00
heartbeat enable dupl check 2026-03-01 18:17:32 +11:00
identity fix(identity): prevent allowlist ID entries from matching usernames (#1406) 2026-03-13 15:41:18 +08:00
logger fix(logger): show first/last 4 chars of bot token for identification 2026-03-16 12:48:28 +02:00
mcp Feat/add tool enable or disable configuration (#1071) 2026-03-05 14:53:26 +08:00
media refactor(media): centralize temp media dir path 2026-03-14 12:01:47 +08:00
memory fix: skip meta json files during session migration (#1340) 2026-03-11 14:29:42 +08:00
migrate docs: remove stale TOOLS.md references (#1388) 2026-03-12 09:47:01 +08:00
providers fix(agent): prevent duplicate history during subturn context recoveries 2026-03-18 12:18:32 +08:00
routing fix(routing): address review feedback on CJK estimation and observability 2026-03-06 13:10:20 +08:00
session fix(security): harden unauthenticated tool-exec paths (#1360) 2026-03-11 19:22:20 +08:00
skills enhance skill installer (#1252) 2026-03-13 14:04:02 +08:00
state fix(security): harden unauthenticated tool-exec paths (#1360) 2026-03-11 19:22:20 +08:00
tools Merge upstream/main into feat/subturn-poc 2026-03-17 21:55:20 +08:00
utils fix(agent): prevent duplicate history during subturn context recoveries 2026-03-18 12:18:32 +08:00
voice Fix lint 2026-03-04 10:21:59 +00:00