diff --git a/agents/conductors/intake/_intake.py b/agents/conductors/intake/_intake.py index 0c51b87e..2079fe5e 100755 --- a/agents/conductors/intake/_intake.py +++ b/agents/conductors/intake/_intake.py @@ -1347,6 +1347,23 @@ def _lane_of(header: dict) -> str: return lane if lane in LANE_VALUES else "any" +# An epic keeps its companions beside its ledger: `_epic_report.md`, +# numbered surveys in `_epic_surveys/` and reviews in `_epic_reviews/`. +# They live under draft/ because the epic does, but they are read-only reports, +# not prompts — census() must not list them as pickable backlog work (until +# 2026-11-05 the dashboard offered 29 of them with "Use the start-dev skill"). +EPIC_COMPANION_DIR_SUFFIXES = ("_epic_surveys", "_epic_reviews") +EPIC_COMPANION_FILE_SUFFIX = "_epic_report.md" + + +def is_epic_companion(rel: Path) -> bool: + """Whether a draft/ path is an epic's report, survey or review, not a prompt.""" + rel = Path(rel) + if rel.name.endswith(EPIC_COMPANION_FILE_SUFFIX): + return True + return any(part.endswith(EPIC_COMPANION_DIR_SUFFIXES) for part in rel.parts[:-1]) + + def census(mind: Path) -> dict: """Inventory the Mind's work — filed prompts plus the registry's live rows. @@ -1371,8 +1388,10 @@ def census(mind: Path) -> dict: for f in sorted(folder.rglob("*.md")): if f.name == "README.md": continue - text = f.read_text(encoding="utf-8", errors="replace") rel = f.relative_to(mind) + if is_epic_companion(rel): + continue + text = f.read_text(encoding="utf-8", errors="replace") header = parse_header(text) missing = [h for h in HEADER_FIELDS if h not in header] themes = parse_theme_list(text) diff --git a/agents/conductors/profiling/_profiling.py b/agents/conductors/profiling/_profiling.py index 326be20a..9ed2af1d 100644 --- a/agents/conductors/profiling/_profiling.py +++ b/agents/conductors/profiling/_profiling.py @@ -93,6 +93,20 @@ COMPILE_DRIFT_RATIO = 2.0 COMPILE_DRIFT_FLOOR_S = 1.0 +# The 2x band is a GROSS flag, not a measured change: today every pin and every +# warm row is one compile timing, so drift compares one point against one point +# (the limitation autolens_profiling's timing-noise audit, #362, found in its P7 +# release badge). Decision (a) of draft/bug/pyautobrain/ +# profiling_compile_drift_point_vs_point.md: keep the band, say so on every +# drifted row. The repeat count is the compile analogue of P7's +# `single_jit_repeats`; no producer writes it yet, so it is read when present +# and never inferred — a row without it is a single sample. +COMPILE_REPEATS_FIELD = "compile_repeats" +SINGLE_SAMPLE_CAVEAT = ( + "single-sample endpoint(s): a gross 2x-band flag from one pinned timing vs " + "one observed timing, not a measured change" +) + # A warm compile at >= this fraction of its own cold cost has effectively stopped # being warm. Not 1.0: a cache miss need not reproduce the cold time exactly. CACHE_REVERT_FRACTION = 0.5 @@ -605,6 +619,33 @@ def campaign_compile(ws: Path, tier: str) -> dict[str, Any]: } +def _compile_repeats(d: dict[str, Any]) -> int | None: + """The repeat count a pin or record carries, or None when it carries none.""" + n = d.get(COMPILE_REPEATS_FIELD) + return n if isinstance(n, int) and not isinstance(n, bool) and n >= 1 else None + + +def _drift_sampling(pin: dict[str, Any], rec: dict[str, Any]) -> dict[str, Any]: + """How many timings stand behind each endpoint of a drift comparison. + + `single_sample` unless BOTH endpoints carry a repeat count >= 2 (P7's rule); + the counts are reported only when the data carries them. + """ + pinned, observed = _compile_repeats(pin), _compile_repeats(rec) + single = not (pinned and pinned >= 2 and observed and observed >= 2) + if single: + caveat = SINGLE_SAMPLE_CAVEAT + else: + caveat = (f"repeat-summarised endpoints (pinned n={pinned}, observed " + f"n={observed}); still compared against the gross 2x band") + return { + "comparison": "single-sample" if single else "repeat-summarised", + "pinned_repeats": pinned, + "observed_repeats": observed, + "caveat": caveat, + } + + def ingest_compile(ws: Path) -> dict[str, Any]: """Which warm compile rows are unpinned, and which have drifted from a pin. @@ -680,6 +721,9 @@ def ingest_compile(ws: Path) -> dict[str, Any]: # classifier treats None as "cannot rule host load in or out" # rather than as "the host was idle". "host_load": (rec.get("host_state") or {}).get("load_avg_1m"), + # Compile cost only: execution (runtime) cost is a separate + # axis and never folded into this comparison. + **_drift_sampling(pin, rec), } ) @@ -694,11 +738,15 @@ def ingest_compile(ws: Path) -> dict[str, Any]: f"Drift = a warm row NEWER than its pin, >= {COMPILE_DRIFT_RATIO}x the " f"pinned value AND >= {COMPILE_DRIFT_FLOOR_S}s absolute, compared ONLY " f"within {'/'.join(COMPARABILITY_FIELDS)}. Cross-key pairs and rows " - "predating the pin are never a regression." + "predating the pin are never a regression. Point-vs-point: unless both " + f"endpoints carry `{COMPILE_REPEATS_FIELD}` >= 2, a drifted row is a " + "single-sample comparison — a gross flag, not a measured change. Compile " + "cost only; execution cost is the runtime axis." ), "steps": [ "re-run the drifted cell warm to confirm it is not host load " - "(check the record's host_state against the pin's)", + "(check the record's host_state against the pin's) — a single-sample " + "drift is a prompt to measure again, not a verdict", "if confirmed, classify it — `pyauto-brain profiling triage --axis compile`", "pin the unpinned rows: `python3 scripts/misc/jax_compile/update_pins.py --write`", ], @@ -922,6 +970,8 @@ def triage_compile(ws: Path) -> dict[str, Any]: "finding": row["pin"], "observed_s": row["observed_s"], "pinned_s": row["pinned_s"], + "comparison": row["comparison"], + "caveat": row["caveat"], **_classify_drift(row, cold), } ) @@ -1109,6 +1159,7 @@ def emit_human(d: dict[str, Any]) -> None: f" {x['pin']}: pinned {x['pinned_s']}s -> observed " f"{x['observed_s']}s ({x['ratio']}x, tag={x['tag']!r})" ) + print(f" {x['caveat']}") print(f"Unpinned warm keys: {len(d['unpinned'])}") for x in d["unpinned"][:10]: print(f" {x['pin']}") @@ -1138,6 +1189,8 @@ def emit_human(d: dict[str, Any]) -> None: for f in d["findings"]: print(f" [{f['classification']}] {f['finding']}") print(f" evidence: {f['evidence']}") + if f.get("caveat"): + print(f" sampling: {f['caveat']}") print(f" -> {f['action']}") if d.get("policy"): print(f"Policy: {d['policy']}") diff --git a/tests/test_intake_dashboard.py b/tests/test_intake_dashboard.py index bef6e843..0339c8e3 100644 --- a/tests/test_intake_dashboard.py +++ b/tests/test_intake_dashboard.py @@ -1435,3 +1435,33 @@ def test_legacy_bundle_registry_and_headers_do_not_create_functionality(tmp_path for page in (_intake.render_dashboard(c), _intake.render_dashboard_html(c)): assert "Bundles" not in page and "start-bundle" not in page assert "draft/feature/widgets/a.md" in page and "draft/feature/widgets/b.md" in page + + +def test_epic_reports_surveys_and_reviews_are_not_backlog_work(tmp_path): + # An epic's companions sit beside its ledger under draft/ (the epic format), + # but they are read-only reports: the dashboard once offered 29 of them as + # pickable prompts with "Use the start-dev skill". + mind = _mind(tmp_path, drafts={ + "research/widgets/gizmo_epic.md": _prompt("Gizmo epic"), + "research/widgets/gizmo_epic_report.md": "# Gizmo report\n", + "research/widgets/gizmo_epic_surveys/01_code.md": "# Survey 01\n", + "research/widgets/gizmo_epic_reviews/01_model_scope.md": "# Review 01\n", + "feature/widgets/real_task.md": _prompt("A real task"), + }) + paths = {r["path"] for r in _intake.census(mind)["records"]} + assert paths == {"draft/research/widgets/gizmo_epic.md", + "draft/feature/widgets/real_task.md"} + page = _page(mind) + assert "Survey 01" not in page and "Review 01" not in page + assert "Gizmo report" not in page + assert "A real task" in page + + +def test_is_epic_companion_matches_only_the_epic_format_names(): + yes = ["draft/research/x/a_epic_report.md", + "draft/research/x/a_epic_surveys/01.md", + "draft/feature/x/a_epic_reviews/sub/02.md"] + no = ["draft/research/x/a_epic.md", "draft/bug/x/report.md", + "draft/research/x/surveys/01.md", "draft/research/x/epic_report_fix.md"] + assert all(_intake.is_epic_companion(Path(p)) for p in yes) + assert not any(_intake.is_epic_companion(Path(p)) for p in no) diff --git a/tests/test_intake_memory.py b/tests/test_intake_memory.py index 7c25387e..56f3d71e 100644 --- a/tests/test_intake_memory.py +++ b/tests/test_intake_memory.py @@ -174,3 +174,32 @@ def test_library_target_with_hits_still_gets_memory_line(tmp_path, monkeypatch): rel = _intake.write_prompt(mind, decision, raw, "test") line = _memory_line((mind / rel).read_text(encoding="utf-8")) assert "wiki/lensing/concepts/subhalo.md" in line + + +def test_organ_target_spellings_get_no_memory_line(tmp_path, monkeypatch): + """`Target:` is matched case-insensitively and through an @-mention: a + hand-written `pyautobrain` or `@PyAutoBrain` is still an organ target. + The loop also covers every repo the body map checks out under organs/ + without `category: organ` (read from repos.yaml, never named here — the + tenant firewall keeps instance facts out of test files).""" + monkeypatch.delenv("PYAUTO_MEMORY", raising=False) + mind = _mind(tmp_path) + _memory(tmp_path) + organs_dir_only = sorted(_intake._ORGANS_DIR_REPOS - _intake.ORGANISM_REPOS) + assert organs_dir_only, "repos.yaml should hold an organs/ repo outside category: organ" + for spelling in ("pyautobrain", "@PyAutoBrain", "PYAUTOMIND", + "@pyautoheart", *organs_dir_only): + assert not _intake._cites_memory(spelling), spelling + assert _intake._with_memory("Priority: normal", ["wiki/x.md"], + spelling) == "Priority: normal", spelling + raw = _declared(spelling) + decision = _intake.analyse(raw, "test") + rel = _intake.write_prompt(mind, decision, raw, "test") + text = (mind / rel).read_text(encoding="utf-8") + assert "Memory:" not in text, spelling + # a library target spelled the same loose ways still cites + library = sorted(_intake.LIBRARY_REPOS)[0] + for spelling in (library.lower(), "@" + library): + assert _intake._cites_memory(spelling), spelling + assert _intake._with_memory("Priority: normal", ["wiki/x.md"], + spelling).endswith("Memory: wiki/x.md") diff --git a/tests/test_profiling_conductor.py b/tests/test_profiling_conductor.py index aec6040f..8c5d0908 100644 --- a/tests/test_profiling_conductor.py +++ b/tests/test_profiling_conductor.py @@ -357,6 +357,52 @@ def test_a_warm_row_reverting_toward_cold_is_drift(tmp_path): assert x["ratio"] > 50 +def test_compile_drift_is_reported_as_a_single_sample_comparison(tmp_path): + """Synthetic witness for decision (a) of + profiling_compile_drift_point_vs_point.md: the 2x band stays as a gross + flag, and a drift between two single-sample endpoints says so; a move + inside the band is no drift at all.""" + ws = _workspace(tmp_path, {"local_cpu/mge.json": [ + _warm(compile_s=10.0, transform="vag"), # 2.5x a 4.0s pin -> drift + _warm(compile_s=6.0, transform="jit"), # 1.5x a 4.0s pin -> in band + ]}) + _pinned(ws, [_pin(compile_s=4.0, transform="vag"), _pin(compile_s=4.0, transform="jit")]) + d = json.loads(_run(["ingest", "--axis", "compile", "--json"], ws).stdout) + + assert len(d["drifted"]) == 1, "only the >2x endpoint pair drifts" + x = d["drifted"][0] + assert "[vag]" in x["pin"] and x["ratio"] == 2.5 + assert x["comparison"] == "single-sample" + assert x["pinned_repeats"] is None and x["observed_repeats"] is None, \ + "no repeat counts in the data -> none reported, never invented" + assert x["caveat"].startswith("single-sample endpoint(s)") + assert "single-sample" in d["policy"] and "Compile cost only" in d["policy"] + + text = _run(["ingest", "--axis", "compile"], ws).stdout + assert "single-sample endpoint(s)" in text + + t = json.loads(_run(["triage", "--axis", "compile", "--json"], ws).stdout) + drift = [f for f in t["findings"] if "[vag]" in f["finding"]] + assert drift and drift[0]["comparison"] == "single-sample" + + +def test_compile_drift_reports_repeat_counts_when_the_data_carries_them(tmp_path): + ws = _workspace(tmp_path, {"local_cpu/mge.json": [ + _warm(compile_s=10.0, compile_repeats=5), + ]}) + _pinned(ws, [_pin(compile_s=4.0, compile_repeats=3)]) + x = json.loads(_run(["ingest", "--axis", "compile", "--json"], ws).stdout)["drifted"][0] + assert x["comparison"] == "repeat-summarised" + assert (x["pinned_repeats"], x["observed_repeats"]) == (3, 5) + assert "pinned n=3, observed n=5" in x["caveat"] + + # one repeat-summarised endpoint is not enough: still single-sample + ws2 = _workspace(tmp_path / "b", {"local_cpu/mge.json": [_warm(compile_s=10.0, compile_repeats=5)]}) + _pinned(ws2, [_pin(compile_s=4.0)]) + y = json.loads(_run(["ingest", "--axis", "compile", "--json"], ws2).stdout)["drifted"][0] + assert y["comparison"] == "single-sample" and y["observed_repeats"] == 5 + + def test_rows_predating_the_pin_are_not_drift(tmp_path): """The pin was CHOSEN over this history; flagging it reports the improvement that set the pin as a regression."""