Skip to content

feat(#995): SPEC_DIVERGENCE escape hatch, ladder halts with evidence bundles, docs - #1016

Merged
admarble merged 13 commits into
mainfrom
feature/995-feat-run-spec-divergence-escape-hatch-ladder-halts
Sep 8, 2026
Merged

admarble merged 13 commits into
mainfrom
feature/995-feat-run-spec-divergence-escape-hatch-ladder-halts

Conversation

@admarble

@admarble admarble commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The other half of #971's bargain: the ladder now knows when to stop instead of climbing. Three halts, each printing an evidence bundle and ending the run — plus the SPEC_DIVERGENCE escape hatch an agent uses to declare an acceptance criterion impossible as written.

  • SPEC_DIVERGENCE — agent-declared via "outcome":"SPEC_DIVERGENCE" in its own SEQUANT_PHASE marker. Terminal for the retry path as well as the ladder: no cold-start retry, no MCP fallback, no rung spent.
  • DIVERGENCE_SUSPECT — two consecutive iterations that each produced a diff at a still-failing verdict. Two, not one: a single such iteration is the ordinary AC_NOT_MET → /loop → re-QA cycle.
  • TOP_OF_LADDER — a further capability-bound trigger on the last rung, reported distinctly from MAX_ITERATIONS.
  • sequant ready gains the three matching terminal reasons; verbose output names triggers in words at all four dispatch print sites; new Model Escalation Ladder reference doc.

⚠️ AC ID scramble (from /spec). The issue's AC lines lead with AC-3 (halt half): rather than **AC-3:**, so ac-parser.ts assigns sequential IDs that do not match the issue's labels: issue AC-3→stored AC-1, AC-10→AC-2, AC-14→AC-3. This table uses the issue's labels throughout.

AC verification

AC Status Verify command → output
AC-3 (halt half) ✅ vitest -t "971 AC-3 halt" → 3 passed
AC-4 ✅ vitest -t "971 AC-4" → 7 passed; grep -c SPEC_DIVERGENCE templates/skills/{exec,loop}/SKILL.md → 3, 3 (≥1); md5 -q … | uniq | wc -l → 1 for exec and 1 for loop
AC-9 ✅ vitest -t "971 AC-9" → 2 passed
AC-10 (verbose half) ✅ vitest -t "971 AC-10 verbose" → 2 passed
AC-12 ✅ grep -c 'modelLadder|model-ladder' → README 2, model-ladder.md 4, run-command.md 2 (≥2 under the strict per-file reading, OQ-2); grep -c SPEC_DIVERGENCE docs/reference/*.md → model-ladder.md 6, run-command.md 2 (≥1)
AC-14 (real run) ✅ See Rigged run below
AC-D1 default-path safety ✅ Covered in model-ladder.test.ts — no halt reachable without a configured ladder
AC-D2 append-only schema ✅ Pre-#995 markers and the real 108 KB metrics.json still parse
AC-D3 dispatch-exactly-once ✅ 383315d2 — retry-path guard asserts dispatch count, not just final status

Full ladder suites: model-ladder + phase-executor.model-ladder + batch-executor.model-ladder → 85 passed. phase-executor + phase-detection → 229 passed. Build ✅ · Lint ✅ (0 warnings) · check-skill-sync → 44 synced, 0 diverged · lint:skill-calls → 0 violations.

AC-14 — the rigged run, and the defect it caught

Fixture #1015 (single AC: a file must both exist and not exist) was run twice through the real sequant run machinery. The first run failed, and that is the point — it surfaced a genuine shipped defect that the whole green suite was blind to.

Run 1 (c9b05922) — did not halt. Root cause, fixed here in eff47840:

  • ClaudeCodeDriver fills AgentPhaseResult.output from assistant text blocks only (drivers/claude-code.ts:194-199).
  • Both skills routed the marker to a gh issue comment — a tool input, never in output. Under sequant run the exec phase posts no issue comment at all, so the marker had no channel whatsoever.
  • parsePhaseMarkers additionally strips fenced code, so the documented example could not double as the declaration.

Net effect: specDivergence was always undefined under orchestration and a diverging spec climbed the ladder anyway — the precise cost #971 AC-4 exists to avoid. The suite was green because every divergence test handed a literal string straight to the parser; nothing drove driver-shaped output through mapAgentSuccessToPhaseResult. 53e6f918 closes that hole.

Run 2 (8f0e181d) — halted as specified, in 31 s on one exec dispatch:

Ladder halt: SPEC_DIVERGENCE — issue #1015, phase 'exec'
  Why: the agent declared the spec impossible as written — no model rung was spent
  Declared impossible: AC-1
  Escalation history:
    (empty — no model rung was spent)
  Next step: Reconcile the acceptance criteria with the repository as it exists,
    then re-run. A stronger model cannot resolve a contradiction in the spec.

Run record: phases: ["exec"] — qa was suppressed, not merely failed. phasePolicies.exec.resolvedModel = claude-sonnet-5, the ladder's bottom rung. AC-14 jq over .sequant/metrics.json → 0. Fixture #1015 closed with a comment linking the run.

Honest caveat on that jq. It returns 0 as AC-14 requires, but it is weak evidence on its own: phaseUsage is absent from every recent run record, not just this one, so the filter has nothing to reject. The load-bearing evidence is the empty escalation history in the halt bundle plus resolvedModel = claude-sonnet-5. Flagged here for the owner rather than filed as an issue (I-7).

Mutation-verified gate tests

Both mutations were run against a committed tree and restored; the suite is green after restore.

Mutation-verified: AC-4 — replaced SEQUANT_PHASE with SEQUANT_exec in the exec skill's example marker (all 3 mirrors); 971 AC-4 … the exec and loop skills tell agents when to emit the marker, in all three mirrored copies failed (expected [] to have a length of 1 but got +0); restored.

Mutation-verified: AC-4 — replaced the "final response message" channel wording with "a gh issue comment" in both skills (all 6 mirrors); the same test failed (expected 'When the spec is impossible as writte…' to match /final response\s+message/); restored.

AC-12 is gated by a manual grep, not by a test, so it carries no mutation record — its outputs are quoted verbatim in the AC table above.

Known gaps

  • phaseUsage is not emitted on this run path (see caveat above), which makes AC-14's jq a weaker check than it reads. Owner's call whether that warrants follow-up.
  • The run-2 agent had fixture: impossible AC — ladder divergence rig (#995 AC-14) #1015's prior comments in context, including the F3 diagnosis, so its choice to emit the marker unfenced was informed by them. The channel is genuinely exercised end-to-end regardless — the parser read the marker from driver output — but the agent's discovery of the correct form was not independent.

Closes #995


Post-QA follow-up (commit 5bac217d)

QA returned AC_MET_BUT_NOT_A_PLUS with two non-blocking gaps. Both are now closed.

1. divergence-halt.ts had no direct test. The halt tests drive the formatter through the real run and ready-gate paths, but never reach an empty shasTried, an empty iterations list, a present-but-empty declaredAcs, or a non-empty escalation history. That last pair is the load-bearing evidence for "no rung was spent" — a renderer that printed (empty …) over a populated history would invert the bundle's meaning with every integration test still green. New divergence-halt.test.ts: 14 tests.

Mutation-verified: replaced the (empty — no model rung was spent) line with (none); formatEvidenceBundle: escalation history is the 'no rung spent' proof > spells out an EMPTY history rather than omitting the section failed; restored, 14/14 green.

2. ready-gate.ts's qa-phase branch is unreachable today. Kept rather than dropped: batch-executor.ts's run-path check is phase-agnostic (it reads result.specDivergence for every phase, qa included), so deleting this would make the two paths disagree on the same input. The comment now states the reachability plainly and records why documenting the hatch in the qa skill is out of #995's scope — that skill's one-shot contract requires a ### Verdict: line from a closed four-value set, so adding a fifth exit is a design decision, not a gap fill. Owner's call.

⚠️ Unrelated pre-existing defect surfaced by this run

The QA phase emitted AC_MET_BUT_NOT_A_PLUS, but the orchestrator recorded AC_NOT_MET and dispatched a /loop iteration on that false premise. Cause: parseQaVerdict (phase-executor.ts:508) uses String.match — first match wins — and its pattern Verdict:?[^A-Za-z0-9_]*(…) matches verdict=AC_NOT_MET, which appeared earlier in the body where the QA comment quoted a test's own assertion string.

body: "| AC-3 | … bundle asserts 2x `verdict=AC_NOT_MET` |\n\n### Verdict: AC_MET_BUT_NOT_A_PLUS"
parsed  : AC_NOT_MET
emitted : AC_MET_BUT_NOT_A_PLUS

Any QA comment that quotes a verdict token before its own verdict line is mis-scraped. parseQaVerdict is untouched by this PR (git diff origin/main...HEAD → 0 occurrences); reporting rather than fixing, since it is shared QA-parsing code well outside #995's scope and needs its own tests. No issue filed, per I-7.

…ENCE marker fields

Entire-Checkpoint: ae6eed2ba02d
…ladder, verbose label

Entire-Checkpoint: 9755c3346c39
… three mirrors

Entire-Checkpoint: b8d099eedc41
…AC-3 halt

Entire-Checkpoint: 09abefb9f83a
… now parses it

Entire-Checkpoint: 474f06e00233
The rigged AC-14 run surfaced that the escape hatch was documented into an
unreachable state. The skills routed the marker to a `gh issue comment`, but
under `sequant run` the phase posts no issue comment at all, and the driver
fills `AgentPhaseResult.output` from assistant text blocks only
(drivers/claude-code.ts:194-199). `parsePhaseMarkers` additionally strips
fenced code, so the documented example cannot double as the declaration.

Net effect before this commit: `specDivergence` was always undefined under
orchestration, so a diverging spec retried and climbed the ladder anyway --
the exact cost #971 AC-4 exists to avoid.

States the channel explicitly in both skills, all three mirrors.

Entire-Checkpoint: 639e0fdfb793
… skill wording

The suite was green over the AC-14 defect because every divergence test hands
a literal string to `parseSpecDivergence`. Nothing drove driver-shaped output
through `mapAgentSuccessToPhaseResult`, which is where the marker is actually
read in a real run.

Adds a test reproducing `ClaudeCodeDriver`'s assistant-text-only capture and
asserting all three cases: marker in a tool input -> undefined (the shipped
defect), marker fenced in assistant text -> undefined (stripped by design),
marker bare in the final message -> parsed. Extends the AC-4 skill gate to
assert the section names the channel, not just the marker.

Entire-Checkpoint: 7e769fe92af6
The escape-hatch entry described the marker but not where it must appear.
Under `sequant run` a marker routed only to a `gh issue comment` never reaches
the parser, which is the defect the AC-14 rigged run surfaced.

Entire-Checkpoint: 7ea7cc84697b
…a-branch reachability

QA surfaced two non-blocking gaps.

1. `divergence-halt.ts` had no direct test. The halt tests drive the formatter
   through the real run and ready-gate paths, but never reach an empty
   `shasTried`, an empty `iterations` list, a present-but-empty `declaredAcs`,
   or a NON-empty escalation history. That last pair is the load-bearing
   evidence for "no rung was spent" (#971 AC-3/AC-4): a renderer that printed
   "(empty ...)" over a populated history would invert the bundle's meaning
   with every integration test still green. 14 tests close those branches.

2. `ready-gate.ts`'s qa-phase `specDivergence` branch is unreachable today --
   no skill instructs a qa agent to emit the marker. Kept rather than dropped
   because `batch-executor.ts`'s run-path check is phase-agnostic, so deleting
   it would make the two paths disagree on the same input. The comment now
   states that plainly, and records why documenting the hatch in the qa skill
   is out of #995's scope rather than leaving it to be rediscovered.

Entire-Checkpoint: 39b6ff1922d4
@admarble
admarble merged commit 7c46d07 into main Sep 8, 2026
9 checks passed
@admarble
admarble deleted the feature/995-feat-run-spec-divergence-escape-hatch-ladder-halts branch September 8, 2026 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(run): SPEC_DIVERGENCE escape hatch, ladder halts with evidence bundles, docs, rigged real run (#971 part B)

1 participant