feat(engine): guard one engine per project per machine

Adds a per-machine singleton lock that engages in
ProjectEngineManager.createAndStart() before any engine subsystems
spin up. Two fn dashboard processes can no longer run engines for the
same project on the same host — previously they would share .fusion/
state and corrupt worktrees / task rows for in-process projects.

The guard combines two independent checks:
  - A proper-lockfile file at <project>/.fusion/engine.lock with
    stale-lock recovery (auto-released on process death).
  - A loopback listener on a hashed per-project address — UDS on
    POSIX, named pipe on Windows. Stale UDS files are probed and
    unlinked before a retry bind.

Failures raise EngineAlreadyRunningError. Both guards are released
from stopAll() and pauseProject(); a release on engine.start()
failure lets retries re-acquire cleanly.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
gsxdsm
2026-05-19 22:50:39 -07:00
parent 959f7cd4eb
commit 98033bc869
8 changed files with 458 additions and 3 deletions

View File

@@ -39,12 +39,14 @@
"@fusion/pi-claude-cli": "workspace:*",
"@mariozechner/pi-ai": "^0.73.0",
"@mariozechner/pi-coding-agent": "^0.73.0",
"typebox": "^1.0.0",
"cron-parser": "^5.5.0"
"cron-parser": "^5.5.0",
"proper-lockfile": "^4.1.2",
"typebox": "^1.0.0"
},
"devDependencies": {
"@modelcontextprotocol/sdk": "^1.0.0",
"@types/node": "^25.5.0",
"@types/proper-lockfile": "^4.1.4",
"@vitest/coverage-v8": "^3.1.0",
"typescript": "^5.7.0",
"vitest": "^3.1.0"