Skip to content

fix(runtime): mitigate SQLite contention with bounded recovery - #177

Open
kingsword09 wants to merge 1 commit into
mainfrom
fix/sqlite-write-recovery-162
Open

kingsword09 wants to merge 1 commit into
mainfrom
fix/sqlite-write-recovery-162

Conversation

@kingsword09

Copy link
Copy Markdown
Owner

Concurrent CLI processes can still fail with SQLITE_BUSY after the existing 10-second wait, while every usage fact starts another cleanup transaction. Add bounded recovery around audited native storage operations and reduce maintenance writes.

Related to #162. This is a contention mitigation; the production outcome is still unconfirmed. #162 remains open pending validation on the reporter's original Linux workload.

  • Scope native busy waits to 25 ms per SQLite call, then retry eligible storage operations with asynchronous jittered backoff within a 30-second budget. Preserve the original connection timeout outside those calls.
  • Serialize writes by database path within the process, preserve ordering within each priority class, and let pending conversation writes proceed between usage retries. Closing a store cancels its own queued writes and backoff.
  • Preserve native transaction ownership and rollback. Retry only audited rollback-safe or ID-idempotent operations; keep model requests and completed tools outside the retry boundary.
  • Check automatic usage cleanup at most once per connection every five minutes and skip its transaction when no rows are expired. Defer busy cleanup without failing a committed usage fact; retain explicit cleanup requests and the 30-day retention policy.
  • Install the bridge after both migration paths through a required, idempotent runtime patch. Reject changed or partial patch boundaries and document the recovery scope.

Validation completed locally on macOS:

  • Type checking; 673 unit tests, 33 runtime integration tests, and 51 TUI tests passed, along with terminal smoke checks.
  • Final Node 26.4.0 SQLite suite: 20 tests passed. Suite and follow-up regression checks also passed on Node 22.19.0 and 24.21.0.
  • Twelve processes persisted 300 input promotions with matching messages, parts and usage records; integrity and foreign-key checks passed.
  • Verified recovery after a 10.5-second lock, partial-write rollback, ordered updates, externally owned transactions, cancellation, and preservation of non-BUSY failures and non-idempotent counters.
  • With expired usage present, 100 usage writes required one cleanup transaction instead of 100.
  • Locked Desktop 3.14.3/runtime 0.16.9 synchronization, runtime/package validation, and npm tarball installation smoke passed.

Synchronous workflow-journal and permission-mode APIs retain their native behavior. Non-idempotent counter operations are ordered but are not replayed. There is no database schema change or sharding; sustained contention can still exceed the budget. Hosted Linux CI and reporter validation are still required before judging the production outcome.

Related to #162. Keep the issue open pending validation on the original workload.
@pkg-pr-new

pkg-pr-new Bot commented Sep 26, 2026

Copy link
Copy Markdown
npx https://pkg.pr.new/zcode-app-cli@29b543f

commit: 29b543f

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