Repository navigation
fix(chat): skip sub-agent synthesis when one turn reported the batch - #17307
Conversation
|
Intent: When one turn already reported a sub-agent batch (a lone sub-agent, or a wave whose results arrive in one digest turn), end there instead of running a follow-up synthesis turn that only restates that report. Batches whose results arrive over two or more turns keep their single synthesis. |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Check that [DESIGN-REVIEWED] d2b6c98 Description read[DESCRIPTION-READ] e738902c125c6e163b6e095296f30d886cdd8ec5dcc1aaf8e4912e4caf41cc7b That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
First Principles Review (Opus 5.5) — 🟡 CONCERNSPremise-level review of First-Principles-Verdict: CONCERNS The user-message Not justified as shipped
Inventory (5 items) — 4 justifiedIntent: a lone sub-agent, or a batch reported in one turn, ends with that turn's reply instead of a restating synthesis turn. This is a FIX (#17274).
[FIRST-PRINCIPLES-REVIEWED] d2b6c98 Description read[DESCRIPTION-READ] 2751ef8d9d738b690127c7cc6ef6d2b1d1e8fa0d2b68a030bbcf0f93dd84a24a That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
213dc67 to
368cc15
Compare
|
Rebased: main moved in |
|
368cc15 to
d0296c3
Compare
|
Rebased: main moved in |
d0296c3 to
e843a7c
Compare
|
Rebased: main moved near this PR's specs and in tests importing its modules ( |
e843a7c to
9733ead
Compare
|
self-added: yes
|
9733ead to
f9057de
Compare
|
self-added: yes
|
|
self-added: yes
|
|
After the last sub-agent of a parent completes, the gateway arms a one-shot synthesis turn. When the whole batch reached the parent in a single completion turn (one spawn_run, or one wave digest), that synthesis only restates the reply the user just read. The gateway now counts each completion it queues or launches into the slot (_ChatSlot._synthesis_completion_turns). The turn-end fire decision in _finish_queue_cycle drops a cleared arm when the count is exactly 1. Any other count fires as before, and so does the store-outage re-check. The count resets when the synthesis runs, when it is dropped, and when a user message drained at a turn's end disarms an armed synthesis while no child of the batch is running, delivering, pending in memory or queued: _hand_off_queue reads synthesis_fire_verdict while the ending turn still holds the slot and passes the answer to the drain as end_batch. The drain itself reads no store, and every other drain keeps the count. The subagent and injected-messages specs describe the rule. Fixes #17274
f9057de to
d2b6c98
Compare
iamwhatever
left a comment
There was a problem hiding this comment.
The red 'Cross-Platform Portability' check is not a real defect. Job 112332176612 never got a runner: its runner name is empty, it has no steps, it sat queued on its run-scoped CodeBuild label from 14:47 to 15:38, and its only annotation is "The run was canceled by @patrigao". Its log blob returns BlobNotFound because no step ever ran, so nothing failed. The fix itself is small and safe: a count of 1 drops the arm only at fire time, and every other count, including 0 and a stale leftover, fires exactly as main does, so a multi-turn batch never loses its synthesis. Reading the fire gate in _hand_off_queue while the ending turn still holds slot.task keeps the drain free of awaits. Please rerun only that one job before merge so this head has a real portability result, even though readiness already shows passed.
Problem / Motivation
Goal: A lone sub-agent, or a batch whose results arrive in one turn, ends with that turn's reply instead of a second turn that restates it.
When a session spawns one background sub-agent, its result arrives as its own
[Subagent completion event]turn, and the agent reports there. That sub-agent was also the last one running, so the gateway arms the post-fan-out synthesis, that is, it schedules one extra turn to run once the session's queued turns are used up. When the queue drains (each queued message is taken off and run in order) and nothing is left, that second turn runs with[SYSTEM] Sub-agent synthesis: ... (1) restate the original goal .... Nothing new arrived between the two turns, so the reply typically opens with "This restates my last message; nothing new has come in since." and repeats the report the user just read.Why it matters
Long-running monitor and loop sessions spawn one work session at a time and report each result on its completion turn. Every result then costs an extra model turn and posts a duplicate message. A
spawn_runwave whose results land in one digest turn hits the same duplicate.Not a goal
spawn_sub_agents, stop/close, the spec-builder stop).What changed (motivation → approach → change)
The gateway arms the synthesis when the last outstanding sub-agent completes and fires it once the queue drains, but nothing records how many turns carried the batch. The synthesis only adds something when the results were spread over two or more turns.
The gateway now counts each completion it queues or launches into the session's chat slot (
_ChatSlot._synthesis_completion_turns, set inslack/gateway.py). The queue drain never merges completions, so each counted completion is one turn. A wave digest is a single queued completion, so it counts once. Indashboard/chat_runner.py, the turn-end fire decision (_finish_queue_cycle) drops an arm that is otherwise ready to fire when the count is exactly 1. Any other count fires as before, including 0, and the store-outage re-check fires exactly as on main. Dropping happens only at fire time, so every disarm path still disarms exactly when it does today.The count resets when the synthesis runs or is dropped, and when a user message drained at a turn's end disarms an armed synthesis while no sub-agent of the batch is running, delivering, pending in memory or queued. The turn-end hand-off (
_hand_off_queue) asks the samesynthesis_fire_verdictthe fire decision uses, while the ending turn still holds the slot, so no turn can start during the read. It passes the answer to the drain (_start_next_queued_turn), which reads no store and dequeues exactly as on main. Every other drain, such as Run now on a queued message, keeps the count: at worst that costs one synthesis main also runs, never one a multi-turn batch should get. Thesubagent.mdandinjected-messages.mdspecs describe the rule.Backwards compatibility
Compatible: nothing main accepts is rejected or renamed; the only change is one fewer automatic turn when exactly one completion turn carried the batch, and every other arm fires as today.
Removes nothing: no key, record, validator or public function goes away, and the synthesis turn still runs for every batch reported across two or more turns.
Tests
test/test_slack_gateway.pyTestSynthesisAfterAOneTurnBatchroutes completions through the realon_doneinto a real slot and ends each turn through_finish_queue_cycle. A lone completion gets no synthesis, both when it launches a turn on an idle chat and when it is queued behind a busy one, and so does a two-member wave digest. A user message drained at the end of the report turn disarms it, and the next lone completion gets none either. These four fail on main. Two completions in separate turns still get one synthesis, and so does a batch that a user message ran beside, both before the arm and while a lone completion's follow-up sub-agents were still running; these pass on main too, as unchanged behaviour should.test/test_chat_runner_coverage.py: a count of 1 drops the arm at turn end, while the store-outage re-check launches the synthesis whatever the count. A user message drained at a turn's end clears the count only when no child is running, delivering, pending in memory or queued in the store, and keeps it when that cannot be read. The hand-off reads the fire gate once, while the ending turn holds the slot; a direct drain and an unarmed hand-off read no store. Running the synthesis, or a user message that runs in its place, resets the count.Manual verification
N/A — unit coverage sufficient: the change is a counter on the delivery path, one check at the turn-end fire decision and one fire-gate read at the turn-end hand-off while a synthesis is armed, and the tests drive each through the real code paths.
Related Issues
Related: #13012 (the synthesis prompt presumes success).
Pattern harvest
Not generalizable: the arm counted outstanding sub-agents but not the turns that carried their results, a gap specific to this one post-fan-out turn.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Fixes #17274