← Back to Pull requests

fix(tools): fail the vault fill closed when the page resets a written field #136599

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Oct 11, 2026 12:18 UTC
Author

What does this PR do?

Fixes the silent failure mode of #136592: browser_vault_fill (and browser_vault_enter_code) reported success: true while a controlled page had reset one of the written fields to empty.

Root cause: the in-page fill script counted a field at write time (if (el.value.length > 0) filled += 1). A React Hook Form-style page batches its state update and re-applies the DOM after the current task — i.e. after the script returns — so a field the page was about to reset still read back non-empty inside the script. That is exactly the reported asymmetry: the expiry <select>s keep their value (their option values match the page state) while the card-number input is reset, and the tool still listed cc-number as filled.

The fix makes the fill script's verdict asynchronous (the supervisor's Runtime.evaluate already runs with awaitPromise: true): after writing every field it yields one macrotask (setTimeout 0) so the page's batched re-render runs, then judges each field by what actually survived, keeping DOM references (the <nonce>:<index> stamps are still stripped synchronously after the writes). The script returns {filled, dropped} — counts and field tokens only; values are never echoed back. Both Python call sites fail closed on a non-empty dropped: success: false, error_type: "field_dropped", dropped_fields: [...], plus a remediation hint to use a real input tool for that field.

What did not change: the injection mechanism itself (native value setter + input/change events) — the report's synthetic-paste hypothesis doesn't match the code, and the reporter confirmed the native-setter path lands on this form when driven manually; the reset is a timing artifact, so the fix is read-back verification, not a different write path.

Related Issue

Fixes #136592

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • Changes Made

  • agent/vault_login_classifier.py: _FILL_JS_TEMPLATE returns a Promise; writes are unchanged, then one macrotask is yielded and every written field (selects included) is re-read by DOM reference; reset fields are reported as dropped tokens; build_fill_js docstring documents the read-back contract.

  • tools/browser_vault_tool.py: new _parse_fill_readback / _mark_dropped_fields helpers; browser_vault_fill and browser_vault_enter_code fail closed on dropped fields and name them (dropped_fields, error_type: field_dropped, remediation text). Never the values.

  • tests/tools/test_browser_vault_fill_readback.py (new): JS-shape tests (settle precedes the verdict, return carries tokens/counts only, the synchronous origin assert still precedes every DOM access) and end-to-end fail-closed tests through browser_vault_fill (page reset → success: false + dropped_fields; kept value and legacy no-dropped page results still succeed).
  • How to Test

    1. python -m pytest tests/tools/test_browser_vault_fill_readback.py tests/tools/test_browser_vault.py tests/agent/test_vault_store.py tests/agent/test_vault_backends.py -q — 67 passed.
    2. python scripts/check --base upstream/main — 11 checks ok (code health: 0 blocking; the read-back logic lives in module-level helpers so browser_vault_fill's complexity stays under its main value).
    3. Behavioral proof of the settle semantics (simulated controlled component, Node vm):
    - page whose handler resets the input in its own setTimeout queued before the fill: {"filled":0,"dropped":["cc-number"]} → tool answers success: false;
    - page that keeps the value: {"filled":1,"dropped":[]} → success: true.

    Observed result: a fill the page discards now fails closed and names the field, instead of answering success: true / fields: [... cc-number] while the DOM value is empty.

    Checklist

    Code

  • I've read the Contributing Guide

  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)

  • I searched for existing PRs to make sure this isn't a duplicate

  • My PR contains only changes related to this fix/feature (no unrelated commits)

  • I've run pytest tests/ -q and all tests pass (targeted: all vault suites, 67 passed; repo-wide run is left to CI)

  • python scripts/check passes (the blocking lint and code-health checks CI runs) (11 checks ok against upstream/main)

  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)

  • I've tested on my platform: macOS 15 (arm64)
  • Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A (the fill script's read-back contract is documented in the build_fill_js docstring)

  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A

  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A

  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A (in-page JS + Python helpers, no platform surface)

  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A (the success/dropped_fields contract is carried in the result payload, not the schema)
  • For New Skills

    N/A — not a skill.

    Screenshots / Logs

    Before: {"success": true, "filled_fields": 3, "fields": ["cc-exp-month", "cc-exp-year", "cc-number"]} while document.querySelector('[autocomplete=cc-number]').value is "" (the report's repro, 6/6 attempts).
    After: the same page answers {"success": false, "filled_fields": 2, "dropped_fields": ["cc-number"], "error_type": "field_dropped", "error": "The page discarded the value for cc-number (scripted validation or a controlled-component re-render reset it). Do not assume the fill landed; enter that field with a real input tool instead."}.

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: PRATHAMESH75 Review duration: 77058m
    All Vouch review confidence checks passed
    Residual risk 0.33 = Change Risk (0.59) × (1 − Review Confidence (0.45)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.59 · 650 lines diff across 8 files
    0.59
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    44%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #136599"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 44.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 59% (MEDIUM) · Higher = larger blast radius
    59%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 44.7% · Lower = rushed or shallow review
    44.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 32.6% · Safe to merge
    32.6%