Skip to content

test: accept Gemini Interactions upstream nondeterminism on live native legs - #522

Merged
jpr5 merged 2 commits into
mainfrom
fix/drift-gemini-interactions-k5-k9
Oct 11, 2026
Merged

jpr5 merged 2 commits into
mainfrom
fix/drift-gemini-interactions-k5-k9

Conversation

@jpr5

@jpr5 jpr5 commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Three "Gemini Interactions live incomplete contracts" drift tests fail now and then on main (Scheduled Drift Tests run 38030209547, and PR #520's drift-live-pr run 38091527077):

  • 'K5 object': expected 400 to be 200
  • 'K9 object': expected [...] to have a length of 1 but got 2 (steps)
  • 'K9 stream': same cause, seen in run 37994194206

Root cause: upstream model nondeterminism

aimock and the test's request are both fine. I re-sent the test's exact requests to live gemini-2.5-flash on 2026-10-10:

Request Matches the capture Variant
K5 object 26/28 2/28: HTTP 400 {"error":{"message":"Model generated invalid JSON syntax ...","code":"malformed_tool_call"}}
K9 object 44/47 3/47: a trailing model_output step after the thought (1-2 output tokens)
K9 stream 46/47 1/47: a thought_signature delta, then a model_output step with one text delta (plus one failed local test run)

The failing K9 assertion is the native-side check (incompleteContract(nativeRaw), line 510), not localhost.

I also tried making the K9 trigger reliable by changing the request. No value fixed it:

max_output_tokens 8 16 24 28 32 (kept) 48 64 128
Object variant 4/6 6/6 4/6 6/6 ~3/47 0/6 6/6 6/6
Stream variant 6/6 6/6 4/6 6/6 ~1/47 1/6 6/6 6/6

thinking_level: "low" was worse (3/6 and 4/6). "medium" is rejected with a 400 by this model.

Change (one test file only)

  • K5: the live native leg also accepts HTTP 400 whose body is exactly {"error":{"message":<string>,"code":"malformed_tool_call"}}. Any other status, code or body shape still fails. Localhost is still graded strictly against the capture.
  • K9 (object and stream): the live native leg also accepts exactly one trailing model_output step with one non-empty text part.
    • Object: 1-6 output tokens.
    • Stream: one thought_signature delta closing step 0, then 1-6 text deltas in step 1.
    • The variant is validated, then removed, and the rest must pass the unchanged strict thought-only contract.
    • max_output_tokens stays at 32. Captured references, derived segmentation tests and localhost stay strict.
  • Real native captures of all three variants are embedded with their sha256. New tests check that the variants are accepted, that they are rejected outside the live native leg, and that mutated shapes are rejected.

Mutation check

These tests run without a key. I changed the new contract code one way at a time to see whether a test catches each change. All 12 changes were caught (at least 1 test failed for each):

  • remove either output-token bound, or either stream text-delta bound
  • remove the signature-delta check, the answer step.start check, the object answer shape check, or the non-empty answer text checks
  • accept any K5 error code, or any HTTP status
  • apply the variant outside the live native leg

Rejected mutant shapes include:

  • K9 object: two model_output steps, wrong order, wrong step type, an extra field, empty or doubled content, 0 or 7 output tokens, output_text set, status: completed
  • K9 stream: missing or wrong-type signature, no answer delta, a second answer step, 7 deltas, empty text, the answer in the terminal interaction
  • K5: codes invalid_request or MALFORMED_TOOL_CALL, a missing code, extra fields, statuses 200/429/500, a non-JSON body

RED (before, live, npx vitest run --config vitest.config.drift.ts src/__tests__/drift/gemini-interactions.drift.ts -t "live incomplete")

   ✓ ... live incomplete contracts > 'K5 object' matches native and localhost  834ms
   × ... live incomplete contracts > 'K9 stream' matches native and localhost 1617ms
     → expected [ 'interaction.created', …(9) ] to deeply equal [ 'interaction.created', …(7) ]
       (live stream had: step.delta, step.stop, step.start, step.delta, step.stop — a second step)
 ❯ incompleteContract gemini-interactions.drift.ts:430:22
 ❯ compareLocalIncomplete gemini-interactions.drift.ts:510:10   <- native side
      Tests  1 failed | 2 passed | 21 skipped (24)

The K5 400 and K9 object variant reproduced in direct live probes (table above). CI shows the same failures.

GREEN (after, live, npx vitest run --config vitest.config.drift.ts src/__tests__/drift/gemini-interactions.drift.ts, two consecutive runs)

== run 1
   ✓ ... live incomplete contracts > 'K5 object' matches native and localhost  590ms
   ✓ ... live incomplete contracts > 'K9 stream' matches native and localhost  1157ms
   ✓ ... live incomplete contracts > 'K9 object' matches native and localhost  1593ms
      Tests  30 passed (30)
== run 2
   ✓ ... live incomplete contracts > 'K5 object' matches native and localhost  594ms
   ✓ ... live incomplete contracts > 'K9 stream' matches native and localhost  1390ms
   ✓ ... live incomplete contracts > 'K9 object' matches native and localhost  2103ms
      Tests  30 passed (30)

At a ~5% rate, the live runs mostly exercise the strict path. The keyless variant tests exercise the accept path with real captured variant bodies.

Gates

pnpm typecheck, pnpm lint, pnpm format:check and pnpm build all pass. pnpm test: 377 files, 14073 passed, 3 skipped. No src/ changes, so the public API and types are unchanged.

Review follow-up

I checked the review findings against live evidence before changing anything:

  • A1 (K9 stream usage stays strict at 0 output tokens): no change. 13 live K9 stream variants with the trailing model_output step all report total_output_tokens: 0 in final usage: 11 new probes at max_output_tokens: 16, where the variant shows up 11/12 times, plus the two earlier captures. A further 20 probes at 32 had no variant. Unlike the object, the stream reports 0, so the strict check is correct.
  • A2 (K5 stream rejects thought_signature deltas): no change. None of 20 live K5 stream calls had a thought step or a thought_signature delta. 19 had no steps at all, and 1 returned HTTP 400 malformed_tool_call. The signature capture in this PR is a K9 stream.
  • B: the live-contract comment now names the two accepted upstream variants.

Re-check after this change: the live drift command for this file passed 30/30 on two more consecutive runs. All gates pass again, and pnpm test is 14073 passed, 3 skipped.

Earlier CI note: test (22) failed once on validate CLI — report-mode consistency > does not print OK ... because the random temp dir /tmp/aimock-validate-modes-GEgOKg contains "OK". The same test failed on main in run 38007611924. The rerun passed.

…ve legs

The live K5 object request sometimes gets a 400 malformed_tool_call from
Google (2/28 calls), and the live K9 requests sometimes add one trailing
model_output step after the thought (3/47 object, 1/47 stream). No
max_output_tokens value from 8 to 128, and no thinking_level, made the
trigger reliable.

The live native leg now accepts exactly these variants. The K9 variant is
validated, then removed, and the rest must pass the unchanged strict
thought-only contract. Captured references and localhost stay strict. Real
variant captures and mutations pin both the accepted and rejected shapes.
@pkg-pr-new

pkg-pr-new Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@copilotkit/aimock@522

commit: ee6c578

@jpr5
jpr5 merged commit b9cff07 into main Oct 11, 2026
36 of 37 checks passed
@jpr5
jpr5 deleted the fix/drift-gemini-interactions-k5-k9 branch October 11, 2026 02:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant