Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions agents/conductors/batch/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,15 @@ Until phase 3b it spawns only stub workers (`PYAUTO_ORCHESTRATOR_FAKE=1`); a rea
dispatch is refused. Doctrine: `AUTONOMY.md` "The watcher's network surface —
2026-11-03"; the exemption it runs under, `PyAutoMind/policy/shift_watcher.md`.

**The open-brief gate is a window: `dispatched:` → `review-at:`.** A brief
that passes `batch brief --check` is open only from its `dispatched:` until its
`review-at:`. Before the start, a tick is idle (`not yet open: opens at
dispatched …`) and touches nothing, not even the slot directory, so a brief may
be landed early. Until 2026-11-05 the gate ignored `dispatched:` and a brief
opened the moment it landed (pilot shadow shift 1 opened a day early;
PyAutoBrain#589). `batch watch` says `not yet open — opens in …` before the
start.

**Real workers (phase 3b).** Without `PYAUTO_ORCHESTRATOR_FAKE=1` each spawn is
`claude --bg --name shift:<task> --permission-mode <worker-mode> <prompt>`, the
prompt filled from `worker_template.md` (the `/start_dev <path> --auto` line,
Expand Down
6 changes: 6 additions & 0 deletions agents/conductors/batch/_orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,12 @@ def brief_open(brief_path: Path, mind: Path, now: _dt.datetime) -> tuple[bool, s
at = _brief._iso(rec["top"]["review-at"]["value"])
if now >= at:
return False, f"review-at {rec['top']['review-at']['value']} has passed", None
# The shift is `dispatched:` → `review-at:`. Landing the brief early is
# allowed; it grants nothing until its start (PyAutoBrain#589 — shadow
# shift 1 opened on landing, a day early).
start = _brief._iso(rec["top"]["dispatched"]["value"])
if now < start:
return False, f"not yet open: opens at dispatched {rec['top']['dispatched']['value']}", None
return True, "open", rec["brief"]


Expand Down
13 changes: 12 additions & 1 deletion agents/conductors/batch/_watch.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ def _time_left(now: _dt.datetime, review_at: _dt.datetime | None) -> str:
return (f"{h}h {m:02d}m" if h else f"{m}m") + " left"


def _opens_in(now: _dt.datetime, start: _dt.datetime) -> str:
"""Before `dispatched:` the watcher does nothing (PyAutoBrain#589)."""
left = _time_left(now, start)
return "not yet open — opens in " + left.replace(" left", "")


def snapshot(brief_path: Path, slot: Path, now: _dt.datetime, *, agents=None,
health=None, tick_lines: int = TICK_LINES) -> dict:
"""Everything one refresh draws, as a dict. Reads only."""
Expand All @@ -89,6 +95,10 @@ def snapshot(brief_path: Path, slot: Path, now: _dt.datetime, *, agents=None,
review_at = _brief._iso(_value(top, "review-at", ""))
except (ValueError, TypeError):
review_at = None
try:
start = _brief._iso(_value(top, "dispatched", ""))
except (ValueError, TypeError):
start = None

started = slot.is_dir()
counters = _orchestrator.read_counters(slot) if started else {}
Expand Down Expand Up @@ -121,7 +131,8 @@ def snapshot(brief_path: Path, slot: Path, now: _dt.datetime, *, agents=None,
"now": _orchestrator._iso(now),
"dispatched": _value(top, "dispatched"),
"review_at": _value(top, "review-at"),
"time_left": _time_left(now, review_at),
"time_left": (_opens_in(now, start) if start is not None and now < start
else _time_left(now, review_at)),
"stop": (slot / _orchestrator.STOP_FILE).exists(),
"digest_posted": (slot / _orchestrator.DIGEST_MARKER).exists(),
"started": started,
Expand Down
7 changes: 7 additions & 0 deletions tests/test_batch_watch.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,13 @@ def test_no_tick_yet_and_closed_and_stop(tmp_path):
assert "STOP present" in text and "digest posted" in text


def test_before_dispatched_the_header_says_not_yet_open(tmp_path):
brief = _record(tmp_path) # dispatched: 09:00Z
early = NOW.replace(hour=8, minute=15)
text = _watch.render(_watch.snapshot(brief, tmp_path / "none", early, health=_health))
assert "not yet open — opens in 45m" in text


def test_time_left_formats():
at = NOW + _dt.timedelta(minutes=7)
assert _watch._time_left(NOW, at) == "7m left"
Expand Down
14 changes: 14 additions & 0 deletions tests/test_orchestrator_watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,20 @@ def test_a_brief_past_review_at_dispatches_nothing(tmp_path):
assert not (orch.slot_dir(brief, home) / "leases").exists()


def test_a_brief_before_dispatched_is_not_yet_open(tmp_path):
"""Landing a brief early grants nothing until its `dispatched:` (#589)."""
mind, brief, home = _shift(tmp_path)
early = NOW.replace(hour=8, minute=0) # dispatched: 08:30Z
r = orch.tick(brief, mind, home=home, now=early, spawner=orch.FakeSpawner())
assert r["action"] == "idle" and r["reason"].startswith("not yet open")
assert "2026-11-04T08:30Z" in r["reason"]
assert not orch.slot_dir(brief, home).exists() # nothing touched
on_time = NOW.replace(hour=8, minute=30)
r = orch.tick(brief, mind, home=home, now=on_time, spawner=orch.FakeSpawner())
assert r["action"] != "idle"
assert orch.slot_dir(brief, home).exists()


def test_a_refused_brief_dispatches_nothing(tmp_path):
mind, brief, home = _shift(tmp_path)
brief.write_text(brief.read_text().replace("- review-at: 2026-11-04T11:30Z\n", ""))
Expand Down
Loading