fix(start-local): close 7 PGlite/Postgres parity-hygiene risks#943
Conversation
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe PR hardens local server boot in start-local.ts: it adds early Sentry instrumentation and runtime imports, sets a repo-root dev path fallback, captures gateway stop for shutdown, installs HTTP 5xx/error reporting with request-scoped de-dup, performs a post-listen external-deps check, and replaces boot error logging with structured serialization. ChangesServer Boot Hardening with Sentry and Graceful Shutdown
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add Comment |
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
047a8bd to
1c6d720
Compare
Summary
Closes 7 hygiene gaps where the PGlite entrypoint (
start-local.ts) silently diverged from the Postgres entrypoint (server.ts) without justification. Each finding is from the parity audit, with file:line refs preserved in commit messages. All patches are 1–6 LOC; no behavior change for happy-path users.Audit plan:
/Users/burakemre/.claude/plans/pglite-postgres-parity-audit.md§3.The 7 risks (ordered by blast radius from audit §3)
1.
stopLobuGateway()missing on shutdown — commit5bbf7fa3Change: added
stopLobuGatewayimport +await stopLobuGateway()inshutdown(), ordered before PGlite-owned resources (socket server, db.close) so postgres.js connections drain through the socket cleanly. Mirrorsserver.ts:258.2.
closeDbSingleton()missing on shutdown — commitb730f5f1Change: import
closeDbSingletonfrom./db/client, call it afterstopLobuGatewayand beforesocketServer.stop(). Mirrorsserver.ts:259.3. Sentry post-response 5xx +
app.onErrorhandler missing — commit0dc5fbfbChange: ported the two
app.use('*', …)blocks (response-status capture) and theapp.onErrorblock fromserver.ts:97-150. BothSentry.captureMessage/captureExceptionare no-ops whenSentry.initran without DSN, so safe on no-DSN installs (the common PGlite case).4.
./instrumentimport missing — commit1777f167Change: one-line
import './instrument';immediately afterassert-node-version.instrument.tsis a guarded no-op whenSENTRY_DSNis unset.5.
LOBU_DEV_PROJECT_PATHdefault missing — commit4e7c0d0fChange: ported the 3-line default block from
server.ts:64-66(resolves repo root from this source file, sets env var only if unset). References the existing CLAUDE.md note onlobu run from a project subdir.6.
assertExternalDepsResolvablepost-listen missing — commitec434d82Change: ported the 6-line try/catch from
server.ts:319-324into thehttpServer.listencallback, before the embedded daemon starts. Uses the existingrequire(createRequire(import.meta.url)).7.
serializeBootError+ stderr fallback missing — commit047a8bdfChange: copied the
serializeBootErrorhelper and the stderr-fallback main-catch fromserver.ts:344-388. Same recursion behavior forcause/errors/issues.Reproducer / verification
Smoke boot ran against
dist/start-local.bundle.mjs(Node 22 from/opt/homebrew/opt/node@22/bin, ephemeralLOBU_DATA_DIR=/tmp/lobu-smoke-data,LOBU_ALLOW_EPHEMERAL_ENCRYPTION_KEY=1, freePORT=8799+WORKER_PROXY_PORT=8129).Happy-path boot: clean.
Lobu running at http://127.0.0.1:8799reachedSIGTERM: clean shutdown.
Shutting downlog fires[gateway] Stopping platform: …for every platform → provesstopLobuGateway()ran (risks 1)Embedded gateway stopped→ confirms gateway awaitedPGlite socket server closed→ confirms ordering held (risks 2)Boot-error path:
LOBU_DATA_DIR=/dev/null/cant-existtriggeredENOTDIRfrommkdirSync. Output:err.type=Object,err.message=ENOTDIR: …,err.stack=…,err.code=ENOTDIRFailed to start: Error: ENOTDIR: not a directory, mkdir '/dev/null/cant-exist'followed by the stack"err":{}per Docker deployment crashes with no error message — impossible to debug locally #766.Validation
make typecheck: cleanmake build-packages: clean (bothstart-local.bundle.mjsandserver.bundle.mjsrebuild without warnings)Notes
defer / document as intentionaland listedassertExternalDepsResolvableas the actual 6th hygiene patch. Patch set follows the plan ordering.buildApp(deps)is intentionally not included — separate decision per audit author.packages/owlettountouched.Summary by CodeRabbit
Bug Fixes
Chores