fix: outbox + thought save not transactional #14

Open
opened 2026-05-29 09:25:31 +00:00 by GKaszewski · 0 comments
Owner

Problem

ThoughtRepository::save() and OutboxWriter::append() each acquire their own DB connection. A crash between the two can lose the outbox event — the thought is persisted but the federation broadcast never fires.

Acknowledged in crates/worker/src/outbox_relay.rs:30.

Fix approach

Requires sharing a transaction handle between repositories. Options:

  1. Pass &mut PgConnection (or a Transaction) through the use case into both repos
  2. Create a UnitOfWork / TransactionalContext wrapper
  3. Move outbox append into PgThoughtRepository::save() so both happen on the same connection

This is an architectural change — each approach has trade-offs for the hexagonal boundary.

## Problem `ThoughtRepository::save()` and `OutboxWriter::append()` each acquire their own DB connection. A crash between the two can lose the outbox event — the thought is persisted but the federation broadcast never fires. Acknowledged in `crates/worker/src/outbox_relay.rs:30`. ## Fix approach Requires sharing a transaction handle between repositories. Options: 1. Pass `&mut PgConnection` (or a `Transaction`) through the use case into both repos 2. Create a `UnitOfWork` / `TransactionalContext` wrapper 3. Move outbox append into `PgThoughtRepository::save()` so both happen on the same connection This is an architectural change — each approach has trade-offs for the hexagonal boundary.
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: GKaszewski/thoughts#14