Files
goodbuddy/scripts/supervision-storage-live.cjs
T
mesalogo d80d42b032 feat(storage): move desktop SQLite ownership into a storage utility process
Main no longer opens desktop business SQLite. A single utility-process
storage owner holds the Assistant, Knowledge, attachment, document-result,
remote-binding and native model-ledger databases and runs whole domain
transactions; Main and Runtime callers use explicit async domain operations.

- Remove the Main readWithFallback path and the supervision worker's
  separate business write connection; manifests are scanned read-only and
  committed by the sole writer.
- Remote events are ACKed only after commit; process loss reports
  unconfirmed writes instead of replaying them.
- Use native utilityProcess messaging with one in-flight bound (32) and
  ordered waiting instead of capacity rejection and retries.
- Start the storage process before the window so startup overlaps.
- Keep short tool output in memory and store full output once in owned
  storage; paging, branching, restart and deletion reuse that copy.
- Put required runtime launch files under goodbuddy-prefixed owned temp
  directories and reclaim confirmed stale ones; stop writing duplicate
  parsed.md.
- Add lint guards for SQLite ownership and architecture, concurrency
  acceptance fixtures, and maintenance/architecture documentation.

Validation: typecheck and lint pass. Alternating baseline (edf019aa) vs
candidate runs show no regression on single-session, C01, C02, C04 and a
5-minute C06; Main p99 drops from ~21 ms to ~16.7 ms under concurrency.
Fresh portable copy (1.75M events) upgrade content unchanged; real-model
output paging passes with 4 external requests. Full npm test runs had
1-9 different timing-sensitive failures per run that pass when rerun.
Not covered: C03 review publication, C07 source body, app-level C05.
2026-10-06 15:40:18 +08:00

34 lines
2.1 KiB
JavaScript

/* global require, process, __dirname, console, setTimeout, clearTimeout */
/* eslint-disable @typescript-eslint/no-require-imports */
// node scripts/supervision-storage-live.cjs <current-runtime-settings.json>
const { build } = require('esbuild')
const { spawn } = require('node:child_process')
const { mkdir, mkdtemp, rm } = require('node:fs/promises')
const { join, resolve } = require('node:path')
async function main() {
const repo = resolve(__dirname, '..')
if (!process.argv[2]) throw new Error('Runtime settings path required')
const parent = join(repo, 'temp', 'supervision-storage-live')
await mkdir(parent, { recursive: true })
const root = await mkdtemp(join(parent, 'probe-'))
try {
for (const [entry, output, format] of [
['scripts/supervision-storage-live.ts', 'main.mjs', 'esm'],
['src/main/desktop-storage-entry.ts', 'desktop-storage-entry.mjs', 'esm'],
['src/main/readonly-query-worker.ts', 'readonly-query-worker.cjs', 'cjs'],
['src/main/assistant-storage-worker.ts', 'assistant-storage-worker.cjs', 'cjs']
]) await build({ entryPoints: [join(repo, entry)], outfile: join(root, output), bundle: true,
platform: 'node', format, packages: 'external', logLevel: 'silent' })
const env = { ...process.env, GB_SUPERVISION_STORAGE_ROOT: root, GB_SUPERVISION_SETTINGS: resolve(process.argv[2]), TEMP: root, TMP: root, TMPDIR: root }
delete env.ELECTRON_RUN_AS_NODE
const child = spawn(require('electron'), [join(root, 'main.mjs')], { env, stdio: ['ignore', 'pipe', 'pipe'] })
child.stdout.on('data', data => process.stdout.write(data))
// The probe prints only bounded metrics; native stderr is not a credential-safe report.
child.stderr.resume()
const timer = setTimeout(() => child.kill(), 300_000)
try { process.exitCode = (await new Promise((resolve, reject) => { child.once('exit', resolve); child.once('error', reject) })) ?? 1 }
finally { clearTimeout(timer) }
} finally { await rm(root, { recursive: true, force: true, maxRetries: 10, retryDelay: 100 }) }
}
main().catch(() => { console.error('Supervision storage probe failed before completion'); process.exitCode = 1 })