Repository navigation
Description
Epic: graph-2026-10-fundamentals Tier: judgment Execution: split Blocked by: #1471, #1475, #1507
- Blocked by: refactor(logs): one run-log module — parseLogFile, listLogFiles, resolveLogDir, formatDuration defined once #1471
- Blocked by: refactor(workflow,locks): worktreeStatus tri-state replaces both isWorktreeDirty copies; one formatSignalLine #1475
- Blocked by: refactor(workflow): split runIssueWithLogging (1,620 lines) into stage functions of ≤ 200 counted lines, behaviour-preserving #1507
Problem
After F-06 the remaining functions over 200 counted lines in src/lib/workflow are six (ESLint counting, blanks and comments skipped, measured 2026-10-18): RunOrchestrator.run (run-orchestrator.ts:790, 646), ensureWorktree (worktree-manager.ts:1057, 393), executePhaseWithRetry (phase-executor.ts:2030, 262), runReadyGate (ready-gate.ts:595, 253), executePhase (phase-executor.ts:1593, 233), ClaudeCodeDriver.executePhase (drivers/claude-code.ts, 230). #1471 edits phase-executor.ts; #1475 edits run-orchestrator.ts and worktree-manager.ts; this node waits for both so the splits move consolidated code. ready-gate.ts and drivers/claude-code.ts are in no consolidation node (#1472 touches aider, codex and opencode, not claude-code). The ESLint rule then holds the line for the whole directory.
Acceptance Criteria
- AC-1: No function over 200 counted lines in the workflow layer. Evidence:
npx eslint --rule 'max-lines-per-function: [error, {max: 200, skipBlankLines: true, skipComments: true}]' 'src/lib/workflow/**/*.ts' --ignore-pattern '**/*.test.ts' --format json | jq '[.[].messages[] | select(.ruleId=="max-lines-per-function")] | length'→0 - AC-2: The ratchet is in the config as its own block scoped to the workflow layer (the
src/commands/**block already exists, so a baregrep -cof 1 is today's baseline and proves nothing). Evidence:awk '/src\/lib\/workflow\/\*\*/{f=1} f&&/max-lines-per-function/{print "found";exit}' eslint.config.js→found - AC-3: Lint is green with the rule (constraint: green today, must stay green after AC-2). Evidence:
npm run lint > /dev/null 2>&1 && echo green→green - AC-4: No test lines are added (I-3, constraint). Evidence:
git diff --numstat $(git merge-base origin/main HEAD)..HEAD -- '*.test.ts' '*.test.tsx' | awk '{a+=$1} END{print a+0}'→0 - AC-5: The workflow suites pass unchanged (constraint; the suite takes more than 90 s and the known local gpg-signing failure in
driver-conformanceis not this node's — CI'stestcheck is the authority). Evidence:npx vitest run src/lib/workflow/→0 failed - AC-6: Golden run (runner, OQ-8), same command as F-06 AC-5. Evidence:
diff <(jq -S '[.issues[] | {issue: .issueNumber, status: .status, phases: [.phases[] | {phase: .phase, status: .status}]}]' "$BEFORE") <(jq -S '[.issues[] | {issue: .issueNumber, status: .status, phases: [.phases[] | {phase: .phase, status: .status}]}]' "$AFTER") && echo identical→identical - AC-7: The baseline moves down with the PR. Evidence:
jq '.functions.over200' scripts/qa/health-baseline.json→0(measured 2026-10-22 on main 039d202: all six over-200 functions are in the workflow layer and thesrc/commands/**ratchet already exists, so nothing may remain)
Prior fixes / producers
- Prior fixes: the three files took 26 of the last 83 fix commits (usage-audit.md). Class, not site: the ACs state the outcome for the directory.
- Producers: refactor(logs): one run-log module — parseLogFile, listLogFiles, resolveLogDir, formatDuration defined once #1471 (
phase-executor.ts), refactor(workflow,locks): worktreeStatus tri-state replaces both isWorktreeDirty copies; one formatSignalLine #1475 (run-orchestrator.ts,worktree-manager.ts) — both merged before launch by the Blocked-by edges.
May touch
src/lib/workflow/run-orchestrator.ts, src/lib/workflow/worktree-manager.ts, src/lib/workflow/phase-executor.ts, src/lib/workflow/ready-gate.ts, src/lib/workflow/drivers/claude-code.ts, new sibling modules under src/lib/workflow/ for extracted stages (same exports re-exported), eslint.config.js (one appended block scoped to src/lib/workflow/**), scripts/qa/health-baseline.json (I-4), CHANGELOG entry. No test file (I-3).
Non-Goals
- Any behaviour change.
src/commands/*(F-08).- The async-I/O redesign (arch: async I/O modernization — unblock true parallel execution #506).
- No edits under
plugin/,.claude/skills/,templates/skills/(I-1).
Done when
The workflow layer has no function over 200 counted lines, the lint rule enforces it, no test changed, and the golden run is identical.
Activity
admarble commentedon Oct 23, 2026
Runner context for the sequant_run session (2026-10-22, owner-approved launch).
max-lines-per-functionblock scoped tosrc/lib/workflow/**, and AC-7 needsfunctions.over200of0inscripts/qa/health-baseline.json.npx vitest run src/lib/workflow/is the suite for AC-5; the one known local failure is the gpgdriver-conformancecodex commit test, which is not this issue's.plugin/,.claude/skills/ortemplates/skills/.Co-Authored-Byline and no session links.admarble commentedon Oct 23, 2026
Complexity: Standard (7 ACs, 2 directories:
src/lib/workflow/(+drivers/), pluseslint.config.jsandscripts/qa/)AC Quality Check
I ran each command-shaped
Evidence:onmain@ 039d202:6(claude-codeexecutePhase230, phase-executorexecutePhase236,executePhaseWithRetry262,runReadyGate253,RunOrchestrator.run649,ensureWorktree393)src/lib/workflow/**string in the config)src/lib/workflow/**match, so a comment with that string placed above the existingsrc/commands/**block (line 132) would match on that block's rule. Append the new block after the commands block, with no glob in a comment above it.green06Line counts have drifted a little since the 2026-10-18 figures in the body (
executePhase233→236,run646→649). The ACs state outcomes, so this does not matter.Scope Assessment
Non-Goals: present (no behaviour change, no
src/commands, no #506, noplugin//.claude/skills//templates/skills/).Verdict:⚠️ SCOPE_WARNING. The scope is coherent, but the work is large: about 2,000 counted lines over 6 functions in 5 files. #1507 took 26 minutes for one function, and the MCP watchdog kills a run after 30 minutes with no phase event. Commit after each function (owner comment).
Blockers: #1471, #1475 and #1507 are all CLOSED ✅.
Acceptance Criteria
0. Assumption: the helpers stay ≤ 200 each, and so doesrun's remaining body.files: ["src/lib/workflow/**/*.ts"]withmax-lines-per-function: [error, {max:200, skipBlankLines:true, skipComments:true}], appended after thesrc/commands/**block, with a short// #1508:comment in the refactor(commands): split initCommand, doctorCommand, syncCommand and updateCommand to ≤ 200 counted lines; max-lines-per-function ratchet for src/commands #1509 style. Tests are already excluded by the global ignores.npm run lintpasses with--max-warnings 0. New helpers must satisfy the type-aware rules (noany, explicit return types where the config demands them).*.test.tsedits. This is why the design below keeps every split in the same file.npx vitest run src/lib/workflow/→ 0 failed, except the known gpgdriver-conformancelocal failure. CItestis the authority.scripts/qa/health-report.ts(or hand-edit as refactor(#1507): split runIssueWithLogging (1,620 lines) into stage functions of ≤ 200 counted lines, behaviour-preserving #1578 did) →over200: 0,over400: 0, andlongestupdated to the new top function.Implementation Plan
Follow ADR-0020 Option A: module-private stage functions in the same file. State passes explicitly as an env/state pair. Early
return/breakbecomes a returned sentinel (RunResult | null,"next" | "break") that the caller checks on the next line.noteSuppressedlabels move with their catches, unchanged, and log wording stays byte-identical.Phase 1: Small ones first (each one commits on its own)
drivers/claude-code.tsClaudeCodeDriver.executePhase(230). Extract private methods: abort/timeout wiring (L71–87), resume-token resolution (L101–120), the SDK stream loop (L166–225), and result/typed-error assembly (L226+).phase-executor.tsexecutePhase(236). Extract the dry-run plan print (L1594–1647) andbuildPhaseEnv(...)for the env block (L1697–1760+).phase-executor.tsexecutePhaseWithRetry(262). Extract the single-attempt path (L2060–2137) and the per-attempt classification inside the cold-start loop (L2152–2287: capped / divergence / window-exhausted / transient / genuine) as a function returning{ kind: "return", result } | { kind: "retry" } | { kind: "break" }. The MCP-fallback tail (L2288+) becomes its own function.ready-gate.tsrunReadyGate(253). ExtractrunPhaseWithProgress(L586 closure → module function), gap-report persistence (L694–723), and the per-iteration verdict guards (L758–836) returning a halt result ornull.Phase 2: The big two
worktree-manager.tsensureWorktree(393). ExtractreuseExistingWorktree(L1118–1304),createWorktreewith fetch, base ref andretryOnConfigLockadd (L1305–1437),rebaseOntoChainBase(L1438–1495), andcopyLocalConfigFiles(L1496+).run-orchestrator.tsRunOrchestrator.run(649). Split along its existing// ──banners into private static methods:setupServices(L785–842),runStateGuard+ chain resume (L843–1010),acquireRunLocks(L1011–1081),chainContentPreflight(L1082–1124),provisionIssues(issue info + worktrees + the three skills pre-flights, L1125–1453; this may need two pieces to fit under 200), andexecuteAndFinalize(L1454+).wallClock/runStartedAtand the shutdown registrations go in an env object so the "every return closes the wall clock" invariant (L760) holds on each early exit.Phase 3: Ratchet + bookkeeping
src/lib/workflow/**block toeslint.config.js. Updatescripts/qa/health-baseline.json. Add a CHANGELOG entry (or achangelog.d/fragment if improve(release): changelog fragments instead of a shared [Unreleased] block — 121/192 main commits touch CHANGELOG.md #1351 lands first). Add an ADR (see the Design Review). Run AC-1/2/3/4/7 and the workflow suite.Design Review
vi.mock. A helper moved to a new module escapes the mocks of modules it imports, which forces test edits (AC-4 forbids that). New exports would also raise knip'sunusedExports(339). Rejected: class conversion forensureWorktree/runReadyGate, which means a larger diff for no gain.finallyandtrysemantics?" Keep eachtry/finallyin the caller when it spans several extracted pieces, and never throw where the original returned. "Isrun's wall-clock and shutdown cleanup still executed on every exit?" Yes, it is passed in the env (step 6).max-lines-per-functionis configured ineslint.config.js(commands block + new block) and inscripts/qa/health-report.ts:114(its own copy, used for the baseline). There are two producers of the threshold. They stay separate by design (the report measures the whole tree), and both use{max:200, skipBlankLines, skipComments}, which I checked.health-baseline.jsonis consumed byhealth-report.ts --check.ADR required: the plan picks between designs (Q2), so the exec PR adds⚠️ #1351's worktree also edits
docs/adr/NNNN-workflow-layer-stage-functions.md, or amends ADR-0020's "Revisit when #1508" consequence, citing it as the shared pattern.docs/adr/README.md. Take the next free number at PR time.Feature Quality Planning
SEQUANT_MUTATIONmarker is needed. A prose line is enough.CHANGELOG/changelog.danddocs/adr/README.mdonly, with no overlap insrc/lib/workflow.Open Questions
run'sprovisionIssues(~330 lines) one helper or two? Recommendation: two (skills pre-flights / worktree provisioning). Impact: AC-1 fails if it stays one.Recommended Workflow
Phases: exec → qa
Quality Loop: enabled
Reasoning: A behaviour-preserving multi-file refactor. No testgen, because no tests may be added (AC-4). The quality loop catches lint and suite regressions within the run. The spec already ran.
Label Review
Current: graph-2026-10-fundamentals
Recommended: +
refactor, +plannedReason: a mechanical, behaviour-preserving split.
admarble commentedon Oct 23, 2026
QA Review for Issue #1508
PR #1585 · HEAD
f851332c9· 0 commits behind mainAC Coverage
0src/lib/workflow/**found. The block is appended after thesrc/commands/**block.eslint --print-config src/lib/workflow/run-orchestrator.tsresolves to[2,{max:200,skipBlankLines,skipComments}].npm run lint→green0npx vitest run src/lib/workflow/in 2 shards: 2,406 passed, 1 failed. The failure isdriver-conformance > codex > commit(local gpg, #1480), and the PR body's "Settled against base" block shows it also fails at base039d2021f.functions.over200= 00.over400is 0 too.health-report.ts --check→ "no metric rose above the baseline"Coverage: 6/7 MET, 1 PENDING (runner-owned)
CI Status
test(required)continue-on-error: true, ci.yml:406). It fails on the repo's existing 207 unused exports, and the diff adds no export.Code Review: behaviour preservation
I traced every stage function against
origin/main:executePhase/executePhaseWithRetry: the dry-run, file-context and env helpers keep the same call order (the shutdown check still comes before the abort controller, and the env is still built after the controller is registered). The originalattempt--; continueafter an auto-wait is now arewaitverdict, and the loop appliesattempt--to it.break(spec only) and loop exhaustion both fall through to the MCP and spec fallbacks with the samelastResult. The log strings are byte-identical.ClaudeCodeDriver.executePhase: the mutable captures moved intoStreamState, which is passed by reference.resultFromStreamis still called inside thetry, so a throw from it is still caught.RunOrchestrator.run,ensureWorktree,runReadyGate: I traced all 10 exit paths ofrunand 6 ofensureWorktree. Each returns the same value after the same side effects (dispose, lock cleanup registration, wall clock). Every reassignedlet(issueNumbers,chainResume,worktreeMap,existingPath/recreateFrom) is written back to shared state, and the try/finally scope is unchanged.Issues: none blocking.
Gates
scripts/qa/health-baseline.json)health-report --checkexit 0[Unreleased]entry under Changed, with (#1508)isGateTestEvidenceplugin/,.claude/skills/,templates/skills/orsrc/commands/Risk Assessment
rewait/breakor an early exit inrun, that the existing suites do not cover. I found none, but the golden run (AC-6) is the end-to-end check.src/lib/workflow. The eslint scan of the whole directory finds 0. The 200-line producer inscripts/qa/health-report.tsuses the same options.return/break/continuein the six original functions against its new sentinel.Adversarial Re-Read
Findings: No gaps found. I traced the exit paths above, confirmed the AC-5 "pre-existing" claim against the settled-against-base block, and found no uncommitted work (the tree is clean and pushed). The Non-Goals hold. The issue body has no motivating-example fixtures; precheck
fixturesreportsnot_applicable.Status: Clean
Follow-up Ledger
Verdict: NEEDS_VERIFICATION
All code-verifiable ACs are MET and the review found no behaviour change. Two items are still open: the required
testcheck was IN_PROGRESS when this review ran, and the AC-6 golden run belongs to the runner. Re-run/qa 1508oncetestis green and AC-6 reportsidentical.Next Steps
testcheck on refactor(#1508): split run, ensureWorktree, executePhaseWithRetry and executePhase to ≤ 200 counted lines; max-lines-per-function ratchet for src/lib/workflow #1585.admarble commentedon Oct 23, 2026
QA Verdict: NEEDS_VERIFICATION
AC coverage: 6/7 met
Pending ACs:
refactor(#1508): point the three noteSuppressed labels in phase-execu…
docs(#1501): HANDOFF.md for graph-2026-10-fundamentals — code nodes c…