Skip to content

feat(workers): deterministic failure-analyzer pipeline with additive findings[] in failure JSON #58

Closed

Description

@jyotir-aditya

Problem

fix_hint strings are templated per failure type (workers/src/assertions/failure-hints.ts), so they can't reflect what the captured evidence actually shows. We already have exactly one evidence-aware hint — appendStaleStateHint() scans the network log for a 401/403 on an auth-ish endpoint and appends context — but it's hardwired string concatenation. A second detector would be another ad-hoc append* call; a fifth would be unmaintainable.

Proposal

Promote that pattern into a small deterministic failure-analyzer pipeline, mirroring how assertion validators are registered:

  1. EvidenceBundle — one typed input assembled on failure: the failing assertion + failure type, all step results so far, console log, network log, state_restored, DOM snapshot path, failure-time facts (once available — see tracking issue). Everything already exists; this just formalizes it.
  2. Analyzers — pure functions (failure, evidence) => Finding | null, registered in an ordered list, run only on the failure path.
  3. Finding — typed output:
    { code: string,        // stable, governed vocabulary — like the failure taxonomy
      summary: string,     // one sentence naming concrete evidence
      evidence: {...},     // the specific log lines / elements that triggered it
      suggestion?: string }
  4. Contract — new additive findings: Finding[] array on each failure object in the JSON output. The single highest-priority finding is also rendered into the fix_hint prose so humans see it without parsing JSON. No existing fields change (the JSON contract is stable and agent-facing — see CLAUDE.md).
  5. First analyzer = refactor, not new behavior: move appendStaleStateHint() into the pipeline as the stale_session analyzer. Output prose for that case should stay effectively identical — this PR proves the pipeline shape with zero behavior change.

Design rules

  • Deterministic only. No LLM calls anywhere in this pipeline — selectors, timestamps, status codes. ("Deterministic first", see CONTRIBUTING.md.)
  • Precision over recall. An analyzer that isn't sure stays silent; a wrong confident hint is worse than no hint. Findings use hypothesis language ("may be intercepting"), never "the cause is".
  • Capped. At most 2–3 findings per failure, priority-ordered.
  • Testable. Analyzers are pure over recorded data — each gets fixture-based standalone ts-node tests like the rest of workers/test/.
  • code values are governed like the failure taxonomy in workers/src/assertions/types.ts: new codes need a GitHub Discussion first.

Acceptance criteria

  • EvidenceBundle + Finding types; analyzer registry in workers/src/assertions/ (or a sibling module)
  • appendStaleStateHint refactored into the pipeline; its existing behavior preserved
  • Failure JSON gains additive findings[]; top finding reflected in fix_hint
  • Fixture-based tests for the pipeline and the stale-session analyzer
  • Analyzer errors never crash a run (log with context, skip the analyzer)

Follow-up analyzers (separate issues): blocking-overlay detection, prior-console-error correlation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions