Skip to content

feat(#1150): per-phase agent selection — run.phases.<phase>.agent - #1163

Merged
admarble merged 8 commits into
mainfrom
feature/1150-feat-run-per-phase-agent-selection-run-phases-phas
Sep 25, 2026
Merged

admarble merged 8 commits into
mainfrom
feature/1150-feat-run-per-phase-agent-selection-run-phases-phas

Conversation

@admarble

@admarble admarble commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1150

Summary

  • Per-phase override: run.phases.<phase>.agent overrides run.agent for one phase, for example run.agent: "codex" with run.phases.qa.agent: "claude-code".
  • One resolver: src/lib/workflow/phase-agent.ts (resolvePhaseAgent) is the only place that reads the run-level agent. Every per-phase driver decision goes through it:
    • phase-executor: the prompt, dry-run driver name and invocation, file context, driver instance, and the MCP-fallback gate;
    • the skills pre-flight and its orchestrator gate;
    • the model ladder;
    • sequant doctor.
  • Early validation: an unknown per-phase agent fails in buildExecutionConfig, before any worktree is provisioned or any phase runs. The message comes from assertKnownDriver, which getDriver now also calls, so it's identical to a bad run.agent.
  • Roles and the ladder follow the phase's agent: a role: model resolves against the phase's own agent. The model ladder is also resolved per overriding agent (ExecutionConfig.modelLadderByAgent, omitted when unused), and every per-phase ladder read goes through ladderForPhase. A pin on a phase's own driver's ladder is its starting rung, not an off-ladder pin.
  • Fix found along the way: role: references and ladder rungs were resolved against settings.run.agent even when --agent overrode it, so another driver's model was handed to the run's driver. They now resolve against the effective run-level agent. Behavior change: --agent codex with a claude-code-only string role (for example the default modelRoles, which uses string shorthand) plus a role: model now stops the run at config time with the existing "string shorthand" error. Pinned by two tests in config-resolver.model-roles.test.ts; separate Fixed entry in the changelog.

QA follow-ups (added after /qa)

  • Settings reference: the table generated in src/lib/settings.ts now has a run.phases row (agent/model/effort), and its agent row lists codex. The phases row had been missing since feat(run): per-phase model and effort configuration for the claude-code driver #914.
  • Suite no longer wipes the checkout's workflow state: state-utils.test.ts › "should skip invalid log files" called rebuildStateFromLogs without statePath. Every npm test run therefore replaced the working checkout's .sequant/state.json with an empty state. It now uses the temp statePath.
    • How it was found: a sentinel state.json was run against each suspect test file on its own.
    • Result: after a full npm test (341 files, 8428 passed), the sentinel issue is still present; before the fix it was wiped.
    • Not fixed here: three MCP tests (src/mcp/server.test.ts and two MCP integration tests) still rewrite the real state non-destructively. They run a live status reconcile that refreshes titles from GitHub and bumps lastSynced. This is left for a follow-up.

AC verification

AC Status Evidence
AC-1 ✅ PhasePolicySchema.agent. settings.phase-policy.test.ts checks the round-trip and that no unknown-key warning appears; config-resolver.phase-policy.test.ts checks the key reaches phasePolicies.
AC-2 ✅ config-resolver.phase-policy.test.ts: buildExecutionConfig throws Unknown agent driver "…", and the message equals getDriver's. skills-preflight.test.ts › 1150 AC-2: the real RunOrchestrator.run rejects with that message before any worktree is created, any pre-flight runs or any issue runs. resolveConfig calls buildExecutionConfig before ensureWorktrees.
AC-3 ✅ phase-executor.phase-agent.test.ts: exec runs on the real CodexDriver, qa on the real ClaudeCodeDriver. The issue's evidence path was updated from phase-executor.test.ts, which doesn't mock the registry.
AC-4 ✅ grep -rn "config\.agent" src/lib/workflow --include='*.ts' | grep -v "\.test\." prints one line: phase-agent.ts:23, inside resolvePhaseAgent.
AC-5 ✅ config-resolver.model-roles.test.ts covers role and ladder resolution per agent, and a failure that names the phase. model-ladder.test.ts shows exec escalating through codex models and qa through claude-code models, and covers the pin rung.
AC-6 ✅ skills-preflight.test.ts: an aider run with a claude-code exec requires only exec, and a claude-code run with an aider qa doesn't require qa.
AC-7 ✅ phase-executor.phase-agent.test.ts: a codex handle is passed to the codex exec but not to the claude-code qa. This uses the real canResume.
AC-8 ✅ doctor.test.ts: run.phases.exec.agent: "codex" with no codex binary reports the codex check as "configured as agent for phase exec".
AC-9 ✅ The 17 related test files (488 tests) passed before any new test was added. The #863 parity test in ready-gate-run.test.ts and phase-executor.test.ts pass unedited.
AC-10 ✅ docs/reference/run-command.md § Per-Phase Agent.
AC-11 ✅ npm run build, npm run lint, npm run typecheck:scripts pass. timeout 900 npm test: 341 files, 8425 passed, 1 expected fail, 3 skipped.

Mutation checks

None of the ACs count as gate tests under isGateTestEvidence. These were run anyway, and each was restored afterwards:

  • resolvePhaseAgent ignores phasePolicies: 11 tests fail, across AC-3, AC-5 (ladder), AC-6, AC-7 and AC-8.
  • Role resolution uses activeDriver instead of policy.agent ?? activeDriver: the AC-5 role test fails, 1 of 43.
  • The assertKnownDriver loop is removed: both AC-2 resolver tests fail (2 of 43), and the RunOrchestrator AC-2 test fails too.
  • agent is removed from PhasePolicySchema: the AC-1 round-trip test fails, 1 of 28.

Pre-PR confidence check

  • Weakest part: resolution runs at a few call sites (resolvePhaseAgent at each), so a new site that reads config.agent directly would bypass it. AC-4's grep is the guard against that. The CI GitHub Action (src/lib/ci/) still has its own single agent input; that's a Non-Goal.
  • Coverage gaps: there's no end-to-end sequant run with two real drivers, because that needs the codex binary. Dispatch is covered with real driver classes and a stubbed executePhase.

🤖 Generated with Claude Code

One resolver (phase-agent.ts) decides which driver runs each phase; phase-executor, the skills pre-flight, role and ladder resolution, and doctor all read through it. Unknown per-phase agents fail at config resolution with the registry's own message.
… .sequant/state.json

The 'should skip invalid log files' case called rebuildStateFromLogs without statePath, so every npm test run replaced the working checkout's workflow state with an empty one.
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): per-phase agent selection — run.phases.<phase>.agent

1 participant