Skip to content

fix(outbox): prune delivered rows inside the add's write transaction - #535

Merged
andrebrait merged 1 commit into
mainfrom
fix/outbox-prune-in-add-transaction
Nov 18, 2026
Merged

andrebrait merged 1 commit into
mainfrom
fix/outbox-prune-in-add-transaction

Conversation

@andrebrait

@andrebrait andrebrait commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Every outbox add ran pruneDelivered as its own autocommit DELETE before
the add's BEGIN IMMEDIATE transaction, so it took the database's write
lock twice. With several server processes adding at once, the
housekeeping DELETE could wait past busy_timeout and fail the whole add
with a 500 ("database is locked"), seen on the Windows CI runner in
"concurrent processes share the 1000-row active pool". The prune now
runs first inside the add's own transaction: one write lock per add, in
the same order as before.

Summary by CodeRabbit

  • Bug Fixes
    • Improved consistency when adding messages to the outbox: delivered entries are now cleaned up as part of the add operation. This helps keep outbox updates coordinated and reduces the chance of cleanup occurring separately from a failed or interrupted addition.

Every outbox add ran pruneDelivered as its own autocommit DELETE before
the add's BEGIN IMMEDIATE transaction, so it took the database's write
lock twice. With several server processes adding at once, the
housekeeping DELETE could wait past busy_timeout and fail the whole add
with a 500 ("database is locked"), seen on the Windows CI runner in
"concurrent processes share the 1000-row active pool". The prune now
runs first inside the add's own transaction: one write lock per add, in
the same order as before.
@coderabbitai

coderabbitai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

runOutboxCommand now prunes delivered entries inside the add operation’s immediate transaction instead of deleting them before the transaction.

Changes: Outbox add operation

Layer / File(s) Summary
Prune delivered entries within add transaction
lib/message-outbox.ts
runOutboxCommand starts the transaction before pruning delivered entries. Pruning and the add operation use the same write lock.

Estimated code review effort: 1 (Trivial) | ~4 minutes

Change: Bug fix

Merge Risk: Minimal · up to 9a980

Pruning delivered outbox rows now happens inside the add's single write transaction, which should avoid "database is locked" failures when several processes add concurrently. No concrete merge-blocking risk was found.

Security architecture risk: Minimal · up to 9a980

The change consolidates pruning and message admission under one write transaction without expanding access or changing message ownership checks. No introduced or worsened security or failure-containment risk was identified.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • observed — Pruning operates across sessions sharing the same outbox database, and admission uses global active-entry limits. This shared-store scope already existed; the change consolidates its transaction boundary rather than expanding the deletion scope.

Trust Boundaries and Controls

  • observed — Within the inspected entrypoint, command-supplied origin is rejected, installation scope and input constraints are checked before admission, and existing identifiers are checked against session membership both before and inside the transaction. The comparison does not move or remove these controls or change the supplied owner and advisor parameters.
Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the change: delivered-row pruning now runs inside the add operation's write transaction, which matches the raw summary (pruning moved from a separate autocommit DELETE into the BEGIN I…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the change: delivered-row pruning now runs inside the add operation's write transaction, which matches the raw summary (pruning moved from a separate autocommit DELETE into the BEGIN IMMEDIATE transaction) and the PR objective of using one write lock per add. The title is specific and concise, and the 68-character length is within normal bounds. It does not mention the lock-timeout symptom, but it does not need to.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3dc95812-81c8-4494-a92b-38f8b5b1abbb
Commits

Reviewing files that changed from the base of the PR and between 7fe50eb and 9a980c0.

Files selected for processing: 1

  • lib/message-outbox.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

@andrebrait
andrebrait merged commit 346e193 into main Nov 18, 2026
5 checks passed
andrebrait added a commit that referenced this pull request Nov 18, 2026
Bumps the version to 0.7.3 and folds [Unreleased] into [v0.7.3]: the Windows tray built at release (#530), resumable omp runner downloads (#531), the normal update of an old linked host (#533) and one write lock per outbox add (#535).
@andrebrait
andrebrait deleted the fix/outbox-prune-in-add-transaction branch November 18, 2026 23:08
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.

1 participant