fix: pre-dispatch save and response task guard - #81
Merged
Conversation
…tasks Move save_message for user messages from _run_response_loop to _handle_message (before send_message) so is_message_handled returns True immediately, closing the dedup window gap. Add _response_tasks guard at top of _handle_message to prevent concurrent task overwrites. Closes #79, closes #80 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.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
• Pre-dispatch save (#79) — Moves
save_messagefor user messages from_run_response_loopto_handle_message, beforesend_message. This closes the dedup window:is_message_handled()returns True immediately, preventing re-triggers during the agent response.• Response task guard (#80) — Adds an early-return check at the top of
_handle_message: if_response_tasks[thread_ts]already exists, the message is silently skipped. Prevents concurrent task overwrites and conflicting DB writes.Closes #79
Closes #80
Test plan
• 6 new tests in
TestPreDispatchSaveandTestResponseTaskGuard• Full suite: 302 passed, 0 failures (baseline was 296)
• Verified RED phase: all 4 fix-specific tests failed before implementation
• Verified GREEN phase: all pass after implementation
🤖 Generated with Claude Code