Repository navigation
Conversation
Entire-Checkpoint: b7016258fff5
Entire-Checkpoint: 500d0ba441de
…ows, and phase env Entire-Checkpoint: 9ec1805f9d30
…ng tests Entire-Checkpoint: 11eaa7ede512
…ing round-trip Entire-Checkpoint: dcf611ecc199
…marker payload Entire-Checkpoint: 58abc53d2668
…dy output Entire-Checkpoint: a62b6f03c30e
…tions field Entire-Checkpoint: 3f91ad0baac9
…latedModel The comment inside the escalating branch said the dispatch was "not topOfLadder yet", while the facts built ~25 lines below set topOfLadder on exactly that dispatch. Both are deliberate and tested (outcome flag = a trigger could not be honored; recorded facts = the rung the phase now sits on), but the comment read as describing both. State which of the two it governs. Comment only, no behavior change. Entire-Checkpoint: 2ff83a43c286
AC-5 and the issue Design both specify an ordering: "effort escalation remains the first rung (retry 1 -> effort +1 tier, same model). Model escalation fires only on a subsequent capability-bound trigger (retry >= 2 with no-progress stagnation)." The dispatch sites gated the effort bump on `isRetry && trigger === null`, which satisfied AC-5's second half (never both on one iteration) but violated its first: when iteration 1 produced no diff -- the ladder's own primary scenario -- retry 1 escalated the model and the effort rung was never spent at all. Because effort was suppressed by exactly the trigger class that escalates the model, and AC-3 forbids escalating on the other class, the two escalators were disjoint by trigger rather than sequenced as rungs: the composition the issue describes never occurred on a ladder-configured run, and the expensive model was reached a full rung early. Add `effectiveModelTrigger(trigger, retryIndex)` to model-ladder.ts, which withholds the trigger until retry 2. Both dispatch paths derive one `modelTrigger` from it and feed it to BOTH escalators, so AC-5's halves stay structural: "effort first" because a withheld trigger leaves the effort bump enabled, "never both" because an active one disables it. Applied at all four dispatch sites; kept in model-ladder.ts so the run path and ready gate cannot drift (AC-11). Tests that encoded the old ordering are corrected, and the ready-gate tests get a 4th iteration so they still cover the loop phase's record and a second rung rather than stopping at the first. Adds the regression test the QA gap named: it derives the trigger from a no-diff iteration 1 instead of hand-feeding it, and asserts the first effort bump precedes the first model rung. The previous AC-5 unit test hand-fed the sequence and so assumed the property under test. Entire-Checkpoint: 1d4af851317b
…ress lines These tests drive the real quality loop, which calls emitProgressLine. That writes SEQUANT_PROGRESS: lines to stderr whenever SEQUANT_ORCHESTRATOR is set, which it is when the suite runs inside an orchestrated `sequant run` phase. Those lines are the launcher's wire protocol — prefix-matched to drive the progress display and reset the no-progress watchdog — so 80 synthetic lines for issue 971 would spoof progress for whatever run is actually in flight. Scrub the var per the existing pattern in state-hook.test.ts. Entire-Checkpoint: e35b4b8e150a
10 tasks
admarble
deleted the
feature/971-feat-run-model-escalation-ladder-on-capability-bou
branch
September 8, 2026 08:34
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds the model escalation ladder (#971, graph node 11): with
run.modelLadder/--model-ladderconfigured, a phase that stalls with no progress is re-dispatched one rung up through the single shared resolver, sticks there, never skips or overflows, and records what it did. With no ladder, nothing changes.The routing constraint is the whole point: escalation fires only on the deterministic no-progress signals (
LOOP_NO_DIFF,SAME_SHA_NO_PROGRESS). Repeated QA failure at advancing SHAs is divergence-suspect and never escalates — a stronger model would only rediscover the contradiction more expensively.src/lib/workflow/model-ladder.ts, a peer ofeffort-escalation.ts(same cycle-avoidance rationale). Stickiness lives in per-runLadderState, never inExecutionConfig— the feat(loop): evidence-based effort escalation on quality-loop retries #915 AC-7 leak this shape prevents.config-resolver.ts:resolveModelLadder.ready-gate.tsinherits it through the shared config and never names the field (AC-11's static gate).batch-executor.ts's inner/loopspawn that feat(loop): evidence-based effort escalation on quality-loop retries #915's effort escalation never reached (spec sibling-site scan / OQ-6).Design decisions taken from the /spec open questions
LOOP_NO_DIFFbecomes continuable in the ready gate — but only when a ladder is configured, a rung remains, anditerations < maxIterations. Without this, AC-2's gate half is unreachable (there is no "next retry" to escalate). With no ladder the terminal is unchanged.batch-executorsnapshots each quality-loop iteration via an injectablesnapshotProgressFn, only when a ladder is configured (AC-D2).--modelspin that is not a ladder entry never escalates. Treatingladder[0]as "next" after an off-ladder pin would silently downgrade it — the inversion #915 and #971 both reject.detectCapabilityBoundTrigger(missing/inconsistent marker ⇒ no trigger + a reason).doctor.tshas no phase-marker check to route through, so "reconciled through the doctor path" is restated as "no escalation occurs and the reason is recorded". Reconciliation staysreconcile.ts's job, unwired here.resolveRoleToModel; raw strings stay legal. This node lands the schema fields, the pure field-builder, the round-trip test and the env threading (SEQUANT_MODEL_RUNG/_BASE/_ESCALATED/SEQUANT_ESCALATION_TRIGGER); #995 wires the skill prose that prints them.run.modelLadderdocumented in the generated settings-reference table.AC-5 is enforced structurally, not by convention. Both halves derive from one value:
effectiveModelTrigger(lastTrigger, retryIndex)withholds the trigger until retry 2, and that singlemodelTriggerfeeds both escalators —withEscalatedEffort(cfg, phase, isRetry && modelTrigger === null)thenwithEscalatedModel(cfg, phase, modelTrigger, state). "Effort first" holds because a withheld trigger leaves the effort bump enabled; "never both" holds because an active one disables it.Post-QA fixes (loop iteration 1)
The first QA pass returned
AC_NOT_METon three findings. All three are fixed here.1. AC-10: ready-gate escalations were recorded nowhere.
ReadyResult.modelEscalationswas populated at both gate dispatch sites and had zero consumers, while #915's
identical
effortEscalationschannel is consumed in three places. Compounding it,gate phase results never enter
IssueResult.phaseResults(batch-executor.ts:893returns them straight into the gate), and
phaseUsagerows are built only fromphaseResults— so a rung the gate spent had nowhere to ride. Net effect:sequant ready --model-ladderescalated the model, spent the money, recorded nothing.Fixed by mirroring #915 exactly: a run-level
MetricRun.modelEscalationslog mergedfrom both paths in
run-orchestrator.ts, verbose output for the gate path, and acommands/ready.tsprint (the only channel on the standalone gate, which writes norun metrics at all). This is not the "second array" the scope note rules out —
that note governs the per-execution facts, which remain columns on the
phaseUsagerow joined to the tokens that execution spent. This is the run-level log, and it
exists precisely because the gate path has no row to attach to.
2. CHANGELOG entry added under
[Unreleased] → Addedfor the new--model-ladderflag andrun.modelLaddersetting.3. Mutation markers rewritten so they parse. AC-1's contained literal braces
inside a string value — breaking the
{[^}]+}anchor, the same nested-bracefailure class AC-D1 exists to guard against — and four others put a
-tselectorwhere
classifyMutationMarkerexpects<file> > <test name>. All eight nowclassify
valid, and each resolves to exactly one real, passing test.Also addressed from QA's non-blocking notes: the AC-5 assertion now keys on what
changed this dispatch rather than what is merely present (a sticky rung plus an
effort bump is AC-6 behaving correctly, and the old presence-based filter would
have flagged it), and the
pr.escalatedModel→phaseUsagerow join now has adirect test.
One regression this surfaced: adding a required
modelEscalationsfield toReadyResultbroke two hand-built fixtures inready.test.ts. Worth noting thattsc --noEmitpassed both before and after — TypeScript cannot prove completenessacross a
...Partial<T>spread, so only the runtime suite caught it.Two broken verify commands (confirmed, as /spec flagged)
Both were green while asserting nothing. Re-ran on this branch:
npx vitest run src/commands/stats.test.ts -t "986 AC-6"→Tests 25 skipped (25), EXIT 0.-t "986 AC-6"is not a substring of any test name. Corrected:-t "AC-6"→1 passed | 24 skipped. ✅grep -rn 'modelLadder' ready-gate.ts config-resolver.ts | grep -v import | wc -lprints one combined count over both files and can never be 0 —config-resolver.tsmust mention it. Corrected per-file:grep -c 'modelLadder' src/lib/workflow/ready-gate.ts→0. ✅ (config-resolver.ts→7.)AC verification
-t "971 AC-1"→ 17 passed. CLI beats settings; with no ladder the key is absent (notundefined) on both producers, andwithEscalatedModelreturns the input config by reference (toBe, not justtoEqual).-t "971 AC-2"→ 11 passed. Driver-options assertion at the dispatch site on both paths: ready-gate (runReadyGate, real loop) →[undefined, "opus", "fable"]; run path (runIssueWithLogging, real quality loop) → same. Plus end-to-end intoquery()options.-t "971 AC-3"→ 3 passed. 3 iterations, new SHA each, failing verdicts → model option constant on every dispatch,modelEscalations: [].-t "971 AC-5"→ 5 passed. Retry 1 = effort only, retry 2 = model only, on both paths; the both-changed filter is empty. Includes a regression test that derives the trigger from a no-diff iteration 1 rather than hand-feeding it, and asserts the first effort bump precedes the first model rung.-t "971 AC-6"→ 7 passed. Sticky across trigger-less dispatches, per-phase, index +1 exactly (["opus","fable","fable"]), top rung leaves the model unchanged and setstopOfLadder.-t "971 AC-7"→ 5 passed. Pin sets the starting rung; off-ladder pin returns the config by reference and is explicitly asserted not to becomeladder[0]; pin with no ladder never escalates.-t "971 AC-8"→ 8 passed. Missing marker, nocommitSHA, wrong phase, unparseable timestamp → no trigger + reason. The guard runs before the signals: a rigged marker suppresses aLOOP_NO_DIFFthat would otherwise fire. Restated per OQ-4.-t "971 AC-10"→ 24 passed. Rung/base/escalated/trigger/requestedModelas columns on #986'sphaseUsagerow for the run path, plus a run-levelmodelEscalationslog so the ready-gate path (which produces no usage row) is auditable too — see the QA-fix note below. Old records still load:stats.test.ts -t "AC-6"✅.execution-config-parity.test.ts ready-gate.phase-policy.test.ts -t "971"→ 5 passed.grep -c 'modelLadder' ready-gate.ts→ 0.-t "971 AC-13"→ 2 passed. No production change needed —claude-code.ts:236already convertssubtype:"success" + is_error:trueintosuccess:false(landed with #973). Labelled a regression guard, and mutation-verified below.formatPhaseMarker→parsePhaseMarkers, and an escalated marker does not desync a sibling marker in the same body.Mutation verification
All eight records below were produced by mutating production code, running the
named test, observing the expected failure, and restoring. Every marker parses
as
validagainst this PR's diff (parseMutationMarkers), and everyfailedTestresolves to exactly one real, passing test.resolveModelLadderreturns an empty-array ladder key instead of omitting the keysmodel-ladder.test.ts— no-ladder-key assertionLOOP_NO_DIFFis unconditionally terminalmodel-ladder.test.ts— gate re-dispatches one rung upmodel-ladder.test.ts— never both changingeffectiveModelTriggerreturn the trigger unconditionally, restoring the pre-fix behaviour where retry 1 escalates the modelbatch-executor.model-ladder.test.ts— effort rung before any model rungqaLadder.recordintoReadyResult.modelEscalationsmodel-ladder.test.ts— gate carries every rungbuildPhaseConfigsets the inheritedmodelLaddertoundefinedexecution-config-parity.test.ts— gate inherits the ladderis_errorguard inclaude-code.tswith a constantfalsephase-executor.model-ladder.test.ts— #973 shapebuildEscalationMarkerFieldsemits a nested object instead of flat scalarsmodel-ladder.recording.test.ts— round-tripladderConfiguredgate on the per-iteration snapshotbatch-executor.model-ladder.test.ts— no snapshot when unconfiguredExec resume pass (2026-09-08)
Re-verified every gate independently rather than trusting the table above.
Build ✅, lint ✅, all 11 AC selectors ✅, all 9
SEQUANT_MUTATIONmarkers parseas
validand eachfailedTestresolves to exactly one real, passing test.One defect found and fixed in this pass, plus one pre-existing one surfaced but
deliberately left alone.
Fixed — the run-path ladder tests spoofed the launcher's wire protocol.
batch-executor.model-ladder.test.tsdrives the real quality loop, whichcalls
emitProgressLine. That writesSEQUANT_PROGRESS:lines to stderrwhenever
SEQUANT_ORCHESTRATORis set — true whenever the suite runs inside anorchestrated
sequant runphase. The file emitted 80 synthetic lineslabelled
{"issue":971,...}. Those lines are not cosmetic: the launcherprefix-matches them to drive the progress display and to reset the no-progress
watchdog, so a test run inside a live phase would report fabricated progress for
whatever run is actually in flight and suppress a watchdog that should have
fired. Fixed in
24d01210withvi.stubEnv("SEQUANT_ORCHESTRATOR", ""), theexisting pattern from
state-hook.test.ts. Emission is now 0 lines; 8/8 testsstill pass. The other three ladder test files were checked and emit nothing.
Surfaced, not fixed —
batch-executor.test.tshas the same ambient-env bug,and it belongs to #543.
withActivityHook (#543) > returns the input config unchanged when onProgress is undefinedassertstoBe(baseConfig), but withSEQUANT_ORCHESTRATORset the config gainsonActivity/onAutoWaitand theidentity check fails:
Pre-existing on
main, invisible in CI (which runs with the var unset), andunrelated to the ladder — it is #543's test reading the ambient environment.
Left untouched on the same reasoning the spec's sibling-site scan used for
#915's missing 4th-site effort escalation: fixing it here would change another
issue's test under a #971 PR. Flagged for a follow-up.
CLI wiring check (#305 class)
RunOptions.modelLadder--model-ladder <rungs>runandready(mirrors--escalate-effort's dual registration)sequant run --helpandsequant ready --helpboth show itExecutionConfig.modelLadder/modelLadderRequested/modelEscalationTest / build / lint
npm run build✅ ·npm run lint✅ (0 warnings) ·npm run lint:skill-calls✅ (no violations)src/commands/__tests__/prompt-wait.test.ts, a relay timing flake. Confirmed pre-existing: reproduced identically on a clean worktree at base0f278b40. Unrelated to this change.batch-executor.test.ts'swithActivityHooktest readsprocess.env.SEQUANT_ORCHESTRATORand therefore fails when the suite is run inside asequant runphase. Green with the var unset; also pre-existing.Deliberately out of scope (node 14 / #995)
Halts, the
SPEC_DIVERGENCEescape hatch, verbose output, README/docs, and the rigged real run.topOfLadderis surfaced on both the record and the marker so #995 can act on it from either path. The verify-failure trigger stays out (OQ-4); semantic finding comparison and downgrades remain rejected.Closes #971
🤖 Generated with Claude Code