diff --git a/.specfuse/features/FEAT-LOOP-2026-0250-gate-timings/GATE-01-CRITERIA.md b/.specfuse/features/FEAT-LOOP-2026-0250-gate-timings/GATE-01-CRITERIA.md new file mode 100644 index 00000000..bdd680ed --- /dev/null +++ b/.specfuse/features/FEAT-LOOP-2026-0250-gate-timings/GATE-01-CRITERIA.md @@ -0,0 +1,119 @@ +### T01#1 + +- **criterion:** `tests.test_gate_timings.TestAttemptGateEvents` fails on HEAD and passes after. It drives one +- **oracle:** python3 -m unittest tests.test_gate_timings.TestAttemptGateEvents -b +- **kind:** `narrow` +- **state:** `pass` +- **proved_at_sha:** `158389e952114613487622605f9b1cf5eef49ad1` +- **attempt:** `1` +- **covers:** specfuse/loop/loop.py, specfuse/loop/data/schemas/driver-event.schema.json, tests/test_gate_timings.py + +### T01#2 + +- **criterion:** `TestNothingExistingChanges` asserts `gate_result` is in the schema's `event_types`. +- **oracle:** python3 -m unittest tests.test_gate_timings.TestNothingExistingChanges.test_gate_result_in_schema_event_types -b +- **kind:** `narrow` +- **state:** `pass` +- **proved_at_sha:** `158389e952114613487622605f9b1cf5eef49ad1` +- **attempt:** `1` +- **covers:** specfuse/loop/loop.py, specfuse/loop/data/schemas/driver-event.schema.json, tests/test_gate_timings.py + +### T01#3 + +- **criterion:** `python3 -m unittest tests.test_dispatch_skeleton tests.test_loop_worklist_injection -b` +- **oracle:** python3 -m unittest tests.test_dispatch_skeleton tests.test_loop_worklist_injection -b +- **kind:** `narrow` +- **state:** `pass` +- **proved_at_sha:** `158389e952114613487622605f9b1cf5eef49ad1` +- **attempt:** `1` +- **covers:** specfuse/loop/loop.py, specfuse/loop/data/schemas/driver-event.schema.json, tests/test_gate_timings.py + +### T02#1 + +- **criterion:** `tests.test_gate_timings.TestAttemptSplit` fails on HEAD and passes after. With a stubbed +- **oracle:** python3 -m unittest tests.test_gate_timings.TestAttemptSplit -b +- **kind:** `narrow` +- **state:** `pass` +- **proved_at_sha:** `158389e952114613487622605f9b1cf5eef49ad1` +- **attempt:** `1` +- **covers:** specfuse/loop/loop.py, tests/test_gate_timings.py + +### T02#2 + +- **criterion:** The same class asserts an attempt whose agent reports `blocked` records `verify_seconds: 0`. +- **oracle:** python3 -m unittest tests.test_gate_timings.TestAttemptSplit.test_blocked_records_zero_verify -b +- **kind:** `narrow` +- **state:** `pass` +- **proved_at_sha:** `158389e952114613487622605f9b1cf5eef49ad1` +- **attempt:** `1` +- **covers:** specfuse/loop/loop.py, tests/test_gate_timings.py + +### T02#3 + +- **criterion:** `python3 -m unittest tests.test_dispatch_skeleton tests.test_files_changed_auto_repair -b` +- **oracle:** python3 -m unittest tests.test_dispatch_skeleton tests.test_files_changed_auto_repair -b +- **kind:** `narrow` +- **state:** `pass` +- **proved_at_sha:** `158389e952114613487622605f9b1cf5eef49ad1` +- **attempt:** `1` +- **covers:** specfuse/loop/loop.py, tests/test_gate_timings.py + +### T03#1 + +- **criterion:** `tests.test_gate_timings.TestBaselineAndBroadPhases` fails on HEAD and passes after. It +- **oracle:** python3 -m unittest tests.test_gate_timings.TestBaselineAndBroadPhases -b +- **kind:** `narrow` +- **state:** `pass` +- **proved_at_sha:** `158389e952114613487622605f9b1cf5eef49ad1` +- **attempt:** `1` +- **covers:** specfuse/loop/loop.py, tests/test_gate_timings.py + +### T03#2 + +- **criterion:** `broad_run_result` and `baseline_attribution` payloads are unchanged; the same class asserts +- **oracle:** python3 -m unittest tests.test_gate_timings.TestBaselineAndBroadPhases -b +- **kind:** `narrow` +- **state:** `pass` +- **proved_at_sha:** `158389e952114613487622605f9b1cf5eef49ad1` +- **attempt:** `1` +- **covers:** specfuse/loop/loop.py, tests/test_gate_timings.py + +### T03#3 + +- **criterion:** The narrow tier passes with no existing broad-run or baseline test edited. +- **oracle:** python3 -m unittest tests.test_gate_timings tests.test_dispatch_skeleton tests.test_events_stats -b +- **kind:** `narrow` +- **state:** `pass` +- **proved_at_sha:** `158389e952114613487622605f9b1cf5eef49ad1` +- **attempt:** `1` +- **covers:** specfuse/loop/loop.py, tests/test_gate_timings.py + +### T04#1 + +- **criterion:** `tests.test_gate_timings.TestStatsReport` fails on HEAD and passes after: a corpus with +- **oracle:** python3 -m unittest tests.test_gate_timings.TestStatsReport -b +- **kind:** `narrow` +- **state:** `pass` +- **proved_at_sha:** `158389e952114613487622605f9b1cf5eef49ad1` +- **attempt:** `1` +- **covers:** specfuse/loop/events_stats.py, docs/methodology.md, tests/test_gate_timings.py + +### T04#2 + +- **criterion:** `python3 -m unittest tests.test_events_stats -b` passes unchanged. +- **oracle:** python3 -m unittest tests.test_events_stats -b +- **kind:** `narrow` +- **state:** `pass` +- **proved_at_sha:** `158389e952114613487622605f9b1cf5eef49ad1` +- **attempt:** `1` +- **covers:** specfuse/loop/events_stats.py, docs/methodology.md, tests/test_gate_timings.py + +### T04#3 + +- **criterion:** `grep -c "unittest.skip" tests/test_gate_timings.py` prints `0`. +- **oracle:** grep -c "unittest.skip" tests/test_gate_timings.py +- **kind:** `narrow` +- **state:** `pass` +- **proved_at_sha:** `158389e952114613487622605f9b1cf5eef49ad1` +- **attempt:** `1` +- **covers:** specfuse/loop/events_stats.py, docs/methodology.md, tests/test_gate_timings.py diff --git a/.specfuse/features/FEAT-LOOP-2026-0250-gate-timings/GATE-01.md b/.specfuse/features/FEAT-LOOP-2026-0250-gate-timings/GATE-01.md new file mode 100644 index 00000000..aae1b6bd --- /dev/null +++ b/.specfuse/features/FEAT-LOOP-2026-0250-gate-timings/GATE-01.md @@ -0,0 +1,72 @@ +--- +gate: 1 +status: passed +feature_oracle: "python3 -m unittest tests.test_gate_timings -v -b" +cost_budget_usd: 22.00 +baseline: + sha: 21191ae86fa93b0ae51ef939b522bd15b130ba6c + probed_at: 2026-11-25T15:20:21.670930+00:00 + tree: 07bbf72d1e7af3c1a03af605f40e5563dc3a18db:0ec7c6da6e74f0b56753f09657b654a6d289b91b:12064a6191eeb830a9826d911a8543fbaba3da75:1fb7d45b824d49ab8dee91cfcfb29ac17ff37a8f:27968248a450a842ccd187b7dce0fb0ded934866:287efde8f90320baffac08f5f3287b9456a65cb9:2e29b2f7e073a0cbe290f01d3b397e1cdd10c81c:302816f6805b548990c2e47c2264d6c68679b21d:42796ea0e0a6c03811b0e4bc9dbd3b5ee62dd2e4:4acc6dfc5e8cece358c167d876515eba4a39a500:7d6f6c977308ee2b7fe76ffe4f86fda3c776ef38:834d9d9c16094a386cd9b5a6f9ced9a3a9b4e7fb:91b2fa050120acfd6e3c5950af079ababcddb2a5:bbd1aea514612d76722a18c7aece7c767cf1a076:c23b62e87f1ae3890c6f9e3d8c7ca7ec9225ed81:caffe2d63ceacde448842a91bc7a12c206a67523:d74b7d113b844e84f0009098f576fd28477f072d:e3b0de29b81a6c8e0abeacb3898519b98014b9ef:fa2f4f88657587b6e3b560977858810846b1d366 + entry_sha: 21191ae86fa93b0ae51ef939b522bd15b130ba6c + source: attributed:FEAT-LOOP-2026-0250/T01 + failing: + - gate: tests + failure_class: tests + failure_signature: "(failures=2," + - gate: coverage + failure_class: other + failure_signature: "no_gate_marker" + - gate: roadmap-link-gate + failure_class: other + failure_signature: "ERROR: roadmap.md:131: ref '#feat-loop-2026-0250' in roadmap…und in roadmap.md or roadmap-archive.md" +broad_run: + tree: 07bbf72d1e7af3c1a03af605f40e5563dc3a18db:0ec7c6da6e74f0b56753f09657b654a6d289b91b:12064a6191eeb830a9826d911a8543fbaba3da75:27968248a450a842ccd187b7dce0fb0ded934866:287efde8f90320baffac08f5f3287b9456a65cb9:2e29b2f7e073a0cbe290f01d3b397e1cdd10c81c:302816f6805b548990c2e47c2264d6c68679b21d:38e1639a0c46c0cd3e0a1bcee16359e18cf4c70f:42796ea0e0a6c03811b0e4bc9dbd3b5ee62dd2e4:4acc6dfc5e8cece358c167d876515eba4a39a500:83478ee1d28da445abebbea95e402a2501fa1343:834d9d9c16094a386cd9b5a6f9ced9a3a9b4e7fb:ae39d552df928f10c8c11cb2a541575d68665933:bbd1aea514612d76722a18c7aece7c767cf1a076:c23b62e87f1ae3890c6f9e3d8c7ca7ec9225ed81:caffe2d63ceacde448842a91bc7a12c206a67523:d74b7d113b844e84f0009098f576fd28477f072d:e3b0de29b81a6c8e0abeacb3898519b98014b9ef:fa2f4f88657587b6e3b560977858810846b1d366 + ran_at: 2026-11-25T15:49:51.825704+00:00 + ok: true + failing: [] +--- + +# Gate 1 — per-gate timings are recorded, and `specfuse stats` reads them + +## Definition of done + +**Stated as an outcome.** In temporary feature folders, with real gate subprocesses (commands +that sleep a known time and exit 0 or 1) and a stubbed agent session: + +1. **Attempt phase.** Each attempt emits one `gate_result` event per gate in its set, the + `feature_oracle` included, carrying `attempt`, `gate`, `ok`, `duration_seconds` and + `phase: attempt`. A gate's `duration_seconds` is at least its command's sleep. A gate skipped + because a dependency failed records `ok: false`, `skipped: true`, `duration_seconds: 0`. +2. **Split.** `attempt_outcome` carries `agent_seconds` and `verify_seconds`, and + `agent_seconds + verify_seconds <= duration_seconds`. An attempt that stopped before + verification (the agent reported blocked) records `verify_seconds: 0`. +3. **Baseline and broad phases.** The baseline probe and the broad run each emit one + `gate_result` per gate with `phase: baseline` or `phase: broad`. A broad run skipped because + the tree is unchanged emits none. +4. **Stats.** `specfuse stats` (text and `--json`) reports the agent/verify split per feature and + the slowest gates (runs, total, median, max seconds). On a corpus with no `gate_result` events + and no split fields it says "not recorded", never zeros. +5. **Nothing existing changes.** `duration_seconds` keeps its meaning; every existing test that + stubs `verify_fn` passes unchanged; `gate_result` is in `driver-event.schema.json` and every + emitted event type validates against it. + +The `feature_oracle` proves 1–5. It is red on the current tree; `FEAT-LOOP-2026-0250/T01` is the +walking skeleton that creates `tests/test_gate_timings.py` and turns clause 1 and clause 5's +schema half green, with every other class `unittest.skip` naming its owner (T02–T04). A skip +surviving to the close is a hollow oracle. + +## Arming discipline (see `.specfuse/rules/planning-discipline.md`) + +- **One runner.** Timing lives in `_run_gate_set()`; the three phases differ only in the `phase` + tag and correlation ID they emit with. +- **Positive controls.** Clause 1 pairs a passing gate with a failing one and a skipped + dependent; clause 3 pairs a fresh broad run with a tree-unchanged skip; clause 4 pairs a new + corpus with an old one. +- **Real subprocesses, stubbed agent.** Gate durations come from real `sleep` commands, so a + duration recorded as a constant fails the lower-bound check. +- **Expected self-halt.** `loop.py` and the event schema are judge surfaces; acknowledge the + stop with your own reason and `/unblock-wu`. + +## Reflection notes + + diff --git a/.specfuse/features/FEAT-LOOP-2026-0250-gate-timings/LEARNINGS-pending.md b/.specfuse/features/FEAT-LOOP-2026-0250-gate-timings/LEARNINGS-pending.md new file mode 100644 index 00000000..4840014c --- /dev/null +++ b/.specfuse/features/FEAT-LOOP-2026-0250-gate-timings/LEARNINGS-pending.md @@ -0,0 +1,24 @@ + + +# Lessons staged for promotion — FEAT-LOOP-2026-0250 + +`autonomy_default: auto`, so `FEAT-LOOP-2026-0250/G1-CLOSE` may not append to +`.specfuse/LEARNINGS.md` directly (`assert_learnings_staged_under_auto`). Two entries generalize. + +## Entries + +- [FEAT-LOOP-2026-0250/T04] **A unit that edits `docs/*.md` must also refresh that file's packaged + copy under `specfuse/loop/data/docs/` in the same unit.** T04 edited `docs/methodology.md` and + not its packaged copy; its narrow tier selected no docs-sync test, so it passed, and three + docs-sync tests went red only in the gate's broad run. Run `scripts/sync-scaffold.sh` before + reporting, and list the packaged copy in `produces:` so the diff guard sees it. + +- [FEAT-LOOP-2026-0250/T01] **A test that validates events through `validate_event` must pin the + real packaged schemas and clear the validator's module caches.** `test_emitted_events_validate` + passed alone and failed in the full suite because an earlier test left + `_DRIVER_EVENT_TYPES_CACHE` empty, dropping every driver event type from the enum. Copy the + pinning from `tests/test_event_gate_full_envelope.py` when writing the test, not after the broad + run fails. diff --git a/.specfuse/features/FEAT-LOOP-2026-0250-gate-timings/PLAN.baseline.json b/.specfuse/features/FEAT-LOOP-2026-0250-gate-timings/PLAN.baseline.json new file mode 100644 index 00000000..2f8adec1 --- /dev/null +++ b/.specfuse/features/FEAT-LOOP-2026-0250-gate-timings/PLAN.baseline.json @@ -0,0 +1,39 @@ +{ + "gates": [ + { + "gate": 1, + "work_units": [ + { + "goal": "T01 \u2014 walking skeleton: attempt-phase `gate_result` events", + "id": "FEAT-LOOP-2026-0250/T01", + "planned_cost_usd": 4.0, + "type": "implementation" + }, + { + "goal": "T02 \u2014 `agent_seconds` and `verify_seconds` on `attempt_outcome`", + "id": "FEAT-LOOP-2026-0250/T02", + "planned_cost_usd": 3.0, + "type": "implementation" + }, + { + "goal": "T03 \u2014 `gate_result` events for the baseline probe and the broad run", + "id": "FEAT-LOOP-2026-0250/T03", + "planned_cost_usd": 3.5, + "type": "implementation" + }, + { + "goal": "T04 \u2014 `specfuse stats` reports the split and the slowest gates; docs", + "id": "FEAT-LOOP-2026-0250/T04", + "planned_cost_usd": 3.0, + "type": "implementation" + }, + { + "goal": "G1-CLOSE \u2014 terminal close", + "id": "FEAT-LOOP-2026-0250/G1-CLOSE", + "planned_cost_usd": 5.0, + "type": "close" + } + ] + } + ] +} diff --git a/.specfuse/features/FEAT-LOOP-2026-0250-gate-timings/PLAN.md b/.specfuse/features/FEAT-LOOP-2026-0250-gate-timings/PLAN.md new file mode 100644 index 00000000..375944d7 --- /dev/null +++ b/.specfuse/features/FEAT-LOOP-2026-0250-gate-timings/PLAN.md @@ -0,0 +1,111 @@ +--- +feature_id: FEAT-LOOP-2026-0250 +title: Record verification gate results and durations +slug: gate-timings +branch: feat/FEAT-LOOP-2026-0250-gate-timings +roadmap_goal: An operator who finds the loop slow can read from `specfuse stats` how much attempt time went to the agent versus the verification gates, and which gates cost the most. +autonomy_default: auto +status: done +planned_cost_usd: 18.50 +--- + +# Plan: Record verification gate results and durations + +`attempt_outcome.payload.duration_seconds` is one wall-clock timer around +`execute_unit_attempt()` (`loop.py`, the `t0 = time.monotonic()` in the attempt loop). It +covers the agent session and every verification gate together. No event says which gates +ran, how long each took, or which passed, and `broad_run_result` carries no duration either. +An operator report measured 184 attempts, about 17.5 hours of attempt time, with no way to +say how much was the agent and how much the gates. Without that split, every optimisation +is a guess: smaller work units, a different model or effort, a faster gate, or the parallel +gates and result cache proposed separately. + +This feature records one `gate_result` event per gate per run (attempt, baseline probe, +broad run), splits `attempt_outcome` into `agent_seconds` and `verify_seconds`, and makes +`specfuse stats` report both. It measures; it speeds nothing up. + +## Decisions (2026-11-25) + +The operator said "take your recommendations" after the first interview question and then +accepted this list. Each item is a recommendation applied on that instruction. + +1. **Events plus stats.** `events_stats.py` reports the agent/verify split per feature and + the slowest gates. Events nobody can read without ad-hoc Python do not remove the guess + (the reason `events_stats.py` exists, #271). +2. **Autonomy `auto`.** A fresh judge session writes the terminal verdict from evidence only. + `loop.py` is a judge surface, so the terminal judge-editing stop fires before the close: + acknowledge it with your own reason and `/unblock-wu`. +3. **One gate**, four substantive units and a terminal `close`, under the 12-unit threshold + (`docs/methodology.md` §6). +4. **Attempt-phase `gate_result` events are buffered in `wu_events`** with `attempt_outcome` + and flushed at the same point. A killed attempt loses them as it already loses its + outcome (LEARNINGS `[FEAT-LOOP-2026-0070/G1-CLOSE-INTERMEDIATE]`); changing that is out of + scope. +5. **Split definition.** `agent_seconds` is wall-clock around the agent-session call, + `verify_seconds` wall-clock around the gate-set call, both inside `execute_unit_attempt()`. + `duration_seconds` keeps its meaning (the total); the remainder is driver overhead and is + not named. An attempt that never reached verification records `verify_seconds: 0`. +6. **How per-gate results leave `verify()` is the implementer's call**, under one constraint: + every existing test that stubs `verify_fn` (e.g. `tests/test_dispatch_skeleton.py`) passes + unchanged. + +**Out of scope:** a live progress view or halt notification; parallel gates or a result +cache; backfilling old `events.jsonl` files; persisting events from killed attempts. + +## Existing-mechanism search (mandatory — see `.specfuse/rules/planning-discipline.md` §1) + +- **Grep command run:** `git grep -nE "gate_duration|gate_seconds|verify_seconds|agent_seconds|gate_result|elapsed" -- 'specfuse/*.py'` + and `grep -n "duration\|monotonic" specfuse/loop/loop.py` +- **Verdict:** no existing per-gate timing, building new. The only hits are `specfuse/agent/budget.py`'s + run-level elapsed minutes and an unrelated `gate_result` local variable in + `specfuse/agent/drafting_invoke.py` (an answer-gate result, not an event type). The + persisted gate logs under `work/gate-logs/` (#3293) are gitignored scratch with no + duration field, so they are not a record. +- **If reusing:** the registry `specfuse/loop/data/schemas/driver-event.schema.json` gains + one event type, the same way `broad_run_result` was added (FEAT-2026-0109/T06). + `_run_gate_set()` is the single runner all three phases already share. + +## Escalation-predicate satisfiability (mandatory for any severity flip — §2) + +n/a — no check changes severity and nothing blocks on the new data. + +## Task graph + +```yaml +gates: + - gate: 1 + file: GATE-01.md + work_units: + - id: FEAT-LOOP-2026-0250/T01 + file: WU-01-attempt-gate-events.md + depends_on: [] + - id: FEAT-LOOP-2026-0250/T02 + file: WU-02-agent-verify-split.md + depends_on: [FEAT-LOOP-2026-0250/T01] + - id: FEAT-LOOP-2026-0250/T03 + file: WU-03-baseline-and-broad.md + depends_on: [FEAT-LOOP-2026-0250/T01] + - id: FEAT-LOOP-2026-0250/T04 + file: WU-04-stats-and-docs.md + depends_on: [FEAT-LOOP-2026-0250/T02, FEAT-LOOP-2026-0250/T03] + # --- closing sequence: single terminal close (single-gate feature) --- + - id: FEAT-LOOP-2026-0250/G1-CLOSE + file: WU-90-gate-1-close.md + depends_on: [FEAT-LOOP-2026-0250/T01, FEAT-LOOP-2026-0250/T02, FEAT-LOOP-2026-0250/T03, FEAT-LOOP-2026-0250/T04] +``` + +## Post-merge checklist + +- Run one real feature and check that `agent_seconds + verify_seconds` is close to + `duration_seconds` on real attempts (the oracle stubs the agent session). +- Run `specfuse stats` on the corpus that motivated this feature and confirm the slowest-gates + view names real gates. + +## Notes + +- LEARNINGS `[FEAT-LOOP-2026-0053/G2-CLOSE]`: any aggregate over per-attempt duration must sum + every field the lifetime is spread across; T04's per-feature split reads `events.jsonl`, which + never loses a cycle. +- LEARNINGS `[FEAT-LOOP-2026-0057/G1-CLOSE]`: buffered events are flushed only at the unit's + terminal outcome, so a close reading its own `gate_result` events mid-session sees none. +- `produces:` lists only `.py` files under `tests/` (#3539). diff --git a/.specfuse/features/FEAT-LOOP-2026-0250-gate-timings/PROGRESS.md b/.specfuse/features/FEAT-LOOP-2026-0250-gate-timings/PROGRESS.md new file mode 100644 index 00000000..cbc12659 --- /dev/null +++ b/.specfuse/features/FEAT-LOOP-2026-0250-gate-timings/PROGRESS.md @@ -0,0 +1,7 @@ +- **FEAT-LOOP-2026-0250/T01**: _run_gate_set times each spawned gate (duration_seconds, skipped gates get skipped:True and duration_seconds:0). verify() stores the per-gate results on wu.last_gate_results, and run() emits one attempt-phase gate_result per gate via build_attempt_gate_events. The schema now lists gate_result. + - note: Side channel is WorkUnit.last_gate_results, reset before each attempt, so the verify_fn signature is unchanged. Reuse build_event("gate_result", ...) with phase baseline or broad for T03. +- **FEAT-LOOP-2026-0250/T02**: attempt 1 outcome=passed +- **FEAT-LOOP-2026-0250/T03**: Added gate_result events for fresh baseline probes (phase "baseline") and fresh broad runs (phase "broad"), both with attempt null. Tree-unchanged skips emit none. TestBaselineAndBroadPhases now has real tests and they pass; the narrow tier passes. +- **FEAT-LOOP-2026-0250/T04**: attempt 1 outcome=passed +- **FEAT-LOOP-2026-0250/G1-CLOSE**: Wrote RETROSPECTIVE.md (per-clause proof, cost reconciliation, "did NOT verify"), three changelog.d fragments tracing to FEAT-LOOP-2026-0250, LEARNINGS-pending.md, and annotated the 12 criteria in GATE-01-CRITERIA.md. I set verdict met in WU-90. The closing lint passes. + - note: This feature's own agent/verify split reads "not recorded" because all 5 attempts ran on builds pinned before T01-T03 landed. The first real split will show on the next feature run after merge. Two post-merge items remain open (real-attempt check, and running stats on the motivating corpus). diff --git a/.specfuse/features/FEAT-LOOP-2026-0250-gate-timings/RETROSPECTIVE.md b/.specfuse/features/FEAT-LOOP-2026-0250-gate-timings/RETROSPECTIVE.md new file mode 100644 index 00000000..3c4fb1e6 --- /dev/null +++ b/.specfuse/features/FEAT-LOOP-2026-0250-gate-timings/RETROSPECTIVE.md @@ -0,0 +1,231 @@ +# Retrospective — FEAT-LOOP-2026-0250 gate 1 close + +First and only close of gate 1 (single-gate feature, PLAN decision 3). Four loop-dispatched +implementation units (T01–T04). This session re-ran the oracles fresh, annotated +`GATE-01-CRITERIA.md`, wrote the changelog fragments and this file. + +## Measurements + +Every command below was run in this session from the repository root, exit codes read +directly. HEAD was `158389e952114613487622605f9b1cf5eef49ad1` plus this close's own +uncommitted edits (`changelog.d/`, this file, `LEARNINGS-pending.md`, `GATE-01-CRITERIA.md`, +the `verdict` field of `WU-90-gate-1-close.md`). The close session may not run git commits. + +### feature_oracle: PASS + +Command: `python3 -m unittest tests.test_gate_timings -v -b` (exit 0): `Ran 13 tests` / `OK`, +every class running, none skipped (the run prints no `skipped` marker). + +``` +TestAttemptGateEvents 3 +TestAttemptSplit 3 +TestBaselineAndBroadPhases 3 +TestStatsReport 2 +TestNothingExistingChanges 2 +``` + +### No surviving skip (close criterion 1) + +`grep -c "unittest.skip" tests/test_gate_timings.py` prints `0`. A looser `grep -nE "skip|Skip"` +matches only the `skipped` payload key, two test names with `skip` in them, and the docstring line +recording the walking skeleton's history. T01 created the module with clauses 2–4 and clause 5's non-schema half +skipped by owner name; T02, T03 and T04 each removed their own. + +### Closing lint (close criterion 5) + +`python3 .specfuse/scripts/lint_plan.py .specfuse/features/FEAT-LOOP-2026-0250-gate-timings --closing` +is run last, after the verdict field is written; its result is in the RESULT block of this +attempt. The bare `specfuse lint --closing` warns that it measures the pipx-installed build +rather than this checkout, so the checkout's script was run instead. + +### Broad run (driver's, not re-run here) + +`events.jsonl` records two `broad_run_result` events for gate 1. The first, at +2026-11-25T15:37:40, was `ok: false` (`tests` `(failures=4,`, `coverage` `no_gate_marker`) +and raised `human_escalation` `broad_run_gate_failure`. The second, at 15:49:51, was `ok: true`, +`failing: []`, on the tree in `GATE-01.md`'s `broad_run:` block. `security` and `coverage` are +`tier: broad` and are the driver's. + +### Per-criterion oracles (12 criteria, `GATE-01-CRITERIA.md`) + +carried forward: 0 criteria, re-measured: 12 + +All twelve were `unverified` on entry. Each was run in this session as its own command; each now +records its oracle command, `kind: narrow`, `state: pass`, `attempt: 1` and `proved_at_sha` +`158389e952114613487622605f9b1cf5eef49ad1`, all exit 0. + +| criterion | oracle | ran | +| --- | --- | --- | +| T01#1 | `TestAttemptGateEvents` | 3 tests, OK | +| T01#2 | `TestNothingExistingChanges.test_gate_result_in_schema_event_types` | 1 test, OK | +| T01#3 | `tests.test_dispatch_skeleton tests.test_loop_worklist_injection` | 20 tests, OK | +| T02#1 | `TestAttemptSplit` | 3 tests, OK | +| T02#2 | `TestAttemptSplit.test_blocked_records_zero_verify` | 1 test, OK | +| T02#3 | `tests.test_dispatch_skeleton tests.test_files_changed_auto_repair` | 18 tests, OK | +| T03#1 | `TestBaselineAndBroadPhases` | 3 tests, OK | +| T03#2 | same class; asserts the key set of the failing-gate lists, see "did NOT verify" 4 | 3 tests, OK | +| T03#3 | `tests.test_gate_timings tests.test_dispatch_skeleton tests.test_events_stats` | 45 tests, OK | +| T04#1 | `TestStatsReport` | 2 tests, OK | +| T04#2 | `tests.test_events_stats` | 20 tests, OK | +| T04#3 | `grep -c "unittest.skip" tests/test_gate_timings.py` | `0` | + +### Definition of done, clause by clause (close criterion 1) + +| clause | proven by | result | +| --- | --- | --- | +| 1. one `gate_result` per gate per attempt, `feature_oracle` included; duration at least the sleep; skipped dependent `ok: false`, `skipped: true`, `0` | `TestAttemptGateEvents.test_one_gate_result_per_gate_with_payload`, `test_durations_and_skip_semantics`, `test_stub_verify_without_gate_results_emits_none`; real `sleep` gates, one passing, one failing, one dependent, plus a sleeping `feature_oracle` | proven, positive control present | +| 2. `attempt_outcome` carries `agent_seconds` and `verify_seconds`, sum at most `duration_seconds`; blocked attempt records `verify_seconds: 0` | `TestAttemptSplit.test_split`, `test_blocked_records_zero_verify`, `test_defaults_when_usage_lacks_keys` | proven with a stubbed session that sleeps and a real sleeping gate | +| 3. baseline probe and broad run emit one `gate_result` per gate with `phase: baseline` / `broad`; unchanged-tree broad skip emits none | `TestBaselineAndBroadPhases.test_broad_run_phase`, `test_baseline_phase`, `test_unchanged_tree_broad_skip_emits_none` | proven at the `build_phase_gate_events` seam; the broad half also observed live, 18 `gate_result` events in this feature's `events.jsonl` | +| 4. `specfuse stats` (text and `--json`) reports the split and the slowest gates; an old corpus reads `not recorded`, never zeros | `TestStatsReport.test_new_corpus_reports_split_and_gates`, `test_old_corpus_reads_not_recorded` (positive control: new and old corpus) | proven; also observed live, see Cost analysis | +| 5. nothing existing changes: `duration_seconds` keeps its meaning, `verify_fn` stubs pass unchanged, `gate_result` in the schema and every emitted shape validates | `TestNothingExistingChanges.test_gate_result_in_schema_event_types`, `test_emitted_events_validate`; `tests.test_dispatch_skeleton`, `tests.test_files_changed_auto_repair`, `tests.test_events_stats` pass unedited | proven for the three new or changed shapes; `duration_seconds` meaning has no dedicated assertion, see "did NOT verify" 5 | + +No `unittest.skip` survives in `tests/test_gate_timings.py` (grep above prints `0`). + +## Cost analysis + +Reconciled from `events.jsonl` `attempt_outcome` events and each unit's `planned_cost_usd`. +The unit plans sum to **18.50** (13.50 for T01–T04 plus 5.00 for this close), matching +`PLAN.md`; `GATE-01.md` sets `cost_budget_usd: 22.00`. + +| unit | planned (USD) | actual (USD) | attempts (outcomes) | duration (s) | +| --- | --- | --- | --- | --- | +| T01 | 4.00 | 0.7950 | 2 (failed `other`, passed) | 358.3 | +| T02 | 3.00 | 0.3352 | 1 (passed) | 79.8 | +| T03 | 3.50 | 0.2817 | 1 (passed) | 72.0 | +| T04 | 3.00 | 0.2925 | 1 (passed) | 54.1 | +| T01–T04 | 13.50 | 1.7043 | 5 recorded | 564.2 | +| G1-CLOSE (this attempt) | 5.00 | not yet recorded | 1 | — | +| **recorded total** | 18.50 | **1.7043** | 5 recorded | 564.2 | + +The five recorded attempts spent $1.70 (12.6% of the $13.50 planned for them, 7.7% of +`cost_budget_usd`). This close's own attempt is written when the driver ends it, so it is not +reconciled and the total excludes it. T01's frontmatter `cost_usd` (0.3842) is its second +dispatch only; `events.jsonl` has both attempts, 0.4108 and 0.3842. The two gate-1 broad runs and +the baseline probe are the driver's with no model session, so they are not charged to a unit. +The two repair commits between T01 and the close (`75c1ace`, `60dc90f`) were made outside the +driver, so `events.jsonl` carries no cost for them. + +**T01's two attempts.** The first (291.2 s, $0.4108) failed `roadmap-link-gate`: the drafted +roadmap detail section had no `` anchor, so the row's detail link did +not resolve. The driver's baseline probe then found `tests` (`(failures=2,`), `coverage` +(`no_gate_marker`) and `roadmap-link-gate` failing on the reset tree, attributed the failure to +the branch rather than to T01, and raised `human_escalation` `preexisting_gate_failure`. Commit +`75c1ace` added the anchor and reopened the gate; the second dispatch passed in 67.1 s. + +**What the broad run caught.** Four tests failed in the first broad run that no unit's narrow +tier selected: `TestNothingExistingChanges.test_emitted_events_validate` passed alone and failed +in the full suite (a module-level cache in `validate_event` left empty by an earlier test), and +three docs-sync tests failed because T04 edited `docs/methodology.md` without its packaged copy. +Commit `60dc90f` fixed both and the second broad run was clean. + +**What the self-halt cost.** The terminal judge-editing stop fired at 2026-11-25T15:49:51 (PLAN +decision 2) and was acknowledged by the operator at 17:03:29: about 73 minutes of wall-clock, $0.00 +driver spend, three acknowledged keys (`produces_driver_helper`, +`specfuse/loop/data/schemas/driver-event.schema.json`, `specfuse/loop/loop.py`). + +### This feature's own agent/verify split (close criterion 3) + +`python3 -m specfuse.loop.events_stats --roots .` (the module `specfuse stats` calls, run from the +checkout because the installed build is not this tree; exit 0) prints, for the whole repository: + +``` +agent / verify time per feature + not recorded +``` + +and `--json` carries `"time_split": {}`. This feature's split is therefore **not recorded**, and +that is the correct reading, not a defect: all five attempts ran under driver builds pinned before +T01–T03 landed (`driver_build_pinned` and `driver_staleness_detected` with `halted: false` for each +unit in `events.jsonl`), so none of the five `attempt_outcome` events carries `agent_seconds` or +`verify_seconds`. Nothing renders `0` where it should read `not recorded`. No attempt on this +repository carries the split yet. + +What this repository does record is the broad phase. `gate_timings` holds 18 `phase: broad` rows +from the clean 15:49:51 run, 351.3 s of gate time in total, of which `tests` is 311.0 s (88.5%), +then `leak-scan` 17.9 s, `sync-scaffold-bats` 10.8 s, `pre-push-hook` 3.6 s, with the other +fourteen gates under 2 s each. The slowest-gates view names real gates, as the plan's post-merge +checklist asks. + +### Failure-class breakdown + +| class | unit / event | count | cost (USD) | what it was | +| --- | --- | --- | --- | --- | +| `other` | T01 attempt 1 | 1 | 0.4108 | `roadmap-link-gate`: roadmap detail anchor missing (`no_gate_marker` on `coverage` rode along); fixed outside the unit | +| `preexisting_gate_failure` halt | gate 1, 2026-11-25T15:26:26 | 1 | $0.00 | probe attributed the red to the branch, not to T01; operator fixed and reopened | +| `tests` + `other` broad-run failure | gate 1 broad run 1, 15:37:40 | 1 | $0.00 | cache pollution in a new test, and a missing packaged docs copy; fixed outside the unit, second broad run clean | +| `judge_editing_terminal` halt | G1-CLOSE 2026-11-25T15:49:51 | 1 | $0.00 | expected (PLAN decision 2); acknowledged by the operator with a reason | + +## Consumer-visible contract changes + +Enumerated across T01–T04 for acknowledgment; each is a `changelog.d/` fragment tracing to +`FEAT-LOOP-2026-0250`, written with `python3 -m specfuse.loop.changelog_fragments add` +(`Added` ×3). `python3 -m specfuse.loop.changelog_fragments check` exits 0. + +- **Added — the `gate_result` driver event type**, registered in + `specfuse/loop/data/schemas/driver-event.schema.json`'s `event_types`. One per gate per run, + payload `attempt`, `gate`, `ok`, `skipped`, `duration_seconds`, `phase` (`attempt`, `baseline` or + `broad`); `attempt` is `null` outside an attempt. Consumers that validate events against the + registry now see a new type. +- **Added — `agent_seconds` and `verify_seconds` on `attempt_outcome` payloads.** `duration_seconds` + keeps its meaning (the attempt loop's total); an attempt that never reached verification records + `verify_seconds: 0`. A consumer reading old events finds neither key. +- **Added — the `specfuse stats` agent/verify section and slowest-gates section**, in text and in + `--json` as `time_split` and `gate_timings`. A corpus with no such events reads `not recorded`. + +No removals or renames. `broad_run_result` and `baseline_attribution` payloads are unchanged, and +existing `--json` keys are untouched. + +## What the loop did NOT verify + +1. **Real agent sessions.** The oracle stubs the agent session, so `agent_seconds` on a real + dispatch is unchecked: that the timer around `dispatch()` covers a real `claude -p` session, and + that `agent_seconds + verify_seconds` is close to `duration_seconds` on real attempts (the + remainder is unnamed driver overhead), has not been observed. All five attempts in this + feature ran on builds pinned before the change, so this repository holds no real attempt that + carries the split. `PLAN.md`'s Post-merge checklist, first item, carries it. +2. **The external corpus that motivated the feature.** The report of 184 attempts and about 17.5 + hours of attempt time was not re-read; `specfuse stats` was not run on it, and whether its + slowest-gates view names that corpus's real gates is unobserved. Backfilling old + `events.jsonl` files is out of scope, so such a corpus reads `not recorded` until it has run + attempts on a build that carries this feature. Post-merge checklist, second item. +3. **The `run()` wiring of attempt and baseline events.** The oracle drives + `execute_unit_attempt()`, `build_attempt_gate_events()` and `build_phase_gate_events()` directly. + That `run()` resets `wu.last_gate_results`, extends `wu_events` and flushes the events with + `attempt_outcome` is covered by no test and has no live example; the broad half of the wiring + was observed live (18 events at 15:49:51), the attempt and baseline halves were not. The + baseline `gate_result` events are emitted only on the retroactive attribution path, the only + path that still probes a baseline since FEAT-2026-0109/T01, and no real probe has run on the new + build. +4. **`broad_run_result` and `baseline_attribution` payloads unchanged.** T03's criterion 2 asks the + class to assert their keys. `TestBaselineAndBroadPhases` asserts the key set of the failing-gate + lists those events carry, not the two event payloads themselves; the diff shows neither payload + was edited. +5. **`duration_seconds` keeps its meaning.** Clause 5 has no dedicated assertion. It rests on + `test_split` bounding `agent_seconds + verify_seconds` by `duration_seconds`, on the unedited + existing suites above, and on the driver's clean broad run. +6. **Killed attempts.** Attempt-phase `gate_result` events share `attempt_outcome`'s buffer, so a + killed attempt loses both; PLAN decision 4 puts changing that out of scope and it is untested. +7. **The "fails on HEAD" halves of the red-first criteria** were claimed by each unit's own attempt and + not re-observed here; this close re-observed only the passing side. +8. **The `feature_oracle` as a timed gate on a real run.** Clause 1 includes it, and the test + drives it with a sleeping command; no real attempt on this repository has recorded it. + +## Retrospective + +**What went well.** Four units, three first-time passes, $1.70 against a $13.50 plan. The walking +skeleton held: T01 created the oracle with later clauses skipped by owner name, each owner removed +its own skip, and none survived to the close. Every clause has a positive control (a passing gate +beside a failing one and a skipped dependent; a fresh broad run beside a tree-unchanged skip; a new +corpus beside an old one). The feature measured itself: the one phase it could observe live, the +broad run, already names `tests` as 88.5% of gate time. + +**What didn't.** The feature could not report its own split, since the driver running it was pinned +before the code existed. The first broad run was red on four tests no unit selected, and T01's first +attempt spent 291 s on a roadmap anchor that the draft step should have written. + +**Lessons.** Two entries staged to `LEARNINGS-pending.md`: a docs edit needs its packaged copy in the +same unit, and a test that validates events must pin the validator's caches. + +**Open follow-ups (not blockers).** The two post-merge checklist items (one real feature checked +for `agent_seconds + verify_seconds` near `duration_seconds`; `specfuse stats` run on the corpus that +motivated this feature), filed at close as `specfuse:post-merge`. diff --git a/.specfuse/features/FEAT-LOOP-2026-0250-gate-timings/WU-01-attempt-gate-events.md b/.specfuse/features/FEAT-LOOP-2026-0250-gate-timings/WU-01-attempt-gate-events.md new file mode 100644 index 00000000..ccf30891 --- /dev/null +++ b/.specfuse/features/FEAT-LOOP-2026-0250-gate-timings/WU-01-attempt-gate-events.md @@ -0,0 +1,65 @@ +--- +id: FEAT-LOOP-2026-0250/T01 +type: implementation +status: done +attempts: 1 +oracle_env: macos_local +planned_cost_usd: 4.00 +produces: + - specfuse/loop/loop.py + - specfuse/loop/data/schemas/driver-event.schema.json + - tests/test_gate_timings.py +produces_driver_helper: + - _run_gate_set +model: sonnet +effort: medium +duration_seconds: 67.084 +cost_usd: 0.384186 +input_tokens: 28 +output_tokens: 8642 +gate_set: code +driver_version: 0.33.2 +started_at: 2026-11-25T15:27:11.734142+00:00 +--- + +# T01 — walking skeleton: attempt-phase `gate_result` events + +**Objective.** Make the gate's `feature_oracle` runnable and turn clause 1 and clause 5's +schema half green. This is the tracer bullet: stubs are allowed here only. + +**Context.** `FEAT-LOOP-2026-0250/T01`; decisions 4 and 6 in `PLAN.md`. + +- `_run_gate_set()` (`loop.py`) times each gate it actually spawns with `time.monotonic()` and + adds `duration_seconds` to that gate's result dict. A gate skipped for a failed dependency + gets `duration_seconds: 0` and `skipped: True`. Existing keys and the return contract are + otherwise unchanged. +- Per attempt, the driver appends one `gate_result` event per gate to `wu_events` (correlation + ID: the unit's), payload `{attempt, gate, ok, skipped, duration_seconds, phase: "attempt"}`, + flushed with `attempt_outcome`. How the per-gate results reach the attempt loop from + `verify()` is your call; existing `verify_fn` stubs must keep working unchanged. +- Add `gate_result` to `event_types` in `specfuse/loop/data/schemas/driver-event.schema.json` + and append a `FEAT-LOOP-2026-0250/T01` sentence to its `$comment`, in the existing style. + +Create `tests/test_gate_timings.py`, one class per Definition-of-done clause in `GATE-01.md`: +`TestAttemptGateEvents`, `TestAttemptSplit`, `TestBaselineAndBroadPhases`, `TestStatsReport`, +`TestNothingExistingChanges`. Implement clause 1 and the schema half of clause 5; skip the rest +naming T02, T03, T04. + +**Acceptance criteria.** + +1. `tests.test_gate_timings.TestAttemptGateEvents` fails on HEAD and passes after. It drives one + attempt with a stubbed agent session and three real gates (one passing with a known sleep, + one failing, one depending on the failing gate) plus a `feature_oracle`, and asserts one + `gate_result` per gate with the payload above and each spawned gate's duration at least + its sleep. +2. `TestNothingExistingChanges` asserts `gate_result` is in the schema's `event_types`. +3. `python3 -m unittest tests.test_dispatch_skeleton tests.test_loop_worklist_injection -b` + passes unchanged. + +**Do not touch.** `execute_unit_attempt()`'s agent/verify timers and `emit_attempt_outcome()` +(T02). `probe_baseline()` and `gate_broad_run_check` (T03). `events_stats.py` and docs (T04). + +**Verification.** The narrow tier for `implementation`, plus AC3's command. + +**Escalation triggers.** If per-gate results cannot reach the attempt loop without changing the +`verify_fn` call signature that existing stubs implement, block with the evidence. diff --git a/.specfuse/features/FEAT-LOOP-2026-0250-gate-timings/WU-02-agent-verify-split.md b/.specfuse/features/FEAT-LOOP-2026-0250-gate-timings/WU-02-agent-verify-split.md new file mode 100644 index 00000000..9b2c1694 --- /dev/null +++ b/.specfuse/features/FEAT-LOOP-2026-0250-gate-timings/WU-02-agent-verify-split.md @@ -0,0 +1,55 @@ +--- +id: FEAT-LOOP-2026-0250/T02 +type: implementation +status: done +attempts: 1 +oracle_env: macos_local +planned_cost_usd: 3.00 +produces: + - specfuse/loop/loop.py + - tests/test_gate_timings.py +produces_driver_helper: + - execute_unit_attempt + - emit_attempt_outcome +model: sonnet +effort: medium +gate_set: code +driver_version: 0.33.2 +started_at: 2026-11-25T15:28:19.062339+00:00 +duration_seconds: 79.802 +cost_usd: 0.335182 +input_tokens: 34 +output_tokens: 7052 +--- + +# T02 — `agent_seconds` and `verify_seconds` on `attempt_outcome` + +**Objective.** Split each attempt's time between the agent session and verification, so +clause 2 of `GATE-01.md` goes green. + +**Context.** `FEAT-LOOP-2026-0250/T02`; decision 5 in `PLAN.md`. + +- In `execute_unit_attempt()`, time the agent-session call (`dispatch_fn`) and the gate-set call + (`verify_fn`) with `time.monotonic()` and return both in the attempt's usage dict as + `agent_seconds` and `verify_seconds`. A path that returns before `verify_fn` runs (blocked, + zero-token, prep halted) records `verify_seconds: 0`. +- `emit_attempt_outcome()` adds both to the payload, defaulting to `0.0` when absent. + `duration_seconds` keeps its current meaning: the attempt loop's own total. + +**Acceptance criteria.** + +1. `tests.test_gate_timings.TestAttemptSplit` fails on HEAD and passes after. With a stubbed + agent session that sleeps a known time and a real gate that sleeps a known time, it asserts + `agent_seconds` and `verify_seconds` are each at least their sleep and their sum is at most + `duration_seconds`. +2. The same class asserts an attempt whose agent reports `blocked` records `verify_seconds: 0`. +3. `python3 -m unittest tests.test_dispatch_skeleton tests.test_files_changed_auto_repair -b` + passes unchanged. + +**Do not touch.** `_run_gate_set()` beyond reading what T01 added. `probe_baseline()` and +`gate_broad_run_check` (T03). `events_stats.py` and docs (T04). + +**Verification.** The narrow tier for `implementation`, plus AC3's command. + +**Escalation triggers.** If any `attempt_outcome` consumer (`gate_eval.py`, `events_stats.py`, +`learnings_suggest`) rejects or misreads the two new keys, block with the evidence. diff --git a/.specfuse/features/FEAT-LOOP-2026-0250-gate-timings/WU-03-baseline-and-broad.md b/.specfuse/features/FEAT-LOOP-2026-0250-gate-timings/WU-03-baseline-and-broad.md new file mode 100644 index 00000000..89eb147c --- /dev/null +++ b/.specfuse/features/FEAT-LOOP-2026-0250-gate-timings/WU-03-baseline-and-broad.md @@ -0,0 +1,56 @@ +--- +id: FEAT-LOOP-2026-0250/T03 +type: implementation +status: done +attempts: 1 +oracle_env: macos_local +planned_cost_usd: 3.50 +produces: + - specfuse/loop/loop.py + - tests/test_gate_timings.py +produces_driver_helper: + - probe_baseline + - gate_broad_run_check +model: sonnet +effort: medium +gate_set: code +driver_version: 0.33.2 +started_at: 2026-11-25T15:29:39.076668+00:00 +duration_seconds: 71.981 +cost_usd: 0.281655 +input_tokens: 20 +output_tokens: 6334 +--- + +# T03 — `gate_result` events for the baseline probe and the broad run + +**Objective.** Record per-gate results for the two runs outside an attempt, so clause 3 of +`GATE-01.md` goes green. + +**Context.** `FEAT-LOOP-2026-0250/T03`. Both runs already go through `_run_gate_set()`, which T01 +made time each gate. + +- **Broad run.** When `gate_broad_run_check` actually runs (the case that already emits + `broad_run_result`), also emit one `gate_result` per gate with `phase: "broad"`, correlation ID + the feature's, alongside `broad_run_result` in `_broad_events`. A tree-unchanged skip emits none. +- **Baseline probe.** When `probe_baseline()` runs fresh, emit one `gate_result` per gate with + `phase: "baseline"`, correlation ID the same one the `baseline_attribution` event on that path + uses, through the same event list. A skip on an unchanged tree emits none. +- `attempt` is `null` on both phases. + +**Acceptance criteria.** + +1. `tests.test_gate_timings.TestBaselineAndBroadPhases` fails on HEAD and passes after. It + asserts one `gate_result` per gate with the right `phase` for a fresh broad run and a fresh + baseline probe, and none for a broad run on an unchanged tree. +2. `broad_run_result` and `baseline_attribution` payloads are unchanged; the same class asserts + their keys. +3. The narrow tier passes with no existing broad-run or baseline test edited. + +**Do not touch.** `execute_unit_attempt()` and `emit_attempt_outcome()` (T02). `events_stats.py` +and docs (T04). + +**Verification.** The narrow tier for `implementation`. + +**Escalation triggers.** If the baseline probe has no event list to emit into on one of its call +paths, block naming that path rather than adding a second flush point. diff --git a/.specfuse/features/FEAT-LOOP-2026-0250-gate-timings/WU-04-stats-and-docs.md b/.specfuse/features/FEAT-LOOP-2026-0250-gate-timings/WU-04-stats-and-docs.md new file mode 100644 index 00000000..ba852f74 --- /dev/null +++ b/.specfuse/features/FEAT-LOOP-2026-0250-gate-timings/WU-04-stats-and-docs.md @@ -0,0 +1,55 @@ +--- +id: FEAT-LOOP-2026-0250/T04 +type: implementation +status: done +attempts: 1 +oracle_env: macos_local +planned_cost_usd: 3.00 +produces: + - specfuse/loop/events_stats.py + - docs/methodology.md + - tests/test_gate_timings.py +model: sonnet +effort: medium +gate_set: code +driver_version: 0.33.2 +started_at: 2026-11-25T15:30:51.265035+00:00 +duration_seconds: 54.107 +cost_usd: 0.292464 +input_tokens: 18 +output_tokens: 6820 +--- + +# T04 — `specfuse stats` reports the split and the slowest gates; docs + +**Objective.** Make the recorded data readable without code, so clause 4 of `GATE-01.md` goes +green and no skip remains in `tests/test_gate_timings.py`. + +**Context.** `FEAT-LOOP-2026-0250/T04`; decision 1 in `PLAN.md`. `events_stats.collect()` today +reads only `attempt_outcome`. + +- `collect()` also reads `gate_result` events, under the same dedupe key. +- Per feature: total `agent_seconds`, total `verify_seconds`, and the share of attempt time + each represents. Per gate name: runs, total, median and max `duration_seconds`, ordered by + total, split by `phase`. +- `render()` prints both sections; `--json` carries them. When no attempt has the split fields + or no `gate_result` exists, the section says `not recorded` — an old corpus must never read as + zero verification time. +- `docs/methodology.md`, section "Per-attempt outcome events": document `gate_result` (payload, + the three phases, buffering and the killed-attempt limit) and the two new `attempt_outcome` + fields. + +**Acceptance criteria.** + +1. `tests.test_gate_timings.TestStatsReport` fails on HEAD and passes after: a corpus with + `gate_result` events and split fields renders both sections with the right figures, and an + old corpus renders `not recorded` for both. +2. `python3 -m unittest tests.test_events_stats -b` passes unchanged. +3. `grep -c "unittest.skip" tests/test_gate_timings.py` prints `0`. + +**Do not touch.** The driver's event emission and the event schema (T01–T03). + +**Verification.** The narrow tier for `implementation`, plus AC2's and AC3's commands. + +**Escalation triggers.** If a T01–T03 event lacks a field this report needs, block naming the +field rather than inferring it. diff --git a/.specfuse/features/FEAT-LOOP-2026-0250-gate-timings/WU-90-gate-1-close.md b/.specfuse/features/FEAT-LOOP-2026-0250-gate-timings/WU-90-gate-1-close.md new file mode 100644 index 00000000..b39830b3 --- /dev/null +++ b/.specfuse/features/FEAT-LOOP-2026-0250-gate-timings/WU-90-gate-1-close.md @@ -0,0 +1,67 @@ +--- +id: FEAT-LOOP-2026-0250/G1-CLOSE +type: close +status: done +attempts: 1 +oracle_env: macos_local +planned_cost_usd: 5.00 +auto_close_disabled: true +judge_edit_acknowledged: + paths: + - produces_driver_helper + - specfuse/loop/data/schemas/driver-event.schema.json + - specfuse/loop/loop.py + reason: "All test are passing and we can continue" +re_arm_count: 1 +re_arm_history: + - + timestamp: 2026-11-25T17:03:20+00:00 + prior_status: blocked_human + prior_attempts: 0 + prior_cost_usd: 0.0 + prior_duration_seconds: 0.0 + reason: "All test are passing and we can continue" +model: sonnet +effort: high +cumulative_cost_usd: 0.0 +cumulative_duration_seconds: 0.0 +cumulative_input_tokens: 0 +cumulative_output_tokens: 0 +cumulative_attempts: 0 +cost_usd: 1.20819 +duration_seconds: 197.611 +input_tokens: 72 +output_tokens: 26080 +folded_through_re_arm: 1 +verdict: met +gate_set: plannext +driver_version: 0.33.2 +started_at: 2026-11-25T17:03:30.162262+00:00 +--- + +# G1-CLOSE — terminal close + +**Context.** The feature's only gate: every gate run records its result and duration, each +attempt splits agent time from verification time, and `specfuse stats` reports both. + +**Acceptance criteria.** + +1. `RETROSPECTIVE.md` records, per Definition-of-done clause in `GATE-01.md`, what was proven and + by which test, and that no `unittest.skip` survives in `tests/test_gate_timings.py`. +2. Each consumer-visible change in the §3 enumeration is written with + `python3 -m specfuse.loop.changelog_fragments add`, tracing to `FEAT-LOOP-2026-0250`. +3. A `## Cost analysis` reconciles every unit against `planned_cost_usd` and `events.jsonl`, and + reports this feature's own agent/verify split from the `specfuse stats` output on this + repository. +4. "What the loop did NOT verify" names, at minimum: real agent sessions (the oracle stubs the + session, so `agent_seconds` on real dispatches is unchecked), and the external corpus that + motivated the feature. +5. `specfuse lint --closing` exits 0 before this unit reports `complete`. + +**Do not touch.** Source files under `specfuse/` and `scripts/`. Permitted closing surfaces: +`RETROSPECTIVE.md`, `LEARNINGS-pending.md`, `changelog.d/`, `.specfuse/roadmap.md`. + +**Verification.** `specfuse lint --closing`, plus the gate set in `.specfuse/verification.yml`. + +**Escalation triggers.** A surviving skip, or a stats figure that renders `0` where it should +render `not recorded`: record `not_met` with a follow-up. diff --git a/.specfuse/features/FEAT-LOOP-2026-0250-gate-timings/events.jsonl b/.specfuse/features/FEAT-LOOP-2026-0250-gate-timings/events.jsonl new file mode 100644 index 00000000..f8c9053b --- /dev/null +++ b/.specfuse/features/FEAT-LOOP-2026-0250-gate-timings/events.jsonl @@ -0,0 +1,61 @@ +{"timestamp": "2026-11-25T15:15:29.558215+00:00", "correlation_id": "FEAT-LOOP-2026-0250", "event_type": "driver_build_pinned", "source": "driver", "source_version": "0.33.2", "payload": {"tree": "62a6668cfff88b97a42e0098860d7a421cff8568", "path": "/private/var/folders/zc/rgq11x850d78dx_kf1fd4vx80000gn/T/specfuse-pins/62a6668cfff88b97a42e0098860d7a421cff8568/specfuse/loop"}} +{"timestamp": "2026-11-25T15:15:30.163594+00:00", "correlation_id": "FEAT-LOOP-2026-0250/T01", "event_type": "task_started", "source": "driver", "source_version": "0.33.2", "payload": {"type": "implementation", "model": "sonnet", "re_arm_count": 0}} +{"timestamp": "2026-11-25T15:20:21.485009+00:00", "correlation_id": "FEAT-LOOP-2026-0250/T01", "event_type": "attempt_outcome", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "outcome": "failed", "duration_seconds": 291.222, "cost_usd": 0.41078410000000004, "input_tokens": 26, "output_tokens": 9911, "cache_read_input_tokens": 779701, "cache_creation_input_tokens": 58413, "model": "sonnet", "effort": "medium", "failure_class": "other", "failure_signature": "ERROR: roadmap.md:131: ref '#feat-loop-2026-0250' in roadmap\u2026und in roadmap.md or roadmap-archive.md", "failure_excerpt": "ok: no validation errors across 90 events.jsonl file(s), 2845 event(s) checked\nNO VERDICT FOUND: the gate command produced no recognisable pass/fail summary anywhere in its output \u2014 the lines above are the tail only, and may be unrelated to the \n...\nror(s), 1 warning(s)\n1 roadmap-link error(s).\nNO VERDICT FOUND: the gate command produced no recognisable pass/fail summary anywhere in its output \u2014 the lines above are the tail only, and may be unrelated to the failure. Run the command directly.", "files_touched": ["tests/test_gate_timings.py"], "agent_status": "complete", "agent_blocked_reason": null, "re_arm_count": 0, "failing_tests": []}} +{"timestamp": "2026-11-25T15:26:26.897002+00:00", "correlation_id": "FEAT-LOOP-2026-0250/T01", "event_type": "baseline_attribution", "source": "driver", "source_version": "0.33.2", "payload": {"gate": 1, "failing": [{"gate": "tests", "failure_class": "tests", "failure_signature": "(failures=2,"}, {"gate": "coverage", "failure_class": "other", "failure_signature": "no_gate_marker"}, {"gate": "roadmap-link-gate", "failure_class": "other", "failure_signature": "ERROR: roadmap.md:131: ref '#feat-loop-2026-0250' in roadmap\u2026und in roadmap.md or roadmap-archive.md"}], "attributed_to": "FEAT-LOOP-2026-0250/T01"}} +{"timestamp": "2026-11-25T15:26:26.920068+00:00", "correlation_id": "FEAT-LOOP-2026-0250", "event_type": "human_escalation", "source": "driver", "source_version": "0.33.2", "payload": {"reason": "preexisting_gate_failure", "gate": 1, "failing_gates": [{"gate": "tests", "failure_class": "tests", "failure_signature": "(failures=2,"}, {"gate": "coverage", "failure_class": "other", "failure_signature": "no_gate_marker"}, {"gate": "roadmap-link-gate", "failure_class": "other", "failure_signature": "ERROR: roadmap.md:131: ref '#feat-loop-2026-0250' in roadmap\u2026und in roadmap.md or roadmap-archive.md"}], "message": "Gate 1 is blocked: the automated checks it depends on failed on a probe the driver ran AFTER FEAT-LOOP-2026-0250/T01's attempt failed and its changes were reset.\n\nFailing check(s) found by that probe:\n - tests: tests (signature: (failures=2,)\n - coverage: other (signature: no_gate_marker)\n - roadmap-link-gate: other (signature: ERROR: roadmap.md:131: ref '#feat-loop-2026-0250' in roadmap\u2026und in roadmap.md or roadmap-archive.md)\n\nFEAT-LOOP-2026-0250/T01 WAS dispatched and its attempt failed. The driver then reset the tree and re-ran the checks to ask whether the failure predated that attempt; the result above is what that probe found.\n\nThe failing check(s)' TRACKED input files are unchanged vs the integration branch (the diff below is the feature's own plan/scaffold files, not code the failing check(s) read):\ngit diff main...HEAD --stat:\n.../FEAT-LOOP-2026-0250-gate-timings/GATE-01.md | 51 ++++++++++\n .../PLAN.baseline.json | 39 ++++++++\n .../FEAT-LOOP-2026-0250-gate-timings/PLAN.md | 111 +++++++++++++++++++++\n .../WU-01-attempt-gate-events.md | 58 +++++++++++\n .../WU-02-agent-verify-split.md | 48 +++++++++\n .../WU-03-baseline-and-broad.md | 49 +++++++++\n .../WU-04-stats-and-docs.md | 48 +++++++++\n .../WU-90-gate-1-close.md | 38 +++++++\n .../FEAT-LOOP-2026-0250-gate-timings/events.jsonl | 1 +\n .specfuse/roadmap.md | 11 ++\n 10 files changed, 454 insertions(+)\n\nWhat that comparison does NOT cover: untracked and gitignored paths. `git reset --hard` restores tracked files and leaves ignored ones in place, so a check that reads a build or output directory (`out/`, `target/`, generated-code trees, caches) can fail on state this feature's own failed attempt produced. The diff above cannot distinguish that from pre-existing breakage.\n\nWhat to do next:\n 1. Check for leftover untracked/ignored state from the reset attempt FIRST \u2014 it is the cheapest to rule out and the most likely cause. `git status --ignored --short` and `git clean -ndX` list what survived; if a listed path feeds a failing check, that is your answer.\n 2. Only if the tree is clean of those is this pre-existing debt \u2014 confirm by running the failing check(s) on the integration branch in a fresh checkout before assuming it.\n 3. If it was leftover state, remove it and re-run; FEAT-LOOP-2026-0250/T01 is back at its previous attempt count and will be retried.\n\nThere is no way to proceed past this halt in this version. A waiver that lets a feature continue against a red baseline is future work tracked as FEAT-2026-0052; it does not exist yet.", "attributed_to": "FEAT-LOOP-2026-0250/T01"}} +{"timestamp": "2026-11-25T15:26:26.935702+00:00", "correlation_id": "FEAT-LOOP-2026-0250", "event_type": "arm_predicate_evaluated", "source": "driver", "source_version": "0.33.2", "payload": {"gate": 1, "would_arm": true, "predicate_version": "v1", "classes": {"budget_projection": {"status": "clean", "reason": "projected spend $18.91 within 2.0x baseline planned total $18.50 (cap $37.00)"}, "judge_editing": {"status": "clean", "reason": "no drafted WU touches judge-path surfaces"}, "decision_class_paths": {"status": "clean", "reason": "no drafted WU touches a recognised dependency manifest (pyproject.toml, package.json, pom.xml, build.gradle, build.gradle.kts, Cargo.toml, go.mod, Gemfile, composer.json, requirements*.txt, *.csproj)"}, "retroactive_edits": {"status": "clean", "reason": "no passed-gate baseline WU altered or removed"}, "drift_caps": {"status": "clean", "reason": "added WUs and gates within drift caps"}, "missing_provenance": {"status": "clean", "reason": "no added WUs"}, "open_questions_human_only": {"status": "clean", "reason": "terminal gate: no drafted successor"}, "plan_next_lint": {"status": "clean", "reason": "plan-next lint: no findings"}}}} +{"timestamp": "2026-11-25T15:27:11.531211+00:00", "correlation_id": "FEAT-LOOP-2026-0250", "event_type": "driver_build_pinned", "source": "driver", "source_version": "0.33.2", "payload": {"tree": "6e41d224c1306b857666276d7ef42459505fadff", "path": "/private/var/folders/zc/rgq11x850d78dx_kf1fd4vx80000gn/T/specfuse-pins/6e41d224c1306b857666276d7ef42459505fadff/specfuse/loop"}} +{"timestamp": "2026-11-25T15:27:11.734339+00:00", "correlation_id": "FEAT-LOOP-2026-0250/T01", "event_type": "task_started", "source": "driver", "source_version": "0.33.2", "payload": {"type": "implementation", "model": "sonnet", "re_arm_count": 0}} +{"timestamp": "2026-11-25T15:28:19.001527+00:00", "correlation_id": "FEAT-LOOP-2026-0250/T01", "event_type": "attempt_outcome", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "outcome": "passed", "duration_seconds": 67.084, "cost_usd": 0.3841855, "input_tokens": 28, "output_tokens": 8642, "cache_read_input_tokens": 817895, "cache_creation_input_tokens": 53980, "model": "sonnet", "effort": "medium", "failure_class": null, "failure_signature": null, "failure_excerpt": null, "files_touched": [".specfuse/features/FEAT-LOOP-2026-0250-gate-timings/WU-01-attempt-gate-events.md", "specfuse/loop/data/schemas/driver-event.schema.json", "specfuse/loop/loop.py", "tests/test_gate_timings.py"], "agent_status": "complete", "agent_blocked_reason": null, "re_arm_count": 0, "failing_tests": []}} +{"timestamp": "2026-11-25T15:28:19.001690+00:00", "correlation_id": "FEAT-LOOP-2026-0250/T01", "event_type": "task_completed", "source": "driver", "source_version": "0.33.2", "payload": {"attempts": 1, "attempts_usage": [{"attempt": 1, "duration_seconds": 67.084, "cost_usd": 0.3841855, "input_tokens": 28, "output_tokens": 8642, "cache_read_input_tokens": 817895, "cache_creation_input_tokens": 53980}], "type": "implementation", "re_arm_count": 0, "cost_usd": 0.384186, "cumulative_cost_usd": 0.384186, "attempts_lifetime": 1, "planned_cost_usd": 4.0}} +{"timestamp": "2026-11-25T15:28:19.008248+00:00", "correlation_id": "FEAT-LOOP-2026-0250", "event_type": "driver_staleness_detected", "source": "driver", "source_version": "0.33.2", "payload": {"gate": 1, "wu_id": "FEAT-LOOP-2026-0250/T01", "driver_paths": ["specfuse/loop/loop.py"], "halted": false, "reason": "driver_restart_required", "pinned_tree": "6e41d224c1306b857666276d7ef42459505fadff", "next_pin_tree": "0dc7a43398ae99b7b4a95cad6ff9546686ec11f9"}} +{"timestamp": "2026-11-25T15:28:19.062521+00:00", "correlation_id": "FEAT-LOOP-2026-0250/T02", "event_type": "task_started", "source": "driver", "source_version": "0.33.2", "payload": {"type": "implementation", "model": "sonnet", "re_arm_count": 0}} +{"timestamp": "2026-11-25T15:29:39.009550+00:00", "correlation_id": "FEAT-LOOP-2026-0250/T02", "event_type": "attempt_outcome", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "outcome": "passed", "duration_seconds": 79.802, "cost_usd": 0.33518190000000003, "input_tokens": 34, "output_tokens": 7052, "cache_read_input_tokens": 859339, "cache_creation_input_tokens": 44665, "model": "sonnet", "effort": "medium", "failure_class": null, "failure_signature": null, "failure_excerpt": null, "files_touched": [".specfuse/features/FEAT-LOOP-2026-0250-gate-timings/WU-02-agent-verify-split.md", ".specfuse/features/FEAT-LOOP-2026-0250-gate-timings/events.jsonl", "specfuse/loop/loop.py", "tests/test_gate_timings.py"], "agent_status": "complete", "agent_blocked_reason": null, "re_arm_count": 0, "failing_tests": []}} +{"timestamp": "2026-11-25T15:29:39.009788+00:00", "correlation_id": "FEAT-LOOP-2026-0250/T02", "event_type": "task_completed", "source": "driver", "source_version": "0.33.2", "payload": {"attempts": 1, "attempts_usage": [{"attempt": 1, "duration_seconds": 79.802, "cost_usd": 0.33518190000000003, "input_tokens": 34, "output_tokens": 7052, "cache_read_input_tokens": 859339, "cache_creation_input_tokens": 44665}], "type": "implementation", "re_arm_count": 0, "cost_usd": 0.335182, "cumulative_cost_usd": 0.335182, "attempts_lifetime": 1, "planned_cost_usd": 3.0}} +{"timestamp": "2026-11-25T15:29:39.018352+00:00", "correlation_id": "FEAT-LOOP-2026-0250", "event_type": "driver_staleness_detected", "source": "driver", "source_version": "0.33.2", "payload": {"gate": 1, "wu_id": "FEAT-LOOP-2026-0250/T02", "driver_paths": ["specfuse/loop/loop.py"], "halted": false, "reason": "driver_restart_required", "pinned_tree": "6e41d224c1306b857666276d7ef42459505fadff", "next_pin_tree": "e686809a71813ffd2e12672e848ca7dcbcdf90f1"}} +{"timestamp": "2026-11-25T15:29:39.076904+00:00", "correlation_id": "FEAT-LOOP-2026-0250/T03", "event_type": "task_started", "source": "driver", "source_version": "0.33.2", "payload": {"type": "implementation", "model": "sonnet", "re_arm_count": 0}} +{"timestamp": "2026-11-25T15:30:51.196292+00:00", "correlation_id": "FEAT-LOOP-2026-0250/T03", "event_type": "attempt_outcome", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "outcome": "passed", "duration_seconds": 71.981, "cost_usd": 0.2816549, "input_tokens": 20, "output_tokens": 6334, "cache_read_input_tokens": 481109, "cache_creation_input_tokens": 42541, "model": "sonnet", "effort": "medium", "failure_class": null, "failure_signature": null, "failure_excerpt": null, "files_touched": [".specfuse/features/FEAT-LOOP-2026-0250-gate-timings/WU-03-baseline-and-broad.md", ".specfuse/features/FEAT-LOOP-2026-0250-gate-timings/events.jsonl", "specfuse/loop/loop.py", "tests/test_gate_timings.py"], "agent_status": "complete", "agent_blocked_reason": null, "re_arm_count": 0, "failing_tests": []}} +{"timestamp": "2026-11-25T15:30:51.196542+00:00", "correlation_id": "FEAT-LOOP-2026-0250/T03", "event_type": "task_completed", "source": "driver", "source_version": "0.33.2", "payload": {"attempts": 1, "attempts_usage": [{"attempt": 1, "duration_seconds": 71.981, "cost_usd": 0.2816549, "input_tokens": 20, "output_tokens": 6334, "cache_read_input_tokens": 481109, "cache_creation_input_tokens": 42541}], "type": "implementation", "re_arm_count": 0, "cost_usd": 0.281655, "cumulative_cost_usd": 0.281655, "attempts_lifetime": 1, "planned_cost_usd": 3.5}} +{"timestamp": "2026-11-25T15:30:51.205278+00:00", "correlation_id": "FEAT-LOOP-2026-0250", "event_type": "driver_staleness_detected", "source": "driver", "source_version": "0.33.2", "payload": {"gate": 1, "wu_id": "FEAT-LOOP-2026-0250/T03", "driver_paths": ["specfuse/loop/loop.py"], "halted": false, "reason": "driver_restart_required", "pinned_tree": "6e41d224c1306b857666276d7ef42459505fadff", "next_pin_tree": "b862619eb0a716df7e0ac8eb87af176c9cc1ae4b"}} +{"timestamp": "2026-11-25T15:30:51.265196+00:00", "correlation_id": "FEAT-LOOP-2026-0250/T04", "event_type": "task_started", "source": "driver", "source_version": "0.33.2", "payload": {"type": "implementation", "model": "sonnet", "re_arm_count": 0}} +{"timestamp": "2026-11-25T15:31:45.513560+00:00", "correlation_id": "FEAT-LOOP-2026-0250/T04", "event_type": "attempt_outcome", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "outcome": "passed", "duration_seconds": 54.107, "cost_usd": 0.29246350000000004, "input_tokens": 18, "output_tokens": 6820, "cache_read_input_tokens": 437955, "cache_creation_input_tokens": 45108, "model": "sonnet", "effort": "medium", "failure_class": null, "failure_signature": null, "failure_excerpt": null, "files_touched": [".specfuse/features/FEAT-LOOP-2026-0250-gate-timings/WU-04-stats-and-docs.md", ".specfuse/features/FEAT-LOOP-2026-0250-gate-timings/events.jsonl", "docs/methodology.md", "specfuse/loop/events_stats.py", "tests/test_gate_timings.py"], "agent_status": "complete", "agent_blocked_reason": null, "re_arm_count": 0, "failing_tests": []}} +{"timestamp": "2026-11-25T15:31:45.513749+00:00", "correlation_id": "FEAT-LOOP-2026-0250/T04", "event_type": "task_completed", "source": "driver", "source_version": "0.33.2", "payload": {"attempts": 1, "attempts_usage": [{"attempt": 1, "duration_seconds": 54.107, "cost_usd": 0.29246350000000004, "input_tokens": 18, "output_tokens": 6820, "cache_read_input_tokens": 437955, "cache_creation_input_tokens": 45108}], "type": "implementation", "re_arm_count": 0, "cost_usd": 0.292464, "cumulative_cost_usd": 0.292464, "attempts_lifetime": 1, "planned_cost_usd": 3.0}} +{"timestamp": "2026-11-25T15:31:45.522019+00:00", "correlation_id": "FEAT-LOOP-2026-0250", "event_type": "driver_staleness_detected", "source": "driver", "source_version": "0.33.2", "payload": {"gate": 1, "wu_id": "FEAT-LOOP-2026-0250/T04", "driver_paths": ["specfuse/loop/events_stats.py"], "halted": false, "reason": "driver_restart_required", "pinned_tree": "6e41d224c1306b857666276d7ef42459505fadff", "next_pin_tree": "589a2b5ba6541adcb1e151d27070bc0ff2f3d3d8"}} +{"timestamp": "2026-11-25T15:37:40.648418+00:00", "correlation_id": "FEAT-LOOP-2026-0250", "event_type": "broad_run_result", "source": "driver", "source_version": "0.33.2", "payload": {"gate": 1, "tree": "07bbf72d1e7af3c1a03af605f40e5563dc3a18db:0ec7c6da6e74f0b56753f09657b654a6d289b91b:12064a6191eeb830a9826d911a8543fbaba3da75:27968248a450a842ccd187b7dce0fb0ded934866:287efde8f90320baffac08f5f3287b9456a65cb9:2e29b2f7e073a0cbe290f01d3b397e1cdd10c81c:302816f6805b548990c2e47c2264d6c68679b21d:42796ea0e0a6c03811b0e4bc9dbd3b5ee62dd2e4:4acc6dfc5e8cece358c167d876515eba4a39a500:834d9d9c16094a386cd9b5a6f9ced9a3a9b4e7fb:a1eaf25ebeaf902ef2c671ef08370e9c6c0910ae:ae39d552df928f10c8c11cb2a541575d68665933:bbd1aea514612d76722a18c7aece7c767cf1a076:c23b62e87f1ae3890c6f9e3d8c7ca7ec9225ed81:caffe2d63ceacde448842a91bc7a12c206a67523:d74b7d113b844e84f0009098f576fd28477f072d:e37cb958241ac428d3a6949eacba20a52b4e9c7a:e3b0de29b81a6c8e0abeacb3898519b98014b9ef:fa2f4f88657587b6e3b560977858810846b1d366", "ok": false, "failing": [{"gate": "tests", "failure_class": "tests", "failure_signature": "(failures=4,"}, {"gate": "coverage", "failure_class": "other", "failure_signature": "no_gate_marker"}]}} +{"timestamp": "2026-11-25T15:37:40.648899+00:00", "correlation_id": "FEAT-LOOP-2026-0250", "event_type": "human_escalation", "source": "driver", "source_version": "0.33.2", "payload": {"reason": "broad_run_gate_failure", "gate": 1, "failing_gates": [{"gate": "tests", "failure_class": "tests", "failure_signature": "(failures=4,"}, {"gate": "coverage", "failure_class": "other", "failure_signature": "no_gate_marker"}], "message": "Gate 1 is blocked: the full `code` gate set failed on the once-per-gate broad run this gate's closing sequence requires before it may dispatch (FEAT-2026-0109/T06).\n\nTree measured: 07bbf72d1e7af3c1a03af605f40e5563dc3a18db:0ec7c6da6e74f0b56753f09657b654a6d289b91b:12064a6191eeb830a9826d911a8543fbaba3da75:27968248a450a842ccd187b7dce0fb0ded934866:287efde8f90320baffac08f5f3287b9456a65cb9:2e29b2f7e073a0cbe290f01d3b397e1cdd10c81c:302816f6805b548990c2e47c2264d6c68679b21d:42796ea0e0a6c03811b0e4bc9dbd3b5ee62dd2e4:4acc6dfc5e8cece358c167d876515eba4a39a500:834d9d9c16094a386cd9b5a6f9ced9a3a9b4e7fb:a1eaf25ebeaf902ef2c671ef08370e9c6c0910ae:ae39d552df928f10c8c11cb2a541575d68665933:bbd1aea514612d76722a18c7aece7c767cf1a076:c23b62e87f1ae3890c6f9e3d8c7ca7ec9225ed81:caffe2d63ceacde448842a91bc7a12c206a67523:d74b7d113b844e84f0009098f576fd28477f072d:e37cb958241ac428d3a6949eacba20a52b4e9c7a:e3b0de29b81a6c8e0abeacb3898519b98014b9ef:fa2f4f88657587b6e3b560977858810846b1d366\n\nFailing check(s):\n - tests: tests (signature: (failures=4,)\n - coverage: other (signature: no_gate_marker)\n\nNo work unit's attempt count was charged for this: every unit in this gate already passed its own per-attempt verification. The per-attempt narrow tier (FEAT-2026-0109/T04, T05) scopes checks to changed files as a speed optimization \u2014 this full-set run is the safety net that catches what that narrowing missed.\n\nWhat to do next:\n 1. Reproduce the failing check(s) above locally and fix them on this branch.\n 2. Re-run the driver \u2014 the closing sequence dispatches once the broad run is clean at the current tree.", "tree": "07bbf72d1e7af3c1a03af605f40e5563dc3a18db:0ec7c6da6e74f0b56753f09657b654a6d289b91b:12064a6191eeb830a9826d911a8543fbaba3da75:27968248a450a842ccd187b7dce0fb0ded934866:287efde8f90320baffac08f5f3287b9456a65cb9:2e29b2f7e073a0cbe290f01d3b397e1cdd10c81c:302816f6805b548990c2e47c2264d6c68679b21d:42796ea0e0a6c03811b0e4bc9dbd3b5ee62dd2e4:4acc6dfc5e8cece358c167d876515eba4a39a500:834d9d9c16094a386cd9b5a6f9ced9a3a9b4e7fb:a1eaf25ebeaf902ef2c671ef08370e9c6c0910ae:ae39d552df928f10c8c11cb2a541575d68665933:bbd1aea514612d76722a18c7aece7c767cf1a076:c23b62e87f1ae3890c6f9e3d8c7ca7ec9225ed81:caffe2d63ceacde448842a91bc7a12c206a67523:d74b7d113b844e84f0009098f576fd28477f072d:e37cb958241ac428d3a6949eacba20a52b4e9c7a:e3b0de29b81a6c8e0abeacb3898519b98014b9ef:fa2f4f88657587b6e3b560977858810846b1d366"}} +{"timestamp": "2026-11-25T15:37:40.666263+00:00", "correlation_id": "FEAT-LOOP-2026-0250", "event_type": "arm_predicate_evaluated", "source": "driver", "source_version": "0.33.2", "payload": {"gate": 1, "would_arm": true, "predicate_version": "v1", "classes": {"budget_projection": {"status": "clean", "reason": "projected spend $6.70 within 2.0x baseline planned total $18.50 (cap $37.00)"}, "judge_editing": {"status": "clean", "reason": "no drafted WU touches judge-path surfaces"}, "decision_class_paths": {"status": "clean", "reason": "no drafted WU touches a recognised dependency manifest (pyproject.toml, package.json, pom.xml, build.gradle, build.gradle.kts, Cargo.toml, go.mod, Gemfile, composer.json, requirements*.txt, *.csproj)"}, "retroactive_edits": {"status": "clean", "reason": "no passed-gate baseline WU altered or removed"}, "drift_caps": {"status": "clean", "reason": "added WUs and gates within drift caps"}, "missing_provenance": {"status": "clean", "reason": "no added WUs"}, "open_questions_human_only": {"status": "clean", "reason": "terminal gate: no drafted successor"}, "plan_next_lint": {"status": "clean", "reason": "plan-next lint: no findings"}}}} +{"timestamp": "2026-11-25T15:44:00.299154+00:00", "correlation_id": "FEAT-LOOP-2026-0250", "event_type": "driver_build_pinned", "source": "driver", "source_version": "0.33.2", "payload": {"tree": "4b3e56b59f640804d90a631de5097e52630c94be", "path": "/private/var/folders/zc/rgq11x850d78dx_kf1fd4vx80000gn/T/specfuse-pins/4b3e56b59f640804d90a631de5097e52630c94be/specfuse/loop"}} +{"timestamp": "2026-11-25T15:49:51.833711+00:00", "correlation_id": "FEAT-LOOP-2026-0250", "event_type": "broad_run_result", "source": "driver", "source_version": "0.33.2", "payload": {"gate": 1, "tree": "07bbf72d1e7af3c1a03af605f40e5563dc3a18db:0ec7c6da6e74f0b56753f09657b654a6d289b91b:12064a6191eeb830a9826d911a8543fbaba3da75:27968248a450a842ccd187b7dce0fb0ded934866:287efde8f90320baffac08f5f3287b9456a65cb9:2e29b2f7e073a0cbe290f01d3b397e1cdd10c81c:302816f6805b548990c2e47c2264d6c68679b21d:38e1639a0c46c0cd3e0a1bcee16359e18cf4c70f:42796ea0e0a6c03811b0e4bc9dbd3b5ee62dd2e4:4acc6dfc5e8cece358c167d876515eba4a39a500:83478ee1d28da445abebbea95e402a2501fa1343:834d9d9c16094a386cd9b5a6f9ced9a3a9b4e7fb:ae39d552df928f10c8c11cb2a541575d68665933:bbd1aea514612d76722a18c7aece7c767cf1a076:c23b62e87f1ae3890c6f9e3d8c7ca7ec9225ed81:caffe2d63ceacde448842a91bc7a12c206a67523:d74b7d113b844e84f0009098f576fd28477f072d:e3b0de29b81a6c8e0abeacb3898519b98014b9ef:fa2f4f88657587b6e3b560977858810846b1d366", "ok": true, "failing": []}} +{"timestamp": "2026-11-25T15:49:51.833749+00:00", "correlation_id": "FEAT-LOOP-2026-0250", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "tests", "ok": true, "skipped": false, "duration_seconds": 310.984, "phase": "broad"}} +{"timestamp": "2026-11-25T15:49:51.833763+00:00", "correlation_id": "FEAT-LOOP-2026-0250", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "lint", "ok": true, "skipped": false, "duration_seconds": 0.063, "phase": "broad"}} +{"timestamp": "2026-11-25T15:49:51.833765+00:00", "correlation_id": "FEAT-LOOP-2026-0250", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "security", "ok": true, "skipped": false, "duration_seconds": 1.628, "phase": "broad"}} +{"timestamp": "2026-11-25T15:49:51.833767+00:00", "correlation_id": "FEAT-LOOP-2026-0250", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "coverage", "ok": true, "skipped": false, "duration_seconds": 1.247, "phase": "broad"}} +{"timestamp": "2026-11-25T15:49:51.833770+00:00", "correlation_id": "FEAT-LOOP-2026-0250", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "leak-scan", "ok": true, "skipped": false, "duration_seconds": 17.945, "phase": "broad"}} +{"timestamp": "2026-11-25T15:49:51.833771+00:00", "correlation_id": "FEAT-LOOP-2026-0250", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "changelog-fragments", "ok": true, "skipped": false, "duration_seconds": 0.057, "phase": "broad"}} +{"timestamp": "2026-11-25T15:49:51.833773+00:00", "correlation_id": "FEAT-LOOP-2026-0250", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "agent-policy-example-lint", "ok": true, "skipped": false, "duration_seconds": 0.115, "phase": "broad"}} +{"timestamp": "2026-11-25T15:49:51.833776+00:00", "correlation_id": "FEAT-LOOP-2026-0250", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "event-type-gate", "ok": true, "skipped": false, "duration_seconds": 0.155, "phase": "broad"}} +{"timestamp": "2026-11-25T15:49:51.833777+00:00", "correlation_id": "FEAT-LOOP-2026-0250", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "roadmap-link-gate", "ok": true, "skipped": false, "duration_seconds": 0.054, "phase": "broad"}} +{"timestamp": "2026-11-25T15:49:51.833779+00:00", "correlation_id": "FEAT-LOOP-2026-0250", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "arm-sweep-gate", "ok": true, "skipped": false, "duration_seconds": 0.404, "phase": "broad"}} +{"timestamp": "2026-11-25T15:49:51.833782+00:00", "correlation_id": "FEAT-LOOP-2026-0250", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "monitoring-example-lint", "ok": true, "skipped": false, "duration_seconds": 0.05, "phase": "broad"}} +{"timestamp": "2026-11-25T15:49:51.833783+00:00", "correlation_id": "FEAT-LOOP-2026-0250", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "leak-scan-hook", "ok": true, "skipped": false, "duration_seconds": 0.856, "phase": "broad"}} +{"timestamp": "2026-11-25T15:49:51.833784+00:00", "correlation_id": "FEAT-LOOP-2026-0250", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "pre-push-hook", "ok": true, "skipped": false, "duration_seconds": 3.557, "phase": "broad"}} +{"timestamp": "2026-11-25T15:49:51.833786+00:00", "correlation_id": "FEAT-LOOP-2026-0250", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "sync-scaffold-bats", "ok": true, "skipped": false, "duration_seconds": 10.766, "phase": "broad"}} +{"timestamp": "2026-11-25T15:49:51.833789+00:00", "correlation_id": "FEAT-LOOP-2026-0250", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "sync-scaffold-symlinks-bats", "ok": true, "skipped": false, "duration_seconds": 1.773, "phase": "broad"}} +{"timestamp": "2026-11-25T15:49:51.833790+00:00", "correlation_id": "FEAT-LOOP-2026-0250", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "init-sh-shim-bats", "ok": true, "skipped": false, "duration_seconds": 0.896, "phase": "broad"}} +{"timestamp": "2026-11-25T15:49:51.833795+00:00", "correlation_id": "FEAT-LOOP-2026-0250", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "init-skills-bats", "ok": true, "skipped": false, "duration_seconds": 0.143, "phase": "broad"}} +{"timestamp": "2026-11-25T15:49:51.833801+00:00", "correlation_id": "FEAT-LOOP-2026-0250", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "hookspath-conflict-bats", "ok": true, "skipped": false, "duration_seconds": 0.624, "phase": "broad"}} +{"timestamp": "2026-11-25T15:49:51.940176+00:00", "correlation_id": "FEAT-LOOP-2026-0250", "event_type": "terminal_judge_editing_evaluated", "source": "driver", "source_version": "0.33.2", "payload": {"gate": 1, "status": "fired", "reason": "FEAT-LOOP-2026-0250/T01 produces specfuse/loop/loop.py; FEAT-LOOP-2026-0250/T01 produces specfuse/loop/data/schemas/driver-event.schema.json; FEAT-LOOP-2026-0250/T01 declares produces_driver_helper ['_run_gate_set']; FEAT-LOOP-2026-0250/T02 produces specfuse/loop/loop.py; FEAT-LOOP-2026-0250/T02 declares produces_driver_helper ['execute_unit_attempt', 'emit_attempt_outcome']; FEAT-LOOP-2026-0250/T03 produces specfuse/loop/loop.py; FEAT-LOOP-2026-0250/T03 declares produces_driver_helper ['probe_baseline', 'gate_broad_run_check']"}} +{"timestamp": "2026-11-25T15:49:51.942918+00:00", "correlation_id": "FEAT-LOOP-2026-0250/G1-CLOSE", "event_type": "human_escalation", "source": "driver", "source_version": "0.33.2", "payload": {"reason": "judge_editing_terminal", "gate": 1, "hits": ["FEAT-LOOP-2026-0250/T01 produces specfuse/loop/loop.py", "FEAT-LOOP-2026-0250/T01 produces specfuse/loop/data/schemas/driver-event.schema.json", "FEAT-LOOP-2026-0250/T01 declares produces_driver_helper ['_run_gate_set']", "FEAT-LOOP-2026-0250/T02 produces specfuse/loop/loop.py", "FEAT-LOOP-2026-0250/T02 declares produces_driver_helper ['execute_unit_attempt', 'emit_attempt_outcome']", "FEAT-LOOP-2026-0250/T03 produces specfuse/loop/loop.py", "FEAT-LOOP-2026-0250/T03 declares produces_driver_helper ['probe_baseline', 'gate_broad_run_check']"], "message": "ESCALATED \u2014 FEAT-LOOP-2026-0250/G1-CLOSE (G1-CLOSE \u2014 terminal close)\n\n## What has been done so far\nGate 1 is the last gate and its work is finished. Work units done: FEAT-LOOP-2026-0250/T01, FEAT-LOOP-2026-0250/T02, FEAT-LOOP-2026-0250/T03, FEAT-LOOP-2026-0250/T04. Nothing has been closed, flipped or archived yet.\n\n## What this issue is about\nOne or more finished units changed files that the judge relies on to grade this feature. Unit and path: FEAT-LOOP-2026-0250/T01 produces specfuse/loop/loop.py; FEAT-LOOP-2026-0250/T01 produces specfuse/loop/data/schemas/driver-event.schema.json; FEAT-LOOP-2026-0250/T01 declares produces_driver_helper ['_run_gate_set']; FEAT-LOOP-2026-0250/T02 produces specfuse/loop/loop.py; FEAT-LOOP-2026-0250/T02 declares produces_driver_helper ['execute_unit_attempt', 'emit_attempt_outcome']; FEAT-LOOP-2026-0250/T03 produces specfuse/loop/loop.py; FEAT-LOOP-2026-0250/T03 declares produces_driver_helper ['probe_baseline', 'gate_broad_run_check'].\n\n## What decision is needed, and why\nSomeone must decide whether those judge-surface edits are sound before the feature closes, because the close verdict would otherwise be written by the same model that made the edits.\n\n## Why it did not, or could not, close automatically\nThe safety catch fired as designed, nothing broke: the gate's own units change the code or config that grades it, so a model-authored verdict over those edits cannot be trusted to close the feature unreviewed. It stops the close however the feature was started and whatever its autonomy level.\n\n## Options, each with pros and cons\n1. **Acknowledge the edits** \u2014 review the paths above, then write `judge_edit_acknowledged` (the paths and your own reason) in the frontmatter of FEAT-LOOP-2026-0250/G1-CLOSE, then run `/unblock-wu`. Pros: the close proceeds and your reason is on the record. Cons: you must read the edits first; the acknowledgement covers only the paths it names, so a path added later stops the close again. A `produces_driver_helper` hit is covered by that literal entry, not by a file path.\n\nPaste into the frontmatter of the close unit, with your own reason:\n\n```yaml\njudge_edit_acknowledged:\n paths:\n - produces_driver_helper\n - specfuse/loop/data/schemas/driver-event.schema.json\n - specfuse/loop/loop.py\n reason: \"\"\n```\n2. **Reject the edits** \u2014 fix or revert them in the producing units. Pros: the judge stays independent. Cons: reopens finished work.\n\n## A recommendation\nOption 1 once you have read the edits and they are sound; option 2 if any of them weakens the check that grades this feature.\n\nReply with the number of your choice, or prose if none fit:\n1. Acknowledge the edits\n2. Reject the edits\n\nResume after deciding:\n python3 -m specfuse.loop.loop --feature FEAT-LOOP-2026-0250\n\n"}} +{"timestamp": "2026-11-25T17:03:29.925314+00:00", "correlation_id": "FEAT-LOOP-2026-0250", "event_type": "driver_build_pinned", "source": "driver", "source_version": "0.33.2", "payload": {"tree": "9159c26ba1ab83ebce323484f215b01132ef7658", "path": "/private/var/folders/zc/rgq11x850d78dx_kf1fd4vx80000gn/T/specfuse-pins/9159c26ba1ab83ebce323484f215b01132ef7658/specfuse/loop"}} +{"timestamp": "2026-11-25T17:03:30.055406+00:00", "correlation_id": "FEAT-LOOP-2026-0250", "event_type": "terminal_judge_editing_evaluated", "source": "driver", "source_version": "0.33.2", "payload": {"gate": 1, "status": "clean", "reason": "acknowledged by operator: produces_driver_helper, specfuse/loop/data/schemas/driver-event.schema.json, specfuse/loop/loop.py"}} +{"timestamp": "2026-11-25T17:03:30.057154+00:00", "correlation_id": "FEAT-LOOP-2026-0250", "event_type": "terminal_judge_editing_acknowledged", "source": "driver", "source_version": "0.33.2", "payload": {"gate": 1, "close_unit": "FEAT-LOOP-2026-0250/G1-CLOSE", "paths": ["produces_driver_helper", "specfuse/loop/data/schemas/driver-event.schema.json", "specfuse/loop/loop.py"], "reason": "All test are passing and we can continue"}} +{"timestamp": "2026-11-25T17:03:30.162482+00:00", "correlation_id": "FEAT-LOOP-2026-0250/G1-CLOSE", "event_type": "task_started", "source": "driver", "source_version": "0.33.2", "payload": {"type": "close", "model": "sonnet", "re_arm_count": 1}} +{"timestamp": "2026-11-25T17:03:30.162487+00:00", "correlation_id": "FEAT-LOOP-2026-0250/G1-CLOSE", "event_type": "re_arm_dispatched", "source": "driver", "source_version": "0.33.2", "payload": {"re_arm_count": 1, "reason": "All test are passing and we can continue"}} +{"timestamp": "2026-11-25T17:06:47.774341+00:00", "correlation_id": "FEAT-LOOP-2026-0250/G1-CLOSE", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "gate": "plan-lint", "ok": true, "skipped": false, "duration_seconds": 0.108, "phase": "attempt"}} +{"timestamp": "2026-11-25T17:06:47.774362+00:00", "correlation_id": "FEAT-LOOP-2026-0250/G1-CLOSE", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "gate": "feature_oracle", "ok": true, "skipped": false, "duration_seconds": 2.422, "phase": "attempt"}} +{"timestamp": "2026-11-25T17:07:02.326258+00:00", "correlation_id": "FEAT-LOOP-2026-0250/G1-CLOSE", "event_type": "judged", "source": "driver", "source_version": "0.33.2", "payload": {"gate": 1, "close_verdict": "met", "close_model": "sonnet", "judge_verdict": "met", "verdict": "met", "lowered": false, "disagreed": false, "findings": 0, "reason": null, "diff_base": "21191ae86fa93b0ae51ef939b522bd15b130ba6c", "diff_base_source": "GATE-01.md baseline.entry_sha", "usage": {"cost_usd": 0.1718868, "input_tokens": 4, "output_tokens": 624, "cache_read_input_tokens": 62868, "cache_creation_input_tokens": 39838}, "judge_cost_usd": 0.171887}} +{"timestamp": "2026-11-25T17:07:02.326530+00:00", "correlation_id": "FEAT-LOOP-2026-0250/G1-CLOSE", "event_type": "attempt_outcome", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "outcome": "passed", "duration_seconds": 197.611, "agent_seconds": 194.99197466706391, "verify_seconds": 2.53918529197108, "cost_usd": 1.2081899, "input_tokens": 72, "output_tokens": 26080, "cache_read_input_tokens": 3270459, "cache_creation_input_tokens": 155050, "model": "sonnet", "effort": "high", "failure_class": null, "failure_signature": null, "failure_excerpt": null, "files_touched": [".specfuse/features/FEAT-LOOP-2026-0250-gate-timings/GATE-01-CRITERIA.md", ".specfuse/features/FEAT-LOOP-2026-0250-gate-timings/LEARNINGS-pending.md", ".specfuse/features/FEAT-LOOP-2026-0250-gate-timings/RETROSPECTIVE.md", ".specfuse/features/FEAT-LOOP-2026-0250-gate-timings/WU-90-gate-1-close.md", ".specfuse/features/FEAT-LOOP-2026-0250-gate-timings/events.jsonl", "changelog.d/FEAT-LOOP-2026-0250-attempt-outcome-payloads-gain-agent-seco.md", "changelog.d/FEAT-LOOP-2026-0250-new-driver-event-type-gate-result-regist.md", "changelog.d/FEAT-LOOP-2026-0250-specfuse-stats-reports-the-agent-verify.md"], "agent_status": "complete", "agent_blocked_reason": null, "re_arm_count": 0, "failing_tests": []}} +{"timestamp": "2026-11-25T17:07:02.326666+00:00", "correlation_id": "FEAT-LOOP-2026-0250/G1-CLOSE", "event_type": "task_completed", "source": "driver", "source_version": "0.33.2", "payload": {"attempts": 1, "attempts_usage": [{"attempt": 1, "duration_seconds": 197.611, "cost_usd": 1.2081899, "input_tokens": 72, "output_tokens": 26080, "cache_read_input_tokens": 3270459, "cache_creation_input_tokens": 155050, "agent_seconds": 194.99197466706391, "verify_seconds": 2.53918529197108}], "type": "close", "re_arm_count": 1, "cost_usd": 1.20819, "cumulative_cost_usd": 1.20819, "attempts_lifetime": 1, "planned_cost_usd": 5.0}} +{"timestamp": "2026-11-25T17:07:02.343181+00:00", "correlation_id": "FEAT-LOOP-2026-0250", "event_type": "gate_reached", "source": "driver", "source_version": "0.33.2", "payload": {"gate": 1}} +{"timestamp": "2026-11-25T17:07:02.343171+00:00", "correlation_id": "FEAT-LOOP-2026-0250", "event_type": "arm_predicate_evaluated", "source": "driver", "source_version": "0.33.2", "payload": {"gate": 1, "would_arm": true, "predicate_version": "v1", "classes": {"budget_projection": {"status": "clean", "reason": "projected spend $2.91 within 2.0x baseline planned total $18.50 (cap $37.00)"}, "judge_editing": {"status": "clean", "reason": "no drafted WU touches judge-path surfaces"}, "decision_class_paths": {"status": "clean", "reason": "no drafted WU touches a recognised dependency manifest (pyproject.toml, package.json, pom.xml, build.gradle, build.gradle.kts, Cargo.toml, go.mod, Gemfile, composer.json, requirements*.txt, *.csproj)"}, "retroactive_edits": {"status": "clean", "reason": "no passed-gate baseline WU altered or removed"}, "drift_caps": {"status": "clean", "reason": "added WUs and gates within drift caps"}, "missing_provenance": {"status": "clean", "reason": "no added WUs"}, "open_questions_human_only": {"status": "clean", "reason": "terminal gate: no drafted successor"}, "plan_next_lint": {"status": "clean", "reason": "plan-next lint: no findings"}}}} +{"timestamp": "2026-11-25T17:07:02.482474+00:00", "correlation_id": "FEAT-LOOP-2026-0250", "event_type": "followups_recorded", "source": "driver", "source_version": "0.33.2", "payload": {"filed": 0, "unfiled": 0, "already_tracked": 0, "issue_numbers": [], "written_back": []}} diff --git a/.specfuse/features/FEAT-LOOP-2026-0250-gate-timings/work/FEAT-LOOP-2026-0250_T01/attempt-1.md b/.specfuse/features/FEAT-LOOP-2026-0250-gate-timings/work/FEAT-LOOP-2026-0250_T01/attempt-1.md new file mode 100644 index 00000000..c2174d19 --- /dev/null +++ b/.specfuse/features/FEAT-LOOP-2026-0250-gate-timings/work/FEAT-LOOP-2026-0250_T01/attempt-1.md @@ -0,0 +1,359 @@ +### tests: PASS +``` +$ python3 -m unittest tests.test_gate_timings -v -b +test_ok_skipped_and_durations (tests.test_gate_timings.TestAttemptGateEvents.test_ok_skipped_and_durations) ... ok +test_one_gate_result_per_gate_with_payload (tests.test_gate_timings.TestAttemptGateEvents.test_one_gate_result_per_gate_with_payload) ... ok +test_stub_verify_without_gate_results_emits_nothing (tests.test_gate_timings.TestAttemptGateEvents.test_stub_verify_without_gate_results_emits_nothing) ... ok +test_split (tests.test_gate_timings.TestAttemptSplit.test_split) ... skipped 'T02 owns the agent_seconds/verify_seconds split' +test_phases (tests.test_gate_timings.TestBaselineAndBroadPhases.test_phases) ... skipped 'T03 owns baseline and broad gate_result phases' +test_every_emitted_event_type_validates (tests.test_gate_timings.TestNothingExistingChanges.test_every_emitted_event_type_validates) ... skipped 'T02-T04 own the remaining clause-5 checks' +test_gate_result_in_schema_event_types (tests.test_gate_timings.TestNothingExistingChanges.test_gate_result_in_schema_event_types) ... ok +test_stats (tests.test_gate_timings.TestStatsReport.test_stats) ... skipped 'T04 owns the specfuse stats report' + +---------------------------------------------------------------------- +Ran 8 tests in 1.286s + +OK (skipped=4) +full output: .specfuse/features/FEAT-LOOP-2026-0250-gate-timings/work/gate-logs/tests-20261125T152018611236Z.log +``` + +### lint: PASS +``` +$ ruff check specfuse .specfuse/scripts tests scripts +All checks passed! +full output: .specfuse/features/FEAT-LOOP-2026-0250-gate-timings/work/gate-logs/lint-20261125T152018695313Z.log +``` + +### changelog-fragments: PASS +``` +$ python3 -m specfuse.loop.changelog_fragments check +full output: .specfuse/features/FEAT-LOOP-2026-0250-gate-timings/work/gate-logs/changelog-fragments-20261125T152018780185Z.log +``` + +### agent-policy-example-lint: PASS +``` +$ python3 .specfuse/scripts/lint_agent_policy.py .specfuse/agent-policy.yml.example && python3 .specfuse/scripts/lint_agent_policy.py .specfuse/agent-policy.yml +full output: .specfuse/features/FEAT-LOOP-2026-0250-gate-timings/work/gate-logs/agent-policy-example-lint-20261125T152018961483Z.log +``` + +### event-type-gate: PASS +``` +$ python3 .specfuse/scripts/event_type_gate.py +ok: no validation errors across 90 events.jsonl file(s), 2845 event(s) checked +NO VERDICT FOUND: the gate command produced no recognisable pass/fail summary anywhere in its output — the lines above are the tail only, and may be unrelated to the failure. Run the command directly. +full output: .specfuse/features/FEAT-LOOP-2026-0250-gate-timings/work/gate-logs/event-type-gate-20261125T152019230269Z.log +``` + +### roadmap-link-gate: FAIL +``` +$ python3 .specfuse/scripts/roadmap_link_gate.py +WARN: roadmap.md:29: FEAT-LOOP-2026-0011's Detail cell is '—' but a detail section already exists in roadmap.md — link it, e.g. '[→ detail](#feat-loop-2026-0011)' or '[→ archive](roadmap-archive.md#feat-loop-2026-0011)' +ERROR: roadmap.md:131: ref '#feat-loop-2026-0250' in roadmap.md does not resolve — no anchor 'feat-loop-2026-0250' found in roadmap.md or roadmap-archive.md +roadmap link lint: checked roadmap.md + roadmap-archive.md link graph — 1 error(s), 1 warning(s) + +1 roadmap-link error(s). +full output: .specfuse/features/FEAT-LOOP-2026-0250-gate-timings/work/gate-logs/roadmap-link-gate-20261125T152019309405Z.log +``` + +### arm-sweep-gate: PASS +``` +$ python3 .specfuse/scripts/arm_sweep_gate.py +branch-observation table: + budget_projection observed=[clean, fired]; NEVER not_evaluable + judge_editing observed=[clean, fired]; NEVER not_evaluable + decision_class_paths observed=[clean, fired]; NEVER not_evaluable + retroactive_edits observed=[clean, fired]; NEVER not_evaluable + drift_caps observed=[clean, fired]; NEVER not_evaluable + missing_provenance observed=[clean, fired]; NEVER not_evaluable + open_questions_human_only observed=[clean, fired]; NEVER not_evaluable + plan_next_lint observed=[clean, fired]; NEVER not_evaluable +evaluable=51 evaluated=51 could_not_evaluate=0 excluded_no_baseline=45 +ok: 51 evaluable feature(s) swept clean, no not_evaluable verdicts +NO VERDICT FOUND: the gate command produced no recognisable pass/fail summary anywhere in its output — the lines above are the tail only, and may be unrelated to the failure. Run the command directly. +full output: .specfuse/features/FEAT-LOOP-2026-0250-gate-timings/work/gate-logs/arm-sweep-gate-20261125T152019943949Z.log +``` + +### monitoring-example-lint: PASS +``` +$ python3 .specfuse/scripts/lint_monitoring.py .specfuse/monitoring.yml.example +OK — monitoring config is structurally valid (or absent). +full output: .specfuse/features/FEAT-LOOP-2026-0250-gate-timings/work/gate-logs/monitoring-example-lint-20261125T152020003773Z.log +``` + +### feature_oracle: PASS +``` +$ python3 -m unittest tests.test_gate_timings -v -b +test_ok_skipped_and_durations (tests.test_gate_timings.TestAttemptGateEvents.test_ok_skipped_and_durations) ... ok +test_one_gate_result_per_gate_with_payload (tests.test_gate_timings.TestAttemptGateEvents.test_one_gate_result_per_gate_with_payload) ... ok +test_stub_verify_without_gate_results_emits_nothing (tests.test_gate_timings.TestAttemptGateEvents.test_stub_verify_without_gate_results_emits_nothing) ... ok +test_split (tests.test_gate_timings.TestAttemptSplit.test_split) ... skipped 'T02 owns the agent_seconds/verify_seconds split' +test_phases (tests.test_gate_timings.TestBaselineAndBroadPhases.test_phases) ... skipped 'T03 owns baseline and broad gate_result phases' +test_every_emitted_event_type_validates (tests.test_gate_timings.TestNothingExistingChanges.test_every_emitted_event_type_validates) ... skipped 'T02-T04 own the remaining clause-5 checks' +test_gate_result_in_schema_event_types (tests.test_gate_timings.TestNothingExistingChanges.test_gate_result_in_schema_event_types) ... ok +test_stats (tests.test_gate_timings.TestStatsReport.test_stats) ... skipped 'T04 owns the specfuse stats report' + +---------------------------------------------------------------------- +Ran 8 tests in 1.283s + +OK (skipped=4) +full output: .specfuse/features/FEAT-LOOP-2026-0250-gate-timings/work/gate-logs/feature_oracle-20261125T152021386511Z.log +``` + +## Rejected working-tree diff (discarded by git reset on block) + +```diff +diff --git a/.specfuse/features/FEAT-LOOP-2026-0250-gate-timings/WU-01-attempt-gate-events.md b/.specfuse/features/FEAT-LOOP-2026-0250-gate-timings/WU-01-attempt-gate-events.md +index bcfb5a7..18533d2 100644 +--- a/.specfuse/features/FEAT-LOOP-2026-0250-gate-timings/WU-01-attempt-gate-events.md ++++ b/.specfuse/features/FEAT-LOOP-2026-0250-gate-timings/WU-01-attempt-gate-events.md +@@ -1,8 +1,8 @@ + --- + id: FEAT-LOOP-2026-0250/T01 + type: implementation +-status: pending +-attempts: 0 ++status: in_progress ++attempts: 1 + oracle_env: macos_local + planned_cost_usd: 4.00 + produces: +@@ -13,6 +13,9 @@ produces_driver_helper: + - _run_gate_set + model: sonnet + effort: medium ++gate_set: code ++driver_version: 0.33.2 ++started_at: 2026-11-25T15:15:30.163148+00:00 + --- + + # T01 — walking skeleton: attempt-phase `gate_result` events +diff --git a/specfuse/loop/data/schemas/driver-event.schema.json b/specfuse/loop/data/schemas/driver-event.schema.json +index 7a1c356..12c4037 100644 +--- a/specfuse/loop/data/schemas/driver-event.schema.json ++++ b/specfuse/loop/data/schemas/driver-event.schema.json +@@ -3,9 +3,10 @@ + "$id": "https://specfuse.dev/loop/schemas/driver-event.schema.json", + "title": "Driver-local envelope registry", + "description": "Additive to the vendored orchestrator envelope (event.schema.json): shapes the loop driver emits with no orchestrator-side counterpart. validate_event.py resolves each shape against the vendored envelope first; only when absent there does it fall through to this registry. `event_types` (FEAT-2026-0060) widens the event_type enum; task_started, task_completed, and human_escalation are already sanctioned in the vendored enum and must not be duplicated here. `correlation_id` (FEAT-2026-0073) widens the correlation_id pattern to admit the closing-sequence and hygiene shapes `.specfuse/rules/correlation-ids.md` documents; `closing_names` and `hygiene_suffix_pattern` here must state the same set of shapes as that rules file's combined pattern (and as specfuse/loop/lint_plan.py's CORRELATION_ID_RE, which independently enforces the same contract on PLAN.md graphs).", +- "$comment": "FEAT-2026-0060/T01: event_types derived from the union of every build_event(...) call site in specfuse/loop/loop.py and a corpus sweep of every .specfuse/features/*/events.jsonl, subtracting the vendored envelope enum. attempt_outcome and gate_reached were already-known precedent (loop.py's build_arm_predicate_event docstring); auto_close_decision, arm_predicate_evaluated, re_arm_dispatched, plan_next_draft_lint, and unsandboxed_dispatch are additional driver-local mechanics the orchestrator has no concept of. gate_auto_armed (loop.py build_event call under gate_events.append) and re_arm_rejected (loop.py build_event call under the spinning_reproduction_missing re-arm check) are emitted by real code paths that have never fired in a recorded run, so a corpus-only sweep cannot see them; they are included because call-site derivation does. FEAT-2026-0073/T01: correlation_id added — closing_names and hygiene_suffix_pattern mirror correlation-ids.md's documented shapes and lint_plan.py's CORRELATION_ID_RE verbatim, so the envelope, the rules file, and the PLAN-graph linter state one contract. FEAT-2026-0075/T03: driver_staleness_detected added — emitted at gate completion when a work unit's squash diff touched the driver's own importable surface, naming the editing unit, the driver paths it touched, and the IDs of units this process dispatched afterward (which ran the pre-edit module). FEAT-2026-0100/T02: judged added — emitted once per terminal close after the closing-deliverable guards, carrying the close's own verdict, the judge session's verdict (null when the judge was disabled, timed out, or returned nothing parseable, with the reason beside it), and whether the judge lowered it. FEAT-2026-0109/T01: baseline_attribution added — emitted when the retroactive per-attempt-failure baseline probe (attribute_failure_to_baseline) runs fresh, carrying the gate, the failing-gate set, and the unit whose failed attempt triggered the probe. FEAT-2026-0109/T06: broad_run_result added — emitted whenever the once-per-gate broad verification pass (gate_broad_run_check) actually runs (never on a tree-unchanged dedup skip), carrying the gate, the tree it was measured on, and its pass/fail outcome; a failing broad run additionally raises the existing human_escalation event type with reason: broad_run_gate_failure, which needs no schema addition since human_escalation is already sanctioned in the vendored envelope enum. FEAT-2026-0109/T08: driver_build_pinned added — emitted once per process, before any work unit is dispatched, when this process is itself a materialized pin (`_reexec_pinned`); carries the pin's tree hash and its path so an operator or test can read what build actually ran without inferring it from `ps` output. `driver_staleness_detected` needed no addition here: this unit reuses it with `halted: false` for the pinned, non-halting case (the registry constrains the type list, not the payload), adding `pinned_tree` / `next_pin_tree` fields alongside the existing `halted: true` shape. FEAT-2026-0104/T04: replan added — emitted once a re-plan turn (T03's run_replan_turn) rewrites a unit's body ahead of its last permitted attempt, so gate_eval.py's evaluate_auto_close (check 2, already reading this event_type since FEAT-2026-0018/T02) can disable auto-close for a gate that needed one. FEAT-2026-0115/T01: fix_unit_inserted added — emitted once a blocked RESULT's `blocked_next:` names a drafted fix unit that `insert_fix_unit` validated and inserted ahead of the blocked unit, carrying the fix unit's id, its file, the gate, and the insertion count; the blocked unit's own re-arm (an existing `re_arm_dispatched`, reason `fix_unit_inserted`) rides alongside it, so this is the only genuinely new event_type the mechanic needs. FEAT-2026-0246/T01: terminal_judge_editing_evaluated added — emitted on every terminal gate immediately before the close (auto or dispatched), carrying the gate, the `arm_eval.evaluate_terminal_judge_editing` verdict status and reason; a `fired` verdict additionally raises the existing human_escalation event type with reason: judge_editing_terminal, which needs no schema addition. FEAT-2026-0246/T02: terminal_judge_editing_acknowledged added — emitted when that check is clean only because the close unit carries an operator-authored judge_edit_acknowledged field covering every hit, carrying the gate, close unit id, acknowledged paths, and the operator's reason. FEAT-2026-0247/T06: the correlation-ID shape (legacy FEAT-YYYY-NNNN and the keyed FEAT--YYYY-NNNN form) now comes from specfuse.loop.ids.", ++ "$comment": "FEAT-2026-0060/T01: event_types derived from the union of every build_event(...) call site in specfuse/loop/loop.py and a corpus sweep of every .specfuse/features/*/events.jsonl, subtracting the vendored envelope enum. attempt_outcome and gate_reached were already-known precedent (loop.py's build_arm_predicate_event docstring); auto_close_decision, arm_predicate_evaluated, re_arm_dispatched, plan_next_draft_lint, and unsandboxed_dispatch are additional driver-local mechanics the orchestrator has no concept of. gate_auto_armed (loop.py build_event call under gate_events.append) and re_arm_rejected (loop.py build_event call under the spinning_reproduction_missing re-arm check) are emitted by real code paths that have never fired in a recorded run, so a corpus-only sweep cannot see them; they are included because call-site derivation does. FEAT-2026-0073/T01: correlation_id added — closing_names and hygiene_suffix_pattern mirror correlation-ids.md's documented shapes and lint_plan.py's CORRELATION_ID_RE verbatim, so the envelope, the rules file, and the PLAN-graph linter state one contract. FEAT-2026-0075/T03: driver_staleness_detected added — emitted at gate completion when a work unit's squash diff touched the driver's own importable surface, naming the editing unit, the driver paths it touched, and the IDs of units this process dispatched afterward (which ran the pre-edit module). FEAT-2026-0100/T02: judged added — emitted once per terminal close after the closing-deliverable guards, carrying the close's own verdict, the judge session's verdict (null when the judge was disabled, timed out, or returned nothing parseable, with the reason beside it), and whether the judge lowered it. FEAT-2026-0109/T01: baseline_attribution added — emitted when the retroactive per-attempt-failure baseline probe (attribute_failure_to_baseline) runs fresh, carrying the gate, the failing-gate set, and the unit whose failed attempt triggered the probe. FEAT-2026-0109/T06: broad_run_result added — emitted whenever the once-per-gate broad verification pass (gate_broad_run_check) actually runs (never on a tree-unchanged dedup skip), carrying the gate, the tree it was measured on, and its pass/fail outcome; a failing broad run additionally raises the existing human_escalation event type with reason: broad_run_gate_failure, which needs no schema addition since human_escalation is already sanctioned in the vendored envelope enum. FEAT-2026-0109/T08: driver_build_pinned added — emitted once per process, before any work unit is dispatched, when this process is itself a materialized pin (`_reexec_pinned`); carries the pin's tree hash and its path so an operator or test can read what build actually ran without inferring it from `ps` output. `driver_staleness_detected` needed no addition here: this unit reuses it with `halted: false` for the pinned, non-halting case (the registry constrains the type list, not the payload), adding `pinned_tree` / `next_pin_tree` fields alongside the existing `halted: true` shape. FEAT-2026-0104/T04: replan added — emitted once a re-plan turn (T03's run_replan_turn) rewrites a unit's body ahead of its last permitted attempt, so gate_eval.py's evaluate_auto_close (check 2, already reading this event_type since FEAT-2026-0018/T02) can disable auto-close for a gate that needed one. FEAT-2026-0115/T01: fix_unit_inserted added — emitted once a blocked RESULT's `blocked_next:` names a drafted fix unit that `insert_fix_unit` validated and inserted ahead of the blocked unit, carrying the fix unit's id, its file, the gate, and the insertion count; the blocked unit's own re-arm (an existing `re_arm_dispatched`, reason `fix_unit_inserted`) rides alongside it, so this is the only genuinely new event_type the mechanic needs. FEAT-2026-0246/T01: terminal_judge_editing_evaluated added — emitted on every terminal gate immediately before the close (auto or dispatched), carrying the gate, the `arm_eval.evaluate_terminal_judge_editing` verdict status and reason; a `fired` verdict additionally raises the existing human_escalation event type with reason: judge_editing_terminal, which needs no schema addition. FEAT-2026-0246/T02: terminal_judge_editing_acknowledged added — emitted when that check is clean only because the close unit carries an operator-authored judge_edit_acknowledged field covering every hit, carrying the gate, close unit id, acknowledged paths, and the operator's reason. FEAT-2026-0247/T06: the correlation-ID shape (legacy FEAT-YYYY-NNNN and the keyed FEAT--YYYY-NNNN form) now comes from specfuse.loop.ids. FEAT-LOOP-2026-0250/T01: gate_result added — emitted once per gate per attempt (phase: attempt) alongside attempt_outcome, carrying the attempt, gate, ok, skipped, duration_seconds and phase, so per-gate wall-clock time is recorded instead of only the attempt total.", + "event_types": [ + "attempt_outcome", ++ "gate_result", + "gate_reached", + "auto_close_decision", + "arm_predicate_evaluated", +diff --git a/specfuse/loop/loop.py b/specfuse/loop/loop.py +index 17e32d9..4408b28 100644 +--- a/specfuse/loop/loop.py ++++ b/specfuse/loop/loop.py +@@ -928,6 +928,12 @@ class WorkUnit: + # attempt's RESULT named untouched paths outside `produces:` that got + # silently dropped from files_changed. None on every other attempt. + auto_repaired_files_changed: "list[str] | None" = None ++ # INTERNAL, never frontmatter (FEAT-LOOP-2026-0250/T01): the per-gate ++ # result dicts of the attempt's most recent `verify()` call, reset by ++ # `execute_unit_attempt` before each verification so the dispatch loop can ++ # emit one `gate_result` event per gate without changing `verify_fn`'s ++ # `(passed, evidence)` return contract. Empty when verify never ran. ++ last_gate_results: "list[dict]" = field(default_factory=list) + # VESTIGIAL tracer-bullet opt-in (FEAT-2026-0104/T01). Parsed for + # backward compatibility with fixtures that still declare it, but no + # longer read by the dispatch loop — T02's `should_replan_instead_of_retry` +@@ -6759,7 +6765,10 @@ def _run_gate_set( + ) -> list[dict]: + """Run every gate in *gate_set* and return one result dict per gate. + +- Each dict is {"name": str, "ok": bool, "report": str} where "report" is ++ Each dict is {"name": str, "ok": bool, "report": str, "duration_seconds": ++ float, "skipped": bool} (the last two FEAT-LOOP-2026-0250/T01: wall-clock ++ seconds of a spawned gate; 0 and True for a gate skipped on a failed ++ dependency) where "report" is + the same PASS/FAIL fenced block `verify()` has always produced. Factored + out of `verify()` (FEAT-2026-0051/T01) so `probe_baseline()` + can run the `code` set independent of any work unit without duplicating the +@@ -6795,6 +6804,8 @@ def _run_gate_set( + f"### {gate['name']}: SKIP — dependency " + f"'{failed_dep}' failed" + ), ++ "duration_seconds": 0, ++ "skipped": True, + }) + continue + command = gate["command"].replace("{feature_dir}", str(feature_dir)) +@@ -6837,6 +6848,8 @@ def _run_gate_set( + f"(https://git-scm.com/download/win) so gate commands can " + f"run through bash.exe.\n```" + +… (diff truncated) +--- /dev/null ++++ b/tests/test_gate_timings.py ++# ++# Copyright 2026 Specfuse contributors ++# Licensed under the Apache License, Version 2.0. See LICENSE. ++# ++"""FEAT-LOOP-2026-0250 — per-gate timings are recorded, and `specfuse stats` reads them. ++ ++One class per Definition-of-done clause in GATE-01.md. T01 (walking skeleton) ++implements clause 1 and the schema half of clause 5; the other classes are ++skipped here and owned by T02, T03 and T04. ++""" ++ ++from __future__ import annotations ++ ++import json ++import tempfile ++import unittest ++from pathlib import Path ++ ++from tests._loop_loader import REPO_ROOT, load_loop ++ ++loop = load_loop() ++ ++SCHEMA_PATH = ( ++ REPO_ROOT / "specfuse" / "loop" / "data" / "schemas" / "driver-event.schema.json" ++) ++ ++PASS_SLEEP = 0.4 ++ORACLE_SLEEP = 0.2 ++ ++ ++def _make_wu(feature_dir: Path) -> "loop.WorkUnit": ++ wu_file = feature_dir / "WU-01-gate-timings.md" ++ wu_file.write_text("---\nstatus: pending\n---\n") ++ return loop.WorkUnit( ++ wu_id="FEAT-LOOP-2026-9999/T01", ++ file=wu_file, ++ depends_on=[], ++ type="implementation", ++ model="sonnet", ++ status="pending", ++ attempts=1, ++ title="T01", ++ body="**Objective.** test", ++ ) ++ ++ ++class TestAttemptGateEvents(unittest.TestCase): ++ """Clause 1 — one `gate_result` per gate per attempt, oracle included.""" ++ ++ def setUp(self): ++ self._tmp = tempfile.TemporaryDirectory() ++ self.addCleanup(self._tmp.cleanup) ++ self.feature_dir = Path(self._tmp.name) ++ (self.feature_dir / "work").mkdir() ++ self.gate_file = self.feature_dir / "GATE-01.md" ++ self.gate_file.write_text( ++ f'---\ngate: 1\nfeature_oracle: "sleep {ORACLE_SLEEP}"\n---\n' ++ ) ++ self.cfg = { ++ "code": [ ++ {"name": "slow_pass", "command": f"sleep {PASS_SLEEP}"}, ++ {"name": "boom", "command": "exit 1"}, ++ {"name": "after_boom", "command": "exit 0", "needs": ["boom"]}, ++ ] ++ } ++ ++ def _attempt(self): ++ wu = _make_wu(self.feature_dir) ++ ++ def verify_fn(w, fd, gate_file=None): ++ return loop.verify(w, fd, cfg=self.cfg, gate_file=gate_file) ++ ++ outcome, _payload, _usage = loop.execute_unit_attempt( ++ wu, self.feature_dir, None, ++ dispatch_fn=lambda w, note: "agent did things", ++ verify_fn=verify_fn, ++ prerun_cfg=self.cfg, ++ gate_file=self.gate_file, ++ ) ++ events = loop.emit_gate_result_events(wu, 1, wu.last_gate_results) ++ return wu, outcome, events ++ ++ def test_one_gate_result_per_gate_with_payload(self): ++ wu, outcome, events = self._attempt() ++ self.assertEqual(outcome, "failed") ++ self.assertEqual( ++ [e["payload"]["gate"] for e in events], ++ ["slow_pass", "boom", "after_boom", "feature_oracle"], ++ ) ++ for e in events: ++ self.assertEqual(e["event_type"], "gate_result") ++ self.assertEqual(e["correlation_id"], wu.wu_id) ++ self.assertEqual( ++ set(e["payload"]), ++ {"attempt", "gate", "ok", "skipped", "duration_seconds", "phase"}, ++ ) ++ self.assertEqual(e["payload"]["attempt"], 1) ++ self.assertEqual(e["payload"]["phase"], "attempt") ++ ++ def test_ok_skipped_and_durations(self): ++ _wu, _outcome, events = self._attempt() ++ by_gate = {e["payload"]["gate"]: e["payload"] for e in events} ++ self.assertTrue(by_gate["slow_pass"]["ok"]) ++ self.assertFalse(by_gate["slow_pass"]["skipped"]) ++ self.assertGreaterEqual(by_gate["slow_pass"]["duration_seconds"], PASS_SLEEP) ++ self.assertFalse(by_gate["boom"]["ok"]) ++ self.assertFalse(by_gate["boom"]["skipped"]) ++ self.assertGreater(by_gate["boom"]["duration_seconds"], 0) ++ self.assertFalse(by_gate["after_boom"]["ok"]) ++ self.assertTrue(by_gate["after_boom"]["skipped"]) ++ self.assertEqual(by_gate["after_boom"]["duration_seconds"], 0) ++ self.assertTrue(by_gate["feature_oracle"]["ok"]) ++ self.assertGreaterEqual( ++ by_gate["feature_oracle"]["duration_seconds"], ORACLE_SLEEP ++ ) ++ ++ def test_stub_verify_without_gate_results_emits_nothing(self): ++ wu = _make_wu(self.feature_dir) ++ outcome, _p, _u = loop.execute_unit_attempt( ++ wu, self.feature_dir, None, ++ dispatch_fn=lambda w, note: "agent did things", ++ verify_fn=lambda w, fd: (True, "ok"), ++ prerun_cfg=self.cfg, ++ ) ++ self.assertEqual(outcome, "passed") ++ self.assertEqual(wu.last_gate_results, []) ++ self.assertEqual(loop.emit_gate_result_events(wu, 1, wu.last_gate_results), []) ++ ++ ++class TestAttemptSplit(unittest.TestCase): ++ """Clause 2 — owned by T02.""" ++ ++ @unittest.skip("T02 owns the agent_seconds/verify_seconds split") ++ def test_split(self): ++ pass ++ ++ ++class TestBaselineAndBroadPhases(unittest.TestCase): ++ """Clause 3 — owned by T03.""" ++ ++ @unittest.skip("T03 owns baseline and broad gate_result phases") ++ def test_phases(self): ++ pass ++ ++ ++class TestStatsReport(unittest.TestCase): ++ """Clause 4 — owned by T04.""" ++ ++ @unittest.skip("T04 owns the specfuse stats report") ++ def test_stats(self): ++ pass ++ ++ ++class TestNothingExistingChanges(unittest.TestCase): ++ """Clause 5 — schema half implemented in T01; the rest owned by T02-T04.""" ++ ++ def test_gate_result_in_schema_event_types(self): ++ schema = json.loads(SCHEMA_PATH.read_text()) ++ self.assertIn("gate_result", schema["event_types"]) ++ ++ @unittest.skip("T02-T04 own the remaining clause-5 checks") ++ def test_every_emitted_event_type_validates(self): ++ pass ++ ++ ++if __name__ == "__main__": ++ unittest.main() + +``` diff --git a/.specfuse/roadmap-archive.md b/.specfuse/roadmap-archive.md index 71432eaa..f6d89575 100644 --- a/.specfuse/roadmap-archive.md +++ b/.specfuse/roadmap-archive.md @@ -43,6 +43,24 @@ sections inline in `roadmap.md`. point; T02 (`roadmap-archive` skill) and T04 (migration) append after it. + +## FEAT-LOOP-2026-0250 — Record verification gate results and durations + +**Why.** `attempt_outcome.duration_seconds` is one timer around the agent session and every verification gate together, and no event records which gates ran, how long each took, or which passed. An operator report measured 184 attempts, about 17.5 hours of attempt time, with no way to say how much was the agent and how much the gates, so every optimisation (smaller units, model or effort, a faster gate, parallel gates) is a guess. + +**Goal.** One `gate_result` event per gate per run (attempt, baseline probe, broad run) with its outcome and duration; `agent_seconds` and `verify_seconds` on `attempt_outcome`; `specfuse stats` reports the agent/verify split per feature and the slowest gates, and says "not recorded" on older logs. One gate, four units and a terminal close. + +**Out of scope.** A live progress view or halt notification, parallel gates or a result cache, backfilling old logs, persisting events from killed attempts. + +**Status: done.** + +**Post-merge checklist.** + +- Run one real feature and check that `agent_seconds + verify_seconds` is close to + `duration_seconds` on real attempts (the oracle stubs the agent session). +- Run `specfuse stats` on the corpus that motivated this feature and confirm the slowest-gates + view names real gates. + ## FEAT-LOOP-2026-0249 — Changelog fragments: stop concurrent PRs conflicting on CHANGELOG.md diff --git a/.specfuse/roadmap.md b/.specfuse/roadmap.md index 5168f3aa..d647aa84 100644 --- a/.specfuse/roadmap.md +++ b/.specfuse/roadmap.md @@ -128,6 +128,7 @@ installation a target project copies via `init.sh`. | FEAT-LOOP-2026-0247 | Project-keyed feature IDs (`FEAT--YYYY-NNNN`) | done | — | [→ archive](roadmap-archive.md#feat-loop-2026-0247) | | FEAT-LOOP-2026-0248 | Make `ids migrate --all` safe on a real repository | done | — | [→ archive](roadmap-archive.md#feat-loop-2026-0248) | | FEAT-LOOP-2026-0249 | Changelog fragments: stop concurrent PRs conflicting on CHANGELOG.md | done | — | [→ archive](roadmap-archive.md#feat-loop-2026-0249) | +| FEAT-LOOP-2026-0250 | Record verification gate results and durations | done | `.specfuse/features/FEAT-LOOP-2026-0250-gate-timings/` | [→ archive](roadmap-archive.md#feat-loop-2026-0250) | Status: `planned` → `active` → `done` (or `abandoned`). `deferred` = parked by choice pending an external decision/dependency; resumable (a human flips it diff --git a/changelog.d/FEAT-LOOP-2026-0250-attempt-outcome-payloads-gain-agent-seco.md b/changelog.d/FEAT-LOOP-2026-0250-attempt-outcome-payloads-gain-agent-seco.md new file mode 100644 index 00000000..2b700828 --- /dev/null +++ b/changelog.d/FEAT-LOOP-2026-0250-attempt-outcome-payloads-gain-agent-seco.md @@ -0,0 +1,5 @@ +--- +class: added +trace: FEAT-LOOP-2026-0250 +--- +`attempt_outcome` payloads gain `agent_seconds` and `verify_seconds`, splitting an attempt's time between the agent session and verification; `duration_seconds` keeps its meaning diff --git a/changelog.d/FEAT-LOOP-2026-0250-new-driver-event-type-gate-result-regist.md b/changelog.d/FEAT-LOOP-2026-0250-new-driver-event-type-gate-result-regist.md new file mode 100644 index 00000000..b47604d1 --- /dev/null +++ b/changelog.d/FEAT-LOOP-2026-0250-new-driver-event-type-gate-result-regist.md @@ -0,0 +1,5 @@ +--- +class: added +trace: FEAT-LOOP-2026-0250 +--- +New driver event type `gate_result` (registered in `driver-event.schema.json`): one per gate per run, carrying `attempt`, `gate`, `ok`, `skipped`, `duration_seconds` and `phase` (`attempt`, `baseline` or `broad`) diff --git a/changelog.d/FEAT-LOOP-2026-0250-specfuse-stats-reports-the-agent-verify.md b/changelog.d/FEAT-LOOP-2026-0250-specfuse-stats-reports-the-agent-verify.md new file mode 100644 index 00000000..807038b8 --- /dev/null +++ b/changelog.d/FEAT-LOOP-2026-0250-specfuse-stats-reports-the-agent-verify.md @@ -0,0 +1,5 @@ +--- +class: added +trace: FEAT-LOOP-2026-0250 +--- +`specfuse stats` reports the agent/verify split per feature and the slowest gates (runs, total, median, max seconds), in text and in `--json` as `time_split` and `gate_timings`; a corpus with no such events reads `not recorded` diff --git a/docs/methodology.md b/docs/methodology.md index 5594ac22..c00eaa3f 100644 --- a/docs/methodology.md +++ b/docs/methodology.md @@ -466,6 +466,24 @@ deliberate versioning decision — **and an update here in the same commit.** Five of the values above shipped without that step, and the drift was found only when someone mined the corpus (#270). +**Timings (FEAT-LOOP-2026-0250).** `attempt_outcome` carries `agent_seconds` +(the dispatched session) and `verify_seconds` (the gate set); their sum is at +most `duration_seconds`. An attempt that stopped before verification, such as +a `blocked` one, records `verify_seconds: 0`. Events written before this +feature lack both fields, and `specfuse stats` reports them as `not recorded`, +never as zero. + +Each gate a run executes also emits one `gate_result` event, payload +`attempt`, `gate`, `ok`, `skipped`, `duration_seconds`, `phase`. `phase` is one +of three values: `attempt` (the per-attempt verify, `feature_oracle` included; +`attempt` is the attempt number), `baseline` (the baseline probe) and `broad` +(the once-per-gate broad run); the last two carry `attempt: null`. A gate +skipped because a dependency failed records `ok: false`, `skipped: true`, +`duration_seconds: 0`. A broad run skipped because the tree is unchanged emits +none. Attempt-phase events are buffered in memory and flushed with the +attempt's `attempt_outcome`, so an attempt killed before its outcome is +recorded loses its `gate_result` events too; stats undercount such attempts. + `failure_class` taxonomy is **locked at v1**: `tests | lint | security | coverage | symbol_existence | bandit | other | null`. `failure_class: other` is the explicit catch-all for paths not yet diff --git a/specfuse/loop/data/docs/methodology.md b/specfuse/loop/data/docs/methodology.md index 5594ac22..c00eaa3f 100644 --- a/specfuse/loop/data/docs/methodology.md +++ b/specfuse/loop/data/docs/methodology.md @@ -466,6 +466,24 @@ deliberate versioning decision — **and an update here in the same commit.** Five of the values above shipped without that step, and the drift was found only when someone mined the corpus (#270). +**Timings (FEAT-LOOP-2026-0250).** `attempt_outcome` carries `agent_seconds` +(the dispatched session) and `verify_seconds` (the gate set); their sum is at +most `duration_seconds`. An attempt that stopped before verification, such as +a `blocked` one, records `verify_seconds: 0`. Events written before this +feature lack both fields, and `specfuse stats` reports them as `not recorded`, +never as zero. + +Each gate a run executes also emits one `gate_result` event, payload +`attempt`, `gate`, `ok`, `skipped`, `duration_seconds`, `phase`. `phase` is one +of three values: `attempt` (the per-attempt verify, `feature_oracle` included; +`attempt` is the attempt number), `baseline` (the baseline probe) and `broad` +(the once-per-gate broad run); the last two carry `attempt: null`. A gate +skipped because a dependency failed records `ok: false`, `skipped: true`, +`duration_seconds: 0`. A broad run skipped because the tree is unchanged emits +none. Attempt-phase events are buffered in memory and flushed with the +attempt's `attempt_outcome`, so an attempt killed before its outcome is +recorded loses its `gate_result` events too; stats undercount such attempts. + `failure_class` taxonomy is **locked at v1**: `tests | lint | security | coverage | symbol_existence | bandit | other | null`. `failure_class: other` is the explicit catch-all for paths not yet diff --git a/specfuse/loop/data/schemas/driver-event.schema.json b/specfuse/loop/data/schemas/driver-event.schema.json index 7a1c3562..e5437782 100644 --- a/specfuse/loop/data/schemas/driver-event.schema.json +++ b/specfuse/loop/data/schemas/driver-event.schema.json @@ -3,9 +3,10 @@ "$id": "https://specfuse.dev/loop/schemas/driver-event.schema.json", "title": "Driver-local envelope registry", "description": "Additive to the vendored orchestrator envelope (event.schema.json): shapes the loop driver emits with no orchestrator-side counterpart. validate_event.py resolves each shape against the vendored envelope first; only when absent there does it fall through to this registry. `event_types` (FEAT-2026-0060) widens the event_type enum; task_started, task_completed, and human_escalation are already sanctioned in the vendored enum and must not be duplicated here. `correlation_id` (FEAT-2026-0073) widens the correlation_id pattern to admit the closing-sequence and hygiene shapes `.specfuse/rules/correlation-ids.md` documents; `closing_names` and `hygiene_suffix_pattern` here must state the same set of shapes as that rules file's combined pattern (and as specfuse/loop/lint_plan.py's CORRELATION_ID_RE, which independently enforces the same contract on PLAN.md graphs).", - "$comment": "FEAT-2026-0060/T01: event_types derived from the union of every build_event(...) call site in specfuse/loop/loop.py and a corpus sweep of every .specfuse/features/*/events.jsonl, subtracting the vendored envelope enum. attempt_outcome and gate_reached were already-known precedent (loop.py's build_arm_predicate_event docstring); auto_close_decision, arm_predicate_evaluated, re_arm_dispatched, plan_next_draft_lint, and unsandboxed_dispatch are additional driver-local mechanics the orchestrator has no concept of. gate_auto_armed (loop.py build_event call under gate_events.append) and re_arm_rejected (loop.py build_event call under the spinning_reproduction_missing re-arm check) are emitted by real code paths that have never fired in a recorded run, so a corpus-only sweep cannot see them; they are included because call-site derivation does. FEAT-2026-0073/T01: correlation_id added — closing_names and hygiene_suffix_pattern mirror correlation-ids.md's documented shapes and lint_plan.py's CORRELATION_ID_RE verbatim, so the envelope, the rules file, and the PLAN-graph linter state one contract. FEAT-2026-0075/T03: driver_staleness_detected added — emitted at gate completion when a work unit's squash diff touched the driver's own importable surface, naming the editing unit, the driver paths it touched, and the IDs of units this process dispatched afterward (which ran the pre-edit module). FEAT-2026-0100/T02: judged added — emitted once per terminal close after the closing-deliverable guards, carrying the close's own verdict, the judge session's verdict (null when the judge was disabled, timed out, or returned nothing parseable, with the reason beside it), and whether the judge lowered it. FEAT-2026-0109/T01: baseline_attribution added — emitted when the retroactive per-attempt-failure baseline probe (attribute_failure_to_baseline) runs fresh, carrying the gate, the failing-gate set, and the unit whose failed attempt triggered the probe. FEAT-2026-0109/T06: broad_run_result added — emitted whenever the once-per-gate broad verification pass (gate_broad_run_check) actually runs (never on a tree-unchanged dedup skip), carrying the gate, the tree it was measured on, and its pass/fail outcome; a failing broad run additionally raises the existing human_escalation event type with reason: broad_run_gate_failure, which needs no schema addition since human_escalation is already sanctioned in the vendored envelope enum. FEAT-2026-0109/T08: driver_build_pinned added — emitted once per process, before any work unit is dispatched, when this process is itself a materialized pin (`_reexec_pinned`); carries the pin's tree hash and its path so an operator or test can read what build actually ran without inferring it from `ps` output. `driver_staleness_detected` needed no addition here: this unit reuses it with `halted: false` for the pinned, non-halting case (the registry constrains the type list, not the payload), adding `pinned_tree` / `next_pin_tree` fields alongside the existing `halted: true` shape. FEAT-2026-0104/T04: replan added — emitted once a re-plan turn (T03's run_replan_turn) rewrites a unit's body ahead of its last permitted attempt, so gate_eval.py's evaluate_auto_close (check 2, already reading this event_type since FEAT-2026-0018/T02) can disable auto-close for a gate that needed one. FEAT-2026-0115/T01: fix_unit_inserted added — emitted once a blocked RESULT's `blocked_next:` names a drafted fix unit that `insert_fix_unit` validated and inserted ahead of the blocked unit, carrying the fix unit's id, its file, the gate, and the insertion count; the blocked unit's own re-arm (an existing `re_arm_dispatched`, reason `fix_unit_inserted`) rides alongside it, so this is the only genuinely new event_type the mechanic needs. FEAT-2026-0246/T01: terminal_judge_editing_evaluated added — emitted on every terminal gate immediately before the close (auto or dispatched), carrying the gate, the `arm_eval.evaluate_terminal_judge_editing` verdict status and reason; a `fired` verdict additionally raises the existing human_escalation event type with reason: judge_editing_terminal, which needs no schema addition. FEAT-2026-0246/T02: terminal_judge_editing_acknowledged added — emitted when that check is clean only because the close unit carries an operator-authored judge_edit_acknowledged field covering every hit, carrying the gate, close unit id, acknowledged paths, and the operator's reason. FEAT-2026-0247/T06: the correlation-ID shape (legacy FEAT-YYYY-NNNN and the keyed FEAT--YYYY-NNNN form) now comes from specfuse.loop.ids.", + "$comment": "FEAT-2026-0060/T01: event_types derived from the union of every build_event(...) call site in specfuse/loop/loop.py and a corpus sweep of every .specfuse/features/*/events.jsonl, subtracting the vendored envelope enum. attempt_outcome and gate_reached were already-known precedent (loop.py's build_arm_predicate_event docstring); auto_close_decision, arm_predicate_evaluated, re_arm_dispatched, plan_next_draft_lint, and unsandboxed_dispatch are additional driver-local mechanics the orchestrator has no concept of. gate_auto_armed (loop.py build_event call under gate_events.append) and re_arm_rejected (loop.py build_event call under the spinning_reproduction_missing re-arm check) are emitted by real code paths that have never fired in a recorded run, so a corpus-only sweep cannot see them; they are included because call-site derivation does. FEAT-2026-0073/T01: correlation_id added — closing_names and hygiene_suffix_pattern mirror correlation-ids.md's documented shapes and lint_plan.py's CORRELATION_ID_RE verbatim, so the envelope, the rules file, and the PLAN-graph linter state one contract. FEAT-2026-0075/T03: driver_staleness_detected added — emitted at gate completion when a work unit's squash diff touched the driver's own importable surface, naming the editing unit, the driver paths it touched, and the IDs of units this process dispatched afterward (which ran the pre-edit module). FEAT-2026-0100/T02: judged added — emitted once per terminal close after the closing-deliverable guards, carrying the close's own verdict, the judge session's verdict (null when the judge was disabled, timed out, or returned nothing parseable, with the reason beside it), and whether the judge lowered it. FEAT-2026-0109/T01: baseline_attribution added — emitted when the retroactive per-attempt-failure baseline probe (attribute_failure_to_baseline) runs fresh, carrying the gate, the failing-gate set, and the unit whose failed attempt triggered the probe. FEAT-2026-0109/T06: broad_run_result added — emitted whenever the once-per-gate broad verification pass (gate_broad_run_check) actually runs (never on a tree-unchanged dedup skip), carrying the gate, the tree it was measured on, and its pass/fail outcome; a failing broad run additionally raises the existing human_escalation event type with reason: broad_run_gate_failure, which needs no schema addition since human_escalation is already sanctioned in the vendored envelope enum. FEAT-2026-0109/T08: driver_build_pinned added — emitted once per process, before any work unit is dispatched, when this process is itself a materialized pin (`_reexec_pinned`); carries the pin's tree hash and its path so an operator or test can read what build actually ran without inferring it from `ps` output. `driver_staleness_detected` needed no addition here: this unit reuses it with `halted: false` for the pinned, non-halting case (the registry constrains the type list, not the payload), adding `pinned_tree` / `next_pin_tree` fields alongside the existing `halted: true` shape. FEAT-2026-0104/T04: replan added — emitted once a re-plan turn (T03's run_replan_turn) rewrites a unit's body ahead of its last permitted attempt, so gate_eval.py's evaluate_auto_close (check 2, already reading this event_type since FEAT-2026-0018/T02) can disable auto-close for a gate that needed one. FEAT-2026-0115/T01: fix_unit_inserted added — emitted once a blocked RESULT's `blocked_next:` names a drafted fix unit that `insert_fix_unit` validated and inserted ahead of the blocked unit, carrying the fix unit's id, its file, the gate, and the insertion count; the blocked unit's own re-arm (an existing `re_arm_dispatched`, reason `fix_unit_inserted`) rides alongside it, so this is the only genuinely new event_type the mechanic needs. FEAT-2026-0246/T01: terminal_judge_editing_evaluated added — emitted on every terminal gate immediately before the close (auto or dispatched), carrying the gate, the `arm_eval.evaluate_terminal_judge_editing` verdict status and reason; a `fired` verdict additionally raises the existing human_escalation event type with reason: judge_editing_terminal, which needs no schema addition. FEAT-2026-0246/T02: terminal_judge_editing_acknowledged added — emitted when that check is clean only because the close unit carries an operator-authored judge_edit_acknowledged field covering every hit, carrying the gate, close unit id, acknowledged paths, and the operator's reason. FEAT-2026-0247/T06: the correlation-ID shape (legacy FEAT-YYYY-NNNN and the keyed FEAT--YYYY-NNNN form) now comes from specfuse.loop.ids. FEAT-LOOP-2026-0250/T01: gate_result added — emitted once per gate per attempt (the feature_oracle included), flushed with attempt_outcome, carrying the attempt, the gate, ok, skipped, duration_seconds, and phase: attempt; a gate skipped for a failed dependency records skipped: true and duration_seconds: 0.", "event_types": [ "attempt_outcome", + "gate_result", "gate_reached", "auto_close_decision", "arm_predicate_evaluated", diff --git a/specfuse/loop/events_stats.py b/specfuse/loop/events_stats.py index 3dc5df0f..7802ff7b 100644 --- a/specfuse/loop/events_stats.py +++ b/specfuse/loop/events_stats.py @@ -95,6 +95,7 @@ def collect(roots: list[Path] | list[str]) -> dict: """ seen: set[tuple] = set() attempts: list[dict] = [] + gate_runs: list[dict] = [] repos: set[str] = set() for root in roots: @@ -124,14 +125,31 @@ def collect(roots: list[Path] | list[str]) -> dict: continue # a torn line is not a reason to abandon the corpus if not isinstance(event, dict): continue - if event.get("event_type") != "attempt_outcome": + if event.get("event_type") not in ("attempt_outcome", "gate_result"): continue + # `gate_result` shares the timestamp of its sibling gates within + # one flush, so the gate name and phase join the key; for + # `attempt_outcome` the three-part key is unchanged. + payload = event.get("payload") or {} key = (event.get("correlation_id"), event.get("timestamp"), event.get("event_type")) + if event["event_type"] == "gate_result": + key += (payload.get("gate"), payload.get("phase"), + payload.get("attempt")) if key in seen: continue seen.add(key) - payload = event.get("payload") or {} + if event["event_type"] == "gate_result": + if payload.get("gate") is None: + continue + gate_runs.append({ + "gate": str(payload["gate"]), + "phase": payload.get("phase") or "attempt", + "seconds": float(payload.get("duration_seconds") or 0.0), + "feature": path.parent.name, + }) + repos.add(repo) + continue attempts.append({ "cid": event.get("correlation_id") or "", "outcome": payload.get("outcome"), @@ -141,6 +159,10 @@ def collect(roots: list[Path] | list[str]) -> dict: "diagnosed": any(payload.get(f) for f in _DIAGNOSTIC_FIELDS), "repo": repo, "feature": path.parent.name, + "agent_s": (float(payload["agent_seconds"]) + if "agent_seconds" in payload else None), + "verify_s": (float(payload["verify_seconds"]) + if "verify_seconds" in payload else None), }) repos.add(repo) @@ -193,6 +215,37 @@ def collect(roots: list[Path] | list[str]) -> dict: g["fires"] += 1 g["waste"] = round(g["waste"] + a["cost"], 2) + # Agent/verify split per feature. Only attempts that carry both fields + # count; an old corpus has neither, and must read "not recorded", never 0. + split: dict[str, dict] = {} + for a in attempts: + if a["agent_s"] is None or a["verify_s"] is None: + continue + f = split.setdefault(f"{a['repo']}:{a['feature']}", { + "attempts": 0, "agent_seconds": 0.0, "verify_seconds": 0.0}) + f["attempts"] += 1 + f["agent_seconds"] += a["agent_s"] + f["verify_seconds"] += a["verify_s"] + for f in split.values(): + total = f["agent_seconds"] + f["verify_seconds"] + f["agent_seconds"] = round(f["agent_seconds"], 2) + f["verify_seconds"] = round(f["verify_seconds"], 2) + f["agent_share"] = round(f["agent_seconds"] / total, 4) if total else 0.0 + f["verify_share"] = round(f["verify_seconds"] / total, 4) if total else 0.0 + + # Slowest gates, split by phase, ordered by total seconds. + by_gate: dict[tuple, list[float]] = {} + for g in gate_runs: + by_gate.setdefault((g["phase"], g["gate"]), []).append(g["seconds"]) + gate_timings = [ + {"phase": phase, "gate": gate, "runs": len(secs), + "total_seconds": round(sum(secs), 2), + "median_seconds": round(statistics.median(secs), 2), + "max_seconds": round(max(secs), 2)} + for (phase, gate), secs in by_gate.items() + ] + gate_timings.sort(key=lambda r: (-r["total_seconds"], r["phase"], r["gate"])) + spend = round(sum(a["cost"] for a in attempts), 2) waste = round(sum(a["cost"] for a in attempts if a["outcome"] != "passed"), 2) return { @@ -208,6 +261,8 @@ def collect(roots: list[Path] | list[str]) -> dict: "by_outcome": by_outcome, "by_guard": by_guard, "undiagnosed": undiagnosed, + "time_split": split, + "gate_timings": gate_timings, } @@ -245,6 +300,31 @@ def render(stats: dict, min_fires: int = 1) -> str: for o, v in sorted(stats["by_outcome"].items(), key=lambda kv: -kv[1]["waste"]): out.append(f" {o:32s} {v['n']:>5d} {v['waste']:>9.2f}") + out += ["", "agent / verify time per feature"] + split = stats.get("time_split") or {} + if not split: + out.append(" not recorded") + else: + out.append(f" {'feature':54s} {'agent s':>9s} {'verify s':>9s} " + f"{'agent%':>7s} {'verify%':>8s}") + for name, v in sorted(split.items(), key=lambda kv: -( + kv[1]["agent_seconds"] + kv[1]["verify_seconds"])): + out.append(f" {name:54s} {v['agent_seconds']:>9.2f} " + f"{v['verify_seconds']:>9.2f} {v['agent_share'] * 100:>6.0f}% " + f"{v['verify_share'] * 100:>7.0f}%") + + out += ["", "slowest gates (gate_result events)"] + timings = stats.get("gate_timings") or [] + if not timings: + out.append(" not recorded") + else: + out.append(f" {'phase':9s} {'gate':32s} {'runs':>5s} {'total s':>9s} " + f"{'median s':>9s} {'max s':>8s}") + for r in timings: + out.append(f" {r['phase']:9s} {r['gate']:32s} {r['runs']:>5d} " + f"{r['total_seconds']:>9.2f} {r['median_seconds']:>9.2f} " + f"{r['max_seconds']:>8.2f}") + if stats["undiagnosed"]: out += ["", f" {stats['undiagnosed']} non-passing attempts carry no " f"diagnostic in any documented field — see docs/methodology.md, " diff --git a/specfuse/loop/loop.py b/specfuse/loop/loop.py index 17e32d96..021674ad 100644 --- a/specfuse/loop/loop.py +++ b/specfuse/loop/loop.py @@ -924,6 +924,10 @@ class WorkUnit: # claimed — the per-path `produces_unchanged:` justification the contract # promises to honour (#3268). None until a session has run. result_block: "dict | None" = None + # Per-gate results of the latest verify() call (FEAT-LOOP-2026-0250/T01): + # side channel so the attempt loop can emit `gate_result` events without + # changing the verify_fn call signature. Reset before each attempt. + last_gate_results: list = field(default_factory=list) # Set by auto_repair_files_changed (FEAT-2026-0103/T03) when a passed # attempt's RESULT named untouched paths outside `produces:` that got # silently dropped from files_changed. None on every other attempt. @@ -2936,6 +2940,8 @@ def emit_attempt_outcome( "attempt": attempt, "outcome": outcome, "duration_seconds": usage.get("duration_seconds", 0.0), + "agent_seconds": usage.get("agent_seconds", 0.0), + "verify_seconds": usage.get("verify_seconds", 0.0), "cost_usd": usage.get("cost_usd", 0.0), "input_tokens": usage.get("input_tokens", 0), "output_tokens": usage.get("output_tokens", 0), @@ -6753,6 +6759,32 @@ def persist_gate_output(feature_dir: Path, gate_name: str, return None +# Per-gate results of the most recent fresh baseline probe / broad run +# (FEAT-LOOP-2026-0250/T03). Side channel so `probe_baseline` and +# `run_gate_broad_set` keep their return shapes; consumed (and cleared) by +# `build_phase_gate_events` where the caller owns an event list. +_PHASE_GATE_RESULTS: dict[str, list] = {"baseline": [], "broad": []} + + +def build_phase_gate_events(phase: str, correlation_id: str) -> list[dict]: + """One `gate_result` event per gate the last fresh *phase* run (`baseline` + or `broad`) executed, with `attempt: null`. Consumes the recorded results, + so a later call without a fresh run returns an empty list.""" + results = _PHASE_GATE_RESULTS.get(phase) or [] + _PHASE_GATE_RESULTS[phase] = [] + events = [] + for gr in results: + events.append(build_event("gate_result", correlation_id, { + "attempt": None, + "gate": gr["name"], + "ok": bool(gr["ok"]), + "skipped": bool(gr.get("skipped", False)), + "duration_seconds": gr.get("duration_seconds", 0), + "phase": phase, + })) + return events + + def _run_gate_set( gate_set: list, feature_dir: Path, _capture_returncodes: "dict | None" = None, @@ -6795,6 +6827,8 @@ def _run_gate_set( f"### {gate['name']}: SKIP — dependency " f"'{failed_dep}' failed" ), + "skipped": True, + "duration_seconds": 0, }) continue command = gate["command"].replace("{feature_dir}", str(feature_dir)) @@ -6837,6 +6871,7 @@ def _run_gate_set( f"(https://git-scm.com/download/win) so gate commands can " f"run through bash.exe.\n```" ), + "duration_seconds": 0, }) continue popen_argv = [bash, "-c", command] @@ -6844,6 +6879,7 @@ def _run_gate_set( else: popen_argv = command popen_kwargs = dict(shell=True) # nosec B604 + gate_started = time.monotonic() proc = subprocess.Popen( # nosec B602 popen_argv, stdin=subprocess.DEVNULL, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, @@ -6885,6 +6921,7 @@ def _run_gate_set( f"(process group) — a hang (test reading stdin, infinite loop, " f"or a wedged subprocess)." ] + gate_duration = round(time.monotonic() - gate_started, 3) if not ok: failed_names.add(gate["name"]) log_path = persist_gate_output(feature_dir, gate["name"], out) @@ -6895,6 +6932,7 @@ def _run_gate_set( "ok": ok, "report": (f"### {gate['name']}: {'PASS' if ok else 'FAIL'}\n" f"```\n$ {command}\n" + "\n".join(tail) + "\n```"), + "duration_seconds": gate_duration, }) return results @@ -6937,6 +6975,7 @@ def run_gate_broad_set(feature_dir: Path, cfg: "dict | None" = None) -> tuple[bo """ if cfg is None: cfg = load_verification() + _PHASE_GATE_RESULTS["broad"] = [] gate_set = cfg.get("code") or [] if not gate_set: return False, [{ @@ -6962,6 +7001,7 @@ def run_gate_broad_set(feature_dir: Path, cfg: "dict | None" = None) -> tuple[bo }] gate_set = resolve_gate_tiers(gate_set, "broad") gate_results = _run_gate_set(gate_set, feature_dir) + _PHASE_GATE_RESULTS["broad"] = list(gate_results) failing = [] for g in gate_results: if g["ok"]: @@ -7723,8 +7763,10 @@ def verify(wu: WorkUnit, feature_dir: Path, f"is not a work-unit failure — fix " f"{Path(gate_file).name} and re-run." ), + "duration_seconds": g.get("duration_seconds", 0), } break + wu.last_gate_results = list(gate_results) ok_all = all(g["ok"] for g in gate_results) for note in fallback_notes: print(f" {note}", file=sys.stderr) @@ -7745,6 +7787,7 @@ def probe_baseline(feature_dir: Path, cfg: dict | None = None) -> list[dict]: """ if cfg is None: cfg = load_verification() + _PHASE_GATE_RESULTS["baseline"] = [] gate_set = cfg.get("code") or [] try: gate_set = order_gate_set(gate_set) @@ -7759,6 +7802,7 @@ def probe_baseline(feature_dir: Path, cfg: dict | None = None) -> list[dict]: ), }] gate_results = _run_gate_set(gate_set, feature_dir) + _PHASE_GATE_RESULTS["baseline"] = list(gate_results) failing = [] for g in gate_results: if g["ok"]: @@ -8259,6 +8303,7 @@ def gate_baseline_check( return baseline["failing"], False if probed_at is None: probed_at = dt.datetime.now(dt.timezone.utc).isoformat() + _PHASE_GATE_RESULTS["baseline"] = [] failing = probe_baseline(feature_dir, cfg) write_gate_baseline( gate_file, head_sha, probed_at, failing, feature_dir, source=source) @@ -8322,6 +8367,23 @@ def _accepts_gate_file(fn) -> bool: ) +def build_attempt_gate_events(wu: "WorkUnit", attempt: int) -> list[dict]: + """One `gate_result` event per gate `verify()` ran for this attempt + (FEAT-LOOP-2026-0250/T01), read from `wu.last_gate_results`. Empty when + verify was stubbed or never reached.""" + events = [] + for gr in (getattr(wu, "last_gate_results", None) or []): + events.append(build_event("gate_result", wu.wu_id, { + "attempt": attempt, + "gate": gr["name"], + "ok": bool(gr["ok"]), + "skipped": bool(gr.get("skipped", False)), + "duration_seconds": gr.get("duration_seconds", 0), + "phase": "attempt", + })) + return events + + def execute_unit_attempt( wu: WorkUnit, feature_dir: Path, @@ -8404,14 +8466,22 @@ def execute_unit_attempt( worklist_section = format_reverification_worklist(wu, feature_dir) if worklist_section: wu.body = wu.body + "\n\n" + worklist_section + _agent_t0 = time.monotonic() if dispatch_fn is None: result = dispatch(wu, failure_note, cost_tracking) else: result = dispatch_fn(wu, failure_note) + agent_seconds = time.monotonic() - _agent_t0 if isinstance(result, tuple): stdout, usage = result else: stdout, usage = result, None + # FEAT-LOOP-2026-0250/T02: split the attempt's time into agent session and + # verification. Always a fresh dict so a stub's own usage is never mutated; + # a plain-string stub (usage None) still gets the timing keys. + usage = dict(usage) if usage else {} + usage["agent_seconds"] = agent_seconds + usage["verify_seconds"] = 0 # Zero-token guard runs BEFORE RESULT-block parsing: the agent did not # produce output, so any block in stdout is hallucinated upstream and # must not be trusted (FEAT-2026-0008/T01). Opt-in via cost tracking — @@ -8426,10 +8496,14 @@ def execute_unit_attempt( # deciding whether to insert a fix unit instead of escalating. wu.result_block = parse_result_block(stdout or "") return "blocked", reason, usage - if _accepts_gate_file(verify_fn): - passed, evidence = verify_fn(wu, feature_dir, gate_file=gate_file) - else: - passed, evidence = verify_fn(wu, feature_dir) + _verify_t0 = time.monotonic() + try: + if _accepts_gate_file(verify_fn): + passed, evidence = verify_fn(wu, feature_dir, gate_file=gate_file) + else: + passed, evidence = verify_fn(wu, feature_dir) + finally: + usage["verify_seconds"] = time.monotonic() - _verify_t0 if not passed: return "failed", evidence, usage # files_changed guard (FEAT-2026-0008/T02): the agent's RESULT claim @@ -12051,6 +12125,8 @@ def run( "ok": _broad_ok, "failing": _broad_failing, })) + _broad_events.extend( + build_phase_gate_events("broad", feature_id)) if not _broad_ok: backend.set_gate(gate, "awaiting_review") escalation_message = format_broad_run_failure( @@ -12399,11 +12475,13 @@ def run( reason = failure_note.strip().splitlines()[0][:200] print(f" retry reason: {reason}") t0 = time.monotonic() + wu.last_gate_results = [] outcome, payload, usage = execute_unit_attempt( wu, feature_dir, failure_note, cost_tracking=cost_tracking, head_before=head_before, prerun_cfg=cfg, gate_file=gate.file, ) + wu_events.extend(build_attempt_gate_events(wu, attempt)) duration = round(time.monotonic() - t0, 3) attempt_record: dict = {"attempt": attempt, "duration_seconds": duration} @@ -13426,6 +13504,8 @@ def run( "failing": _attr_failing, "attributed_to": wu.wu_id, })) + wu_events.extend( + build_phase_gate_events("baseline", wu.wu_id)) if _attr_failing: # Pre-existing: this attempt did not cause the # failure, so it is not counted against the diff --git a/tests/test_gate_timings.py b/tests/test_gate_timings.py new file mode 100644 index 00000000..20089b54 --- /dev/null +++ b/tests/test_gate_timings.py @@ -0,0 +1,364 @@ +# +# Copyright 2026 Specfuse contributors +# Licensed under the Apache License, Version 2.0. See LICENSE. +# +"""FEAT-LOOP-2026-0250 gate 1 oracle — per-gate timings recorded as +`gate_result` events. One class per Definition-of-done clause in GATE-01.md. +T01 implements clause 1 and the schema half of clause 5; the rest are skipped +naming their owning unit. +""" + +from __future__ import annotations + +import json +import tempfile +import time +import unittest +from pathlib import Path + +from tests._loop_loader import load_loop + +loop = load_loop() + +SCHEMA = (Path(__file__).resolve().parent.parent + / "specfuse" / "loop" / "data" / "schemas" / "driver-event.schema.json") + +_BODY = ( + "\n\n**Context.** test\n\n**Acceptance criteria.** test\n\n" + "**Do not touch.** test\n\n**Verification.** test\n\n" + "**Escalation triggers.** test\n" +) +SLEEP = 0.3 + + +class TestAttemptGateEvents(unittest.TestCase): + """Clause 1 — attempt phase.""" + + def setUp(self): + self._tmp = tempfile.TemporaryDirectory(ignore_cleanup_errors=True) + self.root = Path(self._tmp.name) + self.feature_dir = self.root / "feat" + self.feature_dir.mkdir() + self.wu_file = self.feature_dir / "WU-01.md" + self.wu_file.write_text( + "---\nid: FEAT-LOOP-2026-9999/T01\ntype: implementation\n" + f"model: sonnet\nstatus: pending\nattempts: 0\n---\n\n# T{_BODY}") + self.gate_file = self.feature_dir / "GATE-01.md" + self.gate_file.write_text( + "---\ngate: 1\nstatus: open\n" + f'feature_oracle: "sleep {SLEEP} && exit 0"\n---\n\n# Gate 1\n') + self.wu = loop.WorkUnit( + wu_id="FEAT-LOOP-2026-9999/T01", file=self.wu_file, depends_on=[], + type="implementation", model="sonnet", effort="medium", + status="pending", attempts=1, title="T", body="**Objective.** x") + self.cfg = {"code": [ + {"name": "slow-pass", "command": f"sleep {SLEEP} && exit 0"}, + {"name": "bad", "command": "exit 1"}, + {"name": "dependent", "command": "exit 0", "needs": ["bad"]}, + ]} + + def tearDown(self): + self._tmp.cleanup() + + def _attempt(self): + def dispatch_fn(wu, note): + return "RESULT\nstatus: complete\n" + + def verify_fn(wu, fd, gate_file=None): + return loop.verify(wu, fd, cfg=self.cfg, gate_file=gate_file) + + loop_outcome = loop.execute_unit_attempt( + self.wu, self.feature_dir, None, dispatch_fn=dispatch_fn, + verify_fn=verify_fn, cost_tracking=False, prerun_cfg=self.cfg, + gate_file=self.gate_file) + return loop_outcome, loop.build_attempt_gate_events(self.wu, 1) + + def test_one_gate_result_per_gate_with_payload(self): + (outcome, _p, _u), events = self._attempt() + self.assertEqual(outcome, "failed") + self.assertTrue(all(e["event_type"] == "gate_result" for e in events)) + self.assertTrue(all(e["correlation_id"] == self.wu.wu_id for e in events)) + by_gate = {e["payload"]["gate"]: e["payload"] for e in events} + self.assertEqual( + sorted(by_gate), ["bad", "dependent", "feature_oracle", "slow-pass"]) + self.assertEqual(len(events), 4) + for payload in by_gate.values(): + self.assertEqual( + set(payload), + {"attempt", "gate", "ok", "skipped", "duration_seconds", "phase"}) + self.assertEqual(payload["attempt"], 1) + self.assertEqual(payload["phase"], "attempt") + + def test_durations_and_skip_semantics(self): + _, events = self._attempt() + by_gate = {e["payload"]["gate"]: e["payload"] for e in events} + for name in ("slow-pass", "feature_oracle"): + self.assertTrue(by_gate[name]["ok"]) + self.assertFalse(by_gate[name]["skipped"]) + self.assertGreaterEqual(by_gate[name]["duration_seconds"], SLEEP) + self.assertFalse(by_gate["bad"]["ok"]) + self.assertFalse(by_gate["bad"]["skipped"]) + self.assertGreater(by_gate["bad"]["duration_seconds"], 0) + dep = by_gate["dependent"] + self.assertFalse(dep["ok"]) + self.assertTrue(dep["skipped"]) + self.assertEqual(dep["duration_seconds"], 0) + + def test_stub_verify_without_gate_results_emits_none(self): + self.wu.last_gate_results = [] + self.assertEqual(loop.build_attempt_gate_events(self.wu, 1), []) + + +class TestAttemptSplit(unittest.TestCase): + """Clause 2 — agent_seconds / verify_seconds on attempt_outcome.""" + + def setUp(self): + self._tmp = tempfile.TemporaryDirectory(ignore_cleanup_errors=True) + self.root = Path(self._tmp.name) + self.feature_dir = self.root / "feat" + self.feature_dir.mkdir() + wu_file = self.feature_dir / "WU-01.md" + wu_file.write_text( + "---\nid: FEAT-LOOP-2026-9999/T01\ntype: implementation\n" + f"model: sonnet\nstatus: pending\nattempts: 0\n---\n\n# T{_BODY}") + self.gate_file = self.feature_dir / "GATE-01.md" + self.gate_file.write_text("---\ngate: 1\nstatus: open\n---\n\n# Gate 1\n") + self.wu = loop.WorkUnit( + wu_id="FEAT-LOOP-2026-9999/T01", file=wu_file, depends_on=[], + type="implementation", model="sonnet", effort="medium", + status="pending", attempts=1, title="T", body="**Objective.** x") + self.cfg = {"code": [ + {"name": "slow-pass", "command": f"sleep {SLEEP} && exit 0"}]} + + def tearDown(self): + self._tmp.cleanup() + + def _run(self, stdout): + def dispatch_fn(wu, note): + time.sleep(SLEEP) + return stdout + + def verify_fn(wu, fd, gate_file=None): + return loop.verify(wu, fd, cfg=self.cfg, gate_file=gate_file) + + t0 = time.monotonic() + outcome, _p, usage = loop.execute_unit_attempt( + self.wu, self.feature_dir, None, dispatch_fn=dispatch_fn, + verify_fn=verify_fn, cost_tracking=False, prerun_cfg=self.cfg, + gate_file=self.gate_file) + duration = time.monotonic() - t0 + usage = dict(usage) + usage["duration_seconds"] = duration + event = loop.emit_attempt_outcome(self.wu, 1, outcome, usage) + return outcome, event["payload"] + + def test_split(self): + _, payload = self._run("RESULT\nstatus: complete\n") + self.assertGreaterEqual(payload["agent_seconds"], SLEEP) + self.assertGreaterEqual(payload["verify_seconds"], SLEEP) + self.assertLessEqual( + payload["agent_seconds"] + payload["verify_seconds"], + payload["duration_seconds"]) + + def test_blocked_records_zero_verify(self): + outcome, payload = self._run( + "```result\nstatus: blocked\nblocked_reason: nope\n```\n") + self.assertEqual(outcome, "blocked") + self.assertEqual(payload["verify_seconds"], 0) + self.assertGreaterEqual(payload["agent_seconds"], SLEEP) + + def test_defaults_when_usage_lacks_keys(self): + payload = loop.emit_attempt_outcome(self.wu, 1, "failed", {})["payload"] + self.assertEqual(payload["agent_seconds"], 0.0) + self.assertEqual(payload["verify_seconds"], 0.0) + + +class TestBaselineAndBroadPhases(unittest.TestCase): + """Clause 3 — baseline and broad phases.""" + + def setUp(self): + self._tmp = tempfile.TemporaryDirectory(ignore_cleanup_errors=True) + self.root = Path(self._tmp.name) + self.cfg = {"code": [ + {"name": "ok-gate", "command": "exit 0"}, + {"name": "bad", "command": "exit 1"}, + ]} + + def tearDown(self): + self._tmp.cleanup() + + def _check(self, events, phase, cid): + self.assertEqual(len(events), 2) + for e in events: + self.assertEqual(e["event_type"], "gate_result") + self.assertEqual(e["correlation_id"], cid) + self.assertEqual( + set(e["payload"]), + {"attempt", "gate", "ok", "skipped", "duration_seconds", "phase"}) + self.assertIsNone(e["payload"]["attempt"]) + self.assertEqual(e["payload"]["phase"], phase) + self.assertEqual( + sorted(e["payload"]["gate"] for e in events), ["bad", "ok-gate"]) + + def test_broad_run_phase(self): + ok, failing = loop.run_gate_broad_set(self.root, self.cfg) + self.assertFalse(ok) + self.assertEqual(set(failing[0]), { + "gate", "failure_class", "failure_signature"}) + self._check( + loop.build_phase_gate_events("broad", "FEAT-LOOP-2026-9999"), + "broad", "FEAT-LOOP-2026-9999") + self.assertEqual(loop.build_phase_gate_events("broad", "X"), []) + + def test_baseline_phase(self): + failing = loop.probe_baseline(self.root, self.cfg) + self.assertEqual( + set(failing[0]), {"gate", "failure_class", "failure_signature"}) + self._check( + loop.build_phase_gate_events("baseline", "FEAT-LOOP-2026-9999/T01"), + "baseline", "FEAT-LOOP-2026-9999/T01") + + def test_unchanged_tree_broad_skip_emits_none(self): + gate_file = self.root / "GATE-01.md" + gate_file.write_text("---\ngate: 1\nstatus: open\n---\n\n# Gate 1\n") + green = {"code": [{"name": "ok-gate", "command": "exit 0"}]} + orig = loop._current_tree_hash + loop._current_tree_hash = lambda: "tree-abc" + try: + _, _, ran = loop.gate_broad_run_check(gate_file, self.root, green) + self.assertTrue(ran) + loop.build_phase_gate_events("broad", "F") + _, _, ran = loop.gate_broad_run_check(gate_file, self.root, green) + self.assertFalse(ran) + self.assertEqual(loop.build_phase_gate_events("broad", "F"), []) + finally: + loop._current_tree_hash = orig + + +class TestStatsReport(unittest.TestCase): + """Clause 4 — owned by T04.""" + + def setUp(self): + self._tmp = tempfile.TemporaryDirectory(ignore_cleanup_errors=True) + self.root = Path(self._tmp.name) + + def tearDown(self): + self._tmp.cleanup() + + def _write(self, name, events): + d = self.root / ".specfuse" / "features" / name + d.mkdir(parents=True) + (d / "events.jsonl").write_text( + "\n".join(json.dumps(e) for e in events) + "\n") + + @staticmethod + def _attempt(ts, n, **extra): + payload = {"attempt": n, "outcome": "passed", "cost_usd": 1.0, + "duration_seconds": 10.0} + payload.update(extra) + return {"timestamp": ts, "correlation_id": "FEAT-LOOP-2026-9999/T01", + "event_type": "attempt_outcome", "payload": payload} + + @staticmethod + def _gate(ts, gate, secs, phase="attempt", attempt=1): + return {"timestamp": ts, "correlation_id": "FEAT-LOOP-2026-9999/T01", + "event_type": "gate_result", + "payload": {"attempt": attempt, "gate": gate, "ok": True, + "skipped": False, "duration_seconds": secs, + "phase": phase}} + + def test_new_corpus_reports_split_and_gates(self): + from specfuse.loop import events_stats + self._write("FEAT-LOOP-2026-9999-x", [ + self._attempt("t1", 1, agent_seconds=6.0, verify_seconds=2.0), + self._attempt("t2", 2, agent_seconds=2.0, verify_seconds=2.0), + self._gate("t1", "tests", 4.0), self._gate("t1", "lint", 1.0), + self._gate("t2", "tests", 2.0, attempt=2), + self._gate("t3", "tests", 9.0, phase="broad"), + ]) + stats = events_stats.collect([self.root]) + split = next(iter(stats["time_split"].values())) + self.assertEqual(split["agent_seconds"], 8.0) + self.assertEqual(split["verify_seconds"], 4.0) + self.assertAlmostEqual(split["agent_share"], 0.6667, places=4) + rows = {(r["phase"], r["gate"]): r for r in stats["gate_timings"]} + t = rows[("attempt", "tests")] + self.assertEqual((t["runs"], t["total_seconds"], t["median_seconds"], + t["max_seconds"]), (2, 6.0, 3.0, 4.0)) + self.assertEqual(rows[("broad", "tests")]["total_seconds"], 9.0) + # ordered by total seconds, descending + totals = [r["total_seconds"] for r in stats["gate_timings"]] + self.assertEqual(totals, sorted(totals, reverse=True)) + text = events_stats.render(stats) + self.assertNotIn("not recorded", text) + self.assertIn("slowest gates", text) + json.dumps(stats) + + def test_old_corpus_reads_not_recorded(self): + from specfuse.loop import events_stats + self._write("FEAT-LOOP-2026-8888-old", [self._attempt("t1", 1)]) + stats = events_stats.collect([self.root]) + self.assertEqual(stats["time_split"], {}) + self.assertEqual(stats["gate_timings"], []) + text = events_stats.render(stats) + self.assertEqual(text.count("not recorded"), 2) + + +class TestNothingExistingChanges(unittest.TestCase): + """Clause 5 — T01 owns the schema half; T02-T04 own the rest.""" + + def test_gate_result_in_schema_event_types(self): + schema = json.loads(SCHEMA.read_text()) + self.assertIn("gate_result", schema["event_types"]) + + def test_emitted_events_validate(self): + import importlib.resources + from unittest import mock + + from specfuse.loop import validate_event + # Pin the validator to the real packaged schemas and clear its module + # caches, as tests/test_event_gate_full_envelope.py does: another test + # in the full suite can leave `_DRIVER_EVENT_TYPES_CACHE` holding an + # empty set, which drops every driver event type from the enum. + root = importlib.resources.files("specfuse.loop").joinpath("data", "schemas") + for name, value in ( + ("SCHEMA_ROOT", root), + ("SCHEMA_PATH", root / "event.schema.json"), + ("PER_TYPE_SCHEMA_DIR", root / "events"), + ("DRIVER_SCHEMA_PATH", root / "driver-event.schema.json"), + ): + patcher = mock.patch.object(validate_event, name, value) + patcher.start() + self.addCleanup(patcher.stop) + validate_event._PER_TYPE_CACHE.clear() + validate_event._DRIVER_EVENT_TYPES_CACHE = None + validate_event._DRIVER_CORRELATION_PATTERNS_CACHE = validate_event._UNSET + self.addCleanup(validate_event._PER_TYPE_CACHE.clear) + self.addCleanup(setattr, validate_event, "_DRIVER_EVENT_TYPES_CACHE", None) + self.addCleanup(setattr, validate_event, + "_DRIVER_CORRELATION_PATTERNS_CACHE", validate_event._UNSET) + self.addCleanup(loop._PHASE_GATE_RESULTS.update, + {"baseline": [], "broad": []}) + validator = validate_event.load_validator() + wu = loop.WorkUnit( + wu_id="FEAT-LOOP-2026-9999/T01", file=Path("WU-01.md"), + depends_on=[], type="implementation", model="sonnet", + effort="medium", status="pending", attempts=1, title="T", + body="x") + wu.last_gate_results = [ + {"name": "g", "ok": True, "skipped": False, "duration_seconds": 0.5}, + {"name": "h", "ok": False, "skipped": True, "duration_seconds": 0}] + events = loop.build_attempt_gate_events(wu, 1) + events.append(loop.emit_attempt_outcome( + wu, 1, "passed", {"agent_seconds": 1.0, "verify_seconds": 0.5, + "duration_seconds": 2.0})) + loop._PHASE_GATE_RESULTS["broad"] = list(wu.last_gate_results) + events += loop.build_phase_gate_events("broad", "FEAT-LOOP-2026-9999") + for e in events: + self.assertEqual( + validate_event.validate_line( + validator, "t", 0, json.dumps(e)), [], e["event_type"]) + + +if __name__ == "__main__": + unittest.main()