Repository navigation
Description
Context
#761 (PR #781) added a bounded-enum failureCategory to MetricRunSchema (rate_limit, billing, timeout, api_error, build_error, hook_failure, context_overflow, unknown), recorded on failed runs in .sequant/metrics.json. Nothing surfaces it yet: sequant stats shows outcome counts and bars from metrics (src/commands/stats.ts:441-443, display ~:608+) and a log-derived "Common Failures" list of raw error strings (:354), but the new privacy-safe why did it fail dimension is invisible.
Surfacing it answers "what's killing my runs — rate limits or real failures?" directly from metrics, without needing run logs to still exist (logs rotate; metrics don't).
Proposal
Add a failure-category breakdown to the metrics-based analytics display, next to the outcome bars — e.g.:
Failure categories (12 failed runs)
rate_limit 5 (42%)
build_error 4 (33%)
timeout 2 (17%)
unclassified 1 (8%)
Acceptance Criteria
- AC-1:
sequant statsrenders a failure-category breakdown computed fromMetricRun.failureCategoryover failed runs, adjacent to the existing outcome section in the metrics-based display. - AC-2: Pre-feat: detect rate-limit failures mid-chain and halt cleanly instead of timeout-cascading #761 records (no
failureCategory) are bucketed explicitly (e.g.unclassified), not dropped and not conflated with theunknownenum value —unknownmeans "classified as unknown", absence means "recorded before classification existed". - AC-3: The section is hidden entirely when there are zero failed runs (no empty header noise).
- AC-4: The breakdown respects the existing cohort filters (
--label,--since, feat(stats): add --label and --since filters for cohort measurement #640) — computed after filtering, not before. - AC-5: If
statshas a machine-readable output mode (JSON/CSV), the breakdown (or per-run category column) is included there too; otherwise N/A. - AC-6: Unit tests: mixed corpus (categorized failures, pre-feat: detect rate-limit failures mid-chain and halt cleanly instead of timeout-cascading #761 uncategorized failures, successes) produces the expected buckets; zero-failure corpus hides the section.
Out of scope
Changing what gets recorded (#761 owns the recording path); the log-derived "Common Failures" section (raw strings stay as-is — different data source, different purpose).
References
- feat: detect rate-limit failures mid-chain and halt cleanly instead of timeout-cascading #761 / PR fix(#761): classify rate limits mid-phase — skip doomed retries, label the chain halt #781 —
failureCategoryrecording, privacy contract (bounded enum only) - feat(stats): add --label and --since filters for cohort measurement #640 — cohort filters the breakdown must compose with
docs/reference/analytics.md— field documentation added in feat: detect rate-limit failures mid-chain and halt cleanly instead of timeout-cascading #761
Activity
admarble commentedon Jul 18, 2026
→ PROCEED — Clean spec;
src/commands/stats.tsmatches the referenced outcome-bars code; no overlap with other in-flight work.Workflow: spec → testgen → exec → qa (
--testgen— AC-6 mandates unit tests: mixed corpus + zero-failure cases)Run:
sequant run 783 -Q --testgenadmarble commentedon Jul 18, 2026
Plan — /spec
Complexity: Standard (6 ACs, 1 directory)
AC Quality Check
All 6 ACs passed lint (0 flagged).
Scope Assessment
Non-Goals: Present ("Out of scope": recording path #761, log-derived Common Failures section).
Verdict:⚠️ SCOPE_WARNING → quality loop auto-enabled.
Acceptance Criteria
failureCategorybucketed asunclassified, distinct from enumunknown— Unit Test: pre-feat: detect rate-limit failures mid-chain and halt cleanly instead of timeout-cascading #761 record +unknown-classified record produce two separate buckets--label/--sinceforce log-mode (feat(stats): add --label and --since filters for cohort measurement #640 bypasses metrics entirely), so the metrics breakdown never renders on a filtered cohort; breakdown is computed insidecalculateMetricsAnalyticsfrom the passed run set, post-filter by construction--json, metrics source) includes the breakdown; CSV is log-sourced only → N/A for CSV — Unit Test: JSON output hasfailureCategories+ per-runfailureCategoryalready present viarunsImplementation Plan
Phase 1: Compute (
src/commands/stats.ts)MetricsAnalyticswithfailureCategories: { category: string; count: number }[](sorted desc by count, ties stable by enum order;unclassifiedbucket for absent field).calculateMetricsAnalyticsover runs withoutcome === "failed"— pure function of the passed runs array (AC-4 by construction).Phase 2: Display
3. In
displayMetricsAnalytics, renderFailure categories (N failed runs)section immediately after the outcome bars; per-categorycount (pct%); skip entirely whenfailedCount === 0(AC-3).4. Add
failureCategoriesto the--jsonmetrics-source output object (AC-5).Phase 3: Tests + docs
5.
src/commands/stats.test.ts: mixed corpus (categorized failed, uncategorized failed,unknown-categorized failed, success, partial), zero-failure corpus, JSON inclusion.6.
docs/reference/analytics.md: document the breakdown +unclassifiedsemantics.Design Review
src/commands/stats.ts— same module that ownscalculateMetricsAnalytics/displayMetricsAnalytics; no new files.Open Questions
failureCategory(run-orchestrator.ts:1557records it whenever ≥1 issue failed, so apartialrun may have one). AC-1/AC-3 say "failed runs" — implementing literally (outcome === "failed" only). If partial-run categories should count, that's a follow-up; noted here so the signal loss is a decision, not an accident.Recommended Workflow
Phases: spec → testgen → exec → qa | Quality Loop: enabled (SCOPE_WARNING) — matches prior /assess recommendation.
Label Review
Current: enhancement, cli — adequate. No browser testing needed (CLI output only); testgen recommended (unit-test ACs).
admarble commentedon Jul 18, 2026
Test Stubs Generated — /testgen
Unit Test Stubs
src/commands/stats-failure-categories.test.ts(worktree) — 6 AC stubs + 2 edge-case stubs (all-unclassified corpus; partial-run-with-category exclusion), following the existingstats.test.tsmock conventions.Edge cases baked in:
failureCategoryare excluded from the failed-run breakdown (AC-1 literal — see Open Question 1 in the plan)Next: /exec implements the feature and fills these stubs.
admarble commentedon Jul 18, 2026
QA Review for Issue #783
AC Coverage
MetricRun.failureCategoryover failed runs, adjacent to outcome sectiondisplayMetricsAnalytics(src/commands/stats.ts); dogfooded against the real 102-run corpus (25 failed → 23 unclassified, 2 billing)unclassified, distinct from enumunknownrun.failureCategory ?? "unclassified"; test asserts both buckets appear simultaneously for anunknown-classified + field-absent pairfailedCount > 0; test asserts no header on success/partial-only corpus--label/--sinceforce log-mode (#640), bypassing metrics entirely — asserted for both flags; the breakdown is a pure function of the runs array passed tocalculateMetricsAnalytics, so it is post-filter by construction--json(metrics source) emitsfailureCategories: [{category, count}]; per-run field already inruns[]. CSV is log-sourced → N/A per the AC's own "otherwise N/A" branchstats-failure-categories.test.tsincl. edge cases (all-unclassified, partial-run-with-category exclusion)Coverage: 6/6 AC items fully met. Derived ACs: none in spec.
Quality Metrics
any)Precheck Findings
Test Coverage Analysis
src/commands/stats.tsstats-failure-categories.test.ts+ existingstats.test.tsdocs/reference/analytics.md,CHANGELOG.mdExecution Evidence
stats(real 102-run corpus)stats --jsonfailureCategoriespresent, counts match corpusstats --label docsEvidence status: Complete
Risk Assessment
failureCategoryare excluded by design (AC text says "over failed runs") — that signal loss is documented in the plan's Open Question 1, not accidental.failureCategory(different schema), so no stale sibling.Adversarial Re-Read
Findings: No gaps found because: the issue's motivating example block (the one precheck fixture) was compared against real output — semantics match exactly (bucket names incl.
unclassified, counts, percentages, failed-run header count); only the header casing differs ("Failure Categories" viaui.sectionHeadervs the example's "Failure categories"), which follows the file's existing section-header convention and the example is prefixed "e.g.". Evidence claims are post-fix validations on the real corpus, not bug repros. Process state inspected: worktree clean, 2 commits, no stash. Non-Goals checked: recording path and Common Failures section untouched. One improvement (bucket typedstring) was found and fixed in-review (8372ef4— nowFailureCategory | "unclassified").Status: Clean
CHANGELOG Verification
[Unreleased] → Addedentry present with issue reference (#783). Docs updated (docs/reference/analytics.md: example output + semantics ofunclassified).Verdict: READY_FOR_MERGE
All 6 ACs met literally; quality gates (execution evidence, changelog, docs, adversarial re-read) all pass; no improvement suggestions remain open.
admarble commentedon Jul 18, 2026
/fullsolve Complete
Issue: #783
Status: READY_FOR_MERGE
PR: #786
Summary
unclassified 23 (92%),billing 2 (8%); hidden under cohort filters; present in--jsonProgress
8372ef4)CI dispatched (5 checks), PR is MERGEABLE. Ready for human review and merge.
feat(#783): count partial runs in the failure-category breakdown
admarble commentedon Jul 19, 2026
Update — breakdown now counts partial runs
Following review, the failure-category breakdown was widened from failed-only to any run that recorded a failure (outcome
failedORpartial).Why: a
partialrun always had ≥1 issue fail and carries afailureCategory, so it is equally the answer to "what's killing my runs?" Success runs never carry the field and stay excluded.Deliberate deviation from AC-1's literal "over failed runs" wording — flagged here for the record. Concretely:
(N runs with a failure)(was(N failed runs)).unclassifiedwhen uncategorized).Dogfooded on the real corpus (102 runs): now
42 runs with a failure(25 failed + 17 partial) →unclassified 40 (95%),billing 2 (5%). All 17 partials were uncategorized (pre-#761), so they land inunclassified.Verification: 32 tests pass (added
counts categories carried by partial runs,DOES show when only non-success run is a partial,excludes success runs in mixed corpus); build + lint green; mergedorigin/main(resolved a CHANGELOG conflict with #784); all 5 CI checks pass; PR #786 is MERGEABLE / CLEAN.feat(#783): surface failureCategory breakdown from metrics.json in se…
feat(#783): surface failureCategory breakdown in sequant stats
refactor(#783): type failure-category buckets with the FailureCategor…
feat(#783): count partial runs in the failure-category breakdown