You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Improve error capture for tooling failures (60% of all failures) #447
Analysis from #437 found that 60.6% of all phase failures (43 of 71) are generic "Claude Code process exited with code 1" errors. The actual failure reason (context overflow, API error, hook failure, syntax error) is lost, making diagnosis impossible from logs alone.
Context
From the workflow analysis (March 2026):
82 runs analyzed, 71 total failed phases
Tooling failures: 43 (60.6%)
These failures span all phases: exec (29), spec (12), testgen (3)
Acceptance Criteria
AC-1: Phase runner captures stderr/stdout tail (last 50 lines) before process exits
AC-2: Structured error info stored in PhaseLog (new errorContext field alongside existing error)
AC-3:sequant logs --failed shows error context when available
AC-4: Failure categorization in stats improved with richer error data
Non-Goals
Preventing the failures themselves (separate issues per root cause)
Capturing full conversation logs (too large, privacy concern)
AC-5: Old logs without errorContext render correctly (backward compat)
High
Test Coverage
AC-6: Unit tests for RingBuffer and error classifier
High
Code Quality
AC-7: Error categories defined as constants, not inline strings
Medium
Implementation Plan
Phase 1: Output Capture (AC-1)
Add RingBuffer utility in src/lib/workflow/ring-buffer.ts — circular buffer retaining last N lines
Update AgentPhaseResult in drivers/agent-driver.ts — add stderrTail?: string[], stdoutTail?: string[]
Update ClaudeCodeDriver — replace unbounded capturedStderr += with RingBuffer(50)
Update AiderDriver — same RingBuffer approach
Phase 2: Schema & Storage (AC-2)
5. Define ErrorContextSchema in run-log-schema.ts with stderrTail, stdoutTail, exitCode, category
6. Add error classifier in src/lib/workflow/error-classifier.ts — pattern-match stderr to categories
7. Wire through batch-executor.ts → createPhaseLogFromTiming() as errorContext
Phase 3: Display & Stats (AC-3, AC-4)
8. Update logs.ts — show category + stderr tail (5 lines default, 50 with --verbose)
9. Update stats.ts — group failures by errorContext.category, fall back to truncated string for old logs
RingBuffer(50) in both ClaudeCodeDriver and AiderDriver; lines pushed per-chunk, returned via AgentPhaseResult.stderrTail/stdoutTail
AC-2
Original
Structured errorContext field in PhaseLog
MET
ErrorContextSchema added with stderrTail, stdoutTail, exitCode (optional), category. Wired in batch-executor.ts for both spec and general phases. exitCode not populated at runtime (SDK doesn't expose it), but schema supports it for future use
AC-3
Original
sequant logs --failed shows error context
MET
logs.ts:172-189 displays category + stderr tail (5 lines default, 50 with --verbose). --verbose registered in bin/cli.ts:266
AC-4
Original
Failure categorization in stats
MET
stats.ts:174-178 prefers errorContext.category for failure grouping, falls back to truncated error string for old logs
Derived ACs
AC-5
Derived (Error Handling)
Old logs without errorContext render correctly
MET
errorContext is z.optional(), backward compatible
AC-6
Derived (Test Coverage)
Unit tests for RingBuffer and error classifier
MET
31 tests across 2 files, all passing
AC-7
Derived (Code Quality)
Error categories defined as constants
MET
ERROR_CATEGORIES const array, ErrorCategory type derived via typeof
Coverage: 7/7 AC items fully met Original ACs: 4/4 met Derived ACs: 3/3 met
Quality Plan Verification
Quality Plan found: Yes (from spec comment)
Dimension
Items Planned
Items Addressed
Status
Completeness
4 (AC-1 through AC-4)
4
✅ Complete
Error Handling
1 (backward compat)
1
✅ Complete
Code Quality
2 (constants, patterns)
2
✅ Complete
Test Coverage
7 (all ACs + derived)
7
✅ Complete
Best Practices
2 (optional schema, fallback)
2
✅ Complete
Derived ACs: 3/3 addressed Quality Plan Status: Complete
CI Status
No PR found (PR #457 not accessible). CI status unavailable.
Follows existing codebase patterns — errorContext mirrors the cacheMetrics/fileDiffStats optional PhaseLog field pattern
Excellent test coverage (31 tests) including edge cases, backward compatibility, and concurrent capture isolation
Error classifier uses first-match-wins with ordered priority — sensible for overlapping patterns
Issues:
exitCode is defined in ErrorContextSchema but never populated at runtime. The Claude Code SDK doesn't expose exit codes, and the Aider driver has the code but doesn't pass it through AgentPhaseResult. This is acceptable given the optional schema, but the CHANGELOG mentions "exit code" which could be misleading.
Suggestions:
Consider adding exitCode to AgentPhaseResult interface and populating it from the Aider driver's close event (the Claude SDK genuinely doesn't expose it). Low priority since the category is more useful for diagnostics.
Test Quality Review
Category
Status
Notes
Behavior vs Implementation
✅ OK
Tests assert on output behavior (getLines(), classifyError results), not internals
RingBuffer regex patterns reviewed — no ReDoS risk
Critical Issues: 0 Warnings: 0
Call-Site Review
New exported functions detected: 3
Function
Call Sites
Loop?
Conditions
AC Match
classifyError()
batch-executor.ts:558, batch-executor.ts:797
No
if (!result.success && result.stderrTail)
✅ Only on failures
RingBuffer (class)
claude-code.ts:49-50, aider.ts:37-38
No
Constructor at driver init
✅ Captures for every phase
ErrorContextSchema
run-log-schema.ts:149
No
Schema composition
✅ Optional on PhaseLog
Findings: All call sites correctly gated by failure conditions. No mismatches.
Execution Evidence
N/A — No executable scripts changed. Build passes, tests pass (31/31 for this feature, 2199/2200 total — 1 pre-existing timeout in state-utils.test.ts).
CLI Registration Verification
N/A — No new option interface fields with runtime usage added. The --verbose flag for logs command was already wired.
Test efficacy: High — tests cover the primary purpose (tail capture, classification, display) including edge cases
Likely failure mode: A new error pattern not matching any classifier → falls back to "unknown" (safe default). The exitCode field staying empty could confuse users reading raw JSON logs, but the category is more actionable.
Verdict confidence: High — clean implementation, comprehensive tests, follows established patterns
Verdict: READY_FOR_MERGE
All 7 acceptance criteria (4 original + 3 derived) are met. Implementation follows existing codebase patterns, has comprehensive test coverage (31 tests), and is backward compatible. The one minor gap (exitCode not populated) is acceptable given SDK limitations and the optional schema field.
Documentation
CHANGELOG entry added
N/A — No new user-facing commands (enhancement to existing logs and stats commands)
Next Steps
Run /docs 447 to generate feature documentation before merging
RingBuffer(50) in both ClaudeCodeDriver and AiderDriver; lines split per-chunk and pushed; returned via AgentPhaseResult.stderrTail/stdoutTail
AC-2
Original
Structured errorContext field in PhaseLog
MET
ErrorContextSchema with stderrTail, stdoutTail, exitCode (optional), category. Wired in batch-executor.ts for both spec (line 552) and general phases (line 791)
AC-3
Original
sequant logs --failed shows error context
MET
logs.ts:171-192 displays category + stderr tail (5 lines default, 50 with --verbose). --verbose registered in bin/cli.ts:266
AC-4
Original
Failure categorization in stats
MET
stats.ts:172-179 prefers errorContext.category for grouping, falls back to truncated error string for old logs
Derived ACs
AC-5
Derived (Error Handling)
Old logs without errorContext render correctly
MET
errorContext is z.optional() in schema; display code guards with if (phase.errorContext)
AC-6
Derived (Test Coverage)
Unit tests for RingBuffer and error classifier
MET
31 tests across 2 files, all passing
AC-7
Derived (Code Quality)
Error categories defined as constants
MET
ERROR_CATEGORIES const array, ErrorCategory type derived via typeof
Coverage: 7/7 AC items fully met Original ACs: 4/4 met Derived ACs: 3/3 met
Quality Plan Verification
Quality Plan found: Yes
Dimension
Items Planned
Items Addressed
Status
Completeness
4 (AC-1 through AC-4)
4
✅ Complete
Error Handling
1 (backward compat)
1
✅ Complete
Code Quality
2 (constants, patterns)
2
✅ Complete
Test Coverage
7 (all ACs + derived)
7
✅ Complete
Best Practices
2 (optional schema, fallback)
2
✅ Complete
Derived ACs: 3/3 addressed Quality Plan Status: Complete
Follows existing codebase patterns — errorContext mirrors the cacheMetrics/fileDiffStats optional PhaseLog field pattern
Excellent test coverage (31 tests) including edge cases, backward compatibility, and concurrent capture isolation
Error classifier uses first-match-wins with ordered priority — sensible for overlapping patterns
Data flow correctly wired: drivers → AgentPhaseResult → phase-executor → PhaseResult → batch-executor → createPhaseLogFromTiming → disk
Issues:
None blocking
Suggestions:
exitCode is defined in ErrorContextSchema but never populated at runtime (SDK doesn't expose it, Aider driver has it but doesn't pass through). Low priority — the category is more actionable for diagnostics. CHANGELOG mentions "exit code" which could be slightly misleading.
Test Quality Review
Category
Status
Notes
Behavior vs Implementation
✅ OK
Tests assert on outputs (getLines(), classifyError results), not internals
Verified working: Yes — build passes, 31/31 feature tests pass, data flow traced end-to-end from drivers through phase-executor to batch-executor to schema to display
Test efficacy: High — tests directly exercise RingBuffer behavior, classifier accuracy, schema validation, backward compat, and concurrent isolation
Likely failure mode: A new error pattern not matching any classifier → safe fallback to "unknown". The exitCode field staying empty in logs is cosmetic (optional field, category is more actionable)
Verdict confidence: High — clean implementation, comprehensive tests, follows established patterns, CI green
Verdict: READY_FOR_MERGE
All 7 acceptance criteria (4 original + 3 derived) are met. Implementation follows existing codebase patterns (errorContext mirrors cacheMetrics/fileDiffStats), has comprehensive test coverage (31 tests), is backward compatible, and CI is fully green.
Documentation
CHANGELOG entry added
N/A — No new user-facing commands (enhancement to existing logs and stats commands)
Next Steps
Run /docs 447 to generate feature documentation before merging
Activity
feat(#437): add bulk run log analysis and detailed stats
feat(#437): data-driven workflow analysis and detailed stats (#450)
admarble commentedon Mar 26, 2026
Spec Plan — #447: Improve error capture for tooling failures
AC Quality Check
✅ All 4 acceptance criteria are clear and testable.
Scope Assessment
Verdict: ✅ SCOPE_OK — single focused feature across a well-defined pipeline.
Acceptance Criteria with Verification
AC-1: Phase runner captures stderr/stdout tail (last 50 lines) before process exits
Verification: Unit Test + Integration Test
errorContextfieldAC-2: Structured error info stored in PhaseLog (new
errorContextfield)Verification: Unit Test
createPhaseLogFromTiming()is calledPhaseLogcontainserrorContext: { stderrTail, stdoutTail, exitCode, category }alongside existingerrorerrorContextAC-3:
sequant logs --failedshows error context when availableVerification: Integration Test
errorContextsequant logs --failedrunsAC-4: Failure categorization in stats improved with richer error data
Verification: Unit Test
errorContextcontaining different categoriescalculateStats()processes logscontext_overflow,api_error,hook_failure,build_error,timeout,unknown)Derived ACs
errorContextrender correctly (backward compat)Implementation Plan
Phase 1: Output Capture (AC-1)
RingBufferutility insrc/lib/workflow/ring-buffer.ts— circular buffer retaining last N linesAgentPhaseResultindrivers/agent-driver.ts— addstderrTail?: string[],stdoutTail?: string[]ClaudeCodeDriver— replace unboundedcapturedStderr +=with RingBuffer(50)AiderDriver— same RingBuffer approachPhase 2: Schema & Storage (AC-2)
5. Define
ErrorContextSchemainrun-log-schema.tswithstderrTail,stdoutTail,exitCode,category6. Add error classifier in
src/lib/workflow/error-classifier.ts— pattern-match stderr to categories7. Wire through
batch-executor.ts→createPhaseLogFromTiming()aserrorContextPhase 3: Display & Stats (AC-3, AC-4)
8. Update
logs.ts— show category + stderr tail (5 lines default, 50 with--verbose)9. Update
stats.ts— group failures byerrorContext.category, fall back to truncated string for old logsDesign Review
cacheMetrics/fileDiffStats— optional structured PhaseLog fields populated by executorerror?" → backward compat. "Why not full output?" → explicit non-goalOpen Questions
--verbose? (Recommended: yes)Recommended Workflow
Phases: spec → testgen → exec → qa
Quality Loop: disabled
admarble commentedon Mar 26, 2026
Test Stubs Generated
Unit Test Stubs
File:
__tests__/error-capture.test.tsIntegration Test Stubs
File:
__tests__/integration/error-capture.integration.test.tssequant logs --faileddisplay (AC-3): 2 tests (default vs verbose)Next steps:
throw new Error(...)with actual test logic)/exec 447to implement the featurenpm testGenerated with Claude Code
feat(#447): structured error capture for phase failures
admarble commentedon Mar 26, 2026
Exec Phase — Progress Update
AC Coverage
errorContextfield in PhaseLogsequant logs --failedshows error contextKey Files Changed
src/lib/workflow/ring-buffer.tssrc/lib/workflow/error-classifier.tssrc/lib/workflow/run-log-schema.tsErrorContextSchema+errorContexton PhaseLogsrc/lib/workflow/drivers/claude-code.tssrc/lib/workflow/drivers/aider.tssrc/lib/workflow/batch-executor.tssrc/commands/logs.tssrc/commands/stats.tsbin/cli.ts--verboseflag to logs commandQuality Plan Alignment
Quality Checks
npm run buildnpm run lintnpm testPR
PR #457: #457
Generated with Claude Code
admarble commentedon Mar 26, 2026
QA Review for Issue #447
AC Coverage
RingBuffer(50)in both ClaudeCodeDriver and AiderDriver; lines pushed per-chunk, returned viaAgentPhaseResult.stderrTail/stdoutTailerrorContextfield in PhaseLogErrorContextSchemaadded withstderrTail,stdoutTail,exitCode(optional),category. Wired inbatch-executor.tsfor both spec and general phases.exitCodenot populated at runtime (SDK doesn't expose it), but schema supports it for future usesequant logs --failedshows error contextlogs.ts:172-189displays category + stderr tail (5 lines default, 50 with--verbose).--verboseregistered inbin/cli.ts:266stats.ts:174-178preferserrorContext.categoryfor failure grouping, falls back to truncated error string for old logserrorContextrender correctlyerrorContextisz.optional(), backward compatibleERROR_CATEGORIESconst array,ErrorCategorytype derived viatypeofCoverage: 7/7 AC items fully met
Original ACs: 4/4 met
Derived ACs: 3/3 met
Quality Plan Verification
Quality Plan found: Yes (from spec comment)
Derived ACs: 3/3 addressed
Quality Plan Status: Complete
CI Status
No PR found (PR #457 not accessible). CI status unavailable.
Quality Metrics
any)Test Coverage Analysis
src/lib/workflow/ring-buffer.ts__tests__/error-capture.test.tssrc/lib/workflow/error-classifier.ts__tests__/error-capture.test.tssrc/lib/workflow/run-log-schema.ts__tests__/error-capture.test.tssrc/lib/workflow/log-writer.ts__tests__/error-capture.test.ts(viacreatePhaseLogFromTiming)src/lib/workflow/phase-executor.ts__tests__/integration/error-capture.integration.test.tssrc/lib/workflow/batch-executor.tssrc/lib/workflow/drivers/claude-code.tssrc/lib/workflow/drivers/aider.tssrc/lib/workflow/drivers/agent-driver.tssrc/commands/logs.tssrc/commands/stats.tssrc/lib/workflow/types.tsbin/cli.tsCHANGELOG.mdCoverage: 6/11 changed source files have direct tests
Critical paths without tests: None (all new logic has unit tests)
Code Review
Strengths:
RingBuffer(capture) →error-classifier(categorize) → schema (store) → commands (display)errorContextmirrors thecacheMetrics/fileDiffStatsoptional PhaseLog field patternIssues:
exitCodeis defined inErrorContextSchemabut never populated at runtime. The Claude Code SDK doesn't expose exit codes, and the Aider driver has the code but doesn't pass it throughAgentPhaseResult. This is acceptable given the optional schema, but the CHANGELOG mentions "exit code" which could be misleading.Suggestions:
exitCodetoAgentPhaseResultinterface and populating it from the Aider driver's close event (the Claude SDK genuinely doesn't expose it). Low priority since the category is more useful for diagnostics.Test Quality Review
Anti-Pattern Detection
Dependency Audit
N/A — No dependency changes
Code Patterns
No anti-patterns detected:
awaitin loopsCritical Issues: 0
Warnings: 0
Call-Site Review
New exported functions detected: 3
classifyError()batch-executor.ts:558,batch-executor.ts:797if (!result.success && result.stderrTail)RingBuffer(class)claude-code.ts:49-50,aider.ts:37-38ErrorContextSchemarun-log-schema.ts:149Findings: All call sites correctly gated by failure conditions. No mismatches.
Execution Evidence
N/A — No executable scripts changed. Build passes, tests pass (31/31 for this feature, 2199/2200 total — 1 pre-existing timeout in
state-utils.test.ts).CLI Registration Verification
N/A — No new option interface fields with runtime usage added. The
--verboseflag forlogscommand was already wired.CHANGELOG Verification
Result: CHANGELOG requirements met
Self-Evaluation
exitCodefield staying empty could confuse users reading raw JSON logs, but the category is more actionable.Verdict: READY_FOR_MERGE
All 7 acceptance criteria (4 original + 3 derived) are met. Implementation follows existing codebase patterns, has comprehensive test coverage (31 tests), and is backward compatible. The one minor gap (
exitCodenot populated) is acceptable given SDK limitations and the optional schema field.Documentation
logsandstatscommands)Next Steps
/docs 447to generate feature documentation before merging/merger 447admarble commentedon Mar 26, 2026
admarble commentedon Mar 26, 2026
QA Review for Issue #447
AC Coverage
RingBuffer(50)in bothClaudeCodeDriverandAiderDriver; lines split per-chunk and pushed; returned viaAgentPhaseResult.stderrTail/stdoutTailerrorContextfield in PhaseLogErrorContextSchemawithstderrTail,stdoutTail,exitCode(optional),category. Wired inbatch-executor.tsfor both spec (line 552) and general phases (line 791)sequant logs --failedshows error contextlogs.ts:171-192displays category + stderr tail (5 lines default, 50 with--verbose).--verboseregistered inbin/cli.ts:266stats.ts:172-179preferserrorContext.categoryfor grouping, falls back to truncated error string for old logserrorContextrender correctlyerrorContextisz.optional()in schema; display code guards withif (phase.errorContext)ERROR_CATEGORIESconst array,ErrorCategorytype derived viatypeofCoverage: 7/7 AC items fully met
Original ACs: 4/4 met
Derived ACs: 3/3 met
Quality Plan Verification
Quality Plan found: Yes
Derived ACs: 3/3 addressed
Quality Plan Status: Complete
CI Status
build (20.x)build (22.x)typecheckvalidate-skillsvalidate-pluginCI Summary: 5 passed, 0 pending, 0 failed
Quality Metrics
any)Test Coverage Analysis
src/lib/workflow/ring-buffer.ts__tests__/error-capture.test.tssrc/lib/workflow/error-classifier.ts__tests__/error-capture.test.tssrc/lib/workflow/run-log-schema.ts__tests__/error-capture.test.tssrc/lib/workflow/log-writer.ts__tests__/error-capture.test.tssrc/lib/workflow/phase-executor.ts__tests__/integration/error-capture.integration.test.tssrc/lib/workflow/batch-executor.tssrc/lib/workflow/drivers/claude-code.tssrc/lib/workflow/drivers/aider.tssrc/commands/logs.tssrc/commands/stats.tssrc/lib/workflow/types.tsbin/cli.tsCoverage: 5/10 changed source files have direct tests
Critical paths without tests: None (all new logic has unit tests)
Code Review
Strengths:
RingBuffer(capture) →error-classifier(categorize) → schema (store) → commands (display)errorContextmirrors thecacheMetrics/fileDiffStatsoptional PhaseLog field patternAgentPhaseResult→phase-executor→PhaseResult→batch-executor→createPhaseLogFromTiming→ diskIssues:
Suggestions:
exitCodeis defined inErrorContextSchemabut never populated at runtime (SDK doesn't expose it, Aider driver has it but doesn't pass through). Low priority — the category is more actionable for diagnostics. CHANGELOG mentions "exit code" which could be slightly misleading.Test Quality Review
getLines(),classifyErrorresults), not internalsAnti-Pattern Detection
Dependency Audit
N/A — No dependency changes
Code Patterns
No anti-patterns detected. No
awaitin loops, no empty catch blocks, no hardcoded secrets.Critical Issues: 0
Warnings: 0
Call-Site Review
New exported functions detected: 1
classifyError()batch-executor.ts:558,batch-executor.ts:797if (!result.success && result.stderrTail)All call sites correctly gated. No mismatches.
Execution Evidence
N/A — No executable scripts added or modified. Build passes, tests pass.
CLI Registration Verification
N/A — No new option interface fields with runtime usage.
--verboseforlogscorrectly wired atbin/cli.ts:266.Skill Command Verification
N/A — No skill files changed.
Smoke Test
Not Required — No workflow-affecting changes (skills, scripts, CLI commands unchanged).
CHANGELOG Verification
Result: CHANGELOG requirements met
Self-Evaluation
exitCodefield staying empty in logs is cosmetic (optional field, category is more actionable)Verdict: READY_FOR_MERGE
All 7 acceptance criteria (4 original + 3 derived) are met. Implementation follows existing codebase patterns (
errorContextmirrorscacheMetrics/fileDiffStats), has comprehensive test coverage (31 tests), is backward compatible, and CI is fully green.Documentation
logsandstatscommands)Next Steps
/docs 447to generate feature documentation before merging/merger 447fix(#447): add word boundaries to HTTP status regexes and wire exitCo…
admarble commentedon Mar 26, 2026
Documentation Generated
File:
docs/features/error-capture.mdSections Included:
logs --failed,logs --verbose,stats, JSON outputNext Steps:
Ready to merge!
docs(#447): add error capture feature documentation
chore(#447): resolve CHANGELOG conflict with main
feat(#447): structured error capture for phase failures (#457)
admarble commentedon Mar 26, 2026
→ CLOSE — Resolved via PR #457 (merged 2026-03-26)