Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(sqlite): retry failed statement preparations #10584

Mergedyashranaway(GitHub profile, opens in a new tab)merged 2 commits intomain fromrefs/pull/10584/headmerged by shivamhwp(GitHub profile, opens in a new tab) View on GitHub

What Changed

SQLite caches successfully prepared statements for the configured lifetime, but expires failed preparations immediately. A later query can retry after the database becomes available without recreating the client.

Why

The prepare cache retained failures for ten minutes by default. A query that initially failed because a table was missing or another connection held an exclusive lock continued returning its cached error after the condition was resolved.

Testing

  • The missing-table regression fails on upstream even after creating and populating the table.
  • A real temporary SQLite database verifies positional and object queries recover immediately after an exclusive lock is released.
  • All 16 focused shared-client and server persistence tests pass across three suites.
  • Shared-package typecheck, scoped lint, and formatting pass.
  • No live database access, frontend changes, or browser verification.

Model: GPT-6 Astra Harness: T3 code

Note

Fix retry of failed statement preparations in 'nodeSqliteClient'

  • Failed statement preparations were previously cached for the configured TTL in nodeSqliteClient.ts, preventing retries after the underlying issue resolved.
  • The makeWithDatabase client factory now passes the prepare function through Cache.makeWith. Successful preparations keep the configured TTL, while failed results use a zero TTL to allow retrying.
  • Added tests covering query reuse after a missing table is created and after an exclusive database lock is released.
  • Risk: Behavioral Change: failed prepare results in nodeSqliteClient no longer remain cached, so later query executions will re-attempt the prepare step rather than returning the cached error.
Macroscope summarized 0c63948.

Summary by CodeRabbit

  • Bug Fixes
    • SQLite queries can be retried successfully after a temporarily missing table is created.
    • Queries affected by an exclusive database lock can recover once the lock is released.
    • Failed query preparations are no longer cached, preventing repeat failures after database conditions change.
    • Successfully prepared queries continue to be cached for the configured duration, preserving the performance benefit for subsequent executions.
    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    2. Approvability

      Verdict: Approved at 0c63948

      Macroscope's review found this PR approvable — This is a focused SQLite cache bug fix that evicts failed statement preparations immediately while preserving the existing successful-query cache policy. The accompanying tests cover recovery from missing schemas and released database locks, with no schema, API, security, or deployment changes.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    3. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →

      Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

      No actionable comments were generated in the recent review. 🎉

      ℹ️ Recent review info
      ⚙️ Run configuration

      Configuration used: Repository: pingdotgg/t3code/.coderabbit.yaml

      Review profile: CHILL

      Plan: Advanced

      Run ID: efa3b170-6deb-4ec1-bfbb-716551ec38a8

      📥 Commits

      Reviewing files that changed from the base of the PR and between 0c63948f5de2a96e656792aedeefe8d5974849a6 and 004f2e83a02e5e4eabefc6993e53024db05c4821.

      📒 Files selected for processing (2)
      • packages/shared/src/nodeSqliteClient.test.ts
      • packages/shared/src/nodeSqliteClient.ts

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


      📝 Walkthrough

      Walkthrough

      The SQLite client now expires failed prepared statements immediately and retains successful preparations for the configured TTL. Integration tests cover recovery after table creation and lock release.

      Changes

      SQLite preparation recovery

      Layer / File(s)Summary
      Preparation cache behavior
      packages/shared/src/nodeSqliteClient.ts
      The prepared-statement cache uses Cache.makeWith. Successful preparations use the configured or default ten-minute TTL. Failed preparations receive a zero TTL.
      Preparation recovery tests
      packages/shared/src/nodeSqliteClient.test.ts
      Integration tests verify typed preparation errors and successful re-execution after a missing table is created or an exclusive database lock is released.

      Priority: ⬇️ Low

      Estimated code review effort: 2 (Simple) | ~10 minutes

      Change: Bug fix

      Suggested reviewers: juliusmarminge

      Merge Risk: ⚪ Minimal · up to 004f2

      No identified issue prevents merging after normal checks.

      Security Architecture Review

      Security architecture risk: 🔵 Low · up to 004f2

      The change lets queries retry after a temporary SQLite preparation failure without adding an external entrypoint or changing database permissions. Behavior under simultaneous or sustained failures remains less certain.

      Retained concerns No architecture-level concerns identified.

      Security review details

      Security Blast Radius

      • inferred — The changed cache remains connection-local; the examined change does not introduce a cross-connection cache or a production entrypoint. Downstream caller exposure was not established.

      Resilience and Maintainability Implications

      • inferred — Zero-TTL failures permit later retry rather than retaining a transient error. The available evidence does not establish how concurrent lookups or interruption interact with eviction, so it does not establish a security-relevant failure path under those conditions.
      🚥 Pre-merge checks | ✅ 5
      ✅ Passed checks (5 passed)
      Check nameStatusExplanation
      Title check✅ PassedThe title clearly and concisely describes the main change: retrying failed SQLite statement preparations.
      Description check✅ PassedThe description clearly explains what changed, why it changed, and how it was tested. The UI Changes section is not needed because the PR has no UI changes. The repository checklist is omitted, but th…
      Docstring Coverage✅ PassedNo functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
      Linked Issues check✅ PassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes check✅ PassedCheck skipped because no linked issues were found for this pull request.
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create a new PR

      Comment `@coderabbitai help` to get the list of available commands.

Sign in to join this conversation.