refactor(coding-agent): extract session action contract helpers - #572
Merged
Merged
Conversation
This was referenced Aug 1, 2026
snimu
force-pushed
the
refactor/session-action-contracts
branch
3 times, most recently
from
August 2, 2026 13:43
2794787 to
637785f
Compare
This was referenced Aug 2, 2026
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 46d8cbf. Configure here.
alexzhang13
force-pushed
the
refactor/session-action-contracts
branch
from
August 2, 2026 19:56
46d8cbf to
1377888
Compare
alexzhang13
force-pushed
the
refactor/session-action-contracts
branch
from
August 2, 2026 20:00
1377888 to
2db004b
Compare
alexzhang13
approved these changes
Aug 2, 2026
alexzhang13
left a comment
Contributor
There was a problem hiding this comment.
I just added a few small changes to keep the behavior consistent with main.
zhengr
pushed a commit
to zhengr/prime-agent
that referenced
this pull request
Aug 8, 2026
…eIntellect-ai#572) * refactor(coding-agent): extract session action contract helpers * refine happens before new prompt action * ensure queued nextTurn messages are drained only after await --------- 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
First PR of a five-PR stack refactoring session-input scheduling into a single typed action model. This PR changes no behavior: it extracts the duplicated prompt-processing pipelines into shared, policy-driven helpers and adds characterization tests that encode the exact per-entrypoint contracts the rest of the stack must preserve.
Stack: #572 contracts (this) <- #573 kernel <- #574 admission <- #575 protocol <- #576 cleanup
Motivation
AgentSessionhad (at least) three overlapping implementations of "take input, prepare it, hand it to the model": the ordinary direct prompt path (_promptUnserialized, ~365 lines), the injected-message path (_promptInjectedMessageUnserialized, ~175 lines), and the queued-prompt path (_startPreparedPromptItems). Each re-implemented normalization (slash parsing, extension commands, input handlers, skill/template expansion), commit preparation (model/auth validation, pre-turn compaction,before_agent_start, refinement barriers, system-prompt composition), and the dispatch/delivery fence. Before unifying ownership (PR 3), the shared pipeline steps need one implementation each, and the current timing needs to be pinned by tests so later PRs can prove they preserved it.Code changes
_normalizeSubmission()/SubmissionNormalizationPolicy: the admission-time pipeline (session-command parse, extension-command lookup/execute, input interception, skill/template expansion), extracted with per-entrypoint policy; timing bit-for-bit preserved._prepareForCommit()/CommitPreparationPolicy+CommitPreparationSteps: the execution-time pipeline (validation, pending model-selection sync, pre-turn compaction,before_agent_start, refine barriers, final message+system-prompt composition), extracted from all three paths with caller differences kept explicit (compaction/model-selection order, bash flushing, empty-extension-prompt preservation)._dispatchPromptWithFence()/PromptDispatchFence: the shared dispatch fence (delivery observation, restart-checkpoint section, next-turn drain/restore identity)._activeSessionInputphases,_directPromptSectionCount,_directDispatchObservers, accepted-agent-message state,deliveredPendingNextTurnMessages.test/suite/agent-session-action-contracts.test.ts:prompt("/compact")parses as a session command whilesteer("/compact")stays model text; input handlers handle/transform before queue admission;deliverAs: "nextTurn"precedence overtriggerTurn; restore methods bypass interception and idle wake.Agent.prompt(messages)call) - this motivates the per-message two-edge delivery model in PR 2.LOC: +426/-329 production (net +97), +139 tests.
Note
Extract session action contract helpers in
AgentSessionto centralize submission normalization and dispatch_normalizeSubmission,_prepareForCommit,_applyPreparedSystemPrompt, and_dispatchPromptWithFencein agent-session.ts to centralize logic that was previously scattered acrossprompt,_prompt,steer,followUp, and_startPreparedPromptItems.steerandfollowUpexplicitly reject extension commands and apply skill/template expansion via the shared normalization path._pendingNextTurnMessagesvia the fence object returned by_dispatchPromptWithFence.steer/followUpqueues.Macroscope summarized 11a1f67.
Note
Medium Risk
Touches core prompt/commit/dispatch timing across all session input entrypoints; mistakes could change ordering, queue admission, or partial-failure recovery despite characterization tests.
Overview
Refactors
AgentSessionprompt paths so normalization, commit prep, and dispatch share one implementation instead of three copy-pasted pipelines—intended as a no-behavior-change step before a larger scheduling refactor.New shared helpers:
_normalizeSubmission(slash commands, extension commands, input handlers, skill/template expansion, per-entrypoint policy),_prepareForCommit(refine barriers, bash flush, validation, compaction timing,before_agent_start, system prompt),_dispatchPromptWithFence(delivery observation, checkpoint fencing, restoring undelivered next-turn messages), and_applyPreparedSystemPrompt. Directprompt, injected prompt,_prompt, queued batch (_startPreparedPromptItems), plussteer/followUpnow call these with explicit policies (e.g. session-command parsing only onprompt, not onsteer/followUp).Tests:
agent-session-action-contracts.test.tspins those contracts (command parsing scope, input-handler order before queueing,nextTurnvstriggerTurn, restore bypassing handlers).Agenttest documents that a batchedprompt([m1, m2])can leave only a prefix committed if a listener throws mid-batch.Reviewed by Cursor Bugbot for commit 11a1f67. Bugbot is set up for automated code reviews on this repo. Configure here.