Skip to content

feat(logs): run log records each phase's model and the sequant version #1198

Closed

Description

@admarble

Epic: field-2026-09-28 (downstream non-Node adoption) Tier: mechanical Graph: tracker #1203

Problem. PhaseLogSchema (run-log-schema.ts:234-275) has no model field, though the phase result carries resolvedModel and usage[] (phase-executor.ts:1684-1696). The run-log entry (batch-executor.ts:1833-1856) drops them. RunLogSchema has no tool-version field, only the log schema's version: 1. Only metrics.json has models, and its top-level model is a guess: process.env.ANTHROPIC_MODEL ?? "opus" (run-orchestrator.ts:1960). You cannot tell from a run log which model or which sequant produced a verdict.

AC

  • AC-1: Each phase entry in the run log records model (resolved) and requestedModel when the driver reports them. Evidence: npx vitest run src/lib/workflow/run-log-schema.test.ts
  • AC-2: The run log records sequantVersion and the driver name at the top level. Evidence: npx vitest run src/lib/workflow/run-log-schema.test.ts
  • AC-3: The metrics' top-level model comes from resolved phase models, not ANTHROPIC_MODEL ?? "opus". Evidence: npx vitest run src/lib/workflow/run-orchestrator.test.ts

The changes are additive and optional, so no schema-version bump is needed. Related: #914, #975, #971, #986.

Graph metadata

  • No dependency edges; frontier from wave 1.

May touch

  • src/lib/workflow/run-log-schema.ts
  • src/lib/workflow/batch-executor.ts
  • src/lib/workflow/run-orchestrator.ts

File overlap (don't run in the same wave; merge one first):

Activity

  1. added
    enhancement
    graph-2026-09-field
    on Sep 28, 2026
  2. admarble commented on Sep 29, 2026

    @admarble
    ContributorAuthor

    Context before wave 3 (main @ 1b0fa9a). #1193, #1194 and #1201 have merged since this issue was written. Two of them touched this issue's files: #1194 changed run-log-schema.ts and batch-executor.ts (PhaseLog now carries the qa summary), and #1201 changed run-orchestrator.ts. Current line refs:

    • PhaseLogSchema: run-log-schema.ts:240 (was :234)
    • resolvedModel is built at phase-executor.ts:1807 and set at :1818 (was :1684-1696)
    • run-log phase entry: batch-executor.ts:1863 (createPhaseLogFromTiming, main loop). Other call sites are at :1256 (spec) and :2041 (quality loop). All three should carry the model.
    • process.env.ANTHROPIC_MODEL ?? "opus": run-orchestrator.ts:2045 (was :1960)

    Run rules for the phase agents (spec, exec and qa):

    • exec and qa: do not run the full npm test. Run the targeted npx vitest run <files> named in the ACs, in the foreground with a timeout. Every MCP-dispatched phase has a hard 30-minute wall, and in wave 2 an exec ran up to 27 minutes. This applies to the qa phase too, not only exec.
    • Commit WIP early, and commit again before any mutation test. Work that is committed survives a phase timeout.
    • For a mutation record, failedTest must start with the test file path (src/…test.ts > <describe> > <case>). If it starts with a describe name, §6i floors the verdict to AC_NOT_MET.
    • In the PR body, put Closes #<this issue> for this issue and Refs #1203 for the tracker. Never Closes #1203.
    • A skill snippet that reads .sequant/settings.json must handle JSONC (comments and trailing commas), not bare JSON.parse/jq.
  3. admarble commented on Sep 29, 2026

    @admarble
    ContributorAuthor

    Complexity: Standard (3 ACs, 1 directory)

    AC Quality Check

    All three AC have an explicit Evidence: clause naming a scoped npx vitest run <file> command. Checked against main (1b0fa9a): run-log-schema.test.ts (76 tests) and run-orchestrator.test.ts (7 tests) both pass today with zero assertions on model/requestedModel/sequantVersion/driver or on the metrics model derivation — none of the three checks are vacuous.

    No vague/unmeasurable/incomplete language. No title/body tension.


    Scope Assessment

    Non-Goals: ⚠️ Not present in the issue body. The issue's own text is scoping enough (three additive fields, one guess replaced) that I don't think a split is warranted, but flagging per the checklist.

    Metric Value Status
    Feature count 1 (model/version/driver observability) ✅
    AC items 3 ✅
    Directory spread 1 (src/lib/workflow/) ✅

    Verdict: ✅ SCOPE_OK


    Acceptance Criteria

    AC-1: Each phase entry in the run log records model (resolved) and requestedModel when the driver reports them

    Verification: Unit Test
    Scenario: Given a phase execution whose driver populated modelUsage (so PhaseResult.resolvedModel is set) and/or whose config declared a role: policy for that phase → When createPhaseLogFromTiming builds the PhaseLog and LogWriter.logPhase persists it → Then the persisted entry carries model equal to the resolved model and requestedModel equal to the pre-resolution value; both fields are absent (not null/empty string) when the driver reported no modelUsage and no role was configured.
    Assumptions: Field naming and the source of requestedModel are open — see Design Review Q2 and Open Questions 1–2.

    AC-2: The run log records sequantVersion and the driver name at the top level

    Verification: Unit Test
    Scenario: Given a run with config.agent resolved (default "claude-code") → When LogWriter.initialize calls createEmptyRunLog → Then the top-level (sibling to version/runId, not nested in config) log object carries sequantVersion (from getVersion() in ./version.js) and driver (the resolved agent/driver name), for every driver — not just claude-code.
    Assumptions: RunConfigSchema currently has no agent field; driver needs a new home at the top level per the AC's literal wording, not inside config.

    AC-3: The metrics' top-level model comes from resolved phase models, not ANTHROPIC_MODEL ?? "opus"

    Verification: Unit Test
    Scenario: Given a run whose phases resolved concrete models via modelUsage (already computed by enrichPhasePoliciesFromResults) → When RunOrchestrator calls metricsWriter.recordRun → Then metrics.json's top-level model is derived from a resolved phase model, not the raw process.env.ANTHROPIC_MODEL ?? "opus" guess; the guess remains only as a last-resort fallback for drivers that report no modelUsage at all.
    Assumptions: Exact selection rule among multiple resolved phase models is open — see Open Questions 3.


    Implementation Plan

    Phase 1: Per-phase model/requestedModel in the run log

    1. Add model: z.string().optional() and requestedModel: z.string().optional() to PhaseLogSchema (src/lib/workflow/run-log-schema.ts:240-283).
    2. Extend createPhaseLogFromTiming's options Pick<PhaseLog, …> (src/lib/workflow/log-writer.ts:444-460) to include model/requestedModel.
    3. At all three call sites in batch-executor.ts (:1256 spec, :1863 main loop, :2041 quality loop), pass model: result.resolvedModel and requestedModel from the source decided in Open Question 2.

    Phase 2: sequantVersion/driver at the run-log top level

    1. Add sequantVersion: z.string().optional() and driver: z.string().optional() to RunLogSchema (run-log-schema.ts:382-406), top-level — sibling to version/runId.
    2. In createEmptyRunLog (run-log-schema.ts:439), set sequantVersion internally via getVersion() (./version.js) on every call (no caller plumbing needed), and accept driver in the existing options param, mirroring how startCommit is threaded today.
    3. Add driver?: string to LogWriterOptions (log-writer.ts) and thread it into the createEmptyRunLog call inside initialize().
    4. At the sole new LogWriter({...}) call site (run-orchestrator.ts:779), pass driver: config.agent.

    Phase 3: Fix the metrics.json guess

    1. In run-orchestrator.ts around :2045, capture the result of enrichPhasePoliciesFromResults(config.phasePolicies, results) in a local variable (it is currently inlined directly into the phasePolicies: field of the recordRun call) and derive model from it per Open Question 3, falling back to process.env.ANTHROPIC_MODEL ?? "opus" only when no phase resolved a model at all.

    No schema-version bump — all four new fields are optional/additive, matching the pattern already used for resolvedModel/usage/requestedModel (#975, #986).


    Design Review

    1. Where does this logic belong? Schema shape changes stay in run-log-schema.ts; population stays with the existing writers of that data — batch-executor.ts (per-phase), log-writer.ts/run-orchestrator.ts (top-level run log), run-orchestrator.ts (metrics). No new module.
    2. What's the simplest correct approach? Reuse the additive-optional-field pattern already established for resolvedModel/usage (feat(config): model roles — semantic indirection between phase policy/ladders and concrete model strings #975/fix(metrics): tokensUsed is 0 on every recorded run — capture-tokens.sh reads .usage (transcripts carry .message.usage) and run reads the wrong dir; wire SDK modelUsage tokens+costUSD per phase × model into metrics and stats #986) rather than introducing a new versioned log shape or a separate side-channel file.
    3. What existing pattern does this follow? Same shape as PhaseResult.resolvedModel/escalatedModel.requestedModel and PhasePolicy.requestedModel/resolvedModel — optional, additive, populated post-execution.
    4. What would a senior reviewer challenge? "Why is sequantVersion read fresh on every createEmptyRunLog call instead of once at process start?" (cheap — getVersion() is a package.json read cached by the OS, called once per run, not per phase) and "why does the metrics model pick one phase's resolved model to represent a run that could have dispatched several?" (see Open Question 3 — it's best-effort metadata, not a billing figure).

    Feature Quality Planning

    All standard checks pass. Two naming/source decisions are open (below) rather than gaps — they don't block implementation, but the wrong call risks an AC-1 test that "passes" against a narrower definition than the issue intends.


    Open Questions

    1. Field names on PhaseLogSchema: model/requestedModel (matches the issue's literal AC wording) vs. resolvedModel/requestedModel (matches existing PhaseResult/PhasePolicy naming). Recommendation: use model/requestedModel literally — /qa checks AC text literally, and the issue names these fields explicitly. Impact if wrong: a mutation-verified test written against one name needs a rename before merge.
    2. Source for requestedModel on the phase log: PhaseResult.escalatedModel?.requestedModel (only set when a ladder actually escalated) vs. config.phasePolicies?.[phase]?.requestedModel (set for any role:-configured phase, escalated or not). Recommendation: prefer phasePolicies — the escalation-only source under-reports the field for the common case of a role-configured phase that never escalated. Impact if wrong: AC-1's evidence test could pass against the narrower, escalation-only definition while leaving most role:-configured phases unrecorded.
    3. Metrics top-level model derivation: first phase (in config.phases order) with a resolvedModel, vs. most-common resolved model across phases, vs. the exec phase's model specifically. Recommendation: first phase in order with a resolvedModel, falling back to the existing ANTHROPIC_MODEL ?? "opus" guess only when no phase resolved one — simplest deterministic rule, and this field is descriptive metadata rather than a billing figure. Impact if wrong: a mixed-model run reports a technically-arbitrary "representative" model; low stakes either way.

    Recommended Workflow

    Phases: spec → testgen → exec → qa
    Quality Loop: disabled
    Reasoning: All three AC declare Unit Test evidence via scoped vitest commands (run-log-schema.test.ts, run-orchestrator.test.ts) — testgen stubs the new assertions before implementation. Mechanical, additive, single-directory change with no ladder/escalation risk — quality loop not warranted.


    Label Review

    Current: enhancement, graph-2026-09-field
    Recommended: No change beyond planned (added below).
    Reason: No UI/browser-test surface, no complexity/refactor/breaking signal, no security-sensitive path.
    Quality Loop: Won't auto-enable — SCOPE_OK, no escalation risk.


    Operational notes carried from the issue's own follow-up comment (2026-09-29, current line refs verified against main @ 1b0fa9a in this session)

    • PhaseLogSchema: run-log-schema.ts:240 · resolvedModel built at phase-executor.ts:1807, set at :1818 · run-log phase entry sites: batch-executor.ts:1256 (spec), :1863 (main loop), :2041 (quality loop) — all three need the new fields · ANTHROPIC_MODEL ?? "opus" guess: run-orchestrator.ts:2045.
    • exec and qa must not run the full npm test. Run only the targeted npx vitest run <file> named in each AC's Evidence, in the foreground with a timeout — every MCP-dispatched phase has a hard 30-minute wall.
    • Commit WIP early, and again before any mutation test.
    • A mutation record's failedTest must start with the test file path (src/…test.ts > <describe> > <case>), or §6i floors the verdict to AC_NOT_MET.
    • PR body: Closes #1198 for this issue, Refs #1203 for the tracker — never Closes #1203.

    --- DRAFT GITHUB ISSUE COMMENT (PLAN) ---

    AC Checklist

    • AC-1: PhaseLog records model/requestedModel per phase — npx vitest run src/lib/workflow/run-log-schema.test.ts
    • AC-2: RunLog records sequantVersion/driver at the top level — npx vitest run src/lib/workflow/run-log-schema.test.ts
    • AC-3: metrics model derives from resolved phase models, not the ANTHROPIC_MODEL guess — npx vitest run src/lib/workflow/run-orchestrator.test.ts

    Plan: Additive optional fields only, no schema-version bump.

    1. PhaseLogSchema + createPhaseLogFromTiming gain model/requestedModel; wired at all 3 batch-executor.ts call sites.
    2. RunLogSchema gains top-level sequantVersion (via getVersion()) and driver (from config.agent, threaded through LogWriterOptions → createEmptyRunLog).
    3. run-orchestrator.ts:2045 derives model from resolved phase models (first phase with a resolvedModel, in config.phases order) instead of guessing from ANTHROPIC_MODEL.

    Open decisions (see Open Questions above): field naming (model vs resolvedModel), requestedModel source (phasePolicies recommended over escalation-only), and the exact multi-model selection rule for the metrics field.

    Workflow: spec → testgen → exec → qa, quality loop disabled.

  4. added
    planned
    on Sep 29, 2026
  5. admarble commented on Sep 29, 2026

    @admarble
    ContributorAuthor

    Test Stubs Generated

    AC Verification Happy Path Failure/Edge Paths
    AC-1 Unit Test 3 stubs 1 stub
    AC-2 Unit Test 4 stubs 1 stub
    AC-3 Unit Test 1 stub 1 stub

    Counts explained:

    • Happy Path: Number of positive/success test stubs
    • Failure/Edge Paths: Number of absence/fallback/negative-requirement stubs, derived from each AC's own "absent, not null" / "only as a last-resort fallback" wording

    AC-1: per-phase model/requestedModel

    Gate file (per /spec's declared Evidence): src/lib/workflow/run-log-schema.test.ts

    • PhaseLogSchema describe block: 2 new stubs
      • accepts model/requestedModel when set
      • leaves both absent (not null/"") when the driver reported neither

    Supplementary (exercises the same behavior end-to-end through the real writer path the AC's Given/When/Then names — not required for the mutation gate, which is scoped to the file above):

    • src/lib/workflow/log-writer.test.ts
      • createPhaseLogFromTiming: includes model/requestedModel when passed in options
      • LogWriter.logPhase: persists model/requestedModel on the stored phase entry

    AC-2: top-level sequantVersion/driver

    Gate file: src/lib/workflow/run-log-schema.test.ts

    • RunLogSchema describe block: accepts sequantVersion/driver sibling to version/runId, not nested in config
    • createEmptyRunLog describe block: 3 new stubs
      • sets sequantVersion via the real getVersion() (no caller plumbing)
      • sets driver from options for a non-default driver (e.g. "opencode"), not just "claude-code"
      • leaves driver undefined when no driver option is passed

    Supplementary: src/lib/workflow/log-writer.test.ts — LogWriter.initialize threads options.driver through to the persisted run log

    AC-3: metrics model from resolved phase models

    Gate file: src/lib/workflow/run-orchestrator.test.ts

    • New describe block driving the private RunOrchestrator.recordMetrics directly (same exported-for-testing cast pattern as the existing #879 tests in this file), with ./metrics-writer.js mocked so recordRun's call args are inspectable:
      • derives model from the first phase (in config.phases order) with a resolvedModel, not process.env.ANTHROPIC_MODEL
      • falls back to ANTHROPIC_MODEL ?? "opus" only when no phase resolved a model at all

    Verified before posting: all 3 test files pass tsc --noEmit; all 11 new stubs fail with Test stub - implement this test (not a type or wiring error) via npx vitest run <file>, and every pre-existing test in these 3 files (76 + 52 + 7 = 135) still passes.

    Correction to the /spec plan: getVersion() lives at src/lib/version.ts, not src/lib/workflow/version.ts — from run-log-schema.ts/log-writer.ts/run-orchestrator.ts the import is ../version.js, not ./version.js.

    Next steps:

    1. Implement the test stubs (replace throw new Error(...) with real assertions per the inline TODOs)
    2. Run /exec 1198 to implement the feature
    3. Verify tests pass with the scoped npx vitest run commands named in each AC's Evidence

    Generated with Claude Code

  6. admarble commented on Sep 29, 2026

    @admarble
    ContributorAuthor

    Resuming exec (2026-09-29). The first wave-3 run was killed at 16:24 UTC by the MCP no-progress watchdog, which fires after 30 minutes with no phase boundary. This exec had been running for 36 to 44 minutes. Your committed WIP is on the branch and in the worktree, so pick up from it; do not start over.

    • Do not run the full npm test in exec or in qa. The last WIP commit said "before mutation testing and full suite". The full suite takes 10 to 13 minutes, and it is what pushed this phase past the wall. Run only the targeted npx vitest run <files> from the ACs, plus npx tsc --noEmit, in the foreground with a timeout. The runner runs the full suite.
    • Do at most one mutation per gate AC, commit before you mutate, and restore right after.
    • Keep the whole exec under 20 minutes. If you are near that, commit, push and open the PR with what is done, and list what is left in the PR body.
    • If git status ever shows tracked files deleted that you did not delete, stop and say so. Do not commit them. After the kill, the feat(logs): run log records each phase's model and the sequant version #1198 worktree had 44 top-level tracked files deleted (bin/, evals/, stacks/, CHANGELOG.md, LICENSE, …); the runner has restored them.
  7. admarble commented on Sep 29, 2026

    @admarble
    ContributorAuthor

    QA Verdict: AC_NOT_MET

    AC coverage: 2/2 met

    Gaps:

  8. added 2 commits that reference this issue on Sep 29, 2026
  9. admarble commented on Sep 29, 2026

    @admarble
    ContributorAuthor

    Runner fix for QA's AC_NOT_MET (PR #1220, now at a3bebf5)

    QA's two fix_now findings were real:

    1. All three batch-executor.ts sites (spec, main loop, quality loop) set requestedModel from config.phasePolicies[phase].model. resolvePhasePolicies has already replaced that value with the resolved model, so role:fast was logged as the concrete model. The sites now read .requestedModel, and ExecutionConfig.phasePolicies's type now declares it.
    2. No test covered the wiring. Two new tests in batch-executor.test.ts run runIssueWithLogging with a role: policy and with a raw model policy, and assert the options that reach createPhaseLogFromTiming.

    Runner checks: tsc --noEmit is clean, and the five AC and related test files passed (259 tests). Mutation: reverting the main-loop site to ?.model failed both new tests; restored. I added a CHANGELOG entry, replaced the PR body (which was the orchestrator's bare "Automated PR" text), and removed the doubled feat(#1198): feat(logs): from the title. The escalation requestedModel finding is documented in the PR as a known limitation, as QA recommended.

    QA will be re-dispatched once CI is green on a3bebf5.

  10. admarble commented on Sep 29, 2026

    @admarble
    ContributorAuthor

    QA Review for Issue #1198 (re-run at a3bebf5b)

    AC Coverage

    AC Description Status Notes
    AC-1 Phase log records model + requestedModel MET PhaseLogSchema gains both as optional. All three createPhaseLogFromTiming sites (spec, main loop, quality loop) pass resolvedModel and phasePolicies[phase].requestedModel, which is the pre-resolution role: string set by config-resolver.ts:453. The prior QA's fix_now (reading .model) is fixed, and it is covered by the new batch-executor.test.ts wiring tests.
    AC-2 Top-level sequantVersion + driver MET Both are on RunLogSchema as siblings of version/runId. createEmptyRunLog sets getVersion(). driver goes resolveRunAgent(config) → LogWriterOptions → initialize().
    AC-3 Metrics model from resolved phase models MET Uses the first phase in config.phases order with a resolvedModel. The ANTHROPIC_MODEL ?? "opus" guess is kept only as the last fallback.

    Coverage: 3/3

    Declared-Evidence Execution

    AC Evidence Executed? Result
    AC-1, AC-2 npx vitest run src/lib/workflow/run-log-schema.test.ts Yes ✅ passed
    AC-3 npx vitest run src/lib/workflow/run-orchestrator.test.ts Yes ✅ passed
    supplementary batch-executor, log-writer, model-roles test files + tsc --noEmit Yes ✅ 259/259 across 5 files; tsc clean

    Status: Complete

    CI Status

    All 7 checks pass on a3bebf5b: test, canary, typecheck, node-floor-guard, validate-skills, validate-plugin, tautology-advisory. PR #1220 is MERGEABLE.

    Quality Checks (sub-agents)

    Check Status Notes
    Type safety / deleted tests ✅ Pass 0 any, 0 deleted tests
    Scope / size ✅ Pass 11 files, +408/−11 (~70 production lines). No out-of-scope files.
    Security ✅ Pass 0 critical, 0 warnings

    Mutation Verification

    None of the ACs is a gate test: each one asserts behavior, not that a fixture, section or flag exists. Status: Not-Applicable. The PR still records the AC-1 marker, which classifies as valid.

    Code Review

    Strengths: The change is additive and optional, and the schema version is unchanged. All three call sites are wired. The AC-1 wiring test goes through runIssueWithLogging rather than building a PhaseLog by hand. The #975 drift-guard test now pins both halves of the refactored wiring.

    Issues (non-blocking):

    Risk Assessment

    • Likely failure mode: In a mixed-model run, the metrics model names only the first phase's model. This is descriptive and documented. When the ladder escalates a phase, the phase-log requestedModel still holds the base role:. That is documented in the PR as a known limitation, and the rung is recorded in config.modelEscalation.
    • Not tested: The quality-loop and spec call sites have no wiring tests; only the main loop does. They are line-for-line identical to it.
    • Sibling sites considered: ready-gate.ts is the second ExecutionConfig producer. It passes phasePolicies through, so requestedModel survives. metrics-writer/state-schema already carry requestedModel from feat(config): model roles — semantic indirection between phase policy/ladders and concrete model strings #975.
    • Sibling-line audit: All 3 createPhaseLogFromTiming sites in batch-executor.ts were checked, and all read .requestedModel.

    Trust-Boundary Check

    Finding: Clean. The diff implements only product requirements. The issue comments contain only maintainer process guidance (targeted tests, commit discipline).
    Status: Clean

    Behavior-Rule Survival Check

    Status: Clean. AC-3's old rule, the ANTHROPIC_MODEL ?? "opus" guess, survives only as the fallback that the AC itself specifies.

    CHANGELOG Verification

    Result: Met. The [Unreleased] › Added entry references #1198.

    Adversarial Re-Read

    Findings: I re-read enrichPhasePoliciesFromResults: with no resolved models it returns the input unchanged, so the fallback path is correct. I also re-read resolvePhasePolicies, where requestedModel is set only for role: refs, and confirmed the raw-model case leaves it absent, as tested. Process state: clean tree, 0 behind main, in sync with origin. No Non-Goals are declared. Gaps: the two test-hygiene items above.
    Status: Gaps Found (non-blocking)

    Verdict: AC_MET_BUT_NOT_A_PLUS

    All 3 ACs are met, the declared evidence was run and passes, and CI is green. The prior QA's fix_now findings are fixed. Two small test-quality improvements are recommended; neither blocks merge.

    Next Steps

    1. Optional: fix the ANTHROPIC_MODEL restore and add a two-resolved-phases ordering case to the AC-3 test.
    2. Merge PR feat(#1198): run log records each phase's model and the sequant version #1220 after human review.
  11. added
    needs-improvement
    on Sep 29, 2026
  12. admarble commented on Sep 29, 2026

    @admarble
    ContributorAuthor

    QA Verdict: AC_MET_BUT_NOT_A_PLUS

    AC coverage: 3/3 met

  13. added a commit that references this issue on Sep 29, 2026
  14. added a commit that references this issue on Sep 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementgraph-2026-09-fieldneeds-improvementplanned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions