Skip to content

refactor(#1508): split run, ensureWorktree, executePhaseWithRetry and executePhase to ≤ 200 counted lines; max-lines-per-function ratchet for src/lib/workflow - #1585

Merged
admarble merged 9 commits into
mainfrom
feature/1508-refactor-workflow-split-run-ensureworktree-execute
Oct 24, 2026
Merged

admarble merged 9 commits into
mainfrom
feature/1508-refactor-workflow-split-run-ensureworktree-execute

Conversation

@admarble

@admarble admarble commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

All six functions in src/lib/workflow that were over 200 counted lines are now split. A new max-lines-per-function rule keeps the whole directory at 200 or under. I followed ADR-0020 Option A: private stage functions in the same file, early exits returned as values that the caller checks, and no new exports or modules. No test file changed. The branch feature/1508-refactor-workflow-split-run-ensureworktree-execute is pushed, and the orchestrator opens the PR.

Function Before After (largest piece)
RunOrchestrator.run 649 66 (+14 stage methods, max 105)
ensureWorktree 393 73 (+6 stages, max 113)
executePhaseWithRetry 262 47 (+6 helpers, max 80)
runReadyGate 253 under 200 (tracked phase run, halt bundle and finish moved to module functions)
executePhase (phase-executor) 236 163 (+3 helpers)
ClaudeCodeDriver.executePhase 230 under 200 (stream loop, result mapping and throw mapping now private methods; per-run captures in a StreamState)

Pre-PR AC Verification

AC Status Evidence
AC-1 ✅ eslint max-lines JSON count → 0 (it was 6 on main)
AC-2 ✅ awk → found. The new src/lib/workflow/**/*.ts block in eslint.config.js comes after the src/commands/** block.
AC-3 ✅ npm run lint → green
AC-4 ✅ test-file numstat → 0
AC-5 ✅* npx vitest run src/lib/workflow/ (2 shards): 2,406 passed, 1 failed. The one failure is the known codex gpg conformance test, tracked in #1480. It also fails at base (block below).
AC-6 ✅ (runner) The golden run on ad-motion #285 prints identical; see "Golden run" below
AC-7 ✅ functions.over200 → 0. over400 is also 0. The longest function is now collectInstallChecks, 197 lines.

Ratchet check: the same rule found 6 functions over the limit on main (the AC-1 baseline) and finds 0 now, with lint green.

Golden run (AC-6, runner)

The testbed is ad-motion #285, a fixture issue with one fixed change (docs/golden-run.md). Both runs used sequant run 285 --phases spec,exec,qa --force --full-qa through the npm-linked dev dist/, launched detached from ad-motion. Before each run I removed the fixture's branch, worktree, comments and planned label, restored ad-motion's .sequant/ from one snapshot, and bumped the title suffix so the branch slug could not find the previous closed PR.

Run Build Run log PR spec / exec / qa
BEFORE (run 3) main 039d2021f run-2026-10-23T04-45-40-3ad400d4-d599-4ab0-affb-9566bf46a76b.json #288 40 s / 174 s / 217 s
AFTER (run 4) this PR f851332c9 run-2026-10-23T05-15-29-1751db83-1835-4c98-901b-dcfd54f72949.json #289 26 s / 32 s / 193 s

AC-6 projection (diff <(jq -S '[.issues[] | {issue: .issueNumber, status: .status, phases: [.phases[] | {phase: .phase, status: .status}]}]' "$BEFORE") <(jq -S … "$AFTER") && echo identical) → identical. Both sides:

[{"issue":285,"status":"success","phases":[{"phase":"spec","status":"success"},{"phase":"exec","status":"success"},{"phase":"qa","status":"success"}]}]

Also checked on both runs: suppressed is {"total":12,"byScope":{"other":12}}; a "PR #N created" line is in both logs; planned was added both times. Both PRs are closed unmerged and the testbed is reset.

Caveats. The durations differ because the agents' work is not deterministic; the AC compares statuses only. The previous session's .sequant snapshot was lost with the scratchpad, so both runs restored a fresh snapshot taken before run 3 (its state.json has no #285 entry). That snapshot and the two run logs are kept outside both repos under ~/Projects/ad-motion-sequant-snap/ and ~/Projects/ad-motion-golden-logs/.

Runner re-verification on head 2dda4b1af (2026-10-24)

After the golden run, the owner asked for the three noteSuppressed labels in phase-executor.ts to follow their host functions (2dda4b1af: resolvePhaseFiles, buildPhaseEnv, and executePhase without the orphaned #3). That commit changes three string literals in diagnostic labels, so the AC-6 result on f851332c9 stands by the owner's decision; AC-1 to AC-5 and AC-7 were re-run on 2dda4b1af with the results below. npm run lint:health reports no metric above the baseline.

AC Result
AC-1 eslint count → 0 (6 on main)
AC-2 awk → found
AC-3 npm run lint → green
AC-4 test-file numstat → 0
AC-5 npx vitest run src/lib/workflow/ → 2406 passed, 1 failed, the known gpg codex driver-conformance test; identical counts on main 039d2021f
AC-6 identical (above)
AC-7 functions.over200 → 0, over400 → 0

Freeze grep (plugin/, .claude/skills/, templates/skills/) and session-link grep over the diff and the commit messages: empty. Branch 0 behind main.

Settled against base

Ref Result
Head feature/1508-… @ f851332c9 FAIL (exit 1)
Base origin/main @ 039d2021f FAIL (exit 1)

Test: src/lib/workflow/drivers/__tests__/driver-conformance.test.ts -t "commit: git add and git commit succeed". It also fails at base; the issue is #1480.

Checks

Files changed

Pre-PR Confidence Check

  • Weakest part: the size of the run-orchestrator.ts and phase-executor.ts diffs. The retry loop's old attempt--; continue after an auto-wait is now a returned rewait value, and every early exit from run now goes through a returned RunResult | null. The unchanged suites pass, but the golden run (AC-6) is the last check of behaviour.
  • Coverage gaps: none that are new. AC-4 means the existing suites are the only coverage.

CLI wiring: N/A, no option interfaces changed. Quality Plan Alignment: there were no new tests or error paths to add. Log strings and call order are kept, and AC-6 is left to the runner. Docs: nothing user-facing beyond the CHANGELOG entry.

PR status: left to the orchestrator; the branch is pushed. Next step: the runner does the golden run (AC-6), then QA.

Fixes #1508

QA verdict: NEEDS_VERIFICATION — acceptance criteria met, pending external verification (e.g. CI or a manual test). See the QA review comment.


🤖 Generated by sequant run

…and env helpers

Entire-Checkpoint: 522a98fcdcc8
…ult and throw stages

Entire-Checkpoint: c6fb99acef12
…and finish become module functions

Entire-Checkpoint: 82bde66ef1be
…R-0020 note, CHANGELOG

Entire-Checkpoint: c497442f5c88
…nctions of ≤ 200 counted lines

Entire-Checkpoint: 75c1ecaf73d5
…0 counted lines

Entire-Checkpoint: 531c978b2e9c
…tor at their host functions

resolvePhaseFiles and buildPhaseEnv now host the catches that used to be in executePhase, so the file:function labels follow them; the #3 suffix on the one left in executePhase has nothing to be numbered against any more.

Entire-Checkpoint: 16ff31ee3dd6
@admarble
admarble merged commit 683ce66 into main Oct 24, 2026
9 of 10 checks passed
@admarble
admarble deleted the feature/1508-refactor-workflow-split-run-ensureworktree-execute branch October 24, 2026 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant