Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
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
28 changes: 18 additions & 10 deletions .github/workflows/fix-drift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -928,10 +928,13 @@ jobs:
# commitSyncChanges, but that commit lives only in the runner's working tree,
# and the "Push branch + create PR" step above fires only on
# reason == 'ok-applied'. So this step pushes a DISTINCT branch and opens a
# needs-human PR. NO AUTO-MERGE: a human sets `Decision: include` (or closes
# to reject) and merges, and the NEXT drift-sync run reads the approved note
# from main and applies the mechanical edit. Without a persisted note that
# two-run hand-off can never start.
# needs-human PR. NO AUTO-MERGE, and NO two-run hand-off for a new family:
# `includeFamilies` is checksum-pinned, so adding a family moves the pin and
# reds the freeze test gate-2 re-runs, while gate-1's allowlist bars drift-sync
# from re-pinning — a follow-up run reports `gate-failed`, not `ok-applied`. A
# human classifies BY HAND in one commit (registry + both re-pins + the note +
# the offline /models wave) and closes the PR. The note still has to persist:
# it is what makes the decision reachable and reviewable in the repo.
#
# Re-fire discipline (no PR spam): three layers, idempotent in EVERY run
# shape, applied in this order. PRIMARY — skip when an open PR already carries
Expand Down Expand Up @@ -1563,12 +1566,17 @@ jobs:
echo "structural mismatch). It wrote the note file(s) below and opened this PR so"
echo "the decision is REACHABLE in the repo."
echo ""
echo "> **Not auto-merged — a human decides.** For a *new-family* note: set the"
echo "> note's decision line to \`Decision: include\` (to classify it) or delete the"
echo "> note / close this PR (to reject), then **merge this PR**. The NEXT drift-sync"
echo "> run reads the approved note from \`main\` and mechanically applies the registry"
echo "> edit (still zero-LLM — a human-authored marker, not generated code), opening a"
echo "> separate data-only PR. That two-run hand-off is how the loop closes."
echo "> **Not auto-merged — a human decides, and applies it by hand.**"
echo "> For a *new-family* note, DO NOT expect merging this PR to apply anything:"
echo "> \`includeFamilies\` is checksum-pinned, and adding a family moves that pin,"
echo "> which reds the freeze test gate-2 re-runs. drift-sync cannot re-pin — the"
echo "> gate-1 allowlist permits only \`model-registry.ts\` and \`drift-proposals/\`."
echo "> So a follow-up run would report \`gate-failed\`, not \`ok-applied\`."
echo ">"
echo "> The procedure that actually works, in ONE commit: add the family to"
echo "> \`includeFamilies\` (or \`excludeFamilies\` to reject), re-pin BOTH checksums,"
echo "> resolve the note file(s) below, and update the offline \`/models\` wave."
echo "> Then close this PR. Prior examples: 72f85f8, 936b59c."
echo ""
echo "### Note file(s) in this PR"
echo ""
Expand Down
40 changes: 40 additions & 0 deletions drift-proposals/gemini-gemini-3.7-flash-new-family.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# New / unclassified model family: gemini-3.7-flash

Provider: gemini
Detected: 2026-08-14
Status: RESOLVED — decision recorded below and applied to the registry

This model family appeared in a live /models listing but matches no classification rule (include, exclude, -preview, gemma). drift-sync never silently classifies a new family.

## Decision

<!-- drift-sync never auto-classifies a new family. To approve adding it to
the registry, change the line below to `Decision: include` — the NEXT
drift-sync run will then apply the mechanical registry edit (still
zero-LLM: this is a human-authored decision, not generated code). -->

<!-- NOTE: the automated `Decision: include` path CANNOT apply this one. It
writes into `includeFamilies.gemini`, whose membership is checksum-pinned
in `logic-pin.test.ts` (DATA_FROZEN), and drift-sync-check gate-2 re-runs
that exact test after the edit. drift-sync cannot update the pin — the
gate-1 changed-file allowlist admits only `model-registry.ts` and
`drift-proposals/`, so `logic-pin.test.ts` is off-limits to it. Leaving
`Decision: include` here would therefore produce `reason=gate-failed` and
revert the edit, not `ok-applied`. Verified: the add moves the pin from
c2e2c56b… to 566fb89a… and reds `freezes includeFamilies.gemini
membership`. So the include is applied BY HAND together with its re-pin,
in one reviewed commit — the same way every prior classification landed
(72f85f8 claude-opus-5, aa51d0c gemini-3.5-flash-lite/3.6-flash). -->

Decision: INCLUDE (applied — includeFamilies.gemini in
`src/__tests__/drift/model-registry.ts`, with the `includeFamilies.gemini`
re-pin in `src/__tests__/drift/logic-pin.test.ts`).

Rationale: stable GA text tier. Google's live /models entry declares
`supportedGenerationMethods: [generateContent, countTokens, createCachedContent,
batchGenerateContent]` — byte-identical to the already-included
`gemini-3.6-flash`, `gemini-3.5-flash`, `gemini-2.5-flash` and `gemini-2.5-pro`
— with `displayName: "Gemini 3.7 Flash"` and no preview, experimental,
confidential or EAP marker. It declares no `bidiGenerateContent` (so it is not a
Live/native-audio surface), no `embedContent`, and no `predict`. It is the next
release in the flash line aimock already mocks at 3.5 and 3.6.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# New / unclassified model family: gemini-3.7-flash-video-understanding-eap

Provider: gemini
Detected: 2026-08-15
Status: RESOLVED — decision recorded below and applied to the registry

This model family appeared in a live /models listing but matches no classification rule (include, exclude, -preview, gemma). drift-sync never silently classifies a new family.

## Decision

<!-- drift-sync never auto-classifies a new family. To approve adding it to
the registry, change the line below to `Decision: include` — the NEXT
drift-sync run will then apply the mechanical registry edit (still
zero-LLM: this is a human-authored decision, not generated code). -->

<!-- NOTE: the `Decision: include` marker documented above is drift-sync's
AUTOMATED path, and it writes EXCLUSIVELY into `includeFamilies`
(scripts/drift-sync.ts: addFamilyLiteralInSource(..., "includeFamilies", ...)).
There is no automated exclude path, so an EXCLUDE decision is recorded here
in prose and applied by hand — writing `include` would misclassify. -->

Decision: EXCLUDE (applied — excludeFamilies.gemini in
`src/__tests__/drift/model-registry.ts`, with the `excludeFamilies.gemini`
re-pin in `src/__tests__/drift/logic-pin.test.ts`).

Rationale: gated PRE-GA surface, not a stable tier. This is the only one of the
54 entries in the live Gemini /models listing whose provider-declared
`displayName` AND `description` are "[Confidential] Gemini 3.7 Flash Video
Understanding EAP" — an Early Access Program model visible only to allowlisted
keys. aimock does not mock pre-GA surfaces, which is exactly the policy
PREVIEW_FAMILY applies to every `-preview` tier; this id carries no trailing
`-preview` token, so that rule cannot reach it and it must be enumerated.

NOT rejected for being "video" by name. It genuinely declares
`supportedGenerationMethods: [generateContent, countTokens, createCachedContent,
batchGenerateContent]` — the same method set as its GA sibling
`gemini-3.7-flash` — so it IS text-capable, and a name-substring rule would have
been the wrong instrument (compare the native-audio misclassification, where the
declared capability, not the id, was the deciding evidence: the live
`gemini-2.5-flash-native-audio-latest` entry declares only `countTokens` and
`bidiGenerateContent`, and no `generateContent` at all). The disqualifier here is
access status, and it is provider-declared metadata rather than an inference from
the id string.
64 changes: 63 additions & 1 deletion src/__tests__/agui-mock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as http from "node:http";
import * as fs from "node:fs";
import * as os from "node:os";
import * as path from "node:path";
import type { AGUIEvent, AGUIRunAgentInput } from "../agui-types.js";
import type { AGUIEvent, AGUIRunAgentInput, AGUITokenUsage } from "../agui-types.js";
import { AGUIMock } from "../agui-mock.js";
import {
buildTextResponse,
Expand Down Expand Up @@ -1710,6 +1710,68 @@ describe("AGUIMock recorder — structured user content", () => {
// NO_USER_MESSAGE_SENTINEL — wire-format compatibility guard
// ---------------------------------------------------------------------------

describe("AG-UI token usage on terminal events", () => {
const usage: AGUITokenUsage[] = [
{
provider: "openai",
model: "gpt-4o",
inputTokens: 12,
outputTokens: 34,
totalTokens: 46,
reasoningTokens: 5,
cachedInputTokens: 2,
},
];

it("buildTextResponse attaches usage to RUN_FINISHED when supplied", () => {
const events = buildTextResponse("hello", { usage });
const finished = events.find((e) => e.type === "RUN_FINISHED") as unknown as Record<
string,
unknown
>;
expect(finished.usage).toEqual(usage);
});

it("buildErrorResponse attaches usage to RUN_ERROR when supplied", () => {
const events = buildErrorResponse("boom", "ERR_500", { usage });
const errored = events.find((e) => e.type === "RUN_ERROR") as unknown as Record<
string,
unknown
>;
expect(errored.usage).toEqual(usage);
});

it("never synthesizes usage when the caller does not supply it", () => {
// aimock does not estimate token counts from fixture content (same policy
// as the Bedrock/Cohere/Gemini usage overrides): absent in, absent out.
const finished = buildTextResponse("hello").find(
(e) => e.type === "RUN_FINISHED",
) as unknown as Record<string, unknown>;
expect("usage" in finished).toBe(false);

const errored = buildErrorResponse("boom").find(
(e) => e.type === "RUN_ERROR",
) as unknown as Record<string, unknown>;
expect("usage" in errored).toBe(false);
});

it("emits usage over the wire on the SSE stream", async () => {
agui = new AGUIMock({ port: 0 });
agui.onRun("usage please", buildTextResponse("ok", { usage }));
await agui.start();

const resp = await post(agui.url, aguiInput("usage please"));
expect(resp.status).toBe(200);

const parsed = parseSSEEvents(resp.body);
const finished = parsed.find((e) => e.type === "RUN_FINISHED") as unknown as Record<
string,
unknown
>;
expect(finished.usage).toEqual(usage);
});
});

describe("NO_USER_MESSAGE_SENTINEL", () => {
it("preserves the historical on-disk sentinel string", () => {
// Locking the literal value: existing recorded fixtures on disk use this
Expand Down
48 changes: 48 additions & 0 deletions src/__tests__/drift/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,38 @@ export const AUDIO_FIXTURE: Fixture = {
/** The prompt that selects {@link AUDIO_FIXTURE} on both sides of a drift leg. */
export const AUDIO_PROMPT = "Greet me aloud";

/**
* Tool-call fixture for the Gemini Live drift leg.
*
* A Live session carries exactly ONE response modality and it is `AUDIO`, so a
* turn in which the model calls a function is an AUDIO turn that ALSO calls it:
* the model speaks (`serverContent`) and then asks for the call (`toolCall`).
* The shared {@link TOOL_FIXTURE} describes a text-protocol tool turn — tool
* call and nothing else — so driving the Live leg's mock side with it produces
* a bare `toolCall` with no model turn at all.
*
* That mis-drive is what run 31896605497's head report recorded as
* `SSE:serverContent … mock:"<absent>"`, and the ORDER in it is not a guess: the
* probe collects up to and including the FIRST `toolCall`, the real leg's
* `toolCallCount > 0` assertion passed, and a `serverContent` was nonetheless
* present in what it collected — so the provider sent `serverContent` strictly
* BEFORE the `toolCall`. It is the same class of error as the TEXT-modality
* request that mis-drove the REAL side: one side driven into a shape the
* session's modality cannot produce.
*
* NOT PROVEN: the fields of the provider's pre-`toolCall` `serverContent`. The
* artifact records the event TYPE only. `AUDIO` being the session's sole
* modality, audio parts are the shape reproduced here; confirming the
* provider's exact fields needs a live run.
*/
export const LIVE_TOOL_FIXTURE: Fixture = {
match: { userMessage: "Weather in Paris" },
response: {
audio: { b64Json: "AAAAAA==", contentType: "audio/pcm;rate=24000" },
toolCalls: [{ name: "get_weather", arguments: '{"city":"Paris"}' }],
},
};

// ---------------------------------------------------------------------------
// Server lifecycle
// ---------------------------------------------------------------------------
Expand All @@ -188,6 +220,22 @@ export async function startDriftServer(): Promise<ServerInstance> {
});
}

/**
* Drift server for the Gemini Live legs.
*
* Separate from {@link startDriftServer} because the Live leg's fixtures are
* modality-specific: {@link LIVE_TOOL_FIXTURE} answers the same
* `"Weather in Paris"` prompt as the shared {@link TOOL_FIXTURE} but with the
* AUDIO turn a Live session actually produces. Putting it on the shared server
* would mean either shadowing `TOOL_FIXTURE` for every other provider's tool
* leg or gating it on a model-name pattern — and a Live model is not
* identifiable by its name (see the header of ws-gemini-live.drift.ts). A
* dedicated instance needs neither.
*/
export async function startGeminiLiveDriftServer(): Promise<ServerInstance> {
return createServer([AUDIO_FIXTURE, LIVE_TOOL_FIXTURE], { port: 0, chunkSize: 100 });
}

export async function stopDriftServer(instance: ServerInstance): Promise<void> {
await new Promise<void>((r) => instance.server.close(() => r()));
}
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/drift/logic-pin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ const DATA_FROZEN: Record<string, { members: () => string[]; pin: string }> = {
},
"includeFamilies.gemini": {
members: () => [...includeFamilies.gemini].sort(),
pin: "c2e2c56b8f8d5fc56152b4633e7d3782e95b7eeb9bc123da71f00e884a54a743",
pin: "566fb89af6862badeff1d95ecfa511dcd1fc757feeb60a8ff8fec563952cadbc",
},
"excludeFamilies.openai": {
members: () => [...excludeFamilies.openai].sort(),
Expand All @@ -441,7 +441,7 @@ const DATA_FROZEN: Record<string, { members: () => string[]; pin: string }> = {
},
"excludeFamilies.gemini": {
members: () => [...excludeFamilies.gemini].sort(),
pin: "c95dedab7588212bbba0bf9ab6434bfd43a449adbe7b35f81f48271ee849a9c2",
pin: "3c8fb0b7cee776619467afd34407bde69e30b063ae263da4871096e7a7afca1d",
},
// The realtime canary's seed sets, previously pinned NOWHERE. An edit to
// either one was invisible to every guard in the repo: adding a family to
Expand Down
16 changes: 16 additions & 0 deletions src/__tests__/drift/model-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ export const includeFamilies: Record<Provider, Set<string>> = {
"gemini-3.5-flash",
"gemini-3.5-flash-lite",
"gemini-3.6-flash",
"gemini-3.7-flash",
]),
};

Expand Down Expand Up @@ -286,6 +287,21 @@ export const excludeFamilies: Record<Provider, Set<string>> = {
"gemini-2.0-flash-thinking-exp",
// Live/full-duplex voice — owned by the realtime canary, not this text check
"gemini-live",
// Restricted EARLY-ACCESS (EAP) surface, not a GA tier. Google's own live
// /models entry declares `displayName` AND `description` as
// "[Confidential] Gemini 3.7 Flash Video Understanding EAP" — the only one
// of the 54 live entries carrying either marker. NOT excluded for being
// "video" by name: it genuinely declares `generateContent` (same method set
// as its GA sibling gemini-3.7-flash), so it IS text-capable. It is excluded
// because it is a gated pre-GA surface, which is the same policy
// PREVIEW_FAMILY applies to every `-preview` tier — aimock does not mock
// pre-GA surfaces. It carries no trailing `-preview` token, so that rule
// cannot reach it and it must be enumerated here (mirrors the
// `-preview-tts` / `-preview-customtools` entries above).
//
// Decision: EXCLUDE, recorded in
// drift-proposals/gemini-gemini-3.7-flash-video-understanding-eap-new-family.md.
"gemini-3.7-flash-video-understanding-eap",
// NOTE: every `-preview` family (gemini-3.x preview tiers, deep-research
// previews, antigravity-preview-05, computer-use-preview-10, image/tts/robotics
// previews, lyria/veo/nano-banana previews, gemini-embedding-2-preview, …) is
Expand Down
3 changes: 3 additions & 0 deletions src/__tests__/drift/models.drift.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,9 @@ describe("full live /models wave is fully classified (2026-07-16 drift)", () =>
"gemini-3.5-flash",
"gemini-3.5-flash-lite",
"gemini-3.6-flash",
"gemini-3.7-flash",
// Restricted EAP surface — explicit exclude (text-capable, but pre-GA)
"gemini-3.7-flash-video-understanding-eap",
// Preview text tiers — auto-excluded by the -preview pattern rule
"gemini-3-flash-preview",
"gemini-3-pro-preview",
Expand Down
26 changes: 26 additions & 0 deletions src/__tests__/drift/sdk-shapes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1252,6 +1252,32 @@ export function geminiLiveAudioEventShapes(): SSEEventShape[] {

export function geminiLiveToolCallEventShapes(): SSEEventShape[] {
return [
// The model turn that precedes the call. A Live session carries exactly one
// response modality and it is AUDIO, so the turn in which the model decides
// to call a function is itself an audio turn — `serverContent` and
// `toolCall` are alternatives of `LiveServerMessage`'s message union, so
// they arrive as two messages, `serverContent` first.
//
// Listing it here is what lets the leg grade the event's FIELDS and not
// merely its presence: `triangulateAt` raises critical drift only for a
// field the SDK shape and the real API both have and the mock lacks, so
// without a `serverContent` entry a field-level regression on it could
// never be critical.
//
// NOT PROVEN: that the provider's pre-`toolCall` `serverContent` carries
// inlineData audio specifically. The drift artifact records the event type
// only. A field the real API turns out not to send grades as `SDK EXTRA`
// (info), never as a false critical.
{
type: "serverContent",
dataShape: extractShape({
serverContent: {
modelTurn: {
parts: [{ inlineData: { mimeType: "audio/pcm;rate=24000", data: "AAAAAA==" } }],
},
},
}),
},
{
type: "toolCall",
dataShape: extractShape({
Expand Down
Loading
Loading