← reports

#7348 · Session renewal failures are mistaken for browser failures

Bug High Effort: Low plugins GitHub issue · November 10, 2026 · base 7c1353d80729983b86ea1555d18b42407f320406

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

1. TL;DR

Browser Automation updates a session's expiry before and after executing a browser operation. A storage failure during the first update is treated as a browser failure: the server stops the session and, when cleanup persistence succeeds, sends a host close request. A failure only during the final update instead discards the successful execution result. Three fault-injection cases reproduce these outcomes on the trusted main commit, and the same agent repeated them in a second clean checkout. Catching renewal persistence failures locally preserves operation results and session usability without weakening startup or explicit cleanup failures.

2. Claims vs findings

ClaimFindingEvidence
A renewal save failure can stop a healthy session.VerifiedThe before-execution case rejects and makes one host close call despite a host that would succeed.
The final renewal can replace the real execution result.VerifiedThe after-execution case returns a persistence error instead of the host's successful result; no close is sent.
A full disk closes the browser immediately.QualifiedNo disk was filled. With persistent injected write failures, cleanup also fails before the host close call, so the browser may remain running while the server has marked the session stopped. The one-shot failure does close it.
Renewal has no active-record identity guard.Source-only findingThe helper lacks such a guard. No separate inactive-record race was reproduced; the contained fix addresses the demonstrated persistence failure, not speculative lifecycle changes.

3. Environment

4. Minimal reproduction

  1. Clone the trusted repository and detach at the recorded base; install the frozen dependency graph:
    git clone https://github.com/get-bb/bb.git bb-7348
    cd bb-7348
    git checkout --detach 7c1353d80729983b86ea1555d18b42407f320406
    pnpm install --frozen-lockfile --prefer-offline
    pnpm exec turbo run build
    If the initial build lacks SDK runtime outputs, build them with pnpm exec turbo run build --filter=@get-bb/plugin-sdk before retrying the relevant task.
  2. Save the inline regression patch below as regression.patch and apply it to the trusted base:
    git apply /path/to/regression.patch
    pnpm exec turbo run test --filter=bb-plugin-browser-automation -- server.test.ts -t 'renewal persistence'
  3. The table-driven test opens a session successfully, then rejects one renewal write before execution, one after execution, or all writes. It asserts that the successful host result is preserved, no close is sent, and a subsequent operation remains usable.

Expected: all three cases pass, returning { text: "done", images: [], exitCode: 0 } with zero host close calls.

Actual on the unchanged production code: all three fail. The before case sends one close; the after and persistent cases send none but still reject. Verbatim excerpts:

FAIL  |bb-plugin-browser-automation| server.test.ts > server session cleanup > keeps a session usable when renewal persistence fails before execution
-   "closes": 0,
+   "closes": 1,
+     "error": "experimental_PluginRpcCallError: renewal write unavailable",

Test Files  1 failed (1)
Tests  3 failed | 36 skipped (39)

Complete owner-boundary regression patch, including its test code:

diff --git a/plugins/browser-automation/server.test.ts b/plugins/browser-automation/server.test.ts
index 177eb1774e..55beba2dc1 100644
--- a/plugins/browser-automation/server.test.ts
+++ b/plugins/browser-automation/server.test.ts
@@ -553,6 +553,44 @@ describe("server session cleanup", () => {
   const hostCalls = (h: Awaited<ReturnType<typeof setup>>, method: string) =>
     h.worker.mock.calls.filter(([call]) => call.method === method);
 
+  it.each(["before", "after", "both"] as const)(
+    "keeps a session usable when renewal persistence fails %s execution",
+    async (failureAt) => {
+      const h = await setup();
+      const persist = vi.spyOn(h.bb.storage.kv, "set");
+      try {
+        const session = await openLocal(h);
+        const storageError = new Error("renewal write unavailable");
+        if (failureAt === "before") persist.mockRejectedValueOnce(storageError);
+        if (failureAt === "both") persist.mockRejectedValue(storageError);
+        if (failureAt === "after")
+          h.worker.mockImplementationOnce(async () => {
+            persist.mockRejectedValueOnce(storageError);
+            return { text: "done", images: [], exitCode: 0 };
+          });
+        const input = { ...ownedBy(session.id), script: "1" };
+        const outcome = await h.harness.behavior.callRpc("run", input).then(
+          (result) => ({ result }),
+          (error: unknown) => ({ error: String(error) }),
+        );
+        expect({ outcome, closes: hostCalls(h, "close").length }).toEqual({
+          outcome: { result: { text: "done", images: [], exitCode: 0 } },
+          closes: 0,
+        });
+        persist.mockRestore();
+        await expect(h.harness.behavior.callRpc("run", input)).resolves.toEqual({
+          text: "done",
+          images: [],
+          exitCode: 0,
+        });
+        expect((await listed(h, session.id))?.state).toBe("ready");
+      } finally {
+        persist.mockRestore();
+        await h.harness.lifecycle.dispose();
+      }
+    },
+  );
+
   it("renews real operations beyond 30 minutes and closes after 30 minutes idle", async () => {
     vi.useFakeTimers();
     const h = await setup();

5. Root cause

Renewal persistence rejects inside the browser execution error boundary, triggering session cleanup; a second renewal in finally can replace a successful result. The renewal helper updates in-memory timestamps, then directly awaits the save. The execution try/catch/finally puts the first renewal inside the same error boundary as the host operation and the second renewal in an unguarded finally block.

try {
  await touch(record);
  const result = await host.call(...);
  return result;
} catch (error) {
  await finish(record, "stopped").catch(() => {});
  throw error;
} finally {
  ...
  if (current?.session.state === "ready") await touch(current);
}

Cleanup marks the record stopped and saves before asking the host to close. Consequently, one-shot renewal failure can close the healthy browser, while a persistent outage can stop the server's session without reaching the host. These are different failure shapes, not evidence that the browser itself failed. Startup and explicit close writes remain intentionally outside the best-effort renewal behavior.

6. Proposed fix

Keep updating the in-memory activity deadline, but catch and warn on persistence failure within renewal itself. Let genuine host execution and cleanup errors follow their existing paths. This is a server-internal change: no public contract, wire field, database schema, dependency, permission boundary, or persisted record format changes. A failed renewal may leave an older persisted expiry until the next successful save; the live record remains authoritative during the current process.

The implemented patch changes two files and 48 text lines total (47 additions, one deletion). Three focused cases pass after the repair; the plugin's complete existing suite and regressions pass: eight files, 105 tests. Turbo lint and typecheck also pass.

7. Verification

The same agent created a second fresh detached worktree at 7c1353d80729983b86ea1555d18b42407f320406 in a new temporary directory, performed a separate frozen install and build, and applied only the authored test patch. Production server.ts remained byte-identical to the trusted base. The same Turbo reproduction command again failed all three cases for the same assertion reasons. This is a repeated clean-checkout check by the same agent, not an independent reviewer.

No ports or durable data were needed. The report qualifies the full-disk claim and leaves the inactive-record race unverified rather than claiming a browser integration reproduction. Verbatim second-run summary:

Test Files  1 failed (1)
Tests  3 failed | 36 skipped (39)

8. Related issues and pull requests

No open pull request linked to #7348 was found in the issue timeline or an open-PR search before the fix. Nearby browser-plugin reports were checked for classification conventions; none was evidence for this persistence failure.

9. Appendix

Raw logs remain in local evidence storage, not in this public repository. The inline patch above and these exact result summaries provide the repeatable public evidence.

Focused post-fix run:
Test Files  1 passed (1)
Tests  3 passed | 36 skipped (39)

Full plugin validation:
Test Files  8 passed (8)
Tests  105 passed (105)
Tasks:    10 successful, 10 total
pnpm exec oxfmt plugins/browser-automation/server.ts plugins/browser-automation/server.test.ts
pnpm exec turbo run test --filter=bb-plugin-browser-automation -- server.test.ts -t 'renewal persistence'
pnpm exec turbo run test lint typecheck --filter=bb-plugin-browser-automation
git diff --check
git diff --numstat origin/main

Issue content was treated as untrusted claims. No issue-provided code, patch, script, linked branch, or external link was executed. The regression was authored from the trusted server implementation and its existing SDK test harness. Log checkout paths are redacted; no credentials or runtime data are included.