← Back to Pull requests

feat: CANT-191 — the catenary_client package, its SQLite binding and migrator, and the journal (CANT-42a) #127

Open
unknown opened this pull request with 573 lines diff across 7 files
View on GitHub
unknown unknown commented on Oct 04, 2026 01:27 UTC
Author

CANT-191 (CANT-42a, Mode A / evidence) — the floor the rest of the Dart client's protocol half stands on. Spec: the approved plan on CANT-42, rev 2, every ruling on option 0.

What is here

  • dart-client/, package catenary_client (ruling 0 → a sibling; nothing under dart/ is moved or edited). It depends on catenary_wire by path and on package:sqlite3.

  • lib/src/db.dart — the versioned open. PRAGMA synchronous = FULL on every connection, and an in-process migrator over PRAGMA user_version: numbered SQL steps, run inside one BEGIN IMMEDIATE, so a file is at a whole version or at the one before. catenary.db holds journal_meta, messages, conversations, users, counted and credential (ruling 1 → two files). Wire records are stored as the generated codec's JSON beside the columns the store queries by.

  • lib/src/journal.dart — Journal, StagedJournal and MemoryJournal, ported from web/src/transport/journal.ts: one copy of the rules, two commits.

  • lib/src/sqlite_journal.dart — SqliteJournal, ported from idb-journal.ts: one transaction per write, the mirror swapped only after COMMIT returns, the wipe (counted log included, a fresh generation stamped in the wipe's own transaction), and the JournalStale refusal with its reload. midWrite, splitCursor and ignoreGeneration are the reference's seam and negative controls.

  • lib/src/faults.dart — the switch list under the TypeScript names. The journal reads two of them here; the test that enumerates faults.ts against it is CANT-192's criterion.

  • verify.sh resolves, analyzes and tests the package inside the existing command -v dart guard; ci.yml resolves it. gen:check and the staleness-guard step are unedited.
  • The binding, proved first

    package:sqlite3 3.7.0 opens a file-backed database on this box: dart run, dart test and dart build cli all work, through the package's native-asset build hook, which fetches a prebuilt SQLite (3.53.4) rather than linking the system libsqlite3.so.0. dart compile exe is refused ('dart compile' does not support build hooks, use 'dart build' instead), so the driver in CANT-194 is built with dart build cli, which emits bundle/bin/<name> beside bundle/lib/libsqlite3.so. The package needs SDK ^3.10.0 for that reason, where dart/ says ^3.6.0. Whether it opens a file in CI is what this PR's own verify.sh run answers.

    Criteria (from the plan), and the test that holds each

    | criterion | where |
    |---|---|
    | No file under lib/ or bin/ imports package:flutter, dart:ui or a Flutter plugin; a test fails when one does; resolves and analyzes clean | test/source_test.dart, with the rule proved against planted imports and planted pubspecs; dart analyze in verify.sh |
    | [ruling 0 → 0] the package is at dart-client/, no path under dart/ moved, gen:check and the staleness guard pass unedited | the diff; verify.sh |
    | SqliteJournal opens a file-backed database, synchronous FULL, fresh file to current user_version, same journal tests as MemoryJournal | test/sqlite_journal_test.dart › the binding and the migrator; test/journal_test.dart runs every rule against both journals |
    | A wipe, in both journals; fresh generation, one transaction; counted once after a wipe; credential row unchanged | journal_test.dart (both); sqlite_journal_test.dart › obligation 4 |
    | Two SqliteJournal instances over one file | sqlite_journal_test.dart › two contexts, with ignoreGeneration as the control |
    | [ruling 1 → 0], the journal half | the journal and credential tables are in catenary.db and no outbox table is; source_test.dart fails if journal or transport code names the outbox's file. The wipe leaving outbox entries in place, and the outbox's side of the source-shape test, are CANT-196's |

    Two things that differ from the reference, on purpose

  • A wipe's count is the stored count plus one, read inside the wipe's transaction, where IdbJournal writes its mirror's count. With one writer they are the same number; with two contexts that each wipe once, the file says two.

  • The default rollback journal, not WAL, and a 2 s busy_timeout. The plan states synchronous = FULL and is silent on the journal mode; the default keeps the database a single file.
  • Verified

    ./verify.sh green locally with the database lane running (CATENARY_TEST_DATABASE_URL set): dart test (+40: All tests passed!).

    🤖 Generated with Claude Code

    Diff: 573 lines (+429 / -144) across 7 files Reviewer: github-actions[bot] Review duration: 4m
    All Vouch review confidence checks passed
    Residual risk 0.42 = Change Risk (0.50) × (1 − Review Confidence (0.17)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.50 · 573 lines diff across 7 files
    0.50
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 29% · Reviewer familiarity: 35%
    16%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.380
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #127"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: medium confidence: 16.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 49.8% (MEDIUM) · Higher = larger blast radius
    49.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 16.5% · Lower = rushed or shallow review
    16.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 41.6% · Moderate risk
    41.6%