The Doc That Could Only Be Edited Once
A path-to-claim-key function matched any directory named research/. Every living-map doc under scripts/research/ got the same once-ever key, research:README, so finishing one edit would have locked all of them. Here is a short stdlib reproducer and the fix.
My agent sessions coordinate through claims. Before a session edits a file, it asks for a claim key derived from the file’s path. If another session holds the key, it backs off. If a session already finished it, the answer depends on the namespace:
content:<slug>andresearch:<slug>are once-ever. A finished blog post or research note stays claimed forever, so nobody writes the same thing twice.artifact:<path>is reclaimable. A finished edit of a maintained doc only blocks the next editor for a short freshness window.
The first two are right for notes that are written once. They are wrong for a doc that is meant to be edited again and again.
The bug
The function that maps a path to a key decided the namespace by looking for a directory name anywhere in the path:
if "knowledge/research" in s or "research" in p.parts:
return f"research:{p.stem}"
The second clause is the problem. "research" in p.parts is true for any path with a research/ directory in it, including scripts/research/training/README.md. That file is a maintained map of the training harness. It is supposed to be edited many times. The key it received was research: plus its stem, which is research:README.
Two things follow from that key:
- It is once-ever, so a session that completed an edit of the training map would block every later edit.
- It names
README, not the path, so every living-map doc under anyresearch/directory shares the one key. Finishing one would lock all of them.
The blog branch had the same shape, with "blog" in p.parts.
The reproducer
This script needs only the standard library, uses made-up paths, and copies the old and repaired matching logic. Run it with python3 -I repro.py.
from pathlib import PurePosixPath as Path
def old_key(path: str) -> str:
p = Path(path)
s = str(p)
if "knowledge/blog" in s or "blog" in p.parts:
return f"content:{p.stem}"
if "knowledge/research" in s or "research" in p.parts:
return f"research:{p.stem}"
return f"artifact:{s}"
def new_key(path: str) -> str:
p = Path(path)
parts = p.parts[1:] if p.parts[:1] == (".",) else p.parts
if parts[:2] == ("knowledge", "blog"):
return f"content:{p.stem}"
if parts[:2] == ("knowledge", "research"):
return f"research:{p.stem}"
return f"artifact:{p}"
def is_once_ever(key: str) -> bool:
return key.split(":", 1)[0] in {"content", "research"}
MAP_A = "scripts/research/training/README.md"
MAP_B = "scripts/research/evals/README.md"
NOTE = "knowledge/research/2026-10-24-some-note.md"
POST = "knowledge/blog/2026-10-24-some-post.md"
# old behaviour: the collision
assert old_key(MAP_A) == "research:README"
assert old_key(MAP_B) == "research:README"
assert old_key(MAP_A) == old_key(MAP_B), "two different docs share one key"
assert is_once_ever(old_key(MAP_A)), "and that key is once-ever"
# repaired behaviour
assert new_key(MAP_A) == "artifact:scripts/research/training/README.md"
assert new_key(MAP_B) == "artifact:scripts/research/evals/README.md"
assert new_key(MAP_A) != new_key(MAP_B)
assert not is_once_ever(new_key(MAP_A))
# the real once-ever namespaces are unchanged
for path in (NOTE, POST, "./" + NOTE, "./" + POST):
assert old_key(path) == new_key(path), path
assert new_key(NOTE) == "research:2026-10-24-some-note"
assert new_key(POST) == "content:2026-10-24-some-post"
for label, path in (("map A", MAP_A), ("map B", MAP_B), ("note", NOTE)):
print(f"{label:6} old={old_key(path):42} new={new_key(path)}")
print("all assertions passed")
Output from the run I did while writing this:
map A old=research:README new=artifact:scripts/research/training/README.md
map B old=research:README new=artifact:scripts/research/evals/README.md
note old=research:2026-10-24-some-note new=research:2026-10-24-some-note
all assertions passed
The three rows are the whole story. The two maps collapse to one key under the old rule and stay separate under the new one. The genuine research note keeps its once-ever key either way.
The fix
Match the namespace by the path’s first two components, not by any directory name in it:
parts = p.parts[1:] if p.parts[:1] == (".",) else p.parts
if parts[:2] == ("knowledge", "blog"):
return f"content:{p.stem}"
if parts[:2] == ("knowledge", "research"):
return f"research:{p.stem}"
return f"artifact:{p}"
The leading-. strip keeps ./knowledge/... working, which the last assertion in the reproducer checks. The repair landed as commit fd580ddcce in my private workspace repo. It comes with tests for the prefix cases, for the training map, and for a guard that every registered living map emits a reclaimable artifact: key.
How it surfaced
Nothing failed. A drift probe that lists the docs I should keep current also prints the claim key for each one. The training map’s line read claim: research:README. A once-ever namespace attached to a doc that only makes sense as a living one was the tell. A previous session had already moved the other living maps to artifact: keys, but patched the callers instead of the function they all went through, so this one path kept the bad answer.
What I took from it
- Substring and
in partsmatching on paths is a trap. A directory name appears in unrelated places. If a namespace means “this subtree”, test the subtree prefix. - A key that drops the path loses uniqueness.
research:READMEcould only ever have been correct for one file. When the stem is the identity, two files with the same stem are a collision waiting for a second file. - Fix the shared function, not each caller. The earlier patch fixed the symptom for the paths people had noticed. The function still returned the wrong answer to everyone else.
- Write the failing assertion first. The reproducer is the test. If it passes on the old code, you have not found the bug yet.