Repository navigation
Description
Two overlapping inbound message appends can both commit while the conversation retains only one unread increment and the older message's activity timestamp. The message rows survive; the conversation summary and ordering become wrong.
Reproduce locally
Use two transactions against one owned synthetic conversation with zero unread messages. Give the first inbound append an older sentAt and the second a newer sentAt.
- Start the older append using native
addMessageToConversation; pause after it has read the conversation and inserted its message, immediately before its conversation UPDATE. - Submit the newer append to authenticated
POST /api/app/conversations/{id}/messages?orgId={org}and let it commit (201). - Release the older UPDATE and let that transaction commit.
- Read both message rows and the native conversation projection.
Expected: two unread inbound messages; activity time is the newer timestamp regardless of commit order.
Observed: both messages are stored, but metadata.unread_count=1 and both metadata.last_message_at and indexed last_message_at_ms equal the older timestamp. Native GET projects that regressed time. The parent replay used timestamps 1790618104801 and 1790618164801; the final indexed value was 1790618104801.
Evidence and positive control
Real local PostgreSQL at its ordinary transaction isolation; the older append runs the unmodified service with a scheduling-only proxy at the UPDATE, while the other request passes through the authenticated native localhost:3078 route. The sequential control appends newer then older and retains unread=2 and the newer activity timestamp. The held-write seam changes ordering only; it does not stub database reads, persistence or projection. No external transport or real mailbox was involved. Both local transactions and the final HTTP read were observed by the parent.
Root cause and repair boundary
backend/domains/conversations/service.ts:296 reads the parent without a row lock. It then derives unread count and last-message time from that snapshot and writes the whole metadata object at lines 379–412. A later UPDATE can overwrite a concurrent committed increment and timestamp.
Serialize the parent update or make these updates atomic against current stored values while preserving unrelated metadata and the monotonic timestamp contract. Add a real-Postgres overlap test; sequential out-of-order tests alone miss this failure. Count unread and activity as one stale read/modify/write defect.
Audit scope and reproduction record
- Tested source:
480ee6a3e6d33c3414a2c0f8a52fded1ddc4ca2d; local-only audit on 2026-09-28. - Relevant source compared with origin/main
2be6c267eaf8b7a67d0e5abe1b0b3d655eb2ca25. The cause remains present; the only changes in the compared Inbox UI files are unrelated accent/filter-error affordances. - Full-body dedup reviewed against the all-state issue snapshot and the existing 102-finding baseline. This is one distinct cause, not an endpoint/locale variant or documented debt.
- Parent replay log:
/Users/yannick/.codex/notes/tale-1000-additional/inbox-next/parent-concurrent-append.log. Retained proof code lives in the same notes directory outside the repository. No production testing, real customer data, provider calls or application source edits. - Source links are rooted at the tested commit.
- Severity: P2.
Activity
fix(platform): read a conversation's summary under its row lock