Repository navigation
fix(flow): approve Windows grid windows, and bind native fault receipts to what the detector reads - #2795
Conversation
…halts before its request
…ned frame, and name the differing receipt keys
…approval digest as unverified, never masked or complete
…n frame when the lease refuses, on an exact digest match only
…hich windowless identity check fails
… surface, and keep occlusion as its own native refusal check
…rded identity box; report the windowless RuntimeId shape
…tural path, as its own digest-only kind
…l class has no GetValuePattern
…title bar as digest-only approval evidence
Independent adversarial review: REQUEST CHANGESFrom: Grok The safety logic holds up. One required check, Scope
Tests run at the exact head (Linux,
|
…into fix/approval-form-state-unreadable
…ecked value, not an except-return The verdict-fold check counted eight new except-Exception handlers that return a default. The agent's server.py and native_value.py run as copied stdlib files and cannot import openadapt_flow.verdict, so each now goes through one probe that maps any provider exception to NOT_CHECKED, the same rule as verdict.observe; every caller maps it to the refusal it returned before. The replay fallback uses verdict.observe itself. Behaviour is unchanged.
…al it returned before
Independent adversarial review: APPROVEFrom: Grok The previous REQUEST CHANGES at Scope
Tests run at the exact head (Linux)
Adversarial probes (throwaway, not committed, all passed)Previous probes still hold. New ones for the swallow fix:
The official test Findings
CI at this head (
|
Depends on #2788. This PR is stacked on #2788's branch (
fix/native-value-guard-bracket, which includes #2787, now merged); it retargets tomainwhen #2788 merges.Fixes the remaining failures in the
windows replay (Patient Notes, WindowsBackend)job, which has failed since #2291.1. Governed approval halted with
form_state_unreadabletest_standard_run_with_approval_hold_and_resumestopped at step_006 ("click 'Save Note'") before the approval request was written. The agent's/window/form-fieldsrefused the Patient Notes window withobservation/value/bound_identity_unavailable.A type-only census of the window from run 46355293928 shows why. Seven controls report a UI Automation value but have no window of their own (
NativeWindowHandle0): the grid's three column headers, its three data cells, and the title bar. #2291 requires every value-capable control to prove its value with twoWM_GETTEXTreads on its own window that agree with two UIA reads. A windowless control has no second source, so the proof can never exist and every approval on this app refused. The synthetic approval form passed because it has no grid and no title bar, and the unit-test fake gave every control its own handle.The change (option B, approved by the coordinator)
A control that is windowless, read-only and non-password is read through
observe_uia_only_value(native_value.py):CurrentNativeWindowHandleis null or 0 (has_no_native_window). uiautomation'sNativeWindowHandleproperty also answers 0 when the read fails, so the raw element is read instead, and a failed read is never windowless. A control that reports any handle, including its grid's, still owes a full proof and refuses without one.ValuePattern.IsReadOnlymust beTruebefore and after each read, except for the narrow cell scope below. An editable control refuses (value_not_read_only).value_observation_changed).On hosted Windows the WinForms provider gives the grid's cells and headers an empty RuntimeId (
GetRuntimeId()returns()); the title bar has one. So there are two bindings, chosen by the control's own RuntimeId:uia_only_unverified.ControlsAreSame). The path must reach an ancestor below the window that has a RuntimeId (the grid) and end at the bound window's hwnd and process; otherwise it refuses. Field kinduia_only_structural.Read-only and its one narrow exception: WinForms reports a read-only DataGridView's cells as editable (
ValuePattern.IsReadOnlyisFalseon hosted Windows). A control must say read-only, except a windowless grid or list cell or a header (DataItemControl,ListItemControl,HeaderControl,HeaderItemControl) read by its structural path, whose first ancestor with a RuntimeId is aDataGridControl,ListControlorTableControl, and the window's own title bar. For those, the flag only has to be a real boolean and stay the same at every check; a flip between the two reads refuses. An Edit, Document or ComboBox, or anything with its own window, keeps today's complete-read requirement. Digesting an editable cell's value only adds change detection: it is never complete, and read-back, not the approval digest, verifies what a save wrote.uiautomation's
HeaderControlandTitleBarControlclasses have noGetValuePattern; those are read through the genericGetPattern(10002), which answersNone(refused) when unsupported.The bound scope is re-read before and after each of the two value reads, and every snapshot must be identical, so a scroll, resize or new row between the reads refuses.
The result,
UnverifiedValue, hascompletealwaysFalseandproofalwaysNone. On the wire it is a field of kinduia_only_unverifiedoruia_only_structuralwith no proof and no identity.window_fields_statenever paints it out, so OCR still reads its pixels. The form-state kind names the weakest binding in the read (window_fields_uia_only_structural, thenwindow_fields_uia_only_unverified, thenwindow_fields), so the three never compare equal.Provider errors: the agent's
server.pyandnative_value.pyrun as copied stdlib files, so they can't importopenadapt_flow.verdict. Each has one probe (native_value.probe,server._probe) that turns any provider exception into aNOT_CHECKEDsentinel, the same rule asverdict.observe. Every windowless read maps that sentinel to its refusal: not windowless,None, not in scope, orvalue_observation_unavailable. The replay fallback usesverdict.observeitself.check_verdict_folds.pypasses with the baseline unchanged.Why this does not weaken #2291
The approval digest answers one question: did the window change between the person's approval and the save? Before #2291, these controls reached the digest through OCR, or were masked by an unproven UIA value. #2291 made them refuse. Under this change:
observe_complete_value, which read-back and edit baselines use, still refuses the same control, and the agent'sreadroute returns incomplete for it (tested).Known limits (in code and in
docs/LIMITS.md):Things to try to break:
observe_uia_only_valuewith a handle, skip the password guard, or getallow_editableoutside the cell scope?uia_only_unverifiedoruia_only_structuralfield authorize a mask, satisfyvalid_value_proof/valid_value_observation, or produce a digest equal to a proved read?_form_windowless_identity,_form_windowless_path) stay equal while the control is replaced, or bind a path that never reaches a RuntimeId?2. fault-ambiguity trial 3:
qualification_fault_receipt_binding_invalidThe Windows fault driver signs a settled frame. The replayer then took one more capture and required it to be byte-identical. A caret blinking in the note box between the two captures can make identical staging read as a different frame. The replayer now captures up to 30 times at 0.1 s intervals until its own capture's digest equals the signed one. Any mismatch still refuses, and a frame the driver did not sign is never treated as staged. The refusal now names the differing receipt keys (key names only, no values).
3. fault-stale-identity: the detector never saw the fault
The stale-identity overlay covered the whole screen, including the focused note box. The consequential click's revalidation captures through the native keyboard lease, and the lease's hit test failed under the overlay. The run halted safely before delivery, but with "native keyboard lease observation unavailable", not the stale-identity detector refusal (
actuation_revalidation/actuation_observation_changed). Sofault_detector_contract_errorrejected the case, correctly. Earlier runs never reached this case.The fixture changes; production refusal codes do not. A stale identity means the record on screen changed under the same control, so the overlay is now click-through: a layered window, transparent to hit testing, fully opaque (alpha 255, so a blinking caret under it can't change the frame). The keyboard lease and UI Automation still find the app's control, the pixels change, revalidation's identity gate refuses on the fresh frame, and the replayer records it as
actuation_observation_changedwith the receipt's frame digest. The agent's staging confirmation for this kind now requires the frame to change while the element at the save point stays the same.fault_detector_contract_erroris unchanged.Today's occluding overlay is kept as its own agent-only staging kind,
occlusion(not a campaign fault).test_windows_qualification_campaign.pystages it before the campaign and requires the lease to refuse with "native keyboard lease observation unavailable" and the records to stay unchanged.As a fallback, when the detector's own capture refuses after a staged fault, the replayer takes its own plain screenshot and records the receipt only if its SHA-256 equals the signed one. Otherwise nothing is recorded. The original refusal is always re-raised unchanged.
Tests
tests/test_approval_form_fields.py: the census window (seven windowless values unverified, edits still proved); each windowless kind unverified and unmasked; password, unsupported and missing status refuse; status turning to password between reads refuses; an editable cell refuses; disagreeing reads refuse; a cell reporting its grid's handle still needs a proof; the class never satisfies a proof check or a read-back; an unverified digest never equals a proved one; a cell with an empty RuntimeId binds by path under a grid that has one; no RuntimeId up to the window refuses; bounds changing between reads refuses; structural reads that disagree refuse; a structural password or unknown-status cell refuses; an unreadable RuntimeId never falls back to the path; a RuntimeId lost mid-read refuses; a structural value is never a proof or read-back; the three read kinds never compare equal; an editable grid cell under a grid binds as digest-only; an editable windowless Edit or Document in a grid still refuses; an editable cell outside a grid, list or table refuses; a read-only flag that flips between reads refuses; the window's editable title bar binds; header and title-bar classes read throughGetPattern.tests/test_windows_qualification_faults.py: a stale-identity surface stages only when the pixels change and the control under the point does not; occlusion and the other overlays need both to change.tests/test_qualify_windows.py: a caret blink still binds the signed frame; an unsigned frame is never staged; a mismatched receipt names only the differing keys; a stale surface records the receipt on an exact plain-frame match and nothing otherwise, with the halt unchanged both ways; a plain-capture refusal is never rebound.tests/e2e/test_windows_hosted_governed.py: when the approval halts before its request, the test prints the agent's closed refusal receipt and a type-only census of the window (no names or values).Verification
test_standard_run_with_approval_hold_and_resumepassed (approval, hold and resume).test_native_windows_campaign_reads_back_normal_and_all_faultspassed (all 18 cases, plus the occlusion check). Every job in the run passed. The earlier run 46388088373 on 41431aa also passed.check_verdict_folds.pypasses with the baseline unchanged. The file-size ratchet, legacy freeze andbuild_capabilities --check-prpass.test_schema_surfacefails the same way on the untouched base commit in this environment; this PR doesn't change those schemas.