isolate daemon sessions in worker processes - #383
Conversation
…nt-benchmark # Conflicts: # packages/coding-agent/CHANGELOG.md # packages/coding-agent/src/modes/agent-connection/snapshot.ts # packages/tui/CHANGELOG.md
|
Macroscope has since reviewed this pull request. An earlier review was skipped by a cost limit; a review has now completed, so that notice no longer applies. |
|
@macroscope-app please review! |
|
Manual reviews triggered for commit All prior checks · these links stay valid even if you push more commits. |
|
Review in progress! I'll provide feedback through check runs and inline comments once complete. |
ApprovabilityVerdict: Needs human review 17 blocking correctness issues found. Diff is too large for automated approval analysis. A human reviewer should evaluate this PR. You can customize Macroscope's approvability policy. Learn more. |
ENG-4576 Prime Agent multi-processing
ENG-4527 Dispatch heartbeats concurrently across isolated session workers
SummaryThe global daemon scheduler serializes heartbeat execution across every isolated root worker. Although each root has its own worker process, the supervisor waits for one heartbeat's complete LLM/tool turn before dispatching the next. This defeats the throughput benefit of worker isolation for scheduled work and causes later jobs to starve behind earlier or slow jobs. Current behaviorThe supervisor-owned scheduler:
Live stress-test evidence:
RLM heartbeat mutations also write the shared cron store from workers and call a local scheduler wake method, even though resident-worker schedulers are not started. Required behavior
Acceptance criteria
ENG-4526 Reconnect daemon clients transparently after supervisor replacement
SummaryAttached clients surface a fatal Expected supervisor failover should be represented as temporary connection state, not as a fatal session error. Observed incidentDuring a local stress test, one session reached approximately 40 GB of memory. Killing it from Agents View with Ctrl+X produced this sequence:
The daemon remained functional, but client continuity failed and the killed session was resurrected. Required behavior
Acceptance criteria
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 29ee005. Configure here.
* perf(coding-agent): add large daemon attach benchmark * feat(coding-agent): isolate session execution in workers * fix(coding-agent): reconnect after supervisor replacement * fix(tui): preserve input across fullscreen handoff * fix(coding-agent): prevent archived heartbeat revival * fix(coding-agent): cancel orphan heartbeat sessions * fix(tui): preserve drafts across daemon refreshes * fix(coding-agent): separate daemon resyncs from replacements * fix(coding-agent): stabilize daemon streaming ui * refactor(coding-agent): remove obsolete subagent tree * feat(coding-agent): show subagent recaps inline * fix(coding-agent): refine subagent summary spacing * fix(coding-agent): preserve full subagent row selection * fix(coding-agent): align subagent summary rows * fix(coding-agent): preserve reasoning during daemon resync * fix(coding-agent): isolate heartbeat scheduling per worker (ENG-4527) * fix(coding-agent): retry partial daemon reconnects * fix(coding-agent): harden isolated daemon recovery * fix(coding-agent): close daemon recovery races * fix(coding-agent): validate daemon recovery state * fix(coding-agent): close isolated worker recovery gaps * fix(coding-agent): verify orphan process identity * fix(coding-agent): isolate worker client capabilities * fix(coding-agent): preserve daemon terminal ordering * fix(coding-agent): serialize durable daemon state * fix(coding-agent): avoid duplicate worker recovery * fix(coding-agent): isolate peer sync failures * fix(coding-agent): fail unanswered rpc commands * fix(coding-agent): distinguish lease contention

Note
High Risk
Major process and protocol change to core session execution, persistence, and scheduling; recovery/idempotency bugs could lose work or leave stray processes, though v1 legacy paths remain for older daemons.
Overview
Replaces the monolithic daemon with a supervisor that routes clients and spawns one resident worker per root session tree (plus a catalog subprocess for saved-session I/O). Print, JSON, RPC, and
--no-sessioninteractive runs use a separate owned worker frontend incli.tswhile keeping the same public I/O contracts.Protocol v2 adds command envelopes (
clientId,commandId), generation-aware event cursors, chunked attach snapshots, compact assistant streaming on the private channel, and attachment-local backpressure with catch-up/resync. Clients gain transparent reconnect (recoverDaemon),session_resynced, anddaemon retry/daemon restart/shutdown --force.Concurrency and durability: process-safe session leases block double-writes to the same JSONL; cron/heartbeats move from a global file to per-session
scheduled-jobs.jsonwith durable claim/dispatch and concurrent per-worker schedulers. Command and worker recovery journals plus an orphan-process journal avoid replaying uncertain work after crashes; autonomous quality gates now honorAbortSignaland kill detached process trees on abort.Reviewed by Cursor Bugbot for commit 29ee005. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Isolate daemon sessions in dedicated worker processes with supervisor lifecycle management
SessionAlreadyActiveErrorand exits with a user-facing error.WorkerRecoveryJournal,CommandRecoveryJournal, and orphan-process journal for crash recovery: interrupted dispatches are detected on restart, in-flight commands are replayed after reconnect, and orphaned subprocesses are tracked and cleaned up.session_resyncedevents, chunked snapshot delivery,ack_result/retry_worker/restartcommands, and auto-reconnect with resync inDaemonAgentConnection.Macroscope summarized 29ee005.