Skip to content

Commit 318d3e7

Browse files
only21milclaude
andcommitted
fix(pi): keep orchestration tools after tree restores on lean gateways
With eager gateway tools turned off, a session_tree restore to a loadout without T3 tools left orchestrator_capabilities, delegate_task and task_status undeclared until the branch called them. Always re-add the orchestration tools and keep only optional tools subject to call history. Note that the switch needs Pi 0.99, since older Pi has no tool exposure. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 63a414b commit 318d3e7

4 files changed

Lines changed: 20 additions & 9 deletions

File tree

‎docs/user/providers-pi.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ gateways** in the Pi instance's settings to send smaller requests. Pi then decla
3030
tools, `tool_search`, the T3 Code tools `tool_search` loaded, and any T3 Code tool the conversation
3131
has already called. An existing thread keeps every tool it already loaded, including the full set
3232
loaded before you turned the switch off, so the smaller requests apply to new threads and to tools
33-
not yet loaded.
33+
not yet loaded. The switch needs Pi 0.99 or newer; older Pi versions always declare every T3 Code
34+
tool.
3435

3536
On a remote or headless server, connect to that machine over SSH and run `pi`, then `/login`.
3637
Open the authorization URL on your own computer. If the callback cannot reach the server,

‎packages/provider-pi/src/server/mcpExtensionSource.test.ts‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ describe("Pi MCP tool exposure", () => {
200200
assert.include(bridge.getActiveTools(), "mcp__t3-code__preview_snapshot");
201201
});
202202

203-
it("declares only called T3 tools for gateways that opt out of eager schemas", async () => {
203+
it("declares orchestration and called T3 tools for gateways that opt out of eager schemas", async () => {
204204
const bridge = await loadMcpBridge({
205205
modern: true,
206206
toolSearchAvailable: true,
@@ -218,7 +218,14 @@ describe("Pi MCP tool exposure", () => {
218218
};
219219
await bridge.handlers.get("session_start")!(event, gatewayContext);
220220
await bridge.handlers.get("before_agent_start")!(event, gatewayContext);
221-
assert.deepEqual(bridge.getActiveTools(), ["read", "tool_search"]);
221+
const orchestrationLoadout = [
222+
"read",
223+
"tool_search",
224+
"mcp__t3-code__orchestrator_capabilities",
225+
"mcp__t3-code__delegate_task",
226+
"mcp__t3-code__task_status",
227+
];
228+
assert.deepEqual(bridge.getActiveTools(), orchestrationLoadout);
222229

223230
messages.push(
224231
{ role: "user", content: [{ type: "text" }] },
@@ -233,15 +240,14 @@ describe("Pi MCP tool exposure", () => {
233240
);
234241
await bridge.handlers.get("model_select")!(event, gatewayContext);
235242
assert.deepEqual(bridge.getActiveTools(), [
236-
"read",
237-
"tool_search",
243+
...orchestrationLoadout,
238244
"mcp__t3-code__preview_snapshot",
239245
]);
246+
// A tree restore can bring back a loadout without the orchestration tools.
240247
bridge.restoreActiveTools(["read"]);
241248
await bridge.handlers.get("session_tree")!(event, gatewayContext);
242249
assert.deepEqual(bridge.getActiveTools(), [
243-
"read",
244-
"tool_search",
250+
...orchestrationLoadout,
245251
"mcp__t3-code__preview_snapshot",
246252
]);
247253
});

‎packages/provider-pi/src/server/mcpExtensionSource.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,12 @@ export default async function t3McpExtension(pi: ExtensionAPI) {
455455
if (ctx.model?.api === "openai-completions") {
456456
gatewayTools = catalog.map((tool) => "mcp__t3-code__" + tool.name);
457457
if (!eagerGatewayTools) {
458+
// A restored loadout can drop the orchestration tools, so re-add
459+
// them whether or not this branch has called them.
458460
const called = calledToolNames(ctx);
459-
gatewayTools = gatewayTools.filter((name) => called.has(name));
461+
gatewayTools = gatewayTools.filter(
462+
(name) => called.has(name) || directTools.has(name.slice("mcp__t3-code__".length)),
463+
);
460464
}
461465
}
462466
const required = [...(hasToolSearch ? ["tool_search"] : []), ...gatewayTools];

‎packages/provider-pi/src/settings.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export const PiSettings = makeProviderSettingsSchema(
3737
Schema.annotateKey({
3838
title: "Load every T3 tool on completion gateways",
3939
description:
40-
"Declare all T3 tool schemas on OpenAI-compatible chat completion requests, for gateways that drop calls to undeclared tools. Turn off if your gateway runs tools found through tool_search. Requests then declare the orchestration tools, tool_search and the T3 tools tool_search loaded or the conversation already called. Existing threads keep tools they already loaded, including eagerly loaded ones, so the reduction applies to new threads and tools not yet loaded.",
40+
"Declare all T3 tool schemas on OpenAI-compatible chat completion requests, for gateways that drop calls to undeclared tools. Turn off if your gateway runs tools found through tool_search. Requests then declare the orchestration tools, tool_search and the T3 tools tool_search loaded or the conversation already called. Existing threads keep tools they already loaded, including eagerly loaded ones, so the reduction applies to new threads and tools not yet loaded. Needs Pi 0.99 or newer; older Pi always declares every T3 tool.",
4141
providerSettingsForm: { control: "switch" },
4242
}),
4343
),

0 commit comments

Comments
 (0)