2026-10-27: Fix desktop seed failure on upgrade (spawn tsx ENOENT)
Problem
Section titled “Problem”Upgrading Strata 1.5.X → 1.6.2 via npm run tauri:install on a second Mac fails at first launch:
❌ Post-install check failed: desktop backend on :3456 did not start.with popup:
Strata -- startup errorDatabase seed failed:prisma db seed exited with exit status: 1...An error occurred while running the seed command:Error: Command failed with ENOENT: tsx prisma/seed.tsspawn tsx ENOENTBecause the seed fails, the app calls process::exit(1) before spawning the backend, which cascades into the installer’s port-3456 and readiness-marker checks failing.
Root cause
Section titled “Root cause”The chain that breaks:
scripts/tauri-install.shlaunches the app withopen /Applications/Strata.app— LaunchServices gives GUI apps a strippedPATH(/usr/bin:/bin:/usr/sbin:/sbin).run_prisma_seed(src-tauri/src/lib.rs) executesnode <prisma-cli-js> db seedwith an absolute node (works —find_node()+ local CLI js, already hardened in commit3c710f8).prisma db seedre-spawns the configured seed commandtsx prisma/seed.tsfrombackend/prisma.config.tsvia PATH lookup (spawn, no shell).tsxlives atbackend/node_modules/.bin/tsx— not on the stripped PATH →spawn tsx ENOENT.
Reproduced locally on a scratch DB with PATH=/usr/bin:/bin:/usr/sbin:/sbin + absolute node:
Running seed command `tsx prisma/seed.ts` ...Error: Command failed with ENOENT: tsx prisma/seed.tsspawn tsx ENOENTThe migrate path (main.ts / run_prisma_migrate) was already made PATH-independent; the seed path was left on prisma db seed.
Decision
Section titled “Decision”Invoke the seed script directly, mirroring the migrate hardening:
- Resolve
backend/node_modules/tsxbin entry from itspackage.json(currently./dist/cli.mjs), with static fallbacks. - Run
node <tsx-cli-js> <backend>/prisma/seed.tswithcwd=backendand the same env (DATABASE_URL,STRATA_SEED_PROFILE). - No PATH lookup anywhere: node is absolute (
find_node), tsx CLI is an absolute path undernode_modules, seed script is an absolute path.
prisma db seed for human/terminal dev workflows (STRATA_SEED_PROFILE=development npx prisma db seed) is untouched.
Implementation plan
Section titled “Implementation plan”- Add tsx resolution helpers to
src-tauri/src/lib.rs(mirroring the existing prisma ones):tsx_package_dir/tsx_package_json_pathtsx_cli_js_candidates(backend_path)— readsbinfromtsx/package.json; fallbacksdist/cli.mjs,dist/cli.jsensure_tsx_cli_js(backend_path) -> Result<PathBuf, String>with the same error style asensure_prisma_cli_js
- Rewrite
run_prisma_seedto runnode <tsx-cli> <backend>/prisma/seed.tsinstead ofprisma db seed; keepDATABASE_URL+STRATA_SEED_PROFILEenvs, output capture, andResulthandling (popup text “Database seed failed:” unchanged). - Add a guard that fails startup with a clear message if
backend/prisma/seed.tsis missing. - Add Rust unit tests (
ensure_tsx_cli_jsresolves package.json bin; falls back; errors when missing). - Gates:
cargo testinsrc-tauri(baseline: 9 passed)cargo buildinsrc-tauri- End-to-end verification already done on a scratch DB under stripped PATH: direct tsx invocation seeds 13 asset types, exit 0.
- Save this plan doc (Convention 8) and append
## Execution Summaryafter gates pass (Convention 12).
Execution Summary
Section titled “Execution Summary”- Actual changes (vs. plan):
src-tauri/src/lib.rs: addedtsx_package_dir,tsx_package_json_path,tsx_cli_js_candidates,ensure_tsx_cli_js(mirrors the existing prisma CLI resolver; readsbinfromtsx/package.json, fallbacksdist/cli.mjs,dist/cli.js).src-tauri/src/lib.rs: rewroterun_prisma_seedto runnode <tsx-cli-js> <backend>/prisma/seed.tsdirectly instead ofprisma db seed; added a hard guard that fails startup with a clear message ifbackend/prisma/seed.tsis missing. Env (DATABASE_URL,STRATA_SEED_PROFILE), output capture, and theResult-based popup flow are unchanged.- 3 new Rust unit tests for the tsx resolver (missing → error; fallback path; package.json bin preference). Test count: 9 → 12.
- Deviations: none from the plan. The
prisma db seedpath is fully bypassed in the desktop app; terminal dev workflow (npx prisma db seed) untouched. - Test results:
cargo test(src-tauri): 12 passed (baseline 9 → 12).cargo build --release(src-tauri): success.- End-to-end reproduction (scratch DB,
PATH=/usr/bin:/bin:/usr/sbin:/sbin+ absolute node):prisma db seedfails withCommand failed with ENOENT: tsx prisma/seed.ts / spawn tsx ENOENT— byte-identical to the reported popup. Directnode <tsx-cli> prisma/seed.tsunder the same stripped PATH: exit 0, 13 asset types seeded. Scratch DB cleaned up. - Backend build +
test:cov(351 passed, 97.34% coverage) +test:e2e(77 passed): green, run under nvm node v26.12.1 —backend/node_modules/better-sqlite3native module is built for ABI 147 (node 26), so the suite must run with a node-26 runtime on this machine (nvm node 24 →ERR_DLOPEN_FAILED, an environment artifact, not a code regression). Frontend build +vitest coverage(95.7% stmts): green. Docs build + release tooling tests: green. All local gates passed before release; CI onmainran green.
- Commit SHA(s):
0831359— fix + plan doc + root lockfile version sync (fix(desktop): run startup seed via local tsx CLI instead of prisma db seed)c99dfec—chore: release v1.6.3
- Release: tag
v1.6.3pushed toorigin(CI green before release), GitHub release published,docs/src/content/docs/releases/v1-6-3.md+ index row added. Plan closed per Convention 14. - Key discoveries:
v1-2-5release notes claimed “the same fix applies toprisma db seedon first launch” — but hardening only covered the outer invocation (node <prisma-cli> db seed).prisma db seedre-spawns the configured seed commandtsx prisma/seed.ts(backend/prisma.config.ts,migrations.seed) via PATH lookup, which stays broken under LaunchServices’ stripped PATH. The direct-tsx invocation removes the last PATH dependency in the startup chain.