Skip to content
Draft
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
10 changes: 10 additions & 0 deletions src/server/responses/pinned-helper-refusal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { formatErrorResponse } from "../../bridge";

// AGE-2004: what an agent sees when its model pin blocks a helper model. Names the refused case, why, and the one next step.
const NOW = "Now: resend without it, or ask the account owner to turn on Fall back to other AI accounts.";
const refusal = (what: string, helper: string) => formatErrorResponse(400, "invalid_request_error",
`Request refused, nothing was sent: ${what}. This agent's model pin cannot use helper models, so no ${helper} was allowed to run. ${NOW}`);

export const refuseImageOnPin = () => refusal("it contains an image and the pinned model cannot read images (resend without the image, describe it in words)", "vision helper");
export const refuseWebSearchOnPin = () => refusal("it asks for the web_search tool and the pin is not a Claude account (resend without the web_search tool)", "search helper");
export const refuseMediaBridgeOnPin = () => refusal("it needs the image or video bridge (image_gen/video_gen) (resend without image or video generation)", "image or video bridge");
6 changes: 3 additions & 3 deletions src/server/responses/request-sidecar-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
requiresVisionPreprocessing,
stripImagesInPlace,
} from "../../vision";
import { formatErrorResponse } from "../../bridge";
import { refuseImageOnPin, refuseWebSearchOnPin } from "./pinned-helper-refusal";
import { shouldResolveOpenAiWebSearchSidecar } from "../../web-search";
import { shouldResolveOpenAiPassthroughWebSearchBridge } from "../../web-search/passthrough-bridge";
import {
Expand Down Expand Up @@ -65,7 +65,7 @@ export async function prepareResponsesSidecarAuth(
&& !exactAnthropicSourceReplay
&& (shouldResolveOpenAiWebSearchSidecar(config, parsed, isPassthrough)
|| shouldResolveOpenAiPassthroughWebSearchBridge(route.provider, parsed, isPassthrough));
if (options.agentRadarAccount && (needsOpenAiVision || needsOpenAiSearch)) return formatErrorResponse(400, "invalid_request_error", "AgentRadar pinned requests cannot use helper models (vision, image or video bridge, or web search outside a Claude pin)");
if (options.agentRadarAccount && (needsOpenAiVision || needsOpenAiSearch)) return needsOpenAiVision ? refuseImageOnPin() : refuseWebSearchOnPin();
if (needsOpenAiVision || needsOpenAiSearch) {
try {
const candidates = listOpenAiForwardSidecarCandidates(config);
Expand Down Expand Up @@ -134,7 +134,7 @@ export async function prepareResponsesSidecarAuth(
: planVisionSidecar(config, route.provider, route.modelId, parsed, openAiSidecar, {
admission: options.admission, codexAuthPolicy: options.codexAuthPolicy, providerName: route.providerName,
});
if (options.agentRadarAccount && visionPlan) return formatErrorResponse(400, "invalid_request_error", "AgentRadar pinned requests cannot use helper models (vision, image or video bridge, or web search outside a Claude pin)");
if (options.agentRadarAccount && visionPlan) return refuseImageOnPin();
const recordSidecarOutcome = openAiSidecar?.recordOutcome;
let visionMutatedRequest = false;
if (visionPlan) {
Expand Down
7 changes: 5 additions & 2 deletions src/server/responses/sidecar-execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { ResponsesSidecarAuth } from "./request-sidecar-auth";
import type { ResponsesEffects } from "./response-effects";
import type { ResponsesSendBudget } from "./request-send-budget";
import { formatErrorResponse } from "../../bridge";
import { refuseMediaBridgeOnPin, refuseWebSearchOnPin } from "./pinned-helper-refusal";
import { planWebSearch, buildWebSearchTool, runWithWebSearch } from "../../web-search";
import {
planImageBridge,
Expand Down Expand Up @@ -161,8 +162,10 @@ export async function executeResponsesSidecars(
: undefined;
const imgPlan = canPlanSidecars ? await planImageBridge(config, parsed, route.provider) : undefined;
const vidPlan = canPlanSidecars ? await planVideoBridge(config, parsed, route.provider) : undefined;
if (options.agentRadarAccount && ((wsPlan && !(options.agentRadarAccount.provider === "claude" && wsPlan.backend === "anthropic"))
|| imgPlan || vidPlan)) return formatErrorResponse(400, "invalid_request_error", "AgentRadar pinned requests cannot use helper models (vision, image or video bridge, or web search outside a Claude pin)");
if (options.agentRadarAccount) {
if (wsPlan && !(options.agentRadarAccount.provider === "claude" && wsPlan.backend === "anthropic")) return refuseWebSearchOnPin();
if (imgPlan || vidPlan) return refuseMediaBridgeOnPin();
}
const canRunWebSearch = !!wsPlan && !transportState.adapter.runTurn;
const rotateSidecarProviderOn429 = async (
retryAfter: string | null,
Expand Down
4 changes: 2 additions & 2 deletions tests/server/agentradar-account-pin-e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ test("an AgentRadar account pin serves exactly its own stored account (pin.check
assert.equal(r.status, 200, r.text);
assert.ok(inference(r).length >= 2 && !inference(r).at(-1)!.image, `no vision describe planned: ${JSON.stringify(r.upstream)}`);
r = await call(ocx, "/v1/messages", blindImage, { "anthropic-version": "2023-06-01", "x-api-key": "unused", ...pin("claude", "A") });
assert.equal(r.status, 400, `${r.text}\n${JSON.stringify(r.upstream)}`); assert.deepEqual(inference(r), []);
assert.equal(r.status, 400, `${r.text}\n${JSON.stringify(r.upstream)}`); assert.match(r.text, /contains an image.*no vision helper was allowed to run/); assert.deepEqual(inference(r), []);
// Surfaces that do not honour a pin refuse it instead of serving the active account.
r = await call(ocx, "/v1/responses", { model: "anthropic/claude-stub", input: "hi" }, pin("claude", "A"));
assert.equal(r.status, 400, r.text); assert.match(r.text, /only honoured on/); assert.deepEqual(inference(r), []);
Expand All @@ -222,7 +222,7 @@ test("an AgentRadar account pin serves exactly its own stored account (pin.check
assert.deepEqual([...new Set(tokens(r, "/v1/messages"))], ["Bearer atA"], JSON.stringify(r.upstream));
// Grok and Codex have no helper that can run on their pin: still refused.
r = await call(ocx, "/v1/chat/completions", { model: "xai/grok-stub", messages: [{ role: "user", content: "hi" }], tools: [{ type: "web_search" }] }, pin("grok", "gA"));
assert.equal(r.status, 400, r.text); assert.match(r.text, /cannot use helper models/); assert.deepEqual(inference(r), []);
assert.equal(r.status, 400, r.text); assert.match(r.text, /web_search tool.*no search helper was allowed to run/); assert.deepEqual(inference(r), []);
assert.equal((await accounts(ocx, "anthropic")).activeAccountId, "B", "pins never move the active account");

// Claude 429 on the pinned account: returned as is, cooldown recorded, no switch to B.
Expand Down
22 changes: 22 additions & 0 deletions tests/server/pinned-helper-refusal.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { expect, test } from "bun:test";
import { refuseImageOnPin, refuseMediaBridgeOnPin, refuseWebSearchOnPin } from "../../src/server/responses/pinned-helper-refusal";

// AGE-2004: each refused helper case says what was refused, that the pin blocks helpers, and the one next step.
const cases = [
["image on a text-only model", refuseImageOnPin, "it contains an image", "vision helper", "resend without the image"],
["web_search on a non-Claude pin", refuseWebSearchOnPin, "it asks for the web_search tool", "search helper", "resend without the web_search tool"],
["image or video bridge", refuseMediaBridgeOnPin, "it needs the image or video bridge", "image or video bridge", "resend without image or video generation"],
] as const;

for (const [name, refuse, what, helper, cta] of cases) {
test(`pinned refusal: ${name}`, async () => {
const res = refuse();
expect(res.status).toBe(400);
const text = (await res.json()).error.message as string;
expect(text).toContain("Request refused, nothing was sent");
expect(text).toContain(what);
expect(text).toContain(`cannot use helper models, so no ${helper} was allowed to run`);
expect(text).toContain(cta);
expect(text).toContain("ask the account owner to turn on Fall back to other AI accounts");
});
}
Loading