Skip to content

Access control PR 4c part 2: Receive checks on pointer, keyboard and replay delivery - #396

Open
ariel3259 wants to merge 72 commits into
joske:masterfrom
ariel3259:feat/access-control-pr4c-input
Open

ariel3259 wants to merge 72 commits into
joske:masterfrom
ariel3259:feat/access-control-pr4c-input

Conversation

@ariel3259

@ariel3259 ariel3259 commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Access control PR 4c part 2: Receive checks on pointer, keyboard and replay delivery. Spec section "Input delivery under denial" in docs/superpowers/specs/2026-10-30-access-control-layer-design.md (lines 353-527); part 1 (#389) did the notifications. Plans:

  • 2026-12-01-access-control-pr4c-keyboard.md
  • 2026-12-01-access-control-pr4c-pointer.md
  • 2026-12-02-access-control-pr4c-input-tests.md
  • 2026-12-02-access-control-pr4c-replay.md

With no policy installed, nothing a client sees changes. With a policy, every cooked pointer, keyboard and XI1 device event copy asks AccessPolicy::receive at the write that sends it, with the window it is written to as the subject. One delivery attempt asks once per recipient and its writer reuses the answer. A denied copy is a non-delivery: the walk goes on to the next selector, or to the grab window, as it would if that selector were absent. A denied candidate cannot take an implicit grab. Passive grab activation and its sync freeze are unchanged.

  • Keyboard:

    • the focused key walk and XI2 form shadowing;
    • grabbed key delivery;
    • raw key copies;
    • the master raw-key grab leg, which tries the owner's root selection first and then the grab window.
  • Pointer:

    • the natural walks;
    • grabbed and owner-events delivery;
    • the slave press protocol;
    • raw pointer and smooth-scroll copies.
  • XI1 device events: they go through the XI1 router. Its selection walk, owner-events window and grab-window fallback all ask per copy.

  • Replay and thaw. AllowEvents, XIAllowEvents and AllowDeviceEvents replays, and queued events played on thaw, are checked again at each write. Queue bookkeeping, the replay choice and passive grab matching are not checked. On a thaw, the XI1 filter no longer asks for an XI2 copy that the thaw never writes.

  • yserver rules, not Xorg behaviour. The spec marks each of these:

    • The activating write of a passive grab is checked for the grab owner. Xorg has no hook there (dix/events.c:3833-3919). A denial drops only those bytes: the grab still activates, a sync grab still freezes and stores the event, and replay still works.
    • The two-event smooth-scroll stop is one batch.
    • In key repeat, the legacy release and the repeated press are checked separately and keep their order and detectable-repeat eligibility.
  • Removed:

    • the test-only emit_xi2_device_changed_slave_pointer and its tests;
    • xi2_stamp_deviceid_for_source, which the core-vs-XI2 dedup called (pointer_fanout.rs:1860 at the base). Its replacement gives the same result.
  • XI1 router reworked: the route walk is built on xi1_route_windows and xi1_allowed_selectors; compute_xi1_targets_bounded is gone, Xi1SelectionFilter::Client carries the window, and owner-events has its own xi1_owner_events_window. With no policy it routes as before. The last commit then moves the router to pointer_fanout/xi1.rs as it is, because pointer_fanout.rs had passed the 5000-line layout limit.

  • Tests. The input tests are table rows (access_key_input, access_pointer_input, access_replay_input) on one runner. Every row:

    • is driven through production request and input entry points;
    • runs with no policy and with allow-all, comparing bytes, grab and freeze state, replies and errors per step;
    • has denial runs that check hook, subject and description.

    Each row names the mutation that fails it. 107 mutations were replayed against the final tree, and every one is caught by its row. The tables are long because each denied outcome is written out in full rather than derived from the allowed one.

  • Left for later. Core AllowEvents(SyncPointer/SyncKeyboard) does not refreeze on the next event. It is pre-existing, not changed here, and goes in a separate PR.

Testing

  • cargo +nightly fmt -- --check
  • cargo clippy --all-targets -- -D warnings, also with --features tcp-transport and --features xdmcp
  • FreeBSD clippy
  • cargo check -p yserver-core --target x86_64-pc-windows-gnu
  • cargo build --bin yserver on its own
  • cargo test --workspace --features xdmcp, and each tests/*.rs
  • the lavapipe --ignored suite
  • the key, pointer and replay row tables, 20 times under CPU load
  • tools/check-layout.sh
  • just man

Hardware parity with no policy installed, base ef3bc7ac against this branch, on an AMD GPU (HDMI) and an NVIDIA RTX 5060 Ti (DP). Each run was a Cinnamon session with two xterms, driven by xdotool, with an xinput test-xi2 --root observer and an XI1 xinput test observer. The session covered:

  • a click into an unfocused window (the WM's sync button grab and ReplayPointer);
  • typing;
  • a title-bar drag.

On AMD the base ran the same sequence. Focus, typed text and the XI1 and XI2 event counts match it. The NVIDIA run matched the AMD branch run. The same comparison headless (lavapipe, marco) also matches.

🤖 Generated with Claude Code

ariel3259 and others added 30 commits December 1, 2026 14:04
…oard)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Records PR joske#389 (merged as 3e09d8a): XI device notifications, crossings, focus, barriers and root/COW ConfigureNotify, and native XKB Receive checks. Pointer, keyboard and replay delivery follow in the next PR.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Implemented-By: Claude Haiku 5.5
xi2_event_description_with_opcode takes the runtime XI major opcode; xi2_event_description delegates to it with the build-time constant. The XI2 focus emitter uses the opcode-taking form, so both call sites share one constructor.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Implemented-By: Claude Haiku 5.5
emit_xi2_device_changed_slave_pointer has no production caller, and its class block writes little-endian bytes to big-endian clients. Remove it with build_slave_pointer_class_block and the class builders only it used, along with its tests in xi2.rs and the access_xi_notify row.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Implemented-By: Claude Haiku 5.5
Test-only follow-ups from the joske#389 review. The C4 grab chains check the XI2 frames with the same detail and mode triples as core. The re-grab test gives ALLOWED XI2 focus on both windows and checks that no Receive call names it. The R2+R3+R4 resize row gives ALLOWED the overlay and the root substructure selections and checks its copies. dec16 and dec32 sit beside enc16 and enc32 and replace the duplicated readers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Implemented-By: Claude Haiku 5.5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Under a policy, a key selection takes part in the focused walk and in XI2
form shadowing only when the copy it would produce is allowed. A denied
copy does not stop the walk and does not shadow another form. A denied XI2
copy reopens core for that client. A selection that produces no copy (XI2
release suppression, a detectable-repeat core release, or a form the
include flags exclude) still stops the walk, and Receive is not asked for
it.

key_copies_at plans one window's copies and asks Receive once per recipient
and XI2 form class; write_key_copies writes the plan unchecked.
focused_walk_target returns the stopping window with its plan, so the focus
is checked once. The focus, slave and replay callers write the plan their
decision computed. The grab owner's single copy is checked at its own
fanout, which covers the slave grab write.

With no policy, or an allow-all policy, the output bytes are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Implemented-By: Claude Haiku 5.5
The per-selection stop decision is one function, client_key_plan, for one
client at one window. It asks Receive lazily, only for a copy it would
write, and returns that client's copies and whether one of its selections
stops the focus walk. key_copies_at is the "any" of it over the window's
clients, so Task 3 can call the same predicate for one foreign client.

The grab owner's single copy goes through fanout_event_to_clients_with_receive
with subject Window(grab window) and the core or XI2 key description. The
key-specific grab_owner_allows helper is gone.

Tests: frames a denial moves to another window are pinned in full with
literal bytes (child, event coordinates, state), not by identity. Every
such frame must have a literal entry and every entry must be written.
Detectable repeat is set through XkbUseExtension and XkbPerClientFlags, and
the slave grab through XIGrabDevice, not by seeding state. A new row covers
an excluded XI2 master form that still stops the walk.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Implemented-By: Claude Haiku 5.5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The natural owner_events walk asks Receive once per window, for the
grab owner's copy in the grab's protocol. An allowed or suppressed copy
qualifies the owner and the natural write reuses that answer, unchecked.
A denied copy does not qualify it, and the walk continues.

A foreign selector rejects the grabbed walk only when its copy stops
under the per-selection predicate, with both form classes included, and
the event's synthetic repeat. Foreign clients are checked only when the
owner does not qualify, so no phantom check is recorded.

The grab-window copy (owner_events false, the activating press, and the
fallback) stays a fresh checked write, and a denial counts as delivered.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Implemented-By: Claude Haiku 5.5
Every foreign selector is evaluated where the owner does not qualify,
with no short-circuit, so the Receive calls do not depend on the
iteration order of the clients map. k9b pins it.

Adds k13_suppressed_owner_qualifies_on_the_natural_walk: a suppressed
owner copy on an owner_events walk qualifies without a Receive call.

The grab-owner write takes an OwnerWrite enum (Decided / FreshCheck)
instead of a bool, and the checked and unchecked branches share one
helper. The too_many_arguments allow is dropped: the workspace lints
already allow it.

The core detectable-repeat suppression cites dix/events.c:2102-2116.
The XI2 case is a yserver rule and is described as such.

k11 asserts its grab state literally.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Implemented-By: Claude Haiku 5.5
Each root copy of a raw key event (the slave and master root fanouts)
is checked with the root as subject, and a denial drops only that copy.
The master grab leg sends at most one copy to the grab owner: when the
natural owner_events copy holds, it is checked with the root as subject;
when that copy is absent or denied and the grab mask has the raw bit, the
copy is checked with the grab window as subject. The root fanout after it
keeps its filters, including the owner skip for a root grab window, and
is a separate attempt with its own check.

The grab-leg write reuses the decision it was checked under, and a dead
owner is not asked.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Implemented-By: Claude Haiku 5.5
Drop the grab leg's dead-owner guard: process_disconnect releases the
keyboard grab before it removes the client, so the owner is always live
when the grab leg asks. Document on Kind::Raw that the grab-leg and root
copies decode alike and only the Receive trace separates them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Implemented-By: Claude Haiku 5.5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Moves the key harness's request helpers, run/decode/check machinery and
Row shape into access_input_support.rs so later pointer scenarios can
reuse them. access_key_input keeps its 29 rows unchanged.

Batch matching, XI1 and pointer drivers, and per-row denied grab state
are not in this commit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Implemented-By: Claude Haiku 5.5
The shared harness now matches whole batches (every description of a
call must name the same event), names core, XI2, raw and XI1 device
calls by event type, and drives pointer events through
pointer_event_fanout_to_state. Each row can state the grab state of its
denied run (pointer grab added); by default it is the allow-all state.
The no-policy and allow-all runs must now also share their grab state.

Frame decoding covers core and XI2 button and motion events. XI1 device
frames are not decoded yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Implemented-By: Claude Haiku 5.5
Adds access_pointer_input.rs with p1 to p7: denied core and XI2
selectors in the natural walk, the shared check of slave and master
forms, core shadowing and its reopening, a deferred core copy, and a
form that is not written. Rows state the target allow-all Receive calls
and the denied outcome. Eight tests are ignored until the routing change
lands; p7 is a guard and passes today.

Today natural pointer walks ask Receive for no copy, so a denial changes
nothing (the ignored tests fail on their allow-all calls).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Implemented-By: Claude Haiku 5.5
Harness and scenario fixes from the task 1a review, tests only:
- p6 denied row: no master pointer grab, the slave XI2 grab stays, and
  the call order is core admission then the XI2 form.
- p5b and p5 denied rows state the core implicit grab (via_xi2 false).
- Pointer grab facts carry via_xi2; the grab state is a list of facts
  (keyboard, master pointer, slave pointer, XI1, keyboard and pointer
  freezes) compared in full between no-policy and allow-all.
- XI2 moved frames assert child and event_x/event_y as well as the window.
- A Receive call is traced and denied as an ordered list of descriptions,
  each in its own numbering (XI1 offsets are not compared with XI2 types).
- p7 presses physically before the XI2 selection and pins its grab state.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Implemented-By: Claude Haiku 5.5
The moved XI2 literals for the motion rows (p4 denied, p5c) now derive
their event coordinates from the motion target (MOTION_TO) at P's origin,
(25, 25), not from the press position. Press-row literals derive from
POINTER and each window's origin.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Implemented-By: Claude Haiku 5.5
A per-dispatch ReceiveMemo gives each (client, subject, batch) one Receive
result, shared by the routing decision and the write. The core walk, the XI2
route windows and recipients, the core shadow and the deferred core copies
now take a denial as a non-delivery: it does not stop or absorb a walk, shadow
the client's core copy, or become an implicit-grab candidate.

The master route resolves before the core walk; a client's core copy is
shadowed when the client is among the master form's allowed recipients. Forms
the dispatch does not write, or a grab decides, route by selection only.
Fixed grab-window copies and the slave press route are checked at the write.
xi2_stamp_deviceid_for_source has no caller left and is removed with its test.

Four access_crossing_notify tests still pin the old rule that cooked pointer
copies are never checked; they need the controller's ruling.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Implemented-By: Claude Sonnet 5.5
Four access_crossing_notify tests pinned that natural pointer copies were
never asked. Natural copies now ask Receive once each.

- cooked pointer copies: DENIED's copies are not written and each is asked
  once with the child as subject; ALLOWED's ButtonPress frame is unchanged,
  and it gains the core motion DENIED's refused master motion no longer
  absorbs.
- XI2 grab-window ButtonPress: asked once, fresh; a denial writes nothing and
  the grab stays active.
- barrier rows (B1 and the owner denial) pin only the barrier calls; the
  drive's core motion copies are checked but not pinned there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Implemented-By: Claude Sonnet 5.5
- The slave form's route from the live target no longer goes through the
  memo when the slave pass starts from an earlier window: no slave copy is
  written along it, so asking Receive there was a phantom check.
- A written copy that is not a grab attempt (the slave press route) resolves
  through the dispatch memo, so a slave and a master form at one window share
  one call. Only grab-window and grab-owner copies take a fresh check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Implemented-By: Claude Sonnet 5.5
An owner-events grab's natural walk now qualifies the owner through the
first protocol (XI2, XI1, core) whose copy Receive allows, and only an
owner that qualifies in none lets an allowed foreign selector of any
protocol reject the walk. The owner's natural copy reuses the dispatch
memo; each grab-window attempt (core fallback, owner_events false, the XI2
master and slave fallbacks) is one fresh check in the grab's protocol,
made before the grab mask and the via_xi2 guard, and a denial counts as
delivered (dix/events.c:4388-4398). Passive activation, sync freezing and
the stored press are unchanged under a denied activating copy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Implemented-By: Claude Sonnet 5.5
ariel3259 and others added 17 commits December 2, 2026 12:32
Port p1-p28 (incl. p4b, p4c, p5b, p5c, p20b, i1a, i1b) of the pointer Receive
tests to one ROWS table run by the shared input runner. p14, p15 and p28 are
step lists; each intermediate assertion is its own checkpoint row named
`<test>@<step>`. Activation, activate_denied, follow_with_motion, Replay,
replay_p28 and the inline second run of p15 are gone, and with them the old
Row/Expect/Moved/run/check_run/check_row/literal_moved runner, the
CallOrder::Multiset mode nothing uses, and the two dead_code expects.

Rows dropped as duplicates (each is the allow-all run of the row named):
- P4_ALLOWED: p4_slave_and_master_forms_share_one_check
- P4C_ALLOWED: p4c_slave_press_and_master_forms_share_one_check
- P5_ALLOWED: p5_denied_xi2_reopens_that_clients_core
- P23_TWO_FORMS (empty denial): p23_scroll_stop_is_not_rerouted_two_forms_denied
- P26_OWNER_ALLOWED (empty denial): p26_xi1_grab_owner_denied_falls_to_the_grab_window

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Implemented-By: Claude Sonnet 5.5
…utcomes and setups

- The two p14_deferred_master_part_asks_nothing_in_the_route rows state their
  grab, freeze and queue facts, including the queued HostPointerMaster the
  baseline asserted.
- Rows dropped as duplicates, completing the list of 86b42cf: the row
  p26_xi1_grab_owner_allowed_asks_no_foreign_selector (const P26_OWNER_ALLOWED,
  empty denial) is the allow-all run of
  p26_xi1_grab_owner_denied_falls_to_the_grab_window, which states the allow grab.
- Both request steps (thaw_master, replay_slave) use `request`, so the runner
  collects what a step writes to its requester; ClientBytes.sequence is a local.
- Size: p14 prefix scenarios built with `..PREFIX`, named consts for repeated
  outcomes, composed and const-generic setups, xi_grab_device replaces
  xi_grab_master_pointer, canonical_call is expected_call(call, 0), shared
  next_sequence.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Implemented-By: Claude Sonnet 5.5
…eleases

- A request step names the event steps whose events it writes
  (Step::Request(fn, &[Step])); its frames are checked against those events'
  details and its calls take their shorthand from them, so a thaw or replay that
  writes a different event than the previous step can be stated. New row
  p14_denied_xi2_activating_press_from_a_master_origin_still_freezes@replay
  (press, motion, XIAllowEvents(ReplayDevice)) states the replayed press.
- decode handles XI1 DeviceButtonRelease; an XI1 event frame or XI2 touch frame
  with no Kind now panics instead of being skipped (unit test).
- grab_facts includes xi2_keyboard_grabs and xi2_detached_masters; the two key
  rows built on the slave keyboard grab state it.
- Mutation comments name only what probes.md shows the row catches; the header
  claim is narrowed.
- Vestigial surface removed: private items nothing else uses, an assertion that
  an allow outcome states no moved frames, the redundant cfg(test).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Implemented-By: Claude Sonnet 5.5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… XI1 grab-window rows

Request steps state their requester's replies and errors per step, and
the runner allows exactly the admission hooks of the request a step
sent (one Dispatch for an extension opcode, none for a core one); any
other non-Receive hook fails the row. A call takes its step's shorthand
only when the step lists exactly one event.

New rows: p5d (a denied master XI2 copy does not shadow that client's
core copy; closes the P-5c gap carried from plan 2) and p26 (the XI1
implicit grab window is checked before the device mask).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Implemented-By: codex (gpt-6-luna xhigh)
…patch opcodes and server hooks

Review round 1 of plan 3 Task 1: replies and errors are collected from
every client at every step; the shared frame splitter reads a reply's
wire length; a Dispatch hook is matched on the (major, minor) pair the
request carried; the recording policy records Server hooks; the R2-I1
shortening rule is exercised through the p14 master replay row.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Implemented-By: codex (gpt-6-luna max)
Review round 2 of plan 3 Task 1: in a request step that lists several
events, a frame's detail is checked against the event of the frame's
decoded type, so a replayed ButtonPress written with detail 0 no longer
borrows the motion's detail. The swap test checks the unswapped outcome
first and requires the swapped run to fail at the Receive trace.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Implemented-By: codex (gpt-6-luna max)
xi1_selection_filter_for_slave_grab routes the owner-events walk to
choose which XI1 selector a slave XI2 grab lets through. On a thaw
re-entry its memo is fresh, so its XI2 leg asked Receive for XI2
copies the thaw never writes. The XI2 leg now reuses a result the
memo already holds (the live dispatch's slave route made it) and
otherwise counts the selection, without asking. No policy and
allow-all bytes are unchanged.

A grab cannot outlive its owner's disconnect while input arrives
(disconnect releases active grabs before the next HostInput), so the
scroll stop and the filter need no gone-owner guard.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Implemented-By: codex (gpt-6-luna xhigh)
Review round 1 of plan 3 Task 2: a @press checkpoint states the frozen
slave, the stored press and the queued Xi1Routed entry, and a companion
row with no XI2 selection on the route observes the thawed XI1 press,
so a thaw that drops the dequeued entry fails.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Implemented-By: codex (gpt-6-luna max)
New access_replay_input table: ReplayPointer and ReplayKeyboard recheck
the natural target, thawed queued motion and keys are checked at their
own writes (with the owner_events fallback to the grab window), a denied
XI1 activating write still stores and replays, and a denied XI1
grab-window write still trips FreezeNextEvent.

Two equal-key Xi1Routed entries in one thaw pass are not reachable
through the host entry, so the hoisted-memo case has no row. The core
pointer and keyboard FreezeNextEvent pins are left out: they show that
SyncPointer/SyncKeyboard never refreeze on the next event, which
predates this series and is tracked separately.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Implemented-By: codex (gpt-6-luna xhigh)
Review round 1 of plan 3 Task 3: two equal-key Xi1Routed entries are
reachable through two synchronously grabbed pointers released by one
AsyncBoth, so a row now pins one Receive call per thawed entry. r5 gains
the keyboard counterparts of r4: the @press checkpoint, a denied
activation with an allowed replay, and a denied selector that does not
veto another selector at the focus. Storage probes now gate on the
original write's result, and r6 names its mutation site.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Implemented-By: codex (gpt-6-luna max)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Final review of plan 3: r7 also denies the cooked fallback at the root
(no cooked frame, the keyboard grab survives), the runner shortens a
call only for a step with exactly one event, and a probe adds a check
where AllowEvents chooses the stored press.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Implemented-By: codex (gpt-6-luna max)
pointer_fanout.rs grew past check-layout's 5000-line limit with the
Receive checks of this series. The XI1 device-event router (selection
walks, passive and device grabs, freeze state) moves unchanged into its
own submodule; items private to pointer_fanout become pub(super) and are
re-exported, so every caller keeps its path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@joske

joske commented Dec 3, 2026

Copy link
Copy Markdown
Owner

Thanks, this reads well. With no policy installed, the rewritten walks deliver the same bytes in the same order to the same recipients, with the same implicit grab, freeze and replay state, and denial behaves like an absent selector everywhere we traced it. No correctness blockers. A few things before merging:

1. Allocations on the input path with no policy installed. These run on every key press or pointer event, so they should cost nothing when no policy is installed:

  • Keyboard: client_key_plan (key_fanout.rs:744) calls key_xi2_forms for every connected client at every window of the focus walk, which resolves the source device and allocates a Vec each time. Compute the forms once per event and pass them in as a slice.
  • XI1 route: xi1_route_windows (xi1.rs:309) allocates the whole ancestor list, and xi1_allowed_selectors (xi1.rs:352) builds the receive batch at every window, even one with no selectors. Before this PR the walk allocated nothing at windows with no selectors. Return early when no policy is installed or the window has no selectors.
  • Owner-events walk (owner_events.rs:467): three small vectors and event descriptions per ancestor during grabbed motion. Use stack storage for the legs and build descriptions only when a policy needs them.

2. Test size. The four new test files add about 6,450 lines, including an 1,871-line runner. As with #389, please keep the distinct routing, grab and replay cases and trim the repeated expected streams and runner machinery.

3. PR description. Two statements don't match the diff:

  • xi2_stamp_deviceid_for_source was not test-only: the core-vs-XI2 dedup called it (pointer_fanout.rs:1860 at the base). Its replacement is equivalent.
  • The XI1 router did not move unchanged: the route walk was rewritten around xi1_route_windows and xi1_allowed_selectors, compute_xi1_targets_bounded is gone, Xi1SelectionFilter::Client now carries the window, and owner-events gets its own xi1_owner_events_window. All equivalent with no policy as far as we can tell, but the description should say it was reworked.

4. To confirm: with a policy, a client whose XI2 Enter/Leave is denied also loses its core crossing, because the shadow is decided by selection alone. The code comment says this is intended; please point to where the spec says so, or note it there.

ariel3259 and others added 11 commits December 3, 2026 08:38
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With no access policy installed, the pointer walks no longer build the
recipient lists, route legs and event descriptions that only a policy
check needs. Decisions and Receive order with a policy are unchanged.

Allocations per event, no policy (base ef3bc7a -> before -> after):
  two XI2 + core press      23 -> 29 -> 22
  core only press            9 -> 10 ->  9
  slave press, XI1 at root  41 -> 42 -> 41
  slave motion, XI1 at root 35 -> 37 -> 35
  XI1 owner-events press    38 -> 40 -> 38
  master owner-events motion 11 -> 19 -> 9
  slave owner-events motion 35 -> 37 -> 35
  smooth scroll             37 -> 39 -> 37

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Implemented-By: codex (gpt-6-luna xhigh)
The owner-events walk keeps up to three legs as stack slots and visits
each leg's selectors through the existing selection predicates, the
owner first and every foreign selector only when the owner qualifies
nowhere. No route-leg vector, selector lists or descriptions are built
before a check needs them, with or without a policy.

A slave owner-events grab with an XI2 owner hit now allocates 10 times
per event, against 14 at ef3bc7a.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Implemented-By: codex (gpt-6-luna max)
The keyboard path builds its at-most-two XI2 forms once per event, on
the stack, after key routing, and threads them through the natural,
grabbed and replay walks. With an empty policy list the focus walk
finds its stop window with the existing client_key_plan predicate and
materialises recipients only at the delivery window; with a policy
installed each window keeps its client-major pass.

The XI1 selector filter, owner-events walk, fresh grab-window check
and slave-press prepass skip the Receive batch when no policy is
installed (policies_installed(), not memo presence).

Allocation calls per event, no policy (base ef3bc7a -> now):
focused_key_empty_walk 14 -> 8, focused_key_xi2_and_core 19 -> 12;
every other scenario at or below base.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Implemented-By: codex (gpt-6-luna xhigh)
The XI2 key forms are a plain two-slot array at fixed slave and master
positions, and KeyCopies keeps one recipient vector per slot. The
focus walk is one loop; with an empty policy list it skips windows
where no client's client_key_plan stops before planning copies. The
grabbed walk answers owner and foreign selection with the same
predicate, so key_selectors is gone. With a policy installed the
client-major pass, owner-then-foreign order and write order are
unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Implemented-By: codex (gpt-6-luna max)
The runner keeps one per-step byte capture and one hook trace instead
of parallel copies. The physical-pointer fixture, the XI1 class helper
and repeated outcome fragments are shared. Every row and checkpoint is
kept; the four files go from 6,450 to 6,364 lines.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Implemented-By: codex (gpt-6-luna xhigh)
Keep the rows that alone catch a mutation of the input routing, a
small cover of the rest, one row for each spec routing rule not
otherwise pinned, and the k1, p14 replay and p18 fallback rows: 48 of
113. Self-tests that a kept row now exercises are gone. The four files
go from 6,364 to 4,268 lines; every one of the 117 mutation probes is
still caught at a kept assertion.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Implemented-By: codex (gpt-6-luna max)
…ct decision

The review found rows that pruning removed although no kept row pins
their decision: owner-events keyboard continuation (k7, k9), the
exhausted focus walk (k6), the owner's own protocol precedence (p11),
slave/master check sharing (p4, p4c), the fresh XI2 fallback (p13),
write-time and thaw denials (p12, r6, r7), the XI1 press prepass
(p19), and the k13, k14b, k16 and p3 boundaries. They are back, and
the two-form scroll stop row gains an ancestor selector so a resumed
walk shows. Probe catchers point at the row whose assertion the probe
describes. The runner captures and decodes each step once, keeps the
frame-detail negative control, and builds XI1 frames with the
existing encoders.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Implemented-By: codex (gpt-6-luna max)
…held

Restore the focused suppressed-release stops (k5), the pointer
owner-events continuations after a denied owner or foreign core copy
(p8, p10) and the XI1 replay grab-class competition (p28). R1, R6 and
R7 check the frozen boundary before the thaw: queue contents and
order, freeze state and no early copies or checks. R5 selects the
master XI2 form at the focus, so a lost XI2 form in the replay handoff
fails in the suite. Each of these fails under a one-line mutation of
the decision it pins.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Implemented-By: codex (gpt-6-luna max)
@ariel3259

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Pushed 11 commits on top of 279e928: three plan docs, four production commits, then four test-only ones.

1. No-policy allocations on the input path

With no policy installed, every input delivery site now allocates no more than ef3bc7ac did:

  • the forms and legs live on the stack;
  • the window walks are lazy;
  • the selection-only .any() paths come back when policies_installed() is false.

The no-policy test is the installed policy list, never the presence of a memo.

Measured with a counting #[global_allocator] around one production dispatch. The numbers are allocation calls per event with no policy:

Scenario ef3bc7a 279e928 now
focused key, empty walk 14 28 8
focused key, XI2 + core 19 33 12
two XI2 + core pointer 23 29 22
core only 9 10 9
master owner-events motion 11 19 9
slave owner-events XI2 grab motion 14 — 10
slave press, XI1 at root 41 42 41
slave motion, XI1 at root 35 37 35
XI1 grab owner-events press 38 40 38
XI1 grab no-owner-events press 37 — 37
XI1-only owner-events walk 35 37 35
physical smooth scroll 37 39 37

Requested bytes and realloc counts are also at or below base in every scenario. With a policy installed nothing changes: the same Receive calls in the same order, the same recipients, frames, and grab, freeze and queue state. The keyboard keeps its client-major check at every visited window.

key_selectors is gone. The grabbed keyboard walk answers owner and foreign selection with the same client_key_plan predicate as the focus walk.

2. Test size

The four input test files went from 6,450 to 5,194 lines (−1,256), and from 113 rows and checkpoints to 68. I kept a row only if it pins a decision no other row pins; every kept row fails under a one-line mutation of the decision it covers (117 mutation probes, all caught at the row they name). I first pruned harder, to about 4,300 lines, but review showed several of the removed rows were the only test of a distinct decision (owner-events continuation, thaw-time denial, the frozen queue boundary), so they came back.

The runner did not shrink: it is about 2,090 lines. It now captures and decodes each step once and checks the frozen boundary before a thaw. If you want it smaller still, I'd rather do that as a follow-up than drop more comparisons here.

3. PR description

Fixed. The description now says that xi2_stamp_deviceid_for_source was used by the core-vs-XI2 dedup, and that its replacement gives the same result. It also lists what the XI1 router rework changed (xi1_route_windows, xi1_allowed_selectors, the removed compute_xi1_targets_bounded, Xi1SelectionFilter::Client carrying the window, xi1_owner_events_window) instead of calling it unchanged.

4. Denied XI2 crossing vs core crossing

It's in the spec, docs/superpowers/specs/2026-10-30-access-control-layer-design.md l.481–483:

A denial does not reopen a shadow among notifications. Crossings keep their existing XI2-over-core deduplication, and the local check runs after it. A denied XI2 crossing does not expose a core crossing.

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.

2 participants