From cb2169f3341f4f6a36e07f2016d6730478968ab0 Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Fri, 6 Feb 2026 21:55:13 +0900 Subject: [PATCH] fix: guard against undefined modelID in anthropic-effort hook Add early return when model.modelID or model.providerID is nullish, preventing TypeError at runtime when chat.params receives incomplete model data. --- src/hooks/anthropic-effort/index.test.ts | 19 +++++++++++++++++++ src/hooks/anthropic-effort/index.ts | 1 + 2 files changed, 20 insertions(+) diff --git a/src/hooks/anthropic-effort/index.test.ts b/src/hooks/anthropic-effort/index.test.ts index 84168fbb3..be965c0a9 100644 --- a/src/hooks/anthropic-effort/index.test.ts +++ b/src/hooks/anthropic-effort/index.test.ts @@ -156,6 +156,25 @@ describe("createAnthropicEffortHook", () => { //#then effort should NOT be injected expect(output.options.effort).toBeUndefined() }) + + it("should NOT throw when model.modelID is undefined", async () => { + //#given model with undefined modelID (runtime edge case) + const hook = createAnthropicEffortHook() + const input = { + sessionID: "test-session", + agent: { name: "sisyphus" }, + model: { providerID: "anthropic", modelID: undefined as unknown as string }, + provider: { id: "anthropic" }, + message: { variant: "max" as const }, + } + const output = { temperature: 0.1, options: {} } + + //#when chat.params hook is called with undefined modelID + await hook["chat.params"](input, output) + + //#then should gracefully skip without throwing + expect(output.options.effort).toBeUndefined() + }) }) describe("preserves existing options", () => { diff --git a/src/hooks/anthropic-effort/index.ts b/src/hooks/anthropic-effort/index.ts index b52fc32ad..141933cb2 100644 --- a/src/hooks/anthropic-effort/index.ts +++ b/src/hooks/anthropic-effort/index.ts @@ -39,6 +39,7 @@ export function createAnthropicEffortHook() { output: ChatParamsOutput ): Promise => { const { model, message } = input + if (!model?.modelID || !model?.providerID) return if (message.variant !== "max") return if (!isClaudeProvider(model.providerID, model.modelID)) return if (!isOpus46(model.modelID)) return