From 7fe1f810a2202d52bc63bd7fc83055aa5dade974 Mon Sep 17 00:00:00 2001
From: Luke Parker <10430890+Hona@users.noreply.github.com>
Date: Tue, 17 Nov 2026 09:24:27 +1000
Subject: [PATCH] fix(browser): distinguish unattached inventory from
unexecuted actions
---
packages/core/test/browser-permission.test.ts | 2 +-
packages/core/test/browser-tools.test.ts | 5 +++--
packages/plugin-browser/src/tools.ts | 7 +++++--
3 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/packages/core/test/browser-permission.test.ts b/packages/core/test/browser-permission.test.ts
index ca7e6518591..121b6cd2709 100644
--- a/packages/core/test/browser-permission.test.ts
+++ b/packages/core/test/browser-permission.test.ts
@@ -427,7 +427,7 @@ it.live("without a deny, a session with no desktop hears that it is disconnected
const status = (yield* browser.call("build", detached.id)).output
expect(status).toMatchObject({ connected: false, message: expect.stringContaining("retry only after it attaches") })
for (const [op, input] of [["preview", { path: "page.html" }], ["preview", { path: "missing.html" }], ["wait", { tabID: tab.id, selector: "#done" }], ["snapshot", { tabID: missingTab }]] as const)
- expect((yield* browser.run(op, input, "build", detached.id)).output).toEqual(status)
+ expect((yield* browser.run(op, input, "build", detached.id).pipe(Effect.flip)).message).toStartWith("[browser.not_attached]")
expect(browser.commands.count).toBe(0)
}),
)
diff --git a/packages/core/test/browser-tools.test.ts b/packages/core/test/browser-tools.test.ts
index 34719072df9..090ab902868 100644
--- a/packages/core/test/browser-tools.test.ts
+++ b/packages/core/test/browser-tools.test.ts
@@ -293,7 +293,7 @@ it.live("HTML preview passes the checked relative path and requires a usable tab
}),
)
-it.live("preview fails for a missing file, and returns attachment status without a desktop", () =>
+it.live("preview fails for a missing file; an unattached inventory stays iterable and actions do not report success", () =>
Effect.gen(function* () {
const browser = yield* setup((action) => success(action.type === "preview" ? { path: action.path } : tab))
yield* Effect.promise(() => Bun.write(join(browser.directory, "chart.svg"), ""))
@@ -307,6 +307,7 @@ it.live("preview fails for a missing file, and returns attachment status without
const detached = yield* setup(() => success(tab), { attach: false })
yield* Effect.promise(() => Bun.write(join(detached.directory, "chart.svg"), ""))
- expect(JSON.parse(yield* detached.run(`return await tools.browser.preview({ path: "chart.svg" })`))).toMatchObject({ connected: false })
+ expect(JSON.parse(yield* detached.run(`const s = await tools.browser.tabs.list({}); return { ...s, tabs: s.tabs.map(t => t.id) }`))).toMatchObject({ connected: false, tabs: [], focusedTabID: null })
+ expect(yield* detached.run(`try { await tools.browser.click({ tabID: "${tabID}", ref: "e1" }); return "Done" } catch (error) { return error.message }`)).toStartWith("[browser.not_attached]")
}),
)
diff --git a/packages/plugin-browser/src/tools.ts b/packages/plugin-browser/src/tools.ts
index f99dcb31ed3..cbedd03fed8 100644
--- a/packages/plugin-browser/src/tools.ts
+++ b/packages/plugin-browser/src/tools.ts
@@ -146,7 +146,10 @@ export const register = Effect.fn("BrowserTools.register")(function* (
const action = input.type === "wait" ? { ...input, plan: yield* parse(() => waitPlan(input)) } : yield* parse(() => normalizeAction(input))
const paths = "paths" in action ? action.paths.map((path) => BrowserFiles.uploadPath(ctx.location.directory, path)) : undefined
const approved = yield* connection.authorize(tool, action, paths ?? (action.type === "preview" ? [action.path] : undefined))
- if (approved.connected === false) return { output: approved, content: [{ type: "text" as const, text: approved.message }] }
+ if (approved.connected === false) {
+ if (action.type === "tabs.list") return { output: { ...approved, tabs: [], focusedTabID: null }, content: [{ type: "text" as const, text: approved.message }] }
+ return yield* new Tool.Error({ metadata: { code: "not_attached" }, message: `[browser.not_attached] ${approved.message}` })
+ }
if (action.type === "wait") return yield* wait(action.tabID, action.plan, tool, approved)
if (action.type === "preview" && ctx.location.workspaceID) return yield* new Tool.Error({ message: "Browser preview requires a server-local workspace." })
const checked = action.type === "preview" ? { ...action, path: yield* previewable(action.path, tool) } : action
@@ -182,7 +185,7 @@ export const register = Effect.fn("BrowserTools.register")(function* (
name: operation.name.slice(separator + 1),
description: operation.description,
input: operation.input,
- output: Schema.Union([operation.output, Schema.Struct({ connected: Schema.Literal(false), message: Schema.String })]),
+ output: operation.name === "tabs.list" ? Schema.Struct({ ...Browser.State.fields, connected: Schema.optional(Schema.Literal(false)), message: Schema.optional(Schema.String) }) : operation.output,
options: {
namespace: separator < 0 ? "browser" : `browser.${operation.name.slice(0, separator)}`,
permission: "browser",