fix(cua-driver): carry full 32-bit snapshot generation in element tokens - #2608
Conversation
`register_snapshot` masked the minted id with `& 0xffff` and `format_token`
masked it again before rendering a 4-hex-char prefix, so the effective
generation space was 16 bits.
With `LRU_CAP_PER_PID = 8` still-resolvable entries per lane, each mint has
an 8/65536 chance of colliding with a live entry. A session issuing 10k
`get_window_state` calls therefore expects ~1.2 collisions. A collision does
not error: it resolves the token to a different snapshot, which reaches the
caller as a silent misclick — the exact failure this module's header calls
out ("if cua-driver ever changes its internal indexing the silent failure
mode is a misclick").
The prefix widens to 8 hex chars, so a token now reads `s0a1b2c3d:12` —
11-15 characters, still inside the 8-16 character budget the Surface 6 plan
called out, and still greppable in logs without a side table. The registry
continues to key on `(pid, snapshot_id)`, so a same-bits collision across
pids never aliases.
Tokens are documented as opaque and are per-snapshot handles that do not
survive a daemon restart, so widening the prefix does not break a
persisted format.
Verified:
- `cargo test -p cua-driver-core`: 415 passed, 0 failed
- `cargo test -p platform-macos`: 183 passed, 0 failed
- `cua-contract-gen all --check`: generated manifest already up to date
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
@f-trycua — following up on #2210, which had grown to 19 files / +1274 −766. That was too large to review as one change, so I closed it down to a tracking draft and split out the parts that stand on their own. Three PRs, each single-file and independent of the other two:
Three things from #2210 I am deliberately not carrying forward, with reasons in that PR's body: the UUID token format (conflicts with the documented 8–16 char / greppable goals), Two items I originally listed for extraction turned out not to be upstream defects at all — No rush on these; happy to split further or adjust any of them. |
|
Separate ask, unrelated to the change itself: none of the Could you approve workflows for this PR (and #2621 / #2622) when you get a chance? Same request as on #2166. Checks I ran locally in the meantime: Worth noting for the macOS-heavy parts: the repo has |
Correct the module contract and rationale after widening snapshot generations from 16 to 32 bits. The process-global counter is monotonic, so the old collision probability model did not apply. Co-authored-by: Francesco Bonacci <195596869+f-trycua@users.noreply.github.com>
f-trycua
left a comment
There was a problem hiding this comment.
Reviewed after correcting the module contract and monotonic-counter rationale. Full-width tokens remain opaque and round-trip through the existing registry.
Summary
element_tokentruncated a monotonic 32-bit snapshot generation to 16 bits. The truncated id repeats every 65,536 process-global snapshots. In a long-lived daemon, a repeated id can still exist in another runtime and pid lane, allowing a stale token to resolve to the wrong snapshot instead of failing.Change
Example:
Tokens remain opaque, process-local, and snapshot-scoped, so widening the prefix does not change a persisted client contract.
Validation
cargo test -p cua-driver-core element_token --locked: 20 passedThis is split from #2210 so the hardening change can be reviewed independently.