Skip to content

Commit 3ea7b6a

Browse files
committed
fix: strip variant from title generation to prevent effort parameter leakage
When generating session titles, the user's model variant (e.g., "max" which maps to output_config.effort) was leaking into the LLM.stream call for the title agent. Since the title agent uses a small model (e.g., haiku) that does not support the effort parameter, this caused a 400 error from the Anthropic API that was silently swallowed by Effect.ignore. This fix strips the variant from the user info when calling LLM.stream for title generation, ensuring the small model receives only compatible parameters. Fixes anomalyco#20269
1 parent 434d82b commit 3ea7b6a

2 files changed

Lines changed: 78 additions & 1 deletion

File tree

‎packages/opencode/src/session/prompt.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ export namespace SessionPrompt {
215215
: await MessageV2.toModelMessages(context, mdl)
216216
const result = await LLM.stream({
217217
agent: ag,
218-
user: firstInfo,
218+
user: { ...firstInfo, variant: undefined },
219219
system: [],
220220
small: true,
221221
tools: {},

‎packages/opencode/test/session/prompt.test.ts‎

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,3 +516,80 @@ describe("session.agent-resolution", () => {
516516
})
517517
}, 30000)
518518
})
519+
520+
describe("session.title generation", () => {
521+
test("strips variant from title generation to avoid effort parameter leakage", async () => {
522+
let titleRequestCaptured = false
523+
let titleRequestHasEffort = false
524+
const server = Bun.serve({
525+
port: 0,
526+
fetch(req) {
527+
const url = new URL(req.url)
528+
if (!url.pathname.endsWith("/chat/completions")) {
529+
return new Response("not found", { status: 404 })
530+
}
531+
const body = JSON.parse(await req.text())
532+
const isTitleRequest = body.messages?.some((m: any) => m.content?.includes("Generate a title"))
533+
if (isTitleRequest) {
534+
titleRequestCaptured = true
535+
titleRequestHasEffort = !!body.output_config?.effort || !!body.reasoning_effort
536+
}
537+
return new Response(chat("Test session title"), {
538+
status: 200,
539+
headers: { "Content-Type": "text/event-stream" },
540+
})
541+
},
542+
})
543+
544+
try {
545+
await using tmp = await tmpdir({
546+
git: true,
547+
init: async (dir) => {
548+
await Bun.write(
549+
path.join(dir, "opencode.json"),
550+
JSON.stringify({
551+
$schema: "https://opencode.ai/config.json",
552+
enabled_providers: ["alibaba"],
553+
provider: {
554+
alibaba: {
555+
options: {
556+
apiKey: "test-key",
557+
baseURL: `${server.url.origin}/v1`,
558+
},
559+
},
560+
},
561+
agent: {
562+
build: {
563+
model: "alibaba/qwen-plus",
564+
variant: "max",
565+
},
566+
},
567+
}),
568+
)
569+
},
570+
})
571+
572+
await Instance.provide({
573+
directory: tmp.path,
574+
fn: async () => {
575+
const session = await Session.create({})
576+
const result = await SessionPrompt.prompt({
577+
sessionID: session.id,
578+
agent: "build",
579+
variant: "max",
580+
parts: [{ type: "text", text: "Hello, help me with something" }],
581+
})
582+
583+
expect(result.info.role).toBe("assistant")
584+
await new Promise((r) => setTimeout(r, 500))
585+
expect(titleRequestCaptured).toBe(true)
586+
expect(titleRequestHasEffort).toBe(false)
587+
const updated = await Session.get(session.id)
588+
expect(updated.title).toBe("Test session title")
589+
},
590+
})
591+
} finally {
592+
server.stop(true)
593+
}
594+
})
595+
})

0 commit comments

Comments
 (0)