code-coordinator 0.5.712__py3-none-any.whl → 0.5.714__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.712
3
+ Version: 0.5.714
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.712.dist-info/licenses/LICENSE,sha256=851BVZZwf_pEv2ydSlMmcZrwnwSS5YJ98wdLze7lyL8,4212
1
+ code_coordinator-0.5.714.dist-info/licenses/LICENSE,sha256=851BVZZwf_pEv2ydSlMmcZrwnwSS5YJ98wdLze7lyL8,4212
2
2
  coord/__init__.py,sha256=3FN2qrrxtW87xSsSD557YcMwHLDahnFK8LvqQI7Wlf4,9783
3
3
  coord/_board_mapping.py,sha256=SoUZViaiZa2LeXp000Br1SBQxek0l3p9zyQDnwX4Flc,13068
4
4
  coord/acceptance.py,sha256=WspJv7soXc2cSXgn9s78BHD8y0qeGBIyaNmsAl4pYVc,119974
@@ -14,7 +14,7 @@ coord/auto_loop.py,sha256=f2-aDF45BnAL531e3FFG97l2ETBUrW0TRJsnZnpLMl4,108737
14
14
  coord/backup.py,sha256=9mkHgsdnMXQ40Uyi_CUAi_4kZEZFCGB1_Rtz0Yh6FAk,37981
15
15
  coord/block_log.py,sha256=nIaxKYpLavv6G9zXMEF2WVSZw4rxVwYPFAdnfpX2_Hw,57472
16
16
  coord/board_doctor.py,sha256=WLYwYOhzgU5SgXKaD9KqjhbvkGOsvPUYN_afwempI5g,55226
17
- coord/board_doctor_followthrough.py,sha256=EoJWhisKzBZx8mASFiVxkMtInAwmnrQccdXL6RWKN0k,24464
17
+ coord/board_doctor_followthrough.py,sha256=qrhbZ_0kurijdHDu8AGAVS_jtaQyTYNIBc96U_FNwmA,31651
18
18
  coord/board_doctor_permissions.py,sha256=_7k5W305bdWs4s7gZxIPniOAZBxl7hwftrep7LlX0uk,72102
19
19
  coord/board_doctor_policy.py,sha256=pB752d8d2uv2lsQi6skKXcOejbYR2dOA2SF4ETi3Qoc,63863
20
20
  coord/board_schema.py,sha256=SBCRVxTfZ2raIk2whKJFw9NwL648RpQsG19yIyx31KA,29768
@@ -36,10 +36,10 @@ coord/cli.py,sha256=fcJ7uZg6aMX1JqyeJKA1nrypeuBLfpejy1ZB4J5IvGU,21108
36
36
  coord/client.py,sha256=mpygdje1Ez4-KeC-EYSmUZfcVk-jvRlvkDm-ghwSxG8,57093
37
37
  coord/codegen.py,sha256=cB7kTCe0NHsFTlWROABWfpkAATGa2H4zJ3Y0_581WSc,94659
38
38
  coord/comments.py,sha256=ctdAKyDlUv0JUZhHsrdPqd4ULLNu-u05mUjbfFNc9iw,42482
39
- coord/config.py,sha256=jnYz2oCqUxBT7XnfTPyfyNXLktEhyHlU5ZryBg87P_Y,316073
39
+ coord/config.py,sha256=pDyt9HFC25KO7zgQEZVnSktipkaHO2oiGf5nbA0E2oo,316403
40
40
  coord/config_reload.py,sha256=PK46TMsOTECI-U8OLmgYGCJVn6dsixCEuKe28hcY1S8,4830
41
41
  coord/confirm_test.py,sha256=Xq_oGV-5O-y5BRsTJBxrZdWetj73BVG4HSspmA7DPC8,72567
42
- coord/conflict_fix.py,sha256=zZl8fW5jH8FlhTHfye1_i8lfLngpuomFDz9Y21H1WyA,118154
42
+ coord/conflict_fix.py,sha256=Yeql1IpIfh_7dkp_OpfAouMmRTQ001bvoCTR0v5FlD4,125554
43
43
  coord/dao.py,sha256=UALen4Dp5ZD8YiY8vQwbsT7qsY1JdIabJ_4NGWAHVr0,34136
44
44
  coord/db.py,sha256=412MQvfwYELqk0Nu53oQ7jt3c810qFMddaDHk7mIRvo,175359
45
45
  coord/dead_end.py,sha256=glt87vdE-2q31JZAu9W-pB8c-SJilFrQDWRvYWRxsmo,20945
@@ -96,7 +96,7 @@ coord/milestone_dispatch.py,sha256=08UZ_6lL4yBHCITBL0zvbQ-T3XkRJfSTmXe0g_Ujcc0,7
96
96
  coord/milestone_gate.py,sha256=W81H0t8bFes9Yf86GEBsqkWiVHjEtj6GRwrZiiGiv4A,30528
97
97
  coord/milestone_order.py,sha256=uwSXBo6PgvgcxbDMLK4jUOEVYdl-HvRj5wqybjGjN38,40901
98
98
  coord/mock_author.py,sha256=mZWSMCPsIqhpQeOgvW11geHrCrDml8v0LdJJY8TyjmA,35784
99
- coord/models.py,sha256=bNMfbeOwb1ClHc9pH6HwGU9xWJngxXesRgUC7PVbFLw,96599
99
+ coord/models.py,sha256=ibeDGYo9uIj0zn2GAqtrbxamopsI0h8s6Y3PTUYCMM8,96935
100
100
  coord/native_fs_wait.py,sha256=nt4YMjh2dhWsKowuJgiHQJctq8uZwIL2x6r8CBRgwGs,6123
101
101
  coord/native_pixels.py,sha256=mskQbMEnwPxLssXc_S35mLfjVYLiGNQx3fb6gJfY3EQ,22291
102
102
  coord/network.py,sha256=s8Ujts1qalc7Q5clPIdIm8km1eSbhTuXb3BkOZanAZQ,25556
@@ -105,7 +105,7 @@ coord/nightly_runner.py,sha256=PIj5dWl864UXQzIZAf5HRg4E9HToH7pGr1lcJdxLZII,53671
105
105
  coord/nightly_smoke.py,sha256=I0mcSqBvcah8ZWZHbWxZdqgIujDiKjnwIBK0Of1-drg,32034
106
106
  coord/nightly_status.py,sha256=xghltS3iS2rZGiIzzwcjh8V5pkW6GK_xZ8reN3in2Ss,12122
107
107
  coord/nightly_store.py,sha256=aovFemXBlnV8labETSaEmh3NEm893lnKU8rt0QY7-lc,28031
108
- coord/notify.py,sha256=SUgzfekrCQzuh68UoqqQshUy8oB2CVSCwt-ba0Hjr04,301512
108
+ coord/notify.py,sha256=76NKfGHjsH1H7qSBi3xsdyC8kzpNPdbOwU_5TlvDgRs,301588
109
109
  coord/openapi.py,sha256=oZx_zFM_kjEaDzAsWI7i08b78Im6C9zHz68LWC45MIc,16992
110
110
  coord/overlap_fence.py,sha256=eAhyYMQu-AQrJymjQCE7Uw2AWX4mLJcXHgb3f-JcC88,5761
111
111
  coord/overlap_predict.py,sha256=s39OcHNCr7eYRQyEeort20doy9sStFig1D3Mp3YjaYY,49827
@@ -124,7 +124,7 @@ coord/prereqs.py,sha256=Y-o_1L47Nwf5Qlk-jb9-bPAMsXvz4H3xdxkKT3iIXb0,77959
124
124
  coord/prereview_gate.py,sha256=KBt5MaHQAyXZYJX8I12rMFctq9nfX9KXGqZlg0T8gYI,23252
125
125
  coord/progress.py,sha256=uwHE7uaBt69EmQmYhXFe25iHGbAeEkr2z1kTG8xZhw4,28879
126
126
  coord/queue_diagnose.py,sha256=g1FGopwRXFx4-YNlUq2UiNFvRSY6jyucG6It0qV9eLM,41575
127
- coord/reconcile.py,sha256=pXVA9xqlZk6uFrfRGFVvekbLagjJW5t45IEt-YW04T4,253784
127
+ coord/reconcile.py,sha256=MUXLQN3DHg3TemJZfqpOEywwozbxq176CxLx4axLlRs,256810
128
128
  coord/reconcile_tick.py,sha256=sQWfNcxetnC1vMWK0yKaqWW0HpBbDyKV5Tdc9yuWAVY,2908
129
129
  coord/refine_chat.py,sha256=u-GFMazvNDfuaSenVebmszhuRvtcuVNEgNXZz3l5pP4,18447
130
130
  coord/release_cordon.py,sha256=1SxsnMxGOSiDEg6ubG7wE0z_syKmF2KgeQbJwqjlL3E,85253
@@ -313,8 +313,8 @@ coord/skills/review-verdict-recovery/SKILL.md,sha256=Grg8GWkJLK20ct2YiigbTFfNOki
313
313
  coord/skills/tui-quadraui-workflow/SKILL.md,sha256=4hUZza9wSSnPhf0eRAOh2r_MQZxK2pXYO5g-kxmJq-U,3832
314
314
  coord/skills/update-issue/SKILL.md,sha256=VrPinEmLZrCSNDrnz96hQomyO403o5c4i0RdsnUnWA0,3642
315
315
  coord/templates/deploy-cloudflare.node.yml,sha256=icsTiWn2ziQJnpZODhhFKYlnqjt2xAXsbwlQufdxhuM,2078
316
- code_coordinator-0.5.712.dist-info/METADATA,sha256=Cg89171eGWo8ilOV2IQicgHqZD47lJV0vuWofm9zQXU,17855
317
- code_coordinator-0.5.712.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
318
- code_coordinator-0.5.712.dist-info/entry_points.txt,sha256=o-Hq8pvG7ReGePvN_4iOKjLNqiq-MJ43HbPurqjNPZo,41
319
- code_coordinator-0.5.712.dist-info/top_level.txt,sha256=w5sTrXesTCebhXyYv2qufOZGo0PoD1Lxgn0Q3MAXjh4,6
320
- code_coordinator-0.5.712.dist-info/RECORD,,
316
+ code_coordinator-0.5.714.dist-info/METADATA,sha256=cM3q_NK_LTBuag9rFbew8_InQLICWqxfSfcimyHbRmE,17855
317
+ code_coordinator-0.5.714.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
318
+ code_coordinator-0.5.714.dist-info/entry_points.txt,sha256=o-Hq8pvG7ReGePvN_4iOKjLNqiq-MJ43HbPurqjNPZo,41
319
+ code_coordinator-0.5.714.dist-info/top_level.txt,sha256=w5sTrXesTCebhXyYv2qufOZGo0PoD1Lxgn0Q3MAXjh4,6
320
+ code_coordinator-0.5.714.dist-info/RECORD,,
@@ -154,6 +154,11 @@ class Disposition:
154
154
  follow_ups: list[int] = field(default_factory=list)
155
155
  reasons: list[str] = field(default_factory=list)
156
156
  rendered_plan: str = ""
157
+ #: Plan key → filed issue number, for every follow-up created so far.
158
+ follow_up_keys: dict[str, int] = field(default_factory=dict)
159
+ #: Filed issue number → pinned machine ("" = left to `coord drive`) for
160
+ #: every follow-up the auto-queue step enqueued.
161
+ queued: dict[int, str] = field(default_factory=dict)
157
162
 
158
163
  def as_record(self) -> dict[str, Any]:
159
164
  return {
@@ -164,6 +169,7 @@ class Disposition:
164
169
  "dry_run": self.dry_run,
165
170
  "plan_leg_assignment_id": self.plan_leg_assignment_id,
166
171
  "follow_ups": list(self.follow_ups),
172
+ "queued": {str(k): v for k, v in self.queued.items()},
167
173
  "reasons": list(self.reasons),
168
174
  }
169
175
 
@@ -205,6 +211,18 @@ def followthrough_enabled(repo_name: str, config: Any) -> bool:
205
211
  return bool(repo is not None and repo.board_doctor.followthrough)
206
212
 
207
213
 
214
+ def followthrough_auto_queue_enabled(repo_name: str, config: Any) -> bool:
215
+ """Whether filed follow-ups for *repo_name* are also drive-queued.
216
+
217
+ Requires :func:`followthrough_enabled` plus the per-repo
218
+ ``repos[].board_doctor.followthrough_auto_queue`` opt-in (default off).
219
+ """
220
+ if not followthrough_enabled(repo_name, config):
221
+ return False
222
+ repo = config.repo(repo_name)
223
+ return bool(getattr(repo.board_doctor, "followthrough_auto_queue", False))
224
+
225
+
208
226
  def is_followthrough_product(body: str | None) -> bool:
209
227
  """True when *body* carries :data:`FOLLOWTHROUGH_MARKER`."""
210
228
  return bool(body and _FOLLOWTHROUGH_MARKER_RE.search(body))
@@ -462,6 +480,155 @@ def _close_comment(plan: FollowThroughPlan, successors: Sequence[tuple[int, str]
462
480
  return "\n".join(lines)
463
481
 
464
482
 
483
+ # ── Auto-queue ───────────────────────────────────────────────────────────────
484
+
485
+ #: Short capability spellings a plan leg may use for the configured names.
486
+ _CAPABILITY_ALIASES = {"win": "windows", "mac": "macos"}
487
+
488
+
489
+ def normalize_capability(raw: str) -> str:
490
+ """``"[win]"`` / ``"Win"`` → ``"windows"``; unknown names pass through."""
491
+ name = raw.strip().strip("[]").strip().lower()
492
+ return _CAPABILITY_ALIASES.get(name, name)
493
+
494
+
495
+ def capable_machines(
496
+ capability: str, repo_name: str, machines: Sequence[Any],
497
+ ) -> list[str]:
498
+ """Machines that declare *capability* and have *repo_name* checked out.
499
+
500
+ Same candidate filter as :func:`coord.dispatch.route_work_by_capability`
501
+ (``can_work_on`` plus a configured ``repo_path``), in ``coordinator.yml``
502
+ declaration order. Pause/quiet-hours state is not consulted: a queue pin
503
+ outlives a pause, and the tick already waits for a paused pinned machine.
504
+ """
505
+ return [
506
+ m.name for m in machines
507
+ if capability in m.capabilities
508
+ and m.can_work_on(repo_name)
509
+ and m.repo_path(repo_name) is not None
510
+ ]
511
+
512
+
513
+ def _default_enqueue(repo_name: str, issue_number: int, **kwargs: Any) -> Any:
514
+ from coord.state import enqueue_drive_queue # noqa: PLC0415
515
+
516
+ return enqueue_drive_queue(repo_name, issue_number, **kwargs)
517
+
518
+
519
+ @dataclass
520
+ class AutoQueueContext:
521
+ """What the auto-queue step needs beyond the plan.
522
+
523
+ *entries* is the drive queue as it stands (``QueueEntry`` rows);
524
+ *draining_epic* is the epic whose rows the queue is currently working
525
+ through, or ``None``. *enqueue* has the signature of
526
+ :func:`coord.state.enqueue_drive_queue`.
527
+ """
528
+
529
+ machines: Sequence[Any]
530
+ entries: Sequence[Any] = ()
531
+ draining_epic: int | None = None
532
+ enqueue: Callable[..., Any] = _default_enqueue
533
+
534
+
535
+ def build_auto_queue_context(
536
+ repo_name: str,
537
+ config: Any,
538
+ *,
539
+ entries: Sequence[Any] = (),
540
+ draining_epic: int | None = None,
541
+ enqueue: Callable[..., Any] = _default_enqueue,
542
+ ) -> AutoQueueContext | None:
543
+ """An :class:`AutoQueueContext`, or ``None`` when *repo_name* has not
544
+ opted in — ``None`` makes :func:`run_followthrough` file but never queue."""
545
+ if not followthrough_auto_queue_enabled(repo_name, config):
546
+ return None
547
+ return AutoQueueContext(
548
+ machines=list(config.machines), entries=entries,
549
+ draining_epic=draining_epic, enqueue=enqueue,
550
+ )
551
+
552
+
553
+ def _queue_position(partial: PartialMerge, ctx: AutoQueueContext) -> int | None:
554
+ """The original row's slot when its epic is draining, else ``None`` (tail)."""
555
+ if partial.epic_number is None or partial.epic_number != ctx.draining_epic:
556
+ return None
557
+ for entry in ctx.entries:
558
+ if entry.repo == partial.repo_name and entry.issue == partial.issue_number:
559
+ return int(entry.position)
560
+ return None
561
+
562
+
563
+ def auto_queue_follow_ups(
564
+ partial: PartialMerge,
565
+ plan: FollowThroughPlan,
566
+ disposition: Disposition,
567
+ ctx: AutoQueueContext,
568
+ *,
569
+ alert: Callable[[str, str], None],
570
+ ) -> None:
571
+ """Drive-queue every filed follow-up in plan order.
572
+
573
+ ``after`` edges are the plan's own, resolved to ``repo#N`` keys. A
574
+ follow-up declaring a capability is pinned to the first capable machine
575
+ (or its own declared ``machine`` when that one is capable); one whose
576
+ capability no machine covers is not queued and alerts instead. Without a
577
+ capability the follow-up's declared ``machine`` is used if configured,
578
+ else routing is left to ``coord drive``.
579
+ """
580
+ from coord.drive_queue import ( # noqa: PLC0415
581
+ QueueEntry,
582
+ QueueError,
583
+ entry_key,
584
+ validate_enqueue,
585
+ )
586
+
587
+ repo = partial.repo_name
588
+ known_machines = {m.name for m in ctx.machines}
589
+ entries: list[Any] = list(ctx.entries)
590
+ position = _queue_position(partial, ctx)
591
+ for fu in plan.follow_ups:
592
+ number = disposition.follow_up_keys.get(fu.key)
593
+ if number is None:
594
+ continue
595
+ key = entry_key(repo, number)
596
+ machine: str | None
597
+ if fu.capability:
598
+ capability = normalize_capability(fu.capability)
599
+ capable = capable_machines(capability, repo, ctx.machines)
600
+ if not capable:
601
+ reason = (
602
+ f"#{number} not queued: no machine declares capability "
603
+ f"{capability!r} for {repo}"
604
+ )
605
+ disposition.reasons.append(reason)
606
+ alert(f"{key}: follow-up capability unroutable", reason)
607
+ continue
608
+ machine = fu.machine if fu.machine in capable else capable[0]
609
+ else:
610
+ machine = fu.machine if fu.machine in known_machines else None
611
+ after = [
612
+ entry_key(repo, int(t[1:]) if t.startswith("#")
613
+ else disposition.follow_up_keys[t])
614
+ for t in fu.after
615
+ ]
616
+ try:
617
+ validate_enqueue(entries, repo, number, after)
618
+ except QueueError as exc:
619
+ reason = f"#{number} not queued: {exc}"
620
+ disposition.reasons.append(reason)
621
+ alert(f"{key}: follow-up not queued", reason)
622
+ continue
623
+ ctx.enqueue(repo, number, machine=machine, after=after, position=position)
624
+ entries.append(QueueEntry(
625
+ repo=repo, issue=number, machine=machine or "", after=tuple(after),
626
+ ))
627
+ disposition.queued[number] = machine or ""
628
+ if position is not None:
629
+ position += 1
630
+
631
+
465
632
  # ── Orchestration ────────────────────────────────────────────────────────────
466
633
 
467
634
 
@@ -484,12 +651,17 @@ def run_followthrough(
484
651
  epic_exists: Callable[[int], bool] = lambda _n: True,
485
652
  milestone_exists: Callable[[str], bool] = lambda _m: True,
486
653
  dry_run: bool = False,
654
+ auto_queue: AutoQueueContext | None = None,
487
655
  ) -> Disposition:
488
656
  """Resolve one ``merged-partial`` row end to end.
489
657
 
490
658
  *alert* and *page* take ``(subject, body)``. With *dry_run* the plan leg
491
659
  still runs (it is read-only) and the plan is validated and rendered,
492
660
  but nothing is written, alerted, paged or recorded.
661
+
662
+ *auto_queue* (see :func:`build_auto_queue_context`) additionally
663
+ drive-queues each filed follow-up once the original is closed; ``None``
664
+ files without queueing.
493
665
  """
494
666
  key = f"{partial.repo_name}#{partial.issue_number}"
495
667
  disposition = Disposition(
@@ -558,6 +730,12 @@ def run_followthrough(
558
730
  + (", ".join(f"#{n}" for n in disposition.follow_ups) or "none"),
559
731
  )
560
732
  return _finish(ACTION_WRITE_FAILED)
733
+ if auto_queue is not None and disposition.follow_ups:
734
+ try:
735
+ auto_queue_follow_ups(partial, plan, disposition, auto_queue, alert=alert)
736
+ except Exception as exc: # noqa: BLE001 — the follow-ups are filed; alert, don't fail
737
+ disposition.reasons.append(f"auto-queue failed: {exc}")
738
+ alert(f"{key}: follow-up auto-queue failed", str(exc))
561
739
  return _finish(ACTION_ALL_LANDED if plan.all_landed else ACTION_FILED)
562
740
 
563
741
 
@@ -580,6 +758,7 @@ def _write_follow_ups(
580
758
  milestone=fu.milestone or partial.milestone,
581
759
  )
582
760
  disposition.follow_ups.append(number)
761
+ disposition.follow_up_keys[fu.key] = number
583
762
  by_key[fu.key] = number
584
763
  successors.append((number, fu.title))
585
764
  after = tuple(
coord/config.py CHANGED
@@ -4054,6 +4054,13 @@ def _parse_board_doctor_repo_config(raw: Any, repo_index: int) -> BoardDoctorRep
4054
4054
  f"repos[{repo_index}].board_doctor.followthrough must be a boolean"
4055
4055
  )
4056
4056
  cfg.followthrough = followthrough
4057
+ if "followthrough_auto_queue" in raw:
4058
+ auto_queue = raw["followthrough_auto_queue"]
4059
+ if not isinstance(auto_queue, bool):
4060
+ raise ConfigError(
4061
+ f"repos[{repo_index}].board_doctor.followthrough_auto_queue must be a boolean"
4062
+ )
4063
+ cfg.followthrough_auto_queue = auto_queue
4057
4064
  return cfg
4058
4065
 
4059
4066
 
coord/conflict_fix.py CHANGED
@@ -92,7 +92,28 @@ from coord.models import (
92
92
  from coord.network import StatusResult, probe_reachable
93
93
 
94
94
 
95
- CONFLICT_FIX_SYSTEM_PROMPT = """\
95
+ # A `claude -p` leg's session ends the INSTANT it ends its turn — there is
96
+ # no next turn for a backgrounded step to report back to, and no reaper
97
+ # grace period that counts as "still working". A worker that runs a test
98
+ # suite or a multi-stage gate via a background tool (e.g. `Monitor`) and
99
+ # then ends its turn with a status line like "Waiting for the gate." has
100
+ # just ended its OWN session: the push that line implies is coming never
101
+ # happens, and 30s later the reaper SIGTERMs the still-running process
102
+ # group. Every conflict-fix variant in this module shares that single-shot-
103
+ # session risk, not just the ordinary rebase briefing, so this rule is
104
+ # spliced into each one's "Rules" section rather than copied by hand — one
105
+ # string, one place to keep it accurate.
106
+ SESSION_ENDS_ON_TURN_END_RULE = (
107
+ "- Your session ends the moment you end your turn — there is no next "
108
+ "turn. Run the test command (and any other check) in the foreground, "
109
+ "in THIS turn; if something takes a while, wait on it here rather than "
110
+ "backgrounding it. Push BEFORE your final message, not after. A final "
111
+ 'message like "Waiting for the gate." or "Waiting for tests to '
112
+ "finish.\" is a failure, not progress — the session is already over "
113
+ "and nothing you backgrounded gets a chance to finish."
114
+ )
115
+
116
+ CONFLICT_FIX_SYSTEM_PROMPT = f"""\
96
117
  You are a Claude Code conflict-fix worker. The merge of a worker's branch \
97
118
  into the project's target branch failed because the branch is out of date \
98
119
  or has a conflict. Your job is to rebase the branch and push it back.
@@ -102,6 +123,7 @@ Rules:
102
123
  Don't try to use them — the harness will reject the call.
103
124
  - Stay on the worker's branch — do NOT push to main / develop / target.
104
125
  - Use git push --force-with-lease (NOT --force).
126
+ {SESSION_ENDS_ON_TURN_END_RULE}
105
127
  - If conflicts are mechanical (non-overlapping struct fields, list entries, \
106
128
  imports, separate functions), resolve them additively — keep both sides.
107
129
  - If conflicts are SEMANTIC (same function modified two ways, contradictory \
@@ -155,7 +177,7 @@ SEMANTIC_STUCK_MARKER = "coord:conflict=semantic"
155
177
  # `has_prior_semantic_escalation` uses it to enforce exactly-one-retry.
156
178
  SEMANTIC_FIX_TITLE_PREFIX = "[semantic-merge]"
157
179
 
158
- SEMANTIC_CONFLICT_SYSTEM_PROMPT = """\
180
+ SEMANTIC_CONFLICT_SYSTEM_PROMPT = f"""\
159
181
  You are a Claude Code merge worker. A first worker rebased a branch onto its \
160
182
  target branch, hit a conflict it judged SEMANTIC — the two sides changed the \
161
183
  same behaviour in incompatible ways — and stopped rather than guess. You are \
@@ -166,6 +188,7 @@ Constraints:
166
188
  - The coordinator denies `gh` and `git push --force` for this worker.
167
189
  - Stay on the worker's branch — never push to main / develop / the target \
168
190
  branch. Push with `git push --force-with-lease`.
191
+ {SESSION_ENDS_ON_TURN_END_RULE}
169
192
  - The project's tests must pass before you push. A resolution that compiles \
170
193
  but breaks behaviour is worse than no resolution.
171
194
  - If you cannot honour both intents with confidence, stop and say so with a \
@@ -299,6 +322,7 @@ Rules:
299
322
  Don't try to use them — the harness will reject the call.
300
323
  - Stay on the worker's branch — do NOT push to main / develop / target.
301
324
  - Use git push --force-with-lease (NOT --force).
325
+ {SESSION_ENDS_ON_TURN_END_RULE}
302
326
  - Rebase onto the target branch. If the ONLY conflict is inside a \
303
327
  `{SEALED_MANIFEST_FILENAME}` or a `manifest.d/<issue>.(yml|json)` fragment \
304
328
  under `tests/acceptance/`, resolve it ADDITIVELY: keep BOTH sides' issue \
@@ -568,7 +592,7 @@ STALE_REBASE_FIX_TITLE_PREFIX = "[stale-rebase-fix]"
568
592
  # races" situation either way.
569
593
  MAX_STALE_REBASE_RACE_ATTEMPTS = 5
570
594
 
571
- STALE_REBASE_FIX_SYSTEM_PROMPT = """\
595
+ STALE_REBASE_FIX_SYSTEM_PROMPT = f"""\
572
596
  You are a Claude Code conflict-fix worker. This branch's CI ran against a \
573
597
  base that has since moved (a `checks_stale` merge-gate refusal) — there is \
574
598
  no known content conflict, only a stale base. Your job is a PURE rebase: \
@@ -580,10 +604,11 @@ Rules:
580
604
  Don't try to use them — the harness will reject the call.
581
605
  - Stay on the worker's branch — do NOT push to main / develop / target.
582
606
  - Use git push --force-with-lease (NOT --force).
607
+ {SESSION_ENDS_ON_TURN_END_RULE}
583
608
  - BEFORE rebasing, check whether this branch's content is already fully \
584
609
  present on the target (the same change landed via another issue, maybe \
585
610
  with extra tests): compare `git merge-tree --write-tree origin/<target> \
586
- HEAD` against `git rev-parse origin/<target>^{tree}`. If they match, \
611
+ HEAD` against `git rev-parse origin/<target>^{{tree}}`. If they match, \
587
612
  merging this branch would add nothing — there is no conflict AND nothing \
588
613
  to rebase. Stop immediately (do not rebase, do not push) and end your turn \
589
614
  with a STUCK: line starting with the marker `coord:conflict=already-upstream`.
@@ -803,7 +828,7 @@ REWORD_MISMATCH_MARKER = "coord:conflict=reword-mismatch"
803
828
  # narrow, message-only briefing rather than the ordinary conflict-fix one.
804
829
  REWORD_COMMIT_FIX_TITLE_PREFIX = "[reword-commit-fix]"
805
830
 
806
- REWORD_COMMIT_FIX_SYSTEM_PROMPT = """\
831
+ REWORD_COMMIT_FIX_SYSTEM_PROMPT = f"""\
807
832
  You are a Claude Code conflict-fix worker. This branch's PR is marked \
808
833
  `ISSUE_RESOLUTION: partial` or `ISSUE_RESOLUTION: investigation` — it does \
809
834
  NOT fully resolve its issue — but one of its own commit messages still \
@@ -817,6 +842,7 @@ Rules:
817
842
  - The coordinator denies `gh` and `git push --force` for this worker. \
818
843
  Don't try to use them — the harness will reject the call.
819
844
  - Stay on the worker's branch — do NOT push to main / develop / target.
845
+ {SESSION_ENDS_ON_TURN_END_RULE}
820
846
  - Use git push --force-with-lease (NOT --force).
821
847
  - Rewrite ONLY the commit subject/body wording that uses a closing keyword \
822
848
  for this entry's own issue number — e.g. `Fix #N: ...` / `Fixes #N ...` / \
@@ -1074,15 +1100,7 @@ def _decode_worker_text(raw: str) -> str:
1074
1100
  reasoning as the equivalent helpers in ``coord.review``/
1075
1101
  ``coord.plan_parser``.
1076
1102
  """
1077
- stream_json = False
1078
- for line in raw.splitlines():
1079
- stripped = line.strip()
1080
- if not stripped or stripped.startswith("#"):
1081
- continue
1082
- stream_json = stripped.startswith("{")
1083
- break
1084
-
1085
- if not stream_json:
1103
+ if not _looks_like_stream_json(raw):
1086
1104
  return raw
1087
1105
 
1088
1106
  from coord.worker_events import _assistant_text, parse_event # noqa: PLC0415
@@ -1098,6 +1116,24 @@ def _decode_worker_text(raw: str) -> str:
1098
1116
  return "\n".join(decoded)
1099
1117
 
1100
1118
 
1119
+ def _looks_like_stream_json(raw: str) -> bool:
1120
+ """True when *raw* is the agent's default stream-json log format (each
1121
+ non-comment, non-blank line a JSON event) rather than a plain-text log.
1122
+
1123
+ Shared sniff used by :func:`_decode_worker_text` (whole-transcript
1124
+ decode, for marker search) and :func:`_latest_turn_text` (last-turn-only
1125
+ decode, for the final-message check) — the two need the same answer to
1126
+ "is this stream-json", so exactly one place answers it (#2096 "one
1127
+ question, one answer").
1128
+ """
1129
+ for line in raw.splitlines():
1130
+ stripped = line.strip()
1131
+ if not stripped or stripped.startswith("#"):
1132
+ continue
1133
+ return stripped.startswith("{")
1134
+ return False
1135
+
1136
+
1101
1137
  def semantic_verdict_in_text(text: str | None) -> bool:
1102
1138
  """True when a worker log carries the semantic-conflict marker."""
1103
1139
  if not text:
@@ -1243,6 +1279,134 @@ def detect_already_upstream(
1243
1279
  return False
1244
1280
 
1245
1281
 
1282
+ # ── premature session end (backgrounded gate, no push) ─────────────────────
1283
+ #
1284
+ # Every verdict detector above (`detect_semantic_conflict`,
1285
+ # `detect_stale_rebase_mismatch`, `detect_already_upstream`,
1286
+ # `detect_reword_mismatch`) recognises a worker that investigated and
1287
+ # DELIBERATELY stopped, via a fixed `STUCK:` marker — a sanctioned non-push
1288
+ # outcome. A different shape leaves no marker at all: a worker rebases,
1289
+ # launches the test/gate run with a background tool, and ends its turn with
1290
+ # a status line like "Waiting for the gate." In `-p` mode that ended turn
1291
+ # ends the whole session, so nothing it backgrounded ever finishes and no
1292
+ # push is sent.
1293
+ #
1294
+ # Whether a leg actually pushed is answered in exactly one place —
1295
+ # `coord.reconcile._head_unmoved_verdict`, which compares the branch's live
1296
+ # head on GitHub against the head this attempt was dispatched against
1297
+ # (#2096 "one question, one answer"; a worker's own prose claiming success
1298
+ # is not evidence of it). The helper below answers a strictly different
1299
+ # question — WHY a leg that provably did not push ended anyway — and only
1300
+ # feeds the operator-facing diagnosis on that single path. It never decides
1301
+ # success or failure on its own.
1302
+
1303
+ _PREMATURE_WAIT_MARKERS = (
1304
+ "waiting for",
1305
+ "wait for",
1306
+ "will wait for",
1307
+ "i'll wait for",
1308
+ "we'll wait for",
1309
+ "let's wait for",
1310
+ "while the gate",
1311
+ "while it finishes",
1312
+ "while they finish",
1313
+ "once the gate",
1314
+ "running in the background",
1315
+ "monitoring it in the background",
1316
+ )
1317
+
1318
+
1319
+ def looks_like_premature_wait(text: str | None) -> bool:
1320
+ """Best-effort prose check: does *text* — a conflict-fix worker's OWN
1321
+ final assistant turn — read as an announcement that it backgrounded a
1322
+ long-running step (a test run, a multi-stage gate) and would wait for
1323
+ that step to finish?
1324
+
1325
+ A final turn carrying a `STUCK:` line is never a premature wait: every
1326
+ `coord:conflict=...` marker this module defines is written on such a
1327
+ line per the system prompts above, and a deliberate give-up may itself
1328
+ mention waiting (e.g. "waiting on a human decision"). Checking the
1329
+ marker family's shared `STUCK:` prefix keeps that exclusion correct as
1330
+ new marker kinds are added.
1331
+
1332
+ Best-effort, and never a success/failure verdict on its own: it only
1333
+ sharpens the human-facing explanation of a leg that already provably
1334
+ did not push, mirroring the precedent in
1335
+ :func:`coord.worker_events.looks_like_policy_refusal`/
1336
+ :func:`coord.worker_events.looks_like_premise_refusal`.
1337
+ """
1338
+ if not text or "STUCK:" in text:
1339
+ return False
1340
+ lowered = text.lower()
1341
+ return any(marker in lowered for marker in _PREMATURE_WAIT_MARKERS)
1342
+
1343
+
1344
+ def _latest_turn_text(raw: str) -> str | None:
1345
+ """Return the worker's most recent assistant turn's text out of *raw*.
1346
+
1347
+ Handles both the agent's default stream-json log format (delegates to
1348
+ :func:`coord.worker_events.latest_assistant_turn_text_from_text`, which
1349
+ knows the real turn boundaries) and a plain-text log (no turn
1350
+ boundaries exist to find, so the whole decoded text stands in for "the
1351
+ final turn" — the same fallback :func:`_decode_worker_text` uses for
1352
+ marker search). Returns ``None`` when no assistant turn is found at
1353
+ all (distinct from an empty string, which means a real turn produced
1354
+ neither text nor a recognised tool call).
1355
+ """
1356
+ if not _looks_like_stream_json(raw):
1357
+ return raw or None
1358
+
1359
+ from coord.worker_events import latest_assistant_turn_text_from_text # noqa: PLC0415
1360
+
1361
+ return latest_assistant_turn_text_from_text(raw)
1362
+
1363
+
1364
+ def detect_premature_wait(
1365
+ *,
1366
+ log_path: str | None = None,
1367
+ host: str | None = None,
1368
+ assignment_id: str | None = None,
1369
+ port: int = AGENT_PORT,
1370
+ timeout: float = 15.0,
1371
+ ) -> bool:
1372
+ """Log-fetching counterpart to :func:`looks_like_premature_wait`, read
1373
+ against the worker's FINAL turn only (:func:`_latest_turn_text`) rather
1374
+ than the whole transcript — a mid-session "waiting for the tests" note
1375
+ before a later real push is not this failure shape.
1376
+
1377
+ Tries the local log file first (coordinator-local worker), then falls
1378
+ back to the agent's ``/logs/<id>`` endpoint for remote workers, the same
1379
+ two-step every other detector in this module uses. Best-effort: any
1380
+ read/transport failure that leaves no transcript to examine returns
1381
+ ``False``, the same "cannot prove it" default as the sibling detectors.
1382
+
1383
+ Callers reach this only for a leg already confirmed not to have pushed;
1384
+ it never answers that question itself (see this section's comment).
1385
+ """
1386
+ if log_path:
1387
+ try:
1388
+ from pathlib import Path # noqa: PLC0415
1389
+
1390
+ p = Path(log_path)
1391
+ if p.exists():
1392
+ raw = p.read_text(encoding="utf-8", errors="replace")
1393
+ return looks_like_premature_wait(_latest_turn_text(raw))
1394
+ except OSError:
1395
+ pass
1396
+
1397
+ if host and assignment_id:
1398
+ try:
1399
+ resp = httpx.get(
1400
+ f"http://{host}:{port}/logs/{assignment_id}", timeout=timeout
1401
+ )
1402
+ resp.raise_for_status()
1403
+ return looks_like_premature_wait(_latest_turn_text(resp.text))
1404
+ except (httpx.HTTPError, httpx.TimeoutException):
1405
+ return False
1406
+
1407
+ return False
1408
+
1409
+
1246
1410
  def semantic_escalation_disabled(config: Config | None) -> bool:
1247
1411
  """True when a SEMANTIC give-up has nowhere to escalate to (#2566).
1248
1412
 
coord/models.py CHANGED
@@ -102,12 +102,18 @@ class BoardDoctorRepoConfig:
102
102
  function that reads this alongside the fleet-wide kill switch
103
103
  (`Config.board_doctor.followthrough`) and its
104
104
  `COORD_BOARD_DOCTOR_NO_FOLLOWTHROUGH` env-var override.
105
+
106
+ ``followthrough_auto_queue`` additionally drive-queues each follow-up the
107
+ disposition files, pinned to a machine that declares the follow-up's
108
+ capability. `False` (the default) files follow-ups but never queues
109
+ them. It has no effect unless ``followthrough`` is also enabled.
105
110
  """
106
111
 
107
112
  investigate: bool = False
108
113
  finish: bool = False
109
114
  stale_race: bool = False
110
115
  followthrough: bool = False
116
+ followthrough_auto_queue: bool = False
111
117
 
112
118
 
113
119
  @dataclass
coord/notify.py CHANGED
@@ -4658,6 +4658,8 @@ def post_transition(transition: Transition, record: dict, entry: dict) -> None:
4658
4658
  board=board,
4659
4659
  config=config,
4660
4660
  stuck_summary=stuck_summary,
4661
+ fix_log_path=log_path,
4662
+ fix_agent_host=host,
4661
4663
  )
4662
4664
  if semantic and board is not None:
4663
4665
  try:
coord/reconcile.py CHANGED
@@ -3206,6 +3206,36 @@ def _head_unmoved_verdict(
3206
3206
  return (live_sha == dispatched_sha), live_sha
3207
3207
 
3208
3208
 
3209
+ def _ended_waiting_on_a_backgrounded_step(
3210
+ *,
3211
+ log_path: str | None,
3212
+ host: str | None,
3213
+ assignment_id: str | None,
3214
+ ) -> bool:
3215
+ """True when a finished conflict-fix leg's FINAL turn reads as "I
3216
+ backgrounded the gate and am waiting for it" (#3870).
3217
+
3218
+ Explanatory only, and reached only for a leg :func:`_head_unmoved_
3219
+ verdict` already confirmed did not move the branch: it sharpens the
3220
+ parked entry's text, never the success/failure verdict. Best-effort —
3221
+ an unreadable or unreachable transcript returns ``False``, which just
3222
+ leaves the generic "the push appears to be missing or was rejected"
3223
+ wording in place.
3224
+ """
3225
+ if not log_path and not (host and assignment_id):
3226
+ return False
3227
+ from coord.conflict_fix import detect_premature_wait # noqa: PLC0415
3228
+
3229
+ try:
3230
+ return detect_premature_wait(
3231
+ log_path=log_path,
3232
+ host=host,
3233
+ assignment_id=assignment_id,
3234
+ )
3235
+ except Exception: # noqa: BLE001 — never break reconcile on a log read
3236
+ return False
3237
+
3238
+
3209
3239
  def _try_ordinary_escalation_after_head_unmoved(
3210
3240
  entry: "mq.QueuedMerge",
3211
3241
  *,
@@ -3302,6 +3332,8 @@ def on_conflict_fix_done(
3302
3332
  config: Config | None = None,
3303
3333
  stuck_summary: str | None = None,
3304
3334
  usage_limit_reason: str | None = None,
3335
+ fix_log_path: str | None = None,
3336
+ fix_agent_host: str | None = None,
3305
3337
  ) -> None:
3306
3338
  """Update the parent merge entry after a conflict-fix worker finishes.
3307
3339
 
@@ -3393,6 +3425,17 @@ def on_conflict_fix_done(
3393
3425
  phrases, so the latch stays eligible for
3394
3426
  :func:`coord.merge_queue.reconcile_conflict_entries`'s live-
3395
3427
  mergeability re-test instead of parking forever on a stale verdict.
3428
+
3429
+ *fix_log_path* / *fix_agent_host* locate the finished leg's transcript
3430
+ (a coordinator-local log file, and the agent that ran it). They are
3431
+ read ONLY on that ``head_unmoved`` branch, to say WHY a leg that
3432
+ provably didn't push ended anyway — a final turn announcing it was
3433
+ waiting on a step it had backgrounded (#3870) names the single-shot-
3434
+ session mistake in the parked entry's text instead of leaving "the push
3435
+ appears to be missing" unexplained. The verdict itself never depends on
3436
+ them: whether the branch moved is answered only by
3437
+ :func:`_head_unmoved_verdict`, and omitting both simply loses the
3438
+ explanation.
3396
3439
  """
3397
3440
  from coord import merge_queue as mq # noqa: PLC0415
3398
3441
 
@@ -3455,6 +3498,22 @@ def on_conflict_fix_done(
3455
3498
  f"{head_unmoved_sha}) — the push appears to be missing "
3456
3499
  "or was rejected"
3457
3500
  )
3501
+ # Name the single-shot-session mistake when the leg's own
3502
+ # final turn shows it: a `-p` session ends with the turn, so
3503
+ # a worker that backgrounded its gate and signed off with
3504
+ # "Waiting for the gate." never reached its push. Purely
3505
+ # explanatory — the verdict above already stands on the live
3506
+ # branch head.
3507
+ if _ended_waiting_on_a_backgrounded_step(
3508
+ log_path=fix_log_path,
3509
+ host=fix_agent_host,
3510
+ assignment_id=fix_assignment_id,
3511
+ ):
3512
+ detail += (
3513
+ "; its final message announced it was waiting for a "
3514
+ "step it had backgrounded, which a headless session "
3515
+ "never returns from"
3516
+ )
3458
3517
  fix = _try_ordinary_escalation_after_head_unmoved(
3459
3518
  entry,
3460
3519
  board=board,
@@ -3799,6 +3858,14 @@ def _on_conflict_fix_done(
3799
3858
  return
3800
3859
 
3801
3860
  usage_limit_reason = (agent_entry or {}).get("usage_limit_reason")
3861
+ log_path = (agent_entry or {}).get("log_path")
3862
+ fix_machine = next(
3863
+ (
3864
+ m for m in (config.machines if config is not None else [])
3865
+ if m.name == fix_assignment.machine_name
3866
+ ),
3867
+ None,
3868
+ )
3802
3869
 
3803
3870
  semantic = False
3804
3871
  already_upstream = False
@@ -3851,6 +3918,8 @@ def _on_conflict_fix_done(
3851
3918
  config=config,
3852
3919
  stuck_summary=stuck_summary,
3853
3920
  usage_limit_reason=usage_limit_reason,
3921
+ fix_log_path=log_path,
3922
+ fix_agent_host=fix_machine.host if fix_machine is not None else None,
3854
3923
  )
3855
3924
 
3856
3925