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

未关闭
#1,055 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
typescript
领域
tooling

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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.
主要语言
TypeScript
星标
18.2k
派生
2k
平均合并
3 小时 56 分钟
30 天内合并 PR
96

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

cursor/plugins 的其他 Issue

查看 cursor/plugins 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。