Repository navigation
Conversation
Serialize message insertion by conversation before allocating sequence IDs. Apply the same lock order to pings, org events and membership mutations. Include a deterministic two-process PostgreSQL regression that fails before this change and passes afterwards.
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Serialize message and event writes app/Actions/CreateMessage.php, app/Actions/CreateConversationPing.php, app/Actions/CreateConversationEvent.php |
Message and ping creation lock the conversation row. Event creation now runs message creation, conversation advancement, and the actor’s read-through update in a transaction, after requiring the conversation row to exist. |
Serialize membership changes app/Actions/CreateOrgMembers.php, app/Actions/DeleteOrgMember.php, app/Actions/UpdateOrgMemberRole.php |
These actions lock the conversation row and require it to exist before changing membership or a member’s role. |
Verify concurrent message ordering tests/Feature/RemotesCursorConcurrencyTest.php, tests/Support/RemotesCursorWorker.php |
The PostgreSQL test starts independent message writers, checks that the second writer waits for the lock, and verifies message IDs and cursor results. The worker can pause after inserting a message until the test releases it. |
Priority:
Estimated code review effort: 3 (Moderate) | ~25 minutes
Change: Bug fix
Sequence Diagram(s)
sequenceDiagram
participant RemotesCursorConcurrencyTest
participant RemotesCursorWorker
participant CreateMessage
participant PostgreSQL
RemotesCursorConcurrencyTest->>RemotesCursorWorker: Start first worker in hold mode
RemotesCursorWorker->>CreateMessage: Create message
CreateMessage->>PostgreSQL: Lock conversation and insert message
RemotesCursorWorker-->>RemotesCursorConcurrencyTest: Signal insert and wait for release
RemotesCursorConcurrencyTest->>RemotesCursorWorker: Start second writer
RemotesCursorWorker->>CreateMessage: Create second message
CreateMessage->>PostgreSQL: Request conversation lock
RemotesCursorConcurrencyTest->>RemotesCursorWorker: Release first worker
PostgreSQL-->>CreateMessage: Grant lock to second writer
RemotesCursorConcurrencyTest->>PostgreSQL: Check message IDs and cursor results
Possibly related PRs
- dev-null-sh/dev-null.sh#1101: Locks the conversation row when updating organization pins. This PR adds conversation-row locks to other write actions.
Suggested reviewers: xheaven
Merge Risk: 
Minimal · up to b571e
-
The change is mergeable after normal checks. The investigated lock-duration concern does not establish a material workflow impact.
Security architecture risk: 
Low · up to b571e
-
The change strengthens conversation ordering without an identified new authorization bypass. Remaining uncertainty concerns lock contention and concurrent membership transitions; the added regression covers message ordering rather than those broader behaviors.
Retained concerns
No architecture-level concerns identified.Security review details
-
Security Blast Radius
- inferred — The direct serialization domain is the selected conversation. For an organization, that shared row coordinates all members' message writes and membership administration. Broader connection-pool or service availability effects were not quantified.
Trust Boundaries and Controls
- observed — The inspected direct-message and ping requests retain canMessage and push-access checks. Organization message and ping requests require enabled Remotes and membership in the supplied organization. Member-removal requests check actor and target membership, while the deletion query independently scopes the mutation by conversation and target user.
Resilience and Maintainability Implications
- inferred — The new conversation lock is held during existing synchronous attachment processing and storage. Slow media work can therefore delay other writes, including membership removal, within that conversation. Retry and rollback cleanup provide important counterevidence against simply moving file creation outside the transaction; production latency and timeout evidence were unavailable.
Hardening Proposals
- proposed — Measure conversation lock wait and hold times for media-bearing messages and establish suitable processing and storage bounds. Any transaction-shortening change should preserve single-file retry behavior and rollback cleanup.
-
Pre-merge checks: 
5
Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment @coderabbitai help to get the list of available commands.
Serialize message insertion by conversation before allocating sequence IDs. Apply the same lock order to pings, org events and membership mutations. Include a deterministic two-process PostgreSQL regression that fails before this change and passes afterwards.
Summary by CodeRabbit