Skip to content

[P2][cli] CLI lock ownership with pid/host/nonce and safe --force #33

Closed

Description

@cevheri

Summary

CLI advisory lock (src/cli/lock.ts) writes only a static sentinel. release() deletes any lock file regardless of owner. Two --force writers can both acquire; neither owns the lock exclusively.

Audit ID: Section 2 Med — Wave 2
Related: Kernel exclusive open lock (B4 issue)

Root cause

release() {
  rmSync(lockPath, { force: true });
}

No pid/host/nonce in lock file; no verify on release.

Fix

  1. Lock file content: libredb-lock\n<pid>\n<hostname>\n<random-nonce>\n
  2. release() — read and verify nonce matches; only then delete.
  3. --force — check prior lock holder liveness (pid signal 0 / stale detection) before dropOwnLock; refuse if alive holder unless explicit force semantics documented.

Align format with kernel-level lock (B4) if shared constant extracted.

Tests

  • Acquire + release own lock → ok.
  • Simulate foreign lock content → release must not delete (or force path only).
  • --force on stale pid → succeeds.

Acceptance criteria

  • Lock ownership verified on release.
  • --force cannot leave two live writers thinking they hold lock.
  • bun run gate green.
  • Changeset if CLI behavior changes (yes).

Verification

bun run gate

Activity

  1. cevheri commented on Jul 3, 2026

    @cevheri
    MemberAuthor

    Implemented and shipped in PR #43 (merge commit 69f7161), released as v0.2.0. The PR description's comma-separated Closes list only auto-closed the first reference — closing manually. For #39/#28-style partials: the shipped scope is done; the real-browser verification half of #39 continues under #10, and the typed-error contract (#28) shipped as LibreDbError with stable codes across kernel, adapters, lenses, and CLI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/cliPre-announcement auditbugSomething isn't workingpre-announcementPre-announcement auditpriority/mediumPre-announcement audit

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions