fix: skip heartbeat when agent has an active turn#1980
fix: skip heartbeat when agent has an active turn#1980KristjanKruusRIA wants to merge 7 commits intosipeed:mainfrom
Conversation
- Check activeTurnStates before processing heartbeat - Return HEARTBEAT_OK immediately when agent is busy - Log the skipped heartbeat with the active session key - Add 4 tests covering busy, idle, multi-session, and clear scenarios
There was a problem hiding this comment.
Pull request overview
This PR prevents the scheduled heartbeat turn from starting while the agent is already processing another turn, avoiding concurrent-turn interference during active conversations.
Changes:
- Add an early “agent busy” guard to
AgentLoop.ProcessHeartbeatthat skips heartbeat execution when any active turn exists. - Add unit tests covering heartbeat skip/proceed behavior based on presence/absence of active turns.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| pkg/agent/loop.go | Adds a busy-check to skip heartbeat execution when any turn is active. |
| pkg/agent/loop_test.go | Adds tests intended to validate skip/proceed behavior for heartbeat processing. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Use registerActiveTurn/clearActiveTurn helpers instead of direct map access - Update assertions to check HEARTBEAT_SKIPPED (matching new sentinel) - Strengthen idle/proceeds tests to assert Mock response and err==nil
- Fix dogsled: reduce blank identifiers in newTestAgentLoop calls - Fix gci: auto-fixed import ordering in loop_test.go
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Hi, great insight, but it could happen that for those who use picoclaw frequently, this could always have an active turn during the heartbeat and therefore this is always skipped or postponed a lot |
|
Yes that might be an issue. It could be that #1937 is enough for most needs, it's just that personally the heartbeat kept constantly interjecting with old data which kept messing up the chat. |
📝 Description
Prevents the heartbeat system from interrupting active agent conversations. When a user is mid-conversation with the agent, the heartbeat timer can fire and inject autonomous content (e.g. social media posts), disrupting the flow. This fix adds a busy-check guard at the top of
ProcessHeartbeatthat returns aHEARTBEAT_SKIPPEDsentinel when any turn is active.🗣️ Type of Change
🤖 AI Code Generation
🔗 Related Issue
📚 Technical Context (Skip for Docs)
ProcessHeartbeatinpkg/agent/loop.gohad no guard against firing while the agent is actively processing a user turn. The fix uses the existingactiveTurnStatessync.Map (viagetAnyActiveTurnState()) to detect busy state and skip the heartbeat cycle, returningHEARTBEAT_SKIPPEDinstead of invoking the LLM.🧪 Test Environment
📸 Evidence (Optional)
Click to view Logs/Screenshots
All 4 new tests pass:
☑️ Checklist