← reports

#5836 · Async isolation misattributes host React insertions

BugPriority: MediumEffort: MediumpluginsGitHub issue2026-10-20

Trusted base: b0bb68655adcc6cd79e495d3484f4011a0640e2e (origin/main fetched from get-bb/bb).

Verdict: REPRODUCED · Root-cause confidence: high · label: confirmed-repro

1. TL;DR

A pending plugin mount can prevent a host-owned React element from entering the document even though the plugin does not touch the DOM. The guard keeps a global plugin-isolation flag active while awaiting the plugin promise. React's unrelated commit then passes through the same patched DOM methods and is incorrectly rejected. Two clean trusted checkouts reproduce this with real React; a settled-promise control succeeds. The full application/browser journey is not claimed as verified.

2. Claims vs findings

ClaimFindingEvidence
A pending mount with no DOM work can block host React insertion.VerifiedBoth runs: pending case absent, one refusal; settled control present, no refusals.
The global async isolation window is responsible.VerifiedProduction guard, production React commit, pending-versus-settled control.
Every DOM insertion is refused.OverbroadOnly React-owned nodes matching the reparent predicate are refused. Plain DOM nodes and some fresh inserts under React-owned parents are allowed.
Content-script mounting invokes the async guard; its default timeout is 10 seconds.Verified in sourceplugin-frontend mountWithTimeout, its abort signal, and the 10,000 ms default.
All plugin overlays disappear on every full app load, including Windows desktop.Not independently exercisedExact DOM ownership failure reproduced in jsdom. Browser/desktop, timing frequency, and named third-party plugins were not run.

3. Environment

4. Minimal reproduction

  1. Prepare an isolated checkout from the trusted repository at the recorded base.
    git clone --branch main https://github.com/get-bb/bb.git bb-5836
    cd bb-5836
    git checkout --detach b0bb68655adcc6cd79e495d3484f4011a0640e2e
    pnpm install --frozen-lockfile --prefer-offline
  2. Copy the independently authored regression test below into apps/app/src/lib/issue-5836.test.tsx.
  3. Run through the normal package orchestration.
    pnpm exec turbo run test --filter=@bb/app -- src/lib/issue-5836.test.tsx --silent=false

The test creates a real React root, starts a no-DOM plugin callback returning a controlled promise, and commits an overlay-marked host node before that promise settles. It repeats the same operation after settlement as a negative control. It restores the guard and console spy, unmounts React, and removes its DOM container.

Expected: both states insert the overlay element with zero refusals. Actual (both checkouts):

{"state":"pending","presentWhilePending":false,"refused":1,"warningCount":1}
{"state":"settled","presentWhilePending":true,"refused":0,"warningCount":0}
AssertionError: expected false to be true // Object.is equality
Test Files  1 failed (1)
Tests  1 failed | 1 passed (2)
Complete regression test
// @vitest-environment jsdom
import { act } from "@testing-library/react";
import { createRoot } from "react-dom/client";
import { expect, it, vi } from "vitest";
import {
  installForeignDomMutationGuard,
  pluginHostNodeMoveRefusalCount,
  runWithPluginDomIsolationAsync,
  uninstallForeignDomMutationGuardForTest,
} from "./foreign-dom-mutation-guard";

it.each(["pending", "settled"])("allows a host React insertion with a %s plugin mount", async (state) => {
  const warning = vi.spyOn(console, "warn").mockImplementation(() => undefined);
  const container = document.createElement("div");
  document.body.appendChild(container);
  const root = createRoot(container);
  let finishMount = () => {};
  const pendingMount = new Promise<void>((resolve) => {
    finishMount = resolve;
  });
  installForeignDomMutationGuard();
  const mount = runWithPluginDomIsolationAsync(() => pendingMount, "pending-mount");
  try {
    await Promise.resolve();
    if (state === "settled") {
      finishMount();
      await mount;
    }
    act(() => root.render(<div data-bb-plugin-app-overlays="">Overlay content</div>));
    const presentWhilePending = container.querySelector("[data-bb-plugin-app-overlays]") !== null;
    const refused = pluginHostNodeMoveRefusalCount();
    finishMount();
    await mount;
    console.log(JSON.stringify({ state, presentWhilePending, refused, warningCount: warning.mock.calls.length }));
    expect(presentWhilePending).toBe(true);
    expect(refused).toBe(0);
  } finally {
    finishMount();
    await mount;
    act(() => root.unmount());
    uninstallForeignDomMutationGuardForTest();
    container.remove();
    warning.mockRestore();
  }
});

5. Root cause

An app-global isolation depth remains positive across an awaited plugin mount, so the DOM guard attributes unrelated host React commits to that plugin and refuses fresh React nodes inserted into root containers. This is not proof that the plugin executed React's commit; it demonstrates the guard has no execution-owner discriminator during that interval.

Async isolation lifetime:

export async function runWithPluginDomIsolationAsync<T>(
  fn: () => T | Promise<T>,
  label?: string,
  signal?: AbortSignal,
): Promise<T> {
  const previousLabel = enterIsolation(label);
  const work = Promise.resolve().then(fn);
  try {
    if (signal === undefined) return await work;
    const winner = await Promise.race([
      work.then((value) => ({ ok: true as const, value })),
      whenAborted(signal).then(() => ({ ok: false as const })),
    ]);
    if (winner.ok) return winner.value;
  } finally {
    leaveIsolation(previousLabel);
  }
  return await work;
}

Refusal predicate:

function refusePluginReparent(node: Node, newParent: Node): boolean {
  if (isolationDepth === 0) return false;
  if (node.parentNode === newParent) return false;
  if (!isReactHostNode(node)) return false;
  if (node.parentNode === null && isReactHostNode(newParent)) return false;
  recordRefusedMove(node, newParent);
  return true;
}

A freshly created React host node has a React fiber marker but no parent. The external React root container is not a React host node, so the fresh-node exception does not apply. The patched appendChild or insertBefore returns the node without inserting it; React still considers its commit complete. The overlay node can therefore remain detached after the pending mount finishes.

Production linkage: content-script mounting calls the async guard with an abort signal; 10-second default; overlay host element. The test substitutes only a deterministic pending callback; it does not load a third-party plugin or mock React, DOM methods, or the guard.

6. Proposed fix and simple-fix gate

Replace ambient promise-lifetime ownership with execution-scoped attribution, or a carefully specified host-commit exemption, without weakening the existing protection against plugin reparenting after await. This needs a design decision and regression coverage for both invariants.

The existing “keeps isolation across await and event listeners” regression explicitly requires a plugin continuation after await to remain guarded. The implementation wraps timers, listeners, observers, and queueMicrotask, but does not instrument native async/await continuation ownership. Simply shortening the isolation lifetime would remove an existing behavior contract rather than establish correct attribution.

No automatic PR: choosing a replacement execution-ownership mechanism or weakening the post-await guarantee is a design/behavior decision, which fails the rule's simple-fix gate. No production patch was made, no branch was pushed, and no dependency was added. A future design must pass both the new host-commit regression and the existing plugin-reparenting regression.

7. Pull requests and related history

There was no open pull request in get-bb/bb linking this issue when checked. An external plugin-workaround cross-reference was not fetched, checked out, or executed. Repository history identifies #1456 as the addition of the plugin isolation guard and #1418 as the earlier foreign-mutation crash mitigation. No claim is made that those historical PRs fix this bug.

8. Verification

The same agent repeated the reproduction in a second freshly created detached trusted checkout at b0bb68655adcc6cd79e495d3484f4011a0640e2e, with a separate frozen dependency installation and an unchanged production tree. The command was identical; each checkout executed its test rather than receiving a cached test result. Both runs failed the pending-state assertion and passed the settled control. No ports or data directory were used. This is repeat verification, not an independent-agent check.

Existing focused suites passed: foreign-dom-mutation-guard (10 tests), plugin-frontend (8 tests), PluginAppOverlays (3 tests), total 21 passed in 3 files. This confirms the conflicting post-await protection is an intentional covered invariant. The first draft's cleanup removed the guard too early and masked the assertion with a cleanup NotFoundError; cleanup was corrected before both final runs. The final artifact and logs contain the intended assertion failure.

9. Appendix and limits

Reproduced directly with real React and the production guard in jsdom in two clean worktrees. Full browser and Windows desktop journeys were not exercised: the Browser Automation plugin could not find Chrome/Chromium. No screenshots were fabricated. The normal full build hit an unrelated missing plugin-sdk/host build artifact. No production fix or pull request was attempted because a synchronous-only change conflicts with an existing post-await isolation contract.

Reproduction code and sanitized output are inline in this HTML. Raw evidence remains in local investigation storage, in accordance with the reports repository's publication policy.

Checkout A final output (temporary checkout paths anonymized)
• turbo 2.10.12

   • Packages in scope: @bb/app
   • Running test in 1 packages
   • Remote caching disabled, using shared worktree cache

@bb/templates:generate:templates: cache miss, executing 37652f89463f0d90
@bb/templates:generate:plugin-scaffold: cache miss, executing a3e3c06cdf3aef55
//:ensure-native-modules: cache bypass, force executing f7b393c33a4ee56f
@bb/process-utils:generate:profile-worker: cache miss, executing ca91093512378b09
@bb/plugin-build:generate: cache miss, executing 12802639368e6661
@bb/plugin-build:generate: 
@bb/plugin-build:generate: > @bb/plugin-build@0.0.1 generate <checkout-A>/packages/plugin-build
@bb/plugin-build:generate: > node ./scripts/generate-plugin-theme.mjs && node ./scripts/generate-runtime-export-manifest.mjs
@bb/plugin-build:generate: 
@bb/process-utils:generate:profile-worker: 
@bb/process-utils:generate:profile-worker: > @bb/process-utils@0.0.1 generate:profile-worker <checkout-A>/packages/process-utils
@bb/process-utils:generate:profile-worker: > node scripts/generate-profile-worker.mjs
@bb/process-utils:generate:profile-worker: 
@bb/templates:generate:templates: 
@bb/templates:generate:templates: > @bb/templates@0.0.1 generate:templates <checkout-A>/packages/templates
@bb/templates:generate:templates: > node ./scripts/generate-templates.mjs
@bb/templates:generate:templates: 
//:ensure-native-modules: 
//:ensure-native-modules: > bb@ ensure-native-modules <checkout-A>
//:ensure-native-modules: > node scripts/ensure-native-modules.mjs
//:ensure-native-modules: 
@bb/templates:generate:plugin-scaffold: 
@bb/templates:generate:plugin-scaffold: > @bb/templates@0.0.1 generate:plugin-scaffold <checkout-A>/packages/templates
@bb/templates:generate:plugin-scaffold: > node ./scripts/generate-plugin-scaffold.mjs
@bb/templates:generate:plugin-scaffold: 
@bb/plugin-build:generate: plugin-theme.generated.ts up to date
@bb/plugin-build:generate: wrote <checkout-A>/packages/plugin-build/src/generated/runtime-export-manifest.generated.ts (react@19.2.4)
@bb/app:test: cache miss, executing 969bdb9d3261fc3a
@bb/app:test: 
@bb/app:test: > @bb/app@0.0.1 test <checkout-A>/apps/app
@bb/app:test: > node scripts/generate-pwa-icons.mjs --check && vitest run --config vitest.config.ts "src/lib/issue-5836.test.tsx" "--silent=false"
@bb/app:test: 
@bb/app:test: 
@bb/app:test:  RUN  v4.1.1 <checkout-A>/apps/app
@bb/app:test: 
@bb/app:test: stdout | src/lib/issue-5836.test.tsx > allows a host React insertion with a pending plugin mount
@bb/app:test: {"state":"pending","presentWhilePending":false,"refused":1,"warningCount":1}
@bb/app:test: 
@bb/app:test: stdout | src/lib/issue-5836.test.tsx > allows a host React insertion with a settled plugin mount
@bb/app:test: {"state":"settled","presentWhilePending":true,"refused":0,"warningCount":0}
@bb/app:test: 
@bb/app:test:  ❯ |@bb/app:isolated| src/lib/issue-5836.test.tsx (2 tests | 1 failed) 25ms
@bb/app:test:    × allows a host React insertion with a pending plugin mount 21ms
@bb/app:test:    ✓ allows a host React insertion with a settled plugin mount 3ms
@bb/app:test: 
@bb/app:test: ⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯
@bb/app:test: 
@bb/app:test:  FAIL  |@bb/app:isolated| src/lib/issue-5836.test.tsx > allows a host React insertion with a pending plugin mount
@bb/app:test: AssertionError: expected false to be true // Object.is equality
@bb/app:test: 
@bb/app:test: - Expected
@bb/app:test: + Received
@bb/app:test: 
@bb/app:test: - true
@bb/app:test: + false
@bb/app:test: 
@bb/app:test:  ❯ src/lib/issue-5836.test.tsx:35:33
@bb/app:test:      33|     await mount;
@bb/app:test:      34|     console.log(JSON.stringify({ state, presentWhilePending, refused, …
@bb/app:test:      35|     expect(presentWhilePending).toBe(true);
@bb/app:test:        |                                 ^
@bb/app:test:      36|     expect(refused).toBe(0);
@bb/app:test:      37|   } finally {
@bb/app:test: 
@bb/app:test: 
@bb/app:test: ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯
@bb/app:test: 
@bb/app:test:  Test Files  1 failed (1)
@bb/app:test:       Tests  1 failed | 1 passed (2)
@bb/app:test:    Start at  06:20:39
@bb/app:test:    Duration  2.36s (transform 1.30s, setup 1.35s, import 252ms, tests 25ms, environment 564ms)
@bb/app:test: 
@bb/app:test:  ELIFECYCLE  Test failed. See above for more details.
@bb/app#test:  ERROR  command (<checkout-A>/apps/app) /usr/local/bin/pnpm run test src/lib/issue-5836.test.tsx --silent=false exited (1)

 Tasks:    5 successful, 6 total
Cached:    0 cached, 6 total
  Time:    4.6s 
Failed:    @bb/app#test

 ERROR  run failed: command  exited (1)
Checkout B final output (temporary checkout paths anonymized)
• turbo 2.10.12

   • Packages in scope: @bb/app
   • Running test in 1 packages
   • Remote caching disabled, using shared worktree cache

//:ensure-native-modules: cache bypass, force executing f7b393c33a4ee56f
@bb/templates:generate:templates: cache hit, replaying logs 37652f89463f0d90
@bb/templates:generate:plugin-scaffold: cache hit, replaying logs a3e3c06cdf3aef55
@bb/templates:generate:templates: 
@bb/templates:generate:templates: > @bb/templates@0.0.1 generate:templates <checkout-A>/packages/templates
@bb/templates:generate:templates: > node ./scripts/generate-templates.mjs
@bb/templates:generate:templates: 
@bb/templates:generate:plugin-scaffold: 
@bb/templates:generate:plugin-scaffold: > @bb/templates@0.0.1 generate:plugin-scaffold <checkout-A>/packages/templates
@bb/templates:generate:plugin-scaffold: > node ./scripts/generate-plugin-scaffold.mjs
@bb/templates:generate:plugin-scaffold: 
@bb/process-utils:generate:profile-worker: cache hit, replaying logs ca91093512378b09
@bb/process-utils:generate:profile-worker: 
@bb/process-utils:generate:profile-worker: > @bb/process-utils@0.0.1 generate:profile-worker <checkout-A>/packages/process-utils
@bb/process-utils:generate:profile-worker: > node scripts/generate-profile-worker.mjs
@bb/process-utils:generate:profile-worker: 
@bb/plugin-build:generate: cache hit, replaying logs 12802639368e6661
@bb/plugin-build:generate: 
@bb/plugin-build:generate: > @bb/plugin-build@0.0.1 generate <checkout-A>/packages/plugin-build
@bb/plugin-build:generate: > node ./scripts/generate-plugin-theme.mjs && node ./scripts/generate-runtime-export-manifest.mjs
@bb/plugin-build:generate: 
@bb/plugin-build:generate: plugin-theme.generated.ts up to date
@bb/plugin-build:generate: wrote <checkout-A>/packages/plugin-build/src/generated/runtime-export-manifest.generated.ts (react@19.2.4)
//:ensure-native-modules: 
//:ensure-native-modules: > bb@ ensure-native-modules <checkout-B>
//:ensure-native-modules: > node scripts/ensure-native-modules.mjs
//:ensure-native-modules: 
@bb/app:test: cache miss, executing c462475d4695a757
@bb/app:test: 
@bb/app:test: > @bb/app@0.0.1 test <checkout-B>/apps/app
@bb/app:test: > node scripts/generate-pwa-icons.mjs --check && vitest run --config vitest.config.ts "src/lib/issue-5836.test.tsx" "--silent=false"
@bb/app:test: 
@bb/app:test: 
@bb/app:test:  RUN  v4.1.1 <checkout-B>/apps/app
@bb/app:test: 
@bb/app:test: stdout | src/lib/issue-5836.test.tsx > allows a host React insertion with a pending plugin mount
@bb/app:test: {"state":"pending","presentWhilePending":false,"refused":1,"warningCount":1}
@bb/app:test: 
@bb/app:test: stdout | src/lib/issue-5836.test.tsx > allows a host React insertion with a settled plugin mount
@bb/app:test: {"state":"settled","presentWhilePending":true,"refused":0,"warningCount":0}
@bb/app:test: 
@bb/app:test:  ❯ |@bb/app:isolated| src/lib/issue-5836.test.tsx (2 tests | 1 failed) 24ms
@bb/app:test:    × allows a host React insertion with a pending plugin mount 21ms
@bb/app:test:    ✓ allows a host React insertion with a settled plugin mount 3ms
@bb/app:test: 
@bb/app:test: ⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯
@bb/app:test: 
@bb/app:test:  FAIL  |@bb/app:isolated| src/lib/issue-5836.test.tsx > allows a host React insertion with a pending plugin mount
@bb/app:test: AssertionError: expected false to be true // Object.is equality
@bb/app:test: 
@bb/app:test: - Expected
@bb/app:test: + Received
@bb/app:test: 
@bb/app:test: - true
@bb/app:test: + false
@bb/app:test: 
@bb/app:test:  ❯ src/lib/issue-5836.test.tsx:35:33
@bb/app:test:      33|     await mount;
@bb/app:test:      34|     console.log(JSON.stringify({ state, presentWhilePending, refused, …
@bb/app:test:      35|     expect(presentWhilePending).toBe(true);
@bb/app:test:        |                                 ^
@bb/app:test:      36|     expect(refused).toBe(0);
@bb/app:test:      37|   } finally {
@bb/app:test: 
@bb/app:test: ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯
@bb/app:test: 
@bb/app:test: 
@bb/app:test:  Test Files  1 failed (1)
@bb/app:test:       Tests  1 failed | 1 passed (2)
@bb/app:test:    Start at  06:20:45
@bb/app:test:    Duration  2.53s (transform 1.60s, setup 1.61s, import 191ms, tests 24ms, environment 540ms)
@bb/app:test: 
@bb/app:test:  ELIFECYCLE  Test failed. See above for more details.
@bb/app#test:  ERROR  command (<checkout-B>/apps/app) /usr/local/bin/pnpm run test src/lib/issue-5836.test.tsx --silent=false exited (1)

 Tasks:    5 successful, 6 total
Cached:    4 cached, 6 total
  Time:    4.348s 
Failed:    @bb/app#test

 ERROR  run failed: command  exited (1)
Existing focused test summary
@bb/app:test: > node scripts/generate-pwa-icons.mjs --check && vitest run --config vitest.config.ts "src/lib/foreign-dom-mutation-guard.test.tsx" "src/lib/plugin-frontend.test.ts" "src/components/plugin/PluginAppOverlays.test.tsx"
@bb/app:test: 
@bb/app:test: 
@bb/app:test:  RUN  v4.1.1 <checkout-B>/apps/app
@bb/app:test: 
@bb/app:test:  ✓ |@bb/app:isolated| src/lib/foreign-dom-mutation-guard.test.tsx (10 tests) 50ms
@bb/app:test:  ✓ |@bb/app:isolated| src/components/plugin/PluginAppOverlays.test.tsx (3 tests) 184ms
@bb/app:test:  ✓ |@bb/app:isolated| src/lib/plugin-frontend.test.ts (8 tests) 9ms
@bb/app:test: 
@bb/app:test:  Test Files  3 passed (3)
@bb/app:test:       Tests  21 passed (21)
@bb/app:test:    Start at  06:17:24
@bb/app:test:    Duration  45.16s (transform 85.99s, setup 7.89s, import 83.07s, tests 243ms, environment 1.48s)
@bb/app:test: 

 Tasks:    6 successful, 6 total
Cached:    0 cached, 6 total
  Time:    47.369s 

The full baseline build's relevant diagnostic:

bb-plugin-github:build: ✘ [ERROR] "@get-bb/plugin-sdk/host" is installed for this plugin but its dist is not built: run the SDK build (<checkout-A>/plugins/github/node_modules/@get-bb/plugin-sdk/dist/host.js is missing); a server entry's "@get-bb/plugin-sdk/host" import is bundled from the plugin's own SDK install (bb serves only the bare "@get-bb/plugin-sdk" at load time), so the plugin needs the built SDK [plugin bb-plugin-sdk-resolution]
 Tasks:    9 successful, 18 total
Failed:    bb-plugin-github#build
git fetch https://github.com/get-bb/bb.git main
git worktree add --detach <checkout-A> origin/main
git worktree add --detach <checkout-B> origin/main
pnpm install --frozen-lockfile --prefer-offline
pnpm exec turbo run build
pnpm exec turbo run test --filter=@bb/app -- src/lib/issue-5836.test.tsx --silent=false
pnpm exec turbo run test --filter=@bb/app -- src/lib/foreign-dom-mutation-guard.test.tsx src/lib/plugin-frontend.test.ts src/components/plugin/PluginAppOverlays.test.tsx
git diff --check

Issue material was handled only as untrusted claims. No issue-provided scripts, plugin files, patches, external links, or linked PR code were executed. The regression was authored from the trusted production path and existing test conventions. Temporary checkout paths in logs are anonymized; no user runtime data was accessed.

> AGENT GENERATED