Skip to content

fix(#867): SUMMARY duration is run wall clock, not per-issue sum - #868

Merged
admarble merged 2 commits into
mainfrom
feature/867-fix-cli-post-run-summary-duration-sums-per-issue-t
Jul 30, 2026
Merged

admarble merged 2 commits into
mainfrom
feature/867-fix-cli-post-run-summary-duration-sums-per-issue-t

Conversation

@admarble

@admarble admarble commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The post-run SUMMARY header duration was results.reduce((s, r) => s + r.durationSeconds). That was wall clock only while sequant run executed issues serially; #419 replaced the loop with Promise.allSettled + p-limit (default concurrency 3) and left the summation untouched, so every multi-issue run has since over-reported by ~the concurrency factor — a 36m 18s run printed 1h 12m. The stored log was always correct (finalizeRunLog uses (end - start)/1000), so sequant logs and the live summary disagreed ~2×.

The orchestrator — the only component that brackets the whole run — now owns a single wall-clock value; both consumers derive from it rather than each recomputing.

Changes

  • run-orchestrator.ts — RunOrchestrator.run() captures runStartedAt before any service/log setup, computes the run wall clock once, and surfaces it on a new RunResult.wallClockDurationSeconds. recordMetrics derives its duration from the same value (sibling site with the identical double-count bug under --parallel). The run origin is threaded into the LogWriter.
  • run-display.ts — displaySummary reads result.wallClockDurationSeconds; the reduce sum is deleted.
  • log-writer.ts / run-log-schema.ts — LogWriterOptions.startTime / createEmptyRunLog({ startTime }) let the log's stored wall clock share the orchestrator's origin, so sequant logs --last 1 and the SUMMARY header report the same number.

AC coverage

AC Status Evidence
AC-1 SUMMARY shows wall clock, not per-issue sum ✅ run-display.ts:196 reads wallClockDurationSeconds
AC-2 wall clock computed once; both derive from it ✅ runStartedAt origin → RunResult + log + metrics
AC-3 correct under --no-log / log-init failure ✅ runStartedAt captured before log setup, independent of logWriter
AC-4 sequential run unchanged ✅ "leaves a sequential run's duration unchanged" test
AC-5 3-concurrent >2× fixture prints wall clock ✅ 6×600s summed (3600s) vs 1200s wall clock
AC-6 test drives displaySummary from a RunResult ✅ captureSummaryInput / captureStdout, not renderSummary({...})
AC-7 sequant logs and SUMMARY agree, one fixture ✅ shared-origin cross-check via finalizeRunLog
AC-8 regression test mutation-verified ✅ see below

Mutation verification (AC-8)

Restoring the reduce sum at run-display.ts fails exactly the gate test — prints wall clock for a >2× parallel fixture; logs and SUMMARY agree (AssertionError: expected 3600 to be 1200) — while the AC-4 sequential test stays green (sum ≈ wall clock there). Fix restored after verifying.

Test plan

  • npm run build — clean
  • npm run lint — clean
  • npx vitest run on run-display, run-orchestrator, log-writer, run-log-schema — 130 passed

Closes #867


QA gap closure (second commit)

QA surfaced two gaps against the first commit. Both are filled here rather than deferred to follow-ups.

1. Cross-file sibling: src/lib/ci/outputs.ts

The issue body's "blast radius is limited to the CLI display" was incomplete. formatMultiOutputs (the GitHub Actions duration output) and formatSummary (the step summary's Total duration) each carried the identical results.reduce((sum, r) => sum + (r.durationSeconds ?? 0), 0) — same root cause, a third recompute site in a different consumer.

Both now take the run wall clock as a required argument. Required rather than optional-with-sum-fallback: a fallback leaves the defect exactly where it is today, and no-fallback-to-sum is the discipline the rest of this fix follows. Safe to make required — there are no in-repo callers, src/index.ts does not re-export lib/ci, and the package exports map is "."-only, so deep imports are blocked.

Per-phase durations in the summary tables are untouched — phases within an issue run sequentially, so only the run-level roll-up was wrong.

2. Orchestrator producer coverage

There was no run-orchestrator.test.ts at all. The display seam was tested from a hand-built RunResult, so the code that produces wallClockDurationSeconds was verified by review only. The empty-issue early return is a hermetic seam — it returns before any services, git, log writer, or network, and passing baseBranch skips detectDefaultBranch's shell-out — so the real RunOrchestrator.run() can now be driven and the run bracket asserted directly, including AC-3's --no-log path.

3. Duplication cleanup

The wall-clock subtraction had been restated at each of the seven return sites; collapsed into one wallClock() closure.

Mutation verification — gap-closure gate tests

Each new gate test was mutation-verified by restoring the reduce it exists to catch, confirming exactly the expected tests fail, then restoring. Results as actually observed:

# Mutation Result
1 formatMultiOutputs → restore the sum Exactly 1 of 14 fails: reports run wall clock, not the sum of overlapping per-issue durations — expected '3600' to be '1200'
2 formatSummary → restore the sum Exactly 1 of 14 fails: reports run wall clock in Total duration, not the per-issue sum — expected '## Sequant Workflow Results…' to contain '**Total duration:** 1200s'
3 wallClock() → derive from per-issue data instead of the run bracket (empty at this seam ⇒ 0) All 3 of 3 orchestrator producer tests fail — expected +0 to be 2178.334 / 45 / 600. All three assert the bracket, so all three are expected to catch this; noted because the count is 3, not 1.

The AC-4 sequential test stays green through all three mutations, pinning the fix as a no-op for serial runs. All mutations reverted after verifying.

Test plan — after gap closure

  • npm run build — clean
  • npm run lint — clean
  • npm test (full suite) — 225 files, 4643 passed, 1 expected fail, 2 skipped

The post-run SUMMARY header built its duration with
`results.reduce((s, r) => s + r.durationSeconds)`. That equalled wall
clock only while `sequant run` executed issues serially; #419 switched to
`Promise.allSettled` + `p-limit` (default concurrency 3) and left the
summation untouched, so from then on every multi-issue run over-reported
by ~the concurrency factor (a 36m 18s run printed 1h 12m). The stored log
was always correct, so `sequant logs` and the live summary disagreed ~2×.

The orchestrator now owns a single wall-clock value:
- `RunOrchestrator.run()` captures `runStartedAt` before any log setup, so
  the value is independent of the log writer (AC-3: --no-log, log-init
  failure) and computes the run wall clock once (AC-2).
- New `RunResult.wallClockDurationSeconds` carries it to the display;
  `displaySummary` reads it instead of re-summing (AC-1).
- `recordMetrics` derives its `duration` from the same value (sibling site,
  same double-count bug under --parallel).
- The run origin is threaded into the LogWriter → createEmptyRunLog, so the
  log's stored wall clock and the summary share one start; `sequant logs
  --last 1` and the SUMMARY header report the same number (AC-7).

Regression test drives `displaySummary` from a RunResult through the bug
site (AC-6), not `renderSummary({totalDurationSeconds})`: a 3-concurrent
fixture whose per-issue sum (3600s) is 3× the wall clock (1200s), the
verbatim measured run (36m 18s vs 1h 12m), and a shared-origin cross-check
that the log and summary agree (AC-7). A sequential fixture pins the fix as
a no-op there (AC-4).

Mutation-verified (AC-8): restoring the `reduce` sum at run-display.ts
fails exactly the gate test ("prints wall clock for a >2× parallel
fixture; logs and SUMMARY agree" — expected 3600 to be 1200) while the
AC-4 sequential test stays green.

Closes #867

Entire-Checkpoint: 7e42ef01892f
… test

QA on #867 surfaced two gaps in the open PR. Both are filled here rather
than farmed out as follow-ups.

Cross-file sibling (§5). `src/lib/ci/outputs.ts` carried the identical
`results.reduce((sum, r) => sum + (r.durationSeconds ?? 0), 0)` in two
places: `formatMultiOutputs` (the GitHub Actions `duration` output) and
`formatSummary` (the step summary's "Total duration"). Same root cause,
different consumer — the issue body's "blast radius is limited to the CLI
display" was incomplete. Both now take the run wall clock as a required
argument. Required rather than optional-with-sum-fallback because a
fallback leaves the defect exactly where it is today, and no-fallback-to-sum
is the discipline the rest of this fix already follows. No in-repo callers;
`src/index.ts` does not re-export `lib/ci` and the package `exports` map is
"."-only, so nothing external can be reached through it either.

Producer coverage. There was no `run-orchestrator.test.ts` at all — the
code that *produces* `wallClockDurationSeconds` was verified by review
only, while the display seam was tested from a hand-built `RunResult`. The
empty-issue early return is a hermetic seam (returns before services, git,
log writer, or network; passing `baseBranch` skips `detectDefaultBranch`),
so the real `RunOrchestrator.run()` can now be driven and the bracket
asserted directly, including the `--no-log` path from AC-3.

Also collapses the wall-clock subtraction, which this PR had restated at
each of the seven `return` sites, into one `wallClock()` closure.

Mutation verification
---------------------
Each new gate test was mutation-verified by restoring the `reduce` it
exists to catch, confirming exactly the expected tests fail, then
restoring. Results as actually observed:

1. `formatMultiOutputs` -> restore the sum. Exactly 1 of 14 fails:
   "reports run wall clock, not the sum of overlapping per-issue
   durations" (AssertionError: expected '3600' to be '1200').

2. `formatSummary` -> restore the sum. Exactly 1 of 14 fails:
   "reports run wall clock in Total duration, not the per-issue sum"
   (AssertionError: expected '## Sequant Workflow Results…' to contain
   '**Total duration:** 1200s').

3. `wallClock()` -> derive from per-issue data instead of the run bracket
   (empty at this seam, so 0). All 3 of 3 orchestrator producer tests
   fail: expected +0 to be 2178.334 / 45 / 600. All three assert the
   bracket, so all three are expected to catch this — noting it because
   the count is 3, not 1.

The AC-4 sequential test stays green throughout all three mutations,
pinning the fix as a no-op for serial runs. After restoring: 37 tests pass
across run-orchestrator, ci/outputs, and run-display; npm run lint and
npm run build clean.
@admarble
admarble merged commit ea780d1 into main Jul 30, 2026
5 checks passed
@admarble
admarble deleted the feature/867-fix-cli-post-run-summary-duration-sums-per-issue-t branch July 30, 2026 01:55
admarble added a commit that referenced this pull request Jul 30, 2026
CHANGELOG conflict: both PRs prepended to `### Fixed`. Kept both entries,
newest-first, matching the section's existing merge-recency ordering.

run-orchestrator.ts auto-merged cleanly and is semantically disjoint: #867's
work is run-level wall clock in `run()`/`RunResult`, mine is per-issue
`state.completedAt` in `applyProgressEvent`. Verified #868 reads `completedAt`
nowhere — the only readers are the #866 code and `cloneIssueState`.

Post-merge the tautology detector started failing (3 tests, exit 1). Cause is
scope, not quality: `git diff main...HEAD` now includes run-state.test.ts —
my new #866 block pulled the whole file in — exposing 16 pre-existing blocks
plus mine at 58.6%. Every block there drives production via a helper-built
RunOrchestrator and its captured `onProgress` callback, which the detector's
imported-name body scan cannot follow. Same limitation and same pragma as
run-renderer-672.test.ts; the #866 block is mutation-verified, so its
production coverage is proven rather than asserted. App.test.tsx and
ElapsedTimer.test.tsx pass the detector unskipped.
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.

fix(cli): post-run SUMMARY duration sums per-issue times instead of wall clock — 4-issue parallel run reported 1h 12m for 36m 18s

1 participant