Skip to content

fix(agent): consume Gemini replay metadata once - #3824

Closed
kojiwakayama wants to merge 1 commit into
mainfrom
fix/issue-549-consume-provider-metadata
Closed

fix(agent): consume Gemini replay metadata once#3824
kojiwakayama wants to merge 1 commit into
mainfrom
fix/issue-549-consume-provider-metadata

Conversation

@kojiwakayama

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #3820 and veryfront/veryfront-issue-inbox#549. The internal WeakMap replay metadata added by #3820 was read without being consumed, so a signature from tool step 1 could be replayed again on tool step 3 alongside the current signature. Gemini rejects that stale cross-step replay.

This change makes provider-request replay metadata single-use while preserving ordinary/history conversion behavior. Metadata is consumed only for assistant runtime messages that remain in the final outbound prompt; a trailing assistant message trimmed from the current request retains its metadata for the later request that actually sends it.

RED → GREEN

  • RED: a three-request generate flow replayed [signature1, signature2] on request 3 instead of only [signature2].
  • RED: consuming before trailing-assistant trimming lost metadata that needed to be sent after the subsequent tool result.
  • GREEN: generate, legacy stream, and active stream lifecycles now send only the current step signature.
  • GREEN: ordinary/history conversion remains repeatable and non-consuming; provider request conversion consumes only retained outbound metadata.

Verification

  • Full pre-push gate: 3,922 tests / 29,978 steps, 0 failed; cwd suites 13 tests / 213 steps, 0 failed.
  • Focused provider/runtime suites: 110 steps green.
  • Targeted deno check, lint, format, diff check, anti-slop, test-typecheck, public/error docs, and pinned Deno 2.7.7 API docs checks green.
  • Independent exact-diff review: approve, zero findings.

Fixes veryfront/veryfront-issue-inbox#549

Provider replay metadata describes one signed assistant response and is valid only for the immediately following provider request. Record source/runtime message pairs during conversion, trim unsupported assistant tails, and consume only attachments that remain in the outbound prompt.

Constraint: Gemini 3 requires the exact signed function-call part on its matching tool-result leg.

Rejected: Delete metadata while converting every assistant message | trailing assistant messages may be trimmed without being sent.

Confidence: high

Scope-risk: narrow

Directive: Keep history conversion non-consuming and consume replay metadata only after an assistant message survives provider-request trimming.

Tested: Three-request generate, legacy stream, active stream, trimmed-assistant replay, 110-step focused matrix, typecheck, lint, format, anti-slop, docs checks.

Not-tested: Live credentialed Gemini request.
@kojiwakayama

Copy link
Copy Markdown
Contributor Author

@codex review

@kojiwakayama

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@github-actions

Copy link
Copy Markdown

📦 Client bundle boundary

Entrypoint Modules Source size Server leaks
src/index.client.ts 325 1937 KiB ✅ 0

A server module in a client graph aborts hydration in the browser. New leaks fail CI; known leaks are tracked in scripts/lint/client-bundle-baseline.json to burn down.

@coderabbitai

coderabbitai Bot commented Aug 17, 2026

Copy link
Copy Markdown
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Aug 17, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@kojiwakayama, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 36 minutes

Limit details: You’ve used all 1 included review currently available under your plan.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: cbf38030-17e4-4bb0-a0d5-6a980d154fe6

📥 Commits

Reviewing files that changed from the base of the PR and between e297edb and 0867dbe.

📒 Files selected for processing (4)
  • src/agent/runtime/provider-metadata-continuation.test.ts
  • src/agent/runtime/provider-metadata.ts
  • src/agent/runtime/text-generation-runtime-message-converter.test.ts
  • src/agent/runtime/text-generation-runtime-message-converter.ts

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.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: 0867dbe1c3

ℹ️ 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".

@kojiwakayama

Copy link
Copy Markdown
Contributor Author

Closing as invalid after main merged the authoritative regression in #3821. Google’s Gemini 3 protocol requires every accumulated function-call thought signature in the current sequential tool turn: request 3 must contain signature A and signature B. This PR’s consume-once behavior removes signature A and would restore the provider 400. The late review suggestion on #3820 is therefore rejected on protocol grounds, not implemented.

Primary source: https://ai.google.dev/gemini-api/docs/generate-content/thought-signatures#sequential_function_calling_example

@kojiwakayama
kojiwakayama deleted the fix/issue-549-consume-provider-metadata branch August 30, 2026 10:27
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