Review Change StackReview Change Stack
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Advanced
Run ID: a68c549b-1909-41e3-b7a3-ecae9404d3c3
📥 Commits
Reviewing files that changed from the base of the PR and between 455dcf4b2d44b5bfa1eef29de67f57e3b41c603e and 2feefe653f1ccf090878022023e8a2e19bc0183c.
📒 Files selected for processing (2)
apps/server/src/serverSingleton.test.tsapps/server/src/serverSingleton.ts
🚧 Files skipped from review as they are similar to previous changes (2)
- apps/server/src/serverSingleton.ts
- apps/server/src/serverSingleton.test.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.
📝 Walkthrough
Walkthrough
The server now claims a data-directory lock before HTTP binding and SQLite initialization. The lock supports stale-lock reclamation, heartbeat refresh, ownership-safe release, legacy runtime detection, and atomic port recording. Tests cover concurrent reclaimers and lock lifecycle behavior.
Changes
Server Singleton Lock
| Layer / File(s) | Summary |
|---|---|
Lock contract and claim apps/server/src/serverSingleton.ts | Defines lock data, errors, liveness checks, legacy-state detection, and gated stale-lock reclamation. |
Lock lifecycle and port metadata apps/server/src/serverSingleton.ts | Refreshes the held lock, releases only matching ownership, and atomically records the bound port. |
Startup wiring and port recording apps/server/src/server.ts | Provides singleton acquisition to HTTP and runtime dependencies, then records the listening port after binding. |
Singleton behavior validation apps/server/src/serverSingleton.test.ts | Tests ownership, stale and legacy locks, heartbeat protection, concurrent reclaimers, independent directories, release behavior, and atomic port updates. |
Priority: ➖ Normal
Estimated code review effort: 4 (Complex) | ~60 minutes
Change: Bug fix · Severity of issue fixed: Medium
Sequence Diagram(s)
| 1 | sequenceDiagram |
| 2 | participant ServerSingletonLive |
| 3 | participant acquireServerSingleton |
| 4 | participant HttpServerLive |
| 5 | participant recordServerLockPort |
| 6 | participant RuntimeDependenciesLive |
| 7 | ServerSingletonLive->>acquireServerSingleton: claim state directory |
| 8 | ServerSingletonLive->>HttpServerLive: provide held singleton |
| 9 | ServerSingletonLive->>RuntimeDependenciesLive: provide held singleton |
| 10 | HttpServerLive-->>recordServerLockPort: return bound port |
| 11 | recordServerLockPort->>ServerSingletonLive: persist port on lock |
Merge Risk: ⚪ Minimal · up to 2feef
This change adds a startup-time lock so two server processes cannot bind to the same data directory at once, with tests confirming that stale, crashed, and legacy locks are reclaimed correctly while live holders and their successors are protected. No unresolved correctness or availability issue was found in the reviewed lock, heartbeat, release, or port-recording logic, so this is ready to merge from a review standpoint; the previously discussed narrow race with an unmodified, lock-unaware older binary is an acknowledged limitation already deferred to a separate follow-up PR rather than a defect in this change.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
| Check name | Status | Explanation |
|---|---|---|
| Docstring Coverage | ✅ Passed | No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 3… |
| Linked Issues check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
| Out of Scope Changes check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
| Title check | ✅ Passed | The title clearly and concisely describes the primary change: preventing a second server from starting against a live data directory. |
| Description check | ✅ Passed | The description is complete and relevant. It explains what changed, why it changed, startup behavior, recovery behavior, testing, verification results, UI impact, and checklist status. |
✨ Finishing Touches
🧪 Generate unit tests (beta)
- Create PR with unit tests
Comment @coderabbitai help to get the list of available commands.