Open-source AI coworkers that each get a computer of their own: a browser, files and tools, with every action decided before it happens and recorded after. Bring any AG-UI agent.
Stop grant queries polling the placeholder Bot (#240)
anygivenfriday615a04123745
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 9acfaa3f..bf9f33e3 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -266,6 +266,20 @@ given them. It is optional, so a deployment with no proxy is unchanged, and gitiproxy URL can carry a password.**Move these two out of `.env` and into `egress.env`.** In `.env` they reach no process.+### Screens without a conversation stop polling for a Bot that does not exist++Every surface asks which components its Bot holds, and asks again every few seconds so a revoked+grant leaves an open conversation quickly. The Bot it asked about was whichever one the surface+declared — and on a screen with no conversation at all, that was the placeholder id the routing+holder falls back to, which no package registers and the server answers 404 for. An admin page left+open polled a guaranteed miss every five seconds, indefinitely.++Nothing looked wrong. The screen rendered, because an absent grant list and an empty one draw the+same. The cost was the noise: a request log where the same 404 repeats forever is one where the 404+that matters is invisible.++The grant queries now wait for a surface to declare a real Bot, and simply do not run while the+placeholder holds. Conversation surfaces — the Bot page, channels — declare one and are unchanged.### Knowledge searches instead of guessingdiff --git a/app/src/lib/copilot/active-bot.tsx b/app/src/lib/copilot/active-bot.tsxindex b66da3aa..dfb8dda2 100644--- a/app/src/lib/copilot/active-bot.tsx+++ b/app/src/lib/copilot/active-bot.tsx@@ -73,3 +73,24 @@ export function useActiveBotHolder(): BotHolder {export function useActiveBotId(): string {return useContext(ActiveBotValueContext)?.botId ?? DEFAULT_BOT_ID;}++/**+ * The active Bot when a surface has declared one, and undefined while the placeholder holds.+ *+ * The placeholder exists so a handler always has something to route with, but it is not a Bot: no+ * package registers an agent by that name, and the server answers 404 for it. A grant query handed+ * the placeholder therefore polls a guaranteed miss on its own interval — every few seconds, on+ * every screen without a conversation — and the constant failing request is noise that would bury a+ * real 404 the day one matters. A query given undefined instead simply does not run.+ *+ * The name is already reserved in practice: an agents.yaml entry called "default" would be+ * indistinguishable from the placeholder in every handler that reads the holder.+ */+export function declaredBotId(botId: string): string | undefined {+ return botId === DEFAULT_BOT_ID ? undefined : botId;+}++/** As useActiveBotId, for callers that should do nothing while the placeholder holds. */+export function useDeclaredBotId(): string | undefined {+ return declaredBotId(useActiveBotId());+}diff --git a/app/src/lib/copilot/gallery-tools.tsx b/app/src/lib/copilot/gallery-tools.tsxindex 26b39a2a..b421df73 100644--- a/app/src/lib/copilot/gallery-tools.tsx+++ b/app/src/lib/copilot/gallery-tools.tsx@@ -9,7 +9,7 @@ import {decideComponent,type GrantedComponent,} from "@/lib/components/queries";-import { useActiveBotId } from "@/lib/copilot/active-bot";+import { useActiveBotId, useDeclaredBotId } from "@/lib/copilot/active-bot";import {GALLERY_COMPONENTS,type GalleryComponent,@@ -32,7 +32,10 @@ export function GalleryTools() {// Active Bot comes from the route/channel surface currently driving the provider.const grantsFor = useActiveBotId();- const { data: granted } = useQuery(agentComponentsQueryOptions(grantsFor));+ // See sandboxed-tools: the placeholder Bot is not fetchable, so the grant query waits for a+ // surface to declare a real one.+ const declared = useDeclaredBotId();+ const { data: granted } = useQuery(agentComponentsQueryOptions(declared));const held = useMemo(() =>new Map(diff --git a/app/src/lib/copilot/sandboxed-tools.tsx b/app/src/lib/copilot/sandboxed-tools.tsxindex 5b570c01..f69aa43f 100644--- a/app/src/lib/copilot/sandboxed-tools.tsx+++ b/app/src/lib/copilot/sandboxed-tools.tsx@@ -12,7 +12,7 @@ import {decideComponent,type GrantedComponent,} from "@/lib/components/queries";-import { useActiveBotId } from "@/lib/copilot/active-bot";+import { useActiveBotId, useDeclaredBotId } from "@/lib/copilot/active-bot";import {type PublishedSandboxed,publishedSandboxedQueryOptions,@@ -24,8 +24,11 @@ import {*/export function SandboxedTools() {const botId = useActiveBotId();+ // Grants are fetched only once a surface has declared its Bot; the placeholder is not one the+ // server knows, and asking would 404 on every poll.+ const declared = useDeclaredBotId();const { data: published } = useQuery(publishedSandboxedQueryOptions());- const { data: granted } = useQuery(agentComponentsQueryOptions(botId));+ const { data: granted } = useQuery(agentComponentsQueryOptions(declared));const held = new Map((granted ?? []).map((component: GrantedComponent) => [diff --git a/app/tests/declared-bot.test.ts b/app/tests/declared-bot.test.tsnew file mode 100644index 00000000..5b7b2244--- /dev/null+++ b/app/tests/declared-bot.test.ts@@ -0,0 +1,21 @@+import { describe, expect, test } from "bun:test";+import { declaredBotId } from "../src/lib/copilot/active-bot";++/**+ * The placeholder Bot id is a routing convenience, not a Bot. Anything that would ask the server+ * about it must be told there is nothing to ask about.+ */++describe("declaredBotId", () => {+ test("returns undefined for the placeholder", () => {+ expect(declaredBotId("default")).toBeUndefined();+ });++ test("passes a declared Bot through", () => {+ expect(declaredBotId("general-assistant")).toBe("general-assistant");+ });++ test("passes a Bot through even when the placeholder is its prefix", () => {+ expect(declaredBotId("default-2")).toBe("default-2");+ });+});