Skip to content

fix(mobile): report a failed direct cutover instead of leaking it as an unhandled rejection - #19324

Closed
Jinwoo-H wants to merge 5 commits into
mainfrom
mobile/direct-probe-no-unhandled-rejection
Closed

Jinwoo-H wants to merge 5 commits into
mainfrom
mobile/direct-probe-no-unhandled-rejection

Conversation

@Jinwoo-H

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

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​158 $\color{#cf222e}{\Huge{\mathbf{−}}}$​12 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​146
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​35 $\color{#cf222e}{\Huge{\mathbf{−}}}$​7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​28

Follow-up to #19308 from the post-merge adversarial review.

Why

DirectReturnProbe.probe() is only ever reached from a timer that discards its promise. The cutover catch swallowed a withdrawn race (stopped || abortCutover()) but rethrew every other failure, so nothing could catch it. During a reconnect race abortCutover is stopped || !adoptsOutright(), and with nothing connected adoptsOutright() stays true, so a direct candidate that drops between authentication and the swap (or a logical client closed without stopping the supervisor) surfaced as an unhandled rejection. Before #19308 this path only ran against a live relay after a hysteresis streak; it now runs on every reconnect.

Recovery was never affected (the finally reschedules), but the rejection is log noise and a spurious error in crash reporters.

What

  • New onCutoverFailure(error) hook on the probe. A cutover that fails for a reason other than losing the race is reported through it and the probe returns normally.
  • The supervisor wires it to the existing relay recovery log: direct cutover failed after authentication with the first 80 chars of the message.

Tests

  • New: with adoptsOutright true and migrate rejecting, the failure is reported through the hook and process sees no unhandledRejection (fails on main).
  • New: a cutover withdrawn because relay won stays quiet.
  • Full mobile vitest (4324), tsc, oxlint, oxfmt --check clean.

@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

  • DirectReturnProbe.onCutoverFailure hook — the cutover catch no longer rethrows a non-withdrawn migrate failure (which escaped through the timer's discarded promise as an unhandledRejection); it reports it via the new hook and returns normally.
  • Supervisor wiring — onCutoverFailure routes to logRelay('direct cutover failed after authentication', error.message.slice(0, 80)), matching the existing relay bookkeeping failed after migration log.
  • Tests — a failed cutover under adoptsOutright is asserted to land in the hook with no unhandledRejection, and a withdrawn race is asserted to stay quiet.

The fix is minimal and correctly scoped. I traced the only two DirectReturnProbe constructors (supervisor + test fixture), confirmed the finally still reschedules and afterProbe releases the mutex/triggers relay recovery on a genuine failure, and that abortCutover()'s second call in the catch is a side-effect-free predicate. The unhandledRejection assertion is real coverage — it would fail on the pre-fix code (which rethrew). I ran mobile-direct-return-probe.test.ts (5/5 pass).

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

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: 31a5c53f-786b-401d-a70f-41da1af460d4

📥 Commits

Reviewing files that changed from the base of the PR and between 1de9000 and b1d4e0d.

📒 Files selected for processing (3)
  • mobile/src/transport/mobile-direct-return-probe.test.ts
  • mobile/src/transport/mobile-direct-return-probe.ts
  • mobile/src/transport/mobile-endpoint-supervisor.ts

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


📝 Walkthrough

Walkthrough

DirectReturnProbe now reports genuine cutover failures through an onCutoverFailure callback. It records hysteresis failures before reporting and avoids immediate redial. Stopped probes and withdrawn races remain ignored. Post-migration bookkeeping errors no longer produce unhandled promise rejections. MobileEndpointSupervisor logs truncated direct bookkeeping failures. Tests cover these behaviors.

Merge Risk: ⚪ Minimal · up to b1d4e

Mobile direct cutover and post-migration failures are now reported without unhandled promise rejections, while withdrawn races remain quiet. No concrete merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the problem, implementation, and tests, but it omits most required template sections. It does not provide the required Linked Issue format, ELI5, What Changed, Visual Proof wi… Complete the required template sections. Add an ELI5 summary, a What Changed section, a Linked Issue entry such as Fixes #19308`` if applicable, Visual Proof with N/A and a reason, AI Disclosure details or the applicable exemption, Review…
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the primary change: reporting failed direct cutovers instead of exposing them as unhandled promise rejections.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 3 files.
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 problem, implementation, and tests, but it omits most required template sections. It does not provide the required Linked Issue format, ELI5, What Changed, Visual Proof with an N/A explanation, AI Disclosure, Review, Agent skill upstream boundary, Notes, or Checklist details.

Resolution

Complete the required template sections. Add an ELI5 summary, a What Changed section, a Linked Issue entry such as Fixes #19308`` if applicable, Visual Proof with N/A and a reason, AI Disclosure details or the applicable exemption, Review, Agent skill upstream boundary, Notes, and the required checklist items. Include testing platforms and explain any unchecked items.

  • Fix all pre-merge checks with AI
✨ Finishing Touches
📝 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.

@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: ce5a0181-10fa-4879-b9bf-2d17b77640d0

📥 Commits

Reviewing files that changed from the base of the PR and between 9fed61e and 04f0b41.

📒 Files selected for processing (3)
  • mobile/src/transport/mobile-direct-return-probe.test.ts
  • mobile/src/transport/mobile-direct-return-probe.ts
  • mobile/src/transport/mobile-endpoint-supervisor.ts

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

@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 critical issues — one minor type-annotation fix inline.

Reviewed changes

  • Contained a throwing onCutoverFailure reporter — the hook call is now wrapped in try/catch, so a reporter that itself throws can no longer reject the timer-owned probe() promise and leak an unhandled rejection.
  • Added a throwing-reporter regression test — a fixture override that explodes is asserted to still settle cleanly (no unhandledRejection).

The containment matches what the prior review flagged as the remaining gap: the reporter is now truly diagnostics-only, and the new test would fail if the try/catch were removed (the throw would escape the timer-discarded promise).

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | 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.

✅ No new issues found.

Reviewed changes

  • Type-annotated the fixture overrides param — mobile-direct-return-probe.test.ts now declares onCutoverFailure?: (error: Error) => void on the fixture overrides type, closing the gap the prior review flagged (TS2339/TS2353, previously invisible because mobile/tsconfig.json excludes **/*.test.ts from tsc --noEmit).

The incremental delta is a single mechanical type-annotation fix that makes the fixture's contract match its usage; no behavioral surface changed.

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

…t-migration errors

A failed cutover kept the credited success streak, so the next 15s tick re-dialed and failed
the same way forever. The failure now enters hysteresis cooldown. onDirectMigrated rejections
are reported through the same hook instead of escaping the timer promise.

@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 critical issues — the cooldown booking and post-migration containment are correct; one minor diagnostic-labeling suggestion inline.

Reviewed changes

  • Booked a direct failure on a genuine cutover failure — recordDirectFailure now runs before the report, so the resulting cooldown stops the probe from re-dialing, re-promoting on the spot, and failing identically every 15 s tick.
  • Contained post-migration bookkeeping errors — onDirectMigrated is wrapped in try/catch and reported via reportCutoverFailure, so a credentialRefresh failure can no longer reject the timer-discarded promise.
  • Extracted reportCutoverFailure and added onDirectMigrated/hysteresis fixture overrides plus two regression tests.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | 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.

✅ No new issues found.

Reviewed changes

  • Split direct-cutover diagnostics into two hooks — a failed migrate now reports through onCutoverFailure (direct cutover failed after authentication), while a post-migration onDirectMigrated bookkeeping failure routes through a new onBookkeepingError hook (direct bookkeeping failed after migration), so a landed-but-bookkeeping-failed cutover no longer reads as a lost-race fallback in field logs. This mirrors the relay path's pre-existing onBookkeepingError distinction.
  • Generalized the reporter — reportCutoverFailure became report(hook, error), which dispatches on a hook key and keeps the throwing-reporter try/catch containment in a single place for both failure modes.
  • Tests updated in lockstep — the fixture gained an onBookkeepingError override and a bookkeepingErrors sink; the post-migration failure test now asserts the error lands in bookkeepingErrors with cutoverFailures empty (plus no unhandledRejection).

This commit resolves the prior review's diagnostic-labeling nit by giving the cutover-failure and bookkeeping-failure paths distinct hooks and log lines.

Pullfrog  | 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