Skip to content

Evaluate native SQLite persistence #22

Closed

Description

@Igloczek

Parent

Native Bun APIs: measure and selectively migrate runtime boundaries (#18)

What to build

A measured decision for the shared core/plugin SQLite client that preserves durable history, atomic command/event persistence, and reliable concurrent server/CLI access. Adopt a native driver only with qualifying evidence and the full existing observable SQL contract; otherwise retain the working binding with a durable reason.

Ticket-definition review completed on 2026-10-08: Claude Opus 5.5 agrees this ticket is ready for agent implementation with no remaining blockers. Separate review thread. The completed-work review below remains required after execution.

Acceptance criteria

  • Begin after the HTTP/file phase. Use Baseline and profile native Bun opportunities #19's preregistered persistence workload/metric, refreshed on the latest accepted source/archive baseline. If triage was retained/inconclusive and no change has since been accepted, cite that evidence and record retained without re-measuring. After an accepted HTTP, file, or process change, rerun persistence attribution itself before prototyping, not just baseline numbers. An added workload needs a declared reason before measurement and cannot override a nonqualifying unchanged baseline. No unmeasured or sub-5%-cost prototype is allowed unless a Bun-specific incompatibility is reproduced.
  • If retained/inconclusive, land no production changes or preparatory refactors. For an eligible candidate, provide one path/config-parameterized SQL-client constructor from the production entry to core persistence path/config constructors, server composition, project/environment-auth CLI composition, and fork-owned plugin catalog/private-database construction. Do not pass one prebuilt database layer to dynamically named plugin databases or leave a production-reachable compatibility default. Keep Bun-only imports entry-bound; memory/replay and direct compatibility-client Node tests remain their test composition. Any needed shared test/consumer edits count in the rehearsal; broad rewrites require retention.
  • Preserve execution/result modes, raw write results, boolean bindings, safe integers, transformed rows, bounded/time-limited successful statement caching, failed-prepare eviction/recovery, and classified SQLite failures. Prove the parent's preserved client-contract modes in the shared Bun fixture; modes used only in tests or retained compatibility tools do not need separate archive-level workloads. A blind reference swap is insufficient: raw writes, unprepared statement caching, and driver-owned WAL/busy setup differ from the current client.
  • Preserve the persistence layer's redacted canonical SQLite error detail and numeric condition, without exposing driver messages or SQL text. Normalize native errors in the fork-owned adapter instead of changing the upstream-shared formatter, and assert this behavior in the Bun contract fixture.
  • Prove writable immediate transactions, read-only client-contract behavior, rollback/failed-commit recovery, savepoints, contending writers, and existing owner-controlled WAL/foreign-key/busy setup. Preserve each core/catalog/plugin database's current journal/durability policy rather than applying the reference driver's WAL setup everywhere. Core events, projections, command receipts, and outbox effects commit atomically; plugin databases keep independent transactions and recovery.
  • Prove existing schema/history and replay remain usable across restart in the source/archive environment harness. Reuse failed-commit/rollback and event-sink atomicity assertions in a Bun subprocess with the real native layer, rather than inventing an archive fault-injection system. In-process workers may be drained; archive processes are observed through persisted milestones, never sleeps. Include an actual archive server and current-build project CLI writing concurrently to prove cross-process contention. No domain schema, persisted serialization, or database-format migration is allowed.
  • Audit database ownership by underlying file/inode: different bindings never concurrently open the same file in one process unless shared library/locking state is proven. Sequential close-before-open initialization, distinct external-provider usage files, and separate-process state/copy tools stay compatible. Bun comparison fixtures use each variant's own binding for same-process contention.
  • Reuse the actual Bun SQL contract fixture and observable core/plugin integration assertions under Bun, not Node-suite success as proof of native behavior. Obtain source and actual archive parity on all three existing targets; identify emulation and any gaps.
  • Pass the parent's two-batch adoption and regression gates and same-input upstream-sync rehearsal covering all changed shared construction/consumer/test sites. Record current-baseline identity, per-build results, CPU resolution, RSS/footprint/heap distinctions, and attribution limits. Record SQLite version, compile options, and effective synchronous/journal settings per binding/target/build to identify engine/config differences; resolve them before crediting a gain to the API. Incompatibility fixes still need regression evidence; uncertainty or missing platforms prevents adoption.
  • Accepted code has one production backend and a narrow fork-owned adapter, with no public selector or recurring upstream repair procedure. Update only durable runtime/sync constraints; keep the current wire/auth/features, supported distribution, Node contributor toolchain, and lightweight CI. Record evidence/artifact links on this ticket.
  • Run this ticket's candidate evaluation sequentially against the current accepted baseline; it has no dependency on the subprocess ticket. Refresh measurements after any preceding accepted change instead of combining unrelated optimizations into its claimed benefit.
  • Have the completed decision and any implementation/evidence verified by Claude Opus 5.5 in a fresh separate T3 thread; record its link and resolve blocking findings before completion.

Blocked by

Activity

  1. added
    ready-for-agent
    on Oct 8, 2026
  2. Igloczek commented on Oct 9, 2026

    @Igloczek
    Author

    Program progress: execution started (2026-10-09)

    Status: evaluating

  3. Igloczek commented on Oct 9, 2026

    @Igloczek
    Author

    #22 outcome: retained (no production changes; stack layer omitted, no PR)

    Completed-work review: fresh Claude Opus 5.5 / Gilfoyle thread mcp:4b06e343-8953-45e3-b7c5-17b764f2d5b1 . The reviewer independently re-ran the pilot twice and verified the engine metadata. Round 1 required a reopen trigger. Round 2 verdict: VERDICT: AGREE — all #22 acceptance criteria satisfied for a retained decision. Final secret gist revision: 3561fdc9.


    #22 execution outcome: retained — no actionable native SQLite benefit

    Versioned secret gist: 3561fdc9a784e95abd042d36db3a9fb13907f6a5 (public=false), all 22 downloaded files verified byte-identical to the publication payload, with all 21 manifest hashes matching. No production/refactor changes, commits or PR. The independent Opus reviewer accepted retention and requested documentation corrections; this revision addresses them.

    Artifact navigation: report.md contains the decision, preregistration hash/time, all pilot and inherited D1 run tables, per-form gate status, complete gaps and process audit; engine-metadata.json contains both full option lists and effective/default pragmas; pilot-results.json has every measured run; measurement-input-checksums.json and provenance-verification.json identify the pre-attested measurement tooling. Public replay/capture tools and the redacted fixture are included, with portability/redaction differences disclosed. Local raw inputs/logs are withheld.


    #22 outcome: retained — no actionable native SQLite benefit

    No production/preparatory changes, no full adapter, no commit, no PR. Retention follows parent spec #18: evaluate a replacement only for a demonstrated incompatibility or actionable measured cost; retain when there is no actionable problem, and land no production or composition changes for a retained candidate. #19 already established eligibility (26.449% source / 20.923% archive); attribution was not remeasured. Eligibility is permission to evaluate, not evidence of removable binding cost. #20 retained and #21 inconclusive left d5cee2d / Bun 1.4.2 unchanged.

    Decision and limits

    The decisive feasibility argument is the compatibility range: even removing all #19-attributed synchronous SQLite work, 37.922 ms source / 38.244 ms archive, is smaller than the historical end-to-end D1 compatibility ranges, 74.228 / 67.126 ms. On the measured macOS arm64 source runtime, both bindings use SQLite 3.54.0 with the same source ID and all 73 compile options, so changing the API offers binding-overhead removal, not a different engine. That makes complete removal of engine-plus-binding work an intentionally generous screening assumption. These attributed unions came from separate instrumented runs, not the timed baseline launches: this supports retention under the current evidence and gates, not a universal mathematical ceiling or a claim about unmeasured engines. See #19 baseline evidence.

    The worker's separate-process D1 replay has compatibility median 42.868 ms [30.965, 49.767], range 18.802; native 36.359 ms [32.047, 45.476], range 13.429. Its node−bun median difference +6.509 ms is a noisy point estimate, not a bound; paired round differences are +17.720, −3.261, +6.004, +6.509, −3.064 ms. The independent reviewer's two re-runs of the unchanged, pinned Bun 1.4.2 pilot give −0.993 ms / +1.313 ms (node−bun; positive favors bun). Their medians, ranges and all ten wall values per batch are in reviewer-rerun-summary.json, recomputed from the saved reviewer outputs without launching anything. These sign-changing deltas do not establish a stable actionable binding gain. The pilot and reviewer re-runs are feasibility evidence only, not end-to-end adoption batches or native contract proof. There is no reproduced node:sqlite incompatibility.

    #19's Reports-resolve 29.0% / 35.7% source/archive fractions do not change the decision: they include engine work, source's entire 2.209 ms SQLite union is below its 5.069 ms compatibility range, archive would need more than half of its 3.778 ms union removed to exceed its 1.897 ms range with no such binding-only gain demonstrated, and #22 AC1 keeps D1 as the adoption metric.

    Reopen trigger: Reopen if a Bun pin makes node:sqlite and bun:sqlite differ in SQLite source ID or compile options on a supported target; on a reproducible node:sqlite incompatibility; or when a fresh D1 or D2-resolve compatibility batch has max−min range below its attributed synchronous SQLite union and a separate-process replay shows a binding delta ≥5% of the end-to-end compatibility median. D2 may motivate reopening, but cannot replace D1 under #22 AC1. A reopened candidate must establish catalog owner policy first, then satisfy the parent's parity, two-batch benefit/regression, supported-target and upstream-sync gates before adoption. No Linux/storage claim is made.

    Preregistration and identity

    Preregistration SHA-256 ddbf86b2402c997018b1c30f5222c8955b9e248c1425b78133dea05521eea253, UTC 2026-10-09T00:02:17.698279+00:00. Original preregistration remains immutable. Capture clarification records the disposable preload corrections before pilot execution; it excludes setup/auth work, while retaining the 100 auth reads that belong to D1 itself.

    Revision d5cee2d8faed9d4923af4f59fdfa7e81009c880c, branch native-bun/sqlite, origin/main identical. Pinned/installed Bun 1.4.2. Native macOS 27.0.1 build 26A434, Darwin 27.0.0, arm64 Apple M1. pnpm lock SHA-256 0481f1411a5b808e3434eea352eac2458a3300119ccfc220432c8c2dd9feb4ee. No upgrades. Input seed SHA-256 12d140b45bd4df41c58abcf4c74dea31307755bf01d38c97ffc05866129f464e, trace bc8317549120b8e895adadd9db7767c0636ad72e0f9051666061c0d662302d06, actual replay script 58c6746d1e55034bdc9d00dc7686ffb456e7bc174d8940e2ef87b4d37a14cbeb, batch producer fbdba635df675003fbaafd8457dc99e2d04676d81253373556cc572874d49c4f.

    Method and observed behavior

    A fresh compatibility source server copied #19's fixed synthetic fixture (4 projects, 32 stopped threads, 2048 synthetic projection messages; no active work) and drained the exact D1 workload: 100 sequential authenticated project.update calls, same command IDs and alternating titles. Same-binding VACUUM INTO captured a consistent ready-state core snapshot before D1. The server shut down before pilot launch. SQL trace contains 1100 successful executions, 9 distinct prepared SQL strings: 100 auth reads, 400 project reads, 100 BEGIN IMMEDIATE, 100 receipt reservation INSERT RETURNING, 100 event INSERT RETURNING, 100 project projection upserts, 100 receipt upserts, 100 COMMIT. Outbox writes are absent from this project-only D1 mix; no new outbox assertion is claimed.

    Five rounds alternate node/bun then bun/node. Every variant is a fresh Bun subprocess with a fresh seed copy; no process opens one file using two bindings. Prepared successful statements use a capacity-200 cache; total replay is far below ten-minute TTL. Booleans normalize to integers; integer/result settings follow the captured SQL modes. Timed wall interval includes lookup/prepare, binding, SQLite execution, parameter normalization, result collection and timing bookkeeping; open/config/integrity/close are outside it. This is a disposable direct-binding replay, with no Effect/client/HTTP overhead, no profile, no forced GC and no idle window. Transaction tails measure BEGIN-through-COMMIT, not full request tails.

    The pilot caches BEGIN IMMEDIATE and COMMIT along with ordinary statements. Production does not set prepareTransactionControls, so Effect sends those controls through executeUnprepared and the shared client prepares them on each execution (shared client). The reviewer bounded the omitted control preparation/reader-discovery cost from #19 spans at approximately 0.94 ms (0.887 ms prepare + 0.054 ms columns()); this is a historical bound for this mismatch, not a new measurement or a correction applied to pilot timings. Even allowing that whole amount as removable overhead cannot bridge the D1 range gap or change retention.

    All ten read-result digests match db780b5931d6fc77525cdb76d7eea0e6507022ade8be85d92698d66c69c88bd5. Each retains 100 immediate transactions and commits, event/receipt rows 36→136, final title Synthetic title 1 and integrity_check=ok. This validates this SQL mix and final counts; it does not prove complete client/core/plugin atomicity/replay/locking parity. Same-process contention, rollback, savepoints, raw write result shape, failed-prepare cache recovery and full canonical native error normalization were not evaluated by this pilot.

    Pilot per-run values (ms, feasibility only)

    Round Binding PID Replay wall Transaction p50 p95 p99 max
    1 node 3753 49.767 0.154 1.384 7.628 7.687
    1 bun 3807 32.047 0.153 0.459 4.437 5.195
    2 bun 3871 34.225 0.154 0.420 3.163 5.700
    2 node 3996 30.965 0.150 0.244 3.850 5.235
    3 node 4052 46.351 0.182 1.119 3.033 4.792
    3 bun 4155 40.347 0.166 0.950 3.719 5.494
    4 bun 4281 36.359 0.193 0.463 2.836 3.971
    4 node 4413 42.868 0.189 0.766 2.152 8.094
    5 node 4585 42.412 0.227 0.753 3.101 4.378
    5 bun 4788 45.476 0.253 0.785 2.173 5.323
    Binding Replay median min max full range
    node:sqlite 42.868 30.965 49.767 18.802
    bun:sqlite 36.359 32.047 45.476 13.429

    Inherited #19 end-to-end D1 baseline (not new measurements)

    Form Round Batch wall Request p95 p99 max
    source 1 153.584 2.482 7.239 10.144
    source 2 141.186 1.870 7.951 9.312
    source 3 215.414 3.870 11.055 12.871
    source 4 150.647 2.341 7.368 8.165
    source 5 167.657 2.867 12.150 12.284
    archive 1 132.727 1.901 6.628 7.991
    archive 2 191.299 2.860 8.033 9.106
    archive 3 179.672 3.186 8.025 9.904
    archive 4 124.172 1.779 5.346 6.737
    archive 5 162.810 3.072 10.021 10.149
    Form Historical median [min,max] ms Range ms #22 adoption/regression verdict
    source 153.584 [141.186,215.414] 74.228 Not evaluated; early retained before full adapter
    actual archive 162.810 [124.172,191.299] 67.126 Not evaluated; early retained before full adapter

    No first or second adoption batch, startup/60s idle CPU/RSS/footprint gates or end-to-end tail regression comparisons were run. Historical numbers do not substitute for fresh two-batch evidence. CPU resolution from #19 is nominal 41.6667 ns per Mach tick; effective accounting accuracy was unresolved. This pilot uses monotonic wall milliseconds only. RSS, physical footprint and JS heap were not sampled; they are distinct quantities and no memory/CPU benefit is claimed.

    SQLite engine and owner policy

    Both source-interpreter bindings report SQLite 3.54.0, source ID 2026-04-09 12:25:13 8fa8248e303219400c646a885e36dfc52eae33d83f4412e3f369b2be5373aapl, and identical 73 sorted compile options. Full options are in engine-metadata.json; canonical compact-JSON option-list SHA-256 71d63d9a75885c21c63c7a2cbeab0530690700f9fdb8e31b174fd6a249b2c446. Engine identity is proven only for macOS arm64 source; actual archive and Linux engines were not measured and may differ. The source ID ending in aapl may indicate Apple system SQLite; that is an inference, not archive/Linux evidence. Matching IDs/options do not prove shared in-process locking state.

    Binding/target/build Default journal/sync/FK/busy/limit Effective core journal/sync/FK/busy/limit
    node:sqlite / macOS arm64 / Bun source pilot delete / 2 / 1 / 0 / 32768 wal / 2 / 1 / 5000 / 33554432
    bun:sqlite / macOS arm64 / Bun source pilot delete / 2 / 0 / 0 / 32768 wal / 2 / 1 / 5000 / 33554432
    actual archives / Linux targets Not measured in #22 Not measured in #22

    The snapshot produced by VACUUM INTO starts in DELETE mode. Owner setup restores WAL, FK ON, busy 5000ms, journal limit 32MiB, with synchronous FULL (2) left at existing default. Binding foreign-key defaults differ: node:sqlite ON / bun:sqlite OFF. Existing core owner policy resolves that difference, and plugin private databases own WAL/FK/busy setup. In contrast, catalog.sqlite has no owner pragmas: PluginRegistry.ts constructs the client and creates manifests without explicit journal/sync/FK/busy policy. The manifests schema currently has no foreign keys, so the FK default difference has no effect there today; any reopened candidate must establish explicit catalog owner policy first. Neither plugin path was changed or benchmarked, and the pilot's core pragmas must not be generalized to the catalog.

    Platform matrix, rehearsal and preservation

    Target Source evidence in #22 Actual archive evidence in #22
    macOS arm64, native D1 functional capture + separate-binding feasibility replay; unchanged compatibility suite Not run; #19 compatibility baseline inherited only
    Linux arm64 Not reached after early retention Not reached
    Linux x64, would be emulated on M1 Not reached; no emulated performance claim Not reached

    Full native adapter parity, restart/replay, plugin independence, archive-server/current-build project-CLI contention and file/inode ownership audit were not run. Narrow pilot ownership is enforced by separate subprocesses/files and server-close-before-replay. Production binding remains unchanged. Linux was not pursued because macOS feasibility stopped the candidate, not because of a reproduced disk/storage blocker; OrbStack/Docker were never started.

    No candidate changed shared construction/consumer/test sites, so a baseline/candidate upstream-sync rehearsal would be a no-op and was not performed. No new preservation rule is warranted. Existing runtime/sync rule remains: retain working compatibility APIs, SQLite boolean normalization, owner-controlled journal/FK/busy policies, one shared Effect context and fork distribution/web-only scope. No durable schema/format/serialization, runtime option, upgrade/recovery or CI change.

    Verification, commits and artifact provenance

    • Documentation revision only: saved reviewer re-run outputs were read and cross-checked; no new measurements, servers, contract tests or fixture executions. Original preregistration, raw measurements and measurement-time tooling remain unchanged.
    • Actual D1 capture: 100 drained successful mutation responses; 100 immediate commits observed.
    • Ten separate-process replay runs: all result digests, final counts/title and integrity checks match.
    • bun --bun node_modules/vite-plus/bin/vp test run packages/shared/src/nodeSqliteClient.test.ts: 1 file / 10 tests passed, temporary state in ticket scratch. This is unchanged compatibility evidence, not native parity proof.
    • Every recorded pilot prelaunch input hash still matches. Capture-original and intermediate tooling were reconstructed byte-for-byte and independently match their prelaunch hashes. Original capture's supervisor exit 1 came from preload executing on an unconfigured supervisor at exit; its server completed normally. The second capture completed but omitted server preload after a label rename. Both are excluded; only the final attested trace/seed feeds the pilot.
    • Public seed/replay tooling also passed one functional smoke per binding in separate subprocesses with matching redacted result digest; their timing is excluded from pilot/adoption evidence.
    • No tracked edits; targeted changed-file lint/typecheck is not applicable. No repo-wide checks or browsers.
    • git log --oneline origin/main..HEAD: empty. Diff summary: zero tracked files changed. git status --porcelain=v1: empty.

    Local material remains under the ticket #22 scratch directory; measurement-input-checksums.json and per-launch attestations identify exact local producers. Public pilot.mjs, capture.mjs and capture-preload.cjs are byte-identical to their final measurement-time versions. Public runtime.mjs replaces only local executable/repo/archive paths with environment configuration. Public portable batch/capture/seed materials are redacted or adapted replay tooling and are explicitly not original measured bytes. seed-redacted.sql has only the four used table schemas/indexes and sanitized synthetic rows, with synthetic auth identity; it omits unused tables/pages, so it cannot reproduce historical timings. d1-trace-redacted.json preserves SQL operation order/counts/modes, but replaces private paths and the disposable session ID. Generated replay digests consequently differ from the recorded private-input digest. No raw DB, secret, token, pairing URL, raw server log or local private path is published.

    Process/container audit and explicit gaps

    Capture source servers 58953, 63764, 96226 all stopped via captured PID with normal SIGTERM path exit 130. Supervisors 58952 (exit 1), 63745 and 96195 (exit 0) completed. Pilot PIDs 3753,3807,3871,3996,4052,4155,4281,4413,4585,4788 all exited 0. Focused test supervisor 30705 exited 0; public-tool QA supervisors 66030, 67078, 67086 exited 0; worker/helper descendants are owned/awaited by their fixture, not exhaustively PID-journaled. No captured process remains running. No containers/images/VMs created, started or removed. No process killed by name/pattern. No live T3 userdata was read or written.

    Explicit outstanding gaps: full adoption/regression batches, full native SQL contract/core/plugin integration, actual archive/native and Linux evidence, complete mixed-binding inode audit and non-no-op upstream rehearsal are absent because the early retained route stopped implementation. The independent Claude Opus reviewer accepted the retained decision and requested documentation corrections; this revision addresses those findings. Retention is a valid execution outcome.

    Model/harness: GPT-6.1-Sol, high reasoning, Codex in T3 Code.

  4. Igloczek commented on Oct 9, 2026

    @Igloczek
    Author

    Closing: retained decision; acceptance and completed-work Opus review gates passed (see results comment above). No repository changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ready-for-agent

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions