Skip to content

refactor(coding-agent): cut over session action admission - #574

Merged
snimu merged 4 commits into
refactor/session-action-kernelfrom
refactor/session-action-admission
Aug 3, 2026
Merged

snimu merged 4 commits into
refactor/session-action-kernelfrom
refactor/session-action-admission

Conversation

@snimu

@snimu snimu commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Third PR of the session-action stack, and its core: every turn-producing entrypoint now flows through the action scheduler, and the alternate ownership machinery - direct dispatch paths, direct checkpoint fencing, dispatch observers, the accepted-agent-message parallel state - is deleted in the same commit. Net -116 production LOC.

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

Motivation

After #2 there were still two authoritative owners for new work: the scheduler (queued input) and the legacy direct paths (idle prompts, injected messages, accepted agent messages, custom trigger-turns). Split ownership was the root cause of the compensating-state sprawl this stack exists to remove: every busy check, restart fence, and completion mechanism had to be implemented twice and kept in agreement by hand. This PR makes the scheduler the single owner and deletes the second implementation wholesale.

Code changes

  • Routed through the scheduler: idle/direct prompt() (promptUntilAccepted, promptAndWait included), _promptInjectedMessage* (heartbeats, goal context), acceptAgentMessagePrompt/queueAgentMessagePrompt, sendCustomMessage trigger-turn and streaming custom messages, RLM child initial prompts. Idle submissions become immediately eligible actions - externally indistinguishable from the old direct path (no queued-row flash, no spurious queue events).
  • Settlement contracts preserved exactly per entrypoint: AgentConnection.prompt at acceptance/preflight; AgentSession.prompt waits for the run when idle, returns after enqueue when visibly queued; promptUntilAccepted at ownership (and still rejects validation failures); promptAndWait through delivery + completion incl. retry chain; steer/followUp at enqueue (false on coalesce); agent-message ownership/delivery/completion remain separate; heartbeat/cron wake behavior unchanged.
  • Normalization stays entrypoint-specific: steer("/compact") remains model text; extension commands still execute immediately even while streaming.
  • Deleted: _promptUnserialized, _promptInjectedMessageUnserialized, _dispatchPromptWithFence, _observeDirectDispatch, _directPromptSectionCount, _directDispatchObservers, _acceptedAgentMessagePrompt + its event-filtering machinery (behaviors preserved through tickets/lifecycle: clearing an accepted-unstarted prompt restores next-turn context and rejects with the same error; late-event filtering; delivery correlation), _acceptedPromptCompletions, _queueWithPendingNextTurnMessages, _enterDirectPromptSection, _acquireDirectTurnAdmission.
  • Review-driven hardening included: visible-queued gating of early settlement; pump-epoch rollback of preselected actions (update-restart checkpoint deadlock); abort during preparation cancels invisible actions instead of leaving an unsettled ghost; no double error surfacing for awaited failures; queue_update dedup.
  • Wire/UI behavior still bit-for-bit via the legacy projection (protocol changes land in add model agnostic rlm system prompt #4).

LOC: +865/-965 production (net -100), +390/-144 tests (includes review-fix commits: policy-split batching, handed-off clear boundary).

Note

Migrate session action admission in coding agent to action store and ticket pipeline

  • Replaces AcceptedAgentMessagePrompt and PromptDispatchFence abstractions with action store entries and typed tickets, unifying how all prompts (direct, queued, injected, triggered) are admitted and tracked.
  • Introduces TurnExecutionPolicy to parameterize per-turn behavior: when to run extension hooks, drain next-turn context, and whether to await retry chains; turns with different policies no longer batch together.
  • Renames _enqueueSessionInput to _admitSessionInput, which now returns { accepted, disposition, ticket } and supports immediate-start eligibility without waiting on the pump.
  • Adds _cancelSessionActions to handle differentiated cancellation: rejected delivery for accepted/invisible turns, context message restoration, and transcript cleanup for in-flight cancelled dispatches.
  • Risk: several internal APIs used in tests were removed or renamed (_acceptedAgentMessagePrompt, _directPromptSectionCount, activeActionsForMessage), and queue_update events are now suppressed when visible queue content is unchanged.

Macroscope summarized b17d052.


Note

High Risk
Large refactor of core prompt admission, pumping, cancellation, and restart checkpoint behavior with many entrypoint-specific settlement contracts that must stay behavior-identical.

Overview
Unifies session input so idle prompts, injected messages, agent-message acceptance, custom trigger-turns, and queued steer/follow-up all admit through _admitSessionInput with ActionTicket delivery/completion semantics instead of parallel direct agent.prompt() paths.

Adds TurnExecutionPolicy on prepared turns (preparation barriers, before_agent_start, next-turn context timing, retry-inclusive completion) and CommitPreparationPolicy flags for optional model/auth waits. The input pump batches follow-ups only when policies match, handles preselected actions for update-restart rollback, and uses captureRunMessages on cancel to strip in-flight transcript rows.

Deletes _dispatchPromptWithFence, direct-prompt checkpoint fencing, _acceptedAgentMessagePrompt, and _acquireDirectTurnAdmission; cancellation/clear/abort now reject tickets, restore prefix/next-turn context, and gate queue_update / legacy queue projections on queueVisible. session-action-store gains rejectDelivered and actionsForMessage (broader than the old active-only lookup).

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

Comment thread packages/coding-agent/src/core/agent-session.ts
Comment thread packages/coding-agent/src/core/agent-session.ts
Comment thread packages/coding-agent/src/core/session-action-store.ts
Comment thread packages/coding-agent/src/core/agent-session.ts Outdated
@snimu
snimu force-pushed the refactor/session-action-admission branch from f17666b to 62f410b Compare August 1, 2026 20:11
Comment thread packages/coding-agent/src/core/agent-session.ts
Comment thread packages/coding-agent/src/core/agent-session.ts
Comment thread packages/coding-agent/src/core/agent-session.ts
Comment thread packages/coding-agent/src/core/agent-session.ts
@snimu
snimu force-pushed the refactor/session-action-admission branch from fe13e80 to cabe131 Compare August 1, 2026 21:20
Comment thread packages/coding-agent/src/core/agent-session.ts
@snimu
snimu force-pushed the refactor/session-action-admission branch from cabe131 to 3007ef4 Compare August 2, 2026 10:14
Comment thread packages/coding-agent/src/core/agent-session.ts
Comment thread packages/coding-agent/src/core/agent-session.ts
Comment thread packages/coding-agent/src/core/agent-session.ts
Comment thread packages/coding-agent/src/core/agent-session.ts
Comment thread packages/coding-agent/src/core/agent-session.ts
Comment thread packages/coding-agent/src/core/agent-session.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-admission branch from 3007ef4 to 212d2be 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.

@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 3 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 212d2be. Configure here.

Comment thread packages/coding-agent/src/core/agent-session.ts
Comment thread packages/coding-agent/src/core/agent-session.ts
Comment thread packages/coding-agent/src/core/agent-session.ts
snimu added 3 commits August 2, 2026 22:48
Prevent heterogeneous turn batches from applying the first action’s execution policy to every action in the batch.
…ions

Restores the pre-handoff clear boundary for general queue operations while preserving targeted accepted-agent cancellation with abort-backed late-event capture.
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-admission branch from 212d2be to 2a21d52 Compare August 3, 2026 02:59
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.
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 9808aa7 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-admission branch August 5, 2026 18:54
zhengr pushed a commit to zhengr/prime-agent that referenced this pull request Aug 8, 2026
…lect-ai#574)

* refactor(coding-agent): cut over session action admission

* fix(coding-agent): split turn batches on execution policy change

Prevent heterogeneous turn batches from applying the first action’s execution policy to every action in the batch.

* fix(coding-agent): stop general clears from reclaiming handed-off actions

Restores the pre-handoff clear boundary for general queue operations while preserving targeted accepted-agent cancellation with abort-backed late-event capture.

* batched actions had weird commit behavior when cancelled. make it consistent

---------

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