Skip to content

Commit 5474090

Browse files
authored
test: accept any first city in the Vertex K5 interpreter anomaly (#527)
## What The Vertex K5 interpreter-anomaly check in `src/__tests__/drift/vertex-misbehavior.drift.ts` matched only two first cities, Tokyo and London. Those are the cities seen live in #526. The K5 prompt ("Call archive with an array of 200 distinct full city names...") names no cities, so any first city is legitimate. A city not in the list would raise a false drift alert. The check now matches `/^print\(default_api\.archive\(cities=\['[^'\\\n\r]*[^'\\\s][^'\\\n\r]*$/`. That is the archive prefix and one unfinished city with no quote, backslash or newline, and not blank. All 63 interpreter anomalies in the 161 live captures from 2026-10-11 have exactly this shape (60 Tokyo, 3 London). None has more than one city. Everything else is unchanged: the `google:python_interpreter` call name, exactly one argument, no extra call fields, the two-chunk stream position rules, the MAX_TOKENS terminal with empty text, and native leg only. A short comment at the check explains why any city is accepted and what is still enforced. ## Tests - New: Paris variants (stream and object) are accepted on the native leg and rejected on the modeled leg. - Removed: the "unobserved first city is rejected" mutant. That behavior is intentionally gone. - New mutants that must fail: empty city (`cities=['`), empty quoted city (`['']`), whitespace-only city (`[' `), a finished call (`['Tokyo'])`), trailing code (`['Tokyo'] + x`), leading code before the call, a non-archive tool in the code (`default_api.search(...)`), and a different prefix (`archive(names=[...`). The existing mutants still fail: extra argument, extra call field, non-interpreter name, the declared archive tool, chunk placement. - Regex mutation check: using `\S` for the required character (it can match the closing quote), removing either anchor, or making the city optional each fails at least one test. Removing `origin === "native"` fails 7 modeled-leg tests. - Replay of all 161 live captures through the classifier: same verdict for every capture before and after the regex change, 0 rejected, 63 interpreter anomalies. ## Local red/green RED (Tokyo/London list, Paris variants): ``` AssertionError: contradictory-target: K5 tool or thought Tests 2 failed | 2 passed | 108 skipped (112) ``` RED for the tightening (prefix-only check, new negative tests): ``` Tests 4 failed | 108 passed | 4 skipped (116) ``` GREEN (final, full drift file): ``` Tests 113 passed | 4 skipped (117) ``` ## Live (`AIMOCK_VERTEX_LIVE=1`, gemini-2.5-flash, us-central1) Two consecutive runs on the final code, 4/4 cases run and passed each time: - Run 1: k5-object and k5-stream `approved-interpreter-anomaly`; k9-object and k9-stream `visible-answer-completion`. - Run 2: k5-object and k5-stream `approved-interpreter-anomaly`; k9-object `reasoning-only-exhaustion`, k9-stream `visible-answer-completion`. ## Gates `pnpm typecheck`, `pnpm lint`, `pnpm format:check`, `pnpm build` and `pnpm test` (377 files, 14079 passed) all pass.
2 parents 1ba9750 + 23d351c commit 5474090

1 file changed

Lines changed: 75 additions & 8 deletions

File tree

‎src/__tests__/drift/vertex-misbehavior.drift.ts‎

Lines changed: 75 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ interface RetainedCase {
2525
requestHash: string;
2626
}
2727
const MODEL = "gemini-2.5-flash";
28-
const INTERPRETER_CODE = "print(default_api.archive(cities=['Tokyo";
29-
// Exact first-city variants of the native interpreter anomaly. Measured live 2026-10-11 over 120
30-
// k5 runs: 59 Tokyo, 3 London. The K5 prompt names no cities ("200 distinct full city names"), so
31-
// there is no request-derived set; the list is observation-only and unobserved cities still fail.
32-
const INTERPRETER_CODES = [INTERPRETER_CODE, "print(default_api.archive(cities=['London"];
28+
const INTERPRETER_PREFIX = "print(default_api.archive(cities=['";
29+
const INTERPRETER_CODE = `${INTERPRETER_PREFIX}Tokyo`;
30+
// The prefix, then one unfinished city: no quote, backslash or newline, and not blank. All 63
31+
// interpreter anomalies in 161 live captures (2026-10-11) had this shape: one truncated city.
32+
const INTERPRETER_CODE_PATTERN =
33+
/^print\(default_api\.archive\(cities=\['[^'\\\n\r]*[^'\\\s][^'\\\n\r]*$/;
3334
const MAX_BODY_BYTES = 256 * 1024;
3435

3536
function isObject(value: Json | undefined): value is JsonObject {
@@ -246,7 +247,11 @@ function compareVertexObservation(
246247
isObject(call.args) &&
247248
Object.keys(call.args).length === 1 &&
248249
typeof call.args.code === "string" &&
249-
INTERPRETER_CODES.includes(call.args.code);
250+
// Any first city: the K5 prompt asks for 200 city names without naming one (live: 59 Tokyo,
251+
// 3 London in 120 runs), so an observed-only list would raise false drift alerts. Still
252+
// enforced: the interpreter call, the archive prefix, one unfinished non-blank city, native
253+
// leg only.
254+
INTERPRETER_CODE_PATTERN.test(call.args.code);
250255
if (anomaly) {
251256
classification = "NOT_TRIGGERED";
252257
reason = "approved-interpreter-anomaly";
@@ -530,6 +535,12 @@ const interpreterObjectLondon: RetainedCase = {
530535
function editInterpreterStream(edit: (chunks: JsonObject[]) => void) {
531536
return derivative(interpreterStream, edit);
532537
}
538+
function derivativeCase(cell: RetainedCase, city: string) {
539+
const raw = derivative(cell, (chunks) => {
540+
interpreter(chunks).args = { code: `${INTERPRETER_PREFIX}${city}` };
541+
});
542+
return { id: cell.id, cell, raw };
543+
}
533544

534545
describe("Vertex native interpreter anomaly in stream mode and its first-city variants", () => {
535546
it.each([interpreterStream, interpreterStreamLondon, interpreterObjectLondon])(
@@ -555,6 +566,29 @@ describe("Vertex native interpreter anomaly in stream mode and its first-city va
555566
},
556567
);
557568

569+
// The K5 prompt names no cities, so a first city never seen live is still the anomaly.
570+
const parisVariants = [
571+
derivativeCase(interpreterStream, "Paris"),
572+
derivativeCase(interpreterObjectLondon, "Paris"),
573+
];
574+
it.each(parisVariants)("classifies the $id anomaly with an unseen first city", async (cell) => {
575+
const { observation, decoded } = await replay(cell.cell, cell.raw);
576+
const result = compareVertexObservation(cell.cell, observation, decoded, "native");
577+
expect(result.classification).toBe("NOT_TRIGGERED");
578+
expect(result.reason).toBe("approved-interpreter-anomaly");
579+
expect(result.terminal).toBe("MAX_TOKENS");
580+
});
581+
582+
it.each(parisVariants)(
583+
"rejects the $id anomaly with an unseen first city on the modeled leg",
584+
async (cell) => {
585+
const { observation, decoded } = await replay(cell.cell, cell.raw);
586+
expect(() => compareVertexObservation(cell.cell, observation, decoded, "modeled")).toThrow(
587+
/contradictory-target/,
588+
);
589+
},
590+
);
591+
558592
it.each<{ name: string; edit: (chunks: JsonObject[]) => void; error: RegExp }>([
559593
{
560594
name: "a STOP terminal",
@@ -608,9 +642,42 @@ describe("Vertex native interpreter anomaly in stream mode and its first-city va
608642
error: /contradictory-target/,
609643
},
610644
{
611-
name: "an unobserved first city",
645+
name: "an empty first city",
646+
edit: (chunks) => {
647+
interpreter(chunks).args = { code: "print(default_api.archive(cities=['" };
648+
},
649+
error: /contradictory-target/,
650+
},
651+
...[
652+
["an empty quoted city", "''"],
653+
["a whitespace-only city", " "],
654+
["a finished archive call", "Tokyo'])"],
655+
["trailing code after the city list", "Tokyo'] + x"],
656+
].map(([name, rest]) => ({
657+
name,
658+
edit: (chunks: JsonObject[]) => {
659+
interpreter(chunks).args = { code: `${INTERPRETER_PREFIX}${rest}` };
660+
},
661+
error: /contradictory-target/,
662+
})),
663+
{
664+
name: "leading code before the archive call",
665+
edit: (chunks) => {
666+
interpreter(chunks).args = { code: `x = 1; ${INTERPRETER_PREFIX}Paris` };
667+
},
668+
error: /contradictory-target/,
669+
},
670+
{
671+
name: "a non-archive tool in the interpreter code",
672+
edit: (chunks) => {
673+
interpreter(chunks).args = { code: "print(default_api.search(cities=['Paris" };
674+
},
675+
error: /contradictory-target/,
676+
},
677+
{
678+
name: "a different interpreter code prefix",
612679
edit: (chunks) => {
613-
interpreter(chunks).args = { code: "print(default_api.archive(cities=['Paris" };
680+
interpreter(chunks).args = { code: "print(default_api.archive(names=['Paris" };
614681
},
615682
error: /contradictory-target/,
616683
},

0 commit comments

Comments
 (0)