Skip to content

Decide the runtime story: Bun-only engine versus a Node-compatible store #612

Done

Description

@ocsi-architect

Question

Do we intend to support Pi on Node at all, or is Bun a stated requirement we own? Both answers are defensible. Shipping a front-page adapter that only loads on a runtime the host does not use, with no launcher to bridge it, is the one answer that is not.

This ticket is a decision with a measured cost attached, not an open-ended port.

Measured surface

Counted across src/ on main:

Dependency Uses Note
bun:sqlite 1 file src/store/lock.ts — this is the store's locking correctness mechanism: BEGIN IMMEDIATE, PRAGMA busy_timeout, journal-mode handling. Not an optimization to drop.
Bun.file 8 reads in load, gate, init, startup, viewer, commands
Bun.write 7 publication paths
Bun.Glob 6 day-file discovery and gate matching; comments in src/gate/resolver.ts already say a replacement must match Bun.Glob
Bun.spawnSync 4 git probes and host capability probes
Bun.version 1 startup telemetry
Bun.serve 1 the browser viewer, optional surface

The TypeScript entry point is not the obstacle: Pi loaded .ts under Node without complaint, which is why the failure in #610 is our own message rather than a syntax error. The file and process primitives are mechanical. The decision is sqlite.

Options for the locking layer

  1. node:sqlite — no dependency, but Node 22.5 or newer. The seat used to test this runs Node 20.20.2, so a large share of users would still be locked out, and we would be trading one runtime requirement for a version floor.
  2. better-sqlite3 or similar — broad Node coverage, but a native dependency with prebuilds for every platform we claim, and its own install failure modes. We would be removing one install cliff by adding another.
  3. Bun required, owned — keep bun:sqlite, and ship the launcher in No launcher artifact: Pi with memory needs a hand-assembled Bun command every session #611 so the requirement is satisfied for the user rather than explained to them. Cheapest path to a non-broken experience; costs us the "works anywhere Node runs" reading of the portability claim, so the docs must say it out loud at the point of use, not only in README.pi.md.

Acceptance

Non-goals

Not a port of the viewer, and not an argument about which runtime is better. The only question is what a person who installs this package into Pi can be promised.

Activity

  1. added
    severity:high
    proposal
    on Nov 29, 2026
  2. ocsi-architect commented on Nov 29, 2026

    @ocsi-architect
    Author

    Measured option 1, so the decision can be made on numbers rather than on the Node 22.5 date.

    On this machine's two Node installs, same BEGIN IMMEDIATE / PRAGMA busy_timeout = 0 sequence src/store/lock.ts uses, and two processes racing one database file:

    Runtime Module loads Contention result
    Node 20.20.2 no — ERR_UNKNOWN_BUILTIN_MODULE n/a
    Node 22.23.4 yes (node:sqlite, emits an experimental warning) second writer refused after 1 ms
    Bun (current) yes (bun:sqlite) second writer refused after 0 ms, database is locked

    So the mutual exclusion is real under node:sqlite, and option 1 is viable at the level that matters: the lock still locks, it does not silently degrade into a per-process advisory. journal_mode reads back delete, matching what the module sets explicitly.

    The work is not swapping the import. Node reports refusal as ERR_SQLITE_ERROR where Bun reports database is locked, and src/store/lock.ts classifies waits by driver codes (the comment near its error helper notes SQLITE_BUSY versus the extended name, because comparing against the plain code mis-sorts BUSY_RECOVERY and friends). A port has to map error identity per driver, and the tests that assert the reported reason must stay byte-identical — a changed assertion there means the driver is wrong, not the test.

    Cost is therefore: one driver seam plus error-identity mapping, against a hard Node 22.5 floor that excludes the Node most people still have — the machine used to test Pi support is on 20.20.2. That makes option 3 (own "Bun required", bridge it with #613) the cheaper promise to keep honest, and option 1 the better one if we are willing to publish a floor. What we cannot keep doing is the current state: a front-page adapter claim whose runtime constraint is stated only in README.pi.md.

  3. ocsi-architect commented on Nov 29, 2026

    @ocsi-architect
    Author

    Correction to my earlier comment. I wrote that option 1 "excludes the Node most people still have", using this test machine's Node 20.20.2 as the reference. That was the wrong reference, and the ticket owner should not weigh it.

    Pi's own manifest says otherwise:

    Declared by Engines
    @earendil-works/pi-coding-agent 1.7.0 (installed here) node: >=22.19.0
    @earendil-works/pi-coding-agent latest on npm node: >=22.19.0
    @oh-my-pi/pi-coding-agent 19.2.1 bun: >=1.4.4
    this package bun: >=1.3.0

    node:sqlite stopped needing --experimental-sqlite in Node 22.13.0 and 23.4.0 (Node's own compatibility table). So every Node version Pi itself supports already has node:sqlite unflagged: option 1 adds no floor at all for the host this whole thread is about. It removes the requirement, which is better than bridging it.

    This machine's Node 20.20.2 is not a counterexample — it is running Pi outside Pi's declared range, which is why the pi shim works at all.

    Re-scoped the port cost to the graph a Pi session actually loads, rather than all of src/: walking imports from src/adapters/pi/extension.ts reaches 131 files, with no .tsx anywhere in it, one bun: module (bun:sqlite), and 22 Bun.* sites — Bun.file 6, Bun.write 5, Bun.Glob 6, Bun.spawnSync 4, Bun.version 1. TypeScript is not an obstacle either way: Pi's extension loader parsed our .ts entry point under Node 20, so the message in #610 was ours and not a syntax error.

    Two API details the port has to carry, from the same compatibility table: DatabaseSync is the only export from 22.13 through 26.10, with Database added in 26.11, so the import needs Database ?? DatabaseSync rather than either name alone; and Node reports a refused lock as ERR_SQLITE_ERROR where Bun says database is locked, while src/store/lock.ts classifies waits by driver code, so that mapping is part of the work, not a follow-up.

    Revised recommendation, which reverses mine: make the store runtime-neutral (option 1) as the durable fix, and keep #613 as the install-and-diagnose surface rather than as the thing that papers over the runtime. #610 still ships first either way, because it is five lines and it stops the host refusing to start today.

  4. ocsi-architect commented on Nov 29, 2026

    @ocsi-architect
    Author

    Scoping for the implementation, from the branch that fixes #610 (f6a3337), plus the one unknown that turned out fine.

    Error identity is not a blocker. Node exposes the extended SQLite result code on the exception, so src/store/lock.ts can keep classifying by code rather than by message. Forcing a second writer against a held BEGIN IMMEDIATE on Node 22.23.4:

    keys: ["code","errcode","errstr"]
    code: ERR_SQLITE_ERROR | errcode: 5 | errstr: database is locked
    message: database is locked
    

    errcode: 5 is SQLITE_BUSY, and because it is the extended code the existing distinction between plain busy and BUSY_RECOVERY-style variants survives; Bun's driver already exposes errno. So the seam needs { run, get, close } plus a busy classifier over errcode/errno, and nothing has to parse text.

    The port is 22 sites in 13 files, not 1. Walking the imports a Pi session loads, bun:sqlite appears once (src/store/lock.ts), and these are the rest:

    Sites File
    4 src/gate/resolver.ts
    3 src/store/files/load.ts
    2 src/core/logfmt/publish.ts, src/store/undo.ts, src/init/detect.ts, src/capture/available.ts
    1 src/identity/repokey.ts, src/core/permissions.ts, src/runtime/setup.ts, src/runtime/startup.ts, src/store/files/snapshots.ts, src/status/payload.ts, src/capture/triggers.ts

    By API: Bun.file 6, Bun.Glob 6, Bun.write 5, Bun.spawnSync 4, Bun.version 1. So a sqlite-only change would not make Pi load: the engine would still throw on the first Bun.file. The work is one small host-io seam (read, write, glob, spawn, version) threaded through those 13 files, plus the driver seam.

    The risk that decides the order of work is glob semantics, not sqlite. src/gate/resolver.ts comments already say a replacement must match Bun.Glob, and gate matching decides which memories a project sees. So the first artifact should be a differential test that runs both glob implementations over the day-file and gate patterns — real store trees, not hand-written fixtures — and fails on any divergence. Same for spawnSync: src/identity/repokey.ts derives the repo key from git remote get-url origin, so a mismatch there silently re-keys every project's memories. Both of those are correctness, not plumbing, and they need to be pinned before the seam is threaded, not after.

    Nothing here changes the merge condition in the ticket body: store-concurrency, lock and publication tests stay untouched and green, and a test edited to accommodate the new driver means the driver is wrong.

  5. abogartz-opencode-self-improvement commented on Nov 30, 2026

    @abogartz-opencode-self-improvement

    🎉 This issue has been resolved in version 0.41.0 🎉

    The release is available on:

    Your semantic-release bot 📦🚀

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

    proposalreleasedseverity:high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions