Skip to content

Add session and RLM heartbeats - #170

Merged
kevinjosethomas merged 22 commits into
mainfrom
feature/rlm-heartbeats
Jun 18, 2026
Merged

Add session and RLM heartbeats#170
kevinjosethomas merged 22 commits into
mainfrom
feature/rlm-heartbeats

Conversation

@sethkarten

@sethkarten sethkarten commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add a single combined heartbeat feature set for coding-agent sessions
  • add persistent user-owned /heartbeat support with /heartbeat, /heartbeat pause, /heartbeat resume, and /heartbeat clear
  • keep the user-level heartbeat user-controlled: models can inspect it with read-only get_heartbeat, but cannot create, update, pause, resume, clear, delete, or replace it through model tools
  • add a bundled rlm-heartbeat Python skill exposed as await rlm_heartbeat.* from IPython
  • back the RLM skill with rlm_heartbeat.list/create/update/delete host requests
  • keep RLM heartbeats scoped by active session and separate from the user-level /heartbeat
  • support multiple simultaneous RLM heartbeats with optional labels
  • provide the RLM heartbeat controller to top-level daemon sessions, main-agent sessions, and RLM subagent sessions
  • fix daemon-created runtime sessions so the RLM heartbeat controller is preserved when session options are resolved
  • add regression coverage for user heartbeat lifecycle, controller propagation, deleted RLM heartbeats not firing after cancellation, and user-heartbeat model-tool immutability

Testing

  • npx tsx ../../node_modules/vitest/dist/cli.js --run test/cron-jobs.test.ts test/kernel-rlm-heartbeat-skill.test.ts test/builtin-skills.test.ts test/slash-commands.test.ts test/daemon-command.test.ts test/agent-connection-daemon.test.ts test/main-interactive-routing.test.ts from packages/coding-agent — 95 tests passed
  • npx tsgo --noEmit --pretty false
  • npx tsx ../../node_modules/vitest/dist/cli.js --run from packages/coding-agent — 165 files passed, 1672 tests passed, 6 files skipped
  • npm run check
  • pre-commit npm run check on commits a3ecfcc1, 74a19ec3, and merge commit 0d360c06

Live validation

  • launched pa-heartbeat-test through the full Prime Agent CLI/TUI entrypoint: ./prime-agent.sh --daemon-socket /tmp/pa-heartbeat-test.sock --provider prime-inference --model glm-5.1
  • verified model-visible tools in the live session are ipython and read-only get_heartbeat; create_heartbeat and update_heartbeat are not available
  • verified model-side attempts to access user-heartbeat mutation host requests are unavailable
  • verified user-owned TUI slash lifecycle externally from the TUI: /heartbeat --every 5m ... created an active user heartbeat, /heartbeat pause changed it to paused, /heartbeat resume changed it back to active, and /heartbeat clear cancelled it; daemon queue then reported No cron jobs
  • verified RLM skill can create, list, pause, resume, update, and delete multiple RLM-owned heartbeats from a live agent session
  • verified deleted RLM heartbeats did not fire and remained separate from the user-level heartbeat
  • verified parent and subagent RLM heartbeats use separate activeSessionId scopes: parent lists did not include child heartbeats, child lists did not include parent heartbeats, and cross-scope update/delete attempts returned null/no-op
  • cleaned up live test jobs after validation; active daemon queue ended with No cron jobs

PR status

Note

Add session and RLM heartbeats with daemon-backed cron job scheduling

  • Introduces a cron job and heartbeat system to the daemon (daemon-mode.ts, cron-jobs.ts) that persists scheduled prompts to cron-jobs.json and dispatches them against long-running sessions.
  • Adds daemon RPC commands cron_list, cron_add, cron_cancel, heartbeat_get, heartbeat_set, heartbeat_update to the protocol and CLI (daemon cron list/add/cancel).
  • Adds a rlm-heartbeat Python skill that lets agent code call rlm_heartbeat.create/list/update/delete via host requests, handled by AgentSession when an rlmHeartbeatController is provided.
  • Extends AgentSession follow-up queue with queueKey-based deduplication so repeated heartbeat triggers don't stack up.
  • Adds a /heartbeat interactive slash command for setting, pausing, resuming, clearing, and viewing the session heartbeat.
  • Risk: daemon startup now throws if agentDir is not configured; cron_cancel omits activeSessionId while other cron/heartbeat commands include it.

Macroscope summarized b4c99f5.


Note

Medium Risk
Touches long-running daemon session lifecycle, automatic prompt injection, and persisted job state across restarts; incorrect scheduling or queue behavior could surprise users or duplicate work, though scope is localized to coding-agent daemon mode.

Overview
Adds daemon-backed scheduled prompts via a persisted cron-jobs.json store, an AgentCronScheduler, and CLI/protocol surfaces (daemon cron list|add|cancel, plus cron_* / heartbeat_* daemon commands). Due jobs wake or create the target session and inject prompts, with heartbeat-style jobs using per-job follow-up queue keys so busy sessions coalesce duplicate ticks instead of stacking identical follow-ups.

Introduces a user-owned /heartbeat slash command (set, pause, resume, clear, status) backed by the same cron machinery, with models limited to read-only get_heartbeat—no tool path to mutate the user heartbeat.

Adds the bundled rlm-heartbeat IPython skill (rlm_heartbeat.* host bridge) for session-scoped internal recurring checks, separate from /heartbeat, with multiple labeled jobs per session and controllers wired through main and subagent daemon runtimes. AgentSession gains optional followUpQueueKey coalescing and removeQueuedFollowUp for scheduler integration; session restore/rebind keeps jobs attached to the correct session file and active session id.

Reviewed by Cursor Bugbot for commit b4c99f5. Bugbot is set up for automated code reviews on this repo. Configure here.

# Conflicts:
#	packages/coding-agent/src/modes/agent-connection/daemon-agent-connection.ts
#	packages/coding-agent/src/modes/agent-connection/in-process-agent-connection.ts
#	packages/coding-agent/src/modes/daemon/daemon-mode.ts
@sethkarten
sethkarten force-pushed the feature/rlm-heartbeats branch from 2cb9b70 to c40e97b Compare June 15, 2026 22:37
@sethkarten sethkarten changed the title Add RLM-scoped heartbeat tools Add RLM heartbeat skill Jun 15, 2026
@sethkarten sethkarten changed the title Add RLM heartbeat skill Add session and RLM heartbeats Jun 16, 2026
@sethkarten
sethkarten changed the base branch from feature/agent-cron-jobs to main June 16, 2026 03:18
# Conflicts:
#	packages/coding-agent/src/modes/interactive/interactive-mode.ts
#	packages/coding-agent/test/slash-commands.test.ts
Comment thread packages/coding-agent/src/modes/daemon/daemon-mode.ts
@sethkarten
sethkarten marked this pull request as ready for review June 16, 2026 18:35
Comment thread packages/coding-agent/src/core/cron-jobs.ts
Comment thread packages/coding-agent/src/core/cron-jobs.ts
Comment thread packages/coding-agent/src/modes/daemon/daemon-mode.ts
Comment thread packages/coding-agent/src/core/cron-jobs.ts
Comment thread packages/coding-agent/src/core/cron-jobs.ts
Comment thread packages/coding-agent/src/modes/daemon/daemon-mode.ts Outdated
Comment thread packages/coding-agent/src/modes/daemon/daemon-mode.ts Outdated
Comment thread packages/coding-agent/src/modes/daemon/daemon-mode.ts Outdated
Comment thread packages/coding-agent/src/modes/daemon/daemon-mode.ts
Comment thread packages/coding-agent/src/core/cron-jobs.ts
Comment thread packages/coding-agent/src/modes/daemon/daemon-mode.ts
Comment thread packages/coding-agent/src/modes/daemon/daemon-mode.ts
Comment thread packages/coding-agent/src/modes/daemon/daemon-mode.ts

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 308964e. Configure here.

Comment thread packages/coding-agent/src/modes/daemon/daemon-mode.ts
Comment thread packages/coding-agent/src/core/agent-session.ts Outdated
Comment thread packages/coding-agent/src/core/agent-session.ts Outdated
@kevinjosethomas
kevinjosethomas merged commit ce095e9 into main Jun 18, 2026
3 checks passed
@kevinjosethomas
kevinjosethomas deleted the feature/rlm-heartbeats branch June 22, 2026 18:38
zhengr pushed a commit to zhengr/prime-agent that referenced this pull request Aug 8, 2026
- Parse --version and -v flags in args.ts
- Handle version flag early in main.ts (print and exit)
- Add flag to help text
- Add comprehensive test coverage for CLI arg parsing

Co-authored-by: cc-vps <crcatala+vps@gmail.com>
zhengr pushed a commit to zhengr/prime-agent that referenced this pull request Aug 8, 2026
* feat(coding-agent): add persistent session heartbeat

# Conflicts:
#	packages/coding-agent/src/modes/agent-connection/daemon-agent-connection.ts
#	packages/coding-agent/src/modes/agent-connection/in-process-agent-connection.ts
#	packages/coding-agent/src/modes/daemon/daemon-mode.ts

* Add RLM heartbeat skill

* Fix RLM heartbeat controller propagation

* Make user heartbeats user-controlled

* Validate heartbeat get session

* fix(coding-agent): rebind heartbeat jobs on daemon restart

* fix(coding-agent): clean up stale heartbeat jobs

* fix(coding-agent): skip cancelled cron jobs during run

* fix(coding-agent): correct cron job persistence error

* fix(coding-agent): dedupe daemon session creation

* fix(coding-agent): start cron after daemon restore

* fix(coding-agent): list paused cron jobs by default

* fix(coding-agent): preserve concurrent cron job writes

* fix(coding-agent): coalesce heartbeat follow-ups

* fix(coding-agent): coalesce queued heartbeat runs

* fix(coding-agent): handle duplicate queued heartbeats

* fix(coding-agent): preserve queued heartbeat delivery
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants