Skip to content

fix(win_agent): recheck the bound scope around each source read, not each getter - #2788

Merged
abrichr merged 2 commits into
mainfrom
fix/native-value-guard-bracket
Nov 30, 2026
Merged

abrichr merged 2 commits into
mainfrom
fix/native-value-guard-bracket

Conversation

@abrichr

@abrichr abrichr commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

Depends on #2787: this branch is stacked on it. Merge #2787 first; GitHub will then show only this PR's commit.

Problem

A diagnostic Desktop replay run (46351124518) with the fatal-error handler on caught the Windows agent crashing. It exited with 0xC0000005, an access violation inside uiautomation.ControlFromPoint, called from:

native_value.observe_complete_value → guard → identity (server.current_binding) → _focused_target_control → _hits_target

This crash explains the qualification campaign step's missing fault receipt, and most likely the intermittent RemoteDisconnected in the keyboard-lease e2e.

#2291's guard re-read the caller's bound scope before every provider property getter. For editable input that scope check is a strict census plus a hit test, so one value read made about 25 of them, and so dozens of ElementFromPoint calls. That is the slowness #2787 addresses on the census side, and the exposure behind this crash.

Fix

guard(scope=False), before every getter, keeps every check except the caller's scope:

  • the deadline;
  • the UIA HWND, PID and RuntimeId;
  • the native owner;
  • the sensitive status, still last.

guard(scope=True) adds identity(). It runs at the end of each of the four source reads and once more at the end; together with the binding read, that brackets every source read. The result is 6 scope checks per value instead of about 25.

Tests

  • New: exactly 6 scope checks for a complete read. A scope flip at any of checks 2 to 6 is refused with value_identity_changed and gives no value and no proof.
  • test_native_value_completeness.py, test_structural_value_completeness.py, test_win_agent_server.py, test_native_focus_keyboard.py, test_native_value_deployment.py and test_native_editable_value.py: 355 passed before the new tests. test_native_value_completeness.py: 81 passed with them.
  • Windows verification run on this branch, 46354299238:
    • The keyboard-lease and approval-completeness steps passed.
    • The agent stayed up through the qualification campaign. Its log ends normally, with no access violation. The earlier crash had left that step without its fault receipt.
    • The step still fails on two separate issues, both being fixed in a follow-up session: the governed approval run's form_state_unreadable, and one fault-ambiguity trial's qualification_fault_receipt_binding_invalid, which fails closed as FAILED_PLATFORM.

Safety argument for review

Between two getters inside one source read, the bound control's identity (RuntimeId, HWND, PID, native owner) and its sensitive status are still rechecked every time. Only the caller's wider scope check, meaning which control has focus and what is hit at its point, moves to the read boundaries. A change in that scope during a read is caught at the read's end, and the value is discarded.

…each getter

observe_complete_value re-read the caller's bound target scope (for editable
input a strict census plus a hit test) before every provider property getter:
about 25 scope checks, and so dozens of ElementFromPoint calls, per value.
On hosted Windows that made reads time out, and an agent run died with an
access violation inside uiautomation.ControlFromPoint, called from this guard
(diagnostic run 46351124518, exit code 0xC0000005).

The cheap checks still run before every getter: deadline, UIA
HWND/PID/RuntimeId, native owner and, last, the sensitive status. The scope
check now brackets each whole source read (binding read, then the end of each
of the four reads, then a final check): six calls per value. A scope change
between any two source reads is still refused.
@abrichr

abrichr commented Nov 30, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok
Reviewed-Head: 1728c5e

I reviewed this PR's own commit, 1728c5e9, on top of #2787's head 7c975e40, which I reviewed separately. I tried to break the safety argument and couldn't. Every provider getter on the bound control is still preceded by a full recheck of the bound control: deadline, RuntimeId, HWND/PID, native owner, and the sensitive status last. Every source read is now bracketed by two checks of the caller's scope, and a scope change seen at any of those checks refuses the value. Two residuals are below; neither is a fail-open.

What changed (native_value.py:480-555)

  • guard(scope=False) (:480-508) drops only identity() and keeps the rest of the order. require_non_sensitive_value is still last (:508).
  • guard(scope=True) runs at the end of each uia() read (:529) and each native() read (:537), and once more at the end (:555). With binding = identity() (:467), that is six scope checks for the four reads. The reads run in the order native, UIA, native, UIA (:551-554).
  • The native reader's internal guard() calls (reader.read(owner, guard=guard), :536) now skip the scope check. They still recheck the owner, the RuntimeId and the sensitive status before each native call.

Adversarial checks (my own probe, not in the PR)

I instrumented a fake control and native reader to log every provider access, then ran this head and its base (7c975e40) through the same scenarios:

  • Sensitivity stays last. On both, every GetValuePattern, pattern.Value and native read immediately follows a password-status read: 0 violations out of 20 status checks per read.
  • Bracketing. On this head, every source read lies between two scope checks, with exactly one read in each interval ([1, 1, 1, 1, 0]). The base made 20 scope checks for the same read.
  • Flip at every point. For every k from 1 to 20, I flipped IsPassword to True, the RuntimeId, or the native owner starting at the k-th access:
    • Sensitivity: refused at every k on both heads.
    • RuntimeId and owner: refused at every k ≥ 2 on both. At k = 1 the "flip" is just a consistent different identity, and base and head treat it identically.
  • Scope flips. I tested persistent scope flips at checks 2-6, a single transient wrong answer at each check, and identity() returning None from any check. None produced a complete value.
  • Mutation tests. I replaced each guard(scope=True) with guard() in turn: at the end of native (:537), at the end of UIA (:529), the final one (:555), and all of them at once. Each mutant fails the new tests (3, 3, 2 and 7 of 7 fail). The base implementation fails test_bound_scope_is_rechecked_around_each_source_read_not_each_getter (20 ≠ 6). So the new tests pin the bracketing.

Residuals (not blocking)

  1. A scope change that reverts inside one source read is no longer seen. Examples: focus leaves and returns, or something covers the hit point briefly, between two getters of one read. The base would have caught it at the next getter. I don't think this matters for safety:

    • the value bytes come only from the bound control, whose identity, owner and sensitive status are still checked at every getter;
    • the two-source, two-read stability checks (:556-559) still have to agree;
    • the caller (server.py:1131) re-reads the binding again after the observation.

    The docstring at :459-462 could say that identity is now re-read at source-read boundaries, so future callers don't assume it runs per getter.

  2. The last two scope checks are back to back (:529 at the end of the second uia(), then :555). There is no source read between them, so one of them is redundant: 5 checks would give the same bracketing with one fewer census and hit test. Optional. It is harmless as written.

I'd also note that this reduces exposure to the ControlFromPoint access violation rather than removing its cause. That is acceptable, because an agent crash fails closed.

Generality gate

  1. No per-app code: pass. The change is to the generic value reader, and the tests use fakes. python scripts/check_engine_generality.py: "Engine generality OK (7 baseline hits left)".
  2. Fix the class: pass. The cost reduction applies to every caller of observe_complete_value (server.py:1126, editable values, and :2950, form fields), not only to Patient Notes.
  3. Held-out evidence: the hosted dispatch run below, plus the application-independent probe above.

Tests at this head (box, Linux, py3.12, the locked install)

  • pytest -n 8 tests/test_native_value_completeness.py tests/test_structural_value_completeness.py tests/test_win_agent_server.py tests/test_native_focus_keyboard.py tests/test_native_value_deployment.py tests/test_native_editable_value.py tests/test_windows_backend.py tests/e2e/test_windows_approval_completeness.py: 433 passed, 1 skipped. The skip is the opt-in Windows e2e.
  • ruff check, ruff format --check and mypy on native_value.py and the test file: clean.
  • The trace probe and the mutation runs above.

Hosted Windows evidence (dispatch run 46354299238, at this head)

  • Steps 6-13 passed, including the keyboard leases, exact editable values, approval completeness and the governed run. In the approval evidence, the long phase's agent refusal is observation/value/provider_native_value_disagreement.
  • Step 14 (qualification campaign) still fails, but it now gets further. Representative trials 1-3 were VERIFIED and fault-ambiguity trials 1-2 HALTED; then fault-ambiguity trial 3 reported FAILED where HALTED was expected (test_windows_qualification_campaign.py:148). At f5b8f097 (run 46347695633), the same step failed earlier, with case_evidence_unverified: ... requires exactly one fault_receipt evidence artifact, consistent with the agent dying.
  • I couldn't confirm the "no access violation" claim from the failed-step log alone, and the trial 3 failure reason isn't in its captured stdout. That trial fails closed, and the PR says it is tracked separately. Note that the test asserts the outcome before the no-mutation row check, so trial 3's rows weren't compared in that run.

Not run

  • Any Windows step on this box (Linux, no UIA). I didn't reproduce the 0xC0000005 crash or measure the speedup.

CI at this head

When I posted (00:02 EST), 14 checks had passed, 18 were skipped by path filter, and none had failed. The Flow unit, default-at-rest, critical and agent-framework jobs were running or queued. windows replay (run 46354320954) had passed steps 6-13 and was in step 14. Going by the dispatch run, I expect step 14 to fail for the separate reason described above.

Merge order: #2787 first, as the PR body says. I didn't push to this branch, and I won't merge it.

@abrichr
abrichr added this pull request to the merge queue Nov 30, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to invalid changes in the merge commit Nov 30, 2026
@abrichr

abrichr commented Nov 30, 2026

Copy link
Copy Markdown
Member Author

From: Grok
Re: merge from main at 141e3cef702d5d6c6bb6067e658b07fa94e9baa4

I checked the merge from main. My approved head 1728c5e904b53d63cd65f4bfa18e712072944898 is an ancestor of the new head. Against main, the PR diff is the same two files, and both have the same blob ids as at the approved head (native_value.py db5c8e72, test_native_value_completeness.py af955f3a). That means my APPROVE still covers this head, and review-verdict passes.

The required gates (ci, packages-gate, run-ci) are red because of a single error in packages / flow core unit (shard 1/4), which otherwise ran 8765 passed and 338 skipped. The error is in tests/test_extension_copilot_sidepanel.py::test_sidepanel_copilot_end_to_end_native_messaging_and_highlights, at setup: the extension service worker didn't start within 15 s (a Playwright serviceworker timeout). This PR doesn't touch that code path, so it looks like a flake. windows replay (Patient Notes) also fails, but it isn't required and it failed the same way on other branches.

Needed: the PR author or session should rerun the failed jobs in run 46377707682 before re-queueing. If the sidepanel test fails again, it needs its own issue.

@abrichr
abrichr enabled auto-merge November 30, 2026 14:35
@abrichr
abrichr added this pull request to the merge queue Nov 30, 2026
Merged via the queue into main with commit ba8acfc Nov 30, 2026
88 of 94 checks passed
@abrichr
abrichr deleted the fix/native-value-guard-bracket branch November 30, 2026 16:19
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.

1 participant