diff --git a/board-service/README.md b/board-service/README.md index a874907..7fa1dcc 100644 --- a/board-service/README.md +++ b/board-service/README.md @@ -24,10 +24,13 @@ covered. `FACT`, `OBSERVED`, `FAIL` and `CLAIM` content is capped at 100 characters; `PATCH_SUMMARY` at 300. Claims are hidden from live reads and turn-start -snapshots after one hour by default. The recent view holds at most 2,000 entries -and replaces an author's earlier patch summary -with the same `delegation_id` work label. A matching `FAIL` invalidates that -author's latest candidate. MySQL retains all admitted revisions for grep. +snapshots after one hour by default, or immediately upon work completion +(`PATCH_SUMMARY` matching the delegation/issue), renewal, or explicit release +(via `ttl_seconds=0` or release/abandon keywords). The recent view holds at most +2,000 entries and replaces an author's earlier patch summary with the same +`delegation_id` work label. A matching `FAIL` (by the author or a peer citing +the thread) invalidates that latest candidate. MySQL retains all admitted +revisions for grep. `GET /snapshot` returns unread context across requested boards and advances the viewer's cursors when fetched. `GET /board/{board_id}/read` renders the diff --git a/board-service/mcp.cjs b/board-service/mcp.cjs index 6c8221d..3a4cd7b 100755 --- a/board-service/mcp.cjs +++ b/board-service/mcp.cjs @@ -124,16 +124,22 @@ const TOOLS = [ "of peers reading a stale candidate, and a FAIL strikes your own patch " + "summary. A fresh id per note silently disables both.", }, + ttl_seconds: { + type: "number", + description: + "Optional TTL in seconds for CLAIM notes (pass 0 to immediately release an active claim).", + }, }, required: ["board_id", "type", "content"], }, - handler: async ({ board_id, type, content, detail, delegation_id }) => { + handler: async ({ board_id, type, content, detail, delegation_id, ttl_seconds }) => { const r = await httpRequest("POST", `/board/${encodeURIComponent(board_id)}/note`, { thread_id: AGENT, type, content, detail: detail || null, delegation_id: delegation_id || null, + ttl_seconds: typeof ttl_seconds === "number" ? ttl_seconds : null, }); if (r.status >= 500) throw new Error(`board_write ${r.status}: ${r.text}`); return JSON.stringify(r.json || { status: "error", detail: r.text }); diff --git a/board-service/shared_lessons.py b/board-service/shared_lessons.py index 65b8720..12bafd2 100644 --- a/board-service/shared_lessons.py +++ b/board-service/shared_lessons.py @@ -31,6 +31,11 @@ def _rel_min(seconds: float) -> float: r"\b(pass(?:ed|es)?|verified|confirmed|no longer|now returns|now produces)\b", re.IGNORECASE, ) +_CLAIM_RELEASE_RE = re.compile( + r"\b(release[ds]?|abandon(?:ed)?|cancel(?:ed|led)?|done)\b", re.IGNORECASE +) +_ISSUE_REFERENCE_RE = re.compile(r"(? Optional[str]: @@ -100,6 +105,44 @@ def _admit(self, entry: Dict[str, Any]) -> None: entry["_verified_checkpoint"] = True norm_delegation = entry.get("delegation_id") norm_thread = entry["thread_id"] + now_ts = float(entry.get("ts", time.time())) + + # Release author's prior active claim on work completion (PATCH_SUMMARY). + if type == "PATCH_SUMMARY": + issues = set(_ISSUE_REFERENCE_RE.findall(content)) + for e in self._entries: + if e.get("type") == "CLAIM" and e.get("thread_id") == norm_thread: + matches_deleg = ( + norm_delegation is not None + and e.get("delegation_id") == norm_delegation + ) + matches_issue = bool( + issues and set(_ISSUE_REFERENCE_RE.findall(str(e.get("content", "")))) & issues + ) + if matches_deleg or matches_issue: + e["_expires_at"] = min(float(e.get("_expires_at", now_ts)), now_ts) + + # Handling CLAIM renewals, superseding prior claims, and explicit releases. + if type == "CLAIM": + is_explicit_release = bool( + (entry.get("_expires_at") is not None and float(entry["_expires_at"]) <= now_ts) + or _CLAIM_RELEASE_RE.search(content) + ) + if is_explicit_release: + entry["_expires_at"] = now_ts + issues = set(_ISSUE_REFERENCE_RE.findall(content)) + for e in self._entries: + if e.get("type") == "CLAIM" and e.get("thread_id") == norm_thread: + matches_deleg = ( + norm_delegation is not None + and e.get("delegation_id") == norm_delegation + ) + matches_issue = bool( + issues and set(_ISSUE_REFERENCE_RE.findall(str(e.get("content", "")))) & issues + ) + if matches_deleg or matches_issue: + e["_expires_at"] = min(float(e.get("_expires_at", now_ts)), now_ts) + if type == "PATCH_SUMMARY": fail_count = self._delegation_fail_count( self._entries, norm_thread, norm_delegation @@ -121,6 +164,24 @@ def _admit(self, entry: Dict[str, Any]) -> None: e["_invalidated_by_fail"] = content[:MAX_CONTENT_CHARS] e["_local_fail_count"] = fail_count break + + # A peer counterexample citing target thread (e.g. "t1" or "@worker1") + # invalidates that peer's latest patch checkpoint. + peer_match = _PEER_THREAD_RE.search(content) + if peer_match: + peer_num = peer_match.group(1) + for e in reversed(self._entries): + if e.get("type") == "PATCH_SUMMARY": + target_tid = str(e.get("thread_id", "")) + if ( + target_tid == peer_num + or target_tid.endswith(f"-worker{peer_num}") + or target_tid == f"worker{peer_num}" + ): + e.pop("_verified_checkpoint", None) + e["_invalidated_by_fail"] = content[:MAX_CONTENT_CHARS] + e["_local_fail_count"] = int(e.get("_local_fail_count", 0)) + 1 + break if type == "PATCH_SUMMARY": existing_idx: Optional[int] = None for i in range(len(self._entries) - 1, -1, -1): diff --git a/board-service/tests/test_shared_lessons.py b/board-service/tests/test_shared_lessons.py index d409e68..22823ad 100644 --- a/board-service/tests/test_shared_lessons.py +++ b/board-service/tests/test_shared_lessons.py @@ -91,6 +91,28 @@ def test_identical_claims_are_not_merged(self): run(self.board.note(2, "CLAIM", "same")) self.assertEqual(len(run(self.board.read())), 2) + def test_claim_released_when_patch_summary_posted(self): + run(self.board.note(1, "CLAIM", "#7: add parser", delegation_id="p1")) + self.assertEqual(len(run(self.board.read())), 1) + run(self.board.note(1, "PATCH_SUMMARY", "files=a.py | idea=fix #7 | evidence=tests pass", delegation_id="p1")) + # The active claim should be expired/released now + claims = [e for e in run(self.board.read()) if e["type"] == "CLAIM"] + self.assertEqual(claims, []) + + def test_claim_explicit_release_via_keyword(self): + run(self.board.note(1, "CLAIM", "claim #10: refactor")) + self.assertEqual(len(run(self.board.read())), 1) + run(self.board.note(1, "CLAIM", "release #10")) + claims = [e for e in run(self.board.read()) if e["type"] == "CLAIM"] + self.assertEqual(claims, []) + + def test_subsequent_claim_supersedes_prior_claim(self): + run(self.board.note(1, "CLAIM", "#5: attempt 1", delegation_id="d1")) + run(self.board.note(1, "CLAIM", "#5: attempt 2", delegation_id="d1")) + active_claims = [e for e in run(self.board.read()) if e["type"] == "CLAIM"] + self.assertEqual(len(active_claims), 1) + self.assertEqual(active_claims[0]["content"], "#5: attempt 2") + class PatchSummaryTest(unittest.TestCase): def setUp(self): @@ -141,6 +163,19 @@ def test_new_revision_carries_prior_failures(self): entry = run(self.board.note(1, "PATCH_SUMMARY", "files=a | idea=b | evidence=x", delegation_id=3)) self.assertEqual(entry["_local_fail_count"], 1) + def test_peer_fail_invalidates_peer_patch_summary(self): + run(self.board.note(1, "PATCH_SUMMARY", "files=a | idea=b | evidence=tests passed", delegation_id=1)) + # Peer worker 2 reports a failure citing t1 + run(self.board.note(2, "FAIL", "tested t1: fails with division by zero")) + entries = run(self.board.read_all()) + patch = [e for e in entries if e["type"] == "PATCH_SUMMARY"][0] + self.assertNotIn("_verified_checkpoint", patch) + self.assertEqual(patch["_invalidated_by_fail"], "tested t1: fails with division by zero") + self.assertEqual(patch["_local_fail_count"], 1) + line = self.board.format_entry_line(patch) + self.assertTrue(line.endswith("[status=invalidated,local_failures=1]"), line) + + class DedupeTest(unittest.TestCase): def setUp(self):