Skip to content

Commit 3468cea

Browse files
committed
fix(google-antigravity): keep the sentinel out of the real-signature path
Exact-head CI failed three shards that the focused suite did not show — this round's own gate 4 firing on me, since I chose the targets. Five tests in four other suites assert thoughtSignature === undefined and the sentinel filled it. Investigating those five surfaced two REAL defects, not just assertion drift: 1. observeAntigravityReplay cached the sentinel as if it were a genuine signature, so a fabricated token round-tripped into the replay cache and was replayed later as evidence a turn was signed. extractSignature now refuses it on both the direct and nested paths; observing it leaves the cache empty (0 sessions) instead of storing it. 2. isLikelyRealThoughtSignature accepted it — the sentinel is alphanumeric with underscores, so it passed every filter that rejects fc_/ctc_/tsc_ synthetic ids. It is now rejected by name, which is what the issue #174 tests were protecting: a fabricated id must never be treated as real. With both closed, the five assertions are genuinely proxies. They read 'undefined' to mean 'nothing was borrowed from another call, thread, or namespace', and a constant carries no other call's identity. Verified directly: thread-a records a real signature, thread-b replays the same call in a different session, and thread-b receives the sentinel — never thread-a's value. Each assertion now expects the sentinel and states why the property still holds. The PR body for #2693 confirms the sentinel belongs on replayed history too: upstream rejects any multi-turn functionCall lacking a signature, not just the current turn. So narrowing it to fresh turns would reintroduce the 400. 159 pass / 0 fail across all four affected suites; tsc exit 0.
1 parent d829215 commit 3468cea

5 files changed

Lines changed: 21 additions & 7 deletions

‎src/adapters/google-antigravity-replay.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,10 +512,10 @@ export function antigravityReplaySessionKeysForTests(): string[] {
512512

513513
function extractSignature(part: Record<string, unknown>): string | undefined {
514514
const direct = part.thoughtSignature ?? part.thought_signature;
515-
if (typeof direct === "string" && direct.length >= MIN_SIGNATURE_LEN) return direct;
515+
if (typeof direct === "string" && direct.length >= MIN_SIGNATURE_LEN && direct !== THOUGHT_SIGNATURE_BYPASS) return direct;
516516
const extra = part.extra_content as { google?: { thought_signature?: unknown } } | undefined;
517517
const nested = extra?.google?.thought_signature;
518-
if (typeof nested === "string" && nested.length >= MIN_SIGNATURE_LEN) return nested;
518+
if (typeof nested === "string" && nested.length >= MIN_SIGNATURE_LEN && nested !== THOUGHT_SIGNATURE_BYPASS) return nested;
519519
return undefined;
520520
}
521521

‎src/adapters/google-antigravity-wire.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ export const ANTIGRAVITY_REQUEST_UA = antigravityUserAgent();
2929
*/
3030
export function isLikelyRealThoughtSignature(sig: string | undefined): boolean {
3131
if (typeof sig !== "string" || sig.length < 16) return false;
32+
// The validator-bypass sentinel is something WE fabricate for outbound requests when no real
33+
// signature exists. It is alphanumeric with underscores, so it would otherwise satisfy every
34+
// check below and be re-ingested as genuine — cached, replayed, and eventually treated as
35+
// evidence that a turn was signed. It is never a real signature.
36+
if (sig === "skip_thought_signature_validator") return false;
3237
// Reject synthetic Responses/tool-call ids and Anthropic tool-use ids (`_` or `-` separators).
3338
if (/^(fc|ctc|tsc|call|msg|rs|resp|reasoning|item|ws|toolu|tool|func|function)[-_]/i.test(sig)) return false;
3439
// Real Gemini thought signatures are opaque base64/base64url blobs: only [A-Za-z0-9+/_=-].

‎tests/google-antigravity-wire.test.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,10 @@ describe("antigravity history preserves tool-call thoughtSignature", () => {
777777
const env = JSON.parse(req.body);
778778
const modelTurn = (env.request.contents as { role: string; parts: Record<string, unknown>[] }[]).find(c => c.role === "model");
779779
const fcPart = modelTurn?.parts.find(part => "functionCall" in part);
780-
expect(fcPart?.thoughtSignature).toBeUndefined();
780+
// The synthetic fc_ id is still stripped — what lands is the constant bypass sentinel,
781+
// fabricated here rather than forwarded from the client. isLikelyRealThoughtSignature
782+
// rejects both, so neither can be cached or replayed as a genuine signature.
783+
expect(fcPart?.thoughtSignature).toBe("skip_thought_signature_validator");
781784
});
782785

783786
test("custom_tool_call item ids (ctc_...) from Claude/mixed history are NOT forwarded (issue #174)", async () => {
@@ -797,7 +800,8 @@ describe("antigravity history preserves tool-call thoughtSignature", () => {
797800
const env = JSON.parse(req.body);
798801
const modelTurn = (env.request.contents as { role: string; parts: Record<string, unknown>[] }[]).find(c => c.role === "model");
799802
const fcPart = modelTurn?.parts.find(part => "functionCall" in part);
800-
expect(fcPart?.thoughtSignature).toBeUndefined();
803+
// Same contract for ctc_ ids: not forwarded; the sentinel is injected in their place.
804+
expect(fcPart?.thoughtSignature).toBe("skip_thought_signature_validator");
801805
});
802806
});
803807

‎tests/google-signature-history-roundtrip.test.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,9 @@ describe("#1735 thought signature survives history replay", () => {
311311
});
312312
const request = await createGoogleAdapter(provider).buildRequest(parsed);
313313
const part = modelParts(request.body as string).find(candidate => "functionCall" in candidate);
314-
expect(part?.thoughtSignature).toBeUndefined();
314+
// The sentinel, not a borrowed signature: nothing was inherited from another call. The
315+
// property this guards is anti-borrowing, and a constant carries no other call's identity.
316+
expect(part?.thoughtSignature).toBe("skip_thought_signature_validator");
315317
});
316318

317319
test("a signature the proxy remembered re-signs a replay the client sent without extra_content", async () => {
@@ -430,7 +432,8 @@ describe("#1735 thought signature survives history replay", () => {
430432
});
431433
const request = await createGoogleAdapter(provider).buildRequest(parsed);
432434
const part = modelParts(request.body as string).find(candidate => "functionCall" in candidate);
433-
expect(part?.thoughtSignature).toBeUndefined();
435+
// Unknown call_id borrows nothing; it receives the constant bypass sentinel instead.
436+
expect(part?.thoughtSignature).toBe("skip_thought_signature_validator");
434437
});
435438

436439
test("the same call_id in a different thread does not borrow the signature (#1823)", () => {

‎tests/google-vertex-thought-signature.test.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,9 @@ describe("Vertex thought-signature continuation (#1254)", () => {
126126
const otherThread = await createGoogleAdapter(provider).buildRequest(
127127
scopedReplayRequest(continuation(), "thread-b", "shared-cache-cohort"),
128128
);
129-
expect(replayedFunctionCall(otherThread.body as string).thoughtSignature).toBeUndefined();
129+
// #1312 isolation still holds: thread-b gets the CONSTANT sentinel, never thread-a's real
130+
// signature. A genuine cross-namespace leak would surface the real value here and fail.
131+
expect(replayedFunctionCall(otherThread.body as string).thoughtSignature).toBe("skip_thought_signature_validator");
130132

131133
const originalThread = await createGoogleAdapter(provider).buildRequest(
132134
scopedReplayRequest(continuation(), "thread-a", "different-cache-cohort"),

0 commit comments

Comments
 (0)