LearnNewsExamplesServices
Frontmatter
id10312
titleImplement Sleep-Cycle MVP (Heartbeat Cron and Handoff Trap)
stateClosed
labels
enhancementaiagent-role:devarchitecture
assignees[]
createdAtApr 25, 2026, 3:27 AM
updatedAtApr 25, 2026, 4:58 AM
githubUrlhttps://github.com/neomjs/neo/issues/10312
authorneo-gemini-pro
commentsCount1
parentIssue10311
subIssues[]
subIssuesCompleted0
subIssuesTotal0
blockedBy[]
blocking[]
closedAtApr 25, 2026, 4:58 AM

Implement Sleep-Cycle MVP (Heartbeat Cron and Handoff Trap)

Closed v13.0.0/archive-v13-0-0-chunk-6 enhancementaiagent-role:devarchitecture
neo-gemini-pro
neo-gemini-pro commented on Apr 25, 2026, 3:27 AM

Context

As part of the Epic to institutionalize swarm autonomy, we need an immediate tactical solution to the "Global Idle" deadlock before the full A2A Task Schema is formalized.

The Problem

Agents currently wait for explicit human prompts to resume work. Without an automated pulse, the swarm cannot operate overnight. Furthermore, infinite loops will eventually cause the context window to overload (red zone).

The Architectural Reality

This work is primarily contained within a new shell script wrapper (swarm-heartbeat.sh) and a minor integration with the GitHub Workflow MCP server (signal_state_transition). It interacts with the local SQLite Memory Core to inject information-rich context into the prompt, avoiding unnecessary LLM tool-calling overhead.

The Fix

  1. Create swarm-heartbeat.sh that runs a 5-minute loop.
  2. Implement an SQLite fast-path query inside the script to check unread A2A mail and open assigned issues.
  3. Inject the results into an information-rich prompt: [SYSTEM HEARTBEAT] Last wake: T-5min. Mailbox unread: X. Open issues assigned: Y.
  4. Implement a concurrency trap: If the agent process is busy (executing a task), skip the heartbeat injection.
  5. Implement the Sandman Handoff trap: If the agent process exits with the state SESSION_FULL (emitted via signal_state_transition), the script automatically respawns a fresh session, passing the previous sessionId for graph rehydration.

Acceptance Criteria

  • swarm-heartbeat.sh successfully injects the information-rich prompt every 5 minutes (when not busy).
  • The script accurately queries the Memory Core SQLite database for unread counts without using the LLM.
  • The script skips the heartbeat injection if an active task is running.
  • The script correctly handles the SESSION_FULL exit code and auto-respawns the agent.
  • The agent correctly answers "Sleeping" (or similar token-conserving response) when X=0 and Y=0.

Out of Scope

  • Migrating MailboxService to the formal A2A Stateful Task schema (Track 2).

Avoided Traps

  • Information-free Heartbeats: We explicitly reject sending a static [SYSTEM HEARTBEAT] prompt because it would cost 576 daily tool-call loops (checking mailbox/issues) per agent for empty cycles. The wrapper must do the SQLite check itself to conserve tokens.

Related

  • Parent Epic: (Will link natively)

Origin Session ID: dd277d9c-8f9c-44c7-8607-cb68bc42fac0 Retrieval Hint: "swarm-heartbeat.sh", "information-rich heartbeat", "Sandman Handoff trap"

tobiu referenced in commit 3616e32 - "feat(ai): integrate swarm-heartbeat Sleep-Cycle MVP (#10312) (#10335) on Apr 25, 2026, 10:09 PM