Add end-of-turn batching layer for same-channel messages (#91)#95
Open
strix-tkellogg wants to merge 1 commit into
Open
Add end-of-turn batching layer for same-channel messages (#91)#95strix-tkellogg wants to merge 1 commit into
strix-tkellogg wants to merge 1 commit into
Conversation
Part 2 of #91. After responding to a Discord message, drain any same-channel discord_message events queued during the turn and process them in a single follow-up turn so a rapid thread costs 2 turns instead of N. - `_drain_same_channel_discord_events` filters the queue's backing deque directly so `_unfinished_tasks` accounting stays intact; caller is responsible for `task_done` per drained event. - New `batched_turn_start` event records channel_id and batch_size. - `turn_timing` now carries a `batched` field distinguishing the triggering turn from the follow-up batch leg. - Other-channel and non-discord events stay untouched in the queue.
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
_process_eventruns for adiscord_message, pop every queued same-channeldiscord_messageand process them all in a single follow-up turn. A burst of N messages now costs 2 turns instead of N._render_promptalready pulls full recent-channel history, so every batched message lands in context._unfinished_tasksuntouched; caller balances withtask_doneper drained event.Telemetry
batched_turn_startevent:channel_id,trigger_event_type,batch_size.turn_timingnow carries abatchedboolean — distinguishes the triggering turn from the follow-up batch leg so you can jq the events log for turns where batching actually saved work.Closes #91. Part 1 (turn-time instrumentation) shipped in #94 so this can be evaluated against real numbers.
Test plan
tests/test_batched_processing.py::test_same_channel_messages_drain_into_one_batched_turn— 3 queued (2 same-channel + 1 other) → exactly 2 agent invocations,batched_turn_start{batch_size: 2}, oneturn_timing{batched: true}, other-channel event survives.tests/test_batched_processing.py::test_no_batched_turn_when_queue_has_no_same_channel_messages— unrelated queued event does not trigger batching.tests/test_batched_processing.py::test_non_discord_trigger_does_not_batch— scheduler tick does not absorb a matching discord_message.tests/test_batched_processing.py::test_drain_helper_preserves_order_of_kept_events— order-preserving filter across mixed-channel queue.🤖 Generated with Claude Code