Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
This was referenced Jul 29, 2026
…chars
press_key and type_text_chars accepted an element_index, failed to
resolve it from the element cache, discarded the failure and posted the
keystroke anyway — to whatever happened to hold focus, which for a
background agent is often the user's own window.
Both now return the same refusal every other macOS element tool already
returns ("Element index {idx} not found. Call get_window_state first.",
scroll.rs:216-226), and both propagate a failed focus_element instead of
dropping it with `let _ =`.
hqhq1025
force-pushed
the
codex/macos-key-element-guard
branch
from
July 29, 2026 06:28
1d07386 to
dbaa50e
Compare
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
press_keyandtype_text_charsaccept anelement_index, and when it cannot be resolved from the element cache they discard the failure and post the keystroke anyway — to whatever holds focus at that moment. On a driver whose entire purpose is background delivery, that is the user's own window.Every other macOS element tool already refuses in this situation.
scroll.rs:216-226is the precedent:click,set_value,type_text,double_clickandright_clickall do the same. These two were the only ones left.What a caller observes today
The keystroke goes somewhere the caller did not ask for and cannot see, and the result says it worked.
Both tools also dropped the outcome of focusing the element (
let _ = focus_element(...)), so a focus that failed was indistinguishable from one that succeeded — and the key went out regardless.Change
Two files, mirroring
scroll.rsin shape and wording:press_key.rs: whenelement_indexwas supplied but the element guard isNone, return the same errorscrollreturns.type_text_chars.rs: same, converting theif let Some(...)into a match that errors onNone.focus_elementas a tool error instead of discarding it.No new concepts, no new dependencies, and no change for callers who pass a live
element_indexor who address by coordinates.Behaviour change
Anyone relying on the silent fallthrough will now get an error — though relying on it meant relying on keystrokes arriving somewhere unspecified.
Validation
New tests:
press_key::stale_element_index_refuses_instead_of_posting_the_keypress_key::element_index_without_window_id_refusespress_key::ax_px_conflict_still_reports_the_addressing_error_firsttype_text_chars::stale_element_index_refuses_instead_of_typingtype_text_chars::element_index_without_window_id_refusescargo fmt --all -- --checkandgit diff --checkare clean.Context: this is the last piece of #2210 that stands on its own — it is the maintainer's own review point about destructive token consumers, reduced to the part that needs no new machinery. #2608 and #2621 are merged; #2622 is open. I am closing #2210 rather than rebasing it again.