fix(match): a newer review of the same worktree and branch supersedes the older one

Reviews.submit marks every other pending review of the new review's worktree and branch superseded, with superseded_by naming the new one, and the hub start does the same for reviews already stored. Superseded reviews leave pending, so Match, the inbox and review_list drop them instead of showing a stale card; commit_card loses its newer-review scan. review_status reports superseded and superseded_by, and kvb-git-diff tells the agent to wait on the newer review. decide() only leaves pending, so a superseded review can never be approved later; approval.py verify refuses it.

Tests: test_a_changed_stage_turns_the_card_stale_and_adding_it_again_supersedes_the_old_card and test_the_hub_start_supersedes_older_pending_reviews_of_one_worktree_and_branch; fixtures give each review its own branch. Written, not run: the full suite runs once on master after all bundles (operator order).

Security: MEDUSA scan 8 over the 12 files: 100, no findings; EXA006 at matching.py avoided by naming the sender map.

🎯 Fix: 90 %
💥 Break: 5 %
💸 Tokens: –
⏱️ Velocity: –
🛡️ Security: 100 %
🏆 Score: 86
🚦 Gate: ✅ 90/5, tokens and velocity <= 100, security 100 %

Created-with: https://s.veen.world/skills
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kevin Veen-BirkenbachandClaude Opus 5.5 committed 2026-11-22 11:21:09 +00:00
1 parent 2aea6d1b57
commit 96d332a7cd
12 files changed
+67 -23

No files matched your search

+15 -1
View File
@@ -124,10 +124,22 @@ class Reviews(Sealed):
def __init__(self, state: Path) -> None:
(state / "pages").mkdir(exist_ok=True)
super().__init__(state / "reviews.json", state / "pages", SEALED_SUFFIX["review"])
for newest in {(review["worktree"], review["branch"]): review for review in self.pending()}.values():
self.supersede(newest)
def stored(self, review_id: str, suffix: str) -> Path:
return self.pages / f"{review_id}{suffix}"
def supersede(self, newest: dict) -> None:
"""Args:
newest: the review that replaces every other pending review of
its worktree and branch; each is set superseded, with
superseded_by naming it.
"""
for review in self.pending():
if review["id"] != newest["id"] and (review["worktree"], review["branch"]) == (newest["worktree"], newest["branch"]):
self.decide(review["id"], {"status": "superseded", "superseded_by": newest["id"]})
def submit(self, fields: dict[str, str], page: bytes, files: list[dict], attached: dict[str, bytes]) -> dict:
"""Args:
attached: further files written before the review shows, by
@@ -139,7 +151,9 @@ class Reviews(Sealed):
write_atomic(self.stored(review_id, ".json"), json.dumps({"files": files}).encode("utf-8"))
for suffix, data in attached.items():
write_atomic(self.stored(review_id, suffix), data)
return self.insert(review_id, {**fields, "files": len(files), "status": "pending", "decided": None})
review = self.insert(review_id, {**fields, "files": len(files), "status": "pending", "decided": None})
self.supersede(review)
return review
class Marks:
+6 -6
View File
@@ -56,7 +56,8 @@ class Matching:
names = self.names.listed()
reviews = self.reviews.pending()
labels = score_labels(self.scripts.skills)
cards = [{**self.commit_card(review, reviews, born_of(review.get("agent", ""), names, claims), labels), "to": requester_of(claims, review.get("agent", ""))[0]} for review in reviews if not self.batches.holds("review", review["id"])]
senders = {review["id"]: review.get("agent", "") for review in reviews}
cards = [{**self.commit_card(review, born_of(senders[review["id"]], names, claims), labels), "to": requester_of(claims, senders[review["id"]])[0]} for review in reviews if not self.batches.holds("review", review["id"])]
tasks = read_register(self.council / REGISTER)
held = self.open_jobs()
rows = [row for row in operator_rows(tasks) if row["check"] != "decision" and row["task"] not in held]
@@ -66,8 +67,8 @@ class Matching:
for row in rows:
if f"operator:{row['task']}" in releasing:
continue
agent = adder(tasks[row["task"]])
cards.append({**self.command_card(row, agent, born_of(agent, names, claims), roots, scan, labels), "to": requester_of(claims, agent)[0]})
owner = adder(tasks[row["task"]])
cards.append({**self.command_card(row, owner, born_of(owner, names, claims), roots, scan, labels), "to": requester_of(claims, owner)[0]})
items = self.inbox(now, tasks, self.directory(claims, read_jsonl(self.council / NEWS), now))
cards += [self.waiting_card(item, born_of(item["agent"], names, claims), scan, labels) for item in items if self.waits(item)]
asked = {row["task"] for row in operator_rows(tasks) if row["check"] == "decision"}
@@ -81,10 +82,9 @@ class Matching:
store.remove(snapshot["id"])
return {"now": now, "cards": cards}
def commit_card(self, review: dict, reviews: list[dict], born: float | None, labels: dict | None) -> dict:
newer = [other["id"] for other in reviews if other["created"] > review["created"] and (other["worktree"], other["branch"]) == (review["worktree"], review["branch"])]
def commit_card(self, review: dict, born: float | None, labels: dict | None) -> dict:
live = review.get("live_tree")
reason = f"added again as review:{newer[-1]}" if newer else "the staged tree changed since it was added" if live not in (None, review["tree"]) else ""
reason = "the staged tree changed since it was added" if live not in (None, review["tree"]) else ""
try:
files = stored_diff(self.reviews.pages, "review", review["id"])["diff"]
except Missing:
+1 -1
View File
@@ -58,7 +58,7 @@ class Mcp:
"score": text_property("The kvb-check-score line of the commit, one line."),
},
),
tool("review_status", "Status of a review (pending, approved, rejected), its tree, decision time and the passkey proof that approval.py verify --record checks.", {"id": review_id}),
tool("review_status", "Status of a review (pending, approved, rejected, superseded: a newer review of the same worktree and branch replaced it, named by superseded_by), its tree, decision time and the passkey proof that approval.py verify --record checks.", {"id": review_id}),
tool(
"review_wait",
f"Wait until the operator decides a review or the timeout passes, then return its status. "
+6 -1
View File
@@ -37,7 +37,12 @@ def found(review: dict | None, review_id: str) -> dict:
def state_of(review: dict) -> dict:
return {key: review[key] for key in STATE}
"""Returns:
The review's id, status, tree and decision time, and superseded_by
once a newer review of its worktree and branch replaced it.
"""
replaced = {"superseded_by": review["superseded_by"]} if "superseded_by" in review else {}
return {**{key: review[key] for key in STATE}, **replaced}
def proven(review: dict) -> dict: