Skip to content

perf(ios): skip the readiness preflight for foreground probe reads - #5255

Merged
thymikee merged 7 commits into
mainfrom
t3/skip-foreground-read-preflight
Nov 30, 2026
Merged

thymikee merged 7 commits into
mainfrom
t3/skip-foreground-read-preflight

Conversation

@thymikee

@thymikee thymikee commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

Summary

Skip the uptime preflight for each foreground-probe appState read when the ready runner matches the pinned session ID. The two parallel reads keep their one-second deadlines, connection wait, read-only resend, and queued charge rules. A replacement runner receives neither read. Ordinary reads keep their preflight.

Before / after

Warm Settings snapshot -i --debug on Limrun iOS, 30 timed calls per checkout. The base and earlier skip measurements came from the original comparison. The current head used a fresh simulator lease.

Per snapshot Base 12fe72efec Earlier skip 58b647f4c8 Current head 90f369471f
Foreground appState sends 2 2 2
Foreground uptime preflights 2 0 0
Median wall time 591.0 ms 468.7 ms 463.4 ms
p90 wall time 597.5 ms 503.6 ms 499.3 ms

Validation

At 90f369471ffc479035209ac8a8c8ebb50f5b561d, all 944 tests passed across the two foreground-probe test files and eager-closure-budgets.test.ts. After two warmups, the proof snapshot and all 30 timed snapshots each recorded two skipped preflights with reason foreground_probe_read and two matching sends. The lease was released, the isolated daemon stopped, and Limrun reported zero active instances. CI checks and review pending. Debug trace

@github-actions

github-actions Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Size Report

Metric Base Current Diff
Installed (including dependencies) 6.73 MB 6.73 MB +194 B
Package (unpacked) 6.73 MB 6.73 MB +194 B
Package (download) 2.05 MB 2.05 MB +31 B

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 22.6 ms 25.4 ms +2.8 ms
CLI --help 50.8 ms 55.8 ms +5.0 ms

@blacksmith-sh

This comment has been minimized.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 10 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/apple-runner/src/runner-command-recovery.ts">

<violation number="1" location="packages/apple-runner/src/runner-command-recovery.ts:461">
P3: The new foreground-probe hint branch has no test. Add a case in `index-command-retry.test.ts` that rejects a foreground probe with `runnerReadinessPreflightSkipReason: 'foreground_probe_read'` and asserts the hint prefix. Also confirm the wording should omit the journal-confirmation clause that the hot-command hint includes.</violation>
</file>

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apex Sentinel: 1 new finding on 9dc0cde. The verdict and the full list are in the summary comment.

@apex-sentinel-staging

This comment has been minimized.

@thymikee

Copy link
Copy Markdown
Member Author

At 895368c, a skipped probe read loses more than the uptime preflight: it also loses both retry layers. waitForConnection=false sends it once, and the foreground_probe_read rule marks the error retryable: false, which stops the read-only resend. On a ready session, one reset connection, fetch failed, or forwarded 502/503/504 now returns unknown at once, while the base code can retry within the same one-second signal and return the state. On local and remote Simulator captures, unknown can then move a capture with a lingering host process from the bridge to XCTest. The failed send also leaves an abandoned command charge. Unless a later queued command forgives it, close stops the runner instead of retaining it, and a daemon shutdown does not hand it off. The ADR sentence and the thread reply cover only the connection wait, and the one-second deadline does not need this change, because the signal also limits the retries. The rule to meet: a skipped probe read differs from the base only by not sending uptime. That means keeping only the skip branch in resolveRunnerReadinessPreflightDecision and removing waitForConnection, the foreground_probe_read branch in markSkippedPreflightTransportError, the new RUNNER_ERROR_RULES row, and ADR line 186. Please update the timeout, lost-response and refused tests (the refused read needs a deadline signal), and add a case where one transient failure still returns the state. If a single attempt is intended, the maintainer needs to change that rule explicitly, and the ADR should cover both the connection wait and the resend, with the real reason (an earlier unknown).

Could this be just foregroundProbe plus one condition in resolveRunnerReadinessPreflightDecision (foregroundProbe, appState and a ready session give a skip with reason foreground_probe_read, and everything else falls through)? That keeps the existing connection wait, resend, queued charge, session pinning and dispatched: 'no', with no waitForConnection parameter, new error marker branch, new rule row or comment trim, but the Foreground probe section must first stop requiring a single attempt.

Not blocking: these can be taken or left: remove the deadline reason (and, if a single attempt is accepted, state both dropped retries and the earlier unknown as the reason), add the recent-mutation skip to line 221 and limit line 185 to a starting session or move it to the rationale, restore the shortened RUNNER_ERROR_RULES comment and the removed recent-mutation marker comment in runner-exchange.ts once the new row is gone, document on foregroundProbe that it takes effect only with expectedRunnerSessionId and appState, require session.state === 'ready' in the new branch (production probes pass only ready sessions today) and drop the starting-session test and ADR line 180, and update the PR body after the next push as docs/agents/pull-requests.md requires, since its validation still names 9d2308b with CI pending and its summary omits the single send.

The connection wait thread is resolved but still applies. These threads no longer apply and can be resolved: probe exception is now named in the ADR; a pinned ID now rethrows, with a test; runner-command-types.ts left the diff; counts moved to a linked evidence file; the hint branch is gone; recoverRunnerSend is gone.

Not verified here: tests and device runs were not executed, and the retry comparison comes from reading the code against base 12fe72e. The frequency of such transient failures was not measured. The A/B numbers, the 60-sample median, the 27,000 reads and the 944-test run cannot be checked from the repository. The live A/B was measured at 58b647f, before the marker moved to command options. After the send path changes, please run one cloud snapshot -i --debug on the new head; its output should show both appState reads skipped with reason foreground_probe_read.

None of the 22 checks is failing.

Before merge, the skipped probe read needs its connection wait and read-only resend back, or an explicit maintainer decision that accepts a single attempt.

@thymikee

Copy link
Copy Markdown
Member Author

At 90f369471f, a pinned foreground appState read on a ready runner skips only uptime and uses the existing connection wait, read-only resend, and queued charge rules. system-surface-foreground-exchange.test.ts now verifies that one connection reset still returns the foreground state, a lost reply keeps its charge, and a pre-send refusal reports dispatched: 'no' and withdraws the charge. All 944 tests passed across the two foreground-probe files and eager-closure-budgets.test.ts. After two warmups, the Limrun Settings snapshot -i --debug trace recorded the following events and a matching send for each command ID, with zero uptime requests.

{"ts":"2026-11-30T15:40:34.498Z","phase":"ios_runner_readiness_preflight_skipped","data":{"command":"appState","commandId":"runner-f57dcd3f-963c-47e6-92f6-fcf1b136bc5d","reason":"foreground_probe_read","sessionReady":true}}
{"ts":"2026-11-30T15:40:34.498Z","phase":"ios_runner_readiness_preflight_skipped","data":{"command":"appState","commandId":"runner-7425f2da-a60e-46e4-b4af-863488361b3e","reason":"foreground_probe_read","sessionReady":true}}

@thymikee

Copy link
Copy Markdown
Member Author

No problems that need a change were found at 90f3694, and the required evidence is in place. The earlier request is addressed: a skipped foreground probe read now differs from the base only by not sending uptime, so the connection wait and the read-only resend apply again.

These threads no longer apply and can be resolved: the ADR names the probe exception; a pinned ID now rethrows before status recovery, and the refused-read test keeps the session; runner-command-types.ts left the diff; counts moved to a linked evidence file; the hint branch is gone; runner-lifecycle.ts now differs from the base only by one argument; the connection wait is restored, and the connection-reset test covers it.

One expected effect of the skip remains: if the transport fails for the whole deadline and the command is not proven unwritten, appState now leaves an abandoned command charge, while the base failed at uptime without a charge.

Not verified here: tests and device runs were not executed, and the retry and charge behavior and the regression coverage were judged from the code. The cloud trace excerpt shows only the two skip events, so the matching sends, the zero uptime requests, the timing table and the lease cleanup rest on the PR description. The 60-sample median and the 27,000-read figures in the evidence file cannot be checked from the repository.

One of the 23 checks is still queued, and no check has failed. No code change is needed before merge; the queued check still has to finish.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 30, 2026
@apex-sentinel-staging

Copy link
Copy Markdown

Apex Sentinel · ✅ Approve · review of 90f3694

Since the review of 895368c: 0 new · 0 still open · 0 no longer raised

No open findings.

2 findings below minor hidden (user_settings.min_severity).

Reviewed with this repository's own Sentinel configuration (34810b99604e).

💬 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.

@thymikee
thymikee merged commit 5d58cf9 into main Nov 30, 2026
23 checks passed
@thymikee
thymikee deleted the t3/skip-foreground-read-preflight branch November 30, 2026 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Valid work that needs human implementation, judgment, or maintainer merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant