poteto-mode orch store: stale-lock takeover can delete a live lock and admit two writers

Aperta
#1,055 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
typescript
Ambito
tooling

Direzione di ricerca

Start in scripts/orch/store.ts at acquireLock around :385-430, especially the EEXIST path and the unconditional unlink in takeOver at :394; also inspect --force handling. Reproduce the interleaving with the in-memory filesystem approach described, then design recovery serialization and a per-acquisition token checked by release and takeover. Done means the two-acquirer/one-stale-holder schedule admits at most one writer and the regression test asserts that.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Found against pstack 0.15.34 at cursor/plugins 519d36aa98955bf680db01bcde5fdfba686dc901 (harness/pstack/claude-code/skills/poteto-mode/). Line numbers refer to that commit.

scripts/orch/store.ts (acquireLock, around :385-430) recovers a stale lock like this:

  1. open(path, "wx") fails with EEXIST.
  2. It reads the holder PID, and holderIsDead(holder) is true.
  3. takeOver() calls unlink(path) unconditionally (:394), then create() again.

Between steps 2 and 3, another process can take over the same stale lock and create its own lock file. The slower
process then unlinks that new, live lock and creates its own. Both believe they hold the lock. The same applies to
--force (options.force). Every store write is a whole-file read-modify-write (unit updates, ledger records, gates,
standing orders), so two writers lose updates: units or verification records disappear.

Repro (executed in a no-write harness, using the transpiled acquireLock body over an in-memory filesystem):

A and B both fail create() with EEXIST and read the same dead holder PID.
A: unlink, create -> A holds the lock.
B resumes: unlink (deletes A's live lock), create -> B holds the lock too.

Suggested fix:

  • Serialize recovery with a separate exclusive mechanism, such as an OS advisory lock (flock) or a separate
    wx-created recovery lock that is itself removed only by its creator.
  • Write a unique token with each acquisition (pid plus random nonce plus time), and have release and takeover check
    that token instead of only the PID.
  • Rereading the holder just before the unlink narrows the window but doesn't close it.
  • Add a concurrency regression test for the schedule above: two acquirers, one stale holder, interleaved
    read/unlink/create. Assert that at most one acquirer succeeds.
Lingua principale
TypeScript
Stelle
18.2k
Fork
2k
Merge medio
3h 56m
PR unite (30g)
96

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di cursor/plugins

Tutte le issue di cursor/plugins

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.