Skip to content

feat(workers): deterministic closest-matching selector suggestions + DOM snippet in selector failures (Roadmap Phase 3) #65

Closed

Description

@jyotir-aditya

From ROADMAP.md Phase 3:

Richer failure details: DOM snippet around the failed selector, closest-matching selectors (computed deterministically — text/role similarity, no LLM), first console error, failing network request.

Parts of this are now covered by the failure-synthesis track (#63): first console error → #60, failing network request → the stale-session analyzer shipped in failure-hints.ts + #55's prior-anomaly counts. This issue covers the two selector-specific pieces:

Task

When a failure is selector_not_found / selector_not_visible, enrich the failure's details (additive — the JSON contract's type strings and existing fields are frozen):

  1. DOM snippet around the failed selector's expected location — e.g. the nearest matching ancestor/landmark region from the failure-time DOM, truncated. Gives the agent local context without opening the snapshot.
  2. Closest-matching selectors, computed deterministically — candidates from the failure-time DOM ranked by text/role/attribute similarity to the failed selector (e.g. #username when the flow said #user-name). Explicitly no LLM — this is string/tree similarity, and it must work in strict mode with no AI key.

The type-step misclassification fix already puts the failed selector in details; this builds on that. The self-healing resolver (workers/src/ai/self-healing.ts) has related semantic-resolution logic worth reusing or extracting — the deterministic parts only.

Why it matters

ROADMAP.md calls the failure payload the moat: "a failure payload that reliably closes an agent's edit→verify loop is not [copyable]". A wrong-selector failure that names the right selector closes the loop in one iteration.

Acceptance criteria

  • selector_not_found/selector_not_visible failures carry a DOM-context snippet and up to N ranked candidate selectors in details
  • Fully deterministic; works in strict mode with no AI key
  • Additive fields only; existing contract unchanged; fix_hint mentions the top candidate when confidence is high
  • Standalone ts-node test with fixture DOM (near-miss id, role/text match, and no-reasonable-candidate ⇒ silent)

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