Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
3d099a8
chore(loop): FEAT-LOOP-2026-0252 build pin recorded
Nov 27, 2026
d8ca9da
chore: scaffold feature FEAT-LOOP-2026-0252
Nov 27, 2026
2135629
chore(loop): FEAT-LOOP-2026-0252 build pin recorded
Nov 27, 2026
dff8414
chore(loop): FEAT-LOOP-2026-0252 plan baseline snapshot
Nov 27, 2026
c01e0da
feat: T01 — walking skeleton: phase events, the status file and plain…
Nov 27, 2026
f3dd26a
feat: T02 — heartbeat while an attempt runs
Nov 27, 2026
6d9873f
feat: T03 — `specfuse-loop --watch`
Nov 27, 2026
b69f46b
feat: T04 — one notification when the run stops, and the docs
Nov 27, 2026
48b4e84
chore(loop): gate 1 broad run clean
Nov 27, 2026
03ddb71
chore(loop): FEAT-LOOP-2026-0252/G1-CLOSE blocked (judge-editing term…
Nov 27, 2026
a091337
chore(loop): FEAT-LOOP-2026-0252 — operator acknowledged judge edits,…
Nov 27, 2026
cdb4c60
chore(loop): FEAT-LOOP-2026-0252 build pin recorded
Nov 27, 2026
7c37f95
feat: G1-CLOSE — terminal close
Nov 27, 2026
9b758a5
chore(loop): FEAT-LOOP-2026-0252/G1-CLOSE judge cost fold
Nov 27, 2026
5d71ebf
chore(loop): gate 1 awaiting_review
Nov 27, 2026
fd270e7
chore(loop): FEAT-LOOP-2026-0252 — record the follow-up issues the dr…
Nov 27, 2026
a6b8d04
fix(loop): stop reason reads this run's events by timestamp, not a pr…
Nov 27, 2026
db7d324
chore(loop): FEAT-LOOP-2026-0252 — re-arm G1-CLOSE after #3626
Nov 27, 2026
d7ffdec
chore(loop): FEAT-LOOP-2026-0252 build pin recorded
Nov 27, 2026
57f2791
chore(loop): gate 1 broad run clean
Nov 27, 2026
69a9ddd
feat: G1-CLOSE — terminal close
Nov 27, 2026
63ba2c1
chore(loop): FEAT-LOOP-2026-0252/G1-CLOSE judge cost fold
Nov 27, 2026
1aeff6c
chore(loop): gate 1 awaiting_review
Nov 27, 2026
06690ea
chore(loop): FEAT-LOOP-2026-0252/G1-CLOSE terminal flips
Nov 27, 2026
c93083f
chore(loop): FEAT-LOOP-2026-0252 — record trailing driver events
Nov 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .specfuse/agent-policy.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -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'"
72 changes: 72 additions & 0 deletions .specfuse/features/FEAT-LOOP-2026-0252-run-progress/FOLLOW-UPS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Follow-ups — FEAT-LOOP-2026-0252

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()`)

**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
`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 <scratchpad>/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 <scratchpad>/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
`<feature>/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.

**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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
### 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)
- **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

### 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)
- **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

### 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)
- **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

### 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
- **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

### 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)
- **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

### 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)
- **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

### 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)
- **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

### 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
- **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

### 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)
- **kind:** `narrow`
- **state:** `pass`
- **attempt:** `2`
- **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`.
- **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

### 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)
- **kind:** `narrow`
- **state:** `pass`
- **attempt:** `2`
- **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.
- **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

### 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)
- **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

### 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)
- **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

### T04#3

- **criterion:** A message containing `; touch pwned` does not create `pwned`.
- **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

### 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
- **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

### T04#5

- **criterion:** `tests.test_run_progress` has no `unittest.skip` left.
- **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
80 changes: 80 additions & 0 deletions .specfuse/features/FEAT-LOOP-2026-0252-run-progress/GATE-01.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
---
gate: 1
status: passed
feature_oracle: "python3 -m unittest tests.test_run_progress -v -b"
cost_budget_usd: 18.00
broad_run:
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: []
---

# 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, `<feature>/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

<Written by the human at review time.>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!--
Copyright 2026 Specfuse Contributors
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`). Two entries
generalize.

## 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.
- [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.
Loading