Skip to content

feat(workers): report cause-agnostic failure-time page-state facts in failure JSON (#55) - #84

Merged
jyotir-aditya merged 2 commits into
mainfrom
feat/page-state-facts
Jul 11, 2026
Merged

jyotir-aditya merged 2 commits into
mainfrom
feat/page-state-facts

Conversation

@jyotir-aditya

Copy link
Copy Markdown
Contributor

Closes #55.

Problem

When a run fails, the JSON report says what check failed — but nothing about what was actually true on the page at failure time. The motivating field case: a correct click selector blocked by a viewport-covering dialog, reported as a plain selector/timeout failure; the agent had to script-grep the raw HTML snapshot to find the dialog.

What this adds

A new additive page_state field on every failure object, collected from the live page right when the failure happens (computed styles/geometry are not recoverable from the saved static HTML):

  • current URL + title
  • open dialogs/overlays: dialog[open], [role=dialog|alertdialog], [aria-modal=true], plus full-viewport fixed/absolute elements stacked over the page center — each with an accessible name and viewport coverage
  • visible interactive elements (buttons/links/inputs) with accessible names, capped at 20
  • counts of non-excluded console errors and failed requests (>=400 or aborted) from earlier in the run

Strictly facts, no interpretation — interpretation stays in the analyzer pipeline, whose EvidenceBundle now carries page_state (groundwork for the blocking-overlay analyzer, #59).

Design

  • Both failure paths covered. Assertion failures: collected lazily in runAssertions on the first failed assertion, cached for the rest of the list. Step failures (the dialog case — the flow throws before any assertion runs): probed in the engine's crash path while the page is still alive, attached at the ExecutionResult top level, and mapped onto the CLI's fallback failure object.
  • Best-effort and bounded: one page.evaluate, 3s timeout, never throws — facts must never make a failing run fail harder. Passing runs pay zero cost and their output is unchanged.
  • Persisted as an artifact (<id>_page_state.json) next to the console/network logs so verfix show can surface it later.
  • Additive only: no existing JSON field changes. SDK VerifyFailure gains the typed field.

Tests

  • workers/test/artifacts/page-state.test.ts (new, registered as test:page-state): probe/count merging, exclude patterns, never-throw + stall-timeout guarantees, runAssertions attachment on failure and absence on pass.
  • cli/test/local-run.test.ts: new e2e flow — a full-viewport dialog ("Welcome to Cleara") intercepts a correct click selector; the failure JSON must carry page_state naming the dialog, and the facts artifact must exist on disk.
  • Full workers + CLI suites and json-purity.sh pass.

… failure JSON (#55)

On any failure, probe the still-live page once (computed styles and geometry
are not recoverable from the saved static HTML) and attach a new additive
page_state field: URL, title, open dialogs/overlays with accessible names,
visible interactive elements (capped), and counts of non-excluded console
errors / failed requests from earlier in the run. Strictly facts, no
interpretation — that stays in the analyzer pipeline, which now receives
page_state in its EvidenceBundle (groundwork for #59).

Collected on both failure paths: per failed assertion in runAssertions
(lazy, cached across the list), and in the engine's crash path for step
failures — the field-review dialog-blocks-click case — where facts ride at
the ExecutionResult top level since no failed AssertionResult exists. Facts
are also persisted as <id>_page_state.json next to the console/network logs.
Collection is best-effort and bounded (3s probe timeout, never throws);
passing runs pay zero cost and are byte-identical.

CLI maps page_state onto each failure object (including the step-failure
fallback); SDK types gain the field. New e2e case: a viewport-covering
dialog blocking a correct click selector must yield page_state naming the
dialog.
…etric overlay path (#55 review)

Review feedback on #84:

- The visible-elements inventory (up to 20 entries, duplicated verbatim on
  every failed assertion) is token noise in the agent-facing JSON contract,
  and on busy pages the truncation can drop the one element that mattered.
  The CLI now strips visible_elements/visible_elements_truncated from
  failures[].page_state; the full facts still persist in the run result
  (.verfix/runs/<id>.json) and the <id>_page_state.json artifact. SDK type
  updated to the shipped shape.

- Document the center-only elementsFromPoint sampling as a deliberate
  ceiling (ponytail): the geometric path requires >=80% viewport coverage,
  and anything that large necessarily covers the center — lowering the bar
  or multi-point sampling would false-positive on legitimate fixed
  sidebars. ARIA dialogs are caught by the selector query at any position.

- New e2e case: a role-less full-viewport overlay (cookie wall) blocking a
  click must be detected via the geometric probe path — previously only the
  [role=dialog] selector path had end-to-end coverage.
@jyotir-aditya
jyotir-aditya merged commit 4c3d22f into main Jul 11, 2026
2 checks passed
@jyotir-aditya
jyotir-aditya deleted the feat/page-state-facts branch July 11, 2026 05:28
jyotir-aditya added a commit that referenced this pull request Jul 11, 2026
Main already landed #84 (page_state facts) and #86 (blocking_overlay
analyzer). Keep main's code for the overlapping crash-path/findings
wiring; this branch's unique delta remains the failure-diagnosis
playbook in generated agent instructions (#61).
jyotir-aditya added a commit that referenced this pull request Jul 11, 2026
* feat(workers): report cause-agnostic failure-time page-state facts in failure JSON (#55)

On any failure, probe the still-live page once (computed styles and geometry
are not recoverable from the saved static HTML) and attach a new additive
page_state field: URL, title, open dialogs/overlays with accessible names,
visible interactive elements (capped), and counts of non-excluded console
errors / failed requests from earlier in the run. Strictly facts, no
interpretation — that stays in the analyzer pipeline, which now receives
page_state in its EvidenceBundle (groundwork for #59).

Collected on both failure paths: per failed assertion in runAssertions
(lazy, cached across the list), and in the engine's crash path for step
failures — the field-review dialog-blocks-click case — where facts ride at
the ExecutionResult top level since no failed AssertionResult exists. Facts
are also persisted as <id>_page_state.json next to the console/network logs.
Collection is best-effort and bounded (3s probe timeout, never throws);
passing runs pay zero cost and are byte-identical.

CLI maps page_state onto each failure object (including the step-failure
fallback); SDK types gain the field. New e2e case: a viewport-covering
dialog blocking a correct click selector must yield page_state naming the
dialog.

* refactor(cli): keep page_state JSON to high-signal facts; verify geometric overlay path (#55 review)

Review feedback on #84:

- The visible-elements inventory (up to 20 entries, duplicated verbatim on
  every failed assertion) is token noise in the agent-facing JSON contract,
  and on busy pages the truncation can drop the one element that mattered.
  The CLI now strips visible_elements/visible_elements_truncated from
  failures[].page_state; the full facts still persist in the run result
  (.verfix/runs/<id>.json) and the <id>_page_state.json artifact. SDK type
  updated to the shipped shape.

- Document the center-only elementsFromPoint sampling as a deliberate
  ceiling (ponytail): the geometric path requires >=80% viewport coverage,
  and anything that large necessarily covers the center — lowering the bar
  or multi-point sampling would false-positive on legitimate fixed
  sidebars. ARIA dialogs are caught by the selector query at any position.

- New e2e case: a role-less full-viewport overlay (cookie wall) blocking a
  click must be detected via the geometric probe path — previously only the
  [role=dialog] selector path had end-to-end coverage.

* docs(cli): failure-diagnosis playbook in generated instructions (#61)

Teach the escalation ladder for diagnosing a failure of any cause:
fix_hint/findings/page_state in the JSON output first, then --timeline,
then --dom (with page_state.open_dialogs for occluding overlays), then
--console/--network, and only then touch project source.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(workers): report cause-agnostic failure-time facts (page state, prior anomalies) in failure JSON

1 participant