Skip to content

agent: retry a busy commit without repeating the transaction - #2084

Open
evgeny-simplex wants to merge 7 commits into
simplex-chat:masterfrom
evgeny-simplex:ep/sqlite-failed-commit
Open

evgeny-simplex wants to merge 7 commits into
simplex-chat:masterfrom
evgeny-simplex:ep/sqlite-failed-commit

Conversation

@evgeny-simplex

@evgeny-simplex evgeny-simplex commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

A COMMIT that waited more than the 100 ms busy timeout for another reader failed with SQLITE_BUSY and left the transaction open (sqlite-simple's withImmediateTransaction rolls back only when the action fails). dbBusyLoop then retried the whole transaction, BEGIN IMMEDIATE failed with "cannot start a transaction within a transaction", which is not retried, and every later transaction on the store's single connection failed the same way until restart: messages stopped in both directions. A COMMIT that failed on a deferred foreign key left the store stuck in the same way.

  • withTransactionPriority runs its own BEGIN IMMEDIATE, the action and COMMIT, in two dbBusyLoops. BUSY in BEGIN or in the action re-runs both, as before. A busy COMMIT is retried inside the open transaction, so the action runs once. Any failure of the COMMIT retries, including an exhausted budget, rolls back and rethrows, so the connection does not stay inside a transaction.
  • While a COMMIT is retried, the writer holds SQLite's PENDING lock and new readers wait.
  • simplexmq no longer calls sqlite-simple's transaction functions.
  • Tests in "SQLite store", "busy commit":
    • "should retry busy commit without repeating transaction": a second connection holds a read transaction until a second COMMIT has started; the action runs once and the row is committed.
    • "should roll back busy commit after retry budget and keep store usable": the read is held beyond the budget; the transaction fails with ErrorBusy, and the next one succeeds.
/Core tests/Agent core tests/
/SQLite store/

@epoberezkin
epoberezkin marked this pull request as ready for review November 19, 2026 21:08

This branch has not been deployed

No deployments
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