From 22ec577d8077a94e1888abfdd4e6bba63afc1d3d Mon Sep 17 00:00:00 2001 From: pandego <7780875+pandego@users.noreply.github.com> Date: Sun, 1 Mar 2026 14:14:54 +0100 Subject: [PATCH] fix(browser): require managed runtime ownership for tab cap cleanup --- src/browser/server-context.remote-tab-ops.test.ts | 15 +++++++++++++++ src/browser/server-context.ts | 8 +++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/browser/server-context.remote-tab-ops.test.ts b/src/browser/server-context.remote-tab-ops.test.ts index 47531b14e75..509c3e7a3c2 100644 --- a/src/browser/server-context.remote-tab-ops.test.ts +++ b/src/browser/server-context.remote-tab-ops.test.ts @@ -476,6 +476,11 @@ describe("browser server-context tab selection state", () => { global.fetch = withFetchPreconnect(fetchMock); const state = makeState("openclaw"); + (state.profiles as Map).set("openclaw", { + profile: { name: "openclaw" }, + running: { pid: 1234, proc: { on: vi.fn() } }, + lastTargetId: null, + }); const ctx = createBrowserRouteContext({ getState: () => state }); const openclaw = ctx.forProfile("openclaw"); @@ -516,6 +521,11 @@ describe("browser server-context tab selection state", () => { global.fetch = withFetchPreconnect(fetchMock); const state = makeState("openclaw"); + (state.profiles as Map).set("openclaw", { + profile: { name: "openclaw" }, + running: { pid: 1234, proc: { on: vi.fn() } }, + lastTargetId: null, + }); const ctx = createBrowserRouteContext({ getState: () => state }); const openclaw = ctx.forProfile("openclaw"); @@ -699,6 +709,11 @@ describe("browser server-context tab selection state", () => { global.fetch = withFetchPreconnect(fetchMock); const state = makeState("openclaw"); + (state.profiles as Map).set("openclaw", { + profile: { name: "openclaw" }, + running: { pid: 1234, proc: { on: vi.fn() } }, + lastTargetId: null, + }); const ctx = createBrowserRouteContext({ getState: () => state }); const openclaw = ctx.forProfile("openclaw"); diff --git a/src/browser/server-context.ts b/src/browser/server-context.ts index cf576c0ca16..0da19af4f28 100644 --- a/src/browser/server-context.ts +++ b/src/browser/server-context.ts @@ -139,7 +139,13 @@ function createProfileContext( }; const enforceManagedTabLimit = async (keepTargetId: string): Promise => { - if (profile.driver !== "openclaw" || !profile.cdpIsLoopback || state().resolved.attachOnly) { + const profileState = getProfileState(); + if ( + profile.driver !== "openclaw" || + !profile.cdpIsLoopback || + state().resolved.attachOnly || + !profileState.running + ) { return; }