title: Per-skill write lock for batch skills status: experimental kind: feature mode: infra source: > Two overlapping runs of one batch skill over one repository post the same comment or label twice. Implemented by tools/skill-lock/ and the shared prose blocks tools/dev/blocks/write-lock*.md propagated into the write step of issue-triage, security-issue-triage, issue-stale-sweep, pr-stale-sweep, pr-management-triage and good-first-issue-sweep. acceptance:
Makes a batch skill‘s write phase single-flight per skill per repository. A sweep’s read and classify phase is side-effect free and may overlap with anything; its posting phase is not. When two runs of issue-triage over the same repository overlap, whether a maintainer started one while a scheduled one was still posting or two maintainers ran it at once, both post the same proposal comment on the same issue. The lock stops the second run at the door of its write step, tells the maintainer who holds it, and lets the first finish. The lock is local, so it serialises runs from one clone; a run from another clone or another machine, and a run that classified before another posted, are narrowed, not prevented, by the re-read of each item just before its write.
tools/skill-lock/: the lock tool. skill-lock acquire | release | renew | status | list, one JSON object per call, exit 0 acquired, 3 already running, 2 error. Stdlib only. layers.py is the shared personal-layer resolver (a verbatim copy checked by tools/setup-preflight/tests/test_layers.py).plugins/magpie-vetted-ops/: ships the tool on every install; its session hook (tools/vetted-ops/hooks/link-stable-path.sh) links ~/.claude/magpie/skill-lock, and skills run it with uvx --isolated --from ~/.claude/magpie/skill-lock skill-lock … because the plugin cache is read-only.tools/dev/blocks/write-lock-detail.md and write-lock.md: the shared prose blocks, propagated by tools/dev/check-shared-blocks.py --fix, with {override_name} rendered to the skill‘s own name. The first is the rule; the second is a pointer, used where the write step sits in SKILL.md, that says to read the skill’s sibling write-lock.md (which carries the rule) before the step's first write.skills/issue-triage/compose-and-post.md, skills/issue-stale-sweep/posting-and-close.md, skills/pr-management-triage/interaction-loop.md: the rule, inline in the detail file their write step already loads. skills/security-issue-triage/SKILL.md, skills/pr-stale-sweep/SKILL.md, skills/good-first-issue-sweep/SKILL.md: the pointer, at the “post sequentially” / “apply” step, with the rule in each skill's sibling write-lock.md.docs/labels-and-capabilities.md: the substrate:action-guard row for the tool.<skill>@<owner>__<repo>. Two skills on one repository never contend (they post different things); one skill on two repositories never contends.<personal layer>/run/locks/<scope>.lock/, resolved the way every framework tool resolves the personal layer: the gitignored .apache-magpie-local/ in an adopted project, the git-directory home otherwise. Never the working tree of an adopted project.mkdir plus one owner.json (skill, repo, token, pid, host, started, expires, note). No flock, nothing under .git/ of an adopted project.acquire runs as a short uv run, and the owning skill run is an agent session with no stable pid, so the owner record carries an expiry (--ttl, default two hours). An expired lock is stale and is taken over by the next acquire, which reports took_over_stale. renew extends a long run. With --owner-pid, a dead pid on the same host is also stale. A lock directory with no readable owner is a racing starter and is respected.already_running (exit 3) carries the holder record and a hint with the --force release command. The skill prose shows the holder, posts nothing, and states this is not a failure of the sweep. Only the maintainer clears a lock by force.release --token refuses a non-matching holder; a plain release is unconditional; --force is the operator's override.spec-loop-runner.md.skill-lock acquire twice for the same skill and repository: the second exits 3 with status: already_running and the first holder in the result; the lock is unchanged.acquire for a different repository or a different skill succeeds while the first is held.--owner-pid is dead on this host, is taken over and the result says so; a lock with no owner file is reported as already_running with holder: null.release --token <wrong> exits 2 and leaves the lock; --force releases it; releasing a free lock is a no-op..apache-magpie-local/run/locks/; for an unadopted git repository it is under .git/apache-magpie/run/locks/.~/.claude/magpie/skill-lock resolves to a copy of the tool shipped in magpie-vetted-ops, and the block invokes it through that path.write-lock-detail block at its write step, or the write-lock pointer there and the rule in its sibling write-lock.md, rendered with its own skill name, and check-shared-blocks.py reports no drift.uv run --directory tools/skill-lock --group dev pytest uv run --directory tools/skill-lock --group dev ruff check src tests uv run --directory tools/skill-lock --group dev mypy uv run --directory tools/setup-preflight --group dev pytest tests/test_layers.py python3 tools/dev/check-shared-blocks.py uv run --project tools/skill-and-tool-validator --group dev skill-and-tool-validate
renew; the block does not yet say when..apache-magpie-local/ take different locks. Keying the lock on the git common directory would join them, but writes under .git/ of an adopted project are ruled out above; until then the re-read before each write narrows it.gh; a deterministic agent-guard check that refuses a gh issue comment / gh pr comment from a batch skill without a held lock would make it enforced.