sipeed/picoclaw · error
turn is still active for session
Error message
turn %s is still active for session %q
What it means
Session-state guard at the top of AgentLoop.Continue: the session-key turn-state map already holds an active (non-idle) turn for this sessionKey, so a second Continue would race the running turn. This is the TOCTOU claim check — the placeholder claim succeeded, then found real turn state; the claim is released before the error returns.
Solutions
- Wait for the in-flight turn to finish, then re-issue Continue
- Have the front end disable the continue button while a turn is active
- Retry with a small backoff when the active turn is expected to end shortly
Defensive patterns
Strategy: retry
When it happens
Trigger: Thrown at pkg/agent/steering.go:382 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of sipeed/picoclaw@49183d7e8d (2026-08-15).
Data as JSON: /api/errors/fcd1a8cd7db46a96.
Report an issue: GitHub.
Appendix: source
Thrown at pkg/agent/steering.go:382
// Continue resumes an idle agent by dequeuing any pending steering messages
// and running them through the agent loop. This is used when the agent's last
// message was from the assistant (i.e., it has stopped processing) and the
// user has since enqueued steering messages.
//
// If no steering messages are pending, it returns an empty string.
func (al *AgentLoop) Continue(ctx context.Context, sessionKey, channel, chatID string) (string, error) {
// Claim the session with a unique placeholder to prevent a TOCTOU race where two
// concurrent Continue calls for the same session both pass the active-turn
// check and create parallel turns. The placeholder is replaced by the real
// turnState inside continueWithSteeringMessages → runAgentLoop → registerActiveTurn.
placeholder := &turnState{
turnID: "pending-continue-" + sessionKey + "-" + fmt.Sprintf("%d", al.turnSeq.Add(1)),
phase: TurnPhaseSetup,
}
if _, loaded := al.activeTurnStates.LoadOrStore(sessionKey, placeholder); loaded {
if active := al.GetActiveTurnBySession(sessionKey); active != nil {
return "", fmt.Errorf("turn %s is still active for session %q", active.TurnID, sessionKey)
}
// Another Continue just claimed the slot; let it handle the steering.
return "", nil
}
if err := al.ensureHooksInitialized(ctx); err != nil {
al.activeTurnStates.Delete(sessionKey)
return "", err
}
if err := al.ensureMCPInitialized(ctx); err != nil {
al.activeTurnStates.Delete(sessionKey)
return "", err
}
steeringMsgs := al.dequeueSteeringMessagesForScopeWithFallback(sessionKey)
if len(steeringMsgs) == 0 {
al.activeTurnStates.Delete(sessionKey)
return "", nilView on GitHub (pinned to 49183d7e8d)