Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(antigravity): name a connector whose tool list is not known yet in the left-out line

luishron123d863a4b5e1d4
diff --git a/server/drivers/antigravity-coordination-tools.test.ts b/server/drivers/antigravity-coordination-tools.test.ts
index 6badc13bba..96349cc44d 100644
--- a/server/drivers/antigravity-coordination-tools.test.ts
+++ b/server/drivers/antigravity-coordination-tools.test.ts
@@ -125,12 +125,14 @@ describe("a native Antigravity CLI thread over the session's tool budget", () =>
const note = () => (JSON.parse(readFileSync(`${dump}.prompt.json`, "utf8")) as Array<{ text?: string }>)
.map((block) => block.text ?? "").find((text) => text.startsWith("[Tools left out]"));
// `relaysAnswered` false: the turn was set up before any relay had answered and recorded its list, as only this fake
- // allows (the CLI lists every server's tools on session setup, before the prompt), so it can name only OpenMausBot's own.
+ // allows (the CLI lists every server's tools on session setup, before the prompt), so it can name only OpenMausBot's own
+ // and must say which relays it could not size and that the list may be incomplete.
+ const OWN = ["agents", "browser", "data"];
const check = (sent: Sent[], relaysAnswered = true) => {
expect(sent.map((server) => server.name).sort()).toEqual(Object.keys(LISTS).sort());
const lists = shown(sent);
// The turn names what the lists left out, server by server, so the bot knows what it cannot call.
- const left = Object.entries(LISTS).filter(([server]) => relaysAnswered || ["agents", "browser", "data"].includes(server)).flatMap(([server, tools]) => {
+ const left = Object.entries(LISTS).filter(([server]) => relaysAnswered || OWN.includes(server)).flatMap(([server, tools]) => {
const kept = new Set(lists[server]!.map((tool) => tool.name));
return tools.filter((tool) => !kept.has(tool.name)).map((tool) => `${server}/${tool.name}`);
});
@@ -140,13 +142,15 @@ describe("a native Antigravity CLI thread over the session's tool budget", () =>
expect(named).toMatch(new RegExp(`(?:: |; )${server}: (?:[^;]*, )?${name}(?:[,;.]|$)`));
}
if (relaysAnswered && !left.length) expect(note()).toBeUndefined();
+ const unsure = /This list may be incomplete: ([^.]*?) ha(?:s|ve) not reported/.exec(named)?.[1]?.split(", ") ?? [];
+ expect(unsure.sort()).toEqual(relaysAnswered ? [] : Object.keys(LISTS).filter((server) => !OWN.includes(server)).sort());
for (const name of COORDINATION_TOOLS) expect(named).not.toMatch(new RegExp(`\\b${name}\\b`));
for (const name of COORDINATION_TOOLS) expect(lists.agents!.map((tool) => tool.name)).toContain(name);
// Counted as the CLI counts them, each tool by its own name.
const all = Object.values(lists).flat();
expect(definitionListBytes(all)).toBeLessThanOrEqual(ANTIGRAVITY_CLI_TOOL_LIMIT);
expect(cliDrops(all, ANTIGRAVITY_CLI_TOOL_LIMIT)).toEqual([]);
- return lists;
+ return { lists, left, named };
};
// session/new: nothing recorded yet, so the person's servers are sized by a reserve.
@@ -169,11 +173,16 @@ describe("a native Antigravity CLI thread over the session's tool budget", () =>
expect(setups().filter((method) => method !== "session/set_model")).toEqual(["session/new", "session/resume"]);
const resumed = sentNow();
expect(Number(envOf(resumed.find((server) => server.name === "shop")!)[TOOL_LIST_SHARE_ENV])).toBeGreaterThan(0);
- const lists = check(resumed);
+ const { lists, left, named } = check(resumed);
+ // Over the budget: the resumed session leaves tools out and names each of them.
+ expect(left.length).toBeGreaterThan(0);
- // A third turn in the resumed live session: no new setup, the same lists.
+ // A third turn in the resumed live session: no new setup, the same lists, and the same tools named as left out.
await turn("third", { resumeCursor: sessionId });
expect(setups().filter((method) => method !== "session/set_model")).toEqual(["session/new", "session/resume"]);
expect(shown(sentNow())).toEqual(lists);
+ const third = check(sentNow());
+ expect(third.left).toEqual(left);
+ expect(third.named).toBe(named);
}, 120_000);
});
diff --git a/server/drivers/session-tool-budget.test.ts b/server/drivers/session-tool-budget.test.ts
index c286d52bf9..a4267355ba 100644
--- a/server/drivers/session-tool-budget.test.ts
+++ b/server/drivers/session-tool-budget.test.ts
@@ -24,7 +24,7 @@ import { agentsToolList } from "./agents-mcp.ts";
import { antigravityCliTakesHttpMcp, antigravityCliToolBudget } from "./antigravity-acp.ts";
import { acpSessionMcpServers } from "./own-mcp-http.ts";
import { withSessionToolShares } from "./own-mcp-session-budget.ts";
-import { SESSION_TOOL_BUDGET_ENV, UNKNOWN_LIST_RESERVE, withSessionToolBudget } from "./session-tool-budget.ts";
+import { leftOutToolsNote, SESSION_TOOL_BUDGET_ENV, UNKNOWN_LIST_RESERVE, withSessionToolBudget } from "./session-tool-budget.ts";
import { acpMcpServers, type AcpMcpServer } from "./turn-mcp.ts";
import type { SendTurnInput } from "../contracts.ts";
@@ -201,3 +201,16 @@ describe("the session's tool budget over every server", () => {
expect(["agents", "browser", "data", "composio"].reduce((sum, name) => sum + share(name), 0)).toBeLessThanOrEqual(ANTIGRAVITY_CLI_TOOL_BUDGET);
});
});
+
+describe("the line naming what a session leaves out", () => {
+ it("names each tool left out, and each relay whose list is not known yet as a gap in the line", () => {
+ expect(leftOutToolsNote([])).toBeUndefined();
+ expect(leftOutToolsNote([{ server: "data", tools: [] }])).toBeUndefined();
+ const both = leftOutToolsNote([{ server: "data", tools: ["data_export", "data_show"] }, { server: "composio", tools: [], unknown: true }])!;
+ expect(both).toMatch(/^\[Tools left out\] .*does not list: data: data_export, data_show\. They cannot be called here\. /);
+ expect(both).toContain("This list may be incomplete: composio has not reported its tools yet");
+ const only = leftOutToolsNote([{ server: "composio", tools: [], unknown: true }, { server: "shop", tools: [], unknown: true }])!;
+ expect(only).not.toContain("does not list");
+ expect(only).toContain("This list may be incomplete: composio, shop have not reported their tools yet");
+ });
+});
diff --git a/server/drivers/session-tool-budget.ts b/server/drivers/session-tool-budget.ts
index 8762e3faf1..a5bad17034 100644
--- a/server/drivers/session-tool-budget.ts
+++ b/server/drivers/session-tool-budget.ts
@@ -38,15 +38,17 @@ export interface SessionBudgetOptions {
leftOut?: (left: () => LeftOutTools[]) => void;
}
-/** The tools one server of a session leaves out of its list to fit its share. */
-export interface LeftOutTools { server: string; tools: string[] }
+/** The tools one server of a session leaves out of its list to fit its share. `unknown`: a relay that has not answered
+ * and recorded its list yet, so what it leaves out cannot be named. */
+export interface LeftOutTools { server: string; tools: string[]; unknown?: true }
/** What `lists` leave out under `shares`, by server, as each list's own fit chooses (fitToolListWithinShare). */
export function leftOutTools(lists: ReadonlyArray<{ server: string; tools: readonly ListedTool[] | number; share: number | undefined; record?: string }>): LeftOutTools[] {
return lists.flatMap(({ server, tools: planned, share, record }) => {
// A relay set aside a reserve is sized by the list it recorded since, once it has answered.
const tools = typeof planned === "number" && record ? readRecordedToolList(record) ?? planned : planned;
- if (typeof tools === "number" || share === undefined) return [];
+ if (share === undefined) return [];
+ if (typeof tools === "number") return record ? [{ server, tools: [], unknown: true as const }] : [];
const { left } = fitToolListWithinShare(tools, share);
return left.length ? [{ server, tools: left }] : [];
});
@@ -54,9 +56,16 @@ export function leftOutTools(lists: ReadonlyArray<{ server: string; tools: reado
/** The line a turn carries while its session's lists leave tools out, so the bot knows what it cannot call and why. */
export function leftOutToolsNote(left: readonly LeftOutTools[]): string | undefined {
- if (!left.length) return undefined;
- return `[Tools left out] To fit this engine's limit on tool definitions, this session does not list: ${left.map(({ server, tools }) => `${server}: ${tools.join(", ")}`).join("; ")}. `
- + "They cannot be called here. If the task needs one, tell the person which, and that turning off a server this bot does not need brings it back.";
+ const named = left.filter((entry) => !entry.unknown && entry.tools.length);
+ const unknown = left.filter((entry) => entry.unknown).map((entry) => entry.server);
+ if (!named.length && !unknown.length) return undefined;
+ const listed = named.length
+ ? `To fit this engine's limit on tool definitions, this session does not list: ${named.map(({ server, tools }) => `${server}: ${tools.join(", ")}`).join("; ")}. They cannot be called here. `
+ : "";
+ const unsure = unknown.length
+ ? `This list may be incomplete: ${unknown.join(", ")} ${unknown.length === 1 ? "has" : "have"} not reported ${unknown.length === 1 ? "its" : "their"} tools yet, so any ${unknown.length === 1 ? "it leaves" : "they leave"} out to fit the limit cannot be named here. `
+ : "";
+ return `[Tools left out] ${listed}${unsure}If the task needs a tool that is missing, tell the person which, and that turning off a server this bot does not need brings it back.`;
}
export function toolListRecordPath(recordsDir: string, botId: string, server: string): string {