Repository navigation
feat(agent-core-v2): deliver queued prompts to the model in one batched turn - #4052
Open
mike-lmctl wants to merge 1 commit into
Open
mike-lmctl wants to merge 1 commit into
mike-lmctl wants to merge 1 commit into
Conversation
…ed turn When a turn ends with several prompts queued, the harness now drains the whole queue into the next turn instead of starting one turn per prompt: the model receives all queued user messages at once, in FIFO order, each still a separate user message. Single-prompt and idle-submit behavior is unchanged. The prompt gate now evaluates the whole queue snapshot sequentially with per-item block/fail/rewrite; blocked or failed items are dropped individually and arrivals during gating are kept for the next batch. Secondary prompts bind to the shared turn: their handles launch with it, each tracked prompt gets its own started/completed events, and cancellation of any batched prompt cancels the shared turn.
🦋 Changeset detectedLatest commit: 7aaef76 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This branch has not been deployed
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.
Requirement or Bug
Related: #4051 — prompts submitted while a turn is running are delivered strictly one turn per prompt (FIFO); this change delivers all prompts queued at a turn boundary together in a single turn.
Note: this is a behavior enhancement, filed alongside issue #4051 per the contribution policy (external feature PRs need maintainer approval; offered here as a tested reference implementation).
Bug Reproduction Steps
N/A (enhancement; current vs proposed behavior is described in #4051).
Root Cause
N/A. Mechanically: at a turn boundary the agent machine drained only the queue head into the next turn (
drainPendingPatchinpackages/agent-core-v2/src/human/agent/machine.ts), so each queued prompt got its own turn.Code Changes
All changes are in
@moonshot-ai/agent-core-v2:src/human/agent/machine.ts: at a turn boundary the machine now drains the whole queue into the next turn (notifications first, then all queued entries, FIFO). The prompt gate evaluates the entire queue snapshot sequentially with per-item outcomes: blocked items emitprompt.blockedand drop, gate errors emitprompt.gate_failedand drop, rewrites apply per item, and items arriving during gating are kept for the next batch (the stale-gate guard re-gates when a gated item vanished). An actor-level gate failure now fails every queued item and clears the queue instead of potentially re-entering gating forever. The emittedturn.startedevent gainsentries(all drained queue entries);queueItemId/entrystill carry the first entry, and the store journal schema is unchanged.src/agent/loop/machine/engine.ts: passesentriesthrough onturnStarted.src/agent/loop/loopService.ts: secondary (batched) prompts bind to the shared turn — their handles launch with it, each tracked prompt gets its own started/completed events, and completions resolve from the shared turn result. If the batch head was cancelled before binding, the first entry with a live waiter becomes the primary. Cancelling any batched prompt cancels the shared turn. Single-prompt, idle-submit, and pure-notification paths are unchanged.Impact Scope
@moonshot-ai/agent-core-v2suite passes: 6,878 tests.Checklist
/approve). — Enhancement: deliver queued prompts to the model in one batched turn instead of one turn per prompt #4051, awaiting maintainer review; we understand the PR may be closed without review per policy.gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update. — no user-doc surface changes (behavior of prompt queueing only).