/agent-traffic-control:shared-mutable-index-rmw-race-use-marker-blob-per-itemfrom agent-traffic-control
Designing a shared "who is active / recent items" index that concurrent producers write to: one mutable list silently loses entries. Write one marker per item.
Ships in agent-traffic-control. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description, though model invocation is off: only you can start it.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
You are building a feature where multiple producers concurrently register items into a shared collection, and a reader periodically prunes dead entries — e.g. a "see everyone's in-flight runs / active sessions / recent uploads" list shown on a home/dashboard page, shared across a team / workspace / user.
The tempting design is one shared mutable container that you read-modify-write:
# register (producer) # render + prune (reader)
ids = read(index) ids = read(index)
ids = [new_id] + dedupe(ids) live = [i for i in ids if still_alive(i)]
write(index, ids[:CAP]) write(index, live) # prune
This has a read-modify-write race. Interleave two callers:
[A].[A], computes [X, A], writes [X, A].[A] (computed in step 1, before X existed).X is now permanently gone from the index. It is never re-added — registration fires once, at create time. So the very item the feature promises to surface silently never appears for anyone. It is not self-correcting (a common false assumption). The window is small, but it is exactly the "two people working at once" moment the feature exists to serve, and a janitor/prune reader widens it.
in-memory-job-registry-orphans-cloud-result-on-restart and
reconstruction-from-durable-store-must-replicate-completion-gate.Use one marker blob/row PER ITEM, not a shared list:
<prefix>/<item_id> # e.g. _active_runs/<workspace>/<run_id> — empty body
bucket.blob(f"{prefix}/{item_id}").upload_from_string(b"")
list_blobs(prefix=...) → the item_ids are the key basenames.Then layer on three cheap refinements the list design made awkward:
item_id is
<hash>_<epoch> (or any id carrying a creation time), drop entries older than a TTL by name
— delete(key) without a round-trip to resolve the item's real state. Self-cleans abandoned
markers cheaply and bounds the working set.<config_hash>_<ts1> and <config_hash>_<ts2> are re-runs of the same config), keep the
newest per sub-key at read time so a re-run doesn't resurrect a stale card. Delete the older
markers.Why not "JSON list + optimistic-concurrency CAS retry" (generation precondition)? It works,
but it guards the race with retry loops instead of removing it, and it keeps the all-or-nothing
write. Prefer marker-per-item unless you genuinely need ordering or atomic multi-item updates.
Bonus: object stores that already keep results_<id>.json / events/<id>.json per item are
telling you the idiom — marker-per-item matches the grain of the store.
If you DO use CAS (the legitimate ordered/atomic-update exception — e.g. an upload manifest that is a single ordered list with cross-item dedup + cascade-delete semantics), the footguns that make a "passing" CAS silently a no-op or a data-loss:
blob.upload_from_string(data, if_generation_match=gen) raises google.api_core.exceptions.PreconditionFailed
(412) on a lost race — but only if gen is real. Non-obvious: after blob.download_as_text(),
blob.generation IS populated (from the X-goog-generation response header — verified
google-cloud-storage 3.10.1, blob.py _extract_headers_from_download), so you can read+capture
it in one round-trip. If it ever comes back None (a non-modelling test fake, or a future lib
release that stops populating it on download) the code path that does if gen is not None falls
through to an unconditional write → the race protection is gone and tests stay green. More
robust: read via bucket.get_blob(key) (explicit metadata GET → generation always an int; returns
None only on NotFound; raises on a real read error → fail-closed) instead of relying on the
download side-effect. Pin the client major (google-cloud-storage>=2,<4) so the contract can't
silently change.if_generation_match=0 so two concurrent
first-writers can't both blindly create-and-clobber.(new, displaced) from the reloaded state, so a
blob the concurrent winner now references is never deleted. Reaping inside the retry loop, or from
a stale pre-retry displaced, deletes a live blob — a worse bug than the race you fixed.except Exception: return [], None
on the read → the caller writes the index rebuilt from just the new entry → clobbers everything.
Re-raise on a genuine read error (the route's outer handler turns it into a retry), or use
get_blob which fails closed. (the-causal-impact-repo #359 F9 / #457.)the-causal-impact-repo #323 (PR #336, 2026-06-05): a /home "Pick up where you left off" feature
showing a workspace's in-flight analysis runs. First built as _workspace_runs/<slug>.json (a
shared JSON list, read-modify-written at dispatch and pruned on /home). A review panel (two
independent reviewers) flagged the RMW race: a colleague's just-dispatched run could be
permanently dropped — defeating the "see each other's runs" promise. Reworked to a marker blob per
run, _workspace_runs/<slug>/<run_id>: race-free, plus age-prune-by-name, config-hash dedupe, and
an 8-card cap. It also matched the codebase, which already stored results_<method>.json /
tests/<type>.json per item.
reconstruction-from-durable-store-must-replicate-completion-gate (replicate the in-memory
completion gate so a partial item isn't shown as done) and
in-memory-job-registry-orphans-cloud-result-on-restart.These carry disable-model-invocation: true, so open them with Read when one matches.
peer-window-grant-copy-the-parser-and-stay-quiet-while-live: granting a peer agent a window on a shared host through a text mailbox its controller parses. Copy the parser's labels, and write nothing while the window is live.running-job-queue-ignores-in-place-edits: a loop reading a queue file through a held descriptor never sees a sed -i edit, and a rebuild that counts lines can drop a job.What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub wan-huiyan/agent-traffic-control --plugin agent-traffic-controlOther plugins' skills for the same job
118 skills in this plugin
/agent-refusal-with-evidence-beats-literal-complianceA dispatched agent that does exactly what you asked can ship a defect you would
have stopped yourself, because it can see something at the worksite that you
could not see when you wrote the brief. Use when: (1) you are writing a brief
that prescribes a specific fix, threshold, wording or value rather than the
outcome you want; (2) an agent reports that it did not do what you asked and
you are deciding whether that is insubordination or judgement; (3) an agent
asserts "this is fine" or "not needed" with no measurement behind it; (4) you
are reviewing overnight output and want to know which decisions were checked
and which were assumed. Two halves, and both are needed: give the agent
explicit permission to satisfy the INTENT of an instruction while refusing its
letter, and REQUIRE the evidence with the refusal — what it built or measured,
what that showed, what it did instead. Evidence is the whole difference between
a refusal you can bank and one you have to re-litigate. Four agents correctly
declined an instruction in a single run; one built the suggested fix, measured
that it turned a silent safe refusal into a permanently red pipeline, and
reverted it unpushed.
/auto-merge-rearms-while-agent-live-kill-then-disarm-verify