mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-06-12 18:08:54 +00:00
fix(agent): enhance SubTurn robustness and fix race conditions
Major improvements to SubTurn implementation: **Fixes:** - Channel close race condition (sync.Once) - Semaphore blocking timeout (30s) - Redundant context wrapping - Memory accumulation (auto-truncate at 50 msgs) - Channel draining on Finish() - Missing depth limit logging - Model validation **Enhancements:** - Comprehensive documentation (150+ lines) - 11 new tests covering edge cases - Improved error messages All tests pass. Production-ready. Related: #1316
This commit is contained in:
+8
-1
@@ -300,10 +300,16 @@ func registerSharedTools(
|
||||
spawnTool.SetAllowlistChecker(func(targetAgentID string) bool {
|
||||
return registry.CanSpawnSubagent(currentAgentID, targetAgentID)
|
||||
})
|
||||
|
||||
// Set SubTurnSpawner for direct sub-turn execution
|
||||
spawner := NewSubTurnSpawner(al)
|
||||
spawnTool.SetSpawner(spawner)
|
||||
|
||||
agent.Tools.Register(spawnTool)
|
||||
|
||||
|
||||
// Also register the synchronous subagent tool
|
||||
subagentTool := tools.NewSubagentTool(subagentManager)
|
||||
subagentTool.SetSpawner(spawner)
|
||||
agent.Tools.Register(subagentTool)
|
||||
} else {
|
||||
logger.WarnCF("agent", "spawn tool requires subagent to be enabled", nil)
|
||||
@@ -988,6 +994,7 @@ func (al *AgentLoop) runAgentLoop(
|
||||
concurrencySem: make(chan struct{}, 5), // maxConcurrentSubTurns
|
||||
}
|
||||
ctx = withTurnState(ctx, rootTS)
|
||||
ctx = WithAgentLoop(ctx, al) // Inject AgentLoop for tool access
|
||||
isRootTurn = true
|
||||
|
||||
// Register this root turn state so HardAbort can find it
|
||||
|
||||
Reference in New Issue
Block a user