Skip to content

Commit fb81d03

Browse files
authored
fix(commands): restore tool inventory for dynamic models (#119306)
* fix(qa): scale Telegram compact command timeout * fix(qa): surface Telegram compact reply failures Punchcard-Session: amber-workshop-river-yr * fix(commands): prepare tool inventory model context Punchcard-Session: amber-workshop-river-yr * test(commands): type runtime context mock Punchcard-Session: amber-workshop-river-yr * docs(changelog): note tool inventory repair Punchcard-Session: amber-workshop-river-yr * chore(release): defer tool inventory note Punchcard-Session: amber-workshop-river-yr * fix(ci): lower environment variable budget Punchcard-Session: amber-workshop-river-yr
1 parent 0d18bde commit fb81d03

5 files changed

Lines changed: 93 additions & 4 deletions

File tree

‎config/env-var-count-budget.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Distinct OPENCLAW_* names in production source under src, packages, and extensions.
22
# Ratchet: lower this number when cleanup removes names; never raise it.
3-
515
3+
513

‎extensions/qa-lab/src/live-scenario-timeouts.test.ts‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,40 @@ function runCompletionPolicyFlow(
329329
};
330330
}
331331

332+
describe("live transport scenario timeouts", () => {
333+
it("uses the model-aware timeout for the Telegram compact tools reply", () => {
334+
const scenario = requireFlowScenario(readQaScenarioById("telegram-tools-compact-command"));
335+
const waitForReply = scenario.execution.flow?.steps
336+
.flatMap((step) => step.actions)
337+
.find(
338+
(action) => typeof action === "object" && action !== null && "waitForOutbound" in action,
339+
);
340+
341+
expect(waitForReply).toMatchObject({
342+
waitForOutbound: {
343+
timeoutMs: { expr: "liveTurnTimeoutMs(env, 60000)" },
344+
},
345+
});
346+
expect(waitForReply).not.toHaveProperty("waitForOutbound.textIncludes");
347+
});
348+
349+
it("reports the unexpected Telegram compact tools reply", async () => {
350+
await expect(
351+
runLoadedScenarioFlow("telegram-tools-compact-command", {
352+
onWaitForOutboundMessage: ({ state }) => {
353+
state.addOutboundMessage({
354+
accountId: "qa-channel",
355+
to: "channel:telegram-command-room",
356+
text: "Couldn't load available tools right now. Try again in a moment.",
357+
});
358+
},
359+
}),
360+
).rejects.toThrow(
361+
"tools reply missing expected text: Couldn't load available tools right now. Try again in a moment.",
362+
);
363+
});
364+
});
365+
332366
describe("live subagent scenario timeouts", () => {
333367
it.each([
334368
{

‎qa/scenarios/channels/telegram-tools-compact-command.yaml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ flow:
3838
- waitForOutbound:
3939
conversation: { id: telegram-command-room, kind: channel }
4040
sinceIndex: { ref: startIndex }
41-
textIncludes: exec
42-
timeoutMs: 60000
41+
timeoutMs:
42+
expr: liveTurnTimeoutMs(env, 60000)
4343
- call: sleep
4444
args: [1000]
4545
- set: joinedReply

‎src/auto-reply/reply/commands-info.test.ts‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,7 @@ const toolsTestState = vi.hoisted(() => {
564564
return {
565565
resolveToolsImpl: defaultResolveTools,
566566
resolveToolsMock: vi.fn((..._args: unknown[]) => defaultResolveTools()),
567+
resolveRuntimeModelContextMock: vi.fn(async (_params: unknown) => ({})),
567568
threadingContext: {
568569
currentChannelId: "channel-123",
569570
currentMessageId: "message-456",
@@ -574,6 +575,8 @@ const toolsTestState = vi.hoisted(() => {
574575

575576
vi.mock("../../agents/tools-effective-inventory.js", () => ({
576577
resolveEffectiveToolInventory: (...args: unknown[]) => toolsTestState.resolveToolsMock(...args),
578+
resolveEffectiveToolInventoryRuntimeModelContextAsync: (params: unknown) =>
579+
toolsTestState.resolveRuntimeModelContextMock(params),
577580
}));
578581

579582
vi.mock("./agent-runner-utils.js", () => ({
@@ -626,6 +629,8 @@ describe("handleToolsCommand", () => {
626629
vi.mocked(resolveSessionAgentId).mockReturnValue("main");
627630
toolsTestState.resolveToolsMock.mockReset();
628631
toolsTestState.resolveToolsImpl = () => makeDefaultInventory();
632+
toolsTestState.resolveRuntimeModelContextMock.mockReset();
633+
toolsTestState.resolveRuntimeModelContextMock.mockResolvedValue({});
629634
setActivePluginRegistry(createTestRegistry([]));
630635
});
631636

@@ -777,6 +782,43 @@ describe("handleToolsCommand", () => {
777782
expect(result?.reply?.text).toContain("Use /tools verbose for descriptions.");
778783
});
779784

785+
it("prepares dynamic model context before resolving the tool inventory", async () => {
786+
const runtimeModel = {
787+
id: "chat-latest",
788+
name: "chat-latest",
789+
provider: "openai",
790+
api: "openai-responses",
791+
};
792+
toolsTestState.resolveRuntimeModelContextMock.mockResolvedValue({
793+
modelApi: "openai-responses",
794+
runtimeModel,
795+
});
796+
const { buildCommandTestParamsLocal, handleToolsCommandLocal, resolveToolsMock } =
797+
await loadToolsHarness();
798+
const params = buildCommandTestParamsLocal("/tools compact", buildConfig(), undefined, {
799+
workspaceDir: "/tmp",
800+
});
801+
params.agentId = "main";
802+
params.provider = "openai";
803+
params.model = "chat-latest";
804+
805+
const result = await handleToolsCommandLocal(params, true);
806+
807+
expect(result?.reply?.text).toContain("exec");
808+
expect(toolsTestState.resolveRuntimeModelContextMock).toHaveBeenCalledWith({
809+
cfg: params.cfg,
810+
agentId: "main",
811+
agentDir: undefined,
812+
workspaceDir: "/tmp",
813+
modelProvider: "openai",
814+
modelId: "chat-latest",
815+
});
816+
expect(resolveToolsArg(resolveToolsMock)).toMatchObject({
817+
modelApi: "openai-responses",
818+
runtimeModel,
819+
});
820+
});
821+
780822
it("ignores unauthorized senders", async () => {
781823
const { buildCommandTestParamsLocal, handleToolsCommandLocal } = await loadToolsHarness();
782824
const params = buildCommandTestParamsLocal("/tools", buildConfig(), undefined, {

‎src/auto-reply/reply/commands-info.ts‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
/** Handles informational commands such as /help, /commands, /tools, and exports. */
22
import { resolveSessionAgentId } from "../../agents/agent-scope.js";
3-
import { resolveEffectiveToolInventory } from "../../agents/tools-effective-inventory.js";
3+
import {
4+
resolveEffectiveToolInventory,
5+
resolveEffectiveToolInventoryRuntimeModelContextAsync,
6+
} from "../../agents/tools-effective-inventory.js";
47
import { getChannelPlugin } from "../../channels/plugins/index.js";
58
import {
69
listSkillCommandsForAgents,
@@ -170,6 +173,14 @@ export const handleToolsCommand: CommandHandler = async (params, allowTextComman
170173
config: params.cfg,
171174
hasRepliedRef: undefined,
172175
});
176+
const runtimeModelContext = await resolveEffectiveToolInventoryRuntimeModelContextAsync({
177+
cfg: params.cfg,
178+
agentId,
179+
agentDir: sessionBound ? undefined : params.agentDir,
180+
workspaceDir: params.workspaceDir,
181+
modelProvider: params.provider,
182+
modelId: params.model,
183+
});
173184
const result = resolveEffectiveToolInventory({
174185
cfg: params.cfg,
175186
agentId,
@@ -178,6 +189,8 @@ export const handleToolsCommand: CommandHandler = async (params, allowTextComman
178189
agentDir: sessionBound ? undefined : params.agentDir,
179190
modelProvider: params.provider,
180191
modelId: params.model,
192+
modelApi: runtimeModelContext.modelApi,
193+
runtimeModel: runtimeModelContext.runtimeModel,
181194
messageProvider: params.command.channel,
182195
senderId: params.command.senderId,
183196
senderName: params.ctx.SenderName,

0 commit comments

Comments
 (0)