Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions open-sse/handlers/chatCore/upstreamBody.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
type ConnectionCacheOverride,
} from "../../utils/cacheControlPolicy.ts";
import { FORMATS } from "../../translator/formats.ts";
import { stripInternalBodyFields } from "../../config/cliFingerprints.ts";
import { sanitizeRequestForResolvedTarget } from "../../services/targetRequestSanitizer.ts";
import { normalizeThinkingForModel } from "@/shared/constants/modelSpecs.ts";
import {
Expand Down Expand Up @@ -259,6 +260,11 @@ function normalizeAttemptBody(opts: PrepareUpstreamBodyOptions): Body {
}
bodyToSend = stripGpt5SamplingWhenReasoning(bodyToSend, provider, modelToCall, log);
bodyToSend = stripGpt5ReasoningWhenTools(bodyToSend, provider, modelToCall, targetFormat, log);

// All models, including universal/context-handoff summary models, pass through
// this shared pre-executor boundary. Remove OmniRoute-only routing markers here
// so custom executors that serialize their own request bodies cannot leak them.
stripInternalBodyFields(bodyToSend);
return bodyToSend;
}

Expand Down
72 changes: 72 additions & 0 deletions tests/unit/strip-internal-omniroute-markers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,75 @@ test("DefaultExecutor.execute never serializes _omniroute* markers into the upst
assert.ok(raw.includes("claude-opus-5"), "real payload must survive the strip");
}
});

// Cross-layer production regression: universal-handoff itself must reach the common
// executor egress boundary before serialization. Its internal control markers are
// deliberately present while the dispatcher runs, but must be absent from fetch.
test("universal-handoff dispatch never serializes _omniroute markers upstream", async () => {
const { maybeGenerateUniversalHandoff, DEFAULT_UNIVERSAL_HANDOFF_CONFIG } =
await import("../../open-sse/services/contextHandoff.ts");
const { prepareUpstreamBody } = await import("../../open-sse/handlers/chatCore/upstreamBody.ts");

const sentBodies: string[] = [];

let resolveDispatch: (() => void) | undefined;
const dispatched = new Promise<void>((resolve) => {
resolveDispatch = resolve;
});

maybeGenerateUniversalHandoff({
sessionId: "universal-handoff-marker-leak",
comboName: "universal-handoff-marker-leak",
messages: [{ role: "user", content: "Retain this context." }],
prevModel: "anthropic/claude-opus-5",
currModel: "anthropic/claude-sonnet-5",
universalConfig: {
...DEFAULT_UNIVERSAL_HANDOFF_CONFIG,
enabled: true,
handoffModel: "anthropic/claude-sonnet-5",
},
handleSingleModel: async (body, model) => {
// Model a custom executor that serializes its payload itself instead of
// inheriting BaseExecutor's serializer. The shared boundary must remove
// the markers before such an executor receives its body.
const prepared = await prepareUpstreamBody({
translatedBody: body,
modelToCall: model,
provider: "custom-provider",
targetFormat: "openai",
credentials: {},
});
sentBodies.push(JSON.stringify(prepared));
resolveDispatch?.();
return new Response(
JSON.stringify({
choices: [
{
message: {
content: JSON.stringify({
summary: "A valid handoff summary.",
keyDecisions: [],
taskProgress: "",
activeEntities: [],
}),
},
},
],
}),
{ status: 200, headers: { "Content-Type": "application/json" } }
);
},
});

await dispatched;

assert.ok(sentBodies.length > 0, "universal handoff must dispatch an upstream request");
for (const raw of sentBodies) {
const payload = JSON.parse(raw) as Record<string, unknown>;
for (const key of Object.keys(payload)) {
assert.ok(!key.startsWith("_omniroute"), `internal marker leaked upstream: ${key}`);
}
assert.equal(payload.model, "anthropic/claude-sonnet-5");
assert.ok(Array.isArray(payload.messages), "the summary request must retain its messages");
}
});