refactor(coding-agent): add session action scheduler kernel - #573
Merged
snimu merged 1 commit intoAug 3, 2026
Merged
Conversation
This was referenced Aug 1, 2026
snimu
force-pushed
the
refactor/session-action-kernel
branch
from
August 1, 2026 21:20
1b02e9c to
6ae3af0
Compare
snimu
force-pushed
the
refactor/session-action-kernel
branch
from
August 2, 2026 10:14
6ae3af0 to
38da9c5
Compare
snimu
force-pushed
the
refactor/session-action-kernel
branch
from
August 2, 2026 13:43
38da9c5 to
e9e7486
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit e9e7486. Configure here.
alexzhang13
force-pushed
the
refactor/session-action-kernel
branch
from
August 2, 2026 20:00
e9e7486 to
46f328f
Compare
alexzhang13
force-pushed
the
refactor/session-action-kernel
branch
from
August 2, 2026 20:23
46f328f to
09e9e1e
Compare
alexzhang13
approved these changes
Aug 2, 2026
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>
zhengr
pushed a commit
to zhengr/prime-agent
that referenced
this pull request
Aug 8, 2026
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Second PR of the session-action stack: introduces the scheduler kernel - a typed
SessionActionenvelope, a guarded lifecycle, per-message two-edge delivery records, and anActionStorethat becomes the sole owner of the queued-input lists - and routes the existing queued pump through it. External and wire behavior is preserved bit-for-bit via one private legacy projection (deleted in #4).Stack: #572 contracts <- #573 kernel (this) <- #574 admission <- #575 protocol <- #576 cleanup
Motivation
Queued prompts and session commands were typed (
PreparedPromptInput | PreparedCommandInput) but ~15 call sites mutated_steeringMessages/_followUpMessagesdirectly, lifecycle was inferred from loosely coupled fields (_activeSessionInputphases, pump flags), and the ambiguous "pending" projection conflated queued future work with active executing work - the root cause of the executing-/compact-shows-as-queued bug and of/compactseeing itself as its own successor. This PR builds the authoritative ownership model while deliberately not yet touching direct prompt paths, so queue mechanics can be verified in isolation before the risky cutover.Code changes
src/core/session-action-store.ts:SessionActionenvelope (id, source, delivery policy, wake policy, payload unionturn | session_command, lifecycle, queueKey, correlation).DeliveryRecordwith independentstarted(message_start -> acceptance settlement) anddurable(message_end/transcript membership -> gates rollback/restore) edges.transitionSessionAction()asserting the legal-transition table, includingcommitting -> queuedrollback only with transcript-membership proof of non-delivery.ActionTicketController(accepted/delivered/completed legs).ActionStore: facade over the two per-policy FIFO lists;enqueue/enqueueFront(goal-context front insertion)/selectFirst/remove/rollback-at-original-position; named projections (queuedActions,clearableActions,snapshotActions,unfinishedActions,activeActions,queuePreview)./compactsuccessor detection now uses literalqueuedActions()(internal fix; wire semantics unchanged).legacyPendingProjectionreproduces the old external behavior exactly, including the known executing-command-in-queue display bug (fixed in add model agnostic rlm system prompt #4, not here).SessionActionRecoverySnapshotwith a private adapter emitting/reading the current restart-manifest format unchanged._steeringMessages/_followUpMessagesfields and their scattered mutation sites,PreparedPromptInput/PreparedCommandInput/QueuedSessionInput,_startPreparedPromptItems,_activeSessionInput./compactself-successor exclusion.LOC: +853/-399 production (net +454), +264/-54 tests.
Note
Add session action scheduler kernel to
AgentSessionwith lifecycle state machine and two-lane queuesession-action-store.tswith a typed state machine (queued→selected→preparing→committing→running→completed/failed), aLEGAL_TRANSITIONStable, and anActionStoreclass managing two delivery lanes (next_turn_boundaryandwhen_run_idle)._steeringMessages/_followUpMessagesarrays and_activeSessionInputinagent-session.tswith a singleActionStore, binding action lifecycle transitions tomessage_start/message_endagent events.ActionTicketControllerwith three independently settled promises (accepted,delivered,completed), enabling precise rollback and cancellation on deferral or error.canSelectSessionActionandshouldYieldLowerRungate admission based on runtime activity flags and pause state.clearQueue, and checkpoint logic all change semantics; any code relying on the removed internal arrays or_activeSessionInputstate will break (test suite internals were updated accordingly).Macroscope summarized 09e9e1e.
Note
High Risk
Large rewrite of queued scheduling, lifecycle, rollback, and agent-event delivery in
AgentSession; regressions are plausible in coalescing, deferral, multi-turn batching, and restart recovery despite preserved legacy projections.Overview
Introduces
session-action-store.ts, a scheduler kernel with typedSessionActionenvelopes (turn vssession_command), delivery policies (next_turn_boundary/when_run_idle), wake policies, per-messageDeliveryRecordedges (started/durable), guardedtransitionSessionAction, andActionTicketControllersettlement for accepted/delivered/completed.AgentSessiondrops_steeringMessages,_followUpMessages,_activeSessionInput, and the oldPreparedPromptInput/PreparedCommandInputshapes in favor of_actionStore. Enqueue, cancel, clear-queue, coalescing, steering-stop, and recovery snapshots all go through the store;legacyPendingProjectionkeeps external queue/previews/recovery wire behavior unchanged until a later protocol break.The session input pump selects via
canSelectSessionAction/shouldYieldLowerRun, batches turns at selection time (commands as barriers), runspreparing → committing → running → completed(or rollback with transcript proof), and settles tickets on success/failure.message_start/message_endnow update delivery records and drivecommitting → runningfor primary turns./compactsuccessor checks use literalqueuedActions()so an executing command no longer counts as its own queued successor (internal fix; display quirk preserved via legacy projection).Tests add
session-action-store.test.tsand retarget harnesses from internal queue fields to_actionStore/_createPreparedTurnAction.Reviewed by Cursor Bugbot for commit 09e9e1e. Bugbot is set up for automated code reviews on this repo. Configure here.