From 3d099a84f81a374faa9af369bcabde35d04a48c2 Mon Sep 17 00:00:00 2001 From: Test Date: Thu, 26 Nov 2026 22:04:36 -0500 Subject: [PATCH 01/25] chore(loop): FEAT-LOOP-2026-0252 build pin recorded Feature: FEAT-LOOP-2026-0252 --- .specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl | 1 + 1 file changed, 1 insertion(+) create mode 100644 .specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl new file mode 100644 index 00000000..95a1c9f8 --- /dev/null +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl @@ -0,0 +1 @@ +{"timestamp": "2026-11-27T03:04:36.833200+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "driver_build_pinned", "source": "driver", "source_version": "0.33.2", "payload": {"tree": "922820b250ad2ee71f9f116122a255fa09797f8a", "path": "/private/var/folders/zc/rgq11x850d78dx_kf1fd4vx80000gn/T/specfuse-pins/922820b250ad2ee71f9f116122a255fa09797f8a/specfuse/loop"}} From d8ca9dac516c9e7d986c882ca6b9de1c384d004f Mon Sep 17 00:00:00 2001 From: Test Date: Thu, 26 Nov 2026 22:04:37 -0500 Subject: [PATCH 02/25] chore: scaffold feature FEAT-LOOP-2026-0252 --- .../GATE-01.md | 75 +++++++++++ .../FEAT-LOOP-2026-0252-run-progress/PLAN.md | 121 ++++++++++++++++++ .../WU-01-phase-events-and-status.md | 69 ++++++++++ .../WU-02-heartbeat.md | 54 ++++++++ .../WU-03-watch.md | 48 +++++++ .../WU-04-stop-notification-and-docs.md | 65 ++++++++++ .../WU-90-gate-1-close.md | 40 ++++++ .specfuse/roadmap.md | 14 ++ 8 files changed, 486 insertions(+) create mode 100644 .specfuse/features/FEAT-LOOP-2026-0252-run-progress/GATE-01.md create mode 100644 .specfuse/features/FEAT-LOOP-2026-0252-run-progress/PLAN.md create mode 100644 .specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-01-phase-events-and-status.md create mode 100644 .specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-02-heartbeat.md create mode 100644 .specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-03-watch.md create mode 100644 .specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-04-stop-notification-and-docs.md create mode 100644 .specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-90-gate-1-close.md diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/GATE-01.md b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/GATE-01.md new file mode 100644 index 00000000..7dab41c8 --- /dev/null +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/GATE-01.md @@ -0,0 +1,75 @@ +--- +gate: 1 +status: open +feature_oracle: "python3 -m unittest tests.test_run_progress -v -b" +cost_budget_usd: 18.00 +--- + +# Gate 1 — a running unit's progress is visible, and the operator is notified once when the run stops + +## Definition of done + +**Stated as an outcome.** In temporary feature folders, with a stubbed agent session and stub +gate commands, driven through `loop.run()`: + +1. **Phase events, written as they happen.** Each attempt appends `agent_session_started` and + `agent_session_finished` to `events.jsonl`, and each verification gate it runs appends + `gate_started` then `gate_finished` (payload: `attempt`, `gate`, and on `gate_finished` also + `ok` and `duration_seconds`). All four validate against the packaged + `driver-event.schema.json`. They are on disk while the attempt runs: the stubbed session + reads `events.jsonl` and finds its own `agent_session_started`, and a stub gate command finds + its own `gate_started`. +2. **Status file.** While a unit runs, `/work/STATUS.json` holds `feature`, `wu_id`, + `attempt`, `max_attempts`, `phase` (one of `agent`, `gate`, `between`, `stopped`), `gate` + (the running gate's name, else null), `started_at`, `updated_at`, `elapsed_seconds` and + `files_touched`. After `run()` returns, `phase` is `stopped` and `stop_reason` is set (see + clause 6). `git ls-files` never lists the file. +3. **Heartbeat.** With `defaults.heartbeat_seconds: 1`, a stubbed session that runs for 3 s and + writes one file sees `updated_at` advance at least twice during `phase: agent`, and + `files_touched` lists that file. After `run()` returns, also when it raises, no heartbeat + thread is alive. A missing, non-integer or non-positive `heartbeat_seconds` means 30. +4. **Plain driver lines.** The driver prints one line per phase change (session started and + finished, each gate started and finished with its result and duration). Driver output + contains no `\r` and no ANSI escape sequence. +5. **Watcher.** `specfuse-loop --watch [--feature F]` reads the status file and prints a line + naming the unit, attempt, phase, elapsed time and current gate. When stdout is not a + terminal it prints a line only when one of those changes. It prints `no update for Ns` when + `updated_at` is older than three heartbeat intervals. It exits 0 once `phase` is `stopped`, + and exits 1 with a message naming the expected path when no status file exists. +6. **Stop notification.** Each return from `run()` (and each exception out of it) sends exactly + one notification. Its `stop_reason` is `halted` when this run wrote a `human_escalation`, + else `awaiting_review` when it wrote `gate_reached` and the gate is `awaiting_review`, else + `complete` when `PLAN.md` is `done`, else `error` when `run()` raised, else `stopped`. The + message goes to `notify.post_notification` when a webhook is configured, and to + `escalation.notify_command` when set: run as an argument list (`shlex.split`, never a shell) + with `SPECFUSE_STOP_REASON`, `SPECFUSE_FEATURE`, `SPECFUSE_WORK_UNIT` and `SPECFUSE_MESSAGE` + in its environment and a 30 s timeout. A command that fails, hangs or does not exist is + logged and does not change `run()`'s exit code. With neither configured, or under + `--dry-run`, nothing is sent or run. The `agent-policy.yml` validator accepts a string + `escalation.notify_command` and reports an ERROR for any other type. +7. **Nothing else changes.** `dispatch()` and the `attempt_outcome` payload are unchanged. + Every existing test passes unchanged, apart from edits forced by the new driver lines being + picked up by a text-matching assertion; no such edit removes or weakens an assertion, and + each is named in the close. + +The `feature_oracle` proves 1–6. It is red on the current tree; `FEAT-LOOP-2026-0252/T01` is the +walking skeleton that creates `tests/test_run_progress.py` and turns clauses 1, 2 and 4 green, +with the other classes `unittest.skip` naming their owner (T02–T04). A skip surviving to the +close is a hollow oracle. + +## Arming discipline (see `.specfuse/rules/planning-discipline.md`) + +- **Live, not after the fact.** "Written as it happens" is asserted by the stub reading the + file during the attempt, never by comparing timestamps afterwards. +- **Counted, not inferred.** "Exactly one notification" is asserted by a call counter on the + poster and on a stub command, never by reading logs. +- **Positive controls.** Clause 6 pairs each configured channel with an unconfigured run; + clause 5 pairs a fresh status file with a stale one. +- **No reading chosen silently.** A unit that finds a clause above ambiguous blocks and names + the clause; it does not pick an interpretation. +- **Expected self-halt.** `loop.py` and `arm_eval.py` are judge surfaces; acknowledge the stop + with your own reason and `/unblock-wu`. + +## Reflection notes + + diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/PLAN.md b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/PLAN.md new file mode 100644 index 00000000..9fad9d16 --- /dev/null +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/PLAN.md @@ -0,0 +1,121 @@ +--- +feature_id: FEAT-LOOP-2026-0252 +title: Show a running unit's progress, and notify when the driver stops +slug: run-progress +branch: feat/FEAT-LOOP-2026-0252-run-progress +roadmap_goal: While `specfuse-loop` runs, an operator can see which unit, attempt, phase and verification gate is running and for how long, from the driver's terminal or a second one, and is notified once when the run stops. +autonomy_default: auto +status: active +planned_cost_usd: 14.50 +--- + +# Plan: Show a running unit's progress, and notify when the driver stops + +Between an attempt's start line and its outcome the driver prints nothing, and `events.jsonl` +gets `task_started` and then nothing until `attempt_outcome`: the agent session is one +blocking `claude -p --output-format json` call, a unit's events are buffered (`wu_events`, +`flush_events`) and `gate_result` events are written after the whole gate set. An operator +report measured a median attempt of 237 s and a maximum of 2265 s over 184 attempts, and 26 +runs that ended in `human_escalation` with nothing telling the operator. + +This feature writes phase events as they happen, keeps a live status file with a heartbeat, +adds a `--watch` reader, and sends one notification when the run stops. + +## Decisions (2026-11-26) + +The operator chose each of 1–6 from presented options and said "take your recommendations +for the rest" for 7 and 8. + +1. **All three asks in one feature:** phase events, a live view, a stop notification. They + share the same driver call sites, and the notification reuses `notify.py`. +2. **Phase changes in `events.jsonl`; heartbeats in a status file.** `agent_session_started`, + `agent_session_finished`, `gate_started` and `gate_finished` are appended to `events.jsonl` + when they happen (about 2 + 2×gates lines per attempt; `reset_preserving_events` already + keeps lines written mid-attempt). The heartbeat overwrites + `/work/STATUS.json`, which is under the gitignored `work/` and never committed. +3. **The agent session is not changed.** The heartbeat comes from a driver thread (elapsed + time, files touched via `_paths_differing_from`). `dispatch()`, its `--output-format json` + parse and the cost fields three guards depend on stay as they are. +4. **Both a plain driver line per phase change and a `--watch` reader.** The driver prints one + plain line per phase change (no `\r`, no ANSI); `specfuse-loop --watch` keeps a status line + current from another terminal. +5. **Stop notification through both channels.** Once per stop, when `run()` returns: the + existing webhook (`agent-policy.yml` `escalation.webhook_env` / `provider`) when configured, + and a new `escalation.notify_command` run as an argument list when configured. +6. **Autonomy `auto`.** A fresh judge writes the terminal verdict from evidence only. + `loop.py` and `arm_eval.py` are judge surfaces, so the terminal judge-editing stop fires + before the close: acknowledge it with your own reason and `/unblock-wu`. +7. **Heartbeat interval** *(recommendation applied):* 30 s, from `defaults.heartbeat_seconds` + in `verification.yml`, read the way `fail_fast_deliverables` is. +8. **One gate** *(recommendation applied):* four substantive units and a terminal `close` + (`docs/methodology.md` §6). + +**Out of scope:** streaming the agent session's output (`stream-json`, tool-call counts); a +`specfuse watch` alias in the umbrella CLI (another repository); a notification per event; +re-pinging; any change to `dispatch()` or to the `attempt_outcome` payload. + +## Existing-mechanism search (mandatory — see `.specfuse/rules/planning-discipline.md` §1) + +- **Grep command run:** `grep -n "notify\|post_notification\|heartbeat\|gate_result\|flush_events\|output-format" specfuse/loop/loop.py`; + `ls specfuse/loop/` (found `heartbeat.py`, `notify.py`, `notify_escalation.py`, + `notify_sla.py`); `grep -n "^escalation:" -A8 .specfuse/agent-policy.yml.example`. +- **Verdict:** reuse and extend. `notify.post_notification` (webhook, redaction, quiet hours) + is reused for the stop notification; `escalation` in `agent-policy.yml` gains one key. + `heartbeat.py` measures run-level silence from `events.jsonl` and is unrelated to a + heartbeat inside an attempt; it is not changed. `gate_result` (FEAT-LOOP-2026-0250) is + written after the gate set and stays; `gate_started` / `gate_finished` are the live + counterpart. No live progress surface or watch command exists. +- **If reusing:** the stop reason is derived from the events this run wrote, not from state + held in the process (LEARNINGS `[FEAT-LOOP-2026-0075/G2-CLOSE/...]`: rehydrate from the + durable log). + +## Escalation-predicate satisfiability (mandatory for any severity flip — §2) + +n/a — no check changes severity. + +## Task graph + +```yaml +gates: + - gate: 1 + file: GATE-01.md + work_units: + - id: FEAT-LOOP-2026-0252/T01 + file: WU-01-phase-events-and-status.md + depends_on: [] + - id: FEAT-LOOP-2026-0252/T02 + file: WU-02-heartbeat.md + depends_on: [FEAT-LOOP-2026-0252/T01] + - id: FEAT-LOOP-2026-0252/T03 + file: WU-03-watch.md + depends_on: [FEAT-LOOP-2026-0252/T01] + - id: FEAT-LOOP-2026-0252/T04 + file: WU-04-stop-notification-and-docs.md + depends_on: [FEAT-LOOP-2026-0252/T02, FEAT-LOOP-2026-0252/T03] + # --- closing sequence: single terminal close (single-gate feature) --- + - id: FEAT-LOOP-2026-0252/G1-CLOSE + file: WU-90-gate-1-close.md + depends_on: [FEAT-LOOP-2026-0252/T01, FEAT-LOOP-2026-0252/T02, FEAT-LOOP-2026-0252/T03, FEAT-LOOP-2026-0252/T04] +``` + +## Post-merge checklist + +- Run a real feature whose units take several minutes; confirm `specfuse-loop --watch` in a + second terminal shows the phase and gate changing and `files_touched` growing. +- Configure `escalation.notify_command` with a desktop notifier (for example + `terminal-notifier -message`) and confirm exactly one notification arrives when the run halts + and when it completes. +- With a chat webhook configured, confirm the stop message arrives once. + +## Notes + +- LEARNINGS `[FEAT-LOOP-2026-0251/T04]`: a unit that adds driver output runs every test module + that matches driver output text, not only its own. +- LEARNINGS `[FEAT-LOOP-2026-0250/T04]`: a unit that edits `docs/*.md` refreshes its packaged + copy under `specfuse/loop/data/docs/` in the same unit (`scripts/sync-scaffold.sh`). +- LEARNINGS `[FEAT-LOOP-2026-0250/T01]`: a test that validates events through `validate_event` + pins the packaged schemas and clears the validator caches. +- `produces:` lists only `.py` files under `tests/` (#3539). +- FEAT-LOOP-2026-0251 took seven closes because the definition of done left room for + interpretation. `GATE-01.md` states each clause as a checkable fact; a unit that finds a + clause ambiguous blocks and names it rather than choosing a reading. diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-01-phase-events-and-status.md b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-01-phase-events-and-status.md new file mode 100644 index 00000000..b9d35cb3 --- /dev/null +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-01-phase-events-and-status.md @@ -0,0 +1,69 @@ +--- +id: FEAT-LOOP-2026-0252/T01 +type: implementation +status: pending +attempts: 0 +planned_cost_usd: 2.50 +produces: + - specfuse/loop/progress.py + - specfuse/loop/loop.py + - specfuse/loop/arm_eval.py + - specfuse/loop/data/schemas/driver-event.schema.json + - tests/test_run_progress.py +produces_driver_helper: + - execute_unit_attempt + - _run_gate_set +model: sonnet +effort: medium +--- + +# T01 — walking skeleton: phase events, the status file and plain driver lines + +**Objective.** Make the gate's `feature_oracle` runnable and turn Definition-of-done clauses 1, +2 and 4 green. This is the tracer bullet: stubs are allowed here only. + +**Context.** `FEAT-LOOP-2026-0252/T01`; decisions 2 and 4 in `PLAN.md`. + +- Create `specfuse/loop/progress.py` with the status-file writer (atomic replace of + `/work/STATUS.json`) and one function per phase change that appends the event to + `events.jsonl` at once (one-event `flush_events`, not the `wu_events` buffer), rewrites the + status file, and prints the plain line. Register the module in `NON_JUDGE_MODULES` in + `specfuse/loop/arm_eval.py` ("reports progress; changes no verdict"). +- Call it from `loop.py`: around the agent session in `execute_unit_attempt()` (not inside + `dispatch()`, which stays unchanged), and around each gate command in `_run_gate_set()`. + Between units the phase is `between`; when `run()` returns it is `stopped` (T04 adds + `stop_reason`; here write `stop_reason: null`). +- Add `agent_session_started`, `agent_session_finished`, `gate_started` and `gate_finished` to + `specfuse/loop/data/schemas/driver-event.schema.json`, with a `$comment` line like the + existing ones. + +Create `tests/test_run_progress.py`, one class per clause: `TestPhaseEvents`, `TestStatusFile`, +`TestHeartbeat`, `TestDriverLines`, `TestWatch`, `TestStopNotification`. Implement the first +two and `TestDriverLines`; skip the rest naming T02, T03, T04. + +**Acceptance criteria.** + +1. `tests.test_run_progress.TestPhaseEvents` fails on HEAD and passes after. Through + `loop.run()` with a stubbed session and two stub gate commands, `events.jsonl` gains + `agent_session_started`, `agent_session_finished`, then `gate_started`/`gate_finished` for + each gate, in that order, each validating against the packaged schema. The stubbed session + finds its own `agent_session_started` in `events.jsonl` while it runs, and the second gate + command finds its own `gate_started`. +2. `TestStatusFile` passes: during the session the stub reads `STATUS.json` with every field + clause 2 names, `phase: agent` and `gate: null`; a stub gate reads `phase: gate` and its own + name; after `run()` returns, `phase` is `stopped`; `git ls-files` does not list the file. +3. `TestDriverLines` passes: captured driver output has one line per phase change and contains + no `\r` and no `\x1b`. +4. `python3 -m unittest tests.test_judge_path_registry tests.test_driver_event_registry_covers_emitters tests.test_validate_event_driver_types tests.test_gate_timings tests.test_dispatch_skeleton -b` + passes. Any existing test changed because it matches driver output text is listed in the + RESULT's notes. + +**Do not touch.** `dispatch()` and `parse_claude_json_output()`. The `attempt_outcome` payload +and `gate_result` events. The heartbeat thread (T02), `--watch` (T03), notification and docs +(T04). + +**Verification.** The narrow tier for `implementation`, plus AC4's command. + +**Escalation triggers.** If a phase event written mid-attempt is lost by a reset, or lands in +the unit's squash commit in a way a guard reads as the agent's own change, block with the +evidence rather than routing it through the `wu_events` buffer. diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-02-heartbeat.md b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-02-heartbeat.md new file mode 100644 index 00000000..87a3e930 --- /dev/null +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-02-heartbeat.md @@ -0,0 +1,54 @@ +--- +id: FEAT-LOOP-2026-0252/T02 +type: implementation +status: pending +attempts: 0 +planned_cost_usd: 2.50 +produces: + - specfuse/loop/progress.py + - specfuse/loop/loop.py + - .specfuse/verification.yml.example + - specfuse/loop/data/verification.yml.example + - tests/test_run_progress.py +produces_driver_helper: + - resolve_heartbeat_seconds +model: sonnet +effort: medium +--- + +# T02 — heartbeat while an attempt runs + +**Objective.** Turn Definition-of-done clause 3 green. + +**Context.** `FEAT-LOOP-2026-0252/T02`; decisions 3 and 7 in `PLAN.md`. + +- In `specfuse/loop/progress.py`, a daemon thread that rewrites `STATUS.json` every + `heartbeat_seconds` with `updated_at`, `elapsed_seconds` and `files_touched`. Files touched + come from `_paths_differing_from(head_before)` in `loop.py`, minus the driver's bookkeeping + (the unit file, `events.jsonl`, `PROGRESS.md` in the feature folder, by full path). +- Start it in `loop.py` when an attempt starts and stop it in a `finally`, so it never + outlives the attempt, including when the attempt raises. +- `resolve_heartbeat_seconds(verification_cfg)` next to `resolve_fail_fast_deliverables`: + `defaults.heartbeat_seconds`, 30 when missing, not an integer or not positive. Document the + key in `.specfuse/verification.yml.example` and `specfuse/loop/data/verification.yml.example`. + +**Acceptance criteria.** + +1. `tests.test_run_progress.TestHeartbeat` fails on HEAD and passes after (remove its skip). + With `defaults.heartbeat_seconds: 1`, a stubbed session that writes `notes/a.txt` and runs + for 3 s observes `updated_at` change at least twice while `phase` is `agent`, and + `files_touched` includes `notes/a.txt` and not `events.jsonl`. +2. After `run()` returns, and after an attempt whose stubbed session raises, no thread started + by `progress.py` is alive (`threading.enumerate()`). +3. `resolve_heartbeat_seconds` returns 30 for a missing key, `"x"`, `0` and `-5`, and 7 for `7`. +4. `python3 -m unittest tests.test_fail_fast_deliverables tests.test_dispatch_skeleton -b` + passes. + +**Do not touch.** `dispatch()`. Phase events (T01). `--watch` (T03). Notification and docs +under `docs/` (T04). + +**Verification.** The narrow tier for `implementation`, plus AC4's command. + +**Escalation triggers.** If `git` calls from the heartbeat thread contend with the driver's own +`git` calls (index lock errors), block with the evidence rather than adding a lock around +every driver `git` call. diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-03-watch.md b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-03-watch.md new file mode 100644 index 00000000..2bbb8eb9 --- /dev/null +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-03-watch.md @@ -0,0 +1,48 @@ +--- +id: FEAT-LOOP-2026-0252/T03 +type: implementation +status: pending +attempts: 0 +planned_cost_usd: 2.00 +produces: + - specfuse/loop/progress.py + - specfuse/loop/loop.py + - tests/test_run_progress.py +produces_driver_helper: + - main +model: sonnet +effort: medium +--- + +# T03 — `specfuse-loop --watch` + +**Objective.** Turn Definition-of-done clause 5 green. + +**Context.** `FEAT-LOOP-2026-0252/T03`; decision 4 in `PLAN.md`. + +- Add `--watch` to `main()` in `loop.py`; with `--feature` it resolves the feature as a run + does, without it it uses the single active feature. The reader lives in + `specfuse/loop/progress.py` and only reads files: it never takes the run lock and never + writes. +- On a terminal it redraws one line in place; when stdout is not a terminal it prints a line + only when the unit, attempt, phase or gate changes. Staleness is three heartbeat intervals + (`resolve_heartbeat_seconds`, T02). + +**Acceptance criteria.** + +1. `tests.test_run_progress.TestWatch` fails on HEAD and passes after (remove its skip). Given + a status file, the non-terminal output names the unit, attempt, phase, elapsed time and + gate; a rewrite that changes only `elapsed_seconds` prints nothing new, a phase change + prints one line. +2. An `updated_at` older than three heartbeat intervals prints `no update for Ns`. +3. `phase: stopped` ends the watch with exit 0; no status file exits 1 with a message naming + the expected path. +4. `python3 -m unittest tests.test_dispatch_skeleton -b` passes. + +**Do not touch.** `dispatch()`. Phase events and the status file's fields (T01). The heartbeat +thread (T02). Notification and docs (T04). + +**Verification.** The narrow tier for `implementation`, plus AC4's command. + +**Escalation triggers.** If `--watch` cannot be added without changing how `--feature` resolves +for a run, block rather than changing run resolution. diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-04-stop-notification-and-docs.md b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-04-stop-notification-and-docs.md new file mode 100644 index 00000000..c9c73820 --- /dev/null +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-04-stop-notification-and-docs.md @@ -0,0 +1,65 @@ +--- +id: FEAT-LOOP-2026-0252/T04 +type: implementation +status: pending +attempts: 0 +planned_cost_usd: 2.50 +produces: + - specfuse/loop/progress.py + - specfuse/loop/loop.py + - specfuse/loop/agent_policy.py + - .specfuse/agent-policy.yml.example + - docs/getting-started.md + - specfuse/loop/data/docs/getting-started.md + - tests/test_run_progress.py +produces_driver_helper: + - main +model: sonnet +effort: medium +--- + +# T04 — one notification when the run stops, and the docs + +**Objective.** Turn Definition-of-done clause 6 green and document the feature. + +**Context.** `FEAT-LOOP-2026-0252/T04`; decision 5 in `PLAN.md`. + +- In `specfuse/loop/progress.py`, `notify_stop(...)`: work out `stop_reason` from the events + this run appended to `events.jsonl` (remember the file's size when `run()` starts) and + `PLAN.md`, in the order clause 6 gives; write it to `STATUS.json`; send the message once + through `notify.post_notification` and once through `escalation.notify_command`, each only + when configured. +- The command runs as `subprocess.run(shlex.split(cmd), env=..., timeout=30)`, never + `shell=True`. The message is passed only in `SPECFUSE_MESSAGE`, never on the command line. + Every failure (non-zero exit, timeout, missing program) is logged and swallowed. +- Call it from `main()` in `loop.py` in a `finally` around `run()`, skipped under `--dry-run` + and `--watch`. +- In `specfuse/loop/agent_policy.py`, add `notify_command` to the known `escalation` keys: + optional, a string. Add it to `.specfuse/agent-policy.yml.example` with a comment and a + desktop-notifier example. +- In `docs/getting-started.md`, document the driver's phase lines, `--watch`, the status file, + `defaults.heartbeat_seconds` and the stop notification; refresh the packaged copy + `specfuse/loop/data/docs/getting-started.md` with `scripts/sync-scaffold.sh`. + +**Acceptance criteria.** + +1. `tests.test_run_progress.TestStopNotification` fails on HEAD and passes after (remove its + skip). Each of the five stop reasons is produced by a run that reaches it, with a counting + stub poster and a stub command each called exactly once, and the command receiving the four + `SPECFUSE_*` variables. +2. A command that exits 1, one that sleeps past the timeout (patched to 1 s in the test) and + one naming a missing program each leave `run()`'s exit code unchanged. With neither channel + configured, and under `--dry-run`, the poster and the command are called zero times. +3. A message containing `; touch pwned` does not create `pwned`. +4. `python3 -m unittest tests.test_agent_policy_schema tests.test_notify tests.test_notify_escalation -b` + passes; `agent_policy`'s validator accepts a string `notify_command` and reports an ERROR for + a list. +5. `tests.test_run_progress` has no `unittest.skip` left. + +**Do not touch.** `dispatch()`. `notify.py`'s existing behaviour. Phase events (T01), the +heartbeat (T02), `--watch` (T03), except to call `notify_stop`. + +**Verification.** The narrow tier for `implementation`, plus AC4's command. + +**Escalation triggers.** If two stop reasons apply to one run in a way clause 6's order does +not settle, block and name the case rather than choosing. diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-90-gate-1-close.md b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-90-gate-1-close.md new file mode 100644 index 00000000..bbfd8d8d --- /dev/null +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-90-gate-1-close.md @@ -0,0 +1,40 @@ +--- +id: FEAT-LOOP-2026-0252/G1-CLOSE +type: close +status: pending +attempts: 0 +planned_cost_usd: 5.00 +auto_close_disabled: true +model: sonnet +effort: high +--- + +# G1-CLOSE — terminal close + +**Context.** The feature's only gate: phase events written as they happen, a status file with +a heartbeat, plain driver lines, `specfuse-loop --watch`, and one notification when the run +stops. + +**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_run_progress.py`. It + lists every pre-existing test that was changed (clause 7), with why. +2. Each consumer-visible change (phase events and driver lines, the status file and + `defaults.heartbeat_seconds`, `--watch`, the stop notification and + `escalation.notify_command`) is written with + `python3 -m specfuse.loop.changelog_fragments add`, tracing to `FEAT-LOOP-2026-0252`. +3. A `## Cost analysis` reconciles every unit against `planned_cost_usd` and `events.jsonl`. +4. "What the loop did NOT verify" names, at minimum: real desktop and chat delivery (stubs + only), a real multi-minute attempt watched live, and a real driver crash (exceptions are + simulated). Each points at `PLAN.md`'s post-merge checklist. +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, a notification sent more or fewer than once per stop +in any test, or a change to `dispatch()` or the `attempt_outcome` payload: record `not_met` with +a follow-up. diff --git a/.specfuse/roadmap.md b/.specfuse/roadmap.md index d3fa9eca..5a7aaabe 100644 --- a/.specfuse/roadmap.md +++ b/.specfuse/roadmap.md @@ -130,6 +130,7 @@ installation a target project copies via `init.sh`. | 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) | | FEAT-LOOP-2026-0251 | Refuse a missing deliverable before the verification gates run | done | `.specfuse/features/FEAT-LOOP-2026-0251-fail-fast-deliverables/` | [→ archive](roadmap-archive.md#feat-loop-2026-0251) | +| FEAT-LOOP-2026-0252 | Show a running unit's progress, and notify when the driver stops | active | `.specfuse/features/FEAT-LOOP-2026-0252-run-progress/` | [→ detail](#feat-loop-2026-0252) | Status: `planned` → `active` → `done` (or `abandoned`). `deferred` = parked by choice pending an external decision/dependency; resumable (a human flips it @@ -1060,6 +1061,19 @@ So the question is no longer "how do we distil lessons" — that is built and lo **Status: planned.** + +## FEAT-LOOP-2026-0252 — Show a running unit's progress, and notify when the driver stops + +**Why.** Between an attempt's start line and its outcome the driver prints nothing and writes nothing to `events.jsonl`: the agent session is one blocking call, a unit's events are buffered, and gate results are written after the whole gate set. An operator report measured a median attempt of 237 s and a maximum of 2265 s over 184 attempts, and 26 runs that halted for a human with nothing telling the operator. + +**Goal.** Phase events (`agent_session_started`/`_finished`, `gate_started`/`_finished`) appended to `events.jsonl` as they happen; a live `/work/STATUS.json` with a heartbeat (`defaults.heartbeat_seconds`, default 30) carrying unit, attempt, phase, gate, elapsed time and files touched; one plain driver line per phase change; `specfuse-loop --watch` to follow a run from another terminal; and exactly one notification when `run()` returns, through the existing webhook and a new `escalation.notify_command`. + +**Shape.** One gate, four implementation units and a terminal close; `auto`. + +**Out of scope.** Streaming the agent session's output (tool-call counts), a `specfuse watch` alias in the umbrella CLI, a notification per event, re-pinging, and any change to `dispatch()` or the `attempt_outcome` payload. + +**Status: active.** + ## Notes - Correlation IDs are allocated here, sequentially per year: `FEAT-YYYY-NNNN`. From 21356293d4cae452b3e32986c74089d4e0b9b68d Mon Sep 17 00:00:00 2001 From: Test Date: Thu, 26 Nov 2026 22:04:41 -0500 Subject: [PATCH 03/25] chore(loop): FEAT-LOOP-2026-0252 build pin recorded Feature: FEAT-LOOP-2026-0252 --- .specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl | 1 + 1 file changed, 1 insertion(+) diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl index 95a1c9f8..3115a592 100644 --- a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl @@ -1 +1,2 @@ {"timestamp": "2026-11-27T03:04:36.833200+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "driver_build_pinned", "source": "driver", "source_version": "0.33.2", "payload": {"tree": "922820b250ad2ee71f9f116122a255fa09797f8a", "path": "/private/var/folders/zc/rgq11x850d78dx_kf1fd4vx80000gn/T/specfuse-pins/922820b250ad2ee71f9f116122a255fa09797f8a/specfuse/loop"}} +{"timestamp": "2026-11-27T03:04:41.819293+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "driver_build_pinned", "source": "driver", "source_version": "0.33.2", "payload": {"tree": "f903f87239abf0c7dc90999ff3c7c79c295c30a4", "path": "/private/var/folders/zc/rgq11x850d78dx_kf1fd4vx80000gn/T/specfuse-pins/f903f87239abf0c7dc90999ff3c7c79c295c30a4/specfuse/loop"}} From dff8414ce3e841c7fbaa20253448c0cc4196f26f Mon Sep 17 00:00:00 2001 From: Test Date: Thu, 26 Nov 2026 22:04:41 -0500 Subject: [PATCH 04/25] chore(loop): FEAT-LOOP-2026-0252 plan baseline snapshot Feature: FEAT-LOOP-2026-0252 --- .../PLAN.baseline.json | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 .specfuse/features/FEAT-LOOP-2026-0252-run-progress/PLAN.baseline.json diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/PLAN.baseline.json b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/PLAN.baseline.json new file mode 100644 index 00000000..2fef2d0c --- /dev/null +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/PLAN.baseline.json @@ -0,0 +1,39 @@ +{ + "gates": [ + { + "gate": 1, + "work_units": [ + { + "goal": "T01 \u2014 walking skeleton: phase events, the status file and plain driver lines", + "id": "FEAT-LOOP-2026-0252/T01", + "planned_cost_usd": 2.5, + "type": "implementation" + }, + { + "goal": "T02 \u2014 heartbeat while an attempt runs", + "id": "FEAT-LOOP-2026-0252/T02", + "planned_cost_usd": 2.5, + "type": "implementation" + }, + { + "goal": "T03 \u2014 `specfuse-loop --watch`", + "id": "FEAT-LOOP-2026-0252/T03", + "planned_cost_usd": 2.0, + "type": "implementation" + }, + { + "goal": "T04 \u2014 one notification when the run stops, and the docs", + "id": "FEAT-LOOP-2026-0252/T04", + "planned_cost_usd": 2.5, + "type": "implementation" + }, + { + "goal": "G1-CLOSE \u2014 terminal close", + "id": "FEAT-LOOP-2026-0252/G1-CLOSE", + "planned_cost_usd": 5.0, + "type": "close" + } + ] + } + ] +} From c01e0da9da316efa8102ca77b52f90913bb930e9 Mon Sep 17 00:00:00 2001 From: Test Date: Thu, 26 Nov 2026 22:12:48 -0500 Subject: [PATCH 05/25] =?UTF-8?q?feat:=20T01=20=E2=80=94=20walking=20skele?= =?UTF-8?q?ton:=20phase=20events,=20the=20status=20file=20and=20plain=20dr?= =?UTF-8?q?iver=20lines?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Feature: FEAT-LOOP-2026-0252/T01 --- .../PROGRESS.md | 2 + .../WU-01-phase-events-and-status.md | 11 +- specfuse/loop/arm_eval.py | 1 + .../data/schemas/driver-event.schema.json | 8 +- specfuse/loop/loop.py | 37 +- specfuse/loop/progress.py | 205 +++++++++++ tests/test_run_progress.py | 326 ++++++++++++++++++ 7 files changed, 580 insertions(+), 10 deletions(-) create mode 100644 .specfuse/features/FEAT-LOOP-2026-0252-run-progress/PROGRESS.md create mode 100644 specfuse/loop/progress.py create mode 100644 tests/test_run_progress.py diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/PROGRESS.md b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/PROGRESS.md new file mode 100644 index 00000000..c7acd60d --- /dev/null +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/PROGRESS.md @@ -0,0 +1,2 @@ +- **FEAT-LOOP-2026-0252/T01**: Added specfuse/loop/progress.py and wired it into loop.py, so phase events are appended as they happen, work/STATUS.json tracks the phase, and each session or gate change prints one plain line; four event types registered in the packaged schema. + - note: T02 should fill files_touched (always [] now) inside progress._rewrite_status, and its thread will share the module-global _run with the main thread, so status writes need a lock (the temp file name is per process, not per thread). diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-01-phase-events-and-status.md b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-01-phase-events-and-status.md index b9d35cb3..747daee4 100644 --- a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-01-phase-events-and-status.md +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-01-phase-events-and-status.md @@ -1,8 +1,8 @@ --- id: FEAT-LOOP-2026-0252/T01 type: implementation -status: pending -attempts: 0 +status: done +attempts: 1 planned_cost_usd: 2.50 produces: - specfuse/loop/progress.py @@ -15,6 +15,13 @@ produces_driver_helper: - _run_gate_set model: sonnet effort: medium +gate_set: code +driver_version: 0.33.2 +started_at: 2026-11-27T03:04:42.096854+00:00 +duration_seconds: 486.578 +cost_usd: 1.274903 +input_tokens: 46 +output_tokens: 29228 --- # T01 — walking skeleton: phase events, the status file and plain driver lines diff --git a/specfuse/loop/arm_eval.py b/specfuse/loop/arm_eval.py index 2c1abc95..bb0954b6 100644 --- a/specfuse/loop/arm_eval.py +++ b/specfuse/loop/arm_eval.py @@ -169,6 +169,7 @@ "notify_sla.py": "as notify.py", "policy_proposals.py": "drafts policy changes for a human to accept", "policy_review.py": "presents proposals; the human decides", + "progress.py": "reports progress; changes no verdict", "promotion.py": "records which triaged feature issues became roadmap rows " "and reports the backlog awaiting a decision; a human-facing count, " "read by no gate, merge, arm or close verdict. Distinct from " diff --git a/specfuse/loop/data/schemas/driver-event.schema.json b/specfuse/loop/data/schemas/driver-event.schema.json index e5437782..e5d9e165 100644 --- a/specfuse/loop/data/schemas/driver-event.schema.json +++ b/specfuse/loop/data/schemas/driver-event.schema.json @@ -3,7 +3,7 @@ "$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. 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.", + "$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. FEAT-LOOP-2026-0252/T01: agent_session_started, agent_session_finished, gate_started and gate_finished added — appended when the phase changes, not buffered with the unit's events. Each carries the attempt (null outside an attempt, e.g. the broad run); the gate events also carry the gate, and gate_finished carries ok and duration_seconds. gate_started / gate_finished are the live counterpart of gate_result, which stays.", "event_types": [ "attempt_outcome", "gate_result", @@ -24,7 +24,11 @@ "replan", "fix_unit_inserted", "terminal_judge_editing_evaluated", - "terminal_judge_editing_acknowledged" + "terminal_judge_editing_acknowledged", + "agent_session_started", + "agent_session_finished", + "gate_started", + "gate_finished" ], "correlation_id": { "closing_names": [ diff --git a/specfuse/loop/loop.py b/specfuse/loop/loop.py index 97a57bf5..67988787 100644 --- a/specfuse/loop/loop.py +++ b/specfuse/loop/loop.py @@ -66,6 +66,7 @@ from . import _miniyaml from . import _wu_sections from . import criteria_state +from . import progress as _progress from . import ids as _ids from . import scaffold as _scaffold from .changelog import ENTRY_CLASSES @@ -5240,6 +5241,14 @@ def _untracked_file_blocks(max_chars: int) -> str: return "".join(blocks) +#: The driver appends phase events to a feature's log while an attempt runs +#: (FEAT-LOOP-2026-0252). A captured attempt diff leaves those logs out: the +#: lines are not the agent's work, and replaying their hunk over the preserved +#: log (`apply_diff`) would not apply. +_DRIVER_EVENT_LOGS_EXCLUDE = ( + f":(top,exclude,glob){FEATURES_DIR.as_posix()}/*/events.jsonl") + + def capture_working_tree_diff(head_before: str, max_chars: int = 20000) -> str: """Return the working tree's departure from `head_before`, capped. @@ -5260,7 +5269,8 @@ def capture_working_tree_diff(head_before: str, max_chars: int = 20000) -> str: """ try: out = subprocess.run( - ["git", "diff", head_before], + ["git", "diff", head_before, "--", ":(top)", + _DRIVER_EVENT_LOGS_EXCLUDE], capture_output=True, text=True, check=True, ).stdout except (subprocess.CalledProcessError, OSError): @@ -7132,6 +7142,7 @@ def _run_gate_set( else: popen_argv = command popen_kwargs = dict(shell=True) # nosec B604 + _progress.gate_started(gate["name"]) gate_started = time.monotonic() proc = subprocess.Popen( # nosec B602 popen_argv, stdin=subprocess.DEVNULL, @@ -7176,6 +7187,7 @@ def _run_gate_set( f"or a wedged subprocess)." ] gate_duration = round(time.monotonic() - gate_started, 3) + _progress.gate_finished(gate["name"], ok, gate_duration) if not ok: failed_names.add(gate["name"]) log_path = persist_gate_output(feature_dir, gate["name"], out) @@ -8726,11 +8738,15 @@ def execute_unit_attempt( worklist_section = format_reverification_worklist(wu, feature_dir) if worklist_section: wu.body = wu.body + "\n\n" + worklist_section + _progress.agent_session_started() _agent_t0 = time.monotonic() - if dispatch_fn is None: - result = dispatch(wu, failure_note, cost_tracking) - else: - result = dispatch_fn(wu, failure_note) + try: + if dispatch_fn is None: + result = dispatch(wu, failure_note, cost_tracking) + else: + result = dispatch_fn(wu, failure_note) + finally: + _progress.agent_session_finished() agent_seconds = time.monotonic() - _agent_t0 if isinstance(result, tuple): stdout, usage = result @@ -12490,6 +12506,10 @@ def run( return 1 try: + if not dry_run: + _progress.begin_run( + feature_id, feature_dir, events_path, + build_event=build_event, flush_events=flush_events) # Per-project cost-tracking toggle (top-level key in verification.yml, # default True). When True, the driver records cumulative cost / tokens @@ -12610,6 +12630,7 @@ def run( if not pending: break for wu in pending: # sequential v1; the frontier is independent -> fan-out later + _progress.clear_unit() # Per-gate cost budget brake — halt-between-WUs. # Mirrors MAX_ATTEMPTS' shape (a brake, not an estimator). Fires # before the next WU's set_wu(in_progress) so an in-progress WU @@ -13116,6 +13137,7 @@ def run( # What a kept earlier attempt left on disk, so this # attempt's retry note lists only its own changes (#3612). tree_before = snapshot_dirty_tree(head_before) + _progress.begin_attempt(wu.wu_id, attempt, wu_max_attempts) t0 = time.monotonic() wu.last_gate_results = [] outcome, payload, usage = execute_unit_attempt( @@ -13146,7 +13168,7 @@ def run( # as an untouched tree (FEAT-LOOP-2026-0251). _refusal_touched = git_diff_names( head_before, "HEAD", worktree=True, - exclude=(wu.file,)) + exclude=(wu.file, events_path)) if outcome == "zero_token": # Agent never produced output (input_tokens=0). Skip @@ -14601,6 +14623,9 @@ def run( ) return 1 finally: + # Before the lock is released, so no second driver's status is + # overwritten. + _progress.end_run() if lock_fd is not None: lock_fd.close() diff --git a/specfuse/loop/progress.py b/specfuse/loop/progress.py new file mode 100644 index 00000000..78af7bb6 --- /dev/null +++ b/specfuse/loop/progress.py @@ -0,0 +1,205 @@ +# +# Copyright 2026 Specfuse contributors +# Licensed under the Apache License, Version 2.0. See LICENSE. +# +"""Live progress of a running driver (FEAT-LOOP-2026-0252). + +One function per phase change. Each appends its event to `events.jsonl` at +once (never through a unit's buffered `wu_events`), rewrites the status file +`/work/STATUS.json`, and prints one plain line: no carriage return, +no ANSI. + +Every function is a no-op unless `begin_run` was called, so a caller that runs +a gate set or an attempt outside `run()` writes nothing. + +`build_event` and `flush_events` are passed in by the driver: it imports this +module, so this module does not import it. + +Reports only; no merge, arm or close verdict reads anything written here. +""" + +from __future__ import annotations + +import datetime as dt +import json +import os +import time +from dataclasses import dataclass +from pathlib import Path +from typing import Callable + +STATUS_FILENAME = "STATUS.json" + +PHASE_AGENT = "agent" +PHASE_GATE = "gate" +PHASE_BETWEEN = "between" +PHASE_STOPPED = "stopped" + +# `work/` is gitignored by the scaffold. This keeps the status file out of git +# in a project whose ignore rules do not cover it, and ignores nothing else. +_WORK_IGNORE = f"/.gitignore\n/{STATUS_FILENAME}*\n" + + +@dataclass +class _Run: + feature: str + feature_dir: Path + events_path: Path + build_event: Callable + flush_events: Callable + wu_id: "str | None" = None + attempt: "int | None" = None + max_attempts: "int | None" = None + phase: str = PHASE_BETWEEN + gate: "str | None" = None + started_at: str = "" + started_clock: float = 0.0 + agent_clock: float = 0.0 + + +_run: "_Run | None" = None + + +def _now() -> str: + return dt.datetime.now(dt.timezone.utc).isoformat() + + +def _restart_clock(run: _Run) -> None: + run.started_at = _now() + run.started_clock = time.monotonic() + + +def status_path(feature_dir: Path) -> Path: + return Path(feature_dir) / "work" / STATUS_FILENAME + + +def write_status(feature_dir: Path, status: dict) -> None: + """Replace the status file atomically. A write failure is swallowed: + progress reporting never fails a run.""" + path = status_path(feature_dir) + try: + path.parent.mkdir(parents=True, exist_ok=True) + ignore = path.parent / ".gitignore" + if not ignore.exists(): + ignore.write_text(_WORK_IGNORE, encoding="utf-8") + tmp = path.with_name(f"{STATUS_FILENAME}.{os.getpid()}.tmp") + tmp.write_text(json.dumps(status) + "\n", encoding="utf-8") + os.replace(tmp, path) + except OSError: + pass + + +def _rewrite_status(stop_reason: "str | None" = None) -> None: + run = _run + write_status(run.feature_dir, { + "feature": run.feature, + "wu_id": run.wu_id, + "attempt": run.attempt, + "max_attempts": run.max_attempts, + "phase": run.phase, + "gate": run.gate, + "started_at": run.started_at, + "updated_at": _now(), + "elapsed_seconds": round(time.monotonic() - run.started_clock, 3), + "files_touched": [], + "stop_reason": stop_reason, + }) + + +def _append_event(event_type: str, payload: dict) -> None: + run = _run + run.flush_events(run.events_path, [run.build_event( + event_type, run.wu_id or run.feature, payload)]) + + +def _say(text: str) -> None: + plain = "".join(c if c.isprintable() else " " for c in text) + print(f" [{time.strftime('%H:%M:%S')}] {plain}", flush=True) + + +def begin_run( + feature: str, feature_dir: Path, events_path: Path, *, + build_event: Callable, flush_events: Callable, +) -> None: + global _run + _run = _Run(feature, Path(feature_dir), Path(events_path), + build_event, flush_events) + _restart_clock(_run) + + +def end_run(stop_reason: "str | None" = None) -> None: + """Mark the run stopped. A run that never reached a unit writes the status + file too, so a reader never sees an earlier run's live phase.""" + global _run + if _run is None: + return + _run.phase = PHASE_STOPPED + _run.gate = None + _rewrite_status(stop_reason) + _run = None + + +def begin_attempt(wu_id: str, attempt: int, max_attempts: int) -> None: + if _run is None: + return + _run.wu_id = wu_id + _run.attempt = attempt + _run.max_attempts = max_attempts + _run.phase = PHASE_BETWEEN + _run.gate = None + _restart_clock(_run) + _rewrite_status() + + +def clear_unit() -> None: + """No unit is running: gates run from here belong to the feature.""" + if _run is None or _run.wu_id is None: + return + _run.wu_id = _run.attempt = _run.max_attempts = None + _run.phase = PHASE_BETWEEN + _run.gate = None + _restart_clock(_run) + _rewrite_status() + + +def agent_session_started() -> None: + if _run is None: + return + _run.phase = PHASE_AGENT + _run.gate = None + _run.agent_clock = time.monotonic() + _rewrite_status() + _append_event("agent_session_started", {"attempt": _run.attempt}) + _say("agent session started") + + +def agent_session_finished() -> None: + if _run is None: + return + seconds = time.monotonic() - _run.agent_clock + _run.phase = PHASE_BETWEEN + _rewrite_status() + _append_event("agent_session_finished", {"attempt": _run.attempt}) + _say(f"agent session finished ({seconds:.1f}s)") + + +def gate_started(name: str) -> None: + if _run is None: + return + _run.phase = PHASE_GATE + _run.gate = name + _rewrite_status() + _append_event("gate_started", {"attempt": _run.attempt, "gate": name}) + _say(f"gate {name} started") + + +def gate_finished(name: str, ok: bool, duration_seconds: float) -> None: + if _run is None: + return + _run.phase = PHASE_BETWEEN + _run.gate = None + _rewrite_status() + _append_event("gate_finished", { + "attempt": _run.attempt, "gate": name, "ok": bool(ok), + "duration_seconds": duration_seconds}) + _say(f"gate {name} {'PASS' if ok else 'FAIL'} ({duration_seconds:.1f}s)") diff --git a/tests/test_run_progress.py b/tests/test_run_progress.py new file mode 100644 index 00000000..2b09089e --- /dev/null +++ b/tests/test_run_progress.py @@ -0,0 +1,326 @@ +# +# Copyright 2026 Specfuse contributors +# Licensed under the Apache License, Version 2.0. See LICENSE. +# +"""FEAT-LOOP-2026-0252 gate 1 oracle — a running unit's progress is visible. +One class per Definition-of-done clause in GATE-01.md. T01 implements clauses +1, 2 and 4; the rest are skipped naming their owning unit. + +Every run goes through `loop.run()` in a temporary repository, with a stubbed +agent session and two real stub gate commands. What must be on disk while the +attempt runs is read from inside the attempt, never compared afterwards. +""" + +from __future__ import annotations + +import contextlib +import importlib.resources +import io +import json +import os +import re +import subprocess +import tempfile +import unittest +from pathlib import Path +from unittest import mock + +from specfuse.loop import validate_event +from tests._loop_loader import load_loop +from tests._workspace import integration_workspace, write_stub_deliverable + +loop = load_loop() + +FEATURE_ID = "FEAT-LOOP-2026-9999" +WU_ID = f"{FEATURE_ID}/T01" +SLUG = "run-progress-fixture" +STATUS_FIELDS = { + "feature", "wu_id", "attempt", "max_attempts", "phase", "gate", + "started_at", "updated_at", "elapsed_seconds", "files_touched", +} +PHASE_TYPES = ( + "agent_session_started", "agent_session_finished", + "gate_started", "gate_finished", +) + +_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" +) + + +def _read_events(path: Path) -> list: + return [json.loads(ln) for ln in path.read_text().splitlines() if ln] + + +def _scaffold(root: Path, snapshots: Path) -> Path: + """One gate, one implementation unit, gates `alpha` and `beta`. Each gate + copies the status file it sees to *snapshots*; `beta` also fails unless + its own `gate_started` is already in the event log.""" + own_event = '"gate_started".*"gate": "beta"' + gates = [ + ("alpha", f"cp {{feature_dir}}/work/STATUS.json {snapshots}/alpha.json"), + ("beta", f"cp {{feature_dir}}/work/STATUS.json {snapshots}/beta.json " + f"&& grep -q '{own_event}' {{feature_dir}}/events.jsonl"), + ] + code = "".join( + f" - name: {name}\n command: {json.dumps(cmd)}\n" + for name, cmd in gates) + (root / ".specfuse/verification.yml").write_text( + f"code:\n{code}" + "doc:\n - name: noop\n command: \"true\"\n" + "plannext:\n - name: noop\n command: \"true\"\n") + (root / ".gitignore").write_text(".specfuse/.loop.lock\n") + + fdir = root / ".specfuse" / "features" / f"{FEATURE_ID}-{SLUG}" + fdir.mkdir(parents=True) + (fdir / "PLAN.md").write_text( + f"---\nfeature_id: {FEATURE_ID}\ntitle: Progress\nslug: {SLUG}\n" + f"branch: feat/{SLUG}\nroadmap_goal: exercise run progress\n" + "status: active\n---\n\n# Plan\n\n```yaml\ngates:\n" + " - gate: 1\n file: GATE-01.md\n work_units:\n" + f" - id: {WU_ID}\n file: WU-T01.md\n" + " depends_on: []\n```\n") + (fdir / "GATE-01.md").write_text( + "---\ngate: 1\nstatus: open\n---\n\n# Gate 1\n") + (fdir / "WU-T01.md").write_text( + f"---\nid: {WU_ID}\ntype: implementation\n" + "model: claude-haiku-4-5-20251001\nstatus: pending\nattempts: 0\n" + f"max_attempts: 1\n---\n\n# T01{_BODY}") + subprocess.run(["git", "-C", str(root), "add", "."], check=True) + subprocess.run(["git", "-C", str(root), "commit", "-q", "-m", "fixture"], + check=True) + return fdir + + +class _Observed: + """One `loop.run()` and everything seen during and after it.""" + + def __init__(self): + with integration_workspace() as root, \ + tempfile.TemporaryDirectory() as snapshots: + cwd = os.getcwd() + os.chdir(root) + try: + self._run(root, Path(snapshots)) + finally: + os.chdir(cwd) + + def _run(self, root: Path, snapshots: Path) -> None: + fdir = _scaffold(root, snapshots) + rel = fdir.relative_to(root) + + def session(wu, failure_note, cost_tracking=True): + self.events_in_session = _read_events(rel / "events.jsonl") + self.status_in_session = json.loads( + (rel / "work" / "STATUS.json").read_text()) + write_stub_deliverable(wu) + return "```result\nstatus: complete\n```\n" + + out = io.StringIO() + with mock.patch.object(loop, "dispatch", session), \ + contextlib.redirect_stdout(out): + self.rc = loop.run(None, dry_run=False) + self.output = out.getvalue() + self.events = _read_events(rel / "events.jsonl") + self.status_after = json.loads( + (rel / "work" / "STATUS.json").read_text()) + self.gate_status = { + name: json.loads((snapshots / f"{name}.json").read_text()) + for name in ("alpha", "beta") + } + self.tracked = subprocess.run( + ["git", "ls-files"], capture_output=True, text=True, + check=True).stdout.splitlines() + + +class _ObservedRun(unittest.TestCase): + + @classmethod + def setUpClass(cls): + cls.run_seen = _Observed() + + +class TestPhaseEvents(_ObservedRun): + """Clause 1 — phase events, written as they happen.""" + + def _phase_events(self): + return [e for e in self.run_seen.events + if e["event_type"] in PHASE_TYPES] + + def test_attempt_passes(self): + self.assertEqual(self.run_seen.rc, 0, self.run_seen.output) + outcomes = [e["payload"]["outcome"] for e in self.run_seen.events + if e["event_type"] == "attempt_outcome"] + self.assertEqual(outcomes, ["passed"], self.run_seen.output) + + def test_order_and_payloads(self): + seen = [(e["event_type"], e["payload"].get("gate")) + for e in self._phase_events()] + self.assertEqual(seen, [ + ("agent_session_started", None), + ("agent_session_finished", None), + ("gate_started", "alpha"), ("gate_finished", "alpha"), + ("gate_started", "beta"), ("gate_finished", "beta"), + ]) + for event in self._phase_events(): + self.assertEqual(event["correlation_id"], WU_ID) + self.assertEqual(event["payload"]["attempt"], 1) + if event["event_type"] == "gate_finished": + self.assertEqual( + set(event["payload"]), + {"attempt", "gate", "ok", "duration_seconds"}) + self.assertIs(event["payload"]["ok"], True) + self.assertGreaterEqual(event["payload"]["duration_seconds"], 0) + + def test_events_validate_against_the_packaged_schemas(self): + 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) + + def clear_caches(): + validate_event._PER_TYPE_CACHE.clear() + validate_event._DRIVER_EVENT_TYPES_CACHE = None + validate_event._DRIVER_CORRELATION_PATTERNS_CACHE = \ + validate_event._UNSET + + clear_caches() + self.addCleanup(clear_caches) + validator = validate_event.load_validator() + events = self._phase_events() + self.assertEqual({e["event_type"] for e in events}, set(PHASE_TYPES)) + for event in events: + self.assertEqual( + validate_event.validate_line( + validator, "events.jsonl", 1, json.dumps(event)), []) + + def test_session_start_is_on_disk_while_the_session_runs(self): + types = [e["event_type"] for e in self.run_seen.events_in_session] + self.assertIn("agent_session_started", types) + self.assertNotIn("agent_session_finished", types) + + def test_gate_start_is_on_disk_while_the_gate_runs(self): + # `beta` exits non-zero unless its own gate_started is in the log. + results = {e["payload"]["gate"]: e["payload"]["ok"] + for e in self._phase_events() + if e["event_type"] == "gate_finished"} + self.assertIs(results.get("beta"), True, self.run_seen.output) + + def test_captured_attempt_diff_leaves_out_the_driver_event_log(self): + # A replayed best-attempt diff carrying the log's hunk would not apply + # over the preserved log. An agent's own events.jsonl stays in. + with integration_workspace() as root: + cwd = os.getcwd() + os.chdir(root) + self.addCleanup(os.chdir, cwd) + logs = [Path(".specfuse/features/F/events.jsonl"), + Path("docs/events.jsonl")] + for log in logs: + log.parent.mkdir(parents=True, exist_ok=True) + log.write_text("{}\n") + subprocess.run(["git", "add", "."], check=True) + subprocess.run(["git", "commit", "-q", "-m", "logs"], check=True) + for log in logs: + log.write_text("{}\n{}\n") + diff = loop.capture_working_tree_diff("HEAD") + os.chdir(cwd) + self.assertIn("docs/events.jsonl", diff) + self.assertNotIn(".specfuse/features/F/events.jsonl", diff) + + +class TestStatusFile(_ObservedRun): + """Clause 2 — the status file.""" + + def test_during_the_session(self): + status = self.run_seen.status_in_session + self.assertLessEqual(STATUS_FIELDS, set(status)) + self.assertEqual(status["feature"], FEATURE_ID) + self.assertEqual(status["wu_id"], WU_ID) + self.assertEqual(status["attempt"], 1) + self.assertEqual(status["max_attempts"], 1) + self.assertEqual(status["phase"], "agent") + self.assertIsNone(status["gate"]) + self.assertTrue(status["started_at"]) + self.assertTrue(status["updated_at"]) + self.assertGreaterEqual(status["elapsed_seconds"], 0) + self.assertIsInstance(status["files_touched"], list) + + def test_during_each_gate(self): + for name, status in self.run_seen.gate_status.items(): + with self.subTest(gate=name): + self.assertLessEqual(STATUS_FIELDS, set(status)) + self.assertEqual(status["phase"], "gate") + self.assertEqual(status["gate"], name) + self.assertEqual(status["wu_id"], WU_ID) + + def test_stopped_after_run_returns(self): + status = self.run_seen.status_after + self.assertEqual(status["phase"], "stopped") + self.assertIsNone(status["gate"]) + self.assertIsNone(status["stop_reason"]) + + def test_never_tracked(self): + self.assertTrue(self.run_seen.tracked) + self.assertEqual( + [p for p in self.run_seen.tracked + if "STATUS.json" in p or p.endswith("work/.gitignore")], []) + + +class TestDriverLines(_ObservedRun): + """Clause 4 — one plain line per phase change.""" + + def test_one_line_per_phase_change(self): + lines = self.run_seen.output.splitlines() + for pattern in ( + r"\] agent session started$", + r"\] agent session finished \(\d+\.\ds\)$", + r"\] gate alpha started$", + r"\] gate alpha PASS \(\d+\.\ds\)$", + r"\] gate beta started$", + r"\] gate beta PASS \(\d+\.\ds\)$", + ): + with self.subTest(pattern=pattern): + matching = [ln for ln in lines + if re.search(pattern, ln)] + self.assertEqual(len(matching), 1, self.run_seen.output) + + def test_no_carriage_return_or_ansi(self): + self.assertNotIn("\r", self.run_seen.output) + self.assertNotIn("\x1b", self.run_seen.output) + + +@unittest.skip("FEAT-LOOP-2026-0252/T02") +class TestHeartbeat(unittest.TestCase): + """Clause 3 — owned by T02.""" + + def test_placeholder(self): + self.fail("T02 replaces this class") + + +@unittest.skip("FEAT-LOOP-2026-0252/T03") +class TestWatch(unittest.TestCase): + """Clause 5 — owned by T03.""" + + def test_placeholder(self): + self.fail("T03 replaces this class") + + +@unittest.skip("FEAT-LOOP-2026-0252/T04") +class TestStopNotification(unittest.TestCase): + """Clause 6 — owned by T04.""" + + def test_placeholder(self): + self.fail("T04 replaces this class") + + +if __name__ == "__main__": + unittest.main() From f3dd26a5516469f744e7382d2017c10c7e57b785 Mon Sep 17 00:00:00 2001 From: Test Date: Thu, 26 Nov 2026 22:15:50 -0500 Subject: [PATCH 06/25] =?UTF-8?q?feat:=20T02=20=E2=80=94=20heartbeat=20whi?= =?UTF-8?q?le=20an=20attempt=20runs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Feature: FEAT-LOOP-2026-0252/T02 --- .../PROGRESS.md | 2 + .../WU-02-heartbeat.md | 11 +- .../events.jsonl | 13 +++ .specfuse/verification.yml.example | 6 + specfuse/loop/data/verification.yml.example | 6 + specfuse/loop/loop.py | 70 ++++++++++-- specfuse/loop/progress.py | 82 +++++++++++--- tests/test_run_progress.py | 106 +++++++++++++++++- 8 files changed, 264 insertions(+), 32 deletions(-) diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/PROGRESS.md b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/PROGRESS.md index c7acd60d..1979b10b 100644 --- a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/PROGRESS.md +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/PROGRESS.md @@ -1,2 +1,4 @@ - **FEAT-LOOP-2026-0252/T01**: Added specfuse/loop/progress.py and wired it into loop.py, so phase events are appended as they happen, work/STATUS.json tracks the phase, and each session or gate change prints one plain line; four event types registered in the packaged schema. - note: T02 should fill files_touched (always [] now) inside progress._rewrite_status, and its thread will share the module-global _run with the main thread, so status writes need a lock (the temp file name is per process, not per thread). +- **FEAT-LOOP-2026-0252/T02**: Added a heartbeat thread that rewrites STATUS.json with updated_at, elapsed_seconds and files_touched during each attempt, stopped in a finally, plus resolve_heartbeat_seconds and documentation of the key in both example files. + - note: STATUS.json files_touched keeps the last heartbeat reading (empty until the first beat, reset at each new attempt), so a --watch reader should treat it as up to heartbeat_seconds stale. diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-02-heartbeat.md b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-02-heartbeat.md index 87a3e930..c236adb1 100644 --- a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-02-heartbeat.md +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-02-heartbeat.md @@ -1,8 +1,8 @@ --- id: FEAT-LOOP-2026-0252/T02 type: implementation -status: pending -attempts: 0 +status: done +attempts: 1 planned_cost_usd: 2.50 produces: - specfuse/loop/progress.py @@ -14,6 +14,13 @@ produces_driver_helper: - resolve_heartbeat_seconds model: sonnet effort: medium +gate_set: code +driver_version: 0.33.2 +started_at: 2026-11-27T03:12:49.060381+00:00 +duration_seconds: 181.507 +cost_usd: 0.446125 +input_tokens: 18 +output_tokens: 11512 --- # T02 — heartbeat while an attempt runs diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl index 3115a592..5fd523f1 100644 --- a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl @@ -1,2 +1,15 @@ {"timestamp": "2026-11-27T03:04:36.833200+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "driver_build_pinned", "source": "driver", "source_version": "0.33.2", "payload": {"tree": "922820b250ad2ee71f9f116122a255fa09797f8a", "path": "/private/var/folders/zc/rgq11x850d78dx_kf1fd4vx80000gn/T/specfuse-pins/922820b250ad2ee71f9f116122a255fa09797f8a/specfuse/loop"}} {"timestamp": "2026-11-27T03:04:41.819293+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "driver_build_pinned", "source": "driver", "source_version": "0.33.2", "payload": {"tree": "f903f87239abf0c7dc90999ff3c7c79c295c30a4", "path": "/private/var/folders/zc/rgq11x850d78dx_kf1fd4vx80000gn/T/specfuse-pins/f903f87239abf0c7dc90999ff3c7c79c295c30a4/specfuse/loop"}} +{"timestamp": "2026-11-27T03:04:42.097061+00:00", "correlation_id": "FEAT-LOOP-2026-0252/T01", "event_type": "task_started", "source": "driver", "source_version": "0.33.2", "payload": {"type": "implementation", "model": "sonnet", "re_arm_count": 0}} +{"timestamp": "2026-11-27T03:12:48.739627+00:00", "correlation_id": "FEAT-LOOP-2026-0252/T01", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "gate": "tests", "ok": true, "skipped": false, "duration_seconds": 1.935, "phase": "attempt"}} +{"timestamp": "2026-11-27T03:12:48.739676+00:00", "correlation_id": "FEAT-LOOP-2026-0252/T01", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "gate": "lint", "ok": true, "skipped": false, "duration_seconds": 0.018, "phase": "attempt"}} +{"timestamp": "2026-11-27T03:12:48.739679+00:00", "correlation_id": "FEAT-LOOP-2026-0252/T01", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "gate": "changelog-fragments", "ok": true, "skipped": false, "duration_seconds": 0.058, "phase": "attempt"}} +{"timestamp": "2026-11-27T03:12:48.739682+00:00", "correlation_id": "FEAT-LOOP-2026-0252/T01", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "gate": "agent-policy-example-lint", "ok": true, "skipped": false, "duration_seconds": 0.122, "phase": "attempt"}} +{"timestamp": "2026-11-27T03:12:48.739685+00:00", "correlation_id": "FEAT-LOOP-2026-0252/T01", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "gate": "event-type-gate", "ok": true, "skipped": false, "duration_seconds": 0.165, "phase": "attempt"}} +{"timestamp": "2026-11-27T03:12:48.739687+00:00", "correlation_id": "FEAT-LOOP-2026-0252/T01", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "gate": "roadmap-link-gate", "ok": true, "skipped": false, "duration_seconds": 0.059, "phase": "attempt"}} +{"timestamp": "2026-11-27T03:12:48.739688+00:00", "correlation_id": "FEAT-LOOP-2026-0252/T01", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "gate": "arm-sweep-gate", "ok": true, "skipped": false, "duration_seconds": 0.476, "phase": "attempt"}} +{"timestamp": "2026-11-27T03:12:48.739689+00:00", "correlation_id": "FEAT-LOOP-2026-0252/T01", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "gate": "monitoring-example-lint", "ok": true, "skipped": false, "duration_seconds": 0.056, "phase": "attempt"}} +{"timestamp": "2026-11-27T03:12:48.739691+00:00", "correlation_id": "FEAT-LOOP-2026-0252/T01", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "gate": "feature_oracle", "ok": true, "skipped": false, "duration_seconds": 1.901, "phase": "attempt"}} +{"timestamp": "2026-11-27T03:12:48.948756+00:00", "correlation_id": "FEAT-LOOP-2026-0252/T01", "event_type": "attempt_outcome", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "outcome": "passed", "duration_seconds": 486.578, "agent_seconds": 481.57202387508005, "verify_seconds": 4.8648197499569505, "cost_usd": 1.2749034000000001, "input_tokens": 46, "output_tokens": 29228, "cache_read_input_tokens": 2909714, "cache_creation_input_tokens": 172890, "model": "sonnet", "effort": "medium", "failure_class": null, "failure_signature": null, "failure_excerpt": null, "files_touched": [".specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-01-phase-events-and-status.md", "specfuse/loop/arm_eval.py", "specfuse/loop/data/schemas/driver-event.schema.json", "specfuse/loop/loop.py", "specfuse/loop/progress.py", "tests/test_run_progress.py"], "agent_status": "complete", "agent_blocked_reason": null, "re_arm_count": 0, "failing_tests": []}} +{"timestamp": "2026-11-27T03:12:48.948957+00:00", "correlation_id": "FEAT-LOOP-2026-0252/T01", "event_type": "task_completed", "source": "driver", "source_version": "0.33.2", "payload": {"attempts": 1, "attempts_usage": [{"attempt": 1, "duration_seconds": 486.578, "cost_usd": 1.2749034000000001, "input_tokens": 46, "output_tokens": 29228, "cache_read_input_tokens": 2909714, "cache_creation_input_tokens": 172890, "agent_seconds": 481.57202387508005, "verify_seconds": 4.8648197499569505}], "type": "implementation", "re_arm_count": 0, "cost_usd": 1.274903, "cumulative_cost_usd": 1.274903, "attempts_lifetime": 1, "planned_cost_usd": 2.5}} +{"timestamp": "2026-11-27T03:12:48.956536+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "driver_staleness_detected", "source": "driver", "source_version": "0.33.2", "payload": {"gate": 1, "wu_id": "FEAT-LOOP-2026-0252/T01", "driver_paths": ["specfuse/loop/arm_eval.py", "specfuse/loop/loop.py", "specfuse/loop/progress.py"], "halted": false, "reason": "driver_restart_required", "pinned_tree": "f903f87239abf0c7dc90999ff3c7c79c295c30a4", "next_pin_tree": "c0befcb2b833738e5801b65b728f2e9206e085ae"}} diff --git a/.specfuse/verification.yml.example b/.specfuse/verification.yml.example index 5d005cf8..314a1614 100644 --- a/.specfuse/verification.yml.example +++ b/.specfuse/verification.yml.example @@ -126,6 +126,11 @@ # # writes a declared deliverable (a code # # generator, say): all three then run only # # after verification (FEAT-LOOP-2026-0251). +# heartbeat_seconds: 30 # how often the live status file +# # (/work/STATUS.json) is refreshed +# # while an attempt runs. 30 when missing, not +# # an integer or not positive +# # (FEAT-LOOP-2026-0252). # dispatch_skills: false # whether a dispatched session loads the # # project's skills index. Defaults to false: # # a work unit invokes no skill, and the index @@ -161,6 +166,7 @@ # max_attempts: 3 # retain_on_guard_refusal: true # fail_fast_deliverables: true +# heartbeat_seconds: 30 # dispatch_skills: false # post_merge_issue: false # produces_amendable: false diff --git a/specfuse/loop/data/verification.yml.example b/specfuse/loop/data/verification.yml.example index 5d005cf8..314a1614 100644 --- a/specfuse/loop/data/verification.yml.example +++ b/specfuse/loop/data/verification.yml.example @@ -126,6 +126,11 @@ # # writes a declared deliverable (a code # # generator, say): all three then run only # # after verification (FEAT-LOOP-2026-0251). +# heartbeat_seconds: 30 # how often the live status file +# # (/work/STATUS.json) is refreshed +# # while an attempt runs. 30 when missing, not +# # an integer or not positive +# # (FEAT-LOOP-2026-0252). # dispatch_skills: false # whether a dispatched session loads the # # project's skills index. Defaults to false: # # a work unit invokes no skill, and the index @@ -161,6 +166,7 @@ # max_attempts: 3 # retain_on_guard_refusal: true # fail_fast_deliverables: true +# heartbeat_seconds: 30 # dispatch_skills: false # post_merge_issue: false # produces_amendable: false diff --git a/specfuse/loop/loop.py b/specfuse/loop/loop.py index 67988787..eec0336a 100644 --- a/specfuse/loop/loop.py +++ b/specfuse/loop/loop.py @@ -663,6 +663,20 @@ def resolve_fail_fast_deliverables(verification_cfg: dict) -> bool: return bool(project.get("fail_fast_deliverables", True)) +def resolve_heartbeat_seconds(verification_cfg: dict) -> int: + """How often the status file is refreshed while an attempt runs + (FEAT-LOOP-2026-0252/T02). + + Reads `defaults.heartbeat_seconds` from verification.yml. 30 when the key + is missing, not an integer or not positive. + """ + project = (verification_cfg or {}).get("defaults") or {} + value = project.get("heartbeat_seconds") + if type(value) is int and value > 0: + return value + return 30 + + def resolve_dispatch_skills(verification_cfg: dict) -> bool: """Whether a dispatched session gets the project's skills index (#3423). @@ -3124,23 +3138,51 @@ def _path_state(path: str) -> "tuple[int, str] | None": hashlib.sha256(data).hexdigest()) -def _paths_differing_from(head: str) -> "set[str] | None": +def _paths_differing_from(head: str, *, + env: "dict | None" = None) -> "set[str] | None": """Every path whose working-tree state differs from *head*: tracked changes, staged or not, by both their old and new names (no rename pairing), plus untracked files. Names are read NUL-separated, so git - does not quote non-ASCII ones. None on any git error.""" + does not quote non-ASCII ones. None on any git error. *env* replaces + git's environment.""" try: tracked = subprocess.run( ["git", "diff", "--no-renames", "--name-only", "-z", head], - capture_output=True, text=True, check=True).stdout + capture_output=True, text=True, check=True, env=env).stdout untracked = subprocess.run( ["git", "ls-files", "--others", "--exclude-standard", "-z"], - capture_output=True, text=True, check=True).stdout + capture_output=True, text=True, check=True, env=env).stdout except (OSError, subprocess.CalledProcessError): return None return {p for p in (tracked + untracked).split("\0") if p} +def heartbeat_files_touched(head: str, + bookkeeping: "tuple[Path, ...]") -> "list | None": + """`_paths_differing_from(head)` less the driver's *bookkeeping* files, + matched by full path. None when git cannot list the tree. + + It runs beside the session and the driver, and `git diff` rewrites a stale + index under `index.lock`. So git reads a scratch copy of the index, and + their own git calls never find the lock taken by this one. + """ + try: + index = Path(git("rev-parse", "--git-path", "index")).resolve() + with tempfile.TemporaryDirectory() as tmp: + scratch = Path(tmp) / "index" + if index.exists(): + # copy2 keeps the mtime git's racy-index check relies on. + shutil.copy2(index, scratch) + paths = _paths_differing_from( + head, env={**os.environ, "GIT_INDEX_FILE": str(scratch)}) + except (OSError, subprocess.CalledProcessError): + return None + if paths is None: + return None + skip = {Path(p).resolve() for p in bookkeeping} + return sorted(p for p in paths if Path(p).resolve() not in skip) + + @dataclass(frozen=True) class AttemptStart: """The working tree as an attempt found it (#3612, #3614): the commit it @@ -13063,6 +13105,7 @@ def run( # MAX_ATTEMPTS. A malformed value raises here rather than # silently reverting to 3. wu_max_attempts = resolve_max_attempts(wu, load_verification()) + heartbeat_seconds = resolve_heartbeat_seconds(load_verification()) # Convergent-iteration state (#2650); inert unless the unit # opts in. `_best_diff` is the working-tree diff of the best # attempt so far, replayed when a later attempt regresses so a @@ -13140,12 +13183,19 @@ def run( _progress.begin_attempt(wu.wu_id, attempt, wu_max_attempts) 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, - untracked_before=untracked_before, - ) + _progress.start_heartbeat(heartbeat_seconds, functools.partial( + heartbeat_files_touched, head_before, + (wu.file, events_path, feature_dir / PROGRESS_FILENAME))) + try: + 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, + untracked_before=untracked_before, + ) + finally: + _progress.stop_heartbeat() wu_events.extend(build_attempt_gate_events(wu, attempt)) duration = round(time.monotonic() - t0, 3) attempt_record: dict = {"attempt": attempt, diff --git a/specfuse/loop/progress.py b/specfuse/loop/progress.py index 78af7bb6..d1bbf021 100644 --- a/specfuse/loop/progress.py +++ b/specfuse/loop/progress.py @@ -7,7 +7,8 @@ One function per phase change. Each appends its event to `events.jsonl` at once (never through a unit's buffered `wu_events`), rewrites the status file `/work/STATUS.json`, and prints one plain line: no carriage return, -no ANSI. +no ANSI. While an attempt runs, a heartbeat thread also rewrites the status +file, so its elapsed time and touched files stay current. Every function is a no-op unless `begin_run` was called, so a caller that runs a gate set or an attempt outside `run()` writes nothing. @@ -23,8 +24,9 @@ import datetime as dt import json import os +import threading import time -from dataclasses import dataclass +from dataclasses import dataclass, field from pathlib import Path from typing import Callable @@ -55,9 +57,14 @@ class _Run: started_at: str = "" started_clock: float = 0.0 agent_clock: float = 0.0 + files_touched: "list[str]" = field(default_factory=list) _run: "_Run | None" = None +_heartbeat: "tuple[threading.Thread, threading.Event] | None" = None +# The heartbeat and the driver both rewrite the status file, through the same +# temporary name. +_status_lock = threading.Lock() def _now() -> str: @@ -91,19 +98,20 @@ def write_status(feature_dir: Path, status: dict) -> None: def _rewrite_status(stop_reason: "str | None" = None) -> None: run = _run - write_status(run.feature_dir, { - "feature": run.feature, - "wu_id": run.wu_id, - "attempt": run.attempt, - "max_attempts": run.max_attempts, - "phase": run.phase, - "gate": run.gate, - "started_at": run.started_at, - "updated_at": _now(), - "elapsed_seconds": round(time.monotonic() - run.started_clock, 3), - "files_touched": [], - "stop_reason": stop_reason, - }) + with _status_lock: + write_status(run.feature_dir, { + "feature": run.feature, + "wu_id": run.wu_id, + "attempt": run.attempt, + "max_attempts": run.max_attempts, + "phase": run.phase, + "gate": run.gate, + "started_at": run.started_at, + "updated_at": _now(), + "elapsed_seconds": round(time.monotonic() - run.started_clock, 3), + "files_touched": run.files_touched, + "stop_reason": stop_reason, + }) def _append_event(event_type: str, payload: dict) -> None: @@ -133,6 +141,7 @@ def end_run(stop_reason: "str | None" = None) -> None: global _run if _run is None: return + stop_heartbeat() _run.phase = PHASE_STOPPED _run.gate = None _rewrite_status(stop_reason) @@ -147,15 +156,58 @@ def begin_attempt(wu_id: str, attempt: int, max_attempts: int) -> None: _run.max_attempts = max_attempts _run.phase = PHASE_BETWEEN _run.gate = None + _run.files_touched = [] _restart_clock(_run) _rewrite_status() +def start_heartbeat( + interval_seconds: float, + files_touched: "Callable[[], list[str] | None]", +) -> None: + """Rewrite the status file every *interval_seconds* until + `stop_heartbeat`. *files_touched* returning None, or raising, keeps the + last list: a failed reading never stops the beat or the run.""" + global _heartbeat + if _run is None: + return + stop_heartbeat() + run = _run + stop = threading.Event() + + def beat() -> None: + while not stop.wait(interval_seconds): + try: + touched = files_touched() + except Exception: # noqa: BLE001 — reporting never fails a run + touched = None + if touched is not None: + run.files_touched = touched + _rewrite_status() + + thread = threading.Thread( + target=beat, name="specfuse-heartbeat", daemon=True) + thread.start() + _heartbeat = (thread, stop) + + +def stop_heartbeat() -> None: + """Stop the heartbeat and wait for its thread to end.""" + global _heartbeat + if _heartbeat is None: + return + thread, stop = _heartbeat + stop.set() + thread.join() + _heartbeat = None + + def clear_unit() -> None: """No unit is running: gates run from here belong to the feature.""" if _run is None or _run.wu_id is None: return _run.wu_id = _run.attempt = _run.max_attempts = None + _run.files_touched = [] _run.phase = PHASE_BETWEEN _run.gate = None _restart_clock(_run) diff --git a/tests/test_run_progress.py b/tests/test_run_progress.py index 2b09089e..f9b691a9 100644 --- a/tests/test_run_progress.py +++ b/tests/test_run_progress.py @@ -4,7 +4,7 @@ # """FEAT-LOOP-2026-0252 gate 1 oracle — a running unit's progress is visible. One class per Definition-of-done clause in GATE-01.md. T01 implements clauses -1, 2 and 4; the rest are skipped naming their owning unit. +1, 2 and 4, T02 clause 3; the rest are skipped naming their owning unit. Every run goes through `loop.run()` in a temporary repository, with a stubbed agent session and two real stub gate commands. What must be on disk while the @@ -21,6 +21,8 @@ import re import subprocess import tempfile +import threading +import time import unittest from pathlib import Path from unittest import mock @@ -298,12 +300,106 @@ def test_no_carriage_return_or_ansi(self): self.assertNotIn("\x1b", self.run_seen.output) -@unittest.skip("FEAT-LOOP-2026-0252/T02") +class _SessionBoom(Exception): + pass + + +def _run_heartbeat_session(session_body): + """`loop.run()` with a one-second heartbeat and *session_body* as the + agent session. Returns what `run()` raised, or None.""" + with integration_workspace() as root, \ + tempfile.TemporaryDirectory() as snapshots: + cwd = os.getcwd() + os.chdir(root) + try: + fdir = _scaffold(root, Path(snapshots)) + with (root / ".specfuse/verification.yml").open("a") as fh: + fh.write("defaults:\n heartbeat_seconds: 1\n") + subprocess.run(["git", "commit", "-q", "-am", "heartbeat"], + check=True) + rel = fdir.relative_to(root) + + def session(wu, failure_note, cost_tracking=True): + return session_body(wu, rel) + + with mock.patch.object(loop, "dispatch", session), \ + contextlib.redirect_stdout(io.StringIO()): + try: + loop.run(None, dry_run=False) + except _SessionBoom as exc: + return exc + return None + finally: + os.chdir(cwd) + + class TestHeartbeat(unittest.TestCase): - """Clause 3 — owned by T02.""" + """Clause 3 — the status file is refreshed while an attempt runs.""" + + def test_status_refreshes_during_the_session(self): + before = set(threading.enumerate()) + samples = [] + + def body(wu, rel): + Path("notes").mkdir(exist_ok=True) + Path("notes/a.txt").write_text("a\n") + deadline = time.monotonic() + 3.4 + while time.monotonic() < deadline: + samples.append(json.loads( + (rel / "work" / "STATUS.json").read_text())) + time.sleep(0.05) + self.during = set(threading.enumerate()) - before + write_stub_deliverable(wu) + return "```result\nstatus: complete\n```\n" - def test_placeholder(self): - self.fail("T02 replaces this class") + _run_heartbeat_session(body) + + self.assertEqual({s["phase"] for s in samples}, {"agent"}) + updates = list(dict.fromkeys(s["updated_at"] for s in samples)) + self.assertGreaterEqual(len(updates) - 1, 2, updates) + last = samples[-1] + self.assertGreater(last["elapsed_seconds"], + samples[0]["elapsed_seconds"]) + self.assertIn("notes/a.txt", last["files_touched"]) + for name in ("events.jsonl", "WU-T01.md", "PROGRESS.md"): + self.assertEqual( + [p for p in last["files_touched"] if p.endswith(name)], []) + self.assertTrue(self.during) + self.assertEqual(set(threading.enumerate()) - before, set()) + + def test_same_named_file_outside_the_feature_folder_is_listed(self): + seen = {} + + def body(wu, rel): + Path("docs").mkdir(exist_ok=True) + Path("docs/PROGRESS.md").write_text("a\n") + time.sleep(1.6) + seen.update(json.loads((rel / "work" / "STATUS.json").read_text())) + write_stub_deliverable(wu) + return "```result\nstatus: complete\n```\n" + + _run_heartbeat_session(body) + self.assertIn("docs/PROGRESS.md", seen["files_touched"]) + + def test_no_thread_survives_a_raising_session(self): + before = set(threading.enumerate()) + + def body(wu, rel): + self.during = set(threading.enumerate()) - before + raise _SessionBoom() + + self.assertIsInstance(_run_heartbeat_session(body), _SessionBoom) + self.assertTrue(self.during) + self.assertEqual(set(threading.enumerate()) - before, set()) + + def test_resolve_heartbeat_seconds(self): + for cfg in ({}, {"defaults": {}}, None): + self.assertEqual(loop.resolve_heartbeat_seconds(cfg), 30) + for value, expected in (("x", 30), (0, 30), (-5, 30), (True, 30), + (1.5, 30), (7, 7)): + with self.subTest(value=value): + self.assertEqual(loop.resolve_heartbeat_seconds( + {"defaults": {"heartbeat_seconds": value}}), expected) @unittest.skip("FEAT-LOOP-2026-0252/T03") From 6d9873f9064a2e29b71df9e0384958c31f26ae3f Mon Sep 17 00:00:00 2001 From: Test Date: Thu, 26 Nov 2026 22:18:08 -0500 Subject: [PATCH 07/25] =?UTF-8?q?feat:=20T03=20=E2=80=94=20`specfuse-loop?= =?UTF-8?q?=20--watch`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Feature: FEAT-LOOP-2026-0252/T03 --- .../PROGRESS.md | 1 + .../WU-03-watch.md | 11 +- .../events.jsonl | 13 ++ specfuse/loop/loop.py | 10 ++ specfuse/loop/progress.py | 105 +++++++++++- tests/test_run_progress.py | 159 +++++++++++++++++- 6 files changed, 291 insertions(+), 8 deletions(-) diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/PROGRESS.md b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/PROGRESS.md index 1979b10b..8d445fdf 100644 --- a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/PROGRESS.md +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/PROGRESS.md @@ -2,3 +2,4 @@ - note: T02 should fill files_touched (always [] now) inside progress._rewrite_status, and its thread will share the module-global _run with the main thread, so status writes need a lock (the temp file name is per process, not per thread). - **FEAT-LOOP-2026-0252/T02**: Added a heartbeat thread that rewrites STATUS.json with updated_at, elapsed_seconds and files_touched during each attempt, stopped in a finally, plus resolve_heartbeat_seconds and documentation of the key in both example files. - note: STATUS.json files_touched keeps the last heartbeat reading (empty until the first beat, reset at each new attempt), so a --watch reader should treat it as up to heartbeat_seconds stale. +- **FEAT-LOOP-2026-0252/T03**: Added `specfuse-loop --watch` (reader `watch()` in progress.py, wired in main() before build pin and auto_sync); replaced TestWatch placeholder with real tests. Narrow-tier gates and test_dispatch_skeleton pass (run with HOME in $TMPDIR because sandbox blocks ~/.claude/session-env). GATE-01 clause 5 "one of those" literally includes elapsed time; followed WU AC1 (elapsed-only change prints nothing). diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-03-watch.md b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-03-watch.md index 2bbb8eb9..82370ae2 100644 --- a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-03-watch.md +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-03-watch.md @@ -1,8 +1,8 @@ --- id: FEAT-LOOP-2026-0252/T03 type: implementation -status: pending -attempts: 0 +status: done +attempts: 1 planned_cost_usd: 2.00 produces: - specfuse/loop/progress.py @@ -12,6 +12,13 @@ produces_driver_helper: - main model: sonnet effort: medium +gate_set: code +driver_version: 0.33.2 +started_at: 2026-11-27T03:15:51.138811+00:00 +duration_seconds: 137.331 +cost_usd: 0.446936 +input_tokens: 24 +output_tokens: 11063 --- # T03 — `specfuse-loop --watch` diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl index 5fd523f1..db2defb9 100644 --- a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl @@ -13,3 +13,16 @@ {"timestamp": "2026-11-27T03:12:48.948756+00:00", "correlation_id": "FEAT-LOOP-2026-0252/T01", "event_type": "attempt_outcome", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "outcome": "passed", "duration_seconds": 486.578, "agent_seconds": 481.57202387508005, "verify_seconds": 4.8648197499569505, "cost_usd": 1.2749034000000001, "input_tokens": 46, "output_tokens": 29228, "cache_read_input_tokens": 2909714, "cache_creation_input_tokens": 172890, "model": "sonnet", "effort": "medium", "failure_class": null, "failure_signature": null, "failure_excerpt": null, "files_touched": [".specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-01-phase-events-and-status.md", "specfuse/loop/arm_eval.py", "specfuse/loop/data/schemas/driver-event.schema.json", "specfuse/loop/loop.py", "specfuse/loop/progress.py", "tests/test_run_progress.py"], "agent_status": "complete", "agent_blocked_reason": null, "re_arm_count": 0, "failing_tests": []}} {"timestamp": "2026-11-27T03:12:48.948957+00:00", "correlation_id": "FEAT-LOOP-2026-0252/T01", "event_type": "task_completed", "source": "driver", "source_version": "0.33.2", "payload": {"attempts": 1, "attempts_usage": [{"attempt": 1, "duration_seconds": 486.578, "cost_usd": 1.2749034000000001, "input_tokens": 46, "output_tokens": 29228, "cache_read_input_tokens": 2909714, "cache_creation_input_tokens": 172890, "agent_seconds": 481.57202387508005, "verify_seconds": 4.8648197499569505}], "type": "implementation", "re_arm_count": 0, "cost_usd": 1.274903, "cumulative_cost_usd": 1.274903, "attempts_lifetime": 1, "planned_cost_usd": 2.5}} {"timestamp": "2026-11-27T03:12:48.956536+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "driver_staleness_detected", "source": "driver", "source_version": "0.33.2", "payload": {"gate": 1, "wu_id": "FEAT-LOOP-2026-0252/T01", "driver_paths": ["specfuse/loop/arm_eval.py", "specfuse/loop/loop.py", "specfuse/loop/progress.py"], "halted": false, "reason": "driver_restart_required", "pinned_tree": "f903f87239abf0c7dc90999ff3c7c79c295c30a4", "next_pin_tree": "c0befcb2b833738e5801b65b728f2e9206e085ae"}} +{"timestamp": "2026-11-27T03:12:49.060582+00:00", "correlation_id": "FEAT-LOOP-2026-0252/T02", "event_type": "task_started", "source": "driver", "source_version": "0.33.2", "payload": {"type": "implementation", "model": "sonnet", "re_arm_count": 0}} +{"timestamp": "2026-11-27T03:15:50.594870+00:00", "correlation_id": "FEAT-LOOP-2026-0252/T02", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "gate": "tests", "ok": true, "skipped": false, "duration_seconds": 10.003, "phase": "attempt"}} +{"timestamp": "2026-11-27T03:15:50.594902+00:00", "correlation_id": "FEAT-LOOP-2026-0252/T02", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "gate": "lint", "ok": true, "skipped": false, "duration_seconds": 0.107, "phase": "attempt"}} +{"timestamp": "2026-11-27T03:15:50.594907+00:00", "correlation_id": "FEAT-LOOP-2026-0252/T02", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "gate": "changelog-fragments", "ok": true, "skipped": false, "duration_seconds": 0.102, "phase": "attempt"}} +{"timestamp": "2026-11-27T03:15:50.594911+00:00", "correlation_id": "FEAT-LOOP-2026-0252/T02", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "gate": "agent-policy-example-lint", "ok": true, "skipped": false, "duration_seconds": 0.179, "phase": "attempt"}} +{"timestamp": "2026-11-27T03:15:50.594913+00:00", "correlation_id": "FEAT-LOOP-2026-0252/T02", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "gate": "event-type-gate", "ok": true, "skipped": false, "duration_seconds": 0.261, "phase": "attempt"}} +{"timestamp": "2026-11-27T03:15:50.594914+00:00", "correlation_id": "FEAT-LOOP-2026-0252/T02", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "gate": "roadmap-link-gate", "ok": true, "skipped": false, "duration_seconds": 0.067, "phase": "attempt"}} +{"timestamp": "2026-11-27T03:15:50.594916+00:00", "correlation_id": "FEAT-LOOP-2026-0252/T02", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "gate": "arm-sweep-gate", "ok": true, "skipped": false, "duration_seconds": 0.705, "phase": "attempt"}} +{"timestamp": "2026-11-27T03:15:50.594918+00:00", "correlation_id": "FEAT-LOOP-2026-0252/T02", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "gate": "monitoring-example-lint", "ok": true, "skipped": false, "duration_seconds": 0.085, "phase": "attempt"}} +{"timestamp": "2026-11-27T03:15:50.594922+00:00", "correlation_id": "FEAT-LOOP-2026-0252/T02", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "gate": "feature_oracle", "ok": true, "skipped": false, "duration_seconds": 10.392, "phase": "attempt"}} +{"timestamp": "2026-11-27T03:15:50.985185+00:00", "correlation_id": "FEAT-LOOP-2026-0252/T02", "event_type": "attempt_outcome", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "outcome": "passed", "duration_seconds": 181.507, "agent_seconds": 159.29573004203849, "verify_seconds": 21.982830333989114, "cost_usd": 0.44612500000000005, "input_tokens": 18, "output_tokens": 11512, "cache_read_input_tokens": 575450, "cache_creation_input_tokens": 68356, "model": "sonnet", "effort": "medium", "failure_class": null, "failure_signature": null, "failure_excerpt": null, "files_touched": [".specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-02-heartbeat.md", ".specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl", ".specfuse/verification.yml.example", "specfuse/loop/data/verification.yml.example", "specfuse/loop/loop.py", "specfuse/loop/progress.py", "tests/test_run_progress.py"], "agent_status": "complete", "agent_blocked_reason": null, "re_arm_count": 0, "failing_tests": []}} +{"timestamp": "2026-11-27T03:15:50.985604+00:00", "correlation_id": "FEAT-LOOP-2026-0252/T02", "event_type": "task_completed", "source": "driver", "source_version": "0.33.2", "payload": {"attempts": 1, "attempts_usage": [{"attempt": 1, "duration_seconds": 181.507, "cost_usd": 0.44612500000000005, "input_tokens": 18, "output_tokens": 11512, "cache_read_input_tokens": 575450, "cache_creation_input_tokens": 68356, "agent_seconds": 159.29573004203849, "verify_seconds": 21.982830333989114}], "type": "implementation", "re_arm_count": 0, "cost_usd": 0.446125, "cumulative_cost_usd": 0.446125, "attempts_lifetime": 1, "planned_cost_usd": 2.5}} +{"timestamp": "2026-11-27T03:15:51.000470+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "driver_staleness_detected", "source": "driver", "source_version": "0.33.2", "payload": {"gate": 1, "wu_id": "FEAT-LOOP-2026-0252/T02", "driver_paths": ["specfuse/loop/loop.py", "specfuse/loop/progress.py"], "halted": false, "reason": "driver_restart_required", "pinned_tree": "f903f87239abf0c7dc90999ff3c7c79c295c30a4", "next_pin_tree": "51e2c6a4ba4cc7185726000e213b8782019a0414"}} diff --git a/specfuse/loop/loop.py b/specfuse/loop/loop.py index eec0336a..b2725b9a 100644 --- a/specfuse/loop/loop.py +++ b/specfuse/loop/loop.py @@ -15026,6 +15026,10 @@ def main() -> int: ap.add_argument("--feature", help="Feature dir name or bare FEAT-ID (e.g. " "FEAT-2026-0039) under .specfuse/features/ " "(optional if exactly one feature is active).") + ap.add_argument("--watch", action="store_true", + help="Follow a running driver's progress from a second " + "terminal, for --feature or the single active feature. " + "Reads the status file only; runs and writes nothing.") ap.add_argument("--dry-run", action="store_true", help="Walk the current gate without dispatching or writing.") ap.add_argument("--force-full-close", metavar="FEATURE_ID", @@ -15062,6 +15066,12 @@ def main() -> int: if not FEATURES_DIR.exists(): sys.exit(f"No {FEATURES_DIR}. Run from your repo root.") + # Before the build pin and auto_sync: both write, and the watcher must not. + if args.watch: + return _progress.watch( + find_feature(args.feature), + resolve_heartbeat_seconds(load_verification())) + # Build-pin re-entry (FEAT-2026-0109/T08): after argparse (so `--help` # and a bad flag exit here, in-process, without ever touching a pin) and # after the FEATURES_DIR guard, but before any work that would run diff --git a/specfuse/loop/progress.py b/specfuse/loop/progress.py index d1bbf021..86afc090 100644 --- a/specfuse/loop/progress.py +++ b/specfuse/loop/progress.py @@ -16,6 +16,9 @@ `build_event` and `flush_events` are passed in by the driver: it imports this module, so this module does not import it. +`watch` is the `specfuse-loop --watch` reader, run from a second terminal. It +only reads the status file: it takes no run lock and writes nothing. + Reports only; no merge, arm or close verdict reads anything written here. """ @@ -24,6 +27,8 @@ import datetime as dt import json import os +import shutil +import sys import threading import time from dataclasses import dataclass, field @@ -120,9 +125,12 @@ def _append_event(event_type: str, payload: dict) -> None: event_type, run.wu_id or run.feature, payload)]) +def _plain(text: str) -> str: + return "".join(c if c.isprintable() else " " for c in text) + + def _say(text: str) -> None: - plain = "".join(c if c.isprintable() else " " for c in text) - print(f" [{time.strftime('%H:%M:%S')}] {plain}", flush=True) + print(f" [{time.strftime('%H:%M:%S')}] {_plain(text)}", flush=True) def begin_run( @@ -255,3 +263,96 @@ def gate_finished(name: str, ok: bool, duration_seconds: float) -> None: "attempt": _run.attempt, "gate": name, "ok": bool(ok), "duration_seconds": duration_seconds}) _say(f"gate {name} {'PASS' if ok else 'FAIL'} ({duration_seconds:.1f}s)") + + +# A watcher is stale after this many heartbeat intervals without a rewrite. +_STALE_INTERVALS = 3 +_WATCH_POLL_SECONDS = 1.0 + + +def _read_status(path: Path) -> "dict | None": + try: + status = json.loads(path.read_text(encoding="utf-8")) + except (OSError, ValueError): + return None + return status if isinstance(status, dict) else None + + +def _age_seconds(status: dict) -> "float | None": + try: + updated = dt.datetime.fromisoformat(status["updated_at"]) + return (dt.datetime.now(dt.timezone.utc) - updated).total_seconds() + except (KeyError, TypeError, ValueError): + return None + + +def _watch_line(status: dict, stale_age: "float | None") -> str: + attempt = "-" + if status.get("attempt") is not None: + attempt = f"{status['attempt']}/{status.get('max_attempts')}" + elapsed = status.get("elapsed_seconds") + elapsed = f"{int(elapsed)}s" if isinstance(elapsed, (int, float)) else "-" + line = (f"{status.get('wu_id') or status.get('feature')} " + f"attempt {attempt} phase {status.get('phase')} " + f"gate {status.get('gate') or '-'} elapsed {elapsed}") + if stale_age is not None: + # First, so cutting the line to the terminal width keeps it. + line = f"no update for {int(stale_age)}s {line}" + return _plain(line) + + +def watch(feature_dir: Path, heartbeat_seconds: float) -> int: + """Follow the status file of *feature_dir* until its phase is `stopped`. + + On a terminal one line is redrawn in place. Otherwise a line is printed + when the unit, attempt, phase or gate changes, and once each time the file + goes stale. Returns 0 when the run stopped, 1 when there is no status file, + 130 on Ctrl-C. + """ + path = status_path(feature_dir) + out = sys.stdout + tty = out.isatty() + shown = None + drawn = 0 + try: + while True: + status = _read_status(path) + if status is None: + if not path.is_file(): + if drawn: + out.write("\n") + print(f"No status file at {path}. `specfuse-loop` writes " + f"it while it runs this feature.", file=sys.stderr) + return 1 + time.sleep(_WATCH_POLL_SECONDS) + continue + stopped = status.get("phase") == PHASE_STOPPED + age = _age_seconds(status) + stale = (not stopped and age is not None + and age > _STALE_INTERVALS * heartbeat_seconds) + line = _watch_line(status, age if stale else None) + if tty: + width = max(shutil.get_terminal_size().columns - 1, 1) + text = line[:width] + # Padding covers a longer previous line without ANSI codes. + out.write("\r" + text.ljust(min(drawn, width))) + out.flush() + drawn = len(text) + else: + key = tuple(status.get(k) for k in ( + "wu_id", "attempt", "phase", "gate")) + (stale,) + # Leaving the stale state alone is not a change to report. + if key != shown and not ( + shown and shown[-1] and not stale + and key[:-1] == shown[:-1]): + print(line, file=out, flush=True) + shown = key + if stopped: + if tty: + out.write("\n") + return 0 + time.sleep(_WATCH_POLL_SECONDS) + except KeyboardInterrupt: + if drawn: + out.write("\n") + return 130 diff --git a/tests/test_run_progress.py b/tests/test_run_progress.py index f9b691a9..c65db6b4 100644 --- a/tests/test_run_progress.py +++ b/tests/test_run_progress.py @@ -14,12 +14,14 @@ from __future__ import annotations import contextlib +import datetime as dt import importlib.resources import io import json import os import re import subprocess +import sys import tempfile import threading import time @@ -402,12 +404,161 @@ def test_resolve_heartbeat_seconds(self): {"defaults": {"heartbeat_seconds": value}}), expected) -@unittest.skip("FEAT-LOOP-2026-0252/T03") +def _status(age_seconds=0.0, **changes) -> dict: + updated = dt.datetime.now(dt.timezone.utc) - dt.timedelta( + seconds=age_seconds) + status = { + "feature": FEATURE_ID, "wu_id": WU_ID, "attempt": 1, + "max_attempts": 3, "phase": "agent", "gate": None, + "started_at": updated.isoformat(), "updated_at": updated.isoformat(), + "elapsed_seconds": 12.4, "files_touched": [], "stop_reason": None, + } + status.update(changes) + return status + + +class _Tty(io.StringIO): + def isatty(self): + return True + + class TestWatch(unittest.TestCase): - """Clause 5 — owned by T03.""" + """Clause 5 — `specfuse-loop --watch`.""" - def test_placeholder(self): - self.fail("T03 replaces this class") + def _watch(self, statuses, *, out=None, argv=("--watch",), heartbeat=None): + """`main()` over a status file that is rewritten with the next of + *statuses* each time the watcher waits.""" + out = io.StringIO() if out is None else out + err = io.StringIO() + with integration_workspace() as root, \ + tempfile.TemporaryDirectory() as snapshots: + cwd = os.getcwd() + os.chdir(root) + try: + fdir = _scaffold(root, Path(snapshots)) + if heartbeat is not None: + with (root / ".specfuse/verification.yml").open("a") as fh: + fh.write( + f"defaults:\n heartbeat_seconds: {heartbeat}\n") + path = fdir / "work" / "STATUS.json" + pending = list(statuses) + + def rewrite(): + path.parent.mkdir(exist_ok=True) + path.write_text(json.dumps(pending.pop(0))) + + if pending: + rewrite() + + def sleep(_seconds): + if not pending: + raise AssertionError( + "watch kept waiting: " + out.getvalue()) + rewrite() + + def tree(): + return {p: p.read_bytes() for p in root.rglob("*") + if p.is_file() and ".git" not in p.parts + and p.name != "STATUS.json"} + + before = tree() + with mock.patch.object(sys, "argv", ["specfuse-loop", *argv]), \ + mock.patch.object(time, "sleep", sleep), \ + mock.patch.object(loop, "acquire_tree_lock") as lock, \ + mock.patch.object(loop, "auto_sync") as sync, \ + mock.patch.object(loop, "run") as run, \ + contextlib.redirect_stdout(out), \ + contextlib.redirect_stderr(err): + rc = loop.main() + for untouched in (lock, sync, run): + untouched.assert_not_called() + self.assertEqual(tree(), before) + finally: + os.chdir(cwd) + return rc, out.getvalue(), err.getvalue() + + def test_line_names_unit_attempt_phase_elapsed_and_gate(self): + rc, out, _ = self._watch([ + _status(phase="gate", gate="alpha"), + _status(phase="stopped"), + ]) + self.assertEqual(rc, 0) + first = out.splitlines()[0] + for part in (WU_ID, "attempt 1/3", "phase gate", "gate alpha", + "elapsed 12s"): + self.assertIn(part, first) + self.assertNotIn("no update", out) + self.assertNotIn("\r", out) + self.assertNotIn("\x1b", out) + + def test_prints_only_on_unit_attempt_phase_or_gate_change(self): + rc, out, _ = self._watch([ + _status(), + _status(elapsed_seconds=42.0, files_touched=["a.txt"]), + _status(phase="gate", gate="alpha"), + _status(phase="gate", gate="beta"), + _status(attempt=2), + _status(attempt=2, wu_id=f"{FEATURE_ID}/T02"), + _status(phase="stopped"), + ]) + self.assertEqual(rc, 0) + lines = out.splitlines() + self.assertEqual(len(lines), 6, out) + self.assertIn("phase agent", lines[0]) + self.assertIn("gate alpha", lines[1]) + self.assertIn("gate beta", lines[2]) + self.assertIn("attempt 2/3", lines[3]) + self.assertIn("/T02", lines[4]) + self.assertIn("phase stopped", lines[5]) + + def test_stale_status_says_no_update_once(self): + rc, out, _ = self._watch([ + _status(age_seconds=100), + _status(age_seconds=101), + _status(phase="stopped"), + ]) + self.assertEqual(rc, 0) + stale = [ln for ln in out.splitlines() if "no update for" in ln] + self.assertEqual(len(stale), 1, out) + self.assertRegex(stale[0], r"no update for 10\ds") + + def test_staleness_is_three_configured_heartbeat_intervals(self): + for age, expected in ((20, False), (40, True)): + with self.subTest(age=age): + _, out, _ = self._watch( + [_status(age_seconds=age), _status(phase="stopped")], + heartbeat=10) + self.assertEqual("no update for" in out, expected, out) + + def test_old_stopped_status_is_not_stale(self): + rc, out, _ = self._watch([_status(age_seconds=500, phase="stopped")]) + self.assertEqual(rc, 0) + self.assertNotIn("no update", out) + + def test_terminal_redraws_one_line_in_place(self): + rc, out, _ = self._watch([ + _status(), + _status(elapsed_seconds=42.0), + _status(phase="stopped"), + ], out=_Tty()) + self.assertEqual(rc, 0) + self.assertEqual(out.count("\n"), 1, repr(out)) + self.assertTrue(out.endswith("\n")) + self.assertEqual(out.count("\r"), 3, repr(out)) + self.assertIn("elapsed 42s", out) + + def test_feature_argument_resolves_a_bare_id(self): + rc, out, _ = self._watch( + [_status(phase="stopped")], + argv=("--watch", "--feature", FEATURE_ID)) + self.assertEqual(rc, 0) + self.assertIn(WU_ID, out) + + def test_no_status_file_names_the_expected_path(self): + rc, _, err = self._watch([]) + self.assertEqual(rc, 1) + self.assertIn( + f".specfuse/features/{FEATURE_ID}-{SLUG}/work/STATUS.json", err) @unittest.skip("FEAT-LOOP-2026-0252/T04") From b69f46b83aae0b09b72f06cbb28f030c9a7f023e Mon Sep 17 00:00:00 2001 From: Test Date: Thu, 26 Nov 2026 22:23:36 -0500 Subject: [PATCH 08/25] =?UTF-8?q?feat:=20T04=20=E2=80=94=20one=20notificat?= =?UTF-8?q?ion=20when=20the=20run=20stops,=20and=20the=20docs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Feature: FEAT-LOOP-2026-0252/T04 --- .specfuse/agent-policy.yml.example | 7 + .../PROGRESS.md | 2 + .../WU-04-stop-notification-and-docs.md | 11 +- .../events.jsonl | 13 + docs/getting-started.md | 70 ++++++ specfuse/loop/agent_policy.py | 9 + specfuse/loop/data/docs/getting-started.md | 70 ++++++ specfuse/loop/loop.py | 18 +- specfuse/loop/progress.py | 187 ++++++++++++++ tests/test_run_progress.py | 228 +++++++++++++++++- 10 files changed, 603 insertions(+), 12 deletions(-) diff --git a/.specfuse/agent-policy.yml.example b/.specfuse/agent-policy.yml.example index c86ea8cf..0579992d 100644 --- a/.specfuse/agent-policy.yml.example +++ b/.specfuse/agent-policy.yml.example @@ -110,3 +110,10 @@ escalation: quiet_hours: "" # str, may be empty; "HH:MM-HH:MM" when set sla_hours: 24 # int > 0 silence_hours: 24 # OPTIONAL int > 0 — no run within this window flags stale; defaults to 24 + # OPTIONAL str — run once each time `specfuse-loop` stops. Split into an + # argument list, never run through a shell: no pipes, `;` or `$VAR` + # expansion. It reads SPECFUSE_STOP_REASON, SPECFUSE_FEATURE, + # SPECFUSE_WORK_UNIT and SPECFUSE_MESSAGE from its environment; for anything + # that needs them, name a script. 30 s timeout; a failure is only logged. + # Desktop notifier example: + # notify_command: "terminal-notifier -title specfuse -message 'run stopped'" diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/PROGRESS.md b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/PROGRESS.md index 8d445fdf..35f90969 100644 --- a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/PROGRESS.md +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/PROGRESS.md @@ -3,3 +3,5 @@ - **FEAT-LOOP-2026-0252/T02**: Added a heartbeat thread that rewrites STATUS.json with updated_at, elapsed_seconds and files_touched during each attempt, stopped in a finally, plus resolve_heartbeat_seconds and documentation of the key in both example files. - note: STATUS.json files_touched keeps the last heartbeat reading (empty until the first beat, reset at each new attempt), so a --watch reader should treat it as up to heartbeat_seconds stale. - **FEAT-LOOP-2026-0252/T03**: Added `specfuse-loop --watch` (reader `watch()` in progress.py, wired in main() before build pin and auto_sync); replaced TestWatch placeholder with real tests. Narrow-tier gates and test_dispatch_skeleton pass (run with HOME in $TMPDIR because sandbox blocks ~/.claude/session-env). GATE-01 clause 5 "one of those" literally includes elapsed time; followed WU AC1 (elapsed-only change prints nothing). +- **FEAT-LOOP-2026-0252/T04**: Added notify_stop (stop reason taken from this run's events and PLAN.md, written to STATUS.json, sent to the webhook and escalation.notify_command), called it from main(), and added the validator key, policy example, docs and TestStopNotification. + - note: Close should note that every non-dry-run return from main()'s run() call notifies (including --prepare-only and a refused lock, which leaves the other driver's STATUS.json alone), and that quiet_hours gates only the webhook, not notify_command. diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-04-stop-notification-and-docs.md b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-04-stop-notification-and-docs.md index c9c73820..f5a2238d 100644 --- a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-04-stop-notification-and-docs.md +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-04-stop-notification-and-docs.md @@ -1,8 +1,8 @@ --- id: FEAT-LOOP-2026-0252/T04 type: implementation -status: pending -attempts: 0 +status: done +attempts: 1 planned_cost_usd: 2.50 produces: - specfuse/loop/progress.py @@ -16,6 +16,13 @@ produces_driver_helper: - main model: sonnet effort: medium +gate_set: code +driver_version: 0.33.2 +started_at: 2026-11-27T03:18:08.982098+00:00 +duration_seconds: 327.456 +cost_usd: 0.719836 +input_tokens: 26 +output_tokens: 19711 --- # T04 — one notification when the run stops, and the docs diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl index db2defb9..a10c4351 100644 --- a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl @@ -26,3 +26,16 @@ {"timestamp": "2026-11-27T03:15:50.985185+00:00", "correlation_id": "FEAT-LOOP-2026-0252/T02", "event_type": "attempt_outcome", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "outcome": "passed", "duration_seconds": 181.507, "agent_seconds": 159.29573004203849, "verify_seconds": 21.982830333989114, "cost_usd": 0.44612500000000005, "input_tokens": 18, "output_tokens": 11512, "cache_read_input_tokens": 575450, "cache_creation_input_tokens": 68356, "model": "sonnet", "effort": "medium", "failure_class": null, "failure_signature": null, "failure_excerpt": null, "files_touched": [".specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-02-heartbeat.md", ".specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl", ".specfuse/verification.yml.example", "specfuse/loop/data/verification.yml.example", "specfuse/loop/loop.py", "specfuse/loop/progress.py", "tests/test_run_progress.py"], "agent_status": "complete", "agent_blocked_reason": null, "re_arm_count": 0, "failing_tests": []}} {"timestamp": "2026-11-27T03:15:50.985604+00:00", "correlation_id": "FEAT-LOOP-2026-0252/T02", "event_type": "task_completed", "source": "driver", "source_version": "0.33.2", "payload": {"attempts": 1, "attempts_usage": [{"attempt": 1, "duration_seconds": 181.507, "cost_usd": 0.44612500000000005, "input_tokens": 18, "output_tokens": 11512, "cache_read_input_tokens": 575450, "cache_creation_input_tokens": 68356, "agent_seconds": 159.29573004203849, "verify_seconds": 21.982830333989114}], "type": "implementation", "re_arm_count": 0, "cost_usd": 0.446125, "cumulative_cost_usd": 0.446125, "attempts_lifetime": 1, "planned_cost_usd": 2.5}} {"timestamp": "2026-11-27T03:15:51.000470+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "driver_staleness_detected", "source": "driver", "source_version": "0.33.2", "payload": {"gate": 1, "wu_id": "FEAT-LOOP-2026-0252/T02", "driver_paths": ["specfuse/loop/loop.py", "specfuse/loop/progress.py"], "halted": false, "reason": "driver_restart_required", "pinned_tree": "f903f87239abf0c7dc90999ff3c7c79c295c30a4", "next_pin_tree": "51e2c6a4ba4cc7185726000e213b8782019a0414"}} +{"timestamp": "2026-11-27T03:15:51.139219+00:00", "correlation_id": "FEAT-LOOP-2026-0252/T03", "event_type": "task_started", "source": "driver", "source_version": "0.33.2", "payload": {"type": "implementation", "model": "sonnet", "re_arm_count": 0}} +{"timestamp": "2026-11-27T03:18:08.508923+00:00", "correlation_id": "FEAT-LOOP-2026-0252/T03", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "gate": "tests", "ok": true, "skipped": false, "duration_seconds": 12.469, "phase": "attempt"}} +{"timestamp": "2026-11-27T03:18:08.508950+00:00", "correlation_id": "FEAT-LOOP-2026-0252/T03", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "gate": "lint", "ok": true, "skipped": false, "duration_seconds": 0.062, "phase": "attempt"}} +{"timestamp": "2026-11-27T03:18:08.508953+00:00", "correlation_id": "FEAT-LOOP-2026-0252/T03", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "gate": "changelog-fragments", "ok": true, "skipped": false, "duration_seconds": 0.077, "phase": "attempt"}} +{"timestamp": "2026-11-27T03:18:08.508956+00:00", "correlation_id": "FEAT-LOOP-2026-0252/T03", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "gate": "agent-policy-example-lint", "ok": true, "skipped": false, "duration_seconds": 0.156, "phase": "attempt"}} +{"timestamp": "2026-11-27T03:18:08.508957+00:00", "correlation_id": "FEAT-LOOP-2026-0252/T03", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "gate": "event-type-gate", "ok": true, "skipped": false, "duration_seconds": 0.267, "phase": "attempt"}} +{"timestamp": "2026-11-27T03:18:08.508961+00:00", "correlation_id": "FEAT-LOOP-2026-0252/T03", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "gate": "roadmap-link-gate", "ok": true, "skipped": false, "duration_seconds": 0.072, "phase": "attempt"}} +{"timestamp": "2026-11-27T03:18:08.508963+00:00", "correlation_id": "FEAT-LOOP-2026-0252/T03", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "gate": "arm-sweep-gate", "ok": true, "skipped": false, "duration_seconds": 0.602, "phase": "attempt"}} +{"timestamp": "2026-11-27T03:18:08.508967+00:00", "correlation_id": "FEAT-LOOP-2026-0252/T03", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "gate": "monitoring-example-lint", "ok": true, "skipped": false, "duration_seconds": 0.066, "phase": "attempt"}} +{"timestamp": "2026-11-27T03:18:08.508969+00:00", "correlation_id": "FEAT-LOOP-2026-0252/T03", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "gate": "feature_oracle", "ok": true, "skipped": false, "duration_seconds": 11.078, "phase": "attempt"}} +{"timestamp": "2026-11-27T03:18:08.839645+00:00", "correlation_id": "FEAT-LOOP-2026-0252/T03", "event_type": "attempt_outcome", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "outcome": "passed", "duration_seconds": 137.331, "agent_seconds": 112.18943454197142, "verify_seconds": 24.958582791965455, "cost_usd": 0.4469357, "input_tokens": 24, "output_tokens": 11063, "cache_read_input_tokens": 788097, "cache_creation_input_tokens": 64362, "model": "sonnet", "effort": "medium", "failure_class": null, "failure_signature": null, "failure_excerpt": null, "files_touched": [".specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-03-watch.md", ".specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl", "specfuse/loop/loop.py", "specfuse/loop/progress.py", "tests/test_run_progress.py"], "agent_status": "complete", "agent_blocked_reason": null, "re_arm_count": 0, "failing_tests": []}} +{"timestamp": "2026-11-27T03:18:08.840001+00:00", "correlation_id": "FEAT-LOOP-2026-0252/T03", "event_type": "task_completed", "source": "driver", "source_version": "0.33.2", "payload": {"attempts": 1, "attempts_usage": [{"attempt": 1, "duration_seconds": 137.331, "cost_usd": 0.4469357, "input_tokens": 24, "output_tokens": 11063, "cache_read_input_tokens": 788097, "cache_creation_input_tokens": 64362, "agent_seconds": 112.18943454197142, "verify_seconds": 24.958582791965455}], "type": "implementation", "re_arm_count": 0, "cost_usd": 0.446936, "cumulative_cost_usd": 0.446936, "attempts_lifetime": 1, "planned_cost_usd": 2.0}} +{"timestamp": "2026-11-27T03:18:08.853380+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "driver_staleness_detected", "source": "driver", "source_version": "0.33.2", "payload": {"gate": 1, "wu_id": "FEAT-LOOP-2026-0252/T03", "driver_paths": ["specfuse/loop/loop.py", "specfuse/loop/progress.py"], "halted": false, "reason": "driver_restart_required", "pinned_tree": "f903f87239abf0c7dc90999ff3c7c79c295c30a4", "next_pin_tree": "0bc35ad83b292fc4d4800be791f51cb04baaaf33"}} diff --git a/docs/getting-started.md b/docs/getting-started.md index dd2c7515..2c01f31e 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -176,6 +176,76 @@ failure evidence, up to three attempts, then the unit is escalated to > To run two features at once, use separate `git worktree` checkouts. `--dry-run` > is exempt. +### Watching a run + +While a unit runs, the driver prints one plain line per phase change: the agent +session starting and finishing, and each verification gate starting and then +finishing with `PASS` or `FAIL` and its duration. + +``` + [14:02:11] agent session started + [14:06:08] agent session finished (237.4s) + [14:06:08] gate tests started + [14:07:30] gate tests PASS (82.0s) +``` + +From a second terminal in the same checkout, follow along with: + +```bash +specfuse-loop --watch # the single active feature +specfuse-loop --watch --feature +``` + +It shows the unit, attempt, phase, current gate and elapsed time. On a terminal +it redraws one line; otherwise it prints a line only when the unit, attempt, +phase or gate changes. It prints `no update for Ns` when the status has not been +rewritten for three heartbeat intervals. It only reads, takes no lock, and exits +`0` when the run stops, or `1` when there is no status file. + +**Status file.** `--watch` reads `/work/STATUS.json`, which is never +committed. It holds `feature`, `wu_id`, `attempt`, `max_attempts`, `phase` +(`agent`, `gate`, `between` or `stopped`), `gate`, `started_at`, `updated_at`, +`elapsed_seconds`, `files_touched` and `stop_reason`. While an attempt runs the +driver rewrites it every 30 seconds. To change the interval, set it in +`.specfuse/verification.yml` (a positive integer; anything else means 30): + +```yaml +defaults: + heartbeat_seconds: 10 +``` + +### Being told when the run stops + +`specfuse-loop` sends one notification each time a run stops, with one of these +reasons, the first that applies: + +| Reason | The run | +|--------|---------| +| `halted` | escalated to you | +| `awaiting_review` | reached a gate that now awaits your review | +| `complete` | left `PLAN.md` at `done` | +| `error` | ended with an exception | +| `stopped` | ended any other way | + +Both channels are set under `escalation` in `.specfuse/agent-policy.yml`, and +each is used only when configured: + +- **Chat webhook:** `webhook_env` and `provider`. `quiet_hours` applies. +- **Command:** `notify_command`, for example a desktop notifier. It is split + into an argument list and never run through a shell, and has 30 seconds. It + receives `SPECFUSE_STOP_REASON`, `SPECFUSE_FEATURE`, `SPECFUSE_WORK_UNIT` + (empty when no unit applies) and `SPECFUSE_MESSAGE` in its environment. + `quiet_hours` does not apply to it. + +```yaml +escalation: + notify_command: "terminal-notifier -title specfuse -message 'run stopped'" +``` + +A failed notification is logged and does not change the exit code. `--dry-run` +and `--watch` send nothing. The reason is also written to the status file's +`stop_reason`. + ## 6. The gate boundary — where you come back in A gate ends with a **closing sequence** that runs automatically: it writes a diff --git a/specfuse/loop/agent_policy.py b/specfuse/loop/agent_policy.py index cdcc316b..e802e9bc 100644 --- a/specfuse/loop/agent_policy.py +++ b/specfuse/loop/agent_policy.py @@ -70,6 +70,7 @@ _ESCALATION_KNOWN_KEYS = frozenset(_REQUIRED_ESCALATION_FIELDS) | { "provider", "silence_hours", + "notify_command", } # An environment-variable-NAME reference, not a secret value — same shape @@ -956,6 +957,14 @@ def _check_escalation(escalation: object) -> list[str]: f"environment-variable NAME, not a value (got {webhook_env!r})" ) + if "notify_command" in escalation: + notify_command = escalation["notify_command"] + if not isinstance(notify_command, str): + findings.append( + f"ERROR: 'escalation.notify_command' must be a string " + f"(got {notify_command!r})" + ) + if "provider" in escalation: provider = escalation["provider"] if provider not in PROVIDER_VALUES: diff --git a/specfuse/loop/data/docs/getting-started.md b/specfuse/loop/data/docs/getting-started.md index dd2c7515..2c01f31e 100644 --- a/specfuse/loop/data/docs/getting-started.md +++ b/specfuse/loop/data/docs/getting-started.md @@ -176,6 +176,76 @@ failure evidence, up to three attempts, then the unit is escalated to > To run two features at once, use separate `git worktree` checkouts. `--dry-run` > is exempt. +### Watching a run + +While a unit runs, the driver prints one plain line per phase change: the agent +session starting and finishing, and each verification gate starting and then +finishing with `PASS` or `FAIL` and its duration. + +``` + [14:02:11] agent session started + [14:06:08] agent session finished (237.4s) + [14:06:08] gate tests started + [14:07:30] gate tests PASS (82.0s) +``` + +From a second terminal in the same checkout, follow along with: + +```bash +specfuse-loop --watch # the single active feature +specfuse-loop --watch --feature +``` + +It shows the unit, attempt, phase, current gate and elapsed time. On a terminal +it redraws one line; otherwise it prints a line only when the unit, attempt, +phase or gate changes. It prints `no update for Ns` when the status has not been +rewritten for three heartbeat intervals. It only reads, takes no lock, and exits +`0` when the run stops, or `1` when there is no status file. + +**Status file.** `--watch` reads `/work/STATUS.json`, which is never +committed. It holds `feature`, `wu_id`, `attempt`, `max_attempts`, `phase` +(`agent`, `gate`, `between` or `stopped`), `gate`, `started_at`, `updated_at`, +`elapsed_seconds`, `files_touched` and `stop_reason`. While an attempt runs the +driver rewrites it every 30 seconds. To change the interval, set it in +`.specfuse/verification.yml` (a positive integer; anything else means 30): + +```yaml +defaults: + heartbeat_seconds: 10 +``` + +### Being told when the run stops + +`specfuse-loop` sends one notification each time a run stops, with one of these +reasons, the first that applies: + +| Reason | The run | +|--------|---------| +| `halted` | escalated to you | +| `awaiting_review` | reached a gate that now awaits your review | +| `complete` | left `PLAN.md` at `done` | +| `error` | ended with an exception | +| `stopped` | ended any other way | + +Both channels are set under `escalation` in `.specfuse/agent-policy.yml`, and +each is used only when configured: + +- **Chat webhook:** `webhook_env` and `provider`. `quiet_hours` applies. +- **Command:** `notify_command`, for example a desktop notifier. It is split + into an argument list and never run through a shell, and has 30 seconds. It + receives `SPECFUSE_STOP_REASON`, `SPECFUSE_FEATURE`, `SPECFUSE_WORK_UNIT` + (empty when no unit applies) and `SPECFUSE_MESSAGE` in its environment. + `quiet_hours` does not apply to it. + +```yaml +escalation: + notify_command: "terminal-notifier -title specfuse -message 'run stopped'" +``` + +A failed notification is logged and does not change the exit code. `--dry-run` +and `--watch` send nothing. The reason is also written to the status file's +`stop_reason`. + ## 6. The gate boundary — where you come back in A gate ends with a **closing sequence** that runs automatically: it writes a diff --git a/specfuse/loop/loop.py b/specfuse/loop/loop.py index b2725b9a..ee2a2557 100644 --- a/specfuse/loop/loop.py +++ b/specfuse/loop/loop.py @@ -12447,6 +12447,8 @@ def run( _override_ns = argparse.Namespace(force_full_close=force_full_close) _override_active, _override_reason = resolve_auto_close_override(_override_ns, feature_dir) events_path = feature_dir / "events.jsonl" + _progress.remember_run( + feature_id, feature_dir, events_path, load_graph=load_graph) work_dir = feature_dir / "work" backend = make_backend(feat_fm) backend.on_feature_start(feature_id, feat_fm) @@ -12503,6 +12505,7 @@ def run( try: lock_fd = acquire_tree_lock(SPECFUSE_DIR) except BlockingIOError: + _progress.disown_status() print( "another loop driver is already running in this working tree " "(.specfuse/.loop.lock held)", @@ -15095,9 +15098,18 @@ def main() -> int: # the run cannot continue, so the run does not continue. print(f"ERROR: {exc}", file=sys.stderr) return 1 - return run(args.feature, args.dry_run, force_full_close=args.force_full_close, - prepare=args.prepare, prepare_only=args.prepare_only, - no_baseline_probe=args.no_baseline_probe) + _progress.forget_run() + raised = True + try: + rc = run(args.feature, args.dry_run, + force_full_close=args.force_full_close, + prepare=args.prepare, prepare_only=args.prepare_only, + no_baseline_probe=args.no_baseline_probe) + raised = False + return rc + finally: + if not args.dry_run: + _progress.notify_stop(raised=raised, feature_arg=args.feature) if __name__ == "__main__": diff --git a/specfuse/loop/progress.py b/specfuse/loop/progress.py index 86afc090..73df2da5 100644 --- a/specfuse/loop/progress.py +++ b/specfuse/loop/progress.py @@ -19,6 +19,9 @@ `watch` is the `specfuse-loop --watch` reader, run from a second terminal. It only reads the status file: it takes no run lock and writes nothing. +`notify_stop` runs once, after `run()` has ended: it works out why the run +stopped from the events that run appended, and tells the operator. + Reports only; no merge, arm or close verdict reads anything written here. """ @@ -26,8 +29,11 @@ import datetime as dt import json +import logging import os +import shlex import shutil +import subprocess import sys import threading import time @@ -35,6 +41,10 @@ from pathlib import Path from typing import Callable +from . import agent_policy, notify + +logger = logging.getLogger(__name__) + STATUS_FILENAME = "STATUS.json" PHASE_AGENT = "agent" @@ -265,6 +275,183 @@ def gate_finished(name: str, ok: bool, duration_seconds: float) -> None: _say(f"gate {name} {'PASS' if ok else 'FAIL'} ({duration_seconds:.1f}s)") +_NOTIFY_TIMEOUT_SECONDS = 30 + + +@dataclass +class _Stop: + """What `notify_stop` needs once `run()` has ended.""" + + feature: str + feature_dir: Path + events_path: Path + events_offset: int + load_graph: Callable + owns_status: bool = True + + +_stop: "_Stop | None" = None + + +def remember_run( + feature: str, feature_dir: Path, events_path: Path, *, + load_graph: Callable, +) -> None: + """Call as the run starts, before it appends any event.""" + global _stop + try: + offset = Path(events_path).stat().st_size + except OSError: + offset = 0 + _stop = _Stop(feature, Path(feature_dir), Path(events_path), offset, + load_graph) + + +def disown_status() -> None: + """Another driver holds the tree: its status file is not ours to write.""" + if _stop is not None: + _stop.owns_status = False + + +def forget_run() -> None: + global _stop + _stop = None + + +def _events_since(path: Path, offset: int) -> "list[dict]": + try: + with path.open("rb") as fh: + fh.seek(offset) + lines = fh.read().decode("utf-8", errors="replace").splitlines() + except OSError: + return [] + events = [] + for line in lines: + try: + event = json.loads(line) + except ValueError: + continue + if isinstance(event, dict): + events.append(event) + return events + + +def _stop_reason( + stop: "_Stop | None", events: "list[dict]", raised: bool, +) -> str: + fallback = "error" if raised else "stopped" + if stop is None: + return fallback + if any(e.get("event_type") == "human_escalation" for e in events): + return "halted" + try: + plan, gates = stop.load_graph(stop.feature_dir) + except (Exception, SystemExit): # noqa: BLE001 — an unreadable plan + return fallback + reached = {(e.get("payload") or {}).get("gate") for e in events + if e.get("event_type") == "gate_reached"} + if any(g.number in reached and g.status == "awaiting_review" + for g in gates): + return "awaiting_review" + if plan.get("status") == "done": + return "complete" + return fallback + + +def _stop_work_unit(events: "list[dict]") -> str: + """The unit of the last escalation, else the last unit the run wrote + about. A feature-level escalation may name the unit it halted before.""" + escalations = [e for e in events + if e.get("event_type") == "human_escalation"] + if escalations: + last = escalations[-1] + unit = str(last.get("correlation_id", "")) + if "/" in unit: + return unit + return str((last.get("payload") or {}).get("next_wu_id") or "") + for event in reversed(events): + unit = str(event.get("correlation_id", "")) + if "/" in unit: + return unit + return "" + + +def _run_notify_command(env: "dict[str, str]") -> None: + """Run `escalation.notify_command`, when set, as an argument list.""" + try: + policy = agent_policy.load_policy(None) + except FileNotFoundError: + return + escalation = policy.get("escalation") if isinstance(policy, dict) else None + command = (escalation.get("notify_command") + if isinstance(escalation, dict) else None) + if not isinstance(command, str) or not command.strip(): + return + try: + done = subprocess.run( + shlex.split(command), env={**os.environ, **env}, + timeout=_NOTIFY_TIMEOUT_SECONDS, stdin=subprocess.DEVNULL, + stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, + check=False) + except (OSError, ValueError, subprocess.SubprocessError) as exc: + # The exception's text repeats the command, which may hold a token. + logger.warning("notify_command failed: %s", type(exc).__name__) + return + if done.returncode != 0: + logger.warning("notify_command exited %s", done.returncode) + + +def notify_stop(*, raised: bool, feature_arg: "str | None" = None) -> None: + """Record why the run stopped and send it once to each configured channel. + + Never raises: reporting does not change how a run ends. A run that failed + before it found its feature is reported under *feature_arg*. + """ + global _stop + stop, _stop = _stop, None + try: + events = ([] if stop is None + else _events_since(stop.events_path, stop.events_offset)) + reason = _stop_reason(stop, events, raised) + feature = stop.feature if stop else (feature_arg or "") + unit = _stop_work_unit(events) + if stop is not None and stop.owns_status: + _write_stop_reason(stop, reason) + message = f"specfuse-loop {reason}: {feature or 'unknown feature'}" + if unit: + message += f" (last unit {unit})" + except Exception as exc: # noqa: BLE001 + logger.warning("stop notification not built: %s", type(exc).__name__) + return + try: + notify.post_notification(message) + except Exception as exc: # noqa: BLE001 + logger.warning("stop webhook failed: %s", type(exc).__name__) + try: + _run_notify_command({ + "SPECFUSE_STOP_REASON": reason, + "SPECFUSE_FEATURE": feature, + "SPECFUSE_WORK_UNIT": unit, + "SPECFUSE_MESSAGE": message, + }) + except Exception as exc: # noqa: BLE001 + logger.warning("notify_command failed: %s", type(exc).__name__) + + +def _write_stop_reason(stop: _Stop, reason: str) -> None: + """Set `stop_reason` on the status file. A run that ended before + `begin_run` replaces whatever an earlier run left there.""" + now = _now() + status = _read_status(status_path(stop.feature_dir)) or { + "feature": stop.feature, "wu_id": None, "attempt": None, + "max_attempts": None, "started_at": now, "elapsed_seconds": 0.0, + "files_touched": [], + } + status.update(phase=PHASE_STOPPED, gate=None, updated_at=now, + stop_reason=reason) + write_status(stop.feature_dir, status) + + # A watcher is stale after this many heartbeat intervals without a rewrite. _STALE_INTERVALS = 3 _WATCH_POLL_SECONDS = 1.0 diff --git a/tests/test_run_progress.py b/tests/test_run_progress.py index c65db6b4..08c246b7 100644 --- a/tests/test_run_progress.py +++ b/tests/test_run_progress.py @@ -4,7 +4,7 @@ # """FEAT-LOOP-2026-0252 gate 1 oracle — a running unit's progress is visible. One class per Definition-of-done clause in GATE-01.md. T01 implements clauses -1, 2 and 4, T02 clause 3; the rest are skipped naming their owning unit. +1, 2 and 4, T02 clause 3, T03 clause 5, T04 clause 6. Every run goes through `loop.run()` in a temporary repository, with a stubbed agent session and two real stub gate commands. What must be on disk while the @@ -20,6 +20,7 @@ import json import os import re +import shlex import subprocess import sys import tempfile @@ -29,7 +30,7 @@ from pathlib import Path from unittest import mock -from specfuse.loop import validate_event +from specfuse.loop import notify, progress, validate_event from tests._loop_loader import load_loop from tests._workspace import integration_workspace, write_stub_deliverable @@ -561,12 +562,225 @@ def test_no_status_file_names_the_expected_path(self): f".specfuse/features/{FEATURE_ID}-{SLUG}/work/STATUS.json", err) -@unittest.skip("FEAT-LOOP-2026-0252/T04") -class TestStopNotification(unittest.TestCase): - """Clause 6 — owned by T04.""" +_STUB_COMMAND = ( + "import json, os, sys\n" + "seen = {k: v for k, v in os.environ.items() " + "if k.startswith('SPECFUSE_')}\n" + "open(sys.argv[1], 'a').write(" + "json.dumps({'argv': sys.argv[1:], 'env': seen}) + '\\n')\n" +) +_NOTIFY_VARS = ( + "SPECFUSE_STOP_REASON", "SPECFUSE_FEATURE", "SPECFUSE_WORK_UNIT", + "SPECFUSE_MESSAGE", +) + + +def _passing_session(wu, failure_note, cost_tracking=True): + write_stub_deliverable(wu) + return "```result\nstatus: complete\n```\n" + + +def _blocked_session(wu, failure_note, cost_tracking=True): + return ("```result\nstatus: blocked\n" + "blocked_reason: needs a human\n```\n") + - def test_placeholder(self): - self.fail("T04 replaces this class") +def _raising_session(wu, failure_note, cost_tracking=True): + raise _SessionBoom() + + +class _Notified: + """One `loop.main()` over the real `run()`, with a counting webhook poster + and a stub notify command that records each call outside the tree.""" + + def __init__(self, session=_passing_session, *, command="stub", + webhook=True, argv=(), prepare=None): + self.posts = [] + self.rc = self.raised = self.status = None + with integration_workspace() as root, \ + tempfile.TemporaryDirectory() as outside: + cwd = os.getcwd() + os.chdir(root) + try: + self._run(root, Path(outside), session, command, webhook, + argv, prepare) + finally: + os.chdir(cwd) + + def _run(self, root, outside, session, command, webhook, argv, prepare): + fdir = _scaffold(root, outside) + stub = outside / "stub.py" + stub.write_text(_STUB_COMMAND) + calls = outside / "calls.jsonl" + if command == "stub": + command = shlex.join([sys.executable, str(stub), str(calls)]) + lines = ["escalation:", + f" webhook_env: {'FIXTURE_HOOK' if webhook else chr(34) * 2}", + f" provider: {'slack' if webhook else 'none'}"] + if command is not None: + lines.append(f" notify_command: {json.dumps(command)}") + (root / ".specfuse/agent-policy.yml").write_text( + "\n".join(lines) + "\n") + if prepare is not None: + prepare(fdir) + subprocess.run(["git", "add", "."], check=True) + subprocess.run(["git", "commit", "-q", "-m", "policy"], check=True) + + def poster(url, payload): + self.posts.append((url, payload)) + return 200 + + out = io.StringIO() + with mock.patch.object(sys, "argv", ["specfuse-loop", *argv]), \ + mock.patch.dict(os.environ, + {"FIXTURE_HOOK": "https://example.com/hook"}), \ + mock.patch.object(notify, "_default_poster", poster), \ + mock.patch.object(loop, "_reexec_pinned", lambda _a: None), \ + mock.patch.object(loop, "auto_sync"), \ + mock.patch.object(loop, "dispatch", session), \ + contextlib.redirect_stdout(out), \ + contextlib.redirect_stderr(out): + try: + self.rc = loop.main() + except (_SessionBoom, SystemExit) as exc: + self.raised = exc + self.output = out.getvalue() + self.commands = [json.loads(ln) for ln in + calls.read_text().splitlines()] \ + if calls.exists() else [] + status = fdir / "work" / "STATUS.json" + if status.is_file(): + self.status = json.loads(status.read_text()) + self.pwned = list(root.rglob("pwned")) + + +def _all_passed(fdir): + for name, old, new in (("GATE-01.md", "open", "passed"), + ("PLAN.md", "active", "done")): + path = fdir / name + path.write_text(path.read_text().replace( + f"status: {old}", f"status: {new}")) + + +def _draft_unit(fdir): + path = fdir / "WU-T01.md" + path.write_text(path.read_text().replace( + "status: pending", "status: draft")) + + +class TestStopNotification(unittest.TestCase): + """Clause 6 — one notification when the run stops.""" + + def _assert_notified(self, seen, reason, unit): + self.assertEqual(len(seen.posts), 1, seen.output) + self.assertEqual(len(seen.commands), 1, seen.output) + env = seen.commands[0]["env"] + for name in _NOTIFY_VARS: + self.assertIn(name, env) + self.assertEqual(env["SPECFUSE_STOP_REASON"], reason, seen.output) + self.assertEqual(env["SPECFUSE_FEATURE"], FEATURE_ID) + self.assertEqual(env["SPECFUSE_WORK_UNIT"], unit, seen.output) + self.assertIn(reason, env["SPECFUSE_MESSAGE"]) + self.assertEqual(seen.posts[0][1], {"text": env["SPECFUSE_MESSAGE"]}) + self.assertEqual(len(seen.commands[0]["argv"]), 1) + self.assertEqual(seen.status["phase"], "stopped") + self.assertEqual(seen.status["stop_reason"], reason) + + def test_halted(self): + seen = _Notified(_blocked_session) + self._assert_notified(seen, "halted", WU_ID) + + def test_awaiting_review(self): + seen = _Notified() + self.assertEqual(seen.rc, 0, seen.output) + self._assert_notified(seen, "awaiting_review", WU_ID) + + def test_complete(self): + seen = _Notified(prepare=_all_passed, + argv=("--feature", FEATURE_ID)) + self.assertEqual(seen.rc, 0, seen.output) + self._assert_notified(seen, "complete", "") + + def test_error(self): + seen = _Notified(_raising_session) + self.assertIsInstance(seen.raised, _SessionBoom, seen.output) + self._assert_notified(seen, "error", WU_ID) + + def test_stopped(self): + seen = _Notified(prepare=_draft_unit) + self.assertEqual(seen.rc, 2, seen.output) + self._assert_notified(seen, "stopped", "") + + def test_events_of_an_earlier_run_are_not_read(self): + def earlier(fdir): + _draft_unit(fdir) + (fdir / "events.jsonl").write_text(json.dumps({ + "event_type": "human_escalation", + "correlation_id": WU_ID, "payload": {}}) + "\n") + + self._assert_notified(_Notified(prepare=earlier), "stopped", "") + + def test_a_held_lock_leaves_the_other_drivers_status_alone(self): + live = _status() + + def other_driver(fdir): + (fdir / "work").mkdir() + (fdir / "work" / ".gitignore").write_text("*\n") + (fdir / "work" / "STATUS.json").write_text(json.dumps(live)) + + with mock.patch.object(loop, "acquire_tree_lock", + side_effect=BlockingIOError): + seen = _Notified(prepare=other_driver) + self.assertEqual(seen.rc, 1, seen.output) + self.assertEqual(len(seen.commands), 1, seen.output) + self.assertEqual(seen.status, live) + + def test_a_failing_command_leaves_the_exit_code_unchanged(self): + python = shlex.quote(sys.executable) + for label, command in ( + ("exit 1", f"{python} -c 'raise SystemExit(1)'"), + ("timeout", f"{python} -c 'import time; time.sleep(20)'"), + ("missing", "specfuse-no-such-program-fixture"), + ("unbalanced quote", "echo 'x"), + ): + with self.subTest(label), \ + mock.patch.object(progress, "_NOTIFY_TIMEOUT_SECONDS", 1), \ + self.assertLogs(progress.logger, "WARNING"): + started = time.monotonic() + seen = _Notified(command=command) + self.assertEqual(seen.rc, 0, seen.output) + self.assertIsNone(seen.raised) + self.assertEqual(len(seen.posts), 1) + self.assertLess(time.monotonic() - started, 15) + + def test_the_command_timeout_is_thirty_seconds(self): + self.assertEqual(progress._NOTIFY_TIMEOUT_SECONDS, 30) + + def test_nothing_configured_sends_nothing(self): + with mock.patch.object(progress.subprocess, "run", + wraps=subprocess.run) as ran: + seen = _Notified(command=None, webhook=False) + self.assertEqual(seen.rc, 0, seen.output) + self.assertEqual((seen.posts, seen.commands), ([], [])) + self.assertEqual( + [c for c in ran.call_args_list + if "SPECFUSE_MESSAGE" in (c.kwargs.get("env") or {})], []) + + def test_dry_run_sends_nothing(self): + seen = _Notified(argv=("--dry-run",)) + self.assertEqual(seen.rc, 0, seen.output) + self.assertEqual((seen.posts, seen.commands), ([], [])) + + def test_message_never_reaches_a_shell(self): + hostile = "FEAT-X; touch pwned" + seen = _Notified(argv=("--feature", hostile)) + self.assertIsInstance(seen.raised, SystemExit, seen.output) + self.assertEqual(len(seen.commands), 1, seen.output) + env = seen.commands[0]["env"] + self.assertIn("; touch pwned", env["SPECFUSE_MESSAGE"]) + self.assertEqual(env["SPECFUSE_STOP_REASON"], "error") + self.assertEqual(len(seen.commands[0]["argv"]), 1) + self.assertEqual(seen.pwned, []) if __name__ == "__main__": From 48b4e847056cdb2434110a71750fbf0ce1e04ae9 Mon Sep 17 00:00:00 2001 From: Test Date: Thu, 26 Nov 2026 22:34:05 -0500 Subject: [PATCH 09/25] chore(loop): gate 1 broad run clean Feature: FEAT-LOOP-2026-0252 --- .../GATE-01-CRITERIA.md | 101 ++++++++++++++++++ .../GATE-01.md | 5 + .../events.jsonl | 32 ++++++ 3 files changed, 138 insertions(+) create mode 100644 .specfuse/features/FEAT-LOOP-2026-0252-run-progress/GATE-01-CRITERIA.md diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/GATE-01-CRITERIA.md b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/GATE-01-CRITERIA.md new file mode 100644 index 00000000..e44ad2b3 --- /dev/null +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/GATE-01-CRITERIA.md @@ -0,0 +1,101 @@ +### T01#1 + +- **criterion:** `tests.test_run_progress.TestPhaseEvents` fails on HEAD and passes after. Through +- **state:** `unverified` +- **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, specfuse/loop/arm_eval.py, specfuse/loop/data/schemas/driver-event.schema.json, tests/test_run_progress.py + +### T01#2 + +- **criterion:** `TestStatusFile` passes: during the session the stub reads `STATUS.json` with every field +- **state:** `unverified` +- **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, specfuse/loop/arm_eval.py, specfuse/loop/data/schemas/driver-event.schema.json, tests/test_run_progress.py + +### T01#3 + +- **criterion:** `TestDriverLines` passes: captured driver output has one line per phase change and contains +- **state:** `unverified` +- **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, specfuse/loop/arm_eval.py, specfuse/loop/data/schemas/driver-event.schema.json, tests/test_run_progress.py + +### T01#4 + +- **criterion:** `python3 -m unittest tests.test_judge_path_registry tests.test_driver_event_registry_covers_emitters tests.test_validate_event_driver_types tests.test_gate_timings tests.test_dispatch_skeleton -b` +- **state:** `unverified` +- **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, specfuse/loop/arm_eval.py, specfuse/loop/data/schemas/driver-event.schema.json, tests/test_run_progress.py + +### T02#1 + +- **criterion:** `tests.test_run_progress.TestHeartbeat` fails on HEAD and passes after (remove its skip). +- **state:** `unverified` +- **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, .specfuse/verification.yml.example, specfuse/loop/data/verification.yml.example, tests/test_run_progress.py + +### T02#2 + +- **criterion:** After `run()` returns, and after an attempt whose stubbed session raises, no thread started +- **state:** `unverified` +- **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, .specfuse/verification.yml.example, specfuse/loop/data/verification.yml.example, tests/test_run_progress.py + +### T02#3 + +- **criterion:** `resolve_heartbeat_seconds` returns 30 for a missing key, `"x"`, `0` and `-5`, and 7 for `7`. +- **state:** `unverified` +- **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, .specfuse/verification.yml.example, specfuse/loop/data/verification.yml.example, tests/test_run_progress.py + +### T02#4 + +- **criterion:** `python3 -m unittest tests.test_fail_fast_deliverables tests.test_dispatch_skeleton -b` +- **state:** `unverified` +- **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, .specfuse/verification.yml.example, specfuse/loop/data/verification.yml.example, tests/test_run_progress.py + +### T03#1 + +- **criterion:** `tests.test_run_progress.TestWatch` fails on HEAD and passes after (remove its skip). Given +- **state:** `unverified` +- **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, tests/test_run_progress.py + +### T03#2 + +- **criterion:** An `updated_at` older than three heartbeat intervals prints `no update for Ns`. +- **state:** `unverified` +- **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, tests/test_run_progress.py + +### T03#3 + +- **criterion:** `phase: stopped` ends the watch with exit 0; no status file exits 1 with a message naming +- **state:** `unverified` +- **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, tests/test_run_progress.py + +### T03#4 + +- **criterion:** `python3 -m unittest tests.test_dispatch_skeleton -b` passes. +- **state:** `unverified` +- **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, tests/test_run_progress.py + +### T04#1 + +- **criterion:** `tests.test_run_progress.TestStopNotification` fails on HEAD and passes after (remove its +- **state:** `unverified` +- **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, specfuse/loop/agent_policy.py, .specfuse/agent-policy.yml.example, docs/getting-started.md, specfuse/loop/data/docs/getting-started.md, tests/test_run_progress.py + +### T04#2 + +- **criterion:** A command that exits 1, one that sleeps past the timeout (patched to 1 s in the test) and +- **state:** `unverified` +- **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, specfuse/loop/agent_policy.py, .specfuse/agent-policy.yml.example, docs/getting-started.md, specfuse/loop/data/docs/getting-started.md, tests/test_run_progress.py + +### T04#3 + +- **criterion:** A message containing `; touch pwned` does not create `pwned`. +- **state:** `unverified` +- **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, specfuse/loop/agent_policy.py, .specfuse/agent-policy.yml.example, docs/getting-started.md, specfuse/loop/data/docs/getting-started.md, tests/test_run_progress.py + +### T04#4 + +- **criterion:** `python3 -m unittest tests.test_agent_policy_schema tests.test_notify tests.test_notify_escalation -b` +- **state:** `unverified` +- **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, specfuse/loop/agent_policy.py, .specfuse/agent-policy.yml.example, docs/getting-started.md, specfuse/loop/data/docs/getting-started.md, tests/test_run_progress.py + +### T04#5 + +- **criterion:** `tests.test_run_progress` has no `unittest.skip` left. +- **state:** `unverified` +- **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, specfuse/loop/agent_policy.py, .specfuse/agent-policy.yml.example, docs/getting-started.md, specfuse/loop/data/docs/getting-started.md, tests/test_run_progress.py diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/GATE-01.md b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/GATE-01.md index 7dab41c8..12112081 100644 --- a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/GATE-01.md +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/GATE-01.md @@ -3,6 +3,11 @@ gate: 1 status: open feature_oracle: "python3 -m unittest tests.test_run_progress -v -b" cost_budget_usd: 18.00 +broad_run: + tree: 07bbf72d1e7af3c1a03af605f40e5563dc3a18db:0ec7c6da6e74f0b56753f09657b654a6d289b91b:12064a6191eeb830a9826d911a8543fbaba3da75:21853f95bd08cd0c5cd8f5fe0caad3f248ba8e72:27968248a450a842ccd187b7dce0fb0ded934866:287efde8f90320baffac08f5f3287b9456a65cb9:2e29b2f7e073a0cbe290f01d3b397e1cdd10c81c:3e6b8329522b39869d0b9caf5e22bf61f1a87ec0:42796ea0e0a6c03811b0e4bc9dbd3b5ee62dd2e4:4acc6dfc5e8cece358c167d876515eba4a39a500:6f70c7c8afa618acb6b7b66ad5b035d661250dc6:834d9d9c16094a386cd9b5a6f9ced9a3a9b4e7fb:bbd1aea514612d76722a18c7aece7c767cf1a076:c23b62e87f1ae3890c6f9e3d8c7ca7ec9225ed81:caffe2d63ceacde448842a91bc7a12c206a67523:d74b7d113b844e84f0009098f576fd28477f072d:e3b0de29b81a6c8e0abeacb3898519b98014b9ef:f1126d17cf8e5a0a44edefbee7cb726fab9cf3a2:fa2f4f88657587b6e3b560977858810846b1d366 + ran_at: 2026-11-27T03:34:05.038818+00:00 + ok: true + failing: [] --- # Gate 1 — a running unit's progress is visible, and the operator is notified once when the run stops diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl index a10c4351..c2100b14 100644 --- a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl @@ -39,3 +39,35 @@ {"timestamp": "2026-11-27T03:18:08.839645+00:00", "correlation_id": "FEAT-LOOP-2026-0252/T03", "event_type": "attempt_outcome", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "outcome": "passed", "duration_seconds": 137.331, "agent_seconds": 112.18943454197142, "verify_seconds": 24.958582791965455, "cost_usd": 0.4469357, "input_tokens": 24, "output_tokens": 11063, "cache_read_input_tokens": 788097, "cache_creation_input_tokens": 64362, "model": "sonnet", "effort": "medium", "failure_class": null, "failure_signature": null, "failure_excerpt": null, "files_touched": [".specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-03-watch.md", ".specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl", "specfuse/loop/loop.py", "specfuse/loop/progress.py", "tests/test_run_progress.py"], "agent_status": "complete", "agent_blocked_reason": null, "re_arm_count": 0, "failing_tests": []}} {"timestamp": "2026-11-27T03:18:08.840001+00:00", "correlation_id": "FEAT-LOOP-2026-0252/T03", "event_type": "task_completed", "source": "driver", "source_version": "0.33.2", "payload": {"attempts": 1, "attempts_usage": [{"attempt": 1, "duration_seconds": 137.331, "cost_usd": 0.4469357, "input_tokens": 24, "output_tokens": 11063, "cache_read_input_tokens": 788097, "cache_creation_input_tokens": 64362, "agent_seconds": 112.18943454197142, "verify_seconds": 24.958582791965455}], "type": "implementation", "re_arm_count": 0, "cost_usd": 0.446936, "cumulative_cost_usd": 0.446936, "attempts_lifetime": 1, "planned_cost_usd": 2.0}} {"timestamp": "2026-11-27T03:18:08.853380+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "driver_staleness_detected", "source": "driver", "source_version": "0.33.2", "payload": {"gate": 1, "wu_id": "FEAT-LOOP-2026-0252/T03", "driver_paths": ["specfuse/loop/loop.py", "specfuse/loop/progress.py"], "halted": false, "reason": "driver_restart_required", "pinned_tree": "f903f87239abf0c7dc90999ff3c7c79c295c30a4", "next_pin_tree": "0bc35ad83b292fc4d4800be791f51cb04baaaf33"}} +{"timestamp": "2026-11-27T03:18:08.982331+00:00", "correlation_id": "FEAT-LOOP-2026-0252/T04", "event_type": "task_started", "source": "driver", "source_version": "0.33.2", "payload": {"type": "implementation", "model": "sonnet", "re_arm_count": 0}} +{"timestamp": "2026-11-27T03:23:36.500212+00:00", "correlation_id": "FEAT-LOOP-2026-0252/T04", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "gate": "tests", "ok": true, "skipped": false, "duration_seconds": 27.524, "phase": "attempt"}} +{"timestamp": "2026-11-27T03:23:36.500255+00:00", "correlation_id": "FEAT-LOOP-2026-0252/T04", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "gate": "lint", "ok": true, "skipped": false, "duration_seconds": 0.111, "phase": "attempt"}} +{"timestamp": "2026-11-27T03:23:36.500261+00:00", "correlation_id": "FEAT-LOOP-2026-0252/T04", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "gate": "changelog-fragments", "ok": true, "skipped": false, "duration_seconds": 0.13, "phase": "attempt"}} +{"timestamp": "2026-11-27T03:23:36.500264+00:00", "correlation_id": "FEAT-LOOP-2026-0252/T04", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "gate": "agent-policy-example-lint", "ok": true, "skipped": false, "duration_seconds": 0.229, "phase": "attempt"}} +{"timestamp": "2026-11-27T03:23:36.500266+00:00", "correlation_id": "FEAT-LOOP-2026-0252/T04", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "gate": "event-type-gate", "ok": true, "skipped": false, "duration_seconds": 0.591, "phase": "attempt"}} +{"timestamp": "2026-11-27T03:23:36.500268+00:00", "correlation_id": "FEAT-LOOP-2026-0252/T04", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "gate": "roadmap-link-gate", "ok": true, "skipped": false, "duration_seconds": 0.099, "phase": "attempt"}} +{"timestamp": "2026-11-27T03:23:36.500271+00:00", "correlation_id": "FEAT-LOOP-2026-0252/T04", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "gate": "arm-sweep-gate", "ok": true, "skipped": false, "duration_seconds": 1.204, "phase": "attempt"}} +{"timestamp": "2026-11-27T03:23:36.500274+00:00", "correlation_id": "FEAT-LOOP-2026-0252/T04", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "gate": "monitoring-example-lint", "ok": true, "skipped": false, "duration_seconds": 0.154, "phase": "attempt"}} +{"timestamp": "2026-11-27T03:23:36.500282+00:00", "correlation_id": "FEAT-LOOP-2026-0252/T04", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "gate": "feature_oracle", "ok": true, "skipped": false, "duration_seconds": 26.847, "phase": "attempt"}} +{"timestamp": "2026-11-27T03:23:37.003483+00:00", "correlation_id": "FEAT-LOOP-2026-0252/T04", "event_type": "attempt_outcome", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "outcome": "passed", "duration_seconds": 327.456, "agent_seconds": 269.68607466609683, "verify_seconds": 57.04017204197589, "cost_usd": 0.7198355000000001, "input_tokens": 26, "output_tokens": 19711, "cache_read_input_tokens": 1126495, "cache_creation_input_tokens": 102506, "model": "sonnet", "effort": "medium", "failure_class": null, "failure_signature": null, "failure_excerpt": null, "files_touched": [".specfuse/agent-policy.yml.example", ".specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-04-stop-notification-and-docs.md", ".specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl", "docs/getting-started.md", "specfuse/loop/agent_policy.py", "specfuse/loop/data/docs/getting-started.md", "specfuse/loop/loop.py", "specfuse/loop/progress.py", "tests/test_run_progress.py"], "agent_status": "complete", "agent_blocked_reason": null, "re_arm_count": 0, "failing_tests": []}} +{"timestamp": "2026-11-27T03:23:37.003988+00:00", "correlation_id": "FEAT-LOOP-2026-0252/T04", "event_type": "task_completed", "source": "driver", "source_version": "0.33.2", "payload": {"attempts": 1, "attempts_usage": [{"attempt": 1, "duration_seconds": 327.456, "cost_usd": 0.7198355000000001, "input_tokens": 26, "output_tokens": 19711, "cache_read_input_tokens": 1126495, "cache_creation_input_tokens": 102506, "agent_seconds": 269.68607466609683, "verify_seconds": 57.04017204197589}], "type": "implementation", "re_arm_count": 0, "cost_usd": 0.719836, "cumulative_cost_usd": 0.719836, "attempts_lifetime": 1, "planned_cost_usd": 2.5}} +{"timestamp": "2026-11-27T03:23:37.021514+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "driver_staleness_detected", "source": "driver", "source_version": "0.33.2", "payload": {"gate": 1, "wu_id": "FEAT-LOOP-2026-0252/T04", "driver_paths": ["specfuse/loop/agent_policy.py", "specfuse/loop/loop.py", "specfuse/loop/progress.py"], "halted": false, "reason": "driver_restart_required", "pinned_tree": "f903f87239abf0c7dc90999ff3c7c79c295c30a4", "next_pin_tree": "e95597d58f64ab835d912abeaad2af291b7c1c71"}} +{"timestamp": "2026-11-27T03:34:05.056801+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "broad_run_result", "source": "driver", "source_version": "0.33.2", "payload": {"gate": 1, "tree": "07bbf72d1e7af3c1a03af605f40e5563dc3a18db:0ec7c6da6e74f0b56753f09657b654a6d289b91b:12064a6191eeb830a9826d911a8543fbaba3da75:21853f95bd08cd0c5cd8f5fe0caad3f248ba8e72:27968248a450a842ccd187b7dce0fb0ded934866:287efde8f90320baffac08f5f3287b9456a65cb9:2e29b2f7e073a0cbe290f01d3b397e1cdd10c81c:3e6b8329522b39869d0b9caf5e22bf61f1a87ec0:42796ea0e0a6c03811b0e4bc9dbd3b5ee62dd2e4:4acc6dfc5e8cece358c167d876515eba4a39a500:6f70c7c8afa618acb6b7b66ad5b035d661250dc6:834d9d9c16094a386cd9b5a6f9ced9a3a9b4e7fb:bbd1aea514612d76722a18c7aece7c767cf1a076:c23b62e87f1ae3890c6f9e3d8c7ca7ec9225ed81:caffe2d63ceacde448842a91bc7a12c206a67523:d74b7d113b844e84f0009098f576fd28477f072d:e3b0de29b81a6c8e0abeacb3898519b98014b9ef:f1126d17cf8e5a0a44edefbee7cb726fab9cf3a2:fa2f4f88657587b6e3b560977858810846b1d366", "ok": true, "failing": []}} +{"timestamp": "2026-11-27T03:34:05.056852+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "tests", "ok": true, "skipped": false, "duration_seconds": 577.574, "phase": "broad"}} +{"timestamp": "2026-11-27T03:34:05.056860+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "lint", "ok": true, "skipped": false, "duration_seconds": 0.07, "phase": "broad"}} +{"timestamp": "2026-11-27T03:34:05.056864+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "security", "ok": true, "skipped": false, "duration_seconds": 1.782, "phase": "broad"}} +{"timestamp": "2026-11-27T03:34:05.056876+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "coverage", "ok": true, "skipped": false, "duration_seconds": 1.391, "phase": "broad"}} +{"timestamp": "2026-11-27T03:34:05.056880+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "leak-scan", "ok": true, "skipped": false, "duration_seconds": 22.15, "phase": "broad"}} +{"timestamp": "2026-11-27T03:34:05.056882+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "changelog-fragments", "ok": true, "skipped": false, "duration_seconds": 0.085, "phase": "broad"}} +{"timestamp": "2026-11-27T03:34:05.056884+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "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.142, "phase": "broad"}} +{"timestamp": "2026-11-27T03:34:05.056886+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "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.207, "phase": "broad"}} +{"timestamp": "2026-11-27T03:34:05.056893+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "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.065, "phase": "broad"}} +{"timestamp": "2026-11-27T03:34:05.056895+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "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.519, "phase": "broad"}} +{"timestamp": "2026-11-27T03:34:05.056896+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "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.071, "phase": "broad"}} +{"timestamp": "2026-11-27T03:34:05.056898+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "leak-scan-hook", "ok": true, "skipped": false, "duration_seconds": 1.179, "phase": "broad"}} +{"timestamp": "2026-11-27T03:34:05.056899+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "pre-push-hook", "ok": true, "skipped": false, "duration_seconds": 4.052, "phase": "broad"}} +{"timestamp": "2026-11-27T03:34:05.056900+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "sync-scaffold-bats", "ok": true, "skipped": false, "duration_seconds": 14.351, "phase": "broad"}} +{"timestamp": "2026-11-27T03:34:05.056902+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "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": 2.291, "phase": "broad"}} +{"timestamp": "2026-11-27T03:34:05.056903+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "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": 1.102, "phase": "broad"}} +{"timestamp": "2026-11-27T03:34:05.056904+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "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.171, "phase": "broad"}} +{"timestamp": "2026-11-27T03:34:05.056906+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "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.761, "phase": "broad"}} From 03ddb71fc2307a568aa7603faf2b57387779550e Mon Sep 17 00:00:00 2001 From: Test Date: Thu, 26 Nov 2026 22:34:05 -0500 Subject: [PATCH 10/25] chore(loop): FEAT-LOOP-2026-0252/G1-CLOSE blocked (judge-editing terminal gate) Feature: FEAT-LOOP-2026-0252 --- .../FEAT-LOOP-2026-0252-run-progress/WU-90-gate-1-close.md | 2 +- .../features/FEAT-LOOP-2026-0252-run-progress/events.jsonl | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-90-gate-1-close.md b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-90-gate-1-close.md index bbfd8d8d..803b56ad 100644 --- a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-90-gate-1-close.md +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-90-gate-1-close.md @@ -1,7 +1,7 @@ --- id: FEAT-LOOP-2026-0252/G1-CLOSE type: close -status: pending +status: blocked_human attempts: 0 planned_cost_usd: 5.00 auto_close_disabled: true diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl index c2100b14..fba6c621 100644 --- a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl @@ -71,3 +71,5 @@ {"timestamp": "2026-11-27T03:34:05.056903+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "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": 1.102, "phase": "broad"}} {"timestamp": "2026-11-27T03:34:05.056904+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "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.171, "phase": "broad"}} {"timestamp": "2026-11-27T03:34:05.056906+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "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.761, "phase": "broad"}} +{"timestamp": "2026-11-27T03:34:05.196599+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "terminal_judge_editing_evaluated", "source": "driver", "source_version": "0.33.2", "payload": {"gate": 1, "status": "fired", "reason": "FEAT-LOOP-2026-0252/T01 produces specfuse/loop/loop.py; FEAT-LOOP-2026-0252/T01 produces specfuse/loop/arm_eval.py; FEAT-LOOP-2026-0252/T01 produces specfuse/loop/data/schemas/driver-event.schema.json; FEAT-LOOP-2026-0252/T01 declares produces_driver_helper ['execute_unit_attempt', '_run_gate_set']; FEAT-LOOP-2026-0252/T02 produces specfuse/loop/loop.py; FEAT-LOOP-2026-0252/T02 produces .specfuse/verification.yml.example; FEAT-LOOP-2026-0252/T02 produces specfuse/loop/data/verification.yml.example; FEAT-LOOP-2026-0252/T02 declares produces_driver_helper ['resolve_heartbeat_seconds']; FEAT-LOOP-2026-0252/T03 produces specfuse/loop/loop.py; FEAT-LOOP-2026-0252/T03 declares produces_driver_helper ['main']; FEAT-LOOP-2026-0252/T04 produces specfuse/loop/loop.py; FEAT-LOOP-2026-0252/T04 produces specfuse/loop/agent_policy.py; FEAT-LOOP-2026-0252/T04 declares produces_driver_helper ['main']"}} +{"timestamp": "2026-11-27T03:34:05.200398+00:00", "correlation_id": "FEAT-LOOP-2026-0252/G1-CLOSE", "event_type": "human_escalation", "source": "driver", "source_version": "0.33.2", "payload": {"reason": "judge_editing_terminal", "gate": 1, "hits": ["FEAT-LOOP-2026-0252/T01 produces specfuse/loop/loop.py", "FEAT-LOOP-2026-0252/T01 produces specfuse/loop/arm_eval.py", "FEAT-LOOP-2026-0252/T01 produces specfuse/loop/data/schemas/driver-event.schema.json", "FEAT-LOOP-2026-0252/T01 declares produces_driver_helper ['execute_unit_attempt', '_run_gate_set']", "FEAT-LOOP-2026-0252/T02 produces specfuse/loop/loop.py", "FEAT-LOOP-2026-0252/T02 produces .specfuse/verification.yml.example", "FEAT-LOOP-2026-0252/T02 produces specfuse/loop/data/verification.yml.example", "FEAT-LOOP-2026-0252/T02 declares produces_driver_helper ['resolve_heartbeat_seconds']", "FEAT-LOOP-2026-0252/T03 produces specfuse/loop/loop.py", "FEAT-LOOP-2026-0252/T03 declares produces_driver_helper ['main']", "FEAT-LOOP-2026-0252/T04 produces specfuse/loop/loop.py", "FEAT-LOOP-2026-0252/T04 produces specfuse/loop/agent_policy.py", "FEAT-LOOP-2026-0252/T04 declares produces_driver_helper ['main']"], "message": "ESCALATED \u2014 FEAT-LOOP-2026-0252/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-0252/T01, FEAT-LOOP-2026-0252/T02, FEAT-LOOP-2026-0252/T03, FEAT-LOOP-2026-0252/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-0252/T01 produces specfuse/loop/loop.py; FEAT-LOOP-2026-0252/T01 produces specfuse/loop/arm_eval.py; FEAT-LOOP-2026-0252/T01 produces specfuse/loop/data/schemas/driver-event.schema.json; FEAT-LOOP-2026-0252/T01 declares produces_driver_helper ['execute_unit_attempt', '_run_gate_set']; FEAT-LOOP-2026-0252/T02 produces specfuse/loop/loop.py; FEAT-LOOP-2026-0252/T02 produces .specfuse/verification.yml.example; FEAT-LOOP-2026-0252/T02 produces specfuse/loop/data/verification.yml.example; FEAT-LOOP-2026-0252/T02 declares produces_driver_helper ['resolve_heartbeat_seconds']; FEAT-LOOP-2026-0252/T03 produces specfuse/loop/loop.py; FEAT-LOOP-2026-0252/T03 declares produces_driver_helper ['main']; FEAT-LOOP-2026-0252/T04 produces specfuse/loop/loop.py; FEAT-LOOP-2026-0252/T04 produces specfuse/loop/agent_policy.py; FEAT-LOOP-2026-0252/T04 declares produces_driver_helper ['main'].\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-0252/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 - .specfuse/verification.yml.example\n - produces_driver_helper\n - specfuse/loop/agent_policy.py\n - specfuse/loop/arm_eval.py\n - specfuse/loop/data/schemas/driver-event.schema.json\n - specfuse/loop/data/verification.yml.example\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-0252\n\n"}} From a0913370159a93b510aaaa43bfdb45dafecb6bbf Mon Sep 17 00:00:00 2001 From: Test Date: Thu, 26 Nov 2026 22:36:01 -0500 Subject: [PATCH 11/25] =?UTF-8?q?chore(loop):=20FEAT-LOOP-2026-0252=20?= =?UTF-8?q?=E2=80=94=20operator=20acknowledged=20judge=20edits,=20re-arm?= =?UTF-8?q?=20G1-CLOSE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- .../WU-90-gate-1-close.md | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-90-gate-1-close.md b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-90-gate-1-close.md index 803b56ad..266adebd 100644 --- a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-90-gate-1-close.md +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-90-gate-1-close.md @@ -1,12 +1,31 @@ --- id: FEAT-LOOP-2026-0252/G1-CLOSE type: close -status: blocked_human +status: pending attempts: 0 planned_cost_usd: 5.00 auto_close_disabled: true model: sonnet effort: high +judge_edit_acknowledged: + paths: + - .specfuse/verification.yml.example + - produces_driver_helper + - specfuse/loop/agent_policy.py + - specfuse/loop/arm_eval.py + - specfuse/loop/data/schemas/driver-event.schema.json + - specfuse/loop/data/verification.yml.example + - specfuse/loop/loop.py + reason: "Driver changes reviewed and sound, accept them" +re_arm_count: 1 +re_arm_history: + - + timestamp: 2026-11-27T03:36:01+00:00 + prior_status: blocked_human + prior_attempts: 0 + prior_cost_usd: 0.0 + prior_duration_seconds: 0.0 + reason: "Driver changes reviewed and sound, accept them" --- # G1-CLOSE — terminal close From cdb4c6055e2e3ca3c3dc35d8fccacc4e22862010 Mon Sep 17 00:00:00 2001 From: Test Date: Thu, 26 Nov 2026 22:36:05 -0500 Subject: [PATCH 12/25] chore(loop): FEAT-LOOP-2026-0252 build pin recorded Feature: FEAT-LOOP-2026-0252 --- .specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl | 1 + 1 file changed, 1 insertion(+) diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl index fba6c621..2892524d 100644 --- a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl @@ -73,3 +73,4 @@ {"timestamp": "2026-11-27T03:34:05.056906+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "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.761, "phase": "broad"}} {"timestamp": "2026-11-27T03:34:05.196599+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "terminal_judge_editing_evaluated", "source": "driver", "source_version": "0.33.2", "payload": {"gate": 1, "status": "fired", "reason": "FEAT-LOOP-2026-0252/T01 produces specfuse/loop/loop.py; FEAT-LOOP-2026-0252/T01 produces specfuse/loop/arm_eval.py; FEAT-LOOP-2026-0252/T01 produces specfuse/loop/data/schemas/driver-event.schema.json; FEAT-LOOP-2026-0252/T01 declares produces_driver_helper ['execute_unit_attempt', '_run_gate_set']; FEAT-LOOP-2026-0252/T02 produces specfuse/loop/loop.py; FEAT-LOOP-2026-0252/T02 produces .specfuse/verification.yml.example; FEAT-LOOP-2026-0252/T02 produces specfuse/loop/data/verification.yml.example; FEAT-LOOP-2026-0252/T02 declares produces_driver_helper ['resolve_heartbeat_seconds']; FEAT-LOOP-2026-0252/T03 produces specfuse/loop/loop.py; FEAT-LOOP-2026-0252/T03 declares produces_driver_helper ['main']; FEAT-LOOP-2026-0252/T04 produces specfuse/loop/loop.py; FEAT-LOOP-2026-0252/T04 produces specfuse/loop/agent_policy.py; FEAT-LOOP-2026-0252/T04 declares produces_driver_helper ['main']"}} {"timestamp": "2026-11-27T03:34:05.200398+00:00", "correlation_id": "FEAT-LOOP-2026-0252/G1-CLOSE", "event_type": "human_escalation", "source": "driver", "source_version": "0.33.2", "payload": {"reason": "judge_editing_terminal", "gate": 1, "hits": ["FEAT-LOOP-2026-0252/T01 produces specfuse/loop/loop.py", "FEAT-LOOP-2026-0252/T01 produces specfuse/loop/arm_eval.py", "FEAT-LOOP-2026-0252/T01 produces specfuse/loop/data/schemas/driver-event.schema.json", "FEAT-LOOP-2026-0252/T01 declares produces_driver_helper ['execute_unit_attempt', '_run_gate_set']", "FEAT-LOOP-2026-0252/T02 produces specfuse/loop/loop.py", "FEAT-LOOP-2026-0252/T02 produces .specfuse/verification.yml.example", "FEAT-LOOP-2026-0252/T02 produces specfuse/loop/data/verification.yml.example", "FEAT-LOOP-2026-0252/T02 declares produces_driver_helper ['resolve_heartbeat_seconds']", "FEAT-LOOP-2026-0252/T03 produces specfuse/loop/loop.py", "FEAT-LOOP-2026-0252/T03 declares produces_driver_helper ['main']", "FEAT-LOOP-2026-0252/T04 produces specfuse/loop/loop.py", "FEAT-LOOP-2026-0252/T04 produces specfuse/loop/agent_policy.py", "FEAT-LOOP-2026-0252/T04 declares produces_driver_helper ['main']"], "message": "ESCALATED \u2014 FEAT-LOOP-2026-0252/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-0252/T01, FEAT-LOOP-2026-0252/T02, FEAT-LOOP-2026-0252/T03, FEAT-LOOP-2026-0252/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-0252/T01 produces specfuse/loop/loop.py; FEAT-LOOP-2026-0252/T01 produces specfuse/loop/arm_eval.py; FEAT-LOOP-2026-0252/T01 produces specfuse/loop/data/schemas/driver-event.schema.json; FEAT-LOOP-2026-0252/T01 declares produces_driver_helper ['execute_unit_attempt', '_run_gate_set']; FEAT-LOOP-2026-0252/T02 produces specfuse/loop/loop.py; FEAT-LOOP-2026-0252/T02 produces .specfuse/verification.yml.example; FEAT-LOOP-2026-0252/T02 produces specfuse/loop/data/verification.yml.example; FEAT-LOOP-2026-0252/T02 declares produces_driver_helper ['resolve_heartbeat_seconds']; FEAT-LOOP-2026-0252/T03 produces specfuse/loop/loop.py; FEAT-LOOP-2026-0252/T03 declares produces_driver_helper ['main']; FEAT-LOOP-2026-0252/T04 produces specfuse/loop/loop.py; FEAT-LOOP-2026-0252/T04 produces specfuse/loop/agent_policy.py; FEAT-LOOP-2026-0252/T04 declares produces_driver_helper ['main'].\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-0252/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 - .specfuse/verification.yml.example\n - produces_driver_helper\n - specfuse/loop/agent_policy.py\n - specfuse/loop/arm_eval.py\n - specfuse/loop/data/schemas/driver-event.schema.json\n - specfuse/loop/data/verification.yml.example\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-0252\n\n"}} +{"timestamp": "2026-11-27T03:36:05.854238+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "driver_build_pinned", "source": "driver", "source_version": "0.33.2", "payload": {"tree": "e9e8ef336de8752d0551e6b93e2ebb273c925a81", "path": "/private/var/folders/zc/rgq11x850d78dx_kf1fd4vx80000gn/T/specfuse-pins/e9e8ef336de8752d0551e6b93e2ebb273c925a81/specfuse/loop"}} From 7c37f9580bfe8daef0a23907c837cfd773c4e59b Mon Sep 17 00:00:00 2001 From: Test Date: Thu, 26 Nov 2026 22:42:56 -0500 Subject: [PATCH 13/25] =?UTF-8?q?feat:=20G1-CLOSE=20=E2=80=94=20terminal?= =?UTF-8?q?=20close?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Feature: FEAT-LOOP-2026-0252/G1-CLOSE --- .../FOLLOW-UPS.md | 54 ++++ .../GATE-01-CRITERIA.md | 102 ++++++-- .../LEARNINGS-pending.md | 20 ++ .../PROGRESS.md | 2 + .../RETROSPECTIVE.md | 235 ++++++++++++++++++ .../WU-90-gate-1-close.md | 18 +- .../events.jsonl | 8 + ...specfuse-loop-watch-feature-f-follows-a.md | 5 + ...he-driver-prints-one-plain-line-per-pha.md | 5 + ...when-a-specfuse-loop-run-ends-not-under.md | 5 + ...hile-a-feature-runs-the-driver-keeps-fe.md | 5 + 11 files changed, 440 insertions(+), 19 deletions(-) create mode 100644 .specfuse/features/FEAT-LOOP-2026-0252-run-progress/FOLLOW-UPS.md create mode 100644 .specfuse/features/FEAT-LOOP-2026-0252-run-progress/LEARNINGS-pending.md create mode 100644 .specfuse/features/FEAT-LOOP-2026-0252-run-progress/RETROSPECTIVE.md create mode 100644 changelog.d/FEAT-LOOP-2026-0252-specfuse-loop-watch-feature-f-follows-a.md create mode 100644 changelog.d/FEAT-LOOP-2026-0252-the-driver-prints-one-plain-line-per-pha.md create mode 100644 changelog.d/FEAT-LOOP-2026-0252-when-a-specfuse-loop-run-ends-not-under.md create mode 100644 changelog.d/FEAT-LOOP-2026-0252-while-a-feature-runs-the-driver-keeps-fe.md diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/FOLLOW-UPS.md b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/FOLLOW-UPS.md new file mode 100644 index 00000000..6b7d04f5 --- /dev/null +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/FOLLOW-UPS.md @@ -0,0 +1,54 @@ +# Follow-ups — FEAT-LOOP-2026-0252 + +First close of gate 1. One entry is open. + +### Definition of done clause 6 (stop reason when the event log changes during `run()`) + +**Criterion, verbatim:** "**Stop notification.** Each return from `run()` (and each exception +out of it) sends exactly one notification. Its `stop_reason` is `halted` when this run wrote +a `human_escalation`, else `awaiting_review` when it wrote `gate_reached` and the gate is +`awaiting_review`, else `complete` when `PLAN.md` is `done`, else `error` when `run()` +raised, else `stopped`. The message goes to `notify.post_notification` when a webhook is +configured, and to `escalation.notify_command` when set: run as an argument list +(`shlex.split`, never a shell) with `SPECFUSE_STOP_REASON`, `SPECFUSE_FEATURE`, +`SPECFUSE_WORK_UNIT` and `SPECFUSE_MESSAGE` in its environment and a 30 s timeout. A command +that fails, hangs or does not exist is logged and does not change `run()`'s exit code. With +neither configured, or under `--dry-run`, nothing is sent or run. The `agent-policy.yml` +validator accepts a string `escalation.notify_command` and reports an ERROR for any other +type." + +**What fails:** the `stop_reason` rule only. `remember_run` stores the size of +`events.jsonl` before `ensure_feature_branch` can check out the feature branch. +`notify_stop` reads from that offset in the file that is there afterwards. Lines from +earlier runs can then count as this run's, or this run's lines can be skipped. The +`WU` named in the message comes from the same lines. + +**Evidence.** Both probes drive `loop.main()` through `_Notified` from +`tests/test_run_progress.py` and wrap `ensure_feature_branch` to rewrite the log as a +checkout would. The checkout is simulated. + +- command: `PYTHONPATH=. python3 /probe_offset.py` +- exit: 0 +- output: `control (log unchanged by checkout): rc=0 posts=1 commands=1 + reason=awaiting_review`, then `checkout brings an earlier run's escalation: rc=0 posts=1 + commands=1 reason=halted` +- command: `PYTHONPATH=. python3 /probe_converse.py` +- exit: 0 +- output: `control: rc=1 commands=1 reason=halted unit='FEAT-LOOP-2026-9999/T01'`, then + `checkout shortens the log: rc=1 commands=1 reason=stopped unit=''` + +The scratch scripts do not outlive the session. To rebuild the first one: wrap +`loop.ensure_feature_branch`, call the real function, append one `human_escalation` line to +`/events.jsonl`, run `_Notified()` and read `SPECFUSE_STOP_REASON`. + +**Re-run condition.** A test through `loop.main()`, in which the run starts on a branch +other than the feature branch and the two branches hold different `events.jsonl` files (a +real checkout), passes both ways: (a) an older `human_escalation` only on the feature branch, +and a run that reaches the gate, reports `awaiting_review`; (b) a starting log longer than +the feature branch's, and a run that halts, reports `halted` and names the halted unit. The +existing `TestStopNotification` tests stay green. + +**Possible fix, not tried.** Take the offset after the branch has been entered, keeping an +early one for returns that happen before that. Check the `--prepare` and `--prepare-only` +paths, which also switch branches, and the `driver_build_pinned` line written before the +switch. diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/GATE-01-CRITERIA.md b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/GATE-01-CRITERIA.md index e44ad2b3..b746b85f 100644 --- a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/GATE-01-CRITERIA.md +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/GATE-01-CRITERIA.md @@ -1,101 +1,169 @@ ### T01#1 - **criterion:** `tests.test_run_progress.TestPhaseEvents` fails on HEAD and passes after. Through -- **state:** `unverified` +- **oracle:** python3 -m unittest tests.test_run_progress -v -b (class TestPhaseEvents), exit 0 +- **kind:** `narrow` +- **state:** `pass` +- **proved_at_sha:** `cdb4c60` +- **attempt:** `1` - **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, specfuse/loop/arm_eval.py, specfuse/loop/data/schemas/driver-event.schema.json, tests/test_run_progress.py ### T01#2 - **criterion:** `TestStatusFile` passes: during the session the stub reads `STATUS.json` with every field -- **state:** `unverified` +- **oracle:** python3 -m unittest tests.test_run_progress -v -b (class TestStatusFile), exit 0 +- **kind:** `narrow` +- **state:** `pass` +- **proved_at_sha:** `cdb4c60` +- **attempt:** `1` - **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, specfuse/loop/arm_eval.py, specfuse/loop/data/schemas/driver-event.schema.json, tests/test_run_progress.py ### T01#3 - **criterion:** `TestDriverLines` passes: captured driver output has one line per phase change and contains -- **state:** `unverified` +- **oracle:** python3 -m unittest tests.test_run_progress -v -b (class TestDriverLines), exit 0 +- **kind:** `narrow` +- **state:** `pass` +- **proved_at_sha:** `cdb4c60` +- **attempt:** `1` - **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, specfuse/loop/arm_eval.py, specfuse/loop/data/schemas/driver-event.schema.json, tests/test_run_progress.py ### T01#4 - **criterion:** `python3 -m unittest tests.test_judge_path_registry tests.test_driver_event_registry_covers_emitters tests.test_validate_event_driver_types tests.test_gate_timings tests.test_dispatch_skeleton -b` -- **state:** `unverified` +- **oracle:** python3 -m unittest tests.test_judge_path_registry tests.test_driver_event_registry_covers_emitters tests.test_validate_event_driver_types tests.test_gate_timings tests.test_dispatch_skeleton -b (run within the 10-module command in RETROSPECTIVE.md), exit 0 +- **kind:** `narrow` +- **state:** `pass` +- **proved_at_sha:** `cdb4c60` +- **attempt:** `1` - **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, specfuse/loop/arm_eval.py, specfuse/loop/data/schemas/driver-event.schema.json, tests/test_run_progress.py ### T02#1 - **criterion:** `tests.test_run_progress.TestHeartbeat` fails on HEAD and passes after (remove its skip). -- **state:** `unverified` +- **oracle:** python3 -m unittest tests.test_run_progress -v -b (class TestHeartbeat), exit 0 +- **kind:** `narrow` +- **state:** `pass` +- **proved_at_sha:** `cdb4c60` +- **attempt:** `1` - **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, .specfuse/verification.yml.example, specfuse/loop/data/verification.yml.example, tests/test_run_progress.py ### T02#2 - **criterion:** After `run()` returns, and after an attempt whose stubbed session raises, no thread started -- **state:** `unverified` +- **oracle:** python3 -m unittest tests.test_run_progress -v -b (class TestHeartbeat), exit 0 +- **kind:** `narrow` +- **state:** `pass` +- **proved_at_sha:** `cdb4c60` +- **attempt:** `1` - **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, .specfuse/verification.yml.example, specfuse/loop/data/verification.yml.example, tests/test_run_progress.py ### T02#3 - **criterion:** `resolve_heartbeat_seconds` returns 30 for a missing key, `"x"`, `0` and `-5`, and 7 for `7`. -- **state:** `unverified` +- **oracle:** python3 -m unittest tests.test_run_progress -v -b (class TestHeartbeat), exit 0 +- **kind:** `narrow` +- **state:** `pass` +- **proved_at_sha:** `cdb4c60` +- **attempt:** `1` - **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, .specfuse/verification.yml.example, specfuse/loop/data/verification.yml.example, tests/test_run_progress.py ### T02#4 - **criterion:** `python3 -m unittest tests.test_fail_fast_deliverables tests.test_dispatch_skeleton -b` -- **state:** `unverified` +- **oracle:** python3 -m unittest tests.test_fail_fast_deliverables tests.test_dispatch_skeleton -b (run within the 10-module command in RETROSPECTIVE.md), exit 0 +- **kind:** `narrow` +- **state:** `pass` +- **proved_at_sha:** `cdb4c60` +- **attempt:** `1` - **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, .specfuse/verification.yml.example, specfuse/loop/data/verification.yml.example, tests/test_run_progress.py ### T03#1 - **criterion:** `tests.test_run_progress.TestWatch` fails on HEAD and passes after (remove its skip). Given -- **state:** `unverified` +- **oracle:** python3 -m unittest tests.test_run_progress -v -b (class TestWatch), exit 0 +- **kind:** `narrow` +- **state:** `pass` +- **proved_at_sha:** `cdb4c60` +- **attempt:** `1` - **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, tests/test_run_progress.py ### T03#2 - **criterion:** An `updated_at` older than three heartbeat intervals prints `no update for Ns`. -- **state:** `unverified` +- **oracle:** python3 -m unittest tests.test_run_progress -v -b (class TestWatch), exit 0 +- **kind:** `narrow` +- **state:** `pass` +- **proved_at_sha:** `cdb4c60` +- **attempt:** `1` - **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, tests/test_run_progress.py ### T03#3 - **criterion:** `phase: stopped` ends the watch with exit 0; no status file exits 1 with a message naming -- **state:** `unverified` +- **oracle:** python3 -m unittest tests.test_run_progress -v -b (class TestWatch), exit 0 +- **kind:** `narrow` +- **state:** `pass` +- **proved_at_sha:** `cdb4c60` +- **attempt:** `1` - **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, tests/test_run_progress.py ### T03#4 - **criterion:** `python3 -m unittest tests.test_dispatch_skeleton -b` passes. -- **state:** `unverified` +- **oracle:** python3 -m unittest tests.test_dispatch_skeleton -b (run within the 10-module command in RETROSPECTIVE.md), exit 0 +- **kind:** `narrow` +- **state:** `pass` +- **proved_at_sha:** `cdb4c60` +- **attempt:** `1` - **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, tests/test_run_progress.py ### T04#1 - **criterion:** `tests.test_run_progress.TestStopNotification` fails on HEAD and passes after (remove its -- **state:** `unverified` +- **oracle:** python3 -m unittest tests.test_run_progress -v -b (class TestStopNotification), exit 0 +- **kind:** `narrow` +- **state:** `pass` +- **proved_at_sha:** `cdb4c60` +- **attempt:** `1` - **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, specfuse/loop/agent_policy.py, .specfuse/agent-policy.yml.example, docs/getting-started.md, specfuse/loop/data/docs/getting-started.md, tests/test_run_progress.py ### T04#2 - **criterion:** A command that exits 1, one that sleeps past the timeout (patched to 1 s in the test) and -- **state:** `unverified` +- **oracle:** python3 -m unittest tests.test_run_progress -v -b (class TestStopNotification), exit 0 +- **kind:** `narrow` +- **state:** `pass` +- **proved_at_sha:** `cdb4c60` +- **attempt:** `1` - **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, specfuse/loop/agent_policy.py, .specfuse/agent-policy.yml.example, docs/getting-started.md, specfuse/loop/data/docs/getting-started.md, tests/test_run_progress.py ### T04#3 - **criterion:** A message containing `; touch pwned` does not create `pwned`. -- **state:** `unverified` +- **oracle:** python3 -m unittest tests.test_run_progress -v -b (class TestStopNotification), exit 0 +- **kind:** `narrow` +- **state:** `pass` +- **proved_at_sha:** `cdb4c60` +- **attempt:** `1` - **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, specfuse/loop/agent_policy.py, .specfuse/agent-policy.yml.example, docs/getting-started.md, specfuse/loop/data/docs/getting-started.md, tests/test_run_progress.py ### T04#4 - **criterion:** `python3 -m unittest tests.test_agent_policy_schema tests.test_notify tests.test_notify_escalation -b` -- **state:** `unverified` +- **oracle:** python3 -m unittest tests.test_agent_policy_schema tests.test_notify tests.test_notify_escalation -b (run within the 10-module command in RETROSPECTIVE.md), exit 0 ; validate_agent_policy rejects a list and an int +- **kind:** `narrow` +- **state:** `pass` +- **proved_at_sha:** `cdb4c60` +- **attempt:** `1` - **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, specfuse/loop/agent_policy.py, .specfuse/agent-policy.yml.example, docs/getting-started.md, specfuse/loop/data/docs/getting-started.md, tests/test_run_progress.py ### T04#5 - **criterion:** `tests.test_run_progress` has no `unittest.skip` left. -- **state:** `unverified` +- **oracle:** grep of tests/test_run_progress.py for skip markers, no match (grep exit 1) +- **kind:** `narrow` +- **state:** `pass` +- **proved_at_sha:** `cdb4c60` +- **attempt:** `1` - **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, specfuse/loop/agent_policy.py, .specfuse/agent-policy.yml.example, docs/getting-started.md, specfuse/loop/data/docs/getting-started.md, tests/test_run_progress.py diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/LEARNINGS-pending.md b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/LEARNINGS-pending.md new file mode 100644 index 00000000..47fb4556 --- /dev/null +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/LEARNINGS-pending.md @@ -0,0 +1,20 @@ + + +# Lessons staged for promotion — FEAT-LOOP-2026-0252 + +`autonomy_default: auto`, so `FEAT-LOOP-2026-0252/G1-CLOSE` may not append to +`.specfuse/LEARNINGS.md` directly (`assert_learnings_staged_under_auto`). One entry +generalizes. + +## Entries + +- [FEAT-LOOP-2026-0252/G1-CLOSE] **A position remembered in a tracked file is not valid + across a branch checkout.** "What this run wrote" was read as everything in `events.jsonl` + after the byte size taken at the start of `run()`. `run()` can then switch to the feature + branch, which holds a different log, so older lines counted as new ones and new ones were + skipped. The test for "earlier runs are not read" kept one file for the whole run. When a + unit reads "only what this run wrote", list what can replace the file between the two + reads (checkout, reset, merge), and test at least one of them. diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/PROGRESS.md b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/PROGRESS.md index 35f90969..16d9053c 100644 --- a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/PROGRESS.md +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/PROGRESS.md @@ -5,3 +5,5 @@ - **FEAT-LOOP-2026-0252/T03**: Added `specfuse-loop --watch` (reader `watch()` in progress.py, wired in main() before build pin and auto_sync); replaced TestWatch placeholder with real tests. Narrow-tier gates and test_dispatch_skeleton pass (run with HOME in $TMPDIR because sandbox blocks ~/.claude/session-env). GATE-01 clause 5 "one of those" literally includes elapsed time; followed WU AC1 (elapsed-only change prints nothing). - **FEAT-LOOP-2026-0252/T04**: Added notify_stop (stop reason taken from this run's events and PLAN.md, written to STATUS.json, sent to the webhook and escalation.notify_command), called it from main(), and added the validator key, policy example, docs and TestStopNotification. - note: Close should note that every non-dry-run return from main()'s run() call notifies (including --prepare-only and a refused lock, which leaves the other driver's STATUS.json alone), and that quiet_hours gates only the webhook, not notify_command. +- **FEAT-LOOP-2026-0252/G1-CLOSE**: Terminal close recorded verdict not_met because the stop reason is wrong when events.jsonl changes under run() (reproduced in both directions with a simulated checkout); wrote the retrospective, one follow-up, one staged lesson, four changelog fragments and the state of all 17 criteria (disclosure - one read-only git ls-files was run early in the session, against the no-git rule). + - note: Fix where the events offset is taken relative to ensure_feature_branch (also check --prepare and --prepare-only), and test it through loop.main() with a real checkout between branches whose events.jsonl files differ. diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/RETROSPECTIVE.md b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/RETROSPECTIVE.md new file mode 100644 index 00000000..9f2ff42b --- /dev/null +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/RETROSPECTIVE.md @@ -0,0 +1,235 @@ +# Retrospective — FEAT-LOOP-2026-0252, run progress and stop notification + +## Gate 1 + +## Verdict + +`not_met` (advisory; the judge concludes). One Definition-of-done clause fails a probe run in +this session: clause 6. When `run()` switches to the feature branch and that branch holds a +different `events.jsonl`, the stop reason is worked out from the wrong lines. The probe got +`halted` from a run that wrote no `human_escalation`, and `stopped` from a run that did write +one. See `FOLLOW-UPS.md`. All 36 oracle tests and all 17 unit criteria pass. No test +exercises a log that changes during `run()`. + +## Measurements + +Everything here ran fresh in this close, unless a line says otherwise. Test runs and probes +used `HOME` under `$TMPDIR`. With the real `HOME` the sandbox blocks the driver's +`session-env` preflight: the first run of the oracle and of the named modules both exited 1 +(named modules: 153 tests, 34 errors; the traceback shown was that `SystemExit`). + +carried forward: 0 criteria, re-measured: 17 + +One breach of this unit's own rule: an early inspection command in this session included one +read-only `git ls-files` on the feature folder. No other git command was typed. The test and +probe fixtures run git inside their own temporary repositories. + +### feature_oracle: PASS + +`python3 -m unittest tests.test_run_progress -v -b`: exit 0, `Ran 36 tests`, `OK`, no skips. +A search of the file for `unittest.skip`, `skipTest`, `@skip`, `SkipTest` and +`expectedFailure` finds nothing (grep exit 1). + +**Control: the oracle goes red without the feature.** The current `tests/` was run against a +copy of the pre-feature driver (the build pinned at 03:04:41Z, before T01 started): exit 1, +`ImportError: cannot import name 'progress' from 'specfuse.loop'`. This shows the whole +module is red there. It does not show each class going red at its own unit's dispatch. + +### Unit-named modules + +`python3 -m unittest tests.test_judge_path_registry +tests.test_driver_event_registry_covers_emitters tests.test_validate_event_driver_types +tests.test_gate_timings tests.test_dispatch_skeleton tests.test_fail_fast_deliverables +tests.test_agent_policy_schema tests.test_notify tests.test_notify_escalation +tests.test_scaffold_data_in_sync -b`: exit 0, `Ran 153 tests`, `OK`. + +### Probe: the log changes while `run()` is running (clause 6 fails) + +`remember_run` stores the byte size of `events.jsonl` early in `run()` (`loop.py`, before +the lock). `ensure_feature_branch` runs later and can check out an existing feature branch. +`notify_stop` then reads from the stored offset in whatever file is there. + +Both probes drive `loop.main()` through the oracle's `_Notified` helper. They wrap +`ensure_feature_branch` so that, after it returns, the log holds what a checkout would bring +in. **The checkout is simulated by rewriting the file; no real branch with a different log +was used.** + +| Probe | Run | Control reason | Reason after the log changes | +|---|---|---|---| +| `probe_offset.py` | passing session; the log gains an older run's `human_escalation` | `awaiting_review` | `halted` | +| `probe_converse.py` | blocked session; the starting log is long, the new one is empty | `halted`, unit `…/T01` | `stopped`, unit empty | + +`PYTHONPATH=. python3 /probe_offset.py` and `…/probe_converse.py`: exit 0; each +run made exactly one command call. + +**Reachability, from reading the code.** The two pre-flight guards before the checkout, +`require_feature_folder_committed` and `require_feature_folder_unmodified`, look only at +untracked and uncommitted files. Neither compares the log with the feature branch's copy. +So a run started on another branch that holds the feature folder, with the feature branch +already there, reaches this path. A branch with no `events.jsonl` gives offset 0, so every +older escalation on the feature branch counts. This feature's own log already holds one +(`judge_editing_terminal`). + +### Clause 7: what changed outside the new code + +Compared with the pre-feature pinned build, using `diff` and `ast`: + +- `dispatch()` and `parse_claude_json_output()`: identical syntax trees. +- The 2 syntax nodes that name `attempt_outcome` (calls and builder functions): identical. + The full `loop.py` diff shows no change to how the payload is built. One input changed: + `_refusal_touched` now excludes `events.jsonl`, which keeps the driver's new mid-attempt + lines out of a refused attempt's `files_touched`. +- Functions changed in `loop.py`: `_paths_differing_from`, `_run_gate_set`, + `capture_working_tree_diff`, `execute_unit_attempt`, `main`, `run`. Added: + `heartbeat_files_touched`, `resolve_heartbeat_seconds`. None removed. +- `assert_implementation_touched_files` already ignores any `events.jsonl`, so the new + mid-attempt lines cannot count as a deliverable. + +### Live observation: this close attempt + +The driver that dispatched this close runs the feature's own code. + +- `events.jsonl` held `agent_session_started` (`attempt: 1`, 03:36:06Z) while the session + was running. No `task_started` for `G1-CLOSE` was in the file at that point: that event is + still buffered, so file order is not timestamp order. +- `work/STATUS.json` read `phase: agent`, with `elapsed_seconds` 150.4, 180.4, 210.5 and + 270.6 on successive reads, each a multiple of the 30 s beat. +- `python3 -m specfuse.loop.loop --watch --feature FEAT-LOOP-2026-0252`, run for 35 s from + inside the session with output piped: printed one line + (`… attempt 1/3 phase agent gate - elapsed 180s`), printed nothing for the next + elapsed-only rewrite, and was still watching when the probe killed it. +- `files_touched` was `[]` on those reads, taken before a beat had seen any write by this + session. The read at 331.3 s, after this session added the changelog fragments, listed all + four of them, and left out `events.jsonl` and the close's unit file, both modified. + +### Other oracles + +- `validate_agent_policy`: a string `notify_command` gives no finding about the key; `["a", + "b"]` and `5` each give `ERROR: 'escalation.notify_command' must be a string`. +- `cmp` finds both copies of `verification.yml.example` identical, and both copies of + `docs/getting-started.md` identical. +- `python3 -m specfuse.loop.changelog_fragments check`: exit 0. + +### Broad run (the driver's, not re-run here) + +`GATE-01.md` records `broad_run.ok: true` at 03:34:05Z. Its logs read `Ran 5199 tests`, +`OK (skipped=4)`, and total coverage 92% (`progress.py` 92%). This unit does not run the +broad tier. + +### Per-criterion results + +All 17 unit criteria pass on the oracle and named-module runs above; the entries are in +`GATE-01-CRITERIA.md`. "Fails on HEAD" is covered only by the whole-module control above. +The clause 6 failure is a gate-level case that no unit criterion states. + +## Definition of done, clause by clause + +| Clause | Result | Proved by (all in `tests/test_run_progress.py` unless named) | +|---|---|---| +| 1 phase events | proven | `TestPhaseEvents`: `test_order_and_payloads`, `test_events_validate_against_the_packaged_schemas`, `test_session_start_is_on_disk_while_the_session_runs`, `test_gate_start_is_on_disk_while_the_gate_runs`; plus the live observation | +| 2 status file | proven, with the note below on `stop_reason` | `TestStatusFile` (four tests); `TestStopNotification._assert_notified` for `stop_reason` | +| 3 heartbeat | proven | `TestHeartbeat` (four tests); `updated_at` advances at least twice, `notes/a.txt` listed, no thread left after return or raise | +| 4 driver lines | proven | `TestDriverLines` (two tests) | +| 5 watcher | proven, under the reading below | `TestWatch` (eight tests) | +| 6 stop notification | **not met** | `TestStopNotification` passes, including exactly-once counts, five reasons, failing commands, nothing configured, `--dry-run`, no shell. The probe above breaks the reason rule | +| 7 nothing else changes | proven | no pre-existing test changed (next section); syntax-tree comparison above; the driver's broad run | + +**No `unittest.skip` survives** in `tests/test_run_progress.py`. + +**Clause 2.** The clause is stated for runs driven through `loop.run()`. `stop_reason` is +set by `notify_stop`, which `main()` calls. After a direct `loop.run()` it stays `null`, and +`TestStatusFile.test_stopped_after_run_returns` asserts that `null`. The set value is proven +through `loop.main()` only. `pyproject.toml` points `specfuse-loop` at `main`, and a search +of `specfuse/` found no other caller of `run()`. T04's body told it to make the call from +`main()`. The same applies to clause 6's "each return from `run()`". + +**Clause 5.** "Prints a line only when one of those changes" follows a list that includes +elapsed time. T03 followed its own AC1 instead: an elapsed-only change prints nothing. T03 +said so in its progress note and did not block, although `GATE-01.md` asks a unit to block +on an ambiguous clause. The watcher also prints once when the file goes stale. + +## Pre-existing tests changed + +None. The four units' `attempt_outcome.files_touched` name one file under `tests/`, +`tests/test_run_progress.py`, which this feature created. `find tests -newermt` from the +feature's start, leaving out `__pycache__`, lists only that file. So clause 7's allowance +for edits forced by the new driver lines was not used. + +## What happened + +T01 to T04 each passed on the first attempt. The gate's broad run was clean. The driver then +stopped on `judge_editing_terminal`, as `PLAN.md` decision 6 expected. The operator +acknowledged it ("Driver changes reviewed and sound, accept them") and re-armed this close. +The pinned build stayed pre-feature for T01 to T04 (`driver_staleness_detected`, +`halted: false`), so their events carry no phase lines. This close is the first unit run by +the new code. + +The probe result comes from where the offset is taken. The oracle's earlier-run test +(`test_events_of_an_earlier_run_are_not_read`) keeps one file for the whole run, so it +cannot see this. + +## Cost analysis + +Actual figures are `cost_usd` from each unit's `task_completed` event in `events.jsonl`. + +| Unit | Planned USD | Actual USD | Actual / planned | Attempts | +|---|---|---|---|---| +| T01 | 2.50 | 1.27 | 51% | 1 | +| T02 | 2.50 | 0.45 | 18% | 1 | +| T03 | 2.00 | 0.45 | 22% | 1 | +| T04 | 2.50 | 0.72 | 29% | 1 | +| Substantive total | 9.50 | 2.89 | 30% | 4 | +| G1-CLOSE (this attempt, with its judge) | 5.00 | not yet recorded | — | in progress | +| Feature | 14.50 | 2.89 recorded | 20% so far | — | + +The gate budget is 18.00 USD. The judge-editing stop before this close recorded 0.00 cost +and 0 attempts (`re_arm_history`). + +## Consumer-visible contract changes + +Pending human acknowledgment. Each item has a `changelog.d/` fragment tracing to +`FEAT-LOOP-2026-0252`. The operator's judge-edit acknowledgment covers driver paths, not +this list. + +1. **Added:** one plain driver line per phase change, and the event types + `agent_session_started`, `agent_session_finished`, `gate_started` and `gate_finished`. + Gates run outside a unit carry `attempt: null`, from the code. `events.jsonl` order is no + longer timestamp order. +2. **Added:** `/work/STATUS.json` (with a `work/.gitignore` the driver writes if + absent) and `defaults.heartbeat_seconds`, default 30. +3. **Added:** `specfuse-loop --watch [--feature F]`. +4. **Added:** one stop notification through the escalation webhook, and the key + `escalation.notify_command`. A project that already has a webhook configured now gets a + message at the end of every non-dry-run run. The stop reason can be wrong in the case in + `FOLLOW-UPS.md`. + +## Notes for the human reviewer + +- From T04's note and the code: `--prepare-only` and a refused lock also notify. A refused + lock leaves the other driver's status file alone. `quiet_hours` holds back the webhook + (through `notify.post_notification`), not `notify_command`. +- A killed driver sends nothing and leaves the status file at its last phase. `--watch` + then shows `no update for Ns` and keeps waiting. +- `PLAN.md`'s post-merge checklist has no line for a real driver crash. This unit may not + edit `PLAN.md`; add one. +- The driver files the post-merge issue only on a `met` close. + +## What the loop did NOT verify + +- **Real desktop and chat delivery.** Only a counting stub poster and a stub command ran. + See `PLAN.md` "Post-merge checklist", second line (desktop notifier) and third (chat + webhook). +- **A real multi-minute attempt watched live.** The observation above is from inside this + attempt, with piped output, for 35 s. Nobody watched from a second terminal, saw the + in-place redraw on a real terminal, or saw the watcher follow a gate change. See + the checklist's first line. +- **A real driver crash.** Exceptions are simulated by a stub session that raises. No + process was killed. The post-merge checklist is the place for this check, but none of its + three lines covers it (see the reviewer note). +- **A real branch checkout with a different log.** Both clause 6 probes simulate it. +- **The 30 s command timeout in real time.** The test patches it to 1 s and asserts the + constant is 30. + +## Lessons + +Staged in `LEARNINGS-pending.md`. diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-90-gate-1-close.md b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-90-gate-1-close.md index 266adebd..1711631f 100644 --- a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-90-gate-1-close.md +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-90-gate-1-close.md @@ -1,8 +1,9 @@ --- id: FEAT-LOOP-2026-0252/G1-CLOSE type: close -status: pending -attempts: 0 +status: done +attempts: 1 +verdict: not_met planned_cost_usd: 5.00 auto_close_disabled: true model: sonnet @@ -26,6 +27,19 @@ re_arm_history: prior_cost_usd: 0.0 prior_duration_seconds: 0.0 reason: "Driver changes reviewed and sound, accept them" +cumulative_cost_usd: 0.0 +cumulative_duration_seconds: 0.0 +cumulative_input_tokens: 0 +cumulative_output_tokens: 0 +cumulative_attempts: 0 +cost_usd: 1.47429 +duration_seconds: 409.775 +input_tokens: 54 +output_tokens: 40064 +folded_through_re_arm: 1 +gate_set: plannext +driver_version: 0.33.2 +started_at: 2026-11-27T03:36:06.127327+00:00 --- # G1-CLOSE — terminal close diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl index 2892524d..84385ecc 100644 --- a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl @@ -74,3 +74,11 @@ {"timestamp": "2026-11-27T03:34:05.196599+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "terminal_judge_editing_evaluated", "source": "driver", "source_version": "0.33.2", "payload": {"gate": 1, "status": "fired", "reason": "FEAT-LOOP-2026-0252/T01 produces specfuse/loop/loop.py; FEAT-LOOP-2026-0252/T01 produces specfuse/loop/arm_eval.py; FEAT-LOOP-2026-0252/T01 produces specfuse/loop/data/schemas/driver-event.schema.json; FEAT-LOOP-2026-0252/T01 declares produces_driver_helper ['execute_unit_attempt', '_run_gate_set']; FEAT-LOOP-2026-0252/T02 produces specfuse/loop/loop.py; FEAT-LOOP-2026-0252/T02 produces .specfuse/verification.yml.example; FEAT-LOOP-2026-0252/T02 produces specfuse/loop/data/verification.yml.example; FEAT-LOOP-2026-0252/T02 declares produces_driver_helper ['resolve_heartbeat_seconds']; FEAT-LOOP-2026-0252/T03 produces specfuse/loop/loop.py; FEAT-LOOP-2026-0252/T03 declares produces_driver_helper ['main']; FEAT-LOOP-2026-0252/T04 produces specfuse/loop/loop.py; FEAT-LOOP-2026-0252/T04 produces specfuse/loop/agent_policy.py; FEAT-LOOP-2026-0252/T04 declares produces_driver_helper ['main']"}} {"timestamp": "2026-11-27T03:34:05.200398+00:00", "correlation_id": "FEAT-LOOP-2026-0252/G1-CLOSE", "event_type": "human_escalation", "source": "driver", "source_version": "0.33.2", "payload": {"reason": "judge_editing_terminal", "gate": 1, "hits": ["FEAT-LOOP-2026-0252/T01 produces specfuse/loop/loop.py", "FEAT-LOOP-2026-0252/T01 produces specfuse/loop/arm_eval.py", "FEAT-LOOP-2026-0252/T01 produces specfuse/loop/data/schemas/driver-event.schema.json", "FEAT-LOOP-2026-0252/T01 declares produces_driver_helper ['execute_unit_attempt', '_run_gate_set']", "FEAT-LOOP-2026-0252/T02 produces specfuse/loop/loop.py", "FEAT-LOOP-2026-0252/T02 produces .specfuse/verification.yml.example", "FEAT-LOOP-2026-0252/T02 produces specfuse/loop/data/verification.yml.example", "FEAT-LOOP-2026-0252/T02 declares produces_driver_helper ['resolve_heartbeat_seconds']", "FEAT-LOOP-2026-0252/T03 produces specfuse/loop/loop.py", "FEAT-LOOP-2026-0252/T03 declares produces_driver_helper ['main']", "FEAT-LOOP-2026-0252/T04 produces specfuse/loop/loop.py", "FEAT-LOOP-2026-0252/T04 produces specfuse/loop/agent_policy.py", "FEAT-LOOP-2026-0252/T04 declares produces_driver_helper ['main']"], "message": "ESCALATED \u2014 FEAT-LOOP-2026-0252/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-0252/T01, FEAT-LOOP-2026-0252/T02, FEAT-LOOP-2026-0252/T03, FEAT-LOOP-2026-0252/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-0252/T01 produces specfuse/loop/loop.py; FEAT-LOOP-2026-0252/T01 produces specfuse/loop/arm_eval.py; FEAT-LOOP-2026-0252/T01 produces specfuse/loop/data/schemas/driver-event.schema.json; FEAT-LOOP-2026-0252/T01 declares produces_driver_helper ['execute_unit_attempt', '_run_gate_set']; FEAT-LOOP-2026-0252/T02 produces specfuse/loop/loop.py; FEAT-LOOP-2026-0252/T02 produces .specfuse/verification.yml.example; FEAT-LOOP-2026-0252/T02 produces specfuse/loop/data/verification.yml.example; FEAT-LOOP-2026-0252/T02 declares produces_driver_helper ['resolve_heartbeat_seconds']; FEAT-LOOP-2026-0252/T03 produces specfuse/loop/loop.py; FEAT-LOOP-2026-0252/T03 declares produces_driver_helper ['main']; FEAT-LOOP-2026-0252/T04 produces specfuse/loop/loop.py; FEAT-LOOP-2026-0252/T04 produces specfuse/loop/agent_policy.py; FEAT-LOOP-2026-0252/T04 declares produces_driver_helper ['main'].\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-0252/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 - .specfuse/verification.yml.example\n - produces_driver_helper\n - specfuse/loop/agent_policy.py\n - specfuse/loop/arm_eval.py\n - specfuse/loop/data/schemas/driver-event.schema.json\n - specfuse/loop/data/verification.yml.example\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-0252\n\n"}} {"timestamp": "2026-11-27T03:36:05.854238+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "driver_build_pinned", "source": "driver", "source_version": "0.33.2", "payload": {"tree": "e9e8ef336de8752d0551e6b93e2ebb273c925a81", "path": "/private/var/folders/zc/rgq11x850d78dx_kf1fd4vx80000gn/T/specfuse-pins/e9e8ef336de8752d0551e6b93e2ebb273c925a81/specfuse/loop"}} +{"timestamp": "2026-11-27T03:36:06.004090+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "terminal_judge_editing_evaluated", "source": "driver", "source_version": "0.33.2", "payload": {"gate": 1, "status": "clean", "reason": "acknowledged by operator: .specfuse/verification.yml.example, produces_driver_helper, specfuse/loop/agent_policy.py, specfuse/loop/arm_eval.py, specfuse/loop/data/schemas/driver-event.schema.json, specfuse/loop/data/verification.yml.example, specfuse/loop/loop.py"}} +{"timestamp": "2026-11-27T03:36:06.006592+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "terminal_judge_editing_acknowledged", "source": "driver", "source_version": "0.33.2", "payload": {"gate": 1, "close_unit": "FEAT-LOOP-2026-0252/G1-CLOSE", "paths": [".specfuse/verification.yml.example", "produces_driver_helper", "specfuse/loop/agent_policy.py", "specfuse/loop/arm_eval.py", "specfuse/loop/data/schemas/driver-event.schema.json", "specfuse/loop/data/verification.yml.example", "specfuse/loop/loop.py"], "reason": "Driver changes reviewed and sound, accept them"}} +{"timestamp": "2026-11-27T03:36:06.163724+00:00", "correlation_id": "FEAT-LOOP-2026-0252/G1-CLOSE", "event_type": "agent_session_started", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1}} +{"timestamp": "2026-11-27T03:42:39.092019+00:00", "correlation_id": "FEAT-LOOP-2026-0252/G1-CLOSE", "event_type": "agent_session_finished", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1}} +{"timestamp": "2026-11-27T03:42:39.133609+00:00", "correlation_id": "FEAT-LOOP-2026-0252/G1-CLOSE", "event_type": "gate_started", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "gate": "plan-lint"}} +{"timestamp": "2026-11-27T03:42:39.251708+00:00", "correlation_id": "FEAT-LOOP-2026-0252/G1-CLOSE", "event_type": "gate_finished", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "gate": "plan-lint", "ok": true, "duration_seconds": 0.118}} +{"timestamp": "2026-11-27T03:42:39.252989+00:00", "correlation_id": "FEAT-LOOP-2026-0252/G1-CLOSE", "event_type": "gate_started", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "gate": "feature_oracle"}} +{"timestamp": "2026-11-27T03:42:55.826183+00:00", "correlation_id": "FEAT-LOOP-2026-0252/G1-CLOSE", "event_type": "gate_finished", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "gate": "feature_oracle", "ok": true, "duration_seconds": 16.572}} diff --git a/changelog.d/FEAT-LOOP-2026-0252-specfuse-loop-watch-feature-f-follows-a.md b/changelog.d/FEAT-LOOP-2026-0252-specfuse-loop-watch-feature-f-follows-a.md new file mode 100644 index 00000000..8f9cc21e --- /dev/null +++ b/changelog.d/FEAT-LOOP-2026-0252-specfuse-loop-watch-feature-f-follows-a.md @@ -0,0 +1,5 @@ +--- +class: added +trace: FEAT-LOOP-2026-0252 +--- +`specfuse-loop --watch [--feature F]` follows a running driver from a second terminal; it only reads the status file, exits 0 when the run stops and 1 when there is no status file diff --git a/changelog.d/FEAT-LOOP-2026-0252-the-driver-prints-one-plain-line-per-pha.md b/changelog.d/FEAT-LOOP-2026-0252-the-driver-prints-one-plain-line-per-pha.md new file mode 100644 index 00000000..9ec6089e --- /dev/null +++ b/changelog.d/FEAT-LOOP-2026-0252-the-driver-prints-one-plain-line-per-pha.md @@ -0,0 +1,5 @@ +--- +class: added +trace: FEAT-LOOP-2026-0252 +--- +The driver prints one plain line per phase change (agent session started and finished, each gate started and finished with result and duration) and appends `agent_session_started`, `agent_session_finished`, `gate_started` and `gate_finished` to `events.jsonl` as they happen. `events.jsonl` line order is no longer guaranteed to be timestamp order, because a unit's buffered events are still written later diff --git a/changelog.d/FEAT-LOOP-2026-0252-when-a-specfuse-loop-run-ends-not-under.md b/changelog.d/FEAT-LOOP-2026-0252-when-a-specfuse-loop-run-ends-not-under.md new file mode 100644 index 00000000..159478bb --- /dev/null +++ b/changelog.d/FEAT-LOOP-2026-0252-when-a-specfuse-loop-run-ends-not-under.md @@ -0,0 +1,5 @@ +--- +class: added +trace: FEAT-LOOP-2026-0252 +--- +When a `specfuse-loop` run ends (not under `--dry-run`), it sends one notification to the configured escalation webhook and to the new `escalation.notify_command` in `agent-policy.yml`, with the stop reason in the message and in `SPECFUSE_STOP_REASON`. The command runs without a shell, with a 30 s timeout, and its failure does not change the exit code diff --git a/changelog.d/FEAT-LOOP-2026-0252-while-a-feature-runs-the-driver-keeps-fe.md b/changelog.d/FEAT-LOOP-2026-0252-while-a-feature-runs-the-driver-keeps-fe.md new file mode 100644 index 00000000..eeeb527d --- /dev/null +++ b/changelog.d/FEAT-LOOP-2026-0252-while-a-feature-runs-the-driver-keeps-fe.md @@ -0,0 +1,5 @@ +--- +class: added +trace: FEAT-LOOP-2026-0252 +--- +While a feature runs, the driver keeps `/work/STATUS.json` (never committed) with the unit, attempt, phase, gate, elapsed time and files touched, refreshed during an attempt every `defaults.heartbeat_seconds` in `verification.yml` (default 30) From 9b758a50a0b11a59b71638fe7e9104a785928534 Mon Sep 17 00:00:00 2001 From: Test Date: Thu, 26 Nov 2026 22:44:26 -0500 Subject: [PATCH 14/25] chore(loop): FEAT-LOOP-2026-0252/G1-CLOSE judge cost fold Feature: FEAT-LOOP-2026-0252 --- .../FEAT-LOOP-2026-0252-run-progress/WU-90-gate-1-close.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-90-gate-1-close.md b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-90-gate-1-close.md index 1711631f..88103ae5 100644 --- a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-90-gate-1-close.md +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-90-gate-1-close.md @@ -32,10 +32,10 @@ cumulative_duration_seconds: 0.0 cumulative_input_tokens: 0 cumulative_output_tokens: 0 cumulative_attempts: 0 -cost_usd: 1.47429 +cost_usd: 1.889367 duration_seconds: 409.775 -input_tokens: 54 -output_tokens: 40064 +input_tokens: 68 +output_tokens: 44336 folded_through_re_arm: 1 gate_set: plannext driver_version: 0.33.2 From 5d71ebff2e516faedb8447f26a9e0b57406bf09a Mon Sep 17 00:00:00 2001 From: Test Date: Thu, 26 Nov 2026 22:44:26 -0500 Subject: [PATCH 15/25] chore(loop): gate 1 awaiting_review Feature: FEAT-LOOP-2026-0252 --- .../features/FEAT-LOOP-2026-0252-run-progress/GATE-01.md | 2 +- .../FEAT-LOOP-2026-0252-run-progress/events.jsonl | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/GATE-01.md b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/GATE-01.md index 12112081..d4adbed8 100644 --- a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/GATE-01.md +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/GATE-01.md @@ -1,6 +1,6 @@ --- gate: 1 -status: open +status: awaiting_review feature_oracle: "python3 -m unittest tests.test_run_progress -v -b" cost_budget_usd: 18.00 broad_run: diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl index 84385ecc..d617c880 100644 --- a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl @@ -82,3 +82,12 @@ {"timestamp": "2026-11-27T03:42:39.251708+00:00", "correlation_id": "FEAT-LOOP-2026-0252/G1-CLOSE", "event_type": "gate_finished", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "gate": "plan-lint", "ok": true, "duration_seconds": 0.118}} {"timestamp": "2026-11-27T03:42:39.252989+00:00", "correlation_id": "FEAT-LOOP-2026-0252/G1-CLOSE", "event_type": "gate_started", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "gate": "feature_oracle"}} {"timestamp": "2026-11-27T03:42:55.826183+00:00", "correlation_id": "FEAT-LOOP-2026-0252/G1-CLOSE", "event_type": "gate_finished", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "gate": "feature_oracle", "ok": true, "duration_seconds": 16.572}} +{"timestamp": "2026-11-27T03:36:06.127614+00:00", "correlation_id": "FEAT-LOOP-2026-0252/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-27T03:36:06.127620+00:00", "correlation_id": "FEAT-LOOP-2026-0252/G1-CLOSE", "event_type": "re_arm_dispatched", "source": "driver", "source_version": "0.33.2", "payload": {"re_arm_count": 1, "reason": "Driver changes reviewed and sound, accept them"}} +{"timestamp": "2026-11-27T03:42:55.936694+00:00", "correlation_id": "FEAT-LOOP-2026-0252/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.118, "phase": "attempt"}} +{"timestamp": "2026-11-27T03:42:55.936711+00:00", "correlation_id": "FEAT-LOOP-2026-0252/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": 16.572, "phase": "attempt"}} +{"timestamp": "2026-11-27T03:44:26.821627+00:00", "correlation_id": "FEAT-LOOP-2026-0252/G1-CLOSE", "event_type": "judged", "source": "driver", "source_version": "0.33.2", "payload": {"gate": 1, "close_verdict": "not_met", "close_model": "sonnet", "judge_verdict": "not_met", "verdict": "not_met", "lowered": false, "disagreed": false, "findings": 1, "reason": null, "diff_base": "3d099a84f81a374faa9af369bcabde35d04a48c2", "diff_base_source": "merge-base of HEAD with main", "usage": {"cost_usd": 0.41507700000000003, "input_tokens": 14, "output_tokens": 4272, "cache_read_input_tokens": 465130, "cache_creation_input_tokens": 81454}, "judge_cost_usd": 0.415077}} +{"timestamp": "2026-11-27T03:44:26.822720+00:00", "correlation_id": "FEAT-LOOP-2026-0252/G1-CLOSE", "event_type": "attempt_outcome", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "outcome": "passed", "duration_seconds": 409.775, "agent_seconds": 392.9250282079447, "verify_seconds": 16.6949569999706, "cost_usd": 1.8893673, "input_tokens": 68, "output_tokens": 44336, "cache_read_input_tokens": 3971833, "cache_creation_input_tokens": 262172, "model": "sonnet", "effort": "high", "failure_class": null, "failure_signature": null, "failure_excerpt": null, "files_touched": [".specfuse/features/FEAT-LOOP-2026-0252-run-progress/FOLLOW-UPS.md", ".specfuse/features/FEAT-LOOP-2026-0252-run-progress/GATE-01-CRITERIA.md", ".specfuse/features/FEAT-LOOP-2026-0252-run-progress/LEARNINGS-pending.md", ".specfuse/features/FEAT-LOOP-2026-0252-run-progress/RETROSPECTIVE.md", ".specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-90-gate-1-close.md", ".specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl", "changelog.d/FEAT-LOOP-2026-0252-specfuse-loop-watch-feature-f-follows-a.md", "changelog.d/FEAT-LOOP-2026-0252-the-driver-prints-one-plain-line-per-pha.md", "changelog.d/FEAT-LOOP-2026-0252-when-a-specfuse-loop-run-ends-not-under.md", "changelog.d/FEAT-LOOP-2026-0252-while-a-feature-runs-the-driver-keeps-fe.md"], "agent_status": "complete", "agent_blocked_reason": null, "re_arm_count": 0, "failing_tests": []}} +{"timestamp": "2026-11-27T03:44:26.822887+00:00", "correlation_id": "FEAT-LOOP-2026-0252/G1-CLOSE", "event_type": "task_completed", "source": "driver", "source_version": "0.33.2", "payload": {"attempts": 1, "attempts_usage": [{"attempt": 1, "duration_seconds": 409.775, "cost_usd": 1.8893673, "input_tokens": 68, "output_tokens": 44336, "cache_read_input_tokens": 3971833, "cache_creation_input_tokens": 262172, "agent_seconds": 392.9250282079447, "verify_seconds": 16.6949569999706}], "type": "close", "re_arm_count": 1, "cost_usd": 1.889367, "cumulative_cost_usd": 1.889367, "attempts_lifetime": 1, "planned_cost_usd": 5.0}} +{"timestamp": "2026-11-27T03:44:26.842770+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "gate_reached", "source": "driver", "source_version": "0.33.2", "payload": {"gate": 1}} +{"timestamp": "2026-11-27T03:44:26.842762+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "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 $4.78 within 2.0x baseline planned total $14.50 (cap $29.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"}}}} From fd270e7a57d828f990697b231f3cf19248a666aa Mon Sep 17 00:00:00 2001 From: Test Date: Thu, 26 Nov 2026 22:44:30 -0500 Subject: [PATCH 16/25] =?UTF-8?q?chore(loop):=20FEAT-LOOP-2026-0252=20?= =?UTF-8?q?=E2=80=94=20record=20the=20follow-up=20issues=20the=20driver=20?= =?UTF-8?q?filed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../features/FEAT-LOOP-2026-0252-run-progress/FOLLOW-UPS.md | 2 ++ .../features/FEAT-LOOP-2026-0252-run-progress/events.jsonl | 1 + 2 files changed, 3 insertions(+) diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/FOLLOW-UPS.md b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/FOLLOW-UPS.md index 6b7d04f5..e60dde4e 100644 --- a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/FOLLOW-UPS.md +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/FOLLOW-UPS.md @@ -4,6 +4,8 @@ First close of gate 1. One entry is open. ### Definition of done clause 6 (stop reason when the event log changes during `run()`) +**Tracked as #3626.** + **Criterion, verbatim:** "**Stop notification.** Each return from `run()` (and each exception out of it) sends exactly one notification. Its `stop_reason` is `halted` when this run wrote a `human_escalation`, else `awaiting_review` when it wrote `gate_reached` and the gate is diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl index d617c880..ceaa1203 100644 --- a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl @@ -91,3 +91,4 @@ {"timestamp": "2026-11-27T03:44:26.822887+00:00", "correlation_id": "FEAT-LOOP-2026-0252/G1-CLOSE", "event_type": "task_completed", "source": "driver", "source_version": "0.33.2", "payload": {"attempts": 1, "attempts_usage": [{"attempt": 1, "duration_seconds": 409.775, "cost_usd": 1.8893673, "input_tokens": 68, "output_tokens": 44336, "cache_read_input_tokens": 3971833, "cache_creation_input_tokens": 262172, "agent_seconds": 392.9250282079447, "verify_seconds": 16.6949569999706}], "type": "close", "re_arm_count": 1, "cost_usd": 1.889367, "cumulative_cost_usd": 1.889367, "attempts_lifetime": 1, "planned_cost_usd": 5.0}} {"timestamp": "2026-11-27T03:44:26.842770+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "gate_reached", "source": "driver", "source_version": "0.33.2", "payload": {"gate": 1}} {"timestamp": "2026-11-27T03:44:26.842762+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "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 $4.78 within 2.0x baseline planned total $14.50 (cap $29.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-27T03:44:30.526378+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "followups_recorded", "source": "driver", "source_version": "0.33.2", "payload": {"filed": 1, "unfiled": 0, "already_tracked": 0, "issue_numbers": ["3626"], "written_back": ["FOLLOW-UPS.md"]}} From a6b8d044763907f93bcde99debdd039c62bb3f66 Mon Sep 17 00:00:00 2001 From: Test Date: Thu, 26 Nov 2026 22:54:11 -0500 Subject: [PATCH 17/25] fix(loop): stop reason reads this run's events by timestamp, not a pre-checkout byte offset (#3626) The offset into events.jsonl was taken before run() checks out the feature branch, so a checkout to a branch with a different log either counted an older run's escalation or skipped this run's own lines. Select the events stamped at or after the run's start instead. Two tests drive loop.main() through a real checkout in each direction. Co-Authored-By: Claude Opus 5.5 --- .../FEAT-LOOP-2026-0252-run-progress/PLAN.md | 7 +++ specfuse/loop/progress.py | 40 ++++++++++----- tests/test_run_progress.py | 51 +++++++++++++++++++ 3 files changed, 84 insertions(+), 14 deletions(-) diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/PLAN.md b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/PLAN.md index 9fad9d16..f09d4fd7 100644 --- a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/PLAN.md +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/PLAN.md @@ -119,3 +119,10 @@ gates: - FEAT-LOOP-2026-0251 took seven closes because the definition of done left room for interpretation. `GATE-01.md` states each clause as a checkable fact; a unit that finds a clause ambiguous blocks and names it rather than choosing a reading. +- **First-close follow-up (2026-11-26, #3626).** The stop reason was taken from the bytes of + `events.jsonl` past an offset recorded when `run()` started, before the run checks out the + feature branch. A checkout to a branch with a different log made an older run's escalation + count as this run's, or skipped this run's own lines. `notify_stop` now reads the events + stamped at or after the run's start time, so the branch the log came from no longer matters. + Tested in `TestStopNotification` with a real checkout both ways (an older escalation only on + the feature branch; a starting log longer than the feature branch's). diff --git a/specfuse/loop/progress.py b/specfuse/loop/progress.py index 73df2da5..6699eda2 100644 --- a/specfuse/loop/progress.py +++ b/specfuse/loop/progress.py @@ -285,7 +285,7 @@ class _Stop: feature: str feature_dir: Path events_path: Path - events_offset: int + started_at: "dt.datetime" load_graph: Callable owns_status: bool = True @@ -297,14 +297,15 @@ def remember_run( feature: str, feature_dir: Path, events_path: Path, *, load_graph: Callable, ) -> None: - """Call as the run starts, before it appends any event.""" + """Call as the run starts, before it appends any event. + + The run's events are later told apart by timestamp, not by a byte offset: + `run()` may check out the feature branch, whose `events.jsonl` can be + longer or shorter than the one the run started on (#3626). + """ global _stop - try: - offset = Path(events_path).stat().st_size - except OSError: - offset = 0 - _stop = _Stop(feature, Path(feature_dir), Path(events_path), offset, - load_graph) + _stop = _Stop(feature, Path(feature_dir), Path(events_path), + dt.datetime.now(dt.timezone.utc), load_graph) def disown_status() -> None: @@ -318,11 +319,19 @@ def forget_run() -> None: _stop = None -def _events_since(path: Path, offset: int) -> "list[dict]": +def _event_time(event: dict) -> "dt.datetime | None": try: - with path.open("rb") as fh: - fh.seek(offset) - lines = fh.read().decode("utf-8", errors="replace").splitlines() + when = dt.datetime.fromisoformat(str(event.get("timestamp", ""))) + except ValueError: + return None + return when if when.tzinfo is not None else None + + +def _events_since(path: Path, started_at: "dt.datetime") -> "list[dict]": + """Events in *path* stamped at or after *started_at*. An event with no + readable timezone-aware timestamp was not written by this run.""" + try: + lines = path.read_bytes().decode("utf-8", errors="replace").splitlines() except OSError: return [] events = [] @@ -331,7 +340,10 @@ def _events_since(path: Path, offset: int) -> "list[dict]": event = json.loads(line) except ValueError: continue - if isinstance(event, dict): + if not isinstance(event, dict): + continue + when = _event_time(event) + if when is not None and when >= started_at: events.append(event) return events @@ -411,7 +423,7 @@ def notify_stop(*, raised: bool, feature_arg: "str | None" = None) -> None: stop, _stop = _stop, None try: events = ([] if stop is None - else _events_since(stop.events_path, stop.events_offset)) + else _events_since(stop.events_path, stop.started_at)) reason = _stop_reason(stop, events, raised) feature = stop.feature if stop else (feature_arg or "") unit = _stop_work_unit(events) diff --git a/tests/test_run_progress.py b/tests/test_run_progress.py index 08c246b7..f0669f71 100644 --- a/tests/test_run_progress.py +++ b/tests/test_run_progress.py @@ -654,6 +654,26 @@ def poster(url, payload): self.pwned = list(root.rglob("pwned")) +def _commit(message): + subprocess.run(["git", "add", "."], check=True) + subprocess.run(["git", "commit", "-q", "--allow-empty", "-m", message], + check=True) + + +def _on_feature_branch(change): + """Commit *change* on the fixture's feature branch, return to the + starting branch and leave one unrelated edit for `_Notified` to commit, so + the run's own checkout (and merge of the base) switches the event log.""" + start = subprocess.run(["git", "branch", "--show-current"], + capture_output=True, text=True, + check=True).stdout.strip() + subprocess.run(["git", "checkout", "-q", "-b", f"feat/{SLUG}"], check=True) + change() + _commit("feature-branch log") + subprocess.run(["git", "checkout", "-q", start], check=True) + Path("notes.txt").write_text("unrelated\n") + + def _all_passed(fdir): for name, old, new in (("GATE-01.md", "open", "passed"), ("PLAN.md", "active", "done")): @@ -720,6 +740,37 @@ def earlier(fdir): self._assert_notified(_Notified(prepare=earlier), "stopped", "") + def test_checkout_bringing_an_older_escalation_is_not_read(self): + # #3626 (a): the run starts on main; the feature branch, ahead of it, + # holds an older escalation that the real checkout brings in. + def older_escalation_on_feature_branch(fdir): + _commit("policy") + _on_feature_branch(lambda: (fdir / "events.jsonl").write_text( + json.dumps({"timestamp": "2020-01-01T00:00:00+00:00", + "event_type": "human_escalation", + "correlation_id": WU_ID, "payload": {}}) + "\n")) + + seen = _Notified(prepare=older_escalation_on_feature_branch) + self.assertEqual(seen.rc, 0, seen.output) + self._assert_notified(seen, "awaiting_review", WU_ID) + + def test_checkout_to_a_shorter_log_still_reads_this_runs_events(self): + # #3626 (b): the log on main is longer than the feature branch's. + def longer_log_off_the_feature_branch(fdir): + log = fdir / "events.jsonl" + log.write_text("".join( + json.dumps({"timestamp": "2020-01-01T00:00:00+00:00", + "event_type": "gate_reached", + "correlation_id": FEATURE_ID, + "payload": {"gate": 9, "pad": "x" * 200}}) + "\n" + for _ in range(20))) + _commit("long log") + _on_feature_branch(lambda: log.write_text("")) + + seen = _Notified(_blocked_session, + prepare=longer_log_off_the_feature_branch) + self._assert_notified(seen, "halted", WU_ID) + def test_a_held_lock_leaves_the_other_drivers_status_alone(self): live = _status() From db7d32420476d5c83c95a6c003f8b29eb131f641 Mon Sep 17 00:00:00 2001 From: Test Date: Thu, 26 Nov 2026 23:09:28 -0500 Subject: [PATCH 18/25] =?UTF-8?q?chore(loop):=20FEAT-LOOP-2026-0252=20?= =?UTF-8?q?=E2=80=94=20re-arm=20G1-CLOSE=20after=20#3626?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- .../GATE-01.md | 2 +- .../WU-90-gate-1-close.md | 22 +++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/GATE-01.md b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/GATE-01.md index d4adbed8..12112081 100644 --- a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/GATE-01.md +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/GATE-01.md @@ -1,6 +1,6 @@ --- gate: 1 -status: awaiting_review +status: open feature_oracle: "python3 -m unittest tests.test_run_progress -v -b" cost_budget_usd: 18.00 broad_run: diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-90-gate-1-close.md b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-90-gate-1-close.md index 88103ae5..da1f1fed 100644 --- a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-90-gate-1-close.md +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-90-gate-1-close.md @@ -1,9 +1,8 @@ --- id: FEAT-LOOP-2026-0252/G1-CLOSE type: close -status: done -attempts: 1 -verdict: not_met +status: pending +attempts: 0 planned_cost_usd: 5.00 auto_close_disabled: true model: sonnet @@ -18,7 +17,7 @@ judge_edit_acknowledged: - specfuse/loop/data/verification.yml.example - specfuse/loop/loop.py reason: "Driver changes reviewed and sound, accept them" -re_arm_count: 1 +re_arm_count: 2 re_arm_history: - timestamp: 2026-11-27T03:36:01+00:00 @@ -27,6 +26,13 @@ re_arm_history: prior_cost_usd: 0.0 prior_duration_seconds: 0.0 reason: "Driver changes reviewed and sound, accept them" + - + timestamp: 2026-11-27T04:09:24+00:00 + prior_status: done + prior_attempts: 1 + prior_cost_usd: 1.889367 + prior_duration_seconds: 409.775 + reason: "Fixed the stop-reason offset, re-close it" cumulative_cost_usd: 0.0 cumulative_duration_seconds: 0.0 cumulative_input_tokens: 0 @@ -71,3 +77,11 @@ stops. **Escalation triggers.** A surviving skip, a notification sent more or fewer than once per stop in any test, or a change to `dispatch()` or the `attempt_outcome` payload: record `not_met` with a follow-up. + +**Re-close note (2026-11-26).** The first close recorded `not_met` on #3626: the stop reason was +read from `events.jsonl` past a byte offset taken before `run()` checks out the feature branch. +Fixed on the branch (`notify_stop` reads events stamped at or after the run's start; tests in +`TestStopNotification` with a real checkout both ways; see `PLAN.md` Notes). That close already +wrote `RETROSPECTIVE.md`, `FOLLOW-UPS.md`, `LEARNINGS-pending.md` and changelog fragments: update +them in place, do not duplicate fragments, and say in `FOLLOW-UPS.md` whether #3626's re-run +condition now holds. From d7ffdec1c2ddb403573dd5202a69121d1c0901b1 Mon Sep 17 00:00:00 2001 From: Test Date: Thu, 26 Nov 2026 23:09:29 -0500 Subject: [PATCH 19/25] chore(loop): FEAT-LOOP-2026-0252 build pin recorded Feature: FEAT-LOOP-2026-0252 --- .specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl | 1 + 1 file changed, 1 insertion(+) diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl index ceaa1203..95c0bac3 100644 --- a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl @@ -92,3 +92,4 @@ {"timestamp": "2026-11-27T03:44:26.842770+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "gate_reached", "source": "driver", "source_version": "0.33.2", "payload": {"gate": 1}} {"timestamp": "2026-11-27T03:44:26.842762+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "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 $4.78 within 2.0x baseline planned total $14.50 (cap $29.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-27T03:44:30.526378+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "followups_recorded", "source": "driver", "source_version": "0.33.2", "payload": {"filed": 1, "unfiled": 0, "already_tracked": 0, "issue_numbers": ["3626"], "written_back": ["FOLLOW-UPS.md"]}} +{"timestamp": "2026-11-27T04:09:29.865689+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "driver_build_pinned", "source": "driver", "source_version": "0.33.2", "payload": {"tree": "d8f9bb541f2a4a46bccd372c7ab617ebe0907e2f", "path": "/private/var/folders/zc/rgq11x850d78dx_kf1fd4vx80000gn/T/specfuse-pins/d8f9bb541f2a4a46bccd372c7ab617ebe0907e2f/specfuse/loop"}} From 57f27914fdbd4a462d6c3e53b815ea68329b177c Mon Sep 17 00:00:00 2001 From: Test Date: Thu, 26 Nov 2026 23:17:54 -0500 Subject: [PATCH 20/25] chore(loop): gate 1 broad run clean Feature: FEAT-LOOP-2026-0252 --- .../GATE-01-CRITERIA.md | 127 ++++++------------ .../GATE-01.md | 4 +- .../events.jsonl | 55 ++++++++ 3 files changed, 95 insertions(+), 91 deletions(-) diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/GATE-01-CRITERIA.md b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/GATE-01-CRITERIA.md index b746b85f..8c11e063 100644 --- a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/GATE-01-CRITERIA.md +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/GATE-01-CRITERIA.md @@ -1,169 +1,118 @@ ### T01#1 - **criterion:** `tests.test_run_progress.TestPhaseEvents` fails on HEAD and passes after. Through -- **oracle:** python3 -m unittest tests.test_run_progress -v -b (class TestPhaseEvents), exit 0 -- **kind:** `narrow` -- **state:** `pass` -- **proved_at_sha:** `cdb4c60` -- **attempt:** `1` +- **state:** `unverified` - **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, specfuse/loop/arm_eval.py, specfuse/loop/data/schemas/driver-event.schema.json, tests/test_run_progress.py +- **invalidated_by:** specfuse/loop/progress.py ### T01#2 - **criterion:** `TestStatusFile` passes: during the session the stub reads `STATUS.json` with every field -- **oracle:** python3 -m unittest tests.test_run_progress -v -b (class TestStatusFile), exit 0 -- **kind:** `narrow` -- **state:** `pass` -- **proved_at_sha:** `cdb4c60` -- **attempt:** `1` +- **state:** `unverified` - **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, specfuse/loop/arm_eval.py, specfuse/loop/data/schemas/driver-event.schema.json, tests/test_run_progress.py +- **invalidated_by:** specfuse/loop/progress.py ### T01#3 - **criterion:** `TestDriverLines` passes: captured driver output has one line per phase change and contains -- **oracle:** python3 -m unittest tests.test_run_progress -v -b (class TestDriverLines), exit 0 -- **kind:** `narrow` -- **state:** `pass` -- **proved_at_sha:** `cdb4c60` -- **attempt:** `1` +- **state:** `unverified` - **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, specfuse/loop/arm_eval.py, specfuse/loop/data/schemas/driver-event.schema.json, tests/test_run_progress.py +- **invalidated_by:** specfuse/loop/progress.py ### T01#4 - **criterion:** `python3 -m unittest tests.test_judge_path_registry tests.test_driver_event_registry_covers_emitters tests.test_validate_event_driver_types tests.test_gate_timings tests.test_dispatch_skeleton -b` -- **oracle:** python3 -m unittest tests.test_judge_path_registry tests.test_driver_event_registry_covers_emitters tests.test_validate_event_driver_types tests.test_gate_timings tests.test_dispatch_skeleton -b (run within the 10-module command in RETROSPECTIVE.md), exit 0 -- **kind:** `narrow` -- **state:** `pass` -- **proved_at_sha:** `cdb4c60` -- **attempt:** `1` -- **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, specfuse/loop/arm_eval.py, specfuse/loop/data/schemas/driver-event.schema.json, tests/test_run_progress.py +- **state:** `unverified` +- **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, specfuse/loop/arm_eval.py, specfuse/loop/data/schemas/driver-event.schema.json, tests/test_run_progress.py, tests/test_judge_path_registry.py +- **invalidated_by:** specfuse/loop/progress.py ### T02#1 - **criterion:** `tests.test_run_progress.TestHeartbeat` fails on HEAD and passes after (remove its skip). -- **oracle:** python3 -m unittest tests.test_run_progress -v -b (class TestHeartbeat), exit 0 -- **kind:** `narrow` -- **state:** `pass` -- **proved_at_sha:** `cdb4c60` -- **attempt:** `1` +- **state:** `unverified` - **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, .specfuse/verification.yml.example, specfuse/loop/data/verification.yml.example, tests/test_run_progress.py +- **invalidated_by:** specfuse/loop/progress.py ### T02#2 - **criterion:** After `run()` returns, and after an attempt whose stubbed session raises, no thread started -- **oracle:** python3 -m unittest tests.test_run_progress -v -b (class TestHeartbeat), exit 0 -- **kind:** `narrow` -- **state:** `pass` -- **proved_at_sha:** `cdb4c60` -- **attempt:** `1` +- **state:** `unverified` - **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, .specfuse/verification.yml.example, specfuse/loop/data/verification.yml.example, tests/test_run_progress.py +- **invalidated_by:** specfuse/loop/progress.py ### T02#3 - **criterion:** `resolve_heartbeat_seconds` returns 30 for a missing key, `"x"`, `0` and `-5`, and 7 for `7`. -- **oracle:** python3 -m unittest tests.test_run_progress -v -b (class TestHeartbeat), exit 0 -- **kind:** `narrow` -- **state:** `pass` -- **proved_at_sha:** `cdb4c60` -- **attempt:** `1` +- **state:** `unverified` - **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, .specfuse/verification.yml.example, specfuse/loop/data/verification.yml.example, tests/test_run_progress.py +- **invalidated_by:** specfuse/loop/progress.py ### T02#4 - **criterion:** `python3 -m unittest tests.test_fail_fast_deliverables tests.test_dispatch_skeleton -b` -- **oracle:** python3 -m unittest tests.test_fail_fast_deliverables tests.test_dispatch_skeleton -b (run within the 10-module command in RETROSPECTIVE.md), exit 0 -- **kind:** `narrow` -- **state:** `pass` -- **proved_at_sha:** `cdb4c60` -- **attempt:** `1` -- **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, .specfuse/verification.yml.example, specfuse/loop/data/verification.yml.example, tests/test_run_progress.py +- **state:** `unverified` +- **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, .specfuse/verification.yml.example, specfuse/loop/data/verification.yml.example, tests/test_run_progress.py, tests/test_fail_fast_deliverables.py +- **invalidated_by:** specfuse/loop/progress.py ### T03#1 - **criterion:** `tests.test_run_progress.TestWatch` fails on HEAD and passes after (remove its skip). Given -- **oracle:** python3 -m unittest tests.test_run_progress -v -b (class TestWatch), exit 0 -- **kind:** `narrow` -- **state:** `pass` -- **proved_at_sha:** `cdb4c60` -- **attempt:** `1` +- **state:** `unverified` - **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, tests/test_run_progress.py +- **invalidated_by:** specfuse/loop/progress.py ### T03#2 - **criterion:** An `updated_at` older than three heartbeat intervals prints `no update for Ns`. -- **oracle:** python3 -m unittest tests.test_run_progress -v -b (class TestWatch), exit 0 -- **kind:** `narrow` -- **state:** `pass` -- **proved_at_sha:** `cdb4c60` -- **attempt:** `1` +- **state:** `unverified` - **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, tests/test_run_progress.py +- **invalidated_by:** specfuse/loop/progress.py ### T03#3 - **criterion:** `phase: stopped` ends the watch with exit 0; no status file exits 1 with a message naming -- **oracle:** python3 -m unittest tests.test_run_progress -v -b (class TestWatch), exit 0 -- **kind:** `narrow` -- **state:** `pass` -- **proved_at_sha:** `cdb4c60` -- **attempt:** `1` +- **state:** `unverified` - **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, tests/test_run_progress.py +- **invalidated_by:** specfuse/loop/progress.py ### T03#4 - **criterion:** `python3 -m unittest tests.test_dispatch_skeleton -b` passes. -- **oracle:** python3 -m unittest tests.test_dispatch_skeleton -b (run within the 10-module command in RETROSPECTIVE.md), exit 0 -- **kind:** `narrow` -- **state:** `pass` -- **proved_at_sha:** `cdb4c60` -- **attempt:** `1` -- **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, tests/test_run_progress.py +- **state:** `unverified` +- **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, tests/test_run_progress.py, tests/test_dispatch_skeleton.py +- **invalidated_by:** specfuse/loop/progress.py ### T04#1 - **criterion:** `tests.test_run_progress.TestStopNotification` fails on HEAD and passes after (remove its -- **oracle:** python3 -m unittest tests.test_run_progress -v -b (class TestStopNotification), exit 0 -- **kind:** `narrow` -- **state:** `pass` -- **proved_at_sha:** `cdb4c60` -- **attempt:** `1` +- **state:** `unverified` - **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, specfuse/loop/agent_policy.py, .specfuse/agent-policy.yml.example, docs/getting-started.md, specfuse/loop/data/docs/getting-started.md, tests/test_run_progress.py +- **invalidated_by:** specfuse/loop/progress.py ### T04#2 - **criterion:** A command that exits 1, one that sleeps past the timeout (patched to 1 s in the test) and -- **oracle:** python3 -m unittest tests.test_run_progress -v -b (class TestStopNotification), exit 0 -- **kind:** `narrow` -- **state:** `pass` -- **proved_at_sha:** `cdb4c60` -- **attempt:** `1` +- **state:** `unverified` - **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, specfuse/loop/agent_policy.py, .specfuse/agent-policy.yml.example, docs/getting-started.md, specfuse/loop/data/docs/getting-started.md, tests/test_run_progress.py +- **invalidated_by:** specfuse/loop/progress.py ### T04#3 - **criterion:** A message containing `; touch pwned` does not create `pwned`. -- **oracle:** python3 -m unittest tests.test_run_progress -v -b (class TestStopNotification), exit 0 -- **kind:** `narrow` -- **state:** `pass` -- **proved_at_sha:** `cdb4c60` -- **attempt:** `1` +- **state:** `unverified` - **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, specfuse/loop/agent_policy.py, .specfuse/agent-policy.yml.example, docs/getting-started.md, specfuse/loop/data/docs/getting-started.md, tests/test_run_progress.py +- **invalidated_by:** specfuse/loop/progress.py ### T04#4 - **criterion:** `python3 -m unittest tests.test_agent_policy_schema tests.test_notify tests.test_notify_escalation -b` -- **oracle:** python3 -m unittest tests.test_agent_policy_schema tests.test_notify tests.test_notify_escalation -b (run within the 10-module command in RETROSPECTIVE.md), exit 0 ; validate_agent_policy rejects a list and an int -- **kind:** `narrow` -- **state:** `pass` -- **proved_at_sha:** `cdb4c60` -- **attempt:** `1` -- **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, specfuse/loop/agent_policy.py, .specfuse/agent-policy.yml.example, docs/getting-started.md, specfuse/loop/data/docs/getting-started.md, tests/test_run_progress.py +- **state:** `unverified` +- **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, specfuse/loop/agent_policy.py, .specfuse/agent-policy.yml.example, docs/getting-started.md, specfuse/loop/data/docs/getting-started.md, tests/test_run_progress.py, tests/test_agent_policy_schema.py +- **invalidated_by:** specfuse/loop/progress.py ### T04#5 - **criterion:** `tests.test_run_progress` has no `unittest.skip` left. -- **oracle:** grep of tests/test_run_progress.py for skip markers, no match (grep exit 1) -- **kind:** `narrow` -- **state:** `pass` -- **proved_at_sha:** `cdb4c60` -- **attempt:** `1` +- **state:** `unverified` - **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, specfuse/loop/agent_policy.py, .specfuse/agent-policy.yml.example, docs/getting-started.md, specfuse/loop/data/docs/getting-started.md, tests/test_run_progress.py +- **invalidated_by:** specfuse/loop/progress.py diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/GATE-01.md b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/GATE-01.md index 12112081..f5173dbc 100644 --- a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/GATE-01.md +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/GATE-01.md @@ -4,8 +4,8 @@ status: open feature_oracle: "python3 -m unittest tests.test_run_progress -v -b" cost_budget_usd: 18.00 broad_run: - tree: 07bbf72d1e7af3c1a03af605f40e5563dc3a18db:0ec7c6da6e74f0b56753f09657b654a6d289b91b:12064a6191eeb830a9826d911a8543fbaba3da75:21853f95bd08cd0c5cd8f5fe0caad3f248ba8e72:27968248a450a842ccd187b7dce0fb0ded934866:287efde8f90320baffac08f5f3287b9456a65cb9:2e29b2f7e073a0cbe290f01d3b397e1cdd10c81c:3e6b8329522b39869d0b9caf5e22bf61f1a87ec0:42796ea0e0a6c03811b0e4bc9dbd3b5ee62dd2e4:4acc6dfc5e8cece358c167d876515eba4a39a500:6f70c7c8afa618acb6b7b66ad5b035d661250dc6:834d9d9c16094a386cd9b5a6f9ced9a3a9b4e7fb:bbd1aea514612d76722a18c7aece7c767cf1a076:c23b62e87f1ae3890c6f9e3d8c7ca7ec9225ed81:caffe2d63ceacde448842a91bc7a12c206a67523:d74b7d113b844e84f0009098f576fd28477f072d:e3b0de29b81a6c8e0abeacb3898519b98014b9ef:f1126d17cf8e5a0a44edefbee7cb726fab9cf3a2:fa2f4f88657587b6e3b560977858810846b1d366 - ran_at: 2026-11-27T03:34:05.038818+00:00 + tree: 07bbf72d1e7af3c1a03af605f40e5563dc3a18db:0ec7c6da6e74f0b56753f09657b654a6d289b91b:12064a6191eeb830a9826d911a8543fbaba3da75:27968248a450a842ccd187b7dce0fb0ded934866:287efde8f90320baffac08f5f3287b9456a65cb9:2e29b2f7e073a0cbe290f01d3b397e1cdd10c81c:3e6b8329522b39869d0b9caf5e22bf61f1a87ec0:42796ea0e0a6c03811b0e4bc9dbd3b5ee62dd2e4:4acc6dfc5e8cece358c167d876515eba4a39a500:834d9d9c16094a386cd9b5a6f9ced9a3a9b4e7fb:8e461a12f3893b4e2cd07a4871f27fe6ccefbca6:9d6c2e47307324615ad200f969a7ebf56f89a081:b683e1b4106d84290f55a8191bccb8a2259d9502:bbd1aea514612d76722a18c7aece7c767cf1a076:c23b62e87f1ae3890c6f9e3d8c7ca7ec9225ed81:caffe2d63ceacde448842a91bc7a12c206a67523:d74b7d113b844e84f0009098f576fd28477f072d:e3b0de29b81a6c8e0abeacb3898519b98014b9ef:fa2f4f88657587b6e3b560977858810846b1d366 + ran_at: 2026-11-27T04:17:54.136078+00:00 ok: true failing: [] --- diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl index 95c0bac3..5a9fa4e9 100644 --- a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl @@ -93,3 +93,58 @@ {"timestamp": "2026-11-27T03:44:26.842762+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "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 $4.78 within 2.0x baseline planned total $14.50 (cap $29.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-27T03:44:30.526378+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "followups_recorded", "source": "driver", "source_version": "0.33.2", "payload": {"filed": 1, "unfiled": 0, "already_tracked": 0, "issue_numbers": ["3626"], "written_back": ["FOLLOW-UPS.md"]}} {"timestamp": "2026-11-27T04:09:29.865689+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "driver_build_pinned", "source": "driver", "source_version": "0.33.2", "payload": {"tree": "d8f9bb541f2a4a46bccd372c7ab617ebe0907e2f", "path": "/private/var/folders/zc/rgq11x850d78dx_kf1fd4vx80000gn/T/specfuse-pins/d8f9bb541f2a4a46bccd372c7ab617ebe0907e2f/specfuse/loop"}} +{"timestamp": "2026-11-27T04:09:30.014398+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "gate_started", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "tests"}} +{"timestamp": "2026-11-27T04:17:12.663514+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "gate_finished", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "tests", "ok": true, "duration_seconds": 462.648}} +{"timestamp": "2026-11-27T04:17:12.670275+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "gate_started", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "lint"}} +{"timestamp": "2026-11-27T04:17:12.732004+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "gate_finished", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "lint", "ok": true, "duration_seconds": 0.061}} +{"timestamp": "2026-11-27T04:17:12.733088+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "gate_started", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "security"}} +{"timestamp": "2026-11-27T04:17:14.436808+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "gate_finished", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "security", "ok": true, "duration_seconds": 1.703}} +{"timestamp": "2026-11-27T04:17:14.437974+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "gate_started", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "coverage"}} +{"timestamp": "2026-11-27T04:17:15.776806+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "gate_finished", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "coverage", "ok": true, "duration_seconds": 1.338}} +{"timestamp": "2026-11-27T04:17:15.778061+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "gate_started", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "leak-scan"}} +{"timestamp": "2026-11-27T04:17:34.217167+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "gate_finished", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "leak-scan", "ok": true, "duration_seconds": 18.438}} +{"timestamp": "2026-11-27T04:17:34.218416+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "gate_started", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "changelog-fragments"}} +{"timestamp": "2026-11-27T04:17:34.274571+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "gate_finished", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "changelog-fragments", "ok": true, "duration_seconds": 0.055}} +{"timestamp": "2026-11-27T04:17:34.275739+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "gate_started", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "agent-policy-example-lint"}} +{"timestamp": "2026-11-27T04:17:34.397551+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "gate_finished", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "agent-policy-example-lint", "ok": true, "duration_seconds": 0.121}} +{"timestamp": "2026-11-27T04:17:34.398834+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "gate_started", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "event-type-gate"}} +{"timestamp": "2026-11-27T04:17:34.565763+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "gate_finished", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "event-type-gate", "ok": true, "duration_seconds": 0.166}} +{"timestamp": "2026-11-27T04:17:34.566945+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "gate_started", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "roadmap-link-gate"}} +{"timestamp": "2026-11-27T04:17:34.624785+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "gate_finished", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "roadmap-link-gate", "ok": true, "duration_seconds": 0.057}} +{"timestamp": "2026-11-27T04:17:34.625935+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "gate_started", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "arm-sweep-gate"}} +{"timestamp": "2026-11-27T04:17:35.050850+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "gate_finished", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "arm-sweep-gate", "ok": true, "duration_seconds": 0.424}} +{"timestamp": "2026-11-27T04:17:35.052599+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "gate_started", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "monitoring-example-lint"}} +{"timestamp": "2026-11-27T04:17:35.106485+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "gate_finished", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "monitoring-example-lint", "ok": true, "duration_seconds": 0.053}} +{"timestamp": "2026-11-27T04:17:35.107717+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "gate_started", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "leak-scan-hook"}} +{"timestamp": "2026-11-27T04:17:35.970388+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "gate_finished", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "leak-scan-hook", "ok": true, "duration_seconds": 0.862}} +{"timestamp": "2026-11-27T04:17:35.971622+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "gate_started", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "pre-push-hook"}} +{"timestamp": "2026-11-27T04:17:39.587036+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "gate_finished", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "pre-push-hook", "ok": true, "duration_seconds": 3.615}} +{"timestamp": "2026-11-27T04:17:39.588433+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "gate_started", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "sync-scaffold-bats"}} +{"timestamp": "2026-11-27T04:17:50.781131+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "gate_finished", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "sync-scaffold-bats", "ok": true, "duration_seconds": 11.192}} +{"timestamp": "2026-11-27T04:17:50.782497+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "gate_started", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "sync-scaffold-symlinks-bats"}} +{"timestamp": "2026-11-27T04:17:52.485605+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "gate_finished", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "sync-scaffold-symlinks-bats", "ok": true, "duration_seconds": 1.702}} +{"timestamp": "2026-11-27T04:17:52.487158+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "gate_started", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "init-sh-shim-bats"}} +{"timestamp": "2026-11-27T04:17:53.395899+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "gate_finished", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "init-sh-shim-bats", "ok": true, "duration_seconds": 0.908}} +{"timestamp": "2026-11-27T04:17:53.397135+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "gate_started", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "init-skills-bats"}} +{"timestamp": "2026-11-27T04:17:53.528228+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "gate_finished", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "init-skills-bats", "ok": true, "duration_seconds": 0.131}} +{"timestamp": "2026-11-27T04:17:53.529412+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "gate_started", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "hookspath-conflict-bats"}} +{"timestamp": "2026-11-27T04:17:54.135048+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "gate_finished", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "hookspath-conflict-bats", "ok": true, "duration_seconds": 0.605}} +{"timestamp": "2026-11-27T04:17:54.144857+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "broad_run_result", "source": "driver", "source_version": "0.33.2", "payload": {"gate": 1, "tree": "07bbf72d1e7af3c1a03af605f40e5563dc3a18db:0ec7c6da6e74f0b56753f09657b654a6d289b91b:12064a6191eeb830a9826d911a8543fbaba3da75:27968248a450a842ccd187b7dce0fb0ded934866:287efde8f90320baffac08f5f3287b9456a65cb9:2e29b2f7e073a0cbe290f01d3b397e1cdd10c81c:3e6b8329522b39869d0b9caf5e22bf61f1a87ec0:42796ea0e0a6c03811b0e4bc9dbd3b5ee62dd2e4:4acc6dfc5e8cece358c167d876515eba4a39a500:834d9d9c16094a386cd9b5a6f9ced9a3a9b4e7fb:8e461a12f3893b4e2cd07a4871f27fe6ccefbca6:9d6c2e47307324615ad200f969a7ebf56f89a081:b683e1b4106d84290f55a8191bccb8a2259d9502:bbd1aea514612d76722a18c7aece7c767cf1a076:c23b62e87f1ae3890c6f9e3d8c7ca7ec9225ed81:caffe2d63ceacde448842a91bc7a12c206a67523:d74b7d113b844e84f0009098f576fd28477f072d:e3b0de29b81a6c8e0abeacb3898519b98014b9ef:fa2f4f88657587b6e3b560977858810846b1d366", "ok": true, "failing": []}} +{"timestamp": "2026-11-27T04:17:54.144891+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "tests", "ok": true, "skipped": false, "duration_seconds": 462.648, "phase": "broad"}} +{"timestamp": "2026-11-27T04:17:54.144898+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "lint", "ok": true, "skipped": false, "duration_seconds": 0.061, "phase": "broad"}} +{"timestamp": "2026-11-27T04:17:54.144901+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "security", "ok": true, "skipped": false, "duration_seconds": 1.703, "phase": "broad"}} +{"timestamp": "2026-11-27T04:17:54.144903+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "coverage", "ok": true, "skipped": false, "duration_seconds": 1.338, "phase": "broad"}} +{"timestamp": "2026-11-27T04:17:54.144904+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "leak-scan", "ok": true, "skipped": false, "duration_seconds": 18.438, "phase": "broad"}} +{"timestamp": "2026-11-27T04:17:54.144907+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "changelog-fragments", "ok": true, "skipped": false, "duration_seconds": 0.055, "phase": "broad"}} +{"timestamp": "2026-11-27T04:17:54.144909+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "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.121, "phase": "broad"}} +{"timestamp": "2026-11-27T04:17:54.144911+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "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.166, "phase": "broad"}} +{"timestamp": "2026-11-27T04:17:54.144918+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "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.057, "phase": "broad"}} +{"timestamp": "2026-11-27T04:17:54.144919+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "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.424, "phase": "broad"}} +{"timestamp": "2026-11-27T04:17:54.144921+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "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.053, "phase": "broad"}} +{"timestamp": "2026-11-27T04:17:54.144922+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "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.862, "phase": "broad"}} +{"timestamp": "2026-11-27T04:17:54.144924+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "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.615, "phase": "broad"}} +{"timestamp": "2026-11-27T04:17:54.144925+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "gate_result", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": null, "gate": "sync-scaffold-bats", "ok": true, "skipped": false, "duration_seconds": 11.192, "phase": "broad"}} +{"timestamp": "2026-11-27T04:17:54.144926+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "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.702, "phase": "broad"}} +{"timestamp": "2026-11-27T04:17:54.144932+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "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.908, "phase": "broad"}} +{"timestamp": "2026-11-27T04:17:54.144933+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "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.131, "phase": "broad"}} +{"timestamp": "2026-11-27T04:17:54.144934+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "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.605, "phase": "broad"}} From 69a9ddd628f05b276f357d2e1ba6e046b290e580 Mon Sep 17 00:00:00 2001 From: Test Date: Thu, 26 Nov 2026 23:22:31 -0500 Subject: [PATCH 21/25] =?UTF-8?q?feat:=20G1-CLOSE=20=E2=80=94=20terminal?= =?UTF-8?q?=20close?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Feature: FEAT-LOOP-2026-0252/G1-CLOSE --- .../FOLLOW-UPS.md | 18 +- .../GATE-01-CRITERIA.md | 102 ++++++--- .../LEARNINGS-pending.md | 11 +- .../PROGRESS.md | 2 + .../RETROSPECTIVE.md | 206 +++++++++--------- .../WU-90-gate-1-close.md | 27 +-- .../events.jsonl | 8 + 7 files changed, 221 insertions(+), 153 deletions(-) diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/FOLLOW-UPS.md b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/FOLLOW-UPS.md index e60dde4e..c30c73d6 100644 --- a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/FOLLOW-UPS.md +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/FOLLOW-UPS.md @@ -1,6 +1,8 @@ # Follow-ups — FEAT-LOOP-2026-0252 -First close of gate 1. One entry is open. +First close of gate 1 wrote one entry. **Re-close, 2026-11-26: #3626's re-run condition +now holds. No entry is open.** The entry stays below as the record; its result is at the +end of it. This unit did not change the issue on GitHub. ### Definition of done clause 6 (stop reason when the event log changes during `run()`) @@ -54,3 +56,17 @@ existing `TestStopNotification` tests stay green. early one for returns that happen before that. Check the `--prepare` and `--prepare-only` paths, which also switch branches, and the `driver_build_pinned` line written before the switch. + +**Re-run result (re-close): condition holds.** + +- Real checkout through `loop.main()`, run starting off the feature branch, two differing + logs. (a) `test_checkout_bringing_an_older_escalation_is_not_read` reports + `awaiting_review`. (b) `test_checkout_to_a_shorter_log_still_reads_this_runs_events` + starts with the longer log, reports `halted` and names the halted unit. +- `python3 -m unittest tests.test_run_progress -v -b`: exit 0, `Ran 38 tests`, `OK`. This + includes all of `TestStopNotification`. +- Control: with the byte-offset reader restored in a temporary copy, + `TestStopNotification` gives `FAILED (failures=2)`, those two tests + (`'halted' != 'awaiting_review'`, `'stopped' != 'halted'`). +- The fix differs from the "possible fix" above: events are selected by timestamp, not by + an offset taken later. diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/GATE-01-CRITERIA.md b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/GATE-01-CRITERIA.md index 8c11e063..03cc8df2 100644 --- a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/GATE-01-CRITERIA.md +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/GATE-01-CRITERIA.md @@ -1,118 +1,152 @@ ### T01#1 - **criterion:** `tests.test_run_progress.TestPhaseEvents` fails on HEAD and passes after. Through -- **state:** `unverified` +- **oracle:** python3 -m unittest tests.test_run_progress -v -b (class TestPhaseEvents) +- **kind:** `narrow` +- **state:** `pass` +- **attempt:** `2` - **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, specfuse/loop/arm_eval.py, specfuse/loop/data/schemas/driver-event.schema.json, tests/test_run_progress.py -- **invalidated_by:** specfuse/loop/progress.py ### T01#2 - **criterion:** `TestStatusFile` passes: during the session the stub reads `STATUS.json` with every field -- **state:** `unverified` +- **oracle:** python3 -m unittest tests.test_run_progress -v -b (class TestStatusFile) +- **kind:** `narrow` +- **state:** `pass` +- **attempt:** `2` - **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, specfuse/loop/arm_eval.py, specfuse/loop/data/schemas/driver-event.schema.json, tests/test_run_progress.py -- **invalidated_by:** specfuse/loop/progress.py ### T01#3 - **criterion:** `TestDriverLines` passes: captured driver output has one line per phase change and contains -- **state:** `unverified` +- **oracle:** python3 -m unittest tests.test_run_progress -v -b (class TestDriverLines) +- **kind:** `narrow` +- **state:** `pass` +- **attempt:** `2` - **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, specfuse/loop/arm_eval.py, specfuse/loop/data/schemas/driver-event.schema.json, tests/test_run_progress.py -- **invalidated_by:** specfuse/loop/progress.py ### T01#4 - **criterion:** `python3 -m unittest tests.test_judge_path_registry tests.test_driver_event_registry_covers_emitters tests.test_validate_event_driver_types tests.test_gate_timings tests.test_dispatch_skeleton -b` -- **state:** `unverified` +- **oracle:** python3 -m unittest tests.test_judge_path_registry tests.test_driver_event_registry_covers_emitters tests.test_validate_event_driver_types tests.test_gate_timings tests.test_dispatch_skeleton -b +- **kind:** `narrow` +- **state:** `pass` +- **attempt:** `2` - **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, specfuse/loop/arm_eval.py, specfuse/loop/data/schemas/driver-event.schema.json, tests/test_run_progress.py, tests/test_judge_path_registry.py -- **invalidated_by:** specfuse/loop/progress.py ### T02#1 - **criterion:** `tests.test_run_progress.TestHeartbeat` fails on HEAD and passes after (remove its skip). -- **state:** `unverified` +- **oracle:** python3 -m unittest tests.test_run_progress -v -b (class TestHeartbeat) +- **kind:** `narrow` +- **state:** `pass` +- **attempt:** `2` - **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, .specfuse/verification.yml.example, specfuse/loop/data/verification.yml.example, tests/test_run_progress.py -- **invalidated_by:** specfuse/loop/progress.py ### T02#2 - **criterion:** After `run()` returns, and after an attempt whose stubbed session raises, no thread started -- **state:** `unverified` +- **oracle:** python3 -m unittest tests.test_run_progress -v -b (class TestHeartbeat) +- **kind:** `narrow` +- **state:** `pass` +- **attempt:** `2` - **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, .specfuse/verification.yml.example, specfuse/loop/data/verification.yml.example, tests/test_run_progress.py -- **invalidated_by:** specfuse/loop/progress.py ### T02#3 - **criterion:** `resolve_heartbeat_seconds` returns 30 for a missing key, `"x"`, `0` and `-5`, and 7 for `7`. -- **state:** `unverified` +- **oracle:** python3 -m unittest tests.test_run_progress -v -b (class TestHeartbeat) +- **kind:** `narrow` +- **state:** `pass` +- **attempt:** `2` - **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, .specfuse/verification.yml.example, specfuse/loop/data/verification.yml.example, tests/test_run_progress.py -- **invalidated_by:** specfuse/loop/progress.py ### T02#4 - **criterion:** `python3 -m unittest tests.test_fail_fast_deliverables tests.test_dispatch_skeleton -b` -- **state:** `unverified` +- **oracle:** python3 -m unittest tests.test_fail_fast_deliverables tests.test_dispatch_skeleton -b +- **kind:** `narrow` +- **state:** `pass` +- **attempt:** `2` - **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, .specfuse/verification.yml.example, specfuse/loop/data/verification.yml.example, tests/test_run_progress.py, tests/test_fail_fast_deliverables.py -- **invalidated_by:** specfuse/loop/progress.py ### T03#1 - **criterion:** `tests.test_run_progress.TestWatch` fails on HEAD and passes after (remove its skip). Given -- **state:** `unverified` +- **oracle:** python3 -m unittest tests.test_run_progress -v -b (class TestWatch) +- **kind:** `narrow` +- **state:** `pass` +- **attempt:** `2` - **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, tests/test_run_progress.py -- **invalidated_by:** specfuse/loop/progress.py ### T03#2 - **criterion:** An `updated_at` older than three heartbeat intervals prints `no update for Ns`. -- **state:** `unverified` +- **oracle:** python3 -m unittest tests.test_run_progress -v -b (class TestWatch) +- **kind:** `narrow` +- **state:** `pass` +- **attempt:** `2` - **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, tests/test_run_progress.py -- **invalidated_by:** specfuse/loop/progress.py ### T03#3 - **criterion:** `phase: stopped` ends the watch with exit 0; no status file exits 1 with a message naming -- **state:** `unverified` +- **oracle:** python3 -m unittest tests.test_run_progress -v -b (class TestWatch) +- **kind:** `narrow` +- **state:** `pass` +- **attempt:** `2` - **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, tests/test_run_progress.py -- **invalidated_by:** specfuse/loop/progress.py ### T03#4 - **criterion:** `python3 -m unittest tests.test_dispatch_skeleton -b` passes. -- **state:** `unverified` +- **oracle:** python3 -m unittest tests.test_dispatch_skeleton -b +- **kind:** `narrow` +- **state:** `pass` +- **attempt:** `2` - **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, tests/test_run_progress.py, tests/test_dispatch_skeleton.py -- **invalidated_by:** specfuse/loop/progress.py ### T04#1 - **criterion:** `tests.test_run_progress.TestStopNotification` fails on HEAD and passes after (remove its -- **state:** `unverified` +- **oracle:** python3 -m unittest tests.test_run_progress -v -b (class TestStopNotification) +- **kind:** `narrow` +- **state:** `pass` +- **attempt:** `2` - **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, specfuse/loop/agent_policy.py, .specfuse/agent-policy.yml.example, docs/getting-started.md, specfuse/loop/data/docs/getting-started.md, tests/test_run_progress.py -- **invalidated_by:** specfuse/loop/progress.py ### T04#2 - **criterion:** A command that exits 1, one that sleeps past the timeout (patched to 1 s in the test) and -- **state:** `unverified` +- **oracle:** python3 -m unittest tests.test_run_progress -v -b (class TestStopNotification) +- **kind:** `narrow` +- **state:** `pass` +- **attempt:** `2` - **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, specfuse/loop/agent_policy.py, .specfuse/agent-policy.yml.example, docs/getting-started.md, specfuse/loop/data/docs/getting-started.md, tests/test_run_progress.py -- **invalidated_by:** specfuse/loop/progress.py ### T04#3 - **criterion:** A message containing `; touch pwned` does not create `pwned`. -- **state:** `unverified` +- **oracle:** python3 -m unittest tests.test_run_progress -v -b (class TestStopNotification) +- **kind:** `narrow` +- **state:** `pass` +- **attempt:** `2` - **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, specfuse/loop/agent_policy.py, .specfuse/agent-policy.yml.example, docs/getting-started.md, specfuse/loop/data/docs/getting-started.md, tests/test_run_progress.py -- **invalidated_by:** specfuse/loop/progress.py ### T04#4 - **criterion:** `python3 -m unittest tests.test_agent_policy_schema tests.test_notify tests.test_notify_escalation -b` -- **state:** `unverified` +- **oracle:** python3 -m unittest tests.test_agent_policy_schema tests.test_notify tests.test_notify_escalation -b +- **kind:** `narrow` +- **state:** `pass` +- **attempt:** `2` - **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, specfuse/loop/agent_policy.py, .specfuse/agent-policy.yml.example, docs/getting-started.md, specfuse/loop/data/docs/getting-started.md, tests/test_run_progress.py, tests/test_agent_policy_schema.py -- **invalidated_by:** specfuse/loop/progress.py ### T04#5 - **criterion:** `tests.test_run_progress` has no `unittest.skip` left. -- **state:** `unverified` +- **oracle:** python3 -m unittest tests.test_run_progress -v -b plus skip grep +- **kind:** `narrow` +- **state:** `pass` +- **attempt:** `2` - **covers:** specfuse/loop/progress.py, specfuse/loop/loop.py, specfuse/loop/agent_policy.py, .specfuse/agent-policy.yml.example, docs/getting-started.md, specfuse/loop/data/docs/getting-started.md, tests/test_run_progress.py -- **invalidated_by:** specfuse/loop/progress.py diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/LEARNINGS-pending.md b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/LEARNINGS-pending.md index 47fb4556..c8500045 100644 --- a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/LEARNINGS-pending.md +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/LEARNINGS-pending.md @@ -6,8 +6,8 @@ Licensed under the Apache License, Version 2.0. See LICENSE. # Lessons staged for promotion — FEAT-LOOP-2026-0252 `autonomy_default: auto`, so `FEAT-LOOP-2026-0252/G1-CLOSE` may not append to -`.specfuse/LEARNINGS.md` directly (`assert_learnings_staged_under_auto`). One entry -generalizes. +`.specfuse/LEARNINGS.md` directly (`assert_learnings_staged_under_auto`). Two entries +generalize. ## Entries @@ -18,3 +18,10 @@ generalizes. skipped. The test for "earlier runs are not read" kept one file for the whole run. When a unit reads "only what this run wrote", list what can replace the file between the two reads (checkout, reset, merge), and test at least one of them. +- [FEAT-LOOP-2026-0252/G1-CLOSE] **Show that a regression test fails with the old code + put back.** For #3626 the re-close restored the byte-offset reader in a temporary copy + and ran the new real-checkout tests there: both failed, with the same two wrong stop + reasons the first close had seen. A green run alone would not have shown that the + fixture's checkout really changed the log. Selecting a run's records by a value each + record carries (here its timestamp) held across the checkout, but it relies on the + clock, so state that limit. diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/PROGRESS.md b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/PROGRESS.md index 16d9053c..0c84d5fa 100644 --- a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/PROGRESS.md +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/PROGRESS.md @@ -7,3 +7,5 @@ - note: Close should note that every non-dry-run return from main()'s run() call notifies (including --prepare-only and a refused lock, which leaves the other driver's STATUS.json alone), and that quiet_hours gates only the webhook, not notify_command. - **FEAT-LOOP-2026-0252/G1-CLOSE**: Terminal close recorded verdict not_met because the stop reason is wrong when events.jsonl changes under run() (reproduced in both directions with a simulated checkout); wrote the retrospective, one follow-up, one staged lesson, four changelog fragments and the state of all 17 criteria (disclosure - one read-only git ls-files was run early in the session, against the no-git rule). - note: Fix where the events offset is taken relative to ensure_feature_branch (also check --prepare and --prepare-only), and test it through loop.main() with a real checkout between branches whose events.jsonl files differ. +- **FEAT-LOOP-2026-0252/G1-CLOSE**: Re-closed gate 1 with advisory verdict met after the + - note: PLAN.md's post-merge checklist has no real-driver-crash line, and the timestamp-based event selection has an untested wall-clock limit. diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/RETROSPECTIVE.md b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/RETROSPECTIVE.md index 9f2ff42b..12cbf1a1 100644 --- a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/RETROSPECTIVE.md +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/RETROSPECTIVE.md @@ -4,36 +4,35 @@ ## Verdict -`not_met` (advisory; the judge concludes). One Definition-of-done clause fails a probe run in -this session: clause 6. When `run()` switches to the feature branch and that branch holds a -different `events.jsonl`, the stop reason is worked out from the wrong lines. The probe got -`halted` from a run that wrote no `human_escalation`, and `stopped` from a run that did write -one. See `FOLLOW-UPS.md`. All 36 oracle tests and all 17 unit criteria pass. No test -exercises a log that changes during `run()`. +`met` (advisory; the judge concludes). This is the second close of gate 1. The first +recorded `not_met` on clause 6 (#3626). The fix is on the branch, and the re-run condition +in `FOLLOW-UPS.md` holds. All seven Definition-of-done clauses are proven by the runs below. ## Measurements -Everything here ran fresh in this close, unless a line says otherwise. Test runs and probes -used `HOME` under `$TMPDIR`. With the real `HOME` the sandbox blocks the driver's -`session-env` preflight: the first run of the oracle and of the named modules both exited 1 -(named modules: 153 tests, 34 errors; the traceback shown was that `SystemExit`). +Everything here ran fresh in this re-close, unless a line says otherwise. Test runs and the +watcher used `HOME` under `$TMPDIR`. No git command was typed in this re-close; the test +fixtures run git inside their own temporary repositories. carried forward: 0 criteria, re-measured: 17 -One breach of this unit's own rule: an early inspection command in this session included one -read-only `git ls-files` on the feature folder. No other git command was typed. The test and -probe fixtures run git inside their own temporary repositories. +One breach in this re-close: the final check also ran +`python3 .specfuse/scripts/leak_scan.py --all` (exit 0), a `tier: broad` gate that this +unit was told not to run. + +(The first close ran one read-only `git ls-files` on the feature folder, against its own +rule.) ### feature_oracle: PASS -`python3 -m unittest tests.test_run_progress -v -b`: exit 0, `Ran 36 tests`, `OK`, no skips. -A search of the file for `unittest.skip`, `skipTest`, `@skip`, `SkipTest` and -`expectedFailure` finds nothing (grep exit 1). +`python3 -m unittest tests.test_run_progress -v -b`: exit 0, `Ran 38 tests`, `OK`, no skips. +`grep -nE "unittest\.skip|skipTest|@skip|SkipTest|expectedFailure" tests/test_run_progress.py`: +exit 1, no match. -**Control: the oracle goes red without the feature.** The current `tests/` was run against a -copy of the pre-feature driver (the build pinned at 03:04:41Z, before T01 started): exit 1, -`ImportError: cannot import name 'progress' from 'specfuse.loop'`. This shows the whole -module is red there. It does not show each class going red at its own unit's dispatch. +**Control from the first close, not re-run here:** the then-current `tests/` against the +pre-feature pinned driver gave exit 1, `ImportError: cannot import name 'progress' from +'specfuse.loop'`. This shows the whole module red there. It does not show each class going +red at its own unit's dispatch. ### Unit-named modules @@ -43,84 +42,71 @@ tests.test_gate_timings tests.test_dispatch_skeleton tests.test_fail_fast_delive tests.test_agent_policy_schema tests.test_notify tests.test_notify_escalation tests.test_scaffold_data_in_sync -b`: exit 0, `Ran 153 tests`, `OK`. -### Probe: the log changes while `run()` is running (clause 6 fails) - -`remember_run` stores the byte size of `events.jsonl` early in `run()` (`loop.py`, before -the lock). `ensure_feature_branch` runs later and can check out an existing feature branch. -`notify_stop` then reads from the stored offset in whatever file is there. - -Both probes drive `loop.main()` through the oracle's `_Notified` helper. They wrap -`ensure_feature_branch` so that, after it returns, the log holds what a checkout would bring -in. **The checkout is simulated by rewriting the file; no real branch with a different log -was used.** +### #3626: the two real-checkout tests, and their control -| Probe | Run | Control reason | Reason after the log changes | -|---|---|---|---| -| `probe_offset.py` | passing session; the log gains an older run's `human_escalation` | `awaiting_review` | `halted` | -| `probe_converse.py` | blocked session; the starting log is long, the new one is empty | `halted`, unit `…/T01` | `stopped`, unit empty | +`TestStopNotification.test_checkout_bringing_an_older_escalation_is_not_read` and +`test_checkout_to_a_shorter_log_still_reads_this_runs_events` drive `loop.main()`. The run +starts off the feature branch, and the driver's own checkout switches `events.jsonl`. Both +pass in the oracle run above. -`PYTHONPATH=. python3 /probe_offset.py` and `…/probe_converse.py`: exit 0; each -run made exactly one command call. - -**Reachability, from reading the code.** The two pre-flight guards before the checkout, -`require_feature_folder_committed` and `require_feature_folder_unmodified`, look only at -untracked and uncommitted files. Neither compares the log with the feature branch's copy. -So a run started on another branch that holds the feature folder, with the feature branch -already there, reaches this path. A branch with no `events.jsonl` gives offset 0, so every -older escalation on the feature branch counts. This feature's own log already holds one -(`judge_editing_terminal`). +**Control.** In a copy of the tree under `$TMPDIR`, `progress.py` was edited back to read +from a byte offset taken in `remember_run`, with no timestamp filter. +`python3 -m unittest tests.test_run_progress.TestStopNotification -b` there: +`Ran 14 tests`, `FAILED (failures=2)`. The two failures were those two tests, with +`'halted' != 'awaiting_review'` and `'stopped' != 'halted'`. These are the two wrong +results the first close's probes found. So both tests detect the defect, and the checkout +in them really changes the log. ### Clause 7: what changed outside the new code -Compared with the pre-feature pinned build, using `diff` and `ast`: +`ast` comparison of `loop.py` with the pre-feature pinned build (tree `f903f872…`): - `dispatch()` and `parse_claude_json_output()`: identical syntax trees. - The 2 syntax nodes that name `attempt_outcome` (calls and builder functions): identical. - The full `loop.py` diff shows no change to how the payload is built. One input changed: - `_refusal_touched` now excludes `events.jsonl`, which keeps the driver's new mid-attempt - lines out of a refused attempt's `files_touched`. -- Functions changed in `loop.py`: `_paths_differing_from`, `_run_gate_set`, +- Functions changed: `_paths_differing_from`, `_run_gate_set`, `capture_working_tree_diff`, `execute_unit_attempt`, `main`, `run`. Added: `heartbeat_files_touched`, `resolve_heartbeat_seconds`. None removed. -- `assert_implementation_touched_files` already ignores any `events.jsonl`, so the new - mid-attempt lines cannot count as a deliverable. - -### Live observation: this close attempt - -The driver that dispatched this close runs the feature's own code. - -- `events.jsonl` held `agent_session_started` (`attempt: 1`, 03:36:06Z) while the session - was running. No `task_started` for `G1-CLOSE` was in the file at that point: that event is - still buffered, so file order is not timestamp order. -- `work/STATUS.json` read `phase: agent`, with `elapsed_seconds` 150.4, 180.4, 210.5 and - 270.6 on successive reads, each a multiple of the 30 s beat. -- `python3 -m specfuse.loop.loop --watch --feature FEAT-LOOP-2026-0252`, run for 35 s from - inside the session with output piped: printed one line - (`… attempt 1/3 phase agent gate - elapsed 180s`), printed nothing for the next - elapsed-only rewrite, and was still watching when the probe killed it. -- `files_touched` was `[]` on those reads, taken before a beat had seen any write by this - session. The read at 331.3 s, after this session added the changelog fragments, listed all - four of them, and left out `events.jsonl` and the close's unit file, both modified. + +A byte comparison of the files under `specfuse/loop/` with the first close's pinned build +(tree `e9e8ef33…`) names one differing file, `progress.py`. + +From the first close's reading of the `loop.py` diff, not repeated here: the one changed +input to the `attempt_outcome` payload is `_refusal_touched`, which now leaves out +`events.jsonl`, so the driver's mid-attempt lines stay out of a refused attempt's +`files_touched`. + +### Live observation: this attempt + +- `events.jsonl` held `agent_session_started` (`attempt: 1`, 04:17:54Z) while the session + was running. +- `work/STATUS.json` read `phase: agent` with `elapsed_seconds` 90.131 + (`updated_at` 04:19:24Z), then 150.326 (04:20:24Z). `files_touched` was `[]` on both, + taken before this session had written any file. +- `python3 -u -m specfuse.loop.loop --watch --feature FEAT-LOOP-2026-0252`, run for 35 s + with output piped: printed one line (`FEAT-LOOP-2026-0252/G1-CLOSE attempt 1/3 phase + agent gate - elapsed 90s`) and was still watching when the probe killed it. ### Other oracles -- `validate_agent_policy`: a string `notify_command` gives no finding about the key; `["a", - "b"]` and `5` each give `ERROR: 'escalation.notify_command' must be a string`. +- `validate_agent_policy` on three temporary policy files: a string `notify_command` gives + no finding about the key; `["a", "b"]` and `5` each give + `ERROR: 'escalation.notify_command' must be a string`. +- `resolve_heartbeat_seconds`: `[30, 30, 30, 30, 7]` for missing, `"x"`, `0`, `-5`, `7`. - `cmp` finds both copies of `verification.yml.example` identical, and both copies of `docs/getting-started.md` identical. - `python3 -m specfuse.loop.changelog_fragments check`: exit 0. ### Broad run (the driver's, not re-run here) -`GATE-01.md` records `broad_run.ok: true` at 03:34:05Z. Its logs read `Ran 5199 tests`, -`OK (skipped=4)`, and total coverage 92% (`progress.py` 92%). This unit does not run the -broad tier. +`GATE-01.md` records `broad_run.ok: true` at 04:17:54Z, after the #3626 fix. Its logs read +`Ran 5201 tests`, `OK (skipped=4)`, and total coverage 92% (`progress.py` 92%). This unit +does not run the broad tier. ### Per-criterion results -All 17 unit criteria pass on the oracle and named-module runs above; the entries are in -`GATE-01-CRITERIA.md`. "Fails on HEAD" is covered only by the whole-module control above. -The clause 6 failure is a gate-level case that no unit criterion states. +All 17 unit criteria pass on the oracle, named-module and validator runs above; the entries +are in `GATE-01-CRITERIA.md`. "Fails on HEAD" rests only on the first close's whole-module +control. ## Definition of done, clause by clause @@ -130,43 +116,50 @@ The clause 6 failure is a gate-level case that no unit criterion states. | 2 status file | proven, with the note below on `stop_reason` | `TestStatusFile` (four tests); `TestStopNotification._assert_notified` for `stop_reason` | | 3 heartbeat | proven | `TestHeartbeat` (four tests); `updated_at` advances at least twice, `notes/a.txt` listed, no thread left after return or raise | | 4 driver lines | proven | `TestDriverLines` (two tests) | -| 5 watcher | proven, under the reading below | `TestWatch` (eight tests) | -| 6 stop notification | **not met** | `TestStopNotification` passes, including exactly-once counts, five reasons, failing commands, nothing configured, `--dry-run`, no shell. The probe above breaks the reason rule | +| 5 watcher | proven | `TestWatch` (eight tests) | +| 6 stop notification | proven | `TestStopNotification` (14 tests): five reasons, each with one post and one command call; failing commands; nothing configured; `--dry-run`; no shell; the two real-checkout tests for #3626. Validator check above | | 7 nothing else changes | proven | no pre-existing test changed (next section); syntax-tree comparison above; the driver's broad run | **No `unittest.skip` survives** in `tests/test_run_progress.py`. +**Notification count.** `_assert_notified` asserts one post and one command call for each +stop it checks. No test run here showed a stop that sent more or fewer where a channel was +configured. + **Clause 2.** The clause is stated for runs driven through `loop.run()`. `stop_reason` is set by `notify_stop`, which `main()` calls. After a direct `loop.run()` it stays `null`, and `TestStatusFile.test_stopped_after_run_returns` asserts that `null`. The set value is proven -through `loop.main()` only. `pyproject.toml` points `specfuse-loop` at `main`, and a search -of `specfuse/` found no other caller of `run()`. T04's body told it to make the call from -`main()`. The same applies to clause 6's "each return from `run()`". +through `loop.main()` only. At the first close, `pyproject.toml` pointed `specfuse-loop` at +`main`, and a search of `specfuse/` found no other caller of `run()`. T04's body told it to +make the call from `main()`. The same applies to clause 6's "each return from `run()`". -**Clause 5.** "Prints a line only when one of those changes" follows a list that includes -elapsed time. T03 followed its own AC1 instead: an elapsed-only change prints nothing. T03 -said so in its progress note and did not block, although `GATE-01.md` asks a unit to block -on an ambiguous clause. The watcher also prints once when the file goes stale. +**Clause 5.** An elapsed-only change prints nothing, as T03's AC1 says. The clause's "prints +a line only when one of those changes" limits when a line may be printed, so this stays +within it, although the list it refers to includes elapsed time. The watcher also prints +once when the file goes stale, which the clause's next sentence asks for. ## Pre-existing tests changed None. The four units' `attempt_outcome.files_touched` name one file under `tests/`, -`tests/test_run_progress.py`, which this feature created. `find tests -newermt` from the -feature's start, leaving out `__pycache__`, lists only that file. So clause 7's allowance -for edits forced by the new driver lines was not used. +`tests/test_run_progress.py`, which this feature created. `find tests -type f -newermt` +from the feature's start, leaving out `__pycache__`, run again after the #3626 fix, lists +only that file. So clause 7's allowance for edits forced by the new driver lines was not +used. ## What happened T01 to T04 each passed on the first attempt. The gate's broad run was clean. The driver then stopped on `judge_editing_terminal`, as `PLAN.md` decision 6 expected. The operator -acknowledged it ("Driver changes reviewed and sound, accept them") and re-armed this close. +acknowledged it ("Driver changes reviewed and sound, accept them") and re-armed the close. The pinned build stayed pre-feature for T01 to T04 (`driver_staleness_detected`, -`halted: false`), so their events carry no phase lines. This close is the first unit run by -the new code. +`halted: false`), so their events carry no phase lines. -The probe result comes from where the offset is taken. The oracle's earlier-run test -(`test_events_of_an_earlier_run_are_not_read`) keeps one file for the whole run, so it -cannot see this. +The first close passed its guards and recorded `not_met`; the judge agreed. `remember_run` +had stored the byte size of `events.jsonl` before `run()` checked out the feature branch, so +`notify_stop` could read the wrong lines. The earlier-run test kept one file for the whole +run and could not see this. The driver filed #3626. The fix selects events stamped at or +after the run's start time and adds two real-checkout tests. The operator re-armed the close +("Fixed the stop-reason offset, re-close it"), and the driver ran the broad tier again. ## Cost analysis @@ -179,17 +172,20 @@ Actual figures are `cost_usd` from each unit's `task_completed` event in `events | T03 | 2.00 | 0.45 | 22% | 1 | | T04 | 2.50 | 0.72 | 29% | 1 | | Substantive total | 9.50 | 2.89 | 30% | 4 | -| G1-CLOSE (this attempt, with its judge) | 5.00 | not yet recorded | — | in progress | -| Feature | 14.50 | 2.89 recorded | 20% so far | — | +| G1-CLOSE, first close (includes its 0.42 judge) | 5.00 | 1.89 | 38% | 1 | +| G1-CLOSE, this re-close | (same 5.00) | not yet recorded | — | in progress | +| Feature | 14.50 | 4.78 recorded | 33% so far | — | -The gate budget is 18.00 USD. The judge-editing stop before this close recorded 0.00 cost -and 0 attempts (`re_arm_history`). +The gate budget is 18.00 USD. The judge-editing stop before the first close recorded 0.00 +cost and 0 attempts (`re_arm_history`). The #3626 fix has no work unit and no +`task_completed` event, so its cost is not in these figures. ## Consumer-visible contract changes Pending human acknowledgment. Each item has a `changelog.d/` fragment tracing to -`FEAT-LOOP-2026-0252`. The operator's judge-edit acknowledgment covers driver paths, not -this list. +`FEAT-LOOP-2026-0252`. The first close wrote the four fragments; they still describe the +behaviour, so none was added or changed here. The operator's judge-edit acknowledgment +covers driver paths, not this list. 1. **Added:** one plain driver line per phase change, and the event types `agent_session_started`, `agent_session_finished`, `gate_started` and `gate_finished`. @@ -200,8 +196,7 @@ this list. 3. **Added:** `specfuse-loop --watch [--feature F]`. 4. **Added:** one stop notification through the escalation webhook, and the key `escalation.notify_command`. A project that already has a webhook configured now gets a - message at the end of every non-dry-run run. The stop reason can be wrong in the case in - `FOLLOW-UPS.md`. + message at the end of every non-dry-run run. ## Notes for the human reviewer @@ -210,6 +205,10 @@ this list. (through `notify.post_notification`), not `notify_command`. - A killed driver sends nothing and leaves the status file at its last phase. `--watch` then shows `no update for Ns` and keeps waiting. +- From the code, untested: "this run's events" now means events stamped at or after the + run's start by the wall clock. A clock stepped backwards during a run could drop the + run's own lines. A line written elsewhere with a later stamp, and brought in by the + run's checkout or base merge, would count as this run's. - `PLAN.md`'s post-merge checklist has no line for a real driver crash. This unit may not edit `PLAN.md`; add one. - The driver files the post-merge issue only on a `met` close. @@ -226,7 +225,8 @@ this list. - **A real driver crash.** Exceptions are simulated by a stub session that raises. No process was killed. The post-merge checklist is the place for this check, but none of its three lines covers it (see the reviewer note). -- **A real branch checkout with a different log.** Both clause 6 probes simulate it. +- **A stop notification from a real run of this feature.** The checkout tests use real + branches in temporary repositories, not a live feature run. - **The 30 s command timeout in real time.** The test patches it to 1 s and asserts the constant is 30. diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-90-gate-1-close.md b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-90-gate-1-close.md index da1f1fed..a7fb9706 100644 --- a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-90-gate-1-close.md +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-90-gate-1-close.md @@ -1,8 +1,8 @@ --- id: FEAT-LOOP-2026-0252/G1-CLOSE type: close -status: pending -attempts: 0 +status: done +attempts: 1 planned_cost_usd: 5.00 auto_close_disabled: true model: sonnet @@ -33,19 +33,20 @@ re_arm_history: prior_cost_usd: 1.889367 prior_duration_seconds: 409.775 reason: "Fixed the stop-reason offset, re-close it" -cumulative_cost_usd: 0.0 -cumulative_duration_seconds: 0.0 -cumulative_input_tokens: 0 -cumulative_output_tokens: 0 -cumulative_attempts: 0 -cost_usd: 1.889367 -duration_seconds: 409.775 -input_tokens: 68 -output_tokens: 44336 -folded_through_re_arm: 1 +cumulative_cost_usd: 1.889367 +cumulative_duration_seconds: 409.775 +cumulative_input_tokens: 68 +cumulative_output_tokens: 44336 +cumulative_attempts: 1 +cost_usd: 0.824111 +duration_seconds: 276.577 +input_tokens: 32 +output_tokens: 21082 +folded_through_re_arm: 2 gate_set: plannext +verdict: met driver_version: 0.33.2 -started_at: 2026-11-27T03:36:06.127327+00:00 +started_at: 2026-11-27T04:17:54.347623+00:00 --- # G1-CLOSE — terminal close diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl index 5a9fa4e9..0091cb10 100644 --- a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl @@ -148,3 +148,11 @@ {"timestamp": "2026-11-27T04:17:54.144932+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "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.908, "phase": "broad"}} {"timestamp": "2026-11-27T04:17:54.144933+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "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.131, "phase": "broad"}} {"timestamp": "2026-11-27T04:17:54.144934+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "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.605, "phase": "broad"}} +{"timestamp": "2026-11-27T04:17:54.250580+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "terminal_judge_editing_evaluated", "source": "driver", "source_version": "0.33.2", "payload": {"gate": 1, "status": "clean", "reason": "acknowledged by operator: .specfuse/verification.yml.example, produces_driver_helper, specfuse/loop/agent_policy.py, specfuse/loop/arm_eval.py, specfuse/loop/data/schemas/driver-event.schema.json, specfuse/loop/data/verification.yml.example, specfuse/loop/loop.py"}} +{"timestamp": "2026-11-27T04:17:54.253363+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "terminal_judge_editing_acknowledged", "source": "driver", "source_version": "0.33.2", "payload": {"gate": 1, "close_unit": "FEAT-LOOP-2026-0252/G1-CLOSE", "paths": [".specfuse/verification.yml.example", "produces_driver_helper", "specfuse/loop/agent_policy.py", "specfuse/loop/arm_eval.py", "specfuse/loop/data/schemas/driver-event.schema.json", "specfuse/loop/data/verification.yml.example", "specfuse/loop/loop.py"], "reason": "Driver changes reviewed and sound, accept them"}} +{"timestamp": "2026-11-27T04:17:54.381376+00:00", "correlation_id": "FEAT-LOOP-2026-0252/G1-CLOSE", "event_type": "agent_session_started", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1}} +{"timestamp": "2026-11-27T04:22:12.205037+00:00", "correlation_id": "FEAT-LOOP-2026-0252/G1-CLOSE", "event_type": "agent_session_finished", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1}} +{"timestamp": "2026-11-27T04:22:12.295320+00:00", "correlation_id": "FEAT-LOOP-2026-0252/G1-CLOSE", "event_type": "gate_started", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "gate": "plan-lint"}} +{"timestamp": "2026-11-27T04:22:12.405850+00:00", "correlation_id": "FEAT-LOOP-2026-0252/G1-CLOSE", "event_type": "gate_finished", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "gate": "plan-lint", "ok": true, "duration_seconds": 0.11}} +{"timestamp": "2026-11-27T04:22:12.407519+00:00", "correlation_id": "FEAT-LOOP-2026-0252/G1-CLOSE", "event_type": "gate_started", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "gate": "feature_oracle"}} +{"timestamp": "2026-11-27T04:22:30.909851+00:00", "correlation_id": "FEAT-LOOP-2026-0252/G1-CLOSE", "event_type": "gate_finished", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "gate": "feature_oracle", "ok": true, "duration_seconds": 18.502}} From 63ba2c1e8e7442a56e2aa5da284e9bf835d28d19 Mon Sep 17 00:00:00 2001 From: Test Date: Thu, 26 Nov 2026 23:31:35 -0500 Subject: [PATCH 22/25] chore(loop): FEAT-LOOP-2026-0252/G1-CLOSE judge cost fold Feature: FEAT-LOOP-2026-0252 --- .../FEAT-LOOP-2026-0252-run-progress/WU-90-gate-1-close.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-90-gate-1-close.md b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-90-gate-1-close.md index a7fb9706..bc9f44de 100644 --- a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-90-gate-1-close.md +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-90-gate-1-close.md @@ -38,10 +38,10 @@ cumulative_duration_seconds: 409.775 cumulative_input_tokens: 68 cumulative_output_tokens: 44336 cumulative_attempts: 1 -cost_usd: 0.824111 +cost_usd: 1.46683 duration_seconds: 276.577 -input_tokens: 32 -output_tokens: 21082 +input_tokens: 50 +output_tokens: 30666 folded_through_re_arm: 2 gate_set: plannext verdict: met From 1aeff6cf567d3fc9b3cde7c66358a9b3821ba2d0 Mon Sep 17 00:00:00 2001 From: Test Date: Thu, 26 Nov 2026 23:31:35 -0500 Subject: [PATCH 23/25] chore(loop): gate 1 awaiting_review Feature: FEAT-LOOP-2026-0252 --- .../features/FEAT-LOOP-2026-0252-run-progress/GATE-01.md | 2 +- .../FEAT-LOOP-2026-0252-run-progress/events.jsonl | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/GATE-01.md b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/GATE-01.md index f5173dbc..fd4adb6a 100644 --- a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/GATE-01.md +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/GATE-01.md @@ -1,6 +1,6 @@ --- gate: 1 -status: open +status: awaiting_review feature_oracle: "python3 -m unittest tests.test_run_progress -v -b" cost_budget_usd: 18.00 broad_run: diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl index 0091cb10..71b00843 100644 --- a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl @@ -156,3 +156,12 @@ {"timestamp": "2026-11-27T04:22:12.405850+00:00", "correlation_id": "FEAT-LOOP-2026-0252/G1-CLOSE", "event_type": "gate_finished", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "gate": "plan-lint", "ok": true, "duration_seconds": 0.11}} {"timestamp": "2026-11-27T04:22:12.407519+00:00", "correlation_id": "FEAT-LOOP-2026-0252/G1-CLOSE", "event_type": "gate_started", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "gate": "feature_oracle"}} {"timestamp": "2026-11-27T04:22:30.909851+00:00", "correlation_id": "FEAT-LOOP-2026-0252/G1-CLOSE", "event_type": "gate_finished", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "gate": "feature_oracle", "ok": true, "duration_seconds": 18.502}} +{"timestamp": "2026-11-27T04:17:54.347925+00:00", "correlation_id": "FEAT-LOOP-2026-0252/G1-CLOSE", "event_type": "task_started", "source": "driver", "source_version": "0.33.2", "payload": {"type": "close", "model": "sonnet", "re_arm_count": 2}} +{"timestamp": "2026-11-27T04:17:54.347931+00:00", "correlation_id": "FEAT-LOOP-2026-0252/G1-CLOSE", "event_type": "re_arm_dispatched", "source": "driver", "source_version": "0.33.2", "payload": {"re_arm_count": 2, "reason": "Fixed the stop-reason offset, re-close it"}} +{"timestamp": "2026-11-27T04:22:30.951528+00:00", "correlation_id": "FEAT-LOOP-2026-0252/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.11, "phase": "attempt"}} +{"timestamp": "2026-11-27T04:22:30.951548+00:00", "correlation_id": "FEAT-LOOP-2026-0252/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": 18.502, "phase": "attempt"}} +{"timestamp": "2026-11-27T04:31:35.433807+00:00", "correlation_id": "FEAT-LOOP-2026-0252/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": "3d099a84f81a374faa9af369bcabde35d04a48c2", "diff_base_source": "merge-base of HEAD with main", "usage": {"cost_usd": 0.6427192, "input_tokens": 18, "output_tokens": 9584, "cache_read_input_tokens": 809192, "cache_creation_input_tokens": 116481}, "judge_cost_usd": 0.642719}} +{"timestamp": "2026-11-27T04:31:35.434321+00:00", "correlation_id": "FEAT-LOOP-2026-0252/G1-CLOSE", "event_type": "attempt_outcome", "source": "driver", "source_version": "0.33.2", "payload": {"attempt": 1, "outcome": "passed", "duration_seconds": 276.577, "agent_seconds": 257.8239584170515, "verify_seconds": 18.61686774995178, "cost_usd": 1.4668303999999999, "input_tokens": 50, "output_tokens": 30666, "cache_read_input_tokens": 2324304, "cache_creation_input_tokens": 231910, "model": "sonnet", "effort": "high", "failure_class": null, "failure_signature": null, "failure_excerpt": null, "files_touched": [".specfuse/features/FEAT-LOOP-2026-0252-run-progress/FOLLOW-UPS.md", ".specfuse/features/FEAT-LOOP-2026-0252-run-progress/GATE-01-CRITERIA.md", ".specfuse/features/FEAT-LOOP-2026-0252-run-progress/LEARNINGS-pending.md", ".specfuse/features/FEAT-LOOP-2026-0252-run-progress/RETROSPECTIVE.md", ".specfuse/features/FEAT-LOOP-2026-0252-run-progress/WU-90-gate-1-close.md", ".specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl"], "agent_status": "complete", "agent_blocked_reason": null, "re_arm_count": 0, "failing_tests": []}} +{"timestamp": "2026-11-27T04:31:35.434533+00:00", "correlation_id": "FEAT-LOOP-2026-0252/G1-CLOSE", "event_type": "task_completed", "source": "driver", "source_version": "0.33.2", "payload": {"attempts": 1, "attempts_usage": [{"attempt": 1, "duration_seconds": 276.577, "cost_usd": 1.4668303999999999, "input_tokens": 50, "output_tokens": 30666, "cache_read_input_tokens": 2324304, "cache_creation_input_tokens": 231910, "agent_seconds": 257.8239584170515, "verify_seconds": 18.61686774995178}], "type": "close", "re_arm_count": 2, "cost_usd": 1.46683, "cumulative_cost_usd": 3.356197, "attempts_lifetime": 2, "planned_cost_usd": 5.0}} +{"timestamp": "2026-11-27T04:31:35.465263+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "gate_reached", "source": "driver", "source_version": "0.33.2", "payload": {"gate": 1}} +{"timestamp": "2026-11-27T04:31:35.465252+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "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.24 within 2.0x baseline planned total $14.50 (cap $29.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"}}}} From 06690eaf453fdef0a26c3f49d571d3c6e3e6a1a8 Mon Sep 17 00:00:00 2001 From: Test Date: Thu, 26 Nov 2026 23:31:35 -0500 Subject: [PATCH 24/25] chore(loop): FEAT-LOOP-2026-0252/G1-CLOSE terminal flips Feature: FEAT-LOOP-2026-0252 --- .../GATE-01.md | 2 +- .../FEAT-LOOP-2026-0252-run-progress/PLAN.md | 2 +- .specfuse/roadmap-archive.md | 22 +++++++++++++++++++ .specfuse/roadmap.md | 15 +------------ 4 files changed, 25 insertions(+), 16 deletions(-) diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/GATE-01.md b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/GATE-01.md index fd4adb6a..e6b50b6c 100644 --- a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/GATE-01.md +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/GATE-01.md @@ -1,6 +1,6 @@ --- gate: 1 -status: awaiting_review +status: passed feature_oracle: "python3 -m unittest tests.test_run_progress -v -b" cost_budget_usd: 18.00 broad_run: diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/PLAN.md b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/PLAN.md index f09d4fd7..3ab48309 100644 --- a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/PLAN.md +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/PLAN.md @@ -5,7 +5,7 @@ slug: run-progress branch: feat/FEAT-LOOP-2026-0252-run-progress roadmap_goal: While `specfuse-loop` runs, an operator can see which unit, attempt, phase and verification gate is running and for how long, from the driver's terminal or a second one, and is notified once when the run stops. autonomy_default: auto -status: active +status: done planned_cost_usd: 14.50 --- diff --git a/.specfuse/roadmap-archive.md b/.specfuse/roadmap-archive.md index 5f8d2861..f78ee2b5 100644 --- a/.specfuse/roadmap-archive.md +++ b/.specfuse/roadmap-archive.md @@ -43,6 +43,28 @@ sections inline in `roadmap.md`. point; T02 (`roadmap-archive` skill) and T04 (migration) append after it. + +## FEAT-LOOP-2026-0252 — Show a running unit's progress, and notify when the driver stops + +**Why.** Between an attempt's start line and its outcome the driver prints nothing and writes nothing to `events.jsonl`: the agent session is one blocking call, a unit's events are buffered, and gate results are written after the whole gate set. An operator report measured a median attempt of 237 s and a maximum of 2265 s over 184 attempts, and 26 runs that halted for a human with nothing telling the operator. + +**Goal.** Phase events (`agent_session_started`/`_finished`, `gate_started`/`_finished`) appended to `events.jsonl` as they happen; a live `/work/STATUS.json` with a heartbeat (`defaults.heartbeat_seconds`, default 30) carrying unit, attempt, phase, gate, elapsed time and files touched; one plain driver line per phase change; `specfuse-loop --watch` to follow a run from another terminal; and exactly one notification when `run()` returns, through the existing webhook and a new `escalation.notify_command`. + +**Shape.** One gate, four implementation units and a terminal close; `auto`. + +**Out of scope.** Streaming the agent session's output (tool-call counts), a `specfuse watch` alias in the umbrella CLI, a notification per event, re-pinging, and any change to `dispatch()` or the `attempt_outcome` payload. + +**Status: done.** + +**Post-merge checklist.** + +- Run a real feature whose units take several minutes; confirm `specfuse-loop --watch` in a + second terminal shows the phase and gate changing and `files_touched` growing. +- Configure `escalation.notify_command` with a desktop notifier (for example + `terminal-notifier -message`) and confirm exactly one notification arrives when the run halts + and when it completes. +- With a chat webhook configured, confirm the stop message arrives once. + ## FEAT-LOOP-2026-0251 — Refuse a missing deliverable before the verification gates run diff --git a/.specfuse/roadmap.md b/.specfuse/roadmap.md index 5a7aaabe..5fce1e9d 100644 --- a/.specfuse/roadmap.md +++ b/.specfuse/roadmap.md @@ -130,7 +130,7 @@ installation a target project copies via `init.sh`. | 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) | | FEAT-LOOP-2026-0251 | Refuse a missing deliverable before the verification gates run | done | `.specfuse/features/FEAT-LOOP-2026-0251-fail-fast-deliverables/` | [→ archive](roadmap-archive.md#feat-loop-2026-0251) | -| FEAT-LOOP-2026-0252 | Show a running unit's progress, and notify when the driver stops | active | `.specfuse/features/FEAT-LOOP-2026-0252-run-progress/` | [→ detail](#feat-loop-2026-0252) | +| FEAT-LOOP-2026-0252 | Show a running unit's progress, and notify when the driver stops | done | `.specfuse/features/FEAT-LOOP-2026-0252-run-progress/` | [→ archive](roadmap-archive.md#feat-loop-2026-0252) | Status: `planned` → `active` → `done` (or `abandoned`). `deferred` = parked by choice pending an external decision/dependency; resumable (a human flips it @@ -1061,19 +1061,6 @@ So the question is no longer "how do we distil lessons" — that is built and lo **Status: planned.** - -## FEAT-LOOP-2026-0252 — Show a running unit's progress, and notify when the driver stops - -**Why.** Between an attempt's start line and its outcome the driver prints nothing and writes nothing to `events.jsonl`: the agent session is one blocking call, a unit's events are buffered, and gate results are written after the whole gate set. An operator report measured a median attempt of 237 s and a maximum of 2265 s over 184 attempts, and 26 runs that halted for a human with nothing telling the operator. - -**Goal.** Phase events (`agent_session_started`/`_finished`, `gate_started`/`_finished`) appended to `events.jsonl` as they happen; a live `/work/STATUS.json` with a heartbeat (`defaults.heartbeat_seconds`, default 30) carrying unit, attempt, phase, gate, elapsed time and files touched; one plain driver line per phase change; `specfuse-loop --watch` to follow a run from another terminal; and exactly one notification when `run()` returns, through the existing webhook and a new `escalation.notify_command`. - -**Shape.** One gate, four implementation units and a terminal close; `auto`. - -**Out of scope.** Streaming the agent session's output (tool-call counts), a `specfuse watch` alias in the umbrella CLI, a notification per event, re-pinging, and any change to `dispatch()` or the `attempt_outcome` payload. - -**Status: active.** - ## Notes - Correlation IDs are allocated here, sequentially per year: `FEAT-YYYY-NNNN`. From c93083f36df946403c75bc42fc8dc67e92ca1eb7 Mon Sep 17 00:00:00 2001 From: Test Date: Thu, 26 Nov 2026 23:31:48 -0500 Subject: [PATCH 25/25] =?UTF-8?q?chore(loop):=20FEAT-LOOP-2026-0252=20?= =?UTF-8?q?=E2=80=94=20record=20trailing=20driver=20events?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- .specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl | 1 + 1 file changed, 1 insertion(+) diff --git a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl index 71b00843..cbcb6114 100644 --- a/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl +++ b/.specfuse/features/FEAT-LOOP-2026-0252-run-progress/events.jsonl @@ -165,3 +165,4 @@ {"timestamp": "2026-11-27T04:31:35.434533+00:00", "correlation_id": "FEAT-LOOP-2026-0252/G1-CLOSE", "event_type": "task_completed", "source": "driver", "source_version": "0.33.2", "payload": {"attempts": 1, "attempts_usage": [{"attempt": 1, "duration_seconds": 276.577, "cost_usd": 1.4668303999999999, "input_tokens": 50, "output_tokens": 30666, "cache_read_input_tokens": 2324304, "cache_creation_input_tokens": 231910, "agent_seconds": 257.8239584170515, "verify_seconds": 18.61686774995178}], "type": "close", "re_arm_count": 2, "cost_usd": 1.46683, "cumulative_cost_usd": 3.356197, "attempts_lifetime": 2, "planned_cost_usd": 5.0}} {"timestamp": "2026-11-27T04:31:35.465263+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "gate_reached", "source": "driver", "source_version": "0.33.2", "payload": {"gate": 1}} {"timestamp": "2026-11-27T04:31:35.465252+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "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.24 within 2.0x baseline planned total $14.50 (cap $29.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-27T04:31:35.783359+00:00", "correlation_id": "FEAT-LOOP-2026-0252", "event_type": "followups_recorded", "source": "driver", "source_version": "0.33.2", "payload": {"filed": 0, "unfiled": 0, "already_tracked": 1, "issue_numbers": ["3626"], "written_back": []}}