Skip to content

refactor(coding-agent): publish session action protocol - #575

Merged
snimu merged 5 commits into
refactor/session-action-admissionfrom
refactor/session-action-protocol
Aug 3, 2026
Merged

snimu merged 5 commits into
refactor/session-action-admissionfrom
refactor/session-action-protocol

Conversation

@snimu

@snimu snimu commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Fourth PR of the session-action stack: the deliberate wire break. Queue state and session activity become separate, explicitly named projections on the daemon protocol; the executing-command queue display bug is fixed; headless completion waits for scheduler work; the restart manifest is versioned; and all transitional compatibility projections from #2/#3 are deleted. Daemon protocol 6 -> 7, schema 7 -> 8, envelope minimum raised to 7.

Stack: #572 contracts <- #573 kernel <- #574 admission <- #575 protocol (this) <- #576 cleanup

Motivation

pendingMessageCount served incompatible questions - queued future work, scheduler activity, UI rows, restart contents, busy status - and its consumers each picked their own interpretation. That ambiguity produced the "Steering /compact" display for a command that was already executing, headless modes that could exit while a command was still running, and the cross-cutting compensation attempts seen in earlier fix attempts (#565). Everything is team-internal, so rather than dual-writing old semantics, this PR makes one clean break: old clients are rejected before state exchange.

Code changes

  • New SessionActionSnapshot on the wire: literal queuedCount + steering/followUps previews (queued actions only), plus optional active { kind, phase, label }. queue_update replaced by session_action_update.
  • pendingMessageCount removed everywhere; every consumer audited and routed to the semantically correct projection (queuedActionCount, unfinishedActionCount, isSessionActive): cron, agent-observe/agent-message discovery and capacity limits, daemon summaries, RPC, Agents View, supervisor sync, shutdown, and update paths.
  • Display fix: an executing /compact renders as activity, never as a queued row.
  • Headless completion (waitForHeadlessCompletion) and extension waitForIdle bindings now use session-level idle (scheduler + lower agent), with wakeups on pause release, queue clear, and dispose (no microtask livelock, no stranded waiters).
  • Protocol gate: DAEMON_PROTOCOL_VERSION 7, DAEMON_SCHEMA_REVISION 8, envelope minimum 7; compatibility maps updated; both direction tests are real socket-level tests (new-client/old-daemon rejects before writing; old-client/new-daemon receives parse rejection from a real supervisor before any state exchange).
  • Recovery: versioned SessionActionRecoverySnapshot (formatVersion, structural validation, explicit unknown-version rejection on restore; stale/unreadable manifests treated as "nothing restorable" at probe sites and cleared); daemon restore_actions command; per-policy FIFO + correlation preserved on restore.
  • Deleted: legacyPendingProjection, the old-manifest recovery adapter, the legacy attachment fallback to incompatible daemons, and the dead requestLegacy/useLegacyProtocol update-restart plumbing.

LOC: +524/-567 production (net -43), +1075/-667 tests, changelog entry (includes review-fix commits: projection guards, recovery validation, test-fixture migrations).

Note

Publish session action protocol replacing legacy queue API in daemon and session

  • Replaces the queue_update event and pendingMessageCount/pendingMessageCount fields across the daemon, RPC, interactive, and agents-view layers with a structured session_action_update event carrying a SessionActionSnapshot (queuedCount, steering, followUps, active phase).
  • Adds AgentSession.restoreSessionActions() to rehydrate session queues from a versioned SessionActionRecoverySnapshot, replacing the former piecemeal steering/follow-up/accepted-prompt restore paths.
  • Bumps DAEMON_PROTOCOL_VERSION to 7 and schema revision to 8; adds a restore_actions daemon command; enforces command envelopes and rejects unenveloped commands.
  • Removes legacy protocol fallbacks in daemon launch, heartbeat catalog, and update-restart flows; stale daemons now always throw instead of falling back.
  • Risk: breaking protocol change — clients speaking protocol ≤6 will be rejected outright by the supervisor and daemon launcher.

Changes since #575 opened

  • Modified test case 'rejects coordinator spawn errors without terminating the updater' in the update restart coordinator test suite to add explicit cleanup and verification steps [761439f]
  • Added waitForProcessExit async utility function for awaiting process termination in tests [761439f]

Macroscope summarized ea5e528.


Note

High Risk
Breaking daemon protocol and session wire shape; stale clients and daemons are rejected, and update-restart recovery depends on the new manifest format.

Overview
Breaking wire change (daemon protocol 6→7, schema 8): queue state is no longer folded into pendingMessageCount or queue_update. Clients get session_action_update with a SessionActionSnapshot: literal queued steering/follow-up previews (queuedCount) plus optional active work (kind, phase, label). Session summaries expose sessionActions, isSessionActive, and unfinishedActionCount so UI, cron, agent messaging, and busy detection use the right projection instead of one ambiguous counter.

Session core: AgentSession adds getSessionActionSnapshot, restoreSessionActions, and a versioned SessionActionRecoverySnapshot for update-restart; legacy recovery adapters and steering/follow-up snapshot APIs are removed. waitForIdle now waits on scheduler + agent work (used by headless completion and extension bindings).

Daemon / CLI: New restore_actions command; update-restart manifests store queue.actions (not per-queue message lists / accepted prompt). requestLegacy, compatible stale-daemon fallback, and legacy owned-worker frontend routing are deleted; unenveloped commands and pre-v7 daemons are rejected.

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

Comment thread packages/coding-agent/src/package-manager-cli.ts Outdated
Comment thread packages/coding-agent/src/modes/daemon/daemon-mode.ts
Comment thread packages/coding-agent/src/package-manager-cli.ts
Comment thread packages/coding-agent/src/core/agent-session.ts
Comment thread packages/coding-agent/src/package-manager-cli.ts Outdated
@snimu
snimu force-pushed the refactor/session-action-protocol branch from 0655b80 to 82809ee Compare August 1, 2026 20:11
Comment thread packages/coding-agent/src/core/agent-session.ts Outdated
Comment thread packages/coding-agent/src/core/agent-session.ts
Comment thread packages/coding-agent/src/modes/agents-view/agents-view-state.ts
Comment thread packages/coding-agent/src/modes/daemon/daemon-supervisor.ts Outdated
@snimu
snimu force-pushed the refactor/session-action-protocol branch from 82809ee to de175b9 Compare August 1, 2026 20:25
Comment thread packages/coding-agent/src/modes/daemon/daemon-mode.ts
Comment thread packages/coding-agent/src/core/agent-session.ts
Comment thread packages/coding-agent/src/package-manager-cli.ts
Comment thread packages/coding-agent/src/core/agent-session.ts Outdated
@snimu
snimu force-pushed the refactor/session-action-protocol branch from de175b9 to fae12c1 Compare August 1, 2026 21:06
Comment thread packages/coding-agent/src/core/agent-session.ts
Comment thread packages/coding-agent/src/core/agent-session.ts Outdated
@snimu
snimu force-pushed the refactor/session-action-protocol branch from fae12c1 to 5fc996b Compare August 1, 2026 21:20
@snimu
snimu force-pushed the refactor/session-action-protocol branch from 92c7044 to 51ac188 Compare August 2, 2026 10:14
Comment thread packages/coding-agent/src/core/cron-jobs.ts
snimu added a commit that referenced this pull request Aug 2, 2026
Several fixes originate in #574/#575 but land at the stack head to avoid rebasing the whole chain.
@snimu
snimu force-pushed the refactor/session-action-protocol branch from 51ac188 to 415fc79 Compare August 2, 2026 13:43
snimu added a commit that referenced this pull request Aug 2, 2026
Several fixes originate in #574/#575 but land at the stack head to avoid rebasing the whole chain.
Comment thread packages/coding-agent/src/core/cron-jobs.ts
alexzhang13 pushed a commit that referenced this pull request Aug 3, 2026
Several fixes originate in #574/#575 but land at the stack head to avoid rebasing the whole chain.
@alexzhang13
alexzhang13 force-pushed the refactor/session-action-protocol branch from 415fc79 to 14dd5ca Compare August 3, 2026 02:59

@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 1 potential issue.

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 bf28a76. Configure here.

Comment thread packages/coding-agent/src/core/agent-session.ts
@alexzhang13
alexzhang13 force-pushed the refactor/session-action-protocol branch from bf28a76 to ea5e528 Compare August 3, 2026 04:03
alexzhang13 pushed a commit that referenced this pull request Aug 3, 2026
Several fixes originate in #574/#575 but land at the stack head to avoid rebasing the whole chain.
Comment thread packages/coding-agent/src/core/agent-session.ts
alexzhang13 pushed a commit that referenced this pull request Aug 3, 2026
Several fixes originate in #574/#575 but land at the stack head to avoid rebasing the whole chain.
@snimu
snimu merged commit 941576d into main Aug 3, 2026
11 checks passed
snimu added a commit that referenced this pull request Aug 3, 2026
* refactor(coding-agent): harden session action races

* fix(coding-agent): revalidate turn batches after commit fence acquisition

* fix(coding-agent): reschedule pump after batch revalidation deferral

* fix(coding-agent): restore cross-lane queue-key coalescing and compaction pending checks

The underlying bugs originate in PR #573, but this fix lands at the stack head in PR #576 to avoid rebasing three dependent PRs immediately before release.

* refactor(coding-agent): delete compensating scheduler state

* fix(coding-agent): count only pending successors after compaction

* fix(coding-agent): honor prompt abort during fence wait and fix compaction test await

* test(coding-agent): remove flaky post-compaction continue regression

The fake-timer event-await combination never completes under CI timing.
The production change it covered (pending-successor counting after
threshold compaction, 697fcf4) remains covered by the passing
'resumes after threshold compaction when only agent-level queued
messages exist' test exercising the same projection.

* fix(coding-agent): reject fence waiters on session disposal

* fix(coding-agent): restore settlement, ordering, and idle guards

Several fixes originate in #574/#575 but land at the stack head to avoid rebasing the whole chain.

* fix(coding-agent): serialize injected admission with the commit fence

* fix(coding-agent): release fence on admission failure and unify pause-aware admission

* fix(coding-agent): stabilize waitForIdle event-queue wait and drop dead queue-key probe

* fix(coding-agent): preserve batched action message order (fixes #576)

* fix(coding-agent): revalidate commands after commit fence (fixes #576)

---------

Co-authored-by: Alex Zhang <alex.lx.zhang@gmail.com>
@kevinjosethomas
kevinjosethomas deleted the refactor/session-action-protocol branch August 5, 2026 18:54
zhengr pushed a commit to zhengr/prime-agent that referenced this pull request Aug 8, 2026
- Add systemPrompt to BeforeAgentStartEvent so extensions can see current prompt
- Change systemPromptAppend to systemPrompt in BeforeAgentStartEventResult for full replacement
- Extensions can now chain modifications (each sees the result of previous)
- Update ssh.ts to replace local cwd with remote cwd in system prompt
- Update pirate.ts, claude-rules.ts, preset.ts to use new API

fixes PrimeIntellect-ai#575
zhengr pushed a commit to zhengr/prime-agent that referenced this pull request Aug 8, 2026
…ct-ai#575)

* refactor(coding-agent): publish session action protocol

* fix(coding-agent): restore queue projection guards and recovery validation

* fix(coding-agent): repair test migrations for session action snapshots

* correcting when multiple messages are sent, how it's counted

* fix(coding-agent): await update supervisor teardown (fixes PrimeIntellect-ai#575)

---------

Co-authored-by: Alex Zhang <alex.lx.zhang@gmail.com>
zhengr pushed a commit to zhengr/prime-agent that referenced this pull request Aug 8, 2026
…i#576)

* refactor(coding-agent): harden session action races

* fix(coding-agent): revalidate turn batches after commit fence acquisition

* fix(coding-agent): reschedule pump after batch revalidation deferral

* fix(coding-agent): restore cross-lane queue-key coalescing and compaction pending checks

The underlying bugs originate in PR PrimeIntellect-ai#573, but this fix lands at the stack head in PR PrimeIntellect-ai#576 to avoid rebasing three dependent PRs immediately before release.

* refactor(coding-agent): delete compensating scheduler state

* fix(coding-agent): count only pending successors after compaction

* fix(coding-agent): honor prompt abort during fence wait and fix compaction test await

* test(coding-agent): remove flaky post-compaction continue regression

The fake-timer event-await combination never completes under CI timing.
The production change it covered (pending-successor counting after
threshold compaction, 697fcf4) remains covered by the passing
'resumes after threshold compaction when only agent-level queued
messages exist' test exercising the same projection.

* fix(coding-agent): reject fence waiters on session disposal

* fix(coding-agent): restore settlement, ordering, and idle guards

Several fixes originate in PrimeIntellect-ai#574/PrimeIntellect-ai#575 but land at the stack head to avoid rebasing the whole chain.

* fix(coding-agent): serialize injected admission with the commit fence

* fix(coding-agent): release fence on admission failure and unify pause-aware admission

* fix(coding-agent): stabilize waitForIdle event-queue wait and drop dead queue-key probe

* fix(coding-agent): preserve batched action message order (fixes PrimeIntellect-ai#576)

* fix(coding-agent): revalidate commands after commit fence (fixes PrimeIntellect-ai#576)

---------

Co-authored-by: Alex Zhang <alex.lx.zhang@gmail.com>
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