From 08ee65149393897a05f80ee64bba2bb7cbad4147 Mon Sep 17 00:00:00 2001 From: Jammy2211 Date: Thu, 5 Nov 2026 21:45:21 +0000 Subject: [PATCH] fix(batch): a shift opens at dispatched:, not when the brief lands (#589) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit brief_open treats a brief before its dispatched: as not yet open: the tick is idle and touches nothing, so a brief may be landed early. batch watch says 'not yet open — opens in …'. Found in pilot shadow shift 1, which opened a day early. Co-Authored-By: Claude Opus 5.5 --- agents/conductors/batch/AGENTS.md | 9 +++++++++ agents/conductors/batch/_orchestrator.py | 6 ++++++ agents/conductors/batch/_watch.py | 13 ++++++++++++- tests/test_batch_watch.py | 7 +++++++ tests/test_orchestrator_watcher.py | 14 ++++++++++++++ 5 files changed, 48 insertions(+), 1 deletion(-) diff --git a/agents/conductors/batch/AGENTS.md b/agents/conductors/batch/AGENTS.md index 08d5454d..59ae4f1c 100644 --- a/agents/conductors/batch/AGENTS.md +++ b/agents/conductors/batch/AGENTS.md @@ -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: --permission-mode `, the prompt filled from `worker_template.md` (the `/start_dev --auto` line, diff --git a/agents/conductors/batch/_orchestrator.py b/agents/conductors/batch/_orchestrator.py index dea9b3fa..da098989 100644 --- a/agents/conductors/batch/_orchestrator.py +++ b/agents/conductors/batch/_orchestrator.py @@ -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"] diff --git a/agents/conductors/batch/_watch.py b/agents/conductors/batch/_watch.py index 63436f94..526f26cd 100644 --- a/agents/conductors/batch/_watch.py +++ b/agents/conductors/batch/_watch.py @@ -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.""" @@ -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 {} @@ -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, diff --git a/tests/test_batch_watch.py b/tests/test_batch_watch.py index 5a4e1bf1..f8d8f390 100644 --- a/tests/test_batch_watch.py +++ b/tests/test_batch_watch.py @@ -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" diff --git a/tests/test_orchestrator_watcher.py b/tests/test_orchestrator_watcher.py index eaa70fcd..e0df9347 100644 --- a/tests/test_orchestrator_watcher.py +++ b/tests/test_orchestrator_watcher.py @@ -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", ""))