fix(tools): fail the vault fill closed when the page resets a written field #136599
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
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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
PRATHAMESH75
What does this PR do?
Fixes the silent failure mode of #136592:
browser_vault_fill(andbrowser_vault_enter_code) reportedsuccess: truewhile 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 listedcc-numberas filled.The fix makes the fill script's verdict asynchronous (the supervisor's
Runtime.evaluatealready runs withawaitPromise: 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-emptydropped: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/changeevents) — 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
Changes Made
agent/vault_login_classifier.py:_FILL_JS_TEMPLATEreturns 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 asdroppedtokens;build_fill_jsdocstring documents the read-back contract.tools/browser_vault_tool.py: new_parse_fill_readback/_mark_dropped_fieldshelpers;browser_vault_fillandbrowser_vault_enter_codefail 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 throughbrowser_vault_fill(page reset →success: false+dropped_fields; kept value and legacy no-droppedpage 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 sobrowser_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
setTimeoutqueued before the fill:{"filled":0,"dropped":["cc-number"]}→ tool answerssuccess: 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
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests pass (targeted: all vault suites, 67 passed; repo-wide run is left to CI)python scripts/checkpasses (the blocking lint and code-health checks CI runs) (11 checks ok againstupstream/main)Documentation & Housekeeping
docs/, docstrings) — or N/A (the fill script's read-back contract is documented in thebuild_fill_jsdocstring)cli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/AFor New Skills
N/A — not a skill.
Screenshots / Logs
Before:
{"success": true, "filled_fields": 3, "fields": ["cc-exp-month", "cc-exp-year", "cc-number"]}whiledocument.querySelector('[autocomplete=cc-number]').valueis""(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."}.