code-coordinator 0.5.415__py3-none-any.whl → 0.5.416__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: code-coordinator
3
- Version: 0.5.415
3
+ Version: 0.5.416
4
4
  Summary: Coordinate Claude Code workers across multiple machines and repos.
5
5
  Author-email: John Donaghy <johnfdonaghy@gmail.com>
6
6
  License-Expression: LicenseRef-FSL-1.1-MIT
@@ -1,4 +1,4 @@
1
- code_coordinator-0.5.415.dist-info/licenses/LICENSE,sha256=851BVZZwf_pEv2ydSlMmcZrwnwSS5YJ98wdLze7lyL8,4212
1
+ code_coordinator-0.5.416.dist-info/licenses/LICENSE,sha256=851BVZZwf_pEv2ydSlMmcZrwnwSS5YJ98wdLze7lyL8,4212
2
2
  coord/__init__.py,sha256=3FN2qrrxtW87xSsSD557YcMwHLDahnFK8LvqQI7Wlf4,9783
3
3
  coord/_board_mapping.py,sha256=5FTW-8Dg5SzHvszdFj9MuAirpe2KmRqgipZWBAhgUJI,11627
4
4
  coord/acceptance.py,sha256=oAec-wQbrcR5PPfI9NW8JJYipfQ9-3EDpmMmxrP3pQM,90211
@@ -39,7 +39,7 @@ coord/deploy_manifest.py,sha256=X-deE_n6oRfDQDRSqcnLCEiLUMXbgKqgBUaoU1MD1hg,8103
39
39
  coord/deploy_units.py,sha256=ZfFueMPXKW4u8geOMEHhmgyseUPuKWNub77NDjMNrHA,24097
40
40
  coord/deprecation_telemetry.py,sha256=ZK6wmN3qzF2-Ic1iVpYSC8Y4gw1sA0sJnerErzgKAI8,4149
41
41
  coord/deps.py,sha256=WnV5u_zYw_f3oMr88Qy7EUVeb3vBj5cTq8Ts1oGAR2s,3770
42
- coord/diagnose.py,sha256=6dyQwHWL7zD1X0lpzKn596h1gPw5hmw2Kk4QNrGkSCk,99433
42
+ coord/diagnose.py,sha256=VCLUvNCQeZ-80uTUSiq8u6FqkSZFN0IdVioKlj2D77I,104544
43
43
  coord/dispatch.py,sha256=9TqGs0Mb_IBwmNVav2WnWapjGWLucJWD8PXUOsyEl70,59218
44
44
  coord/dist_name.py,sha256=XDhumYscJahwcaKjmSw135HYsnXQjwGGxRo0Qv4b0xM,5583
45
45
  coord/dr_promote.py,sha256=xS9fFvzrY-EjSEj1XMSwD7RtjbBhhXZT76XFLnddDng,60329
@@ -64,8 +64,8 @@ coord/goal.py,sha256=URYTwPHFU2zpCjrDYoKoItZiNCb8EMaOzMTOfY51dSs,5198
64
64
  coord/graph_health.py,sha256=VN9Eg3uTMlcQ3Hm-tNUhW0-LjMsBp7To_jd5-avdfkI,29823
65
65
  coord/hooks.py,sha256=fdEwUf1zGF7xFm9TqlTda94EmtH2Tl8NNVeD-JfpkvA,3968
66
66
  coord/housekeeping.py,sha256=mHCyewO8w-XWesEFSn3GUuVeSP2Jz7uSHAOoLoll2nY,10510
67
- coord/interactive.py,sha256=AEK-5S2aMknpP6k3Xx-aBuTEulw0_c-gbYPEKTwUjRE,219083
68
- coord/issue_store.py,sha256=mI22xBCLQ1IgnsEpcQCr14LbeJaztPzLV-NW7m89RiU,74106
67
+ coord/interactive.py,sha256=L8wMrKV-ykh--TGjVLLZFa5S0KKdiVN8Q28wpMfTVio,220556
68
+ coord/issue_store.py,sha256=T9vp_TpD6v7cjsZkEnVQYt9hSJwZcoksRq7hQsMwN_I,74000
69
69
  coord/issues_sync_status.py,sha256=_6ucx7oW3TUGZZvs93wRbzR_SUQcNlz-7RptOzr4alo,9262
70
70
  coord/liveness_auditor.py,sha256=sf_xBklt37DUnrIEeD4fVp4_gWPDaXbydZgfuWAPFRE,12478
71
71
  coord/machine_metrics.py,sha256=paWqBTZgeIi7w1pgH5QSJL59UxwetxE8bXblzzcspSI,16300
@@ -111,7 +111,7 @@ coord/repo_onboard.py,sha256=HRm-SALgUNcp6h0Zr5B1kR-4RH-6jBucpTZ3-BCL6wY,94132
111
111
  coord/reports.py,sha256=7pAdEGUjWyKTqZ3EKeeg6_jrtOTC7WMKbOvonirFRsQ,170794
112
112
  coord/rest_schema.py,sha256=RymD01eTPN8ckVZEyMlDXlcc5riKjQeCnAtFzuLOuWs,12063
113
113
  coord/revalidate.py,sha256=fQaYCvObqUawSZWMEOkVWFtYswz9PQQwSMApAyP5zeA,66266
114
- coord/review.py,sha256=Xx-91E4U_u-QE37onmFTE5NegWmmOrEyMSdG93aix-k,235404
114
+ coord/review.py,sha256=_-jWVtySdXROojobPynssAbJF4SyK1Y97xaaE1V9fYE,236013
115
115
  coord/scorecard.py,sha256=axe_doBJBBFWtN21JZDRSijwDI0xaZrt2oVYbwJPW7U,20211
116
116
  coord/self_health.py,sha256=9PLVdaEReFLUY6y2QXMGVd6U1CdHAh9_8MzduwBOzAY,10651
117
117
  coord/serve_app.py,sha256=WxyeNtwiqxpVbI344vC7zarpe993cZnFsPCPpicnfKc,540068
@@ -120,7 +120,7 @@ coord/spend_ceiling.py,sha256=hfuiXlnD4or7Wqoqf6BHcOMT2CXd92FBZuVdnQVlI2M,13573
120
120
  coord/split_work.py,sha256=Gp_cNtYBe7nDxBN7cDRs8CJG3V_Y0C1QUi35fHGcvnY,8502
121
121
  coord/sql.py,sha256=wOXKh4b5cJT1KYi4GTp6USBnAQOuFt4S08x0DINkaS0,62734
122
122
  coord/stage_projection.py,sha256=BtVNqOOnv5mttJbdoSBC8QES5Nh-bzkkdWBlrFuT-D8,52012
123
- coord/state.py,sha256=PMbNaydsngvYUk4oN3fs_mAmkuRlnIeVs9bd1yHl4ow,345408
123
+ coord/state.py,sha256=88tqlQoWek_YJvH6u4uGccSWtfLSjo2IqgDs2zFAFPM,351674
124
124
  coord/store_migrate.py,sha256=NFB7BT41OkedR9oGl8br2xGKlBKJVVwaLhmyfgEc0Rg,39163
125
125
  coord/store_parity.py,sha256=wCmGUSYXZPtEhYMaw4H-JpY3QdcKL-op9m81nNSfM3Q,20111
126
126
  coord/test_author.py,sha256=CCLMyEDpLE1bjancrmiqvemzBJD-JToINMSSov4vY2o,60120
@@ -267,8 +267,8 @@ coord/skills/review-verdict-recovery/SKILL.md,sha256=Grg8GWkJLK20ct2YiigbTFfNOki
267
267
  coord/skills/tui-quadraui-workflow/SKILL.md,sha256=4hUZza9wSSnPhf0eRAOh2r_MQZxK2pXYO5g-kxmJq-U,3832
268
268
  coord/skills/update-issue/SKILL.md,sha256=VrPinEmLZrCSNDrnz96hQomyO403o5c4i0RdsnUnWA0,3642
269
269
  coord/templates/deploy-cloudflare.node.yml,sha256=icsTiWn2ziQJnpZODhhFKYlnqjt2xAXsbwlQufdxhuM,2078
270
- code_coordinator-0.5.415.dist-info/METADATA,sha256=e9HaJgQkUUQSHo7vwPQY3H_l-Oc34DkBKm2pRl87KQk,27178
271
- code_coordinator-0.5.415.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
272
- code_coordinator-0.5.415.dist-info/entry_points.txt,sha256=o-Hq8pvG7ReGePvN_4iOKjLNqiq-MJ43HbPurqjNPZo,41
273
- code_coordinator-0.5.415.dist-info/top_level.txt,sha256=w5sTrXesTCebhXyYv2qufOZGo0PoD1Lxgn0Q3MAXjh4,6
274
- code_coordinator-0.5.415.dist-info/RECORD,,
270
+ code_coordinator-0.5.416.dist-info/METADATA,sha256=aoXhOAKZSruUSPx_nrYhqy_AOvsEwwaPA35qT5W2ex4,27178
271
+ code_coordinator-0.5.416.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
272
+ code_coordinator-0.5.416.dist-info/entry_points.txt,sha256=o-Hq8pvG7ReGePvN_4iOKjLNqiq-MJ43HbPurqjNPZo,41
273
+ code_coordinator-0.5.416.dist-info/top_level.txt,sha256=w5sTrXesTCebhXyYv2qufOZGo0PoD1Lxgn0Q3MAXjh4,6
274
+ code_coordinator-0.5.416.dist-info/RECORD,,
coord/diagnose.py CHANGED
@@ -709,7 +709,56 @@ def diagnose_stage(
709
709
  def _recover_review(
710
710
  board, config, latest, state, res: DiagnoseResult, *, dry_run: bool
711
711
  ) -> None:
712
- from coord.state import load_assignment_review_findings # noqa: PLC0415
712
+ from coord.state import has_review_claim, load_assignment_review_findings # noqa: PLC0415
713
+
714
+ # #3206: a review row that has no live session left (status is already
715
+ # terminal — the `running`/`pending` + machine-unconfigured phantom case
716
+ # above already returned before reaching here, and #1180's "resolve the
717
+ # reviewed id" comment on `_do_reset` explains why `review_of_assignment_
718
+ # id` is the FK to check) but whose work assignment's `review_claims` row
719
+ # is STILL held is permanently wedged: every future `dispatch_review` for
720
+ # that work assignment loses `claim_review_dispatch` forever and denies
721
+ # with the misleading #3113 "lost the atomic dispatch-claim race" reason
722
+ # — even though nothing is racing. `latest.status not in ("running",
723
+ # "pending")` is a positive disproof that anything is still in flight to
724
+ # release it itself, so this is checked FIRST, before any of the
725
+ # per-shape branches below: none of the "healthy"/"recovered" outcomes
726
+ # they report are actually dispatchable while the claim is held (this is
727
+ # exactly the coord-tui#49 repro — a SIGKILLed review that reached
728
+ # `status=failed` and then reported "review stage looks healthy").
729
+ # #3206 fix-review note: there is a narrow, real false-positive window
730
+ # here on a legitimate re-review. `dispatch_review` (review.py) takes
731
+ # `claim_review_dispatch` BEFORE it ever inserts the new review's
732
+ # `assignments` row. If this function runs in that gap, `latest` above
733
+ # still resolves to the *previous* terminal review row, `has_review_claim`
734
+ # is now True (it's the new, in-flight dispatch's claim, not a leak), and
735
+ # this would misreport a leaked claim — with `--reset` then releasing a
736
+ # claim a live dispatch still needs. No known way to distinguish the two
737
+ # cases from this read alone (both look like "terminal review row +
738
+ # live claim"); flagged here rather than fixed, since fixing it would
739
+ # need `dispatch_review` to expose in-flight state this function can
740
+ # check first.
741
+ work_assignment_id = (
742
+ latest.review_of_assignment_id
743
+ if latest.type == "review" and latest.review_of_assignment_id
744
+ else latest.assignment_id
745
+ )
746
+ if (
747
+ latest.status not in ("running", "pending")
748
+ and work_assignment_id
749
+ and has_review_claim(work_assignment_id)
750
+ ):
751
+ res.findings.append(
752
+ f"review stage is terminal (status={latest.status!r}) but its "
753
+ f"review-dispatch claim for work assignment {work_assignment_id} "
754
+ "is still held (leaked review_claims row, #3206) — every future "
755
+ "dispatch_review for this work assignment will deny with the "
756
+ "misleading #3113 'lost the atomic dispatch-claim race' reason "
757
+ "until it is released. Re-run with --reset to release it."
758
+ )
759
+ res.recovered = False
760
+ res.needs_reset = True
761
+ return
713
762
 
714
763
  has_findings = False
715
764
  if latest.assignment_id:
@@ -1408,7 +1457,43 @@ def _reset_review_stage(
1408
1457
  repo_name, issue_number, types=("review",),
1409
1458
  review_of_assignment_id=assignment_id,
1410
1459
  )
1411
- res.actions_taken.append(f"deleted {deleted} review row(s) → stage grey")
1460
+ # #3206: VERIFY the delete actually persisted before reporting it as an
1461
+ # action taken — `delete_assignments_for_issue`'s own `cur.rowcount`
1462
+ # only proves the DELETE statement was issued and committed on ITS
1463
+ # connection; it is not proof the row is gone from the canonical board
1464
+ # (the coord-tui#49 `--reset` run reported "deleted 1 review row(s)"
1465
+ # while `f00d5e20670c` was still present, unchanged, on the daemon's
1466
+ # board immediately afterward). A re-read against the same predicate,
1467
+ # taken AFTER the write, is the observation #2096 requires before a
1468
+ # success line is trustworthy — the claim-release and review_state
1469
+ # writes below already get exactly this scrutiny implicitly, since
1470
+ # their own callers read the board fresh next; the delete's rowcount
1471
+ # was the one unverified "success" in this function.
1472
+ #
1473
+ # Scope note: this re-read uses the same `get_connection()` singleton,
1474
+ # in the same process, immediately after `conn.commit()` — within a
1475
+ # single connection it cannot observe a delete that "didn't stick" the
1476
+ # way the original coord-tui#49 evidence looked (the daemon's board
1477
+ # still showing the row afterward implies a *different* connection/
1478
+ # process saw stale state, not this one). What this DOES still catch:
1479
+ # a genuine concurrent insert/delete race from another connection or
1480
+ # process, and any future predicate mismatch between the delete and
1481
+ # this re-read. It is narrower than "verify the delete actually
1482
+ # persisted" sounds, but it's a real gate, not a tautology — see
1483
+ # `tests/test_diagnose.py`'s coverage that mocks
1484
+ # `delete_assignments_for_issue`'s rowcount to exercise the failure path.
1485
+ still_present = state.count_review_rows_for_reset(
1486
+ repo_name, issue_number, review_of_assignment_id=assignment_id
1487
+ )
1488
+ if still_present:
1489
+ res.actions_taken.append(
1490
+ f"delete requested for {deleted} review row(s), but "
1491
+ f"{still_present} still present on re-read — the row delete did "
1492
+ "NOT persist (#3206); stage grey/re-reviewable status below "
1493
+ "does not depend on this delete having landed"
1494
+ )
1495
+ else:
1496
+ res.actions_taken.append(f"deleted {deleted} review row(s) → stage grey")
1412
1497
  # #3113: the raw DELETE above never goes through
1413
1498
  # ``coord.issue_store._update_local_state`` — the ONLY other seam that
1414
1499
  # releases a ``review_claims`` row (on a review assignment's own
coord/interactive.py CHANGED
@@ -4362,7 +4362,11 @@ def reap_stale_interactive_sessions(
4362
4362
  return []
4363
4363
 
4364
4364
  from coord import sql # noqa: PLC0415
4365
- from coord.state import COORD_DIR, get_connection # noqa: PLC0415
4365
+ from coord.state import ( # noqa: PLC0415
4366
+ COORD_DIR,
4367
+ get_connection,
4368
+ release_review_claim_if_row_is_review,
4369
+ )
4366
4370
 
4367
4371
  if worktrees_dir is None:
4368
4372
  worktrees_dir = COORD_DIR / "worktrees"
@@ -4488,6 +4492,18 @@ def reap_stale_interactive_sessions(
4488
4492
  (terminal_status, now, a.assignment_id),
4489
4493
  )
4490
4494
  conn.commit()
4495
+ # #3206: this raw SQL terminal-status write bypasses
4496
+ # `coord.issue_store._update_local_state`, so an interactively
4497
+ # dispatched (`provider_name="claude-pty"`) type="review" leg
4498
+ # reaped here (the Work→Review handoff and the `coord review
4499
+ # <id>` escape hatch both dispatch one, per review.py:3789-3795)
4500
+ # would otherwise leak its `review_claims` row exactly like the
4501
+ # headless reaper path did before #3206 — wedging every later
4502
+ # `dispatch_review` for the same work assignment behind the
4503
+ # misleading #3113 "lost the atomic dispatch-claim race" denial.
4504
+ # Safe to call unconditionally: it's a no-op for any row whose
4505
+ # type isn't "review".
4506
+ release_review_claim_if_row_is_review(a.assignment_id)
4491
4507
  except Exception: # noqa: BLE001
4492
4508
  pass # non-fatal — the board update below still releases the claim
4493
4509
 
@@ -4568,7 +4584,10 @@ def _mark_stale_reap_in_db(assignment_id: str, status: str, finished_at: float)
4568
4584
  """
4569
4585
  try:
4570
4586
  from coord import sql # noqa: PLC0415
4571
- from coord.state import get_connection # noqa: PLC0415
4587
+ from coord.state import ( # noqa: PLC0415
4588
+ get_connection,
4589
+ release_review_claim_if_row_is_review,
4590
+ )
4572
4591
  conn = get_connection()
4573
4592
  sql.execute(
4574
4593
  conn,
@@ -4577,6 +4596,13 @@ def _mark_stale_reap_in_db(assignment_id: str, status: str, finished_at: float)
4577
4596
  (status, finished_at, assignment_id),
4578
4597
  )
4579
4598
  conn.commit()
4599
+ # #3206: this raw SQL terminal-status write is the remote-fallback
4600
+ # sibling of reap_stale_interactive_sessions's DB update above and
4601
+ # bypasses `coord.issue_store._update_local_state` the same way —
4602
+ # release the review-dispatch claim here too so a reaped remote
4603
+ # interactive review doesn't leak its `review_claims` row. No-op
4604
+ # for any row whose type isn't "review".
4605
+ release_review_claim_if_row_is_review(assignment_id)
4580
4606
  except Exception: # noqa: BLE001
4581
4607
  pass
4582
4608
 
coord/issue_store.py CHANGED
@@ -287,36 +287,28 @@ def _update_local_state(
287
287
  )
288
288
  conn.commit()
289
289
 
290
- # #3113: this is the generic chokepoint where ANY assignment (review,
291
- # smoke, work, ...) transitions to a terminal status — the same moment
292
- # `coord.claim.has_active_followup` starts reporting "not in flight"
293
- # (board partitioning keys off exactly this status, #_board_mapping.
294
- # _ACTIVE_STATUSES). A `type="review"` row leaving the active state is
295
- # therefore exactly when its dispatch-time claim (coord.state.
290
+ # #3113/#3206: this is the generic chokepoint where ANY assignment
291
+ # (review, smoke, work, ...) transitions to a terminal status — the same
292
+ # moment `coord.claim.has_active_followup` starts reporting "not in
293
+ # flight" (board partitioning keys off exactly this status, #_board_
294
+ # mapping._ACTIVE_STATUSES). A `type="review"` row leaving the active
295
+ # state is therefore exactly when its dispatch-time claim (coord.state.
296
296
  # claim_review_dispatch) must be released — otherwise a legitimate later
297
297
  # re-review of the same work assignment (the `coord review <id>` escape
298
- # hatch) would find the claim still held forever. Best-effort: a lookup
299
- # failure here must never turn a successful status write into a raised
300
- # exception.
301
- try:
302
- row = sql.execute(
303
- conn,
304
- "SELECT type, review_of_assignment_id FROM assignments WHERE assignment_id=?",
305
- (assignment_id,),
306
- ).fetchone()
307
- if row is not None:
308
- row_type = row["type"] if hasattr(row, "keys") else row[0]
309
- row_of_id = (
310
- row["review_of_assignment_id"] if hasattr(row, "keys") else row[1]
311
- )
312
- if row_type == "review" and row_of_id:
313
- from coord.state import ( # noqa: PLC0415
314
- _release_review_dispatch_claim_local,
315
- )
316
-
317
- _release_review_dispatch_claim_local(row_of_id)
318
- except Exception: # noqa: BLE001 — best-effort; never break the status write
319
- pass
298
+ # hatch) would find the claim still held forever.
299
+ #
300
+ # #3206: the type/review_of_assignment_id check + release used to be
301
+ # duplicated inline here AND, independently, missing entirely from
302
+ # `coord.state._mark_notified_local` (the `coord notify` polling path a
303
+ # reaper-killed headless review's terminal write goes through when no
304
+ # daemon reconcile tick got there first) — the exact "two surfaces, two
305
+ # implementations" split-brain #2096 warns about, and how a SIGKILLed
306
+ # review's claim leaked forever (coord-tui#49). Both seams now call the
307
+ # same `coord.state.release_review_claim_if_row_is_review` — one
308
+ # question, one answer.
309
+ from coord.state import release_review_claim_if_row_is_review # noqa: PLC0415
310
+
311
+ release_review_claim_if_row_is_review(assignment_id)
320
312
 
321
313
 
322
314
  def _record_notification(
coord/review.py CHANGED
@@ -2870,9 +2870,18 @@ def dispatch_review(
2870
2870
  # `completed.assignment_id`; the loser denies here, before spending
2871
2871
  # anything on a candidate machine. Released by every subsequent
2872
2872
  # `_deny(...)` call in this function (see `_claim_held` above) and, once
2873
- # this call succeeds through to a real dispatch, by the review
2874
- # assignment's own terminal-status write (`coord.issue_store.
2875
- # _update_local_state`) — never left permanently held.
2873
+ # this call succeeds through to a real dispatch, by every seam that can
2874
+ # write the review assignment's own terminal status — all of which now
2875
+ # route through the single `coord.state.
2876
+ # release_review_claim_if_row_is_review` check (#3206):
2877
+ # `coord.issue_store._update_local_state` (worker self-report / git-floor
2878
+ # backstop), `coord.state._mark_notified_local` (the `coord notify`
2879
+ # polling path a headless reap's SIGKILL lands through), and
2880
+ # `coord.interactive.reap_stale_interactive_sessions` /
2881
+ # `_mark_stale_reap_in_db` (the local/remote interactive-session
2882
+ # reapers — dispatch_review is also reachable for a `provider_name=
2883
+ # "claude-pty"` type="review" leg, see the Work→Review handoff below).
2884
+ # Never left permanently held by any of them.
2876
2885
  from coord.state import claim_review_dispatch # noqa: PLC0415
2877
2886
 
2878
2887
  if not claim_review_dispatch(completed.assignment_id):
coord/state.py CHANGED
@@ -2109,6 +2109,18 @@ def _mark_notified_local(
2109
2109
  )
2110
2110
  conn.commit()
2111
2111
 
2112
+ # #3206: this write can be the FIRST (and, absent a daemon reconcile
2113
+ # tick, only) place a review assignment's terminal status ever lands —
2114
+ # e.g. a headless review reaped by `AgentServer._reap`'s 7200s max-wait
2115
+ # SIGKILL, observed here via `coord notify`'s own agent poll rather than
2116
+ # the daemon's passive reconcile tick. Release its review-dispatch claim
2117
+ # the same way `coord.issue_store._update_local_state` does for every
2118
+ # other terminal-status seam — `release_review_claim_if_row_is_review`
2119
+ # is a no-op for the composite `f"{aid}:stuck"`-style keys the four
2120
+ # override events above pass (no row matches that string), so this is
2121
+ # safe to call unconditionally.
2122
+ release_review_claim_if_row_is_review(assignment_id)
2123
+
2112
2124
  # #1036: this is the single funnel every notify.py call site (completion,
2113
2125
  # failure, advisory, stuck, needs-attention, stalled, liveness) reaches —
2114
2126
  # hook here rather than at each of the ~10 mark_notified() call sites.
@@ -2316,6 +2328,39 @@ def _claim_review_dispatch_local(of_assignment_id: str) -> bool:
2316
2328
  return (cur.rowcount or 0) > 0
2317
2329
 
2318
2330
 
2331
+ def has_review_claim(of_assignment_id: str) -> bool:
2332
+ """True when *of_assignment_id* still holds a live ``review_claims`` row
2333
+ (#3206) — the read side of :func:`claim_review_dispatch`/
2334
+ :func:`release_review_dispatch_claim`, used by ``coord diagnose --stage
2335
+ review`` to cross-check a review row's own terminal ``status`` against
2336
+ the claim table, so a leaked claim (one whose releasing write went
2337
+ through a seam other than :func:`release_review_claim_if_row_is_review`)
2338
+ is reported as an unhealthy, undispatchable stage instead of silently
2339
+ passing.
2340
+
2341
+ **Local-DB read only** — unlike ``claim_review_dispatch``/
2342
+ ``release_review_dispatch_claim``, this does NOT route to the daemon via
2343
+ ``board_service``. ``review_claims`` lives on the canonical board (the
2344
+ ``coord serve`` daemon's DB, per this function's own module docs above);
2345
+ a thin client's local ``~/.coord/coord.db`` copy is empty/stale for this
2346
+ table exactly like it is for `build_board()` (`#615`,
2347
+ `_thin_client_local_board_guard`). Giving this its own daemon-routed GET
2348
+ endpoint is tracked separately — see the #3206 issue's closing note on
2349
+ thin-client visibility — so for now this answers correctly on the daemon
2350
+ host (where the local DB IS canonical) and undercounts on a thin client,
2351
+ same known limitation as the rest of this diagnostic path.
2352
+ """
2353
+ if not of_assignment_id:
2354
+ return False
2355
+ conn = get_connection()
2356
+ row = sql.execute(
2357
+ conn,
2358
+ "SELECT 1 FROM review_claims WHERE of_assignment_id=?",
2359
+ (of_assignment_id,),
2360
+ ).fetchone()
2361
+ return row is not None
2362
+
2363
+
2319
2364
  def release_review_dispatch_claim(of_assignment_id: str) -> None:
2320
2365
  """Release a claim taken by :func:`claim_review_dispatch`.
2321
2366
 
@@ -2350,6 +2395,53 @@ def _release_review_dispatch_claim_local(of_assignment_id: str) -> None:
2350
2395
  conn.commit()
2351
2396
 
2352
2397
 
2398
+ def release_review_claim_if_row_is_review(assignment_id: str) -> None:
2399
+ """Release *assignment_id*'s own review-dispatch claim, iff that row is
2400
+ itself a ``type="review"`` assignment (#3206).
2401
+
2402
+ This is the ONE "did a review assignment just reach a terminal status,
2403
+ and if so release the claim it took" check — every seam capable of
2404
+ writing a review row's terminal ``status`` must call this SAME function
2405
+ immediately after its own write, rather than re-deriving the
2406
+ ``type == "review" and review_of_assignment_id`` test independently.
2407
+ Before #3206 there were two such seams reading the row and applying that
2408
+ test on their own: :func:`coord.issue_store._update_local_state` (the
2409
+ worker self-report / git-floor-backstop path) had it; this module's own
2410
+ :func:`_mark_notified_local` (the ``coord notify`` polling path a
2411
+ reaper-killed headless review's terminal write goes through when no
2412
+ daemon reconcile tick got there first) did not. That gap is exactly how
2413
+ a review SIGKILLed by ``AgentServer._reap``'s 7200s max-wait ceiling
2414
+ left its ``review_claims`` row held forever: `_mark_notified_local`
2415
+ wrote ``status='failed'`` and stopped, so every later
2416
+ ``dispatch_review`` for the same work assignment lost
2417
+ ``claim_review_dispatch`` permanently and denied with the misleading
2418
+ "lost the atomic dispatch-claim race — #3113" reason, even though
2419
+ nothing was racing (coord-tui#49, stuck ~11h). One shared function
2420
+ closes the gap for both existing callers and any future one.
2421
+
2422
+ Best-effort: a lookup failure here must never turn a successful status
2423
+ write into a raised exception.
2424
+ """
2425
+ if not assignment_id:
2426
+ return
2427
+ conn = get_connection()
2428
+ try:
2429
+ row = sql.execute(
2430
+ conn,
2431
+ "SELECT type, review_of_assignment_id FROM assignments WHERE assignment_id=?",
2432
+ (assignment_id,),
2433
+ ).fetchone()
2434
+ if row is not None:
2435
+ row_type = row["type"] if hasattr(row, "keys") else row[0]
2436
+ row_of_id = (
2437
+ row["review_of_assignment_id"] if hasattr(row, "keys") else row[1]
2438
+ )
2439
+ if row_type == "review" and row_of_id:
2440
+ _release_review_dispatch_claim_local(row_of_id)
2441
+ except Exception: # noqa: BLE001 — best-effort; never break the status write
2442
+ pass
2443
+
2444
+
2353
2445
  # ── Review-findings tracking ──────────────────────────────────────────────────
2354
2446
 
2355
2447
  def update_assignment_review_findings(
@@ -2539,6 +2631,37 @@ def delete_assignments_for_issue(
2539
2631
  return cur.rowcount
2540
2632
 
2541
2633
 
2634
+ def count_review_rows_for_reset(
2635
+ repo_name: str, issue_number: int, *, review_of_assignment_id: str
2636
+ ) -> int:
2637
+ """Count ``type='review'`` rows still matching
2638
+ :func:`delete_assignments_for_issue`'s own ``review_of_assignment_id``
2639
+ predicate (#3206) — used by ``coord diagnose --reset`` to VERIFY a
2640
+ review-row delete actually persisted before reporting success, rather
2641
+ than trusting the delete call's own rowcount.
2642
+
2643
+ A ``DELETE`` statement's rowcount only proves the statement was issued
2644
+ and committed on its own connection; it is not proof the row is
2645
+ actually gone from the canonical board afterward (the coord-tui#49
2646
+ ``--reset`` run reported "deleted 1 review row(s)" while the row was
2647
+ still present, unchanged, on the daemon's board immediately after —
2648
+ exactly the "unconfirmed success" shape #2096 calls a defect: a
2649
+ reported outcome must come from a re-read taken AFTER the write, never
2650
+ from the write call's own return value alone). Re-querying with a fresh
2651
+ read against the same predicate is that re-read.
2652
+ """
2653
+ if not review_of_assignment_id:
2654
+ return 0
2655
+ conn = get_connection()
2656
+ row = sql.execute(
2657
+ conn,
2658
+ "SELECT COUNT(*) AS c FROM assignments WHERE repo_name=? AND "
2659
+ "issue_number=? AND type='review' AND review_of_assignment_id=?",
2660
+ (repo_name, issue_number, review_of_assignment_id),
2661
+ ).fetchone()
2662
+ return int(row["c"] if hasattr(row, "keys") else row[0])
2663
+
2664
+
2542
2665
  def reset_work_review_state(
2543
2666
  repo_name: str, issue_number: int, *, assignment_id: str | None = None
2544
2667
  ) -> int: