Skip to main content
← Back to list
01Issue
BugClosedSwamp CLI
Assigneesstack72

#204 Add process-level install lock around installExtension

Opened by stack72 · 5/1/2026

Context

installExtension in src/libswamp/extensions/pull.ts has no process-level lock. Concurrent invocations (multi-process or multi-tab) race during extraction.

Pre-issue-#202 behaviour

Concurrent installs produced duplicate or interleaved files — recoverable by re-installing.

Post-issue-#202 behaviour (introduced by PR #1275)

installExtension now prunes orphan files after extraction but before the lockfile write. Concurrent installs can race so that process A's prune deletes a file process B just wrote — net result: missing files (a worse failure mode than today's duplicates).

Ask

Add a process-level lock around installExtension keyed on the lockfile path. A file lock should suffice. extension rm should also acquire it. Concurrent invocations should serialise rather than race.

References

  • PR #1275 (issue #202 fix)
  • Risk #5 in PR #1275's "Risks & non-mitigations" section
02Bog Flow
OPENTRIAGEDIN PROGRESSCLOSED+ 1 MOREASSIGNEDCLASSIFICATION

Closed

5/1/2026, 3:56:58 PM

No activity in this phase yet.

03Sludge Pulse
stack72 assigned stack725/1/2026, 3:49:38 PM
Editable. Press Enter to edit.

stack72 commented 5/1/2026, 3:56:57 PM

The race is real: post-PR #1275, concurrent installExtension calls can result in process A's orphan-prune deleting files process B just wrote, leaving the install in a "lockfile says present, disk says missing" state. The infrastructure to fix it (FileLock in src/infrastructure/persistence/file_lock.ts) already exists and a fix is mechanically straightforward — wrap the install/rm flow in FileLock.withLock() keyed on the lockfile path.

We're not pulling the trigger now because:

  • The pre-#1275 racy behaviour (duplicate/interleaved files) shipped for a long time without a user-facing report. Concurrent installs in solo workflows are rare.
  • The failure mode is recoverable: swamp extension pull <name> --force re-runs the install and reconciles the lockfile against disk.
  • Day-to-day cost of leaving it is low; engineering time is better spent on features users are actually asking for.

We will revisit if either of these changes:

  1. Multi-agent / multi-worktree workflows that share .swamp/pulled-extensions/ become common enough that two installs racing is a realistic event, not a theoretical one.
  2. A user reports "missing files after install" in the wild.

Workaround for anyone who suspects they hit this: re-run swamp extension pull <name> --force to re-extract and rewrite the lockfile.

Sign in to post a ripple.