Skip to content

Release the embedded-database lock when the database closes - #65

Merged
shashikanth-gs merged 1 commit into
mainfrom
claude/fix-pglite-lock-release
Oct 19, 2026
Merged

shashikanth-gs merged 1 commit into
mainfrom
claude/fix-pglite-lock-release

Conversation

@shashikanth-gs

Copy link
Copy Markdown
Member

What changed and why

Fixes a regression from #64. That change added a <folder>.lock file so two processes cannot open the same PGlite folder, but held it until the process exited. A process that opened and closed the database and then started a server on the same folder, which is what scripts/verify-identity-http.mjs does, made the server refuse to start. The script failed with /api/agents: 503 !== 401.

  • The lock is now tied to open databases: createDatabaseOrm claims it and orm.close() releases it. Several openers in one process share one claim, and the lock file is removed with the last release.
  • The MikroORM CLI (npm run db:migrate) claims the folder in mikro-orm.config.ts for the life of the command.
  • createMikroOrmOptions no longer takes the lock itself.
  • A process that exits while still holding a claim removes its lock files.

How it was verified

  • New regression test (pglite-guard.db.test.ts): a process opens and closes the database, stays running, and a second process must be able to open the folder. It fails on the old code with the "already open in another process" refusal and passes with the fix. A second test covers claim counting and lock-file removal.
  • node --import tsx scripts/verify-identity-http.mjs passes (it failed before).
  • Lint, type check and all 594 unit tests pass. In the database suite, 34 of 35 files passed in the full run; the last one is described below.
  • db:migrate, db:schema:check, npm run build and all 15 test:http scripts pass.

Not clean: in one full npm run check, auto-discovery.db.test.ts "stops at its sweep and lifetime limits" timed out (137s against its own 120s limit). Run alone it passes in about 105s on this branch and about 110s on the previous code, so it is slow rather than affected by this change, but it has little headroom. I did not change its timeout. The PostgreSQL variants of the database tests only run in CI. Not exercised on macOS or Windows; the informational platforms job from #64 will show that.

Checklist

  • Focused change, with tests in the same change
  • npm run check passes (or the part you could run is listed above) — the full command stopped at the timeout above; every step after it was run separately and passed
  • Docs updated for the behavior you changed, per docs/contributing/documentation.md (or say why none apply) — the behavior documented in Claude/UI workflow redesign #64 is unchanged apart from when the lock is released
  • Security-relevant changes update docs/security/threat-model.md (not applicable: no change to access control)
  • User-visible changes are in CHANGELOG.md (not applicable: this corrects an unreleased change)

Generated by Claude Code

The lock was held until the process exited, so a process that opened and closed
the database and then started a server on the same folder (as the HTTP
verification scripts do) made the server refuse to start. Several openers in one
process now share a claim that is released on close.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Lu73uozkZGX8gP8LWNbBqt
@shashikanth-gs
shashikanth-gs merged commit 97b02f8 into main Oct 19, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants