Skip to content

fix(google): replay Vertex thought signatures - #1266

Merged
lidge-jun merged 1 commit into
devfrom
agent/fix-1254-vertex-thought-signature
Aug 8, 2026
Merged

fix(google): replay Vertex thought signatures#1266
lidge-jun merged 1 commit into
devfrom
agent/fix-1254-vertex-thought-signature

Conversation

@Ingwannu

@Ingwannu Ingwannu commented Aug 8, 2026

Copy link
Copy Markdown
Owner

Closes #1254

Summary

  • preserve Vertex Gemini thoughtSignature values across Codex tool-result continuations by reusing the existing bounded TTL/LRU Google replay store
  • scope Vertex replay identities by transport, project, location, and the hashed opaque session key so provider-private state cannot cross into Antigravity
  • observe both streaming and non-streaming Vertex function-call responses, then re-inject only after Google tool names have been compiled
  • document the shared Vertex/Antigravity contract in the architecture source of truth and all adapter-reference locales

Root cause

The Google adapter wired signature observation and replay only for googleMode: "cloud-code-assist". Vertex used the same Gemini function-call wire but bypassed the replay store, so the first call succeeded and the next tool-result request omitted the required opaque signature and received HTTP 400.

Verification

  • bun test tests/google-vertex-thought-signature.test.ts tests/google-antigravity-replay.test.ts tests/google-antigravity-wire.test.ts tests/google-adapter.test.ts — 94 pass, 0 fail
  • bun run typecheck
  • bun run privacy:scan
  • bun run --cwd docs-site build — 221 pages
  • git diff --check
  • bun run test was also exercised under a two-core affinity. The changed Google suites passed; the host run exposed an unrelated existing codex-shim service-token path isolation failure. The initially missing GUI dependency was installed and its affected provider-rail suite then passed. Clean GitHub CI remains the authoritative full-suite gate.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults.

Summary by CodeRabbit

  • New Features

    • Vertex AI now preserves and reuses Gemini thought signatures across tool calls, supporting both streaming and non-streaming responses.
    • Reasoning continuity is maintained after tool results for Vertex AI and Antigravity.
    • Replay data is isolated across transport, project, location, and model contexts.
  • Documentation

    • Updated English, Japanese, Korean, Russian, and Simplified Chinese documentation to describe Vertex support.
    • Added details on signature replay behavior and session handling.

@coderabbitai

coderabbitai Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The Google adapter now preserves and replays Gemini thoughtSignature values for Vertex and Antigravity. Vertex uses transport-scoped replay namespaces, supports streaming and non-streaming responses, clears invalid replay state, and includes continuation tests and documentation updates.

Changes

Vertex thought-signature replay

Layer / File(s) Summary
Replay contract and session identity
src/adapters/google-antigravity-replay.ts, src/adapters/google.ts, structure/04_transports-and-sidecars.md
The replay cache is documented as Google-family functionality. Vertex session identity prefers promptCacheKey and otherwise uses the existing fallback. Vertex state includes transport-, project-, location-, and model-scoped replay identifiers.
Vertex request and response replay lifecycle
src/adapters/google.ts
Vertex applies cached signatures after tool-name compilation. Signature-related upstream errors clear the matching Vertex or Cloud Code Assist replay state. Streaming and non-streaming responses record Vertex signatures.
Replay validation and documentation
tests/google-vertex-thought-signature.test.ts, docs-site/src/content/docs/*/reference/adapters.md
Tests cover streaming, non-streaming, continuation replay, and separation from the Antigravity namespace. Adapter documentation now includes Vertex thought-signature preservation in English, Japanese, Korean, Russian, and Simplified Chinese.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant GoogleAdapter
  participant ReplayCache
  participant VertexAPI
  participant ToolContinuation
  GoogleAdapter->>ReplayCache: Apply cached thoughtSignature values
  GoogleAdapter->>VertexAPI: Send compiled request
  VertexAPI-->>GoogleAdapter: Return functionCall and thoughtSignature
  GoogleAdapter->>ReplayCache: Record thoughtSignature
  ToolContinuation->>GoogleAdapter: Submit tool result
  GoogleAdapter->>VertexAPI: Replay thoughtSignature in continuation
Loading

Possibly related PRs

  • lidge-jun/opencodex#971: Implements similar provider reasoning replay with scoped caches in another adapter path.

Suggested reviewers: lidge-jun, wibias

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The implementation and tests address issue #1254 by preserving and replaying Vertex thought signatures for streaming and non-streaming tool continuations.
Out of Scope Changes check ✅ Passed The code, tests, and documentation changes are directly related to Vertex thought-signature replay and issue #1254.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: replaying Vertex Gemini thought signatures in the Google adapter.
✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch agent/fix-1254-vertex-thought-signature

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added the bug Something isn't working label Aug 8, 2026
@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Deterministic PR hygiene checks passed.

@Ingwannu
Ingwannu force-pushed the agent/fix-1254-vertex-thought-signature branch from ae28b69 to c0ffaef Compare August 8, 2026 06:21
@lidge-jun
lidge-jun marked this pull request as ready for review August 8, 2026 09:16
@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

✅ READY

  • this PR is ready for review.

UI screenshot waived by a maintainer comment.

@github-actions
github-actions Bot marked this pull request as draft August 8, 2026 09:17

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/adapters/google.ts`:
- Around line 540-545: Centralize replay cleanup in a helper that selects the
Antigravity or Vertex model/session from provider.googleMode and matches
signature or invalid-argument errors, then invoke it from formatErrorBody, the
SSE chunk.error branch, and the non-streaming raw.error branch. Remove the
duplicated inline selection/match logic while preserving existing behavior, and
add regression coverage verifying a non-streaming or HTTP 400 rejection clears
replay state before a clean continuation.

In `@tests/google-vertex-thought-signature.test.ts`:
- Around line 58-71: Update the vertexResponseBody fixture to accept a parameter
selecting thoughtSignature or thought_signature, then parameterize the
continuation tests over both response spellings. Parse each variant and assert
that the subsequent request replays the exact SIGNATURE value.
- Around line 110-121: Extend the test around applyAntigravityReplay to record a
Vertex signature using one project or location, then build the same continuation
with a different value and assert its functionCall has no thoughtSignature.
Ensure the assertions specifically verify isolation across Vertex configuration
identifiers, not only between Vertex and Antigravity namespaces.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 42235640-70b4-42c8-b807-b85f13d961bb

📥 Commits

Reviewing files that changed from the base of the PR and between fdc47db and c0ffaef.

📒 Files selected for processing (9)
  • docs-site/src/content/docs/ja/reference/adapters.md
  • docs-site/src/content/docs/ko/reference/adapters.md
  • docs-site/src/content/docs/reference/adapters.md
  • docs-site/src/content/docs/ru/reference/adapters.md
  • docs-site/src/content/docs/zh-cn/reference/adapters.md
  • src/adapters/google-antigravity-replay.ts
  • src/adapters/google.ts
  • structure/04_transports-and-sidecars.md
  • tests/google-vertex-thought-signature.test.ts

Comment thread src/adapters/google.ts
Comment on lines +540 to +545
const replayModel = provider.googleMode === "cloud-code-assist" ? antigravityModel : vertexReplayModel;
const replaySession = provider.googleMode === "cloud-code-assist" ? antigravitySession : vertexReplaySession;
if ((provider.googleMode === "cloud-code-assist" || provider.googleMode === "vertex")
&& replayModel && replaySession
&& /signature|invalid_argument|invalid argument/i.test(err?.message ?? "")) {
clearAntigravityReplay(antigravityModel, antigravitySession);
clearAntigravityReplay(replayModel, replaySession);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Clear replay state for all signature rejection paths.

Lines 540-545 clear state only for an in-band SSE chunk.error. A non-streaming raw.error returns at line 778 without clearing state. An HTTP 400 is formatted through formatErrorBody at lines 327-329 without clearing state.

The stale signature is replayed on the next continuation until the TTL expires. Centralize the model/session selection and signature-error match in a helper. Call it from formatErrorBody, the SSE error branch, and the non-streaming raw.error branch. Add regression coverage for a non-streaming or HTTP 400 rejection followed by a clean continuation.

Proposed fix
+    const clearReplayOnSignatureError = (message: string): void => {
+      const replayModel = provider.googleMode === "cloud-code-assist"
+        ? antigravityModel
+        : vertexReplayModel;
+      const replaySession = provider.googleMode === "cloud-code-assist"
+        ? antigravitySession
+        : vertexReplaySession;
+      if ((provider.googleMode === "cloud-code-assist" || provider.googleMode === "vertex")
+        && replayModel && replaySession
+        && /signature|invalid_argument|invalid argument/i.test(message)) {
+        clearAntigravityReplay(replayModel, replaySession);
+      }
+    };
+
     ...(provider.googleMode === "vertex" || provider.googleMode === "cloud-code-assist"
       ? {
           fetchResponse: ...,
-          formatErrorBody: (status, _headers, payloadText) =>
-            ...,
+          formatErrorBody: (status, _headers, payloadText) => {
+            clearReplayOnSignatureError(payloadText);
+            return ...;
+          },
         }
       : {}),
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/adapters/google.ts` around lines 540 - 545, Centralize replay cleanup in
a helper that selects the Antigravity or Vertex model/session from
provider.googleMode and matches signature or invalid-argument errors, then
invoke it from formatErrorBody, the SSE chunk.error branch, and the
non-streaming raw.error branch. Remove the duplicated inline selection/match
logic while preserving existing behavior, and add regression coverage verifying
a non-streaming or HTTP 400 rejection clears replay state before a clean
continuation.

Comment on lines +58 to +71
function vertexResponseBody(): Record<string, unknown> {
return {
candidates: [{
content: {
role: "model",
parts: [{
functionCall: { name: "shell_command", args: { command: "pwd" } },
thoughtSignature: SIGNATURE,
}],
},
finishReason: "STOP",
}],
usageMetadata: { promptTokenCount: 5, candidatesTokenCount: 2 },
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Test both Vertex thought-signature field spellings.

vertexResponseBody() only emits thoughtSignature. The stated replay contract also accepts thought_signature. A regression in the snake_case response parser would pass both continuation tests and fail against affected Vertex responses.

Parameterize this fixture for both field names. Parse each response form, then assert that the next request replays the exact signature value.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/google-vertex-thought-signature.test.ts` around lines 58 - 71, Update
the vertexResponseBody fixture to accept a parameter selecting thoughtSignature
or thought_signature, then parameterize the continuation tests over both
response spellings. Parse each variant and assert that the subsequent request
replays the exact SIGNATURE value.

Comment on lines +110 to +121
test("Vertex signatures cannot enter the Antigravity replay namespace", async () => {
const first = firstTurn(false);
const adapter = createGoogleAdapter(provider);
await adapter.buildRequest(first);
await adapter.parseResponse!(new Response(JSON.stringify(vertexResponseBody())));

const contents = [{
role: "model",
parts: [{ functionCall: { name: "shell_command", args: { command: "pwd" } } }],
}];
applyAntigravityReplay(MODEL, antigravitySessionId(first), contents);
expect((contents[0].parts[0] as { thoughtSignature?: string }).thoughtSignature).toBeUndefined();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Security & Privacy | 🔵 Trivial | ⚡ Quick win

Test Vertex project and location isolation.

This test proves that a Vertex entry does not enter the Antigravity namespace. It does not prove that two Vertex configurations with the same conversation but different project or location stay isolated. If either identifier is removed from the replay key, this suite still passes and can replay provider-private state across GCP tenants or regions.

Record a signature with one Vertex project or location. Build the same continuation with a different value. Assert that its functionCall has no thoughtSignature.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/google-vertex-thought-signature.test.ts` around lines 110 - 121, Extend
the test around applyAntigravityReplay to record a Vertex signature using one
project or location, then build the same continuation with a different value and
assert its functionCall has no thoughtSignature. Ensure the assertions
specifically verify isolation across Vertex configuration identifiers, not only
between Vertex and Antigravity namespaces.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c0ffaef643

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/adapters/google.ts
Comment on lines +459 to +463
applyAntigravityReplay(
vertexReplayModel,
vertexReplaySession,
(compiled.body as { contents: unknown[] }).contents,
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve signatures for repeated identical Vertex calls

When a Vertex conversation invokes the same compiled function with identical arguments more than once (for example, repeating pwd or a status check), observeAntigravityReplay stores both occurrences under the same name-plus-arguments key, so the newer signature overwrites the older one. This newly added call then applies that single newest signature to every matching historical functionCall, rather than replaying each model turn's exact opaque value, causing a later tool-result continuation to be rejected by Vertex. Store signatures per occurrence/order or stable call identity, and add a regression test with two identical calls followed by a third turn.

AGENTS.md reference: src/AGENTS.md:L19-L19

Useful? React with 👍 / 👎.

@Wibias

Wibias commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator

Not gui

@github-actions
github-actions Bot marked this pull request as ready for review August 8, 2026 09:45
@lidge-jun
lidge-jun merged commit 28ba793 into dev Aug 8, 2026
30 of 32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants