pstack orch: stale-lock takeover can be lost (unlink-then-create TOCTOU); frontier SHAs use local branches
Maintainers usually reply within 1 day
Nobody has claimed this yet.
- #733 by @deanrie — closed without merging
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 52/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- node.js, typescript
Research direction
Start with skills/poteto-mode/scripts/orch/store.ts, reading acquireLock and the frontier mapping around the locations cited in the issue. Trace how stale lock holders are read and how the PR head SHA is represented in the snapshot. Done means stale takeover preserves mutual exclusion and frontier SHAs identify the PR head; the issue suggests a two-process test for the lock behavior.
Written by the indexing model from the issue text.
Description
Summary
acquireLock in the pstack orchestrator store takes over a stale lock by unlink-then-create, which has a TOCTOU window: two processes that both see the same dead holder can end up both holding the lock.
- Version: pstack
0.15.28(harness/pstack/claude-code) - File:
skills/poteto-mode/scripts/orch/store.ts,acquireLock(~L376–405)
const takeOver = async (): Promise<void> => {
await unlink(path); // (1) both processes can reach here
try {
await create(); // (2) one wins; the loser's unlink may land later
} catch (retryError) { ... }
};
Interleaving that loses mutual exclusion
| step | P1 | P2 |
|---|---|---|
| 1 | reads holder, decides it is dead | |
| 2 | reads holder, decides it is dead | |
| 3 | unlink(path) |
|
| 4 | create() → holds lock |
|
| 5 | unlink(path) → deletes P1's fresh lock |
|
| 6 | create() → also "holds" lock |
Both processes then proceed to write the store, so one writer's update is lost.
Suggested fix
Make takeover atomic rather than unlink-then-create. Either:
- Lock directory —
mkdirthe lock path (atomic;EEXISTis the contention signal) andrmdiron release. Changes the lock artifact from a file to a directory, and the reader ofholderIsDeadneeds to read the pid from a file inside it. - Rename-based takeover —
rename(path, path + ".stale." + pid): only one process can win the rename; then read the renamed file to report the previous holder, andcreate()the new lock. OnEEXIST, report the current holder.
A two-process test (spawn two children that both observe a dead pid and assert exactly one acquireLock resolves) would pin the behaviour.
Related finding in the same file: frontier SHAs come from local branches
skills/poteto-mode/scripts/orch/store.ts (~L1229–1235):
return chain.map((row) => ({
pr: row.pr,
branches: row.branch,
sha: branchSha({ branch: row.branch, repo }), // local branch, not PR head
state: row.state,
}));
The frontier's verification identity is taken from the local branch, while the thing being verified is the PR head. If a local branch is stale or missing, the recorded SHA silently describes a commit that is not under review — a false verification identity rather than an error.
Suggested fix: source the SHA from the PR head OID already present in the snapshot, and represent "no local branch" as an explicit unknown instead of substituting a branch tip.
Happy to send PRs for either; filing first in case the lock artifact shape (file vs directory) is a compatibility constraint I cannot see.
- Dominant language
- TypeScript
- Stars
- 18.2k
- Forks
- 2k
- Avg merge
- 3h 56m
- Merged PRs (30d)
- 96
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from cursor/plugins
-
pstack: interrogate asks the user, which worker.md forbids for delegates that reach itPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
cursor/plugins#1272 · 1 comment ·
Maintainers usually reply within 1 day
-
poteto-mode: multi-phase-plan Merge placeholder still appends every PR to a base-branch stackPossibly taken @mangeshraut712 claimed this 15 days ago. Open
Difficulty 1/5 Under an hour Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
typescript-best-practices: schema example uses z.string().uuid(), deprecated in Zod 4Possibly taken @mangeshraut712 claimed this 14 days ago. Open
Difficulty 1/5 Under an hour Newbie friendliness 88/100
cursor/plugins#1165 · 1 comment ·
Maintainers usually reply within 1 day
-
statechart: relative-symlink launcher test fails on macOS because /var is a symlinkPossibly taken @lnuxe claimed this 3 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
cursor/plugins#1164 · 2 comments ·
Maintainers usually reply within 1 day
-
pstack docs/harness/claude-code.md: transcript slug replaces every non-alphanumeric character, not only / and .Possibly taken @isTuhin claimed this 9 days ago. Open
Difficulty 1/5 1-3 hours Newbie friendliness 82/100
cursor/plugins#1155 · 2 comments ·
Maintainers usually reply within 1 day
Similar issues
-
infra needs-triage
Difficulty 2/5 Under an hour Newbie friendliness 82/100
LucasSantana-Dev/Lucky#3331 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
kOaDT/oss-oopssec-store#381 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
nocobase/nocobase#11669 · 1 comment ·
Maintainers usually reply within 1 day
-
iOS: Clear Context (/clear) and model picker fallback use negative agent check instead of isClaudeOpen
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
Area: API Bug Difficulty: Low Priority: Low
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
DouglasNeuroInformatics/OpenDataCapture#1937 ·
Maintainers usually reply within 1 day