Repository navigation
feat(agent): coalesce queued follow-ups into one run - #871
Merged
Merged
Conversation
Restores the follow-up coalescing removed in #637, this time behind an opt-in `enqueue_coalescing` busy policy so only callers that can absorb a folded run opt in. Agent: - `BusyPolicy::EnqueueCoalescing` queues like `enqueue_if_busy` but lets the run boundary fold a consecutive run of such requests into one. - `InMemoryRunQueue::drain_coalescing_after_first` takes that prefix atomically: the front must itself have opted in, folding stops at the first request that did not (order and identity preserved) and at the merged-payload byte cap; folded requests leave the queue, release their quota and are recorded terminal with reason `merged`. - `start_next_scheduled` merges text, model-context sidecar, images and attachments in queue order (nothing dropped, nothing reordered), keeps the front request's run identity, and takes the EXECUTION configuration (model, thinking, cwd, permissions, sandbox) from the LAST folded request, so #637's "front config silently reused for later requests" cannot happen. The accepted message carries `coalesced_run_ids`. TUI: submits with the coalescing policy, and renders a folded submission as `merged into the previous run` (`RunState::Merged`) instead of leaving it at `queued (#n)`. Loop: the supervisor outbox delivers batches with the coalescing policy — batches are fire-and-forget state syncs, so the ones that queue behind a busy orchestrator fold into one reconciliation run instead of each starting and being superseded on its own. CLI `--follow-up`, the IM bridges and Desktop/Mobile keep plain `enqueue_if_busy`: they stream their own run and would stall on a merged ack they never receive.
huichen
enabled auto-merge (squash)
September 26, 2026 08:24
huichen
added a commit
that referenced
this pull request
Sep 26, 2026
Picks up future-skills#60, which documents the coalesced supervisor delivery from #871 (busy orchestrator folds queued batches into one turn) and the per-batch note cap. The bump also carries the three commits main already had (future-slides research decks, builtin lookup helper fixes, the code-development skill), so the pin is current. skills offline checks pass on the bumped content (builtin structure, 27 unit tests, experimental-design, slides, orchestration, deep-research).
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.
Restores the follow-up coalescing that #637 removed, behind an opt-in
enqueue_coalescingbusy policy so only callers that can absorb a folded run pay for it.Why
A submission sent while a turn is running is usually a supplement to the one before it. Answering each fragment in its own run makes the model reply to a half-stated request. The same is true of the loop's supervisor outbox: those batches are state syncs, not questions, so a busy orchestrator turning each into its own run (and having most of them superseded) is pure waste — one measured goal ran 26 queued orchestrator runs back-to-back after a 2h turn, 25 of them cancelled.
What
Agent
BusyPolicy::EnqueueCoalescing: queues likeenqueue_if_busy, but the run boundary may fold a consecutive run of such requests into ONE run.InMemoryRunQueue::drain_coalescing_after_firsttakes that prefix atomically. Folding stops at the first request that did not opt in (so a client that streams its own run keeps its own run, in order), and at the merged-payload byte cap — folding happens after admission, so this is the only bound on the combined size.merged.start_next_scheduledmerges message + model-context sidecar + images + attachments in queue order (nothing dropped, nothing reordered), keeps the front request's run identity, and takes the execution configuration (model, thinking level, cwd, permissions, sandbox) from the LAST folded request — the user's latest instruction decides how the combined turn runs. That is the behaviour fix: harden agent, desktop, and mobile reliability #637 objected to (it reused the front's settings for later requests), and it no longer happens. The accepted user message recordscoalesced_run_ids.TUI — submits with the coalescing policy and renders a folded submission as
merged into the previous run(RunState::Merged) instead of leaving it stuck atqueued (#n); amergedreason is mapped before the plain terminal state on refresh.Loop —
supervision::flushdelivers its batches with the coalescing policy, so batches that queue behind a busy orchestrator fold into one reconciliation turn. A batch arriving while the orchestrator is idle still runs immediately.Deliberately unchanged — CLI
--follow-up, the IM bridges (Feishu/DingTalk) and Desktop/Mobile keepenqueue_if_busy: they stream their own run and would wait forever for anagent_endthat a folded run never produces. Desktop and Mobile additionally block submission while a reply streams (stop first, then send), so they have nothing to coalesce anyway.Verification
cargo fmt --check,cargo clippy --all-targets -- -D warnings,cargo testforfuture-agent,future-tui,future-loop,future-rpc."second question\n\nthird question",mergedreceipts,coalesced_run_idsmetadata), last-settings-wins (falsified: it fails when the front's snapshot is used), TUI merged rendering + refresh mapping, and the outbox's wire policy.REGENERATE_PROTO=1); only the field-144 comment changed.Known limitation
The fold drains before the run is activated, so if activation fails (inaccessible workspace, lost lease race) the folded requests are gone with the front request that is cancelled in the same arm. This matches the pre-#637 shape and the window is narrow (persistence is checked earlier); it is documented at the call site.
Follow-up (not in this PR)
skills/builtin/future-loop/SKILL.md(separate submodule) can mention that a burst of reports may arrive as one prompt.