#7350 · Native transport failures leave requests pending
Bug Priority: Medium Effort: Low mobile confirmed-repro
REPRODUCED · Root-cause confidence: high
1. TL;DR
A page asking the native shell to share or copy content does not promptly learn that its message could not be sent. The generated bridge catches a synchronous transport exception, but leaves the request promise and deadline intact. A deterministic execution of the actual injected script keeps share pending for its configured 10-second deadline and clipboard pending for 30 seconds, before rejecting with a misleading timeout. Both the observed behavior and the failing regression test were repeated by the same agent in a second clean checkout. Actual device navigation was not exercised; this confirms the reported failure path, not its frequency on hardware.
2. Claims vs findings
| Claim | Status | Evidence |
|---|---|---|
| A synchronous native send failure is hidden from request callers. | Verified | The real injected script catches the thrown transport error; the promise remains pending after a microtask checkpoint. |
| Normal requests wait 10 seconds; image clipboard requests wait 30 seconds. | Verified | Observed scheduled delays are 10000 and 30000 milliseconds. Executing those deadline callbacks rejects both with native request timed out. |
| Navigation can trigger this transport failure. | Unverified | The test deliberately makes the WebView transport throw. No real WebView navigation or mobile hardware was tested. |
| The submitter ran a regression locally. | Unverified | No submitter artifact was executed. New tests were designed from trusted repository code. |
3. Environment
- Public repository
get-bb/bb, full base SHA above; Linux x86_64, Node v22.19.0, pnpm 9.15.0, Vitest 4.1.12. - Two separate source worktrees at the same fetched origin/main commit. Only a locally authored test was applied to the verification checkout; production sources stayed unchanged.
- Frozen workspace install:
pnpm install --frozen-lockfile --prefer-offline. Package build:pnpm exec turbo run build --filter=@bb/mobile-bridge(this source-only package has no build task). - No running BB instance, providers, ports, databases, credentials, or mobile hardware were used. Tests execute the generated script against a throwing WebView boundary and controlled timers.
4. Minimal reproduction
- Clone the public target repository, check out
7c1353d80729983b86ea1555d18b42407f320406, and run the frozen install above. - Save the complete observer below as
observe.mjsin the checkout root and executenode --import tsx observe.mjs. This exercises the generated injection script, not a reimplementation of its request logic. - Expected: after a rejected send, the request is already rejected and no deadline remains. Actual, verbatim on both runs:
{"kind":"share","immediate":"pending","timers":1,"delayMs":10000}
{"kind":"share","afterDeadline":"rejected","error":"native request timed out"}
{"kind":"clipboard","immediate":"pending","timers":1,"delayMs":30000}
{"kind":"clipboard","afterDeadline":"rejected","error":"native request timed out"}
The observer asserts the defective baseline behavior and exits 0 when it is present. It advances controlled deadline callbacks rather than sleeping for 40 seconds. The regression below instead asserts the corrected behavior and intentionally exits 1 before the fix.
Save this regression patch as regression.patch, apply it to the base checkout with git apply regression.patch, then run the focused command below:
Complete regression patch
diff --git a/packages/mobile-bridge/test/inject.test.ts b/packages/mobile-bridge/test/inject.test.ts
index 1a95071c25..6f453af395 100644
--- a/packages/mobile-bridge/test/inject.test.ts
+++ b/packages/mobile-bridge/test/inject.test.ts
@@ -149,6 +149,30 @@ describe("buildBridgeInjectionScript", () => {
await expect(promise).rejects.toThrow("share sheet unavailable");
});
+ it.each(["share", "clipboard"])(
+ "rejects a %s request immediately when the native transport throws",
+ async (kind) => {
+ vi.useFakeTimers();
+ try {
+ const { native, fakeWindow } = installBridge();
+ fakeWindow.ReactNativeWebView.postMessage = () => {
+ throw new Error("transport disconnected");
+ };
+ const rejected = vi.fn();
+ const promise = native.request(kind, { text: "hello" });
+ void promise.catch(rejected);
+ await Promise.resolve();
+ expect(rejected).toHaveBeenCalledWith(expect.any(Error));
+ await expect(promise).rejects.toThrow("native message could not be sent");
+ expect(vi.getTimerCount()).toBe(0);
+ expect(() => native.post({ type: "haptic", kind: "selection" })).not.toThrow();
+ } finally {
+ vi.clearAllTimers();
+ vi.useRealTimers();
+ }
+ },
+ );
+
it("times out a request the shell never answers", async () => {
vi.useFakeTimers();
try {
pnpm exec turbo run test --filter=@bb/mobile-bridge -- --testNamePattern='native transport throws'
Actual pre-fix regression result, repeated in the clean second checkout:
AssertionError: expected "vi.fn()" to be called with arguments: [ Any<Error> ] Number of calls: 0 Tests 2 failed | 40 skipped (42) exit status: 1
Complete standalone observer
import assert from "node:assert/strict";
import { resolve } from "node:path";
import { pathToFileURL } from "node:url";
import { runInNewContext } from "node:vm";
const sourceRoot = process.argv[2] ?? process.cwd();
const { buildBridgeInjectionScript } = await import(
pathToFileURL(resolve(sourceRoot, "packages/mobile-bridge/src/inject.ts")).href
);
const handshake = {
bridgeVersion: 2,
appVersion: "0.39.0",
platform: "ios",
profileMode: "connect",
secureContext: true,
safeArea: { top: 59, right: 0, bottom: 34, left: 0 },
capabilities: ["share"],
};
for (const [kind, expectedDelay] of [["share", 10000], ["clipboard", 30000]]) {
const timers = new Map();
let nextTimer = 0;
const window = {
ReactNativeWebView: {
postMessage() {
throw new Error("transport disconnected");
},
},
};
runInNewContext(buildBridgeInjectionScript(handshake), {
window,
setTimeout(callback, delay) {
const timer = ++nextTimer;
timers.set(timer, { callback, delay });
return timer;
},
clearTimeout(timer) {
timers.delete(timer);
},
});
let settlement = "pending";
let errorMessage = null;
const observed = window.bb.native.request(kind, { text: "hello" }).then(
() => { settlement = "resolved"; },
(error) => {
settlement = "rejected";
errorMessage = error.message;
},
);
await Promise.resolve();
const scheduled = [...timers.values()];
console.log(JSON.stringify({ kind, immediate: settlement, timers: timers.size, delayMs: scheduled[0]?.delay ?? null }));
assert.equal(settlement, "pending");
assert.equal(scheduled.length, 1);
assert.equal(scheduled[0].delay, expectedDelay);
for (const [timer, entry] of timers) {
timers.delete(timer);
entry.callback();
}
await observed;
console.log(JSON.stringify({ kind, afterDeadline: settlement, error: errorMessage }));
assert.equal(settlement, "rejected");
assert.equal(errorMessage, "native request timed out");
}5. Root cause
The fire-and-forget sender is also used by request/reply calls. In inject.ts:63–70, the sender catches every exception, so request callers cannot distinguish delivery failure from successful delivery. The request path inject.ts:143–153 first creates a timeout and stores its resolve/reject pair, then invokes that swallowing sender. Since no response can follow a failed send, only the timeout eventually settles the promise.
var timer = setTimeout(function () {
delete pending[id];
reject(new Error("native request timed out"));
}, kind === "clipboard" ? 30000 : 10000);
pending[id] = { resolve: resolve, reject: reject, timer: timer };
post({ type: "request", id: id, request: { kind: kind, payload: payload } });
The API's public post signature returns void. Fire-and-forget calls should stay non-throwing; request/reply calls need explicit failure cleanup without changing that signature or the wire format.
6. Proposed fix and local validation
Share a private throwing serializer/transport helper between the existing non-throwing post wrapper and request. Catch send errors in request itself, remove its pending record, cancel its deadline, and reject immediately. This keeps best-effort haptics harmless and preserves existing normal reply and timeout behavior.
A local implementation changes two existing mobile-bridge files: 41 added lines and 6 deleted lines, 47 total. No dependency, generated output, protocol, schema, or stored data changes. The focused regression passes both cases after the repair. Existing successful replies, explicit native errors, fire-and-forget behavior, and 10/30-second unanswered-request cases are covered by the passing package suite.
pnpm exec turbo run test typecheck lint:type-aware --filter=@bb/mobile-bridge Test Files 3 passed (3) Tests 42 passed (42) Found 0 warnings and 0 errors. Tasks: 4 successful, 4 total git diff --check: clean
7. Verification
The same agent repeated both checks in a second clean temporary checkout at the recorded base commit. That checkout received only the locally authored regression patch and a fresh frozen install. No dev service was started, so new ports and data directories were not required.
git worktree add --detach ../verification 7c1353d80729983b86ea1555d18b42407f320406 cd ../verification pnpm install --frozen-lockfile --prefer-offline git apply regression.patch pnpm exec turbo run build --filter=@bb/mobile-bridge pnpm exec turbo run test --force --filter=@bb/mobile-bridge -- --testNamePattern='native transport throws' node --import tsx observe.mjs
The forced second regression run executes rather than replaying a cached result: two expected failures at the immediate-rejection assertion, exit 1. The second observer run exits 0 with identical pending/deadline output. Production code remained unchanged. Code permalinks were checked against that full base commit; no report correction was needed. This is repeat verification by one agent, not independent verification.
8. Related issues and pull requests
No linked open pull request was present in the issue cross-reference timeline, and an open-PR search for issue 7350 returned none before implementation. Related mobile-area issues were checked for classification conventions; none was used as evidence for this transport defect. No external issue-supplied link, patch, script, or branch was executed.
9. Appendix
The complete observer, regression patch, exact observed deadline output, and failing/passing test summaries are inline above. Raw logs remain in local evidence storage and are not published, in accordance with the reports repository's publication rules.
Focused post-fix result: Test Files 1 passed | 2 skipped (3) Tests 2 passed | 40 skipped (42) Commands also used: git fetch origin main git rev-parse origin/main git diff --check git diff --numstat origin/main pnpm exec oxfmt packages/mobile-bridge/test/inject.test.ts packages/mobile-bridge/src/inject.ts
Trust note: the issue included a proposed patch and asserted local testing. Both were treated solely as untrusted claims. The reproduction and implementation were authored from trusted target origin/main sources. Classification: Bug / Medium / Low / mobile; reproduction label: confirmed-repro.