Skip to content

fix(mobile): re-ask a refused status probe, fresh miss budget per resume probe, persist endpoint before booking a refresh - #19325

Closed
Jinwoo-H wants to merge 4 commits into
mainfrom
mobile/review-round-2-fixes
Closed

Jinwoo-H wants to merge 4 commits into
mainfrom
mobile/review-round-2-fixes

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​179 $\color{#cf222e}{\Huge{\mathbf{−}}}$​7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​172
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​42 $\color{#cf222e}{\Huge{\mathbf{−}}}$​15 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​27

Follow-ups to #19260, #19280, and #19308 from the post-merge adversarial review. Four findings, each reproduced against main; the two behavioural ones have failing-first tests.

Why

What

  • runtime-status-probe.ts: an ok:false reply re-asks at the 15 s ceiling instead of stopping. Unanswered requests still back off from 1 s; cutover still re-asks at 250 ms. onUnavailable always reports a retry armed.
  • rpc-session-liveness-watchdog.ts: probeNow(…, 'resume') resets the miss count before starting the urgent probe.
  • mobile-relay-credential-refresh.ts: refreshed = true moves below await persistResolvedRelay(...).
  • relay-dial-stage.ts: comment only.

Tests

  • Status probe: an error reply is re-asked at 15 s and the next ok lands (fails on main, which asserted the probe stopped).
  • Watchdog: two resume probes each tolerate one miss; termination needs the second miss of the second probe (fails on main).
  • Full mobile vitest (4323), tsc, oxlint, oxfmt --check clean.

… fresh miss budget, persist the relay endpoint before booking a refresh

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

  • Status probe re-asks a refused status.get — startRuntimeStatusProbe now treats an ok:false reply as a failed attempt worth retrying at the 15 s ceiling instead of settling permanently, so worktree.activate and every capability can upgrade after a transient host failure or a relay-surfaced error frame.
  • Fresh miss budget per resume probe — RpcSessionLivenessWatchdog.probeNow(…, 'resume') zeroes missedProbes before starting the urgent probe, so a second app-resume nudge in the urgent window no longer inherits the first probe's miss.
  • Endpoint persisted before the refresh gate lifts — MobileRelayCredentialRefresh moves refreshed = true below await persistResolvedRelay(…), so a failed endpoint write no longer lifts the fresh-credential gate and fires onRefreshed against a pre-rotation cell.
  • confirming budget comment corrected — relay-dial-stage.ts now documents that the live session publishes connected on stage entry and bounds the resume confirm itself at 12 s; the 35 s entry stays for stage-table totality. The relayDialStageBudgetMs signature (keyof typeof RELAY_DIAL_STAGE_BUDGET_MS) is type-equivalent to the previous Exclude<..., 'opening'> and lets the table drive the accepted param names.
  • Tests — failing-first tests for the probe re-ask and the per-resume miss budget; both reproduce the mutation first.

ℹ️ Credential-refresh reorder ships without a regression test

The persist-before-gate-lift change in mobile-relay-credential-refresh.ts is the one behavioral adjustment here with no covering test (the probe and watchdog fixes both got failing-first tests; MobileRelayCredentialRefresh has no test file at all). The contract it now relies on — a failed persistResolvedRelay must neither lift the gate nor fire onRefreshed — is asserted only by the inline comment. The reorder itself is trivially correct and I found no bug, so this isn't blocking; a small async-ordering test pinning that contract would harden it against a future regression.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@coderabbitai

coderabbitai Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The changes update relay refresh completion ordering and derive relay dial budget parameter types from the budget constant. Resume probes now preserve miss counts across repeated urgent probes and re-arm after booked misses. Runtime status probes retry answered error responses after 15 seconds. Tests cover relay refresh recovery, liveness budgets, and runtime status retries.

Merge Risk: 🔵 Low · up to 6081e

Relay refresh now waits for endpoint persistence before completing, but its test suite does not verify that the newly resolved relay endpoint is the value persisted. This is a bounded coverage gap that should be addressed before relying on the test to prevent stale-endpoint regressions.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the problems, changes, and tests, but it does not follow the required template. It omits the ELI5, Linked Issue, Visual Proof, Review, Agent skill upstream boundary, Notes, an… Add all required template sections. Include an ELI5 summary, a What Changed section, a Fixes #<issue> link, and N/A with a reason under Visual Proof if there is no UI or interaction change. Complete Testing, Review, Agent skill upstream…
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 7 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main mobile fixes: retrying refused status probes, resetting resume miss budgets, and persisting the relay endpoint before refresh success.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description explains the problems, changes, and tests, but it does not follow the required template. It omits the ELI5, Linked Issue, Visual Proof, Review, Agent skill upstream boundary, Notes, and Checklist sections, and it does not include a required Fixes # issue link or N/A visual-proof statement.

Resolution

Add all required template sections. Include an ELI5 summary, a What Changed section, a Fixes #&lt;issue&gt; link, and N/A with a reason under Visual Proof if there is no UI or interaction change. Complete Testing, Review, Agent skill upstream boundary, Notes, and Checklist sections. Preserve the existing technical rationale and test results.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

…er credential refresh ordering

A resume zeroed the miss count unconditionally, so a burst of resumes or a user tapping
reconnect on a dead relay socket never reached a verdict. The clean budget now comes only
from the profile switch. New tests for MobileRelayCredentialRefresh pin that the gate lifts
only after the endpoint persists and that a failed persist leaves a retry, not a wedge.

@pullfrog pullfrog 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.

Important

The "fresh miss budget per resume probe" fix is no longer in the code — the headline of this PR contradicts what it merges.

Reviewed changes

  • Credential-refresh ordering now has a regression test — mobile-relay-credential-refresh.test.ts was added covering the happy-path order plus both failure paths (a failed persist keeps the gate closed, and a later run re-enters instead of staying wedged). This addresses the prior review's open observation.
  • Watchdog reworked to keep the miss budget across repeated resumes — the probeNow per-resume missedProbes = 0 reset was dropped, so a burst of resumes (AppState flaps, a user tapping reconnect on a dead socket) no longer zeroes the budget on every tap and stalls the verdict.

⚠️ The description now describes behavior the code no longer has, and #19280 goes unfixed

The second commit removed if (urgent) this.missedProbes = 0 from probeNow, leaving rpc-session-liveness-watchdog.ts a comment-only diff against main. But the title still advertises a "fresh miss budget per resume probe", the body still says probeNow(…, 'resume') "resets the miss count", and the Tests section still claims "two resume probes each tolerate one miss (fails on main)". None of that is true of the committed code — both new watchdog tests pass against main unchanged.

The consequence: back-to-back resumes (the iOS active/inactive/active pair #19280 described) once again share a single miss budget, so a live session with two cold-radio slow answers is terminated — the exact symptom this PR was opened to fix. That may be the right trade-off against the dead-socket-never-terminates regression the reset introduced, but the description must say so.

Technical details
# Reconcile the description with the reverted watchdog change

## Affected sites
- PR title — claims "fresh miss budget per resume probe"; the final code keeps the budget across repeated resumes.
- PR body "What" — says `probeNow(…, 'resume')` resets the miss count; it no longer does.
- PR body "Tests" — says "two resume probes each tolerate one miss"; the committed tests assert the opposite.
- mobile/src/transport/rpc-session-liveness-watchdog.ts:114 — `probeNow` no longer zeroes `missedProbes`; only `startProbe`'s profile switch (`profile !== this.profile`) does.
- mobile/src/transport/rpc-session-liveness-watchdog.test.ts:259 and :290 — both pass on `main`; they document existing behavior, not a regression.

## Required outcome
- Update the title and body to state that back-to-back resume probes intentionally share a miss budget, and drop the "fails on main" claim.
- Confirm whether leaving #19280's original symptom unfixed is the intended resolution.

## Open questions for the human (optional)
- Is the profile-switch reset a sufficient standalone answer for #19280, or should a "new observation" be distinguished from a "repeated tap" (e.g. a short debounce)?

ℹ️ Nitpicks

  • mobile-relay-credential-refresh.test.ts "lifts the gate and starts the relay race only after the endpoint is durable" asserts an event order the pre-fix code also produces — completeRefresh/onRefreshed fire in finally after persistResolvedRelay regardless of where refreshed is assigned, so only the two failure-path tests actually pin the reorder.

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog 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.

Important

The delta is clean, but the PR description still contradicts the committed watchdog behavior — the item flagged last round is unaddressed and this commit makes it worse.

Reviewed changes

  • Kept an in-flight urgent probe's deadline — RpcSessionLivenessWatchdog.probeNow(…, 'resume') now returns early when a resume lands while a 'resume'-profile probe is already in flight, so a tap burst or AppState flap no longer re-arms the 2 s clock and starves the death verdict. The prior commit preserved the miss budget across repeated resumes; this adds deadline preservation, closing the dead-socket-never-terminates regression.
  • Rewrote the repeated-resume regression test as a timed loop — a resume every 1.5 s on a black-holed socket now asserts the verdict still lands. On main each resume re-arms the deadline so termination never fires, making this genuinely failing-first against the un-patched watchdog.
  • Added a no-op refresh test — MobileRelayCredentialRefresh now also asserts an unforced run with a fresh credential rotates nothing, pinning the needs-rotation gate the hoisted needsRotation mock newly exposes.

⚠️ Description still does not match the committed watchdog

The title/body reconciliation requested in the prior review is still outstanding, and this commit's guard change widens the gap. The title still advertises a "fresh miss budget per resume probe"; the body's "What" still says probeNow(…, 'resume') "resets the miss count"; and "Tests" still claims "two resume probes each tolerate one miss (fails on main)". None of that describes the committed code: repeated resumes are now swallowed wholesale, and the committed test asserts a dead socket still terminates (which fails on main because main re-arms the deadline every resume, not because of a shared budget).

Technical details
# Reconcile the PR description with the final watchdog semantics

## Affected sites
- PR title — "fresh miss budget per resume probe"; the code does not grant repeated resumes a fresh budget.
- PR body "What" — `probeNow(…, 'resume')` does not reset the miss count; only `startProbe`'s profile switch does.
- PR body "Tests" — the committed test is not "two resume probes each tolerate one miss"; it is "repeated resumes on a dead socket still reach a verdict".
- mobile/src/transport/rpc-session-liveness-watchdog.ts:133 — the new `if (urgent && this.probing && this.profile === this.urgentProfile) return` guard.

## Required outcome
- Update the title and body to state that a resume landing while an urgent probe is in flight is a no-op (deadline and budget both preserved), and that the profile switch — not the resume itself — is what grants a clean budget.
- Drop or correct the "fails on main" framing to match the new test's actual mechanism.

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

…ow, one re-arm per miss

Keeping the deadline unconditionally gave a real resume at 3.9 s only the last 100 ms of the
previous probe and killed a socket that answered at 4.1 s. Each booked miss now buys exactly
one re-arm, so a tap burst still reaches a verdict within (limit × timeout) + one window per miss.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: 09ce0861-654f-41fc-8418-2b3aed9f3376

📥 Commits

Reviewing files that changed from the base of the PR and between de6571e and 6081e23.

📒 Files selected for processing (3)
  • mobile/src/transport/mobile-relay-credential-refresh.test.ts
  • mobile/src/transport/rpc-session-liveness-watchdog.test.ts
  • mobile/src/transport/rpc-session-liveness-watchdog.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review.

Comment on lines +31 to +35
persistResolvedRelay:
overrides.persistResolvedRelay ??
(async () => {
order.push('persist')
}),

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.

🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

Assert the persisted relay endpoint.

The fixture records only that persistResolvedRelay ran. It discards the callback argument. The happy-path test will therefore pass if the implementation persists a stale or unrelated endpoint. Capture the argument and assert that it equals rotated.relay in the ordering test.

@pullfrog pullfrog 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.

Important

The PR description still contradicts the committed watchdog behavior, and this commit widens the gap by adding a rearmedAtMiss re-arm rule the description never mentions.

Reviewed changes

  • Replaced the unconditional resume no-op with one-re-arm-per-miss — RpcSessionLivenessWatchdog.probeNow(…, 'resume') now re-arms the urgent deadline when a miss has been booked since the last re-arm (rearmedAtMiss), giving a resume at 3.9 s a fresh 2 s window instead of the previous probe's final 100 ms, while a tap burst with no new miss still keeps the in-flight probe's deadline.
  • Added a failing-first test for the resume-after-miss case — the new test exits the urgent window at 3.9 s, delivers inbound traffic at 4.1 s, and asserts no termination; it fails against the prior commit's unconditional return. The repeated-resume loop was extended to 9 s and its comment rederived for the re-arm bound.

⚠️ Description still does not describe the committed watchdog

The title/body reconciliation requested in the two prior reviews remains outstanding, and this commit makes it worse: the plain no-op guard is now a rearmedAtMiss re-arm rule that appears nowhere in the description. The title still advertises a "fresh miss budget per resume probe"; the body's "What" still says probeNow(…, 'resume') "resets the miss count"; the "Tests" section still claims "two resume probes each tolerate one miss (fails on main)". None of that is what the code does: the miss count is never reset by probeNow (only startProbe's profile switch is), a resume landing while an urgent probe is in flight is a no-op unless a miss was booked since the last re-arm, and each booked miss buys exactly one re-arm.

Technical details
# Reconcile the PR description with the re-arm rule

## Affected sites
- PR title — "fresh miss budget per resume probe"; the code grants one fresh window per booked miss, not per resume.
- PR body "What" — says `probeNow(…, 'resume')` "resets the miss count"; it no longer does under any condition.
- PR body "Tests" — says "two resume probes each tolerate one miss"; the committed tests are "repeated resumes on a dead socket still reach a verdict" and "a resume after a tolerated miss gets a fresh window".
- mobile/src/transport/rpc-session-liveness-watchdog.ts:139 — the `rearmedAtMiss` guard is the actual mechanism and should be the thing the description documents.

## Required outcome
- Update the title and body to state that a resume during an in-flight urgent probe is a no-op unless a miss was booked since the last re-arm, that each booked miss buys exactly one re-arm, and that the profile switch — not the resume — is what grants a clean budget.
- Correct the "fails on main" framing to match each test's actual mechanism.

## Open questions for the human (optional)
- Does the one-re-arm-per-miss rule now sufficiently resolve #19280's back-to-back-resume symptom, or should a "new observation" (cold radio) still be distinguished from a "repeat tap"?

ℹ️ Nitpicks

  • rearmedAtMiss is reset in noteAuthenticatedInbound and on the startProbe profile switch, but not in start(), stop(), or the idle-background reset in handleProbeTimeout — the three other places that zero missedProbes. It is safe today only because every path back into the urgent profile passes through the profile switch; resetting it alongside missedProbes in those three sites would keep the invariant symmetric.

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@Jinwoo-H

Jinwoo-H commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

Closed with #19348, which reverts the mobile pass this PR fixes bugs inside. The mobile reconnect work will be re-landed one narrow, device-verified change at a time.

@Jinwoo-H Jinwoo-H closed this Sep 7, 2026
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.

1 participant