Repository navigation
fix(android): stop admitting orientation reads once the settle budget is spent - #4575
Conversation
… is spent The settle loop checked the deadline before its wait, then started another display read with the remaining budget clamped to a 1 ms floor. A rotation that never takes effect therefore died as a misleading adb timeout instead of reporting the last observed rotation. Admission is now rechecked after the wait, so the existing "did not take effect" fact wins and a read that fails inside its own budget stays a probe failure. Closes #4562 Co-authored-by: Apex by Callstack <noreply@callstack.com> Co-authored-by: opencode <noreply@opencode.ai>
Size Report
Startup median (7 runs, lower is better):
|
|
The guard at 3de249c does not fully remove the misleading adb timeout, so this needs one more change before merge. CI is green (18 checks, none failing). The check This change alters the live Android Not blocking, and fine to take or leave: the new tests in input-actions.test.ts:594 pin only the zero-budget and full-budget sides, so a bare Could one named Once the guard is a minimum-budget predicate, the tests pin both sides, and the head-bound pinned-orientation run shows |
|
The admission correction is pushed at 67a44f5. One predicate now reserves 300 ms, rounded above the prior observed 20–280 ms display reads, both before the poll and after the wait. The checked remaining budget is passed unchanged to the read, so this does not raise an adb timeout floor. Genuine in-budget probe failures retain their existing outcome. The new positive-cost regression reproduces a 50 ms probe timeout at 3de249c. The delayed-wait boundary rejects 299 ms and admits 300 ms. In an isolated baseline checkout the same suite had 2 failures / 33 passes; candidate passes all 35. TypeScript and Android helper builds passed. The exact-head affected gate passed all 8 runnable checks (receipt run-yFQYUv, exactCommit=true, checkoutChanged=false); unit: 19,973 passed / 10 skipped. The experiment checkout was removed after verifying the implementation identity. The candidate-head pinned-orientation run is still missing. Fresh T3 inventory shows the previously used Android targets booted with ownership unestablished; its runtime inventory exposes published 0.21.31/0.21.36 rather than this candidate. No device was opened, shared runtime changed or foreign daemon stopped. The PR remains an explicitly blocked draft until candidate device evidence is available; the earlier pinned-runtime observations are only latency-premise evidence. |
This comment has been minimized.
This comment has been minimized.
|
Thanks for the update. The 300 ms read floor and its tests at 67a44f5 look right, but this still needs a device run before merge. The change alters the live Android orientation settle (input-actions.ts#L165). The earlier review asked for a run on the head that shows Please run a build of 67a44f5 (local source daemon, not published 0.21.x) on an Android emulator or device whose foreground app is portrait-locked. Issue CI is green on all 18 checks. The diff touches only the Android input actions and their unit test, so no hosted job drives a pinned-orientation device, and green CI does not cover this behavior. The code and tests need no further change. Before merge, the pinned and unpinned runs on this head must be attached. Not blocking, take or leave: the floor is 20 ms above the highest read seen (280 ms), so a read that runs past its budget on a loaded emulator can still end as |
|
The requested head-bound pinned and unpinned runs are still missing. I rechecked the available device tooling: T3 requires agent-device 0.21.36 and is running 0.21.31; its device launcher exposes no source-entry or worktree state-directory binding. That cannot exercise 67a44f5. The assigned API_35B is also already booted with ownership unestablished, so I left it and the shared runtime untouched. The PR stays a blocked draft. The green checks and mock-clock regressions are not being treated as evidence for either requested device run. |
|
The missing source-head device runs now pass at Source identity: Pinned foreground target: own native fixture
All three have Unpinned control: the same package's Performance reconciliation: the 300 ms constant is admission reserve, not a sleep or timeout floor. Immediate read and 500 ms polls remain unchanged. Added deterministic success traces cover already-rotated, first-poll and second-poll success: 1/2/3 display reads, waits In an isolated checkout of that current main, applying only this production patch passed 108 tests across five suites: input-actions, screenshot, helper fallback, Android interaction freshness and ADB executor. This preserves #4603's screenshot rotation metadata fast path, #4605's proved-fresh settle path, #4609's helper-input animation-wait removal and #4610's cancellation/readiness ownership. The unmerged adaptive/fast-poll prototype #4611 is not assumed to be shipping. No poll-cadence or quiet-window changes were added here. Final validation: Cleanup complete: own session closed, fixture uninstalled, isolated source daemon stopped gracefully, portrait restored, and this run's emulator shut down to its original stopped state. Other devices and sessions were left alone. The experiment checkout was removed after verifying implementation SHA and clean status. Raw JSON, fixture manifest/source/APK and experiment logs are retained locally under |
This comment has been minimized.
This comment has been minimized.
|
Thanks for the update. I reviewed 984b94e and found no problems in the code or the test changes, so the evidence gap from my earlier review is now closed. The change since 67a44f5 is test-only. I traced the settle loop and the test arithmetic by hand and they hold. The pinned and unpinned emulator results in your comment 6957928616 name the head, daemon identity, device, fixture and per-trial output. CI is green: 24 checks, none failing. No hosted device job exercises the Android settle path, so the live runs are the only coverage of it. There are no conflicts and no open review threads. Nothing more is needed from you before merge. It is ready for the maintainer. |
|
A follow-up pass at 984b94e on whether every added line earns its place. The fix stays: #4562 is a real false error, and slower remote emulators hit it more often. The code and tests can be smaller, so I removed the ready-for-human label until they shrink.
The live emulator evidence at this head still covers the behavior if the shape changes this way. Re-running the locked-app case once at the new head is enough. |
… wait The loop checked the deadline in its condition and again after the wait, through a helper. Computing the time left once per iteration makes the shape smaller: break when it is below one read's reserve, and let the wait spend only what is above the reserve. The read keeps its deadline-based signature. The orientation tests shrink from about 270 lines to about 50. The three-case latency test.each passed without the fix, the later in-budget-read test repeated one of its cases, and the real-budget probe failure covered pre-existing behaviour, so they are gone. One regression test keeps the case the fix is about: display reads that cost real time must end the settle with the last rotation, never with a starved read's adb timeout. Co-authored-by: Apex by Callstack <noreply@callstack.com> Co-authored-by: opencode <noreply@opencode.ai>
Apex Sentinel · ✅ Approve · review of
|
| Where | Finding |
|---|---|
packages/platform-android/src/input-actions.ts:170 |
🆕 Reserve is checked before the sleep, so the final read can still be admitted starved |
1 finding below minor hidden (user_settings.min_severity).
Reviewed with this repository's own Sentinel configuration (655ede2796e5).
💬 Talking to Sentinel
In a finding's thread, reply with:
| Command | What it does |
|---|---|
@apex-sentinel-staging note <context> |
Adds context; Sentinel re-checks the cited code |
@apex-sentinel-staging pivot <why> |
Says the finding is wrong; Sentinel re-checks the cited code |
@apex-sentinel-staging like |
Marks the finding as useful |
@apex-sentinel-staging dislike <why> |
Marks it as not useful, so it is not raised again |
On this conversation, comment @apex-sentinel-staging review to run a full review once again.
There was a problem hiding this comment.
Apex Sentinel: 1 new finding on 1404b7c. The verdict and the full list are in the summary comment.
|
Shrunk at One budget check per iteration (input-actions.ts:167-180): const deadline = Date.now() + ORIENTATION_SETTLE_TIMEOUT_MS;
let observed = await readAndroidDisplayRotation(device, orientation, deadline);
while (observed !== undefined && observed !== userRotation) {
// The wait spends only what is above one read's reserve, so every admitted read can answer.
const leftMs = deadline - Date.now();
if (leftMs < MIN_ORIENTATION_READ_BUDGET_MS) break;
await sleep(Math.min(ORIENTATION_SETTLE_POLL_MS, leftMs - MIN_ORIENTATION_READ_BUDGET_MS));
observed = await readAndroidDisplayRotation(device, orientation, deadline);
}The second check and Tests: +49/−1 lines instead of +270. The three-case latency
With main's loop in place, that test fails on the false error, so it is a real regression test: Locked-app case, re-run once at this head. Bound 0.21.36 CLI against an isolated daemon built from this checkout ( No
|
|
This PR is ready at 1404b7c, and it is now the smaller shape from the follow-up pass. The loop now makes one check before the wait, which fixes the over-reserving predicate from the earlier review (#4575 (comment)). Nothing from that review remains open in the code. Not blocking, and you can take or leave these: the PR body still describes the 984b94e shape (a predicate reserving 300 ms before and after the wait, the deleted success-path timing tests, 37 passing tests), so please rewrite Summary and Validation to the current shape (single pre-wait check, one regression test, the evidence comment 6963006385); and the new test in packages/platform-android/src/tests/input-actions.test.ts#L597 asserts exactly 26 reads, which follows from the 500 ms poll and the 50/100 ms costs, so dropping that assertion and keeping the min and last budget assertions would avoid breakage on a future polling change. The one open thread (#4575 (comment), late host sleep) is true but not worth a second check, so it can be resolved as is. If device runs ever show reads above 300 ms, raise the constant. All 19 checks pass at 1404b7c. The diff is the Android settle loop and its unit test, and no hosted job drives a pinned-orientation device, so green checks do not cover the behavior. The test-clock arithmetic holds against both this head and main. The live evidence is one pinned trial at this head, as requested, and the success path (immediate read, 500 ms polls) is unchanged. There are no conflicts. Nothing blocks merge once the PR body is updated. |
Summary
Android orientation settling could admit a final display read with too little time and replace the last observed rotation with a misleading adb timeout. The loop now makes one pre-wait budget check and sleeps only above a 300 ms read reserve. Reads retain their deadline-based signature. The immediate first read and normal 500 ms polling cadence are unchanged.
Two files change. Refs #4562. No shared adb timeout policy or scope expansion. One positive-cost regression replaces the larger intermediate test set.
Validation
1404b7cfacaedc665054e8d42699b36ec1305a9d.pnpm check:affected --run --head 1404b7cfac...passed withexactCommit=true; hosted CI: 18 successful checks / one skipped placeholder.did not take effecterror, requested/observed rotations 1/0. Cleanup complete.The maintainer accepted the remaining late-host-sleep caveat. No paired physical latency benchmark is claimed. Ready-for-human review is recorded at this head.