Skip to content

Wake agent sessions after their inbox events commit - #351

Merged
HamptonMakes merged 3 commits into
block:mainfrom
ThePumpingLemma:dgrochowski/wake-after-commit
Nov 24, 2026
Merged

HamptonMakes merged 3 commits into
block:mainfrom
ThePumpingLemma:dgrochowski/wake-after-commit

Conversation

@ThePumpingLemma

@ThePumpingLemma ThePumpingLemma commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

What changed and why

#344 made AgentEvents::Publish lock and re-read a comment before queuing its events, so a deleted comment isn't queued. That put every recipient's AgentEvent insert 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. CreateNotificationsJob doesn'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 review found this while reviewing #349 and #350.

Evidence

spec/services/coplan/agent_events/publish_spec.rb adds 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

bundle exec rspec spec/services/coplan/agent_events/publish_spec.rb -e "keeps every queued event"

Testing

  • No browser UI involved.
  • Added a service spec that fails on main and passes here.
  • Ran 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.
  • Light and dark mode don't apply.
  • Evidence is spec output.

Generated with Codex

- 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
HamptonMakes merged commit b58042a into block:main Nov 24, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants