Repository navigation
Wake agent sessions after their inbox events commit - #351
Merged
HamptonMakes merged 3 commits intoNov 24, 2026
Merged
Conversation
- block#344 wrapped comment event delivery in a transaction (the deleted-comment lock). session.wake! broadcasts the pill synchronously, so a Cable error rolled back every recipient's inbox row. - Run the wake after commit, like the webhook and the bus signal; inbox rows stay durable.
HamptonMakes
approved these changes
Nov 24, 2026
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.
What changed and why
#344 made
AgentEvents::Publishlock and re-read a comment before queuing its events, so a deleted comment isn't queued. That put every recipient'sAgentEventinsert in one transaction. Inside it,session.wake!broadcasts the session pill synchronously. If that broadcast raises, for example while Cable's database is down, the transaction rolls back the inbox rows for every recipient, not just the one being woken.CreateNotificationsJobdoesn't retry, so those events are gone, and the inbox is supposed to be the durable copy.Now the wake runs after the transaction commits, like the wake webhook and the inbox bus signal already do. A failed session wake is reported without stopping later recipients, webhook jobs, inbox signals, or human notifications. The wake locks and reloads the session so it cannot overwrite an acknowledgement made after the event commits.
sq agents reviewfound this while reviewing #349 and #350.Evidence
spec/services/coplan/agent_events/publish_spec.rbadds a spec with two wakeable sessions and a pill broadcast that raises. It checks both inbox events survive and both recipients still receive webhook jobs and inbox signals. Real-commit tests also cover nested commit and rollback, visibility from another database connection, and an agent acknowledgement before the deferred wake. The original durability case fails on main: the events are rolled back.How to try it
Testing
bundle exec rspec --exclude-pattern "spec/system/**/*_spec.rb": 2,925 examples, 0 failures. System specs can't start Chrome locally, so CI covers them.Generated with Codex