diff --git a/src/cache-ledger.ts b/src/cache-ledger.ts index 0620faa821..265fff34c0 100644 --- a/src/cache-ledger.ts +++ b/src/cache-ledger.ts @@ -1536,6 +1536,7 @@ function formatSeam(r: BiliCacheReport): string { if (r.seam.providerSide.count > 0) { out.push("▲ PROVIDER-SIDE MISS (previous request's message list fully preserved)"); out.push(` ${r.seam.providerSide.count} sample(s) · ${fmtTok(r.seam.providerSide.missed)} tok — the previous request's message list is preserved in this one (byte-for-byte under the 512 KiB forensics cap; above it, proven by the stable recorded head plus exact message-count growth — any difference is only the appended tail); the upstream did not serve its cache (TTL expiry / eviction / relay node rotation). Not a bili rebuild seam.`); + out.push(` stateful-upstream check (#2483): if your upstream keeps a live session per conversation and validates the echoed history against its own transcript (claude-code-based relays such as magpie), bili's render tags on assistant text trip that check even though bili's own list is unchanged — set diagnostics.renderNone=true until per-route render-tags control ships; expect exactly ONE replay when flipping the flag mid-session`); } if (r.seam.abortCorrelated > 0) { out.push("⏻ ABORT-CORRELATED"); diff --git a/src/server/prepare-anthropic.ts b/src/server/prepare-anthropic.ts index 8b8bf5349c..1270f31a3e 100644 --- a/src/server/prepare-anthropic.ts +++ b/src/server/prepare-anthropic.ts @@ -67,6 +67,10 @@ export async function prepareAnthropic( let clientCacheControls: Map | undefined; let systemOut = parsed.system; let toolsOut = parsed.tools; + // #2483: single source for the effective render strategy — processTurn, the + // diag log and Prepared must all report what was actually rendered (the + // log label used to hardcode "text-only" and lie under renderNone). + const renderStrategy = knobRenderNone() ? "none" : "text-only"; // #1085: sticky head-system anchor — freeze the client's own `system` text // at first sight and forward it byte-stable; detected changes ride as @@ -201,7 +205,7 @@ export async function prepareAnthropic( const foldCoveredBefore = session.stats.pendingFoldUsage === true ? new Set(session.state.blocks.flatMap((b) => (b.active ? b.effectiveMessageIds : []))) : null; - const turn = core.processTurn({ messages: msgs, state: session.state, config: loopConfig, tokenCount, renderTags: knobRenderNone() ? "none" : "text-only", contentStore: contentStoreOf(session) }); + const turn = core.processTurn({ messages: msgs, state: session.state, config: loopConfig, tokenCount, renderTags: renderStrategy, contentStore: contentStoreOf(session) }); session.state = turn.state; adoptContentStore(session, turn.contentStore); // The fold from last turn's compress has now materialized in state — @@ -226,7 +230,7 @@ export async function prepareAnthropic( const t = deriveTitle(msgs); if (t) session.meta.title = t; } - log("info", diagTagSummary(turn.messages, sessionId, "text-only")); + log("info", diagTagSummary(turn.messages, sessionId, renderStrategy)); // #2155: a self-heal-suppressed session (nudge idle / zombie fallback) // stops nagging — including the emergency path, per session. const willInjectNudge = opts.compress.injectNudge && !!turn.nudge && !nudgeSuppressed(session) && !compressBreakerArmed(session) && !(autoFoldEngaged(loopConfig, session) && growthFoldingArmed(loopConfig)) && (turn.nudge.shouldInject || emergencyNudge(turn.nudge, undefined, loopConfig.compress.minCompressRange)); @@ -388,7 +392,7 @@ export async function prepareAnthropic( + countSystemAndToolsTokens(extractSystem(systemOut), toolsOut) + imageReserveFor(session, "anthropic", rebuilt, opts, upstreamOrigin); if (upstreamOrigin) session.stats.lastLocalTextEstimateOrigin = upstreamOrigin; - return { body: JSON.stringify(rebuilt), session, attachedRetrievals, attachedRetrievalNoteIds, processedMessages, originalMessages, anthropicSystem: parsed.system, anthropicBillingBlock, anthropicCacheMarks, anthropicClientCacheControls: clientCacheControls, systemNotes: sysNotes, protocol: "anthropic", stream, compressInjected: injectTools, pluginMode, nudge, prompts, surface, renderTags: knobRenderNone() ? "none" : "text-only", dropReasoning: stripReasoning } as Prepared; + return { body: JSON.stringify(rebuilt), session, attachedRetrievals, attachedRetrievalNoteIds, processedMessages, originalMessages, anthropicSystem: parsed.system, anthropicBillingBlock, anthropicCacheMarks, anthropicClientCacheControls: clientCacheControls, systemNotes: sysNotes, protocol: "anthropic", stream, compressInjected: injectTools, pluginMode, nudge, prompts, surface, renderTags: renderStrategy, dropReasoning: stripReasoning } as Prepared; } diff --git a/src/server/prepare-google.ts b/src/server/prepare-google.ts index 4f1d2ac584..a7d6e68bc5 100644 --- a/src/server/prepare-google.ts +++ b/src/server/prepare-google.ts @@ -22,6 +22,7 @@ import { attachSubagentSessions } from "../subagent-sessions.js"; import { reconcileSystemAnchor } from "../system-anchor.js"; import { stripAcpPanelMessages, stripAcpStatusMarkers } from "../acp-panel.js"; import { stripEmbeddedChainCarriers } from "../chain-checkpoint.js"; +import { renderNone as knobRenderNone } from "../knobs.js"; import { clampOutgoingOutput, countSystemAndToolsTokens, dshLedgerFloorTokens, emergencyNudge } from "./budget.js"; import { estimateCoreMessages } from "../preflight.js"; import { effectiveAbsorbBlock } from "./prepare-responses.js"; @@ -87,6 +88,9 @@ export async function prepareGoogle( const isTitleGen = maxTokens <= 200; const shouldInject = opts.compress.injectTool && !isTitleGen; const injectTools = shouldInject && !pluginMode; + // #2483: this lane used to ignore renderNone entirely (hardcoded "text-only" + // in processTurn, Prepared and countTokens) — the knob was dead config on /v1beta. + const renderStrategy = knobRenderNone() ? "none" : "text-only"; const strippedCarriers = stripEmbeddedChainCarriers(parsed, "google"); if (strippedCarriers > 0) { @@ -147,11 +151,11 @@ export async function prepareGoogle( const foldCoveredBefore = session.stats.pendingFoldUsage === true ? new Set(session.state.blocks.flatMap((b) => (b.active ? b.effectiveMessageIds : []))) : null; - const turn = core.processTurn({ messages: msgs, state: session.state, config: loopConfig, tokenCount, renderTags: "text-only", contentStore: contentStoreOf(session) }); + const turn = core.processTurn({ messages: msgs, state: session.state, config: loopConfig, tokenCount, renderTags: renderStrategy, contentStore: contentStoreOf(session) }); session.state = turn.state; adoptContentStore(session, turn.contentStore); - // The fold from last turn's compress has materialized in state — future - // usage reports are post-fold reality, drop the credit. + // The fold from last turn's compress has now materialized in state — + // future usage reports are post-fold reality, drop the credit. session.stats.compressCreditTokens = 0; if (foldCoveredBefore !== null && !isTitleGen && msgs.length >= REWRITE_MIN_INCOMING_TOTAL) { const gap = foldCoverage(foldCoveredBefore, msgs.map((m) => m.id)); @@ -161,8 +165,9 @@ export async function prepareGoogle( storeEffectiveRules(session, config); turn.messages = applyAbsorbView(turn.messages, session.state, loopConfig, tokenCount); turn.messages = attachSubagentSessions(turn.messages, session); - // Drop sub-viability fragments before any consumer sees them (the - // kernel validates a compress batch atomically). + // Drop sub-viability fragments before any consumer sees them: a tiny + // range in the list makes batched compress attempts fail atomically + // (kernel validates the whole batch). Mirrors billion-context-pi. if (turn.nudge) turn.nudge.compressibleRanges = viableRanges(turn.nudge.compressibleRanges); nudge = turn.nudge; session.stats.contextTokens = tokenCount; @@ -171,7 +176,7 @@ export async function prepareGoogle( const t = deriveTitle(msgs); if (t) session.meta.title = t; } - log("info", diagTagSummary(turn.messages, sessionId, "text-only")); +log("info", diagTagSummary(turn.messages, sessionId, renderStrategy)); const willInjectNudge = opts.compress.injectNudge && !!turn.nudge && shouldInject && !nudgeSuppressed(session) && !compressBreakerArmed(session) && !(autoFoldEngaged(loopConfig, session) && growthFoldingArmed(loopConfig)) && (turn.nudge.shouldInject || emergencyNudge(turn.nudge, undefined, loopConfig.compress.minCompressRange)); log("info", diagNudge(turn, sessionId, tokenCount, config.modelContextLimit, model, willInjectNudge)); processedMessages = stripKernelSummaries(turn.messages, turn.state); @@ -193,7 +198,7 @@ export async function prepareGoogle( // and round-2 re-requests — skipping them here would fork the prefix // at every fold and collapse the upstream cache hit. if (shouldInject) sysParts.push(withMarkerIntegrityNote(withSummaryBudgetNote(buildCompressSystemPrompt(prompts, surface?.promptSections), externalSummaryEnabled(config)), visibilityMarkers)); - else if (!isTitleGen) { + else if (!isTitleGen && renderStrategy !== "none") { // #1881: the NEVER-echo prohibition follows the rendered tags, not the tool switch. const tagsOnly = buildAcpTagsOnlyPrompt("function", prompts, surface?.promptSections); if (tagsOnly) sysParts.push(tagsOnly); @@ -277,7 +282,7 @@ export async function prepareGoogle( } snapshotMessages(session, originalMessages); markDirty(session); - return { body: JSON.stringify(rebuilt), session, processedMessages, originalMessages, protocol: "google", stream, compressInjected: injectTools, pluginMode, nudge, prompts, surface, google: { system: googleClientSystem, model }, systemNotes: sysNotes, renderTags: "text-only" } as Prepared; + return { body: JSON.stringify(rebuilt), session, processedMessages, originalMessages, protocol: "google", stream, compressInjected: injectTools, pluginMode, nudge, prompts, surface, google: { system: googleClientSystem, model }, systemNotes: sysNotes, renderTags: renderStrategy } as Prepared; } /** `POST /v1beta/models/:countTokens` — the fold-prune twin of @@ -296,7 +301,7 @@ export function prepareGoogleCountTokens( const { msgs } = googleToCore(parsed); // Read-only preview: the store rides in so placeholder substitution is // counted, but nothing is adopted (state is discarded here too). - const turn = core.processTurn({ messages: msgs, state: session.state, config: ccrLoopConfig(session, config), tokenCount: usageGradeInputBaseline(session), renderTags: "text-only", contentStore: contentStoreOf(session) }); + const turn = core.processTurn({ messages: msgs, state: session.state, config: ccrLoopConfig(session, config), tokenCount: usageGradeInputBaseline(session), renderTags: knobRenderNone() ? "none" : "text-only", contentStore: contentStoreOf(session) }); const stripped = stripKernelSummaries(turn.messages, turn.state); const rebuilt: GoogleRequestBody = { ...parsed, contents: coreToGoogle(stripped as BiliMessage[]) }; log("info", `[${sessionId}] countTokens pruned: ${msgs.length} → ${stripped.length} msgs`); diff --git a/src/server/prepare-openai.ts b/src/server/prepare-openai.ts index fdff375e06..c22716e3d6 100644 --- a/src/server/prepare-openai.ts +++ b/src/server/prepare-openai.ts @@ -63,6 +63,10 @@ export async function prepareOpenai( let nudge: NudgeDecision | undefined; let rebuiltMessages = parsed.messages; let toolsOut = parsed.tools; + // #2483: single source for the effective render strategy — processTurn, the + // diag log and Prepared must all report what was actually rendered (the + // log label used to hardcode "text-only" and lie under renderNone). + const renderStrategy = knobRenderNone() ? "none" : "text-only"; const maxTokens = typeof parsed.max_tokens === "number" ? parsed.max_tokens : 8192; // Title-generation requests (tiny max_tokens) get no compress tooling so @@ -163,7 +167,7 @@ export async function prepareOpenai( const foldCoveredBefore = session.stats.pendingFoldUsage === true ? new Set(session.state.blocks.flatMap((b) => (b.active ? b.effectiveMessageIds : []))) : null; - const turn = core.processTurn({ messages: msgs, state: session.state, config: loopConfig, tokenCount, renderTags: knobRenderNone() ? "none" : "text-only", contentStore: contentStoreOf(session) }); + const turn = core.processTurn({ messages: msgs, state: session.state, config: loopConfig, tokenCount, renderTags: renderStrategy, contentStore: contentStoreOf(session) }); session.state = turn.state; adoptContentStore(session, turn.contentStore); // The fold from last turn's compress has now materialized in state — @@ -188,7 +192,7 @@ export async function prepareOpenai( const t = deriveTitle(msgs); if (t) session.meta.title = t; } - log("info", diagTagSummary(turn.messages, sessionId, "text-only")); +log("info", diagTagSummary(turn.messages, sessionId, renderStrategy)); const willInjectNudge = opts.compress.injectNudge && !!turn.nudge && shouldInject && !nudgeSuppressed(session) && !compressBreakerArmed(session) && !(autoFoldEngaged(loopConfig, session) && growthFoldingArmed(loopConfig)) && (turn.nudge.shouldInject || emergencyNudge(turn.nudge, undefined, loopConfig.compress.minCompressRange)); log("info", diagNudge(turn, sessionId, tokenCount, config.modelContextLimit, parsed.model, willInjectNudge)); processedMessages = stripReasoning(stripKernelSummaries(turn.messages, turn.state)); @@ -374,7 +378,7 @@ export async function prepareOpenai( } snapshotMessages(session, originalMessages); markDirty(session); - return { body: JSON.stringify(rebuilt), session, attachedRetrievals, attachedRetrievalNoteIds, processedMessages, originalMessages, protocol: "openai", stream, compressInjected: injectTools, pluginMode, nudge, prompts, surface, openaiSystemText, systemNotes: sysNotes, renderTags: knobRenderNone() ? "none" : "text-only", dropReasoning: stripReasoning } as Prepared; + return { body: JSON.stringify(rebuilt), session, attachedRetrievals, attachedRetrievalNoteIds, processedMessages, originalMessages, protocol: "openai", stream, compressInjected: injectTools, pluginMode, nudge, prompts, surface, openaiSystemText, systemNotes: sysNotes, renderTags: renderStrategy, dropReasoning: stripReasoning } as Prepared; } /** Append the ephemeral nudge to a Gemini `contents` array. Gemini is diff --git a/src/server/prepare-responses.ts b/src/server/prepare-responses.ts index 1af98ee527..6e02b82325 100644 --- a/src/server/prepare-responses.ts +++ b/src/server/prepare-responses.ts @@ -273,7 +273,7 @@ export async function prepareResponses( const t = deriveTitle(msgs); if (t) session.meta.title = t; } - log("info", diagTagSummary(turn.messages, sessionId, "text-only")); +log("info", diagTagSummary(turn.messages, sessionId, renderTags)); const willInjectNudge = opts.compress.injectNudge && !!turn.nudge && shouldInject && !isCompactionTrigger && !nudgeSuppressed(session) && !compressBreakerArmed(session) && !(autoFoldEngaged(loopConfig, session) && growthFoldingArmed(loopConfig, codexLane && codexCompactMode() === "intercept" ? loopConfig.modelContextLimit * CODEX_COMPACT_HEALTH_RATIO : undefined)) && (turn.nudge.shouldInject || emergencyNudge(turn.nudge, undefined, loopConfig.compress.minCompressRange)); log("info", diagNudge(turn, sessionId, tokenCount, config.modelContextLimit, parsed.model, willInjectNudge)); processedMessages = repairResponsesAssistantOrdering(stripReasoning(stripKernelSummaries(turn.messages, turn.state)), originalMessages); diff --git a/tests/cache-seam-detector.test.ts b/tests/cache-seam-detector.test.ts index bd496da4d9..842b16034c 100644 --- a/tests/cache-seam-detector.test.ts +++ b/tests/cache-seam-detector.test.ts @@ -156,6 +156,19 @@ test("seam detector: byte-stable resend attributes to PROVIDER-SIDE MISS, not a assert.match(handleAcpCache(s).text, /PROVIDER-SIDE MISS/); }); +test("seam detector: PROVIDER-SIDE MISS section mentions the stateful-upstream render-tag check (#2483)", () => { + const s = makeSession(); + const same = body(["a", "b"]); + noteForwardedBody(s, same); + settle(s, T0, 100_000, 99_000); + noteForwardedBody(s, same); + settle(s, T0 + 1000, 100_000, 20_000); + const text = handleAcpCache(s).text; + assert.match(text, /PROVIDER-SIDE MISS/); + assert.match(text, /stateful-upstream check \(#2483\)/); + assert.match(text, /diagnostics\.renderNone=true/); +}); + test("seam detector: tail-append turn attributes to PROVIDER-SIDE MISS, not a seam (#2059)", () => { const s = makeSession(); noteForwardedBody(s, body(["a", "b"])); diff --git a/tests/issue2483-render-strategy.test.ts b/tests/issue2483-render-strategy.test.ts new file mode 100644 index 0000000000..691eab2d01 --- /dev/null +++ b/tests/issue2483-render-strategy.test.ts @@ -0,0 +1,268 @@ +import test from "node:test"; +import assert from "node:assert/strict"; +import http from "node:http"; +import { once } from "node:events"; +import { mkdirSync, rmSync, writeFileSync } from "node:fs"; +import { tmpdir } from "node:os"; +import path from "node:path"; +import { defaultConfig } from "acp-kernel"; +import { startServer } from "../src/server.ts"; +import { loadRoutes, type ProxyOptions } from "../src/config.ts"; +import { SessionStore, _setStoreForTest } from "../src/persist.ts"; +import { _setForTest as setRegistryForTest } from "../src/registry.ts"; + +// #2483: the effective render strategy had two consistency holes: +// (a) the processTurn diag line hardcoded renderTags=text-only even when +// renderNone was active (misleading log); +// (b) the Google lane ignored renderNone entirely — hardcoded "text-only" in +// processTurn / Prepared / countTokens and no knob check on the #1881 +// tagsOnly gate, so ACP_RENDER_NONE was dead config on /v1beta. +// These e2e tests pin the WIRE bytes on both lanes: the default still tags +// assistant/model text (no behavior drift), and under ACP_RENDER_NONE=1 the +// forwarded assistant/model text is byte-identical to the client's and the +// NEVER-echo prompt section disappears (the tagsOnly gate follows the strategy). + +function close(server: http.Server): Promise { + return new Promise((resolve, reject) => server.close((error) => error ? reject(error) : resolve())); +} + +async function freePort(): Promise { + const server = http.createServer(); + server.listen(0, "127.0.0.1"); + await once(server, "listening"); + const port = (server.address() as { port: number }).port; + await close(server); + return port; +} + +function upstreamServer(onBody: (path: string, body: unknown) => void): Promise { + const server = http.createServer((req, res) => { + const chunks: Buffer[] = []; + req.on("data", (c: Buffer) => chunks.push(c)); + req.on("end", () => { + let parsed: unknown = null; + try { parsed = JSON.parse(Buffer.concat(chunks).toString("utf8")); } catch { /* ignore */ } + const url = req.url ?? ""; + onBody(url, parsed); + res.writeHead(200, { "content-type": "application/json" }); + if (url.includes(":generateContent")) { + res.end(JSON.stringify({ + candidates: [{ content: { role: "model", parts: [{ text: "ok" }] }, finishReason: "STOP" }], + usageMetadata: { promptTokenCount: 10, candidatesTokenCount: 5, totalTokenCount: 15 }, + })); + return; + } + res.end(JSON.stringify({ + id: "chatcmpl-test", object: "chat.completion", created: 0, model: "test", + choices: [{ index: 0, message: { role: "assistant", content: "ok" }, finish_reason: "stop" }], + usage: { prompt_tokens: 10, completion_tokens: 5, total_tokens: 15 }, + })); + }); + }); + return new Promise((resolve) => server.listen(0, "127.0.0.1", () => resolve(server))); +} + +interface Harness { port: number; stop: () => Promise; cleanup: () => void } + +async function startProxy(upstream: http.Server, injectTool: boolean): Promise { + _setStoreForTest(new SessionStore({ enabled: false })); + setRegistryForTest({}); + const root = path.join(tmpdir(), `bili-2483-${process.pid}-${Date.now()}-${Math.random().toString(16).slice(2)}`); + const biliConfig = path.join(root, "billion-context.json"); + mkdirSync(root, { recursive: true }); + writeFileSync(biliConfig, `{"providers":{}}`, "utf8"); + const previous = process.env.BILI_CONFIG_FILE; + process.env.BILI_CONFIG_FILE = biliConfig; + delete process.env.ACP_RENDER_NONE; + delete process.env.ACP_NO_COMPRESS_PROMPT; + const upstreamPort = (upstream.address() as { port: number }).port; + const port = await freePort(); + const opts: ProxyOptions = { + port, + host: "127.0.0.1", + upstream: `http://127.0.0.1:${upstreamPort}`, + routes: loadRoutes(), + proxy: "", + proxyMode: "direct", + proxySource: "direct", + modelContextLimit: 400_000, + kernelConfig: defaultConfig(400_000), + compress: { injectTool, injectNudge: false }, + promptCache: { routing: "auto" }, + sessionHeader: "x-acp-session", + log: false, + debug: false, + passthrough: false, + chainContentDetection: false, + passthroughSource: null, + compat: { roles: {} }, + streamErrorShape: "protocol", + autoRestartOnUpdate: false, + updateTag: "latest", + advisoryCheck: false, + releaseNotesCheck: false, + autoUpdate: false, + mitm: { enabled: false, domains: [] }, + }; + const proxy = await startServer(opts); + if (!proxy.listening) await once(proxy, "listening"); + return { + port, + stop: async () => { await close(proxy); }, + cleanup: () => { + delete process.env.ACP_RENDER_NONE; + if (previous === undefined) delete process.env.BILI_CONFIG_FILE; else process.env.BILI_CONFIG_FILE = previous; + rmSync(root, { recursive: true, force: true }); + }, + }; +} + +const CHAT_BODY = JSON.stringify({ + model: "test", + max_tokens: 1000, + messages: [ + { role: "system", content: "You are helpful." }, + { role: "user", content: "hello" }, + { role: "assistant", content: "hi there" }, + { role: "user", content: "what did we say?" }, + ], +}); + +const GOOGLE_BODY = JSON.stringify({ + systemInstruction: "You are helpful.", + contents: [ + { role: "user", parts: [{ text: "hello" }] }, + { role: "model", parts: [{ text: "hi there" }] }, + { role: "user", parts: [{ text: "what did we say?" }] }, + ], +}); + +type Msg = { role?: string; content?: unknown }; + +function chatAssistantText(fwd: Record): string { + const msgs = fwd.messages as Msg[] | undefined; + assert.ok(Array.isArray(msgs), "forwarded body carries messages"); + const a = msgs.find((m) => m.role === "assistant"); + assert.ok(a, "the assistant message reaches the upstream"); + return typeof a.content === "string" ? a.content : JSON.stringify(a.content); +} + +function chatSystemText(fwd: Record): string { + const msgs = fwd.messages as Msg[] | undefined; + assert.ok(Array.isArray(msgs), "forwarded body carries messages"); + const sys = msgs.find((m) => m.role === "system"); + assert.ok(sys, "a system message reaches the upstream"); + return typeof sys.content === "string" ? sys.content : JSON.stringify(sys.content); +} + +interface GPart { text?: string } +interface GContent { role?: string; parts?: GPart[] } + +function googleModelText(fwd: Record): string { + const contents = fwd.contents as GContent[] | undefined; + assert.ok(Array.isArray(contents), "forwarded body carries contents"); + const model = contents.find((c) => c.role === "model"); + assert.ok(model, "the model turn reaches the upstream"); + const texts = (model.parts ?? []).map((p) => p.text ?? ""); + return texts.join(""); +} + +function googleSystemText(fwd: Record): string { + const si = fwd.systemInstruction; + if (typeof si === "string") return si; + const parts = (si as { parts?: GPart[] })?.parts; + assert.ok(Array.isArray(parts), "object-form systemInstruction carries parts"); + return parts.map((p) => p.text ?? "").join("\n\n"); +} + +test("#2483 openai lane default: assistant text is tagged (behavior unchanged)", async () => { + const seen: Array> = []; + const upstream = await upstreamServer((_path, body) => seen.push(body as Record)); + const harness = await startProxy(upstream, false); + try { + const res = await fetch(`http://127.0.0.1:${harness.port}/v1/chat/completions`, { + method: "POST", + headers: { "content-type": "application/json", "x-session-id": "issue2483-openai-default" }, + body: CHAT_BODY, + }); + assert.equal(res.status, 200); + assert.equal(seen.length, 1); + const a = chatAssistantText(seen[0]!); + assert.ok(a.startsWith(" { + const seen: Array> = []; + const upstream = await upstreamServer((_path, body) => seen.push(body as Record)); + const harness = await startProxy(upstream, false); + process.env.ACP_RENDER_NONE = "1"; + try { + const res = await fetch(`http://127.0.0.1:${harness.port}/v1/chat/completions`, { + method: "POST", + headers: { "content-type": "application/json", "x-session-id": "issue2483-openai-none" }, + body: CHAT_BODY, + }); + assert.equal(res.status, 200); + assert.equal(seen.length, 1); + assert.equal(chatAssistantText(seen[0]!), "hi there", "renderNone forwards the assistant text untouched"); + assert.ok(!chatSystemText(seen[0]!).includes("NEVER echo"), "tags-only prompt follows the rendered tags"); + } finally { + delete process.env.ACP_RENDER_NONE; + await harness.stop(); + harness.cleanup(); + await close(upstream); + } +}); + +test("#2483 google lane default: model text is tagged (behavior unchanged)", async () => { + const seen: Array> = []; + const upstream = await upstreamServer((_path, body) => seen.push(body as Record)); + const harness = await startProxy(upstream, false); + try { + const res = await fetch(`http://127.0.0.1:${harness.port}/v1beta/models/test:generateContent`, { + method: "POST", + headers: { "content-type": "application/json", "x-session-id": "issue2483-google-default" }, + body: GOOGLE_BODY, + }); + assert.equal(res.status, 200); + assert.equal(seen.length, 1); + const t = googleModelText(seen[0]!); + assert.ok(t.startsWith(" { + const seen: Array> = []; + const upstream = await upstreamServer((_path, body) => seen.push(body as Record)); + const harness = await startProxy(upstream, false); + process.env.ACP_RENDER_NONE = "1"; + try { + const res = await fetch(`http://127.0.0.1:${harness.port}/v1beta/models/test:generateContent`, { + method: "POST", + headers: { "content-type": "application/json", "x-session-id": "issue2483-google-none" }, + body: GOOGLE_BODY, + }); + assert.equal(res.status, 200); + assert.equal(seen.length, 1); + assert.equal(googleModelText(seen[0]!), "hi there", "renderNone forwards the model text untouched"); + assert.ok(!googleSystemText(seen[0]!).includes("NEVER echo"), "tags-only prompt follows the rendered tags"); + } finally { + delete process.env.ACP_RENDER_NONE; + await harness.stop(); + harness.cleanup(); + await close(upstream); + } +});