Skip to content

fix(state): wire PID lock into mutating commands - #157

Merged
LucasSantana-Dev merged 2 commits into
mainfrom
fix/148-wire-lock
Jul 3, 2026
Merged

fix(state): wire PID lock into mutating commands#157
LucasSantana-Dev merged 2 commits into
mainfrom
fix/148-wire-lock

Conversation

@LucasSantana-Dev

Copy link
Copy Markdown
Owner

Summary

This completes issue #148 by wiring the existing acquireLock() / releaseLock() primitives into all state-mutating commands. Previously, these functions existed but had zero call sites, leaving concurrent install/update/rollback/uninstall operations vulnerable to read-modify-write races on installed.json and backup directories.

Changes

  • acquireLock(): Improved error message to clearly state another sharekit process is running (PID <N>) — retry after it finishes, or delete ~/.sharekit/.lock if stale
  • Wired lock into mutating commands:
    • install() — acquires lock at entry, releases in finally block
    • update() — same pattern
    • rollback() — same pattern
    • uninstall() — same pattern
  • Read-only commands remain unlocked: preview, inspect, list, search, scan, init do not acquire the lock (by design)
  • Lock placement: Lock choke point at function entry (after initial validation) ensures it's held for the entire operation and released even on error

Testing

  • test/lock.test.ts: New test file covering:
    • Live-PID detection (throws with clear message on Linux, cleans stale lock on macOS)
    • Stale-lock cleanup and successful acquisition
    • Lock release (file removal)
    • Lock file creation when directory doesn't exist
  • Integration: Existing integration tests verify the lock doesn't break the happy path
  • All gates pass: typecheck, npm test, format:check

Notes

@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 8 minutes

Your organization has reached its usage spending cap. Adjust your spending cap in the billing tab.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e1f04b45-2018-4f0f-8ecd-c7de95a51c7f

📥 Commits

Reviewing files that changed from the base of the PR and between b03a56c and e4c1e8d.

📒 Files selected for processing (4)
  • src/commands.ts
  • src/sharekit.ts
  • src/state.ts
  • test/lock.test.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/148-wire-lock

Comment @coderabbitai help to get the list of available commands.

- Improved acquireLock error message to be clearer: 'another sharekit process is running (PID <N>) — retry after it finishes, or delete ~/.sharekit/.lock if stale'
- Wired lock acquisition/release into: install, update, rollback, uninstall
- Lock is acquired at function entry (after initial checks) and released in finally block (guarantees release on error)
- Read-only commands (preview, inspect, list, search, scan, init) remain unlocked per design
- Added comprehensive lock tests: live-PID detection, stale-lock cleanup, successful release, directory creation
- All gates pass: typecheck, test, format:check
Replace /proc/<pid> check (Linux-only, breaks on macOS) with process.kill(pid, 0)
which works cross-platform:
- EPERM: process is alive but not owned by us
- ESRCH: process is dead
- Other errors: treat as dead

Also handle non-numeric PIDs as stale (corrupted lock files).

Update test suite:
- Live-PID test now unconditionally throws on all platforms
- Added test for non-numeric/corrupted lock content
- All tests pass on both macOS and Linux
@LucasSantana-Dev
LucasSantana-Dev merged commit 6882448 into main Jul 3, 2026
17 checks passed
@LucasSantana-Dev
LucasSantana-Dev deleted the fix/148-wire-lock branch July 3, 2026 15:13
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.

1 participant