Repository navigation
refactor(#1507): split runIssueWithLogging (1,620 lines) into stage functions of ≤ 200 counted lines, behaviour-preserving - #1578
Merged
admarble merged 2 commits intoOct 23, 2026
Conversation
… most 200 counted lines Same-file, module-private stages share an explicit IssueRunEnv/IssueRunState pair. Every former break or return is a returned signal the caller checks. No behaviour change. Entire-Checkpoint: d5fbe297736e
…seline, ADR-0020, CHANGELOG Entire-Checkpoint: 01d4af48ff35
admarble
deleted the
feature/1507-refactor-workflow-split-runissuewithlogging-1-620-
branch
October 23, 2026 04:27
This was referenced Oct 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The 1,072-counted-line function in
src/lib/workflow/batch-executor.tsis now a short series of stage calls. The stages are private functions in the same file, so everyvi.mockin the tests still resolves and the file's exports are the same. They pass two objects explicitly, with no module-level state:IssueRunEnvis read-only and built once: the context, worktree path and branch, start time, auto-wait ledger,log/warn, the per-issue config and the relay activation.IssueRunStateis mutable and created per call: phase results, the resume handle, the phase list, the halt flags, the divergence bundle and the ladder state.The stages:
initIssueRun.dispatchSpecPhase,recordSpecOutcome,resolvePhasesFromSpec.finalizePhasePlan.runQualityLoop,runPhaseStep,dispatchLoopPhase,recordLoopPhaseOutcome,logLoopPhaseResult,handlePhaseFailure,runLoopFixPhase,assessIterationProgress.settleIssueStatusanddeliverIssueBranch.openOrUpdatePR,makeWaitTransitionandbuildBundleare now module-level functions.Control flow: every old
breakor earlyreturnis now a value the caller checks on the next line:runPhaseStepreturns"next"or"break".dispatchLoopPhasereturnsnullfor the top-of-ladder halt.IssueResultthat halts the issue.All 26
noteSuppressedlabels moved with their catches, unchanged.Shared helpers: only code whose output was already byte-identical in both places is shared:
buildPhaseErrorContext,phaseLogStatusandpersistResumeHandle. Spec's run-log entry still has no diff stats, commit hash or verdict.AC verification
max-lines-per-functioncommand →0git diff --numstattest-file count →0batch-executor.test.tsplusbatch-executor.suppressed.integration.test.ts: 154/154 passed1 1identical; see "Golden run" belowjqcheck →true;health-report --jsonshowsover2006,over4001, longestRunOrchestrator.run(649)__tests__/, 2 integration). All 15 passed: 368 testsdiffof^exportlines againstorigin/main→samenpm run build,npm run lint,tscandnpm run lint:healthare clean. knip reports nothing inbatch-executor.ts; its other findings were already onmainFiles changed
src/lib/workflow/batch-executor.ts: the split, plus three type-only imports (AutoWaitLedger,LadderState,LoopProgressSnapshot).scripts/qa/health-baseline.json: I edited only thefunctionskeys by hand. A full--write-baselinealso movestestRatio28d(a rolling 28-day number this change doesn't affect) and thegeneratedAt/commitstamps, so I left those as they were, per the runner note.docs/adr/0020-issue-run-stage-functions.mdand thedocs/adr/README.mdindex: the ADR is outside the issue's "May touch" list. The spec's Open Question 1 recommended including it.CHANGELOG.md: one[Unreleased]→### Changedline.Checks
npx vitest run --changed origin/mainselected 47 files, run as--shard=1/3,2/3and3/3: 16 / 16 / 15 files passed (274, 537 and 271 tests).--changedruns only files on both lists. It covered the 15 caller files plus 8 tests that read a changed file (adr-convention,health-report,ground-check,markdown-only-ci,merge-check-extended,assess-collision-detect,merger-release-checkout-lock,qa-markdown-on (runner: the generated body is cut here, at the 4000-character exec-summary cap incapImportedText`)Golden run (AC-5, runner, 2026-10-22)
The testbed is ad-motion #285, a fixture issue with one fixed change (
docs/golden-run.md). Both runs usedsequant run 285 --phases spec,exec,qa --force --full-qathrough the npm-linked devdist/. Before each run I removed the fixture's branch, worktree, comments andplannedlabel, and restored ad-motion's.sequant/from one snapshot..sequant/logs/)df795ca64run-2026-10-22T03-01-05-41f479a0-07c2-4456-a928-be468b53f9bb.json0672b1526run-2026-10-22T03-31-46-05a8fddb-5845-4707-9f79-64d8eb2c1150.jsonThe AC-5 projection is the same for both runs, and
diffprintsidentical:[{"issue":285,"phases":[{"phase":"spec","status":"success"},{"phase":"exec","status":"success"},{"phase":"qa","status":"success"}],"status":"success"}]Beyond the AC, the two runs also match on these points:
suppressed{total: 12, byScope: {other: 12}}.docs/golden-run.md.plannedlabel both times.Both PRs are closed unmerged.
A superseded first AFTER run. The first AFTER run (
run-2026-10-22T03-27-14-e724a5e7-…json) kept #285's original title. The branch name comes from the title, so it found the closed PR #286 by branch name and took the existing-PR path, not PR creation. Its spec also reused BEFORE's plan comment. Its projection matched too, which shows that the existing-PR path behaves the same on this build. It is not the AC-5 evidence. For the AFTER run above, I added "(run 2)" to the title and deleted the earlier comments, so it started from the same conditions as BEFORE.What the runner traced in the diff. Git's moved-code detection, allowing indentation changes, finds 2,070 moved lines, 491 added lines and 207 removed lines that are not moves. The removed lines are locals that moved onto the
IssueRunState/IssueRunEnvobjects, plus closures that became functions. I checked these by hand againstmain:finalizePhasePlankeeps main's order: resume filter, testgen, security-review,onPhasePlan.runPhaseStep,"break"happens exactly where the inline loop broke, including when a/looppass succeeds.TOP_OF_LADDER(dispatchLoopPhasereturnsnull) matches main's halt.I did not read
recordSpecOutcome,recordLoopPhaseOutcome,runLoopFixPhase,settleIssueStatusordeliverIssueBranchline by line. The unchanged suite (154 tests in AC-3's two files) and the golden run cover them.Fixes #1507
Follow-ups
🤖 Generated by
sequant run