Skip to content

feat(#915): evidence-based effort escalation on quality-loop retries - #926

Merged
admarble merged 6 commits into
mainfrom
feature/915-feat-loop-evidence-based-effort-escalation-on-
Aug 10, 2026
Merged

admarble merged 6 commits into
mainfrom
feature/915-feat-loop-evidence-based-effort-escalation-on-

Conversation

@admarble

@admarble admarble commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds run.effortEscalation (default false) and a --escalate-effort flag on sequant run/sequant ready: on a retried phase execution, run one reasoning-effort tier above the resolved base, for that execution only.
  • Escalation is per-execution (computed at dispatch time via withEscalatedEffort, cloning ExecutionConfig), never baked into the config at build time — so it never leaks into a later, unrelated phase.
  • Wired at the two real retry-dispatch sites: batch-executor.ts's outer quality loop, and ready-gate.ts's QA-pass loop (both qa and loop sub-dispatches).
  • Metrics record base+escalated effort per escalated execution (effortEscalations, a sibling array to feat(run): per-phase model and effort configuration for the claude-code driver #914's phasePolicies); escalations print under --verbose.

Re-spec note

Spec was re-run against #914's actual merged shape (76fc911) after the prior plan — written while #914 was still open — got three integration points wrong: there is no spec-retry.ts file, the escalation channel is config.phasePolicies[phase].effort (not a separate field), and metrics needed a new sibling array rather than an extension of phasePolicies. The updated plan is on the issue: #915 (comment)

Deliberate deviations from the issue's literal AC-4 (flagged, not silent)

AC-4 names "spec retry and QA-stagnation re-runs" as the third escalation trigger, alongside the outer quality loop. Investigation during /spec found neither applies as written:

  • QA-stagnation is a halt signal, not a retry. detectStagnation's own doc comment says the orchestrator should not re-invoke /qa when stagnant — there is no re-run to escalate.
  • Spec-retry recovers transient failures, not evidence of difficulty. Its own code comment says spec has an ~8.6% transient failure rate; escalating there would spend tokens with no quality signal, which cuts against the issue's stated cost/quality thesis.

In their place, the sequant ready QA-pass loop (ready-gate.ts's qa/loop dispatch, pass ≥ 2) was wired as the third genuine retry site in the same subsystem — a real retry loop the original AC's intent clearly covers.

AC Verification

AC Description Status
AC-1 run.effortEscalation + --escalate-effort parsed, CLI > settings ✅ Implemented (both run and ready); mutation-verified both producers
AC-2 Disabled → retried phase runs at configured/inherited effort ✅ Implemented — unconfigured phase stays key-absent (not "carries the value undefined", which isn't expressible); configured phase carries its value unchanged
AC-3 Enabled → loop iteration ≥ 2 escalates one tier ✅ Implemented and tested at the resolver, cross-producer, and live-dispatch levels
AC-4 Same resolver across spec-retry + QA-stagnation ⚠️ Deviation, see above — wired at loop-retry + ready-gate QA-pass loop instead (one shared resolver, no per-call-site copies, for the two real retry sites)
AC-5 Unconfigured phase treats base as high, lands on xhigh ✅ Implemented as literally specified (DEFAULT_ESCALATION_BASE); flagged in effort-escalation.ts's doc comment that this is an explicit assumption about the SDK's actual default, easy to revise in one place if wrong
AC-6 Cap at max; ≤ one tier per retry, from configured base ✅ Implemented and mutation-verified (removing the cap fails exactly the boundary tests)
AC-7 Escalated tier scoped to the retried execution ✅ Implemented — config clone, never mutates the shared input. Note: because the outer quality loop re-runs its whole phase list per iteration (not just the failed phase), every phase dispatched during a retried iteration escalates together — documented in code and tests
AC-8 Metrics + verbose record base and escalated effort ✅ Implemented — effortEscalations metrics array (mutation-verified aggregation), verbose print at both live sites
AC-9 README + docs/ document flag, ladder, cost, no-downgrade rationale ✅ README, docs/reference/run-command.md, docs/reference/ready-command.md, CHANGELOG.md

Test plan

  • npm run build — clean
  • npm run lint — clean
  • Full suite: 259 files, 5339 tests passed (1 pre-existing expected-fail, 2 pre-existing skipped)
  • New dedicated tests: effort-escalation.test.ts (resolver + dispatch wrapper, all AC boundary cases), cross-producer tests in config-resolver.phase-policy.test.ts / ready-gate.phase-policy.test.ts, live-dispatch tests in batch-executor.test.ts, metrics tests in metrics-schema.effort-escalation.test.ts / run-orchestrator.phase-policy.test.ts, settings schema test in settings.phase-policy.test.ts
  • Mutation-verified: the AC-6 ladder cap, both cross-producer wiring lines (delete each → its guarding test fails for the right reason), and the metrics aggregation logic in run-orchestrator.ts

Closes #915

🤖 Generated with Claude Code

Adds run.effortEscalation (default false) and a --escalate-effort flag on
`sequant run`/`sequant ready`: when enabled, a retried phase execution
(outer quality-loop iteration ≥ 2, or a ready-gate QA-pass retry) runs one
reasoning-effort tier above its configured/inherited base, for that
execution only.

The resolver lives in a new effort-escalation.ts rather than beside #914's
resolvePhasePolicies in config-resolver.ts, to avoid a circular import
(config-resolver.ts already imports from batch-executor.ts, which needs
this resolver). withEscalatedEffort clones ExecutionConfig per dispatch
rather than baking an escalated value into the config at build time, so
escalating one phase's retry never leaks into the next phase in the chain.

Wired at the two real retry-dispatch sites: batch-executor.ts's outer
quality loop and ready-gate.ts's QA-pass loop (both qa and loop
sub-dispatches). Deliberately does NOT escalate phase-executor.ts's
cold-start/MCP-fallback/spec-retry loops — those recover transient
infrastructure failures, not evidence of task difficulty, and escalating
there would burn tokens for no quality signal.

Metrics: effortEscalations is a sibling array on MetricRunSchema, not an
extension of #914's phasePolicies — phasePolicies is a flat per-run map and
can't express a value that changes per retry.
…-to-end escalation-to-driver test

Closes two QA-review gaps:

- DEFAULT_ESCALATION_BASE was documented as an unverified assumption.
  Confirmed directly against @anthropic-ai/claude-agent-sdk's own query()
  Options type (sdk.d.ts): effort defaults to 'high'. No behavior change
  (the constant was already correct) — doc comment now cites the source
  instead of hedging.

- No test proved an escalated effort survives the full chain from resolver
  to the SDK call. The existing per-hop tests (phase-executor.phase-policy,
  claude-code.phase-policy) each proved one hop for an arbitrary effort
  string; phase-executor.effort-escalation.test.ts chains the real
  resolver, the real executePhaseWithRetry, and the real ClaudeCodeDriver
  together, mocking only the SDK's query() call — the same boundary #914
  already established, no live subprocess. Mutation-verified.

Third gap raised in review (standalone 'sequant ready' never writes run
metrics) is out of scope for this issue — filed as #929.
@admarble
admarble merged commit 969ddaf into main Aug 10, 2026
5 checks passed
@admarble
admarble deleted the feature/915-feat-loop-evidence-based-effort-escalation-on- branch August 10, 2026 00:19
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(loop): evidence-based effort escalation on quality-loop retries

1 participant