Skip to content

feat(run): a dropped error leaves a trace — noteSuppressed() counts into the run log, batch-executor's 25 silent catches converted #1504

Closed

Description

@admarble

Epic: graph-2026-10-fundamentals Tier: judgment Execution: sequant_run Blocked by: #1502

Problem

119 catch clauses in non-test source have empty bodies; 25 are in src/lib/workflow/batch-executor.ts. Each is deliberate and commented ("State tracking errors shouldn't stop execution", "progress errors must not halt"), and the policy is right: a run should not die because a status write failed. What is missing is the other half of the rule. A dropped error leaves no debug line and no count, so when .sequant/state.json drifts it drifts invisibly, and reconcile.ts repairs symptoms whose cause was never recorded. #1469 was the same shape one layer down: a failed git worktree add was absorbed and the run continued in the main checkout; the fix added a failure side-channel so the caller could learn what happened.

Design: src/lib/workflow/suppressed.ts exports noteSuppressed(scope: "state" | "progress" | "cleanup" | "platform" | "other", err: unknown, context?: string). It never throws, writes one debug line through the existing run-log debug path, and increments a per-run counter. log-writer.ts persists suppressed: { total, byScope: Record<scope, number> } as an optional field in run-log-schema.ts (the schema stays version: 1, as its own comments require for optional additions). Display in sequant logs is F-04, because commands/logs.ts is in #1471's scope.

Acceptance Criteria

  • AC-1: The helper counts by scope and never throws. Evidence: npx vitest run src/lib/workflow/suppressed.test.ts → ≥ 3 passed, 0 failed (new file: two calls in scope state and one in progress yield {total: 3, byScope: {state: 2, progress: 1}}; a sink that throws does not propagate; the counter resets per run)
  • AC-2: The run log carries the count without a schema version bump. Evidence: grep -c 'suppressed' src/lib/workflow/run-log-schema.ts → ≥ 1
  • AC-3: The persisted schema version is unchanged (constraint: holds today, must still hold after AC-2). Evidence: grep -c 'version: z.literal(1)' src/lib/workflow/run-log-schema.ts → 1
  • AC-4: batch-executor has no empty catch left. Evidence: npx tsx scripts/qa/health-report.ts --json | jq '.emptyCatch.byFile["src/lib/workflow/batch-executor.ts"] // 0' → 0
  • AC-5: Fault injection against the real filesystem. Evidence: npx vitest run src/lib/workflow/batch-executor.suppressed.integration.test.ts → ≥ 2 passed, 0 failed (new file; the .integration. name puts it in the 30 s vitest project; a real StateManager on a temp dir whose state.json is chmod 0444 so the write fails on the real fs: the issue result is still produced and the written run log has .suppressed.byScope.state >= 1; a throwing onProgress callback yields .suppressed.byScope.progress >= 1; no fs mock)
  • AC-6: The baseline moves down with the PR. Evidence: npx tsx scripts/qa/health-report.ts --check > /dev/null 2>&1 && jq '.emptyCatch.total' scripts/qa/health-baseline.json → ≤ 94

Prior fixes / producers

May touch

src/lib/workflow/suppressed.ts (new), src/lib/workflow/suppressed.test.ts (new), src/lib/workflow/batch-executor.suppressed.integration.test.ts (new, integration project by filename), src/lib/workflow/batch-executor.ts (the 25 catch bodies only; no other change — F-06 splits the function), src/lib/workflow/log-writer.ts, src/lib/workflow/run-log-schema.ts, scripts/qa/health-baseline.json (I-4), CHANGELOG entry.

Non-Goals

Done when

A run whose state write fails finishes and its run log says how many errors were dropped and where.

Activity

  1. added
    graph-2026-10-fundamentals
    on Oct 18, 2026
  2. admarble commented on Oct 19, 2026

    @admarble
    ContributorAuthor

    Runner context, 2026-10-19, before launch (fundamentals W2, beside #1509 and #1512; judgment tier, all phases on Opus; stop-at-PR). main = 23a60b3.

    Changed since filing:

    Notes:

    For every phase, and the qa phase by name: run the full suite at most once, in the foreground, under timeout, after a WIP commit. Each MCP-dispatched phase has a 30-minute wall. Prefer the targeted npx vitest run <files> for the ACs.
    CHANGELOG: add [Unreleased] lines under the existing ### Added / ### Changed headings, not changelog.d/ fragments, and never add a second heading of the same name.
    Lint: #1503 made no-unused-vars, no-empty-object-type and prefer-const errors, and knip counts unused exports. Don't export what nothing imports.
    Health baseline: regenerate scripts/qa/health-baseline.json (npx tsx scripts/qa/health-report.ts --write-baseline) only to record a metric that went down. If npm run lint:health reports a rise, restructure so it holds. Otherwise leave the baseline alone and name the rise in the PR body. Owner ruling: a proseGate.lines rise caused by tests in files that mention SKILL.md only as a path may be absorbed, and must be said so.
    Freeze: nothing under plugin/, .claude/skills/ or templates/skills/.

  3. admarble commented on Oct 19, 2026

    @admarble
    ContributorAuthor

    Complexity: Standard (6 ACs, 3 directories)

    AC Quality Check

    Every AC is one line and has an Evidence: clause. I ran each command-shaped Evidence against main (23a60b3):

    AC On base Gates?
    AC-1 no test file found → fails ✅
    AC-2 grep -c suppressed → 0 ✅
    AC-3 → 1 constraint by design (passes today, must keep passing)
    AC-4 .emptyCatch.byFile[batch-executor] → 25 ✅
    AC-5 no test file found → fails ✅, but see ⚠️ below
    AC-6 .emptyCatch.total → 118 (the issue says 119; #1473 changed it) ✅. After the PR: 118 − 25 = 93 ≤ 94

    ⚠️ AC-5's mechanism doesn't do what it says. StateManager.saveState (src/lib/workflow/state-manager.ts:243-253) writes a temp file in os.tmpdir() and then renameSyncs it over state.json. On POSIX, renaming over a 0444 file works when the directory is writable, so chmod 0444 state.json does not make the write fail. I checked this on this machine: renaming over a 0444 file succeeded. With the directory at chmod 0555, the lock openSync(…".lock","wx") failed with EACCES. acquireLock rethrows anything that isn't EEXIST (state-manager.ts:113), so every withLock write (updatePhaseStatus, updateIssueStatus, …) throws right away, with no lock-timeout wait. The requirement still holds: the write fails on the real fs, and there is no fs mock. Only the prescribed chmod target is wrong. See Open Question 1.


    Scope Assessment

    Non-Goals: present. Excluded: the other 93 catches (F-04), display in sequant logs/MCP, changes to what each site does after the error, and the plugin/skills freeze (I-1).

    Metric Value Status
    Feature count 1 ✅
    AC items 6 ✅
    Directory spread 3 (src/lib/workflow, scripts/qa, root) ✅

    Verdict: ✅ SCOPE_OK

    Blocker: #1502 is CLOSED, and scripts/qa/health-report.ts exists on main.

    Conflict risk: the in-flight #1473 worktree also edits scripts/qa/health-baseline.json (emptyCatch 118→117) and CHANGELOG.md. Whichever PR merges second regenerates the baseline after merging main (--write-baseline; both changes lower the number). No overlap on batch-executor.ts/log-writer.ts/run-log-schema.ts. #1509 and #1512 haven't diverged from main.


    Acceptance Criteria

    AC-1: Helper counts by scope and never throws

    Verification: Unit Test (src/lib/workflow/suppressed.test.ts, new)
    Scenario: Given a fresh run (reset) → When noteSuppressed("state",…) ×2 + ("progress",…) ×1 → Then the counts are {total:3, byScope:{state:2, progress:1}}. A throwing sink doesn't propagate. A reset zeroes the counts.
    Assumptions: byScope has keys only for scopes that occurred (the AC's expected object has no zero keys). Use toEqual on exactly that shape.

    AC-2: Run log carries the count, no version bump

    Verification: Unit Test + grep
    Scenario: Given RunLogSchema → When suppressed: z.object({ total: z.number().int().nonnegative(), byScope: z.record(…) }).optional() is added → Then old logs without the field still parse.

    AC-3: Version stays z.literal(1)

    Verification: grep (constraint)

    AC-4: No empty catch left in batch-executor

    Verification: health-report.ts --json
    Scenario: Every one of the 25 sites gets one call, noteSuppressed(scope, err, "<context>"), and keeps its existing comment. Control flow doesn't change.

    AC-5: Fault injection on the real fs

    Verification: Integration Test (src/lib/workflow/batch-executor.suppressed.integration.test.ts, new; the .integration. name puts it in the 30 s project)
    Scenario: Given a temp dir with a real StateManager whose state.json dir is chmod 0555, a real LogWriter (temp logPath), and ./phase-executor.js mocked to return success → When runIssueWithLogging runs and then logWriter.finalize() → Then an IssueResult comes back and the written JSON has .suppressed.byScope.state >= 1. Case 2: an onProgress that throws → .suppressed.byScope.progress >= 1.
    Assumptions: Mocking phase execution is allowed. "No fs mock" means only fs. CI is ubuntu, non-root. Restore the mode in afterEach so the temp dir can be removed.

    AC-6: Baseline moves down

    Verification: health-report.ts --check + jq. Regenerate with --write-baseline (allowed, because the metric goes down).


    Implementation Plan

    Phase 1: Helper (src/lib/workflow/suppressed.ts, new)

    1. export type SuppressedScope = "state" | "progress" | "cleanup" | "platform" | "other".
    2. Module-level per-run state: counts, plus an optional sink: ((line: string) => void) | undefined.
    3. noteSuppressed(scope, err, context?) increments the count, then calls sink?.(\suppressed[${scope}]${context ? ${context} : ""}: ${message(err)}`). The whole body is wrapped in try { … } catch { /* never throw */ }`. That catch is non-empty (counting comes first, outside the sink try), or split it so health-report doesn't count a new empty catch.
    4. resetSuppressed(sink?) and suppressedCounts() return a copy. Export only what log-writer.ts and the tests import (knip, chore(lint): end the 2026-01 "temporarily relaxed" rules, add knip as an advisory job with a numeric baseline #1503).

    Phase 2: Persist (log-writer.ts, run-log-schema.ts)

    1. Schema: add the optional suppressed field next to sequantVersion, with a doc comment ("optional, so version stays 1").
    2. LogWriter.initialize() calls resetSuppressed(this.verbose ? (l) => console.error(l) : undefined). finalize() sets finalLog.suppressed = suppressedCounts() before writing. Write it every time, even when total: 0: a 0 shows "counted and none", and an absent field means an older log (OQ 2).

    Phase 3: Convert the 25 sites (batch-executor.ts, catch bodies only)

    1. Scope map, taken from the AST walk:

      • state (11): :876, :1314 (read), :1378, :1482, :1518, :1622, :1904, :2022, :2228, :2242, :2600
      • progress (12): :170 / :182 / :209 (activity/liveness in withActivityHook), :1470, :1538, :1559, :1892, :2070, :2094, :2326, :2427, :2435
      • cleanup (1): :1654 deactivateRelay
      • progress (1): :1788 onPhasePlan (renderer wiring)

      Change catch { to catch (err) { and add one call. Keep the feat(qa): the verdict comment names its reviewer — separate session, driver and model, author's driver and model beside it — and the docs name phases.qa.agent as the independence knob #1521 attribution code. Add no logic to runIssueWithLogging (1050 lines) beyond the one-line calls.

    Phase 4: Tests, baseline, docs

    1. Write suppressed.test.ts (AC-1) and the integration test (AC-5). Add no assertions to batch-executor.test.ts (flake test(workflow): the #533 label-shortcut tests take ~850 ms with every phase mocked — one hit 5785 ms on CI and turned main red at da9c4fd49 #1560). Note that it mocks ./log-writer.js, so nothing there changes.
    2. Run npx tsx scripts/qa/health-report.ts --write-baseline. Merge main first if refactor(lib): one definition each for ensureDir, escapeRegex, formatTimestamp, truncateToWidth, parseIssueNumber #1473 has landed.
    3. CHANGELOG [Unreleased] → existing ### Added heading. Write ADR docs/adr/0018-suppressed-error-counter.md.

    Design Review

    1. Where does this logic belong? In src/lib/workflow/suppressed.ts, a leaf module with no imports from batch-executor. LogWriter owns the per-run lifecycle (it already marks run start and end), so it does the reset and the read.
    2. Simplest correct approach? A module-level counter, reset in LogWriter.initialize(). Rejected: a counter on the LogWriter instance passed into each site. The issue fixes the signature as noteSuppressed(scope, err, context?) with no handle, and logWriter can be null at those sites (logging disabled), which would need logWriter?. at all 25. A module singleton is safe because each process runs one run (MCP spawns sequant run as a subprocess, mcp/tools/run.ts:106). Concurrent issues inside one run correctly share one count. → The exec PR includes an ADR (docs/adr/0018-…, shape per docs/adr/README.md).
    3. Pattern and re-patch count? It's the failure side-channel from fix(run): a failed git worktree add must fail the issue, not run its phases in the main checkout (two CLIs race on .git/config) #1469 (recordWorktreeBaseRef "reports, rather than swallows"). That makes two prior fixes, so this is a class. The plan fixes the class with a reusable helper, and F-04 rolls it out to the remaining 93. git log -S noteSuppressed finds only the tracker: graph-2026-10-fundamentals — ratchets for function size, dropped errors, the gh seam, prose gates, deprecations and knowledge location #1501 graph doc. No divergence.
    4. What would a reviewer challenge?
      • "The issue says 'the existing run-log debug path', and that path doesn't exist." True: src/ has no debug logger. The only nearby channels are verbose console.log and SEQUANT_DEBUG_RENDERER, which belongs to the renderer. The plan uses a verbose-gated stderr sink. The count gets persisted either way (OQ 3).
      • "Does a global counter leak between vitest tests?" initialize() resets it, and AC-1 asserts the reset.
      • "Why console.error?" stdout is what the renderer draws. The MCP runId capture parses stderr only for its own runId line pattern.
    5. Producers and consumers of the run log (whole-repo grep). Producers: createEmptyRunLog/finalizeRunLog (run-log-schema.ts:503,599) feeding the single writer LogWriter.writeLogFile (log-writer.ts:448). There is one writer path, so no parity test is needed. Consumers: commands/logs.ts, mcp/tools/logs.ts, mcp/tools/run.ts, lib/run-logs.ts (owned by refactor(logs): one run-log module — parseLogFile, listLogFiles, resolveLogDir, formatDuration defined once #1471, untouched). The schema isn't .strict(), and the field is optional, so readers are unaffected. log-rotation.ts reads filenames only.

    Feature Quality Planning

    All standard checks pass. Notable items:

    • Mutation record (CLAUDE.md §Testing): AC-5 gates a behaviour claim. The PR body should carry Mutation-verified: AC-5 — removed noteSuppressed call from the :1904 state catch; batch-executor.suppressed.integration.test.ts > … failed; restored. plus the SEQUANT_MUTATION marker, with the file path first.
    • Error message extraction: err instanceof Error ? err.message : String(err), inside the never-throw guard, because String() of a hostile object can throw.
    • New empty catch: the helper's own guard must not add a new empty catch. Put a statement or comment-plus-statement in it, or AC-6's count rises by 1.

    Open Questions

    1. AC-5's chmod target — Recommendation: the owner edits AC-5 to read "whose .sequant/ directory is chmod 0555" instead of "whose state.json is chmod 0444", because the literal mechanism leaves the write succeeding (shown above). Impact if unchanged: exec implements the directory form to meet the stated outcome, and a literal-reading /qa flags the mismatch.
    2. Write suppressed when the total is 0? — Recommendation: yes, always write it. Impact: minimal, because no exact-shape tests on finalized logs exist (grep found none).
    3. Debug-line sink — Recommendation: stderr when verbose, otherwise no line (the count is still kept). Impact: if the owner wants a line in every run, add a bounded lastErrors array to the log. That is scope growth, better left to F-04.

    Recommended Workflow

    Phases: exec → qa
    Quality Loop: disabled
    Reasoning: SCOPE_OK, one feature, and the AC text already names exact test files and shapes. I skip testgen on purpose, even though AC-1 and AC-5 declare test evidence: the issue fixes the file names and assertions, and an extra phase eats into the 30-minute-per-phase budget without adding information. There is no /assess comment to reconcile.


    Label Review

    Current: graph-2026-10-fundamentals
    Recommended: + planned, + enhancement
    Reason: new helper plus a schema field. No UI, so no test phase.
    Quality Loop: won't auto-enable (SCOPE_OK).

  4. added
    planned
    enhancement
    on Oct 19, 2026
  5. admarble commented on Oct 19, 2026

    @admarble
    ContributorAuthor

    QA Verdict: AC_MET_BUT_NOT_A_PLUS

    AC coverage: 6/6 met

    Gaps:

    • A dropped state error in the auto-wait path is still uncounted; health-report counts only empty catch clauses, so AC-4 passes but the Done-when trace is incomplete for auto-wait runs — unresolved: owner to fold into F-04 or file
    • On verbose runs, suppressed[...] stderr lines can push the real failure out of the MCP error tail — dropped: minor, only with verbose on, display work belongs to F-04
    • batch-executor.ts:1262: stateManager.updateAutoWait(...).catch(() => { /* Never let state bookkeeping disturb a live wait. */ }) is the same defect class, a dropped state error, and it is still uncounted. health-report counts only empty catch {} clauses, not .catch(() => {}) callbacks, so AC-4 passes literally. But the issue's "Done when" ("its run log says how many errors were dropped and where") is not fully true for an auto-wait run on a read-only state dir. The issue limits the change to "the 25 catch bodies only", so this is a scope decision for the owner, not an exec defect.

    Suggestions:

    • With --verbose, the suppressed[...] lines go to stderr. When a run fails, the MCP tool returns stderr.slice(-1000) as the error (run.ts:457), so on a verbose run these lines can push the real error out of that tail. Minor, and it only happens with verbose on.
  6. added a commit that references this issue on Oct 19, 2026
  7. admarble commented on Oct 19, 2026

    @admarble
    ContributorAuthor

    Execution Verification (runner, 2026-10-19), PR #1564 @ 25639b5

    The runner re-ran AC-1..AC-6 verbatim:

    • AC-1: 5 passed
    • AC-2: 1
    • AC-3: 1
    • AC-4: 0
    • AC-5: 3 passed
    • AC-6: 92 (≤ 94)
    • Lint green.

    AC-5 mutation repeated: deleting every noteSuppressed("state"…) call fails "a state write that fails on the real fs still yields a result, and the log counts it under state". Restored.

    Runner fix from QA's open finding: updateAutoWait(...).catch(() => {}) at batch-executor.ts:1262 dropped a state error uncounted, the same defect class. It now calls noteSuppressed("state", err, "updateAutoWait"). There is no direct test, because the auto-wait path needs a live wait; the 159 tests in the three affected files pass.

    For the owner — baseline:

    • functions.longest.lines (runIssueWithLogging) rises from 1050 to 1071 in exec's regenerated baseline, plus 1 line from the runner's fix, so 1072 on the tree.
    • Each converted catch gains one code line. In exchange, emptyCatch.total falls from 117 to 92.
    • The baseline has not been regenerated for the +1 yet, and lint:health reads 'rose 1071 → 1072' until you rule.

    New ADR-0018 is 'Proposed'; accepting it is yours (D-4).

  8. added a commit that references this issue on Oct 20, 2026
  9. added 2 commits that reference this issue on Oct 20, 2026
  10. added 2 commits that reference this issue on Oct 28, 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-10-fundamentalsplanned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions