You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(db): recover WASM SQLite locks via PID sentinel, not a 60s age window (#1261)
## Summary
Follow-up to #1260 addressing a post-merge finding from **Cursor
Bugbot** and **sentry-warden**.
On the WASM SQLite fallback (npm package on Node < 22.15),
`node-sqlite3-wasm` locks the DB with a `<db>.lock` directory (mkdir
mutex) and releases it via `rmdir` on close. A CLI process killed by
**SIGINT (Ctrl+C) / SIGTERM** mid-write bypasses the
`process.on('exit')` handler, so the lock dir leaks. The previous
recovery only cleared a leftover lock once it aged past a **60-second**
window — so a quick re-run after Ctrl+C failed with `database is locked`
for up to a minute.
## Fix
PID-owner sentinel for **precise** liveness detection instead of a time
guess:
- On open (WASM), write `<db>.lock.owner` = our PID.
- On the next open, `clearStaleWasmLock` reads it:
- owner **dead** → lock is provably orphaned → cleared **immediately**
(no wait),
- owner **alive** → genuine live lock → left to `busy_timeout` (no
stealing),
- **no sentinel** → fall back to the age window (older CLI / races).
- On clean close, remove the sentinel.
The sentinel lives **outside** the lock dir — a file *inside* it would
make the driver's `rmdir` unlock fail (verified), defeating the driver's
own cleanup.
### Why not a SIGINT/SIGTERM handler?
A DB-layer signal handler would risk interfering with commands that
legitimately own SIGINT for graceful streaming shutdown (`log list
--follow`, `dashboard view`), which keep the process alive after the
signal. The recovery-side fix has zero interference risk.
## Verification
- New tests: dead-owner lock cleared immediately despite fresh mtime;
live-owner (current PID) lock preserved despite old mtime. 28
sqlite-adapter tests, 296 db tests pass.
- E2E reproduction: a fresh lock dir with a dead-owner sentinel is
cleared on the next run in ~startup time (no 60s stall); previously this
exact case blocked for 60s.
- SEA binary still excludes the WASM driver (0 driver symbols); native
path unchanged.
- npm real-install (no `node_modules`) smoke passes.
Also corrected the now-inaccurate JSDoc that described the (previously
wrong) 'live lock is recently re-touched' premise.
***Always perform rigorous, read-only code reviews with specific focus areas**: The user consistently conducts critical, adversarial code reviews in a read-only manner, focusing on specific technical areas. They provide detailed context about the repository, branch, and changes under review, and specify exact focus areas like path correctness, dependency management, build configurations, and security implications. The user maintains strict read-only discipline, prohibiting any modifications to source files, and often works within isolated worktrees. They expect thorough verification of technical changes against documented requirements and prior decisions.
***Always plan systemic fixes with structured multi-problem breakdowns before implementation**: When the user identifies documentation or tooling issues, they consistently organize them as numbered problems with precise file locations, line numbers, and root causes before any code is written. They expect the assistant to engage at the planning level first — proposing detection strategies, fix approaches, and tradeoffs — and to consolidate related problems (e.g., merging overlapping tasks) rather than treating each in isolation. Plans are written to files and iterated on. Implementation only follows after the plan is agreed upon. The user prefers systemic/automated fixes (e.g., derive patterns from package.json) over one-off patches.
***Always plans for testing or verification of tasks**: The user consistently implies a need for testing or verification of tasks, as seen in multiple instances where they either directly request tests or imply the necessity for verification. This pattern is observed across various sessions where the user is planning and executing tasks, indicating a preference for ensuring that tasks are validated or tested.
***Always provide comprehensive technical context for implementation decisions**: The user consistently provides detailed technical context when making implementation decisions, including code diffs, test results, build configurations, and dependency analysis. This pattern shows the user expects technical discussions to be grounded in concrete evidence and implementation details, with changes justified by specific requirements like Node version compatibility or WASM driver behavior.
***Always provide comprehensive verification artifacts during code reviews**: The user consistently provides detailed verification artifacts when submitting code for review. This includes sharing commit hashes, full code snippets with context, test results across multiple environments, CI status updates, and bot review comments. The user expects reviewers to have complete visibility into the changes and their impact, and proactively shares all relevant information to facilitate thorough review and fast iteration.
***Always read and document full file details before proceeding with analysis or implementation**: When exploring a codebase, the user consistently reads files in full and records comprehensive structured details: exact line counts, all imports, every exported type/interface with their fields, all constants, all function signatures with their logic, and any notable comments or assertions. This applies to both source files and build/tooling scripts. The user expects the assistant to capture and reference these details precisely rather than summarizing loosely. When examining related files (e.g., a module and its consumers), the user reads each completely before drawing conclusions. This pattern applies during architecture exploration, feature planning, and documentation generation tasks.
***Always Verify and Validate Code Correctness**: The user consistently verifies and validates code correctness across multiple sessions. This includes checking the correctness of functions, ensuring proper scoping of catch blocks, verifying variable destructuring, and confirming the integrity of specific code elements. The user also tends to ask questions about code behavior, compatibility, and potential issues, demonstrating a thorough approach to code review and validation.
***Always verify bot findings and test coverage before merging**: The user consistently demonstrates a pattern of thorough verification before merging changes. They always review bot findings (sentry-warden, Cursor Bugbot, etc.) in detail, share relevant code snippets to verify findings against current code, and run comprehensive tests including edge cases. The user expects to see test results for all scenarios, especially for database operations and signal handling. They also verify that fixes address the root cause and don't introduce new issues.
***Always verify code claims against actual file contents before accepting them as true**: When evaluating PRs, documentation, or assertions about code behavior, the user systematically cross-checks every claim against the actual source files at specific line numbers. They expect the assistant to read the real files, confirm exact line locations, quote the relevant code/comments, and flag discrepancies between what is claimed and what the code actually does. The user marks confirmed findings with 🟡 (verified) and actionable directives with 🔴 (user assertion/directive). Never accept a PR description or assertion at face value — always ground-truth it against the codebase with precise line references.
0 commit comments