Skip to content

fix(mobile): keep Attach Photos working while desktop requests are stalled - #36922

Merged
AmoabaKelvin merged 1 commit into
mainfrom
mobile-bridge-capacity-36568-36571-36573
Nov 1, 2026
Merged

AmoabaKelvin merged 1 commit into
mainfrom
mobile-bridge-capacity-36568-36571-36573

Conversation

@AmoabaKelvin

@AmoabaKelvin AmoabaKelvin commented Nov 1, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​107 $\color{#cf222e}{\Huge{\mathbf{−}}}$​56 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​51
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​33 $\color{#cf222e}{\Huge{\mathbf{−}}}$​9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​24

ELI5

On the phone, the web page talks to the app through a pipe that can hold 64 open requests. Requests to the desktop and requests for things the phone does itself, like opening the photo picker, shared those 64 slots. If the desktop stopped answering for a while, its requests could fill all 64, and tapping Attach Photos did nothing. Now the desktop can only use 60 of them, so the last 4 are always free for the phone's own actions.

What Changed

  • Before: with 64 desktop calls waiting (for example during a long reconnect), native.media.pick was refused before the picker opened (Mobile native actions are starved by outstanding desktop bridge requests #36568). A refused native.media.release was only logged by the page, so each refusal left a staged photo handle open. After eight of those, every later pick failed with native_media_handle_cap until the 5-minute expiry, even once the desktop answered again (Failed staged-media releases strand all attachment slots after transport recovery #36573).
  • After: desktop calls are admitted while fewer than 60 requests are in flight. native.* verbs are admitted up to the existing 64. The total bound is unchanged.
  • Mechanism: a new bridgePendingRequestCap(isNative) in bridge-caps.ts, next to BRIDGE_MAX_PENDING_REQUESTS. The page (BridgeRpcClient.sendRequest) and the shell (BridgeHostRequests.open) both admit requests through it. The shell's count already includes desktop calls that outlive a closed page, so a replacement page also finds the reserve free.

Why

The registry never fails a release on its own: MediaHandleRegistry.release deletes the handle before a best-effort file delete. A release therefore fails only when the bridge refuses the request, and in practice that means the shared cap. Reserving slots fixes the starvation and the stranded handles at the one decision that caused both.

Alternatives considered:

Mixed versions:

  • New page on an old shell: within one page the page holds desktop calls at 60, so native verbs still get the old shell's last 4.
  • Old page on a new shell: the shell refuses that page's desktop calls 61–64 with the usual cap error, and the old page already settles those.
  • No wire changes: the init grant still advertises the 64 total, and no new fields were added.

#36571 (the page keeping a retired orcaBridge) is left out on purpose, because shipped shells can't replace the channel inside a live document:

  • iOS: the shell defines orcaBridge with configurable:false, writable:false at document start.
  • Android: the shell calls addWebMessageListener only right before loadUrl, and Chromium injects the object into the next document only.

Linked Issue

Fixes #36568
Fixes #36573

Visual Proof

N/A. Nothing on screen changes. The failure only appears after 60 or more desktop calls stall, so it was reproduced in the real page↔shell bridge harness, which runs the serialized page client, the shell host, and the real native media server and registry. On main, the new test fails at the first pick with BridgeClientCapExceededError: over 64 requests in flight. A variant that lets picks through but takes the slot before each release fails on round 9 with native_media_handle_cap. With this change both pass.

Testing

  • bridge-host-media-verbs.test.ts: with every desktop slot filled before each step, nine pick → read → release rounds succeed and leave no live handles. This fails on main.

  • bridge-host-native-verbs.test.ts: an older page sends 64 desktop requests. The new shell admits 60 and still serves a native verb. This fails on main.

  • Existing cap tests are now pinned to the desktop cap (BRIDGE_MAX_PENDING_DESKTOP_REQUESTS). The probe that fills slots until refused is now shared through the port-pair harness.

  • Ran the focused bridge, media, dictation and native-media tests, the RPC recording goldens (2334 tests), the changed-file quality and React Doctor checks, oxlint and oxfmt. I didn't run anything on a device. The change is shared TS that runs the same way on iOS and Android.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

AI Disclosure

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Security, desktop, SSH: no change. This is mobile-only bridge admission.
  • Mobile: Android and iOS share this code.
  • Compatibility: covered above, with no wire changes.
  • Performance: one string prefix check per bridge request.
  • Dictation: audio verbs also count as native. The shipped drain keeps about two audio reads in flight, and photo verbs run one at a time, so 4 reserved slots cover both.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

Desktop RPCs and on-device native verbs shared the bridge's 64 in-flight request slots on both page and shell. Unanswered desktop calls could hold all of them, refusing native.media.pick and native.media.release; refused releases stranded staged handles until expiry, so later picks hit native_media_handle_cap. Desktop calls now stop at 60 so native verbs always have the last 4.
@coderabbitai

coderabbitai Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7af22c6e-7a40-4319-81d2-f1858f780b67
Commits

Reviewing files that changed from the base of the PR and between 7876c23 and 449df51.

Files selected for processing: 10
  • mobile/src/mobile-web-shell/bridge-host-media-verbs.test.ts
  • mobile/src/mobile-web-shell/bridge-host-native-verbs.test.ts
  • mobile/src/mobile-web-shell/bridge-host-requests.ts
  • mobile/src/mobile-web-shell/bridge-host.test.ts
  • mobile/src/mobile-web-shell/bridge/bridge-caps.ts
  • mobile/src/mobile-web-shell/bridge/bridge-client-unsendable-frame.test.ts
  • mobile/src/mobile-web-shell/bridge/bridge-port-pair-test-harness.ts
  • mobile/src/mobile-web-shell/bridge/bridge-rpc-client-frames.test.ts
  • mobile/src/mobile-web-shell/bridge/bridge-rpc-client.ts
  • mobile/src/platform/dictation-capture-bridge-budget.test.tsx

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Walkthrough

The bridge now reserves four of the shared pending-request slots from desktop requests. The bridge client and host use the full cap for native methods and the reduced cap for other methods. Tests cover request admission, slot reuse, native clipboard and media requests during desktop congestion, and dictation request budgets.

Severity of issue fixed: Medium

Merge Risk: Minimal · up to 449df

The change reserves capacity for native actions while retaining the overall request bound. No merge-blocking risk is established.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Linked Issues check Warning The changes satisfy the coding requirements of #36568. bridgePendingRequestCap reserves four slots for native methods, and both BridgeRpcClient.sendRequest and BridgeHostRequests.open enforce th… Implement the bounded staged-media release queue required by #36573. Retry queued releases before the next explicit media selection, drop cleanup from old sessions, and fence late completions. Retain the existing capacity reservation for #3…
Docstring Coverage Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title clearly and concisely identifies the primary user-facing fix: preserving Attach Photos functionality while desktop bridge requests remain stalled.
Description check Passed The description is complete and focused. It includes the required ELI5, change summary, rationale, linked issues, visual proof, testing details, review notes, compatibility considerations, and checkli…
Out of Scope Changes check Passed The changes stay within the linked issue scope. Production changes adjust page and shell bridge admission caps. Test changes cover the new desktop reserve, native admission, uncancellable requests, an…
Full details: Description check

Explanation

The description is complete and focused. It includes the required ELI5, change summary, rationale, linked issues, visual proof, testing details, review notes, compatibility considerations, and checklist status. It also states that no device testing was performed and identifies the remaining unchecked full-suite checklist item.

Full details: Out of Scope Changes check

Explanation

The changes stay within the linked issue scope. Production changes adjust page and shell bridge admission caps. Test changes cover the new desktop reserve, native admission, uncancellable requests, and media cleanup under congestion. No unrelated product behavior is changed. The explicitly excluded #36571 work is not included.

Full details: Linked Issues check

Explanation

The changes satisfy the coding requirements of #36568. bridgePendingRequestCap reserves four slots for native methods, and both BridgeRpcClient.sendRequest and BridgeHostRequests.open enforce the desktop cap. The updated tests cover native admission and media pick/read/release under desktop saturation. The changes do not satisfy the coding requirements of #36573. That issue requires a bounded per-client/session queue for failed staged-media releases, retries before the next explicit media selection, old-session cleanup dropping, and late-completion fencing. The PR only prevents release refusal caused by the shared pending-request cap. It does not retain or retry releases that fail for another reason.

Resolution

Implement the bounded staged-media release queue required by #36573. Retry queued releases before the next explicit media selection, drop cleanup from old sessions, and fence late completions. Retain the existing capacity reservation for #36568.

Full details: Docstring Coverage

Explanation

Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 6 functions across 10 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
Generate docstrings
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@AmoabaKelvin
AmoabaKelvin merged commit 5eac01e into main Nov 1, 2026
24 of 25 checks passed
nwparker added a commit that referenced this pull request Nov 1, 2026
…e bridge (#36938)

The free-slot probe fills every desktop slot, so end()'s final chunk forward
is refused by construction. Since #36922 reserved native slots, that final
read now succeeds and its forward is refused, failing Mobile verify under Bun.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant