Skip to content

fix: correct gemini interactions streaming - #607

Merged
chenyme merged 6 commits into
DEEIX-AI:devfrom
ADabbler:fix/gemini-interactions-adapter
Aug 16, 2026
Merged

fix: correct gemini interactions streaming#607
chenyme merged 6 commits into
DEEIX-AI:devfrom
ADabbler:fix/gemini-interactions-adapter

Conversation

@ADabbler

Copy link
Copy Markdown
Contributor

Summary

Fix Gemini Interactions streaming handling and interrupted-generation recovery.

  • Parse the official event_type field from Gemini Interactions SSE events.
  • Route step.delta events with delta.type: "thought_summary" to the reasoning stream rather than normal assistant text.
  • Reconstruct function-call arguments from step.start and subsequent arguments_delta events.
  • Read official interaction usage fields, including thought-token usage.
  • Remove the failed-run marker that could prevent a server-pending generation from resuming after the initial browser stream disconnected.

Change type

  • Bug fix

Affected areas

  • Frontend / UI
  • Backend / API
  • Conversations / streaming
  • Model routing / providers

Verification

  • go test ./internal/infra/llm -count=1
  • pnpm check
  • pnpm test
  • pnpm build
  • git diff --check

Screenshots, API examples, or logs

The updated stream test fixture covers the official event shape:

{
  "event_type": "step.delta",
  "delta": {
    "type": "thought_summary",
    "content": {
      "type": "text",
      "text": "..."
    }
  }
}

No UI layout changes.

Configuration, migration, and compatibility notes

  • No database migration, deployment configuration, environment variable, or HTTP API contract change.
  • No generated artifacts are required.
  • Existing model settings are unchanged.

Documentation

  • Documentation is not needed for this change.

Security and privacy

  • No secrets, tokens, credentials, local config, or personal data are included.
  • User data access remains scoped by authenticated user context unless an admin-only path explicitly requires broader access.
  • Security-sensitive behavior was reviewed, including authentication, authorization, provider routing, file processing, billing, and admin APIs where relevant.

Checklist

  • I searched existing issues and pull requests.
  • Changes are focused and do not include unrelated refactors.
  • Tests or static verification were run where practical.
  • User-facing behavior, deployment steps, API contracts, or configuration changes are documented.
  • Generated artifacts are included only when this project explicitly requires them.
  • Caches, build output, .pyc files, .env files, and local storage data are not committed.

Comment thread backend/internal/infra/llm/gemini_interactions.go Fixed
@chenyme

chenyme commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Additional fixes

  • Preserve text, thought summaries, and thought signatures already present in step.start events.
  • Keep function-call reconstruction state local to the Gemini Interactions stream instead of storing protocol-specific state on the shared output type.
  • Preserve the observed service_tier across later usage events that omit it.
  • Handle official streamed image and video deltas so generated media is retained.
  • Parse Google Search, Code Execution, and URL Context call/result steps.
  • Merge native tool calls and results by call_id, retain citations, and count each server-side tool invocation only once.
  • Notify the frontend when the local active-run set changes so a disconnected server-pending generation can resume without waiting for an unrelated render.

Additional verification

  • Compared the implementation against the current Gemini Interactions API reference and streaming documentation.
  • Sent an unauthenticated request to the live Google Interactions endpoint and confirmed the official endpoint and API-key authentication behavior through its expected HTTP 403 response.
  • Added regression coverage for:
    • step.start text and thought content
    • thought signatures
    • streamed function arguments
    • cumulative usage and cached tokens
    • service-tier preservation
    • native server-side tools
    • streamed images and videos
    • citation extraction and non-duplicated tool usage
  • go test ./internal/infra/llm -run 'GeminiInteraction|GeminiInteractions' -count=1
  • go test -race ./internal/infra/llm -run 'GeminiInteraction|GeminiInteractions' -count=1
  • pnpm check
  • pnpm test
  • pnpm --filter @deeix/web build
  • pnpm --filter @deeix/api build
  • git diff --check

Compatibility notes

  • No database migration, HTTP API contract, environment variable, or deployment configuration change is required.
  • Existing model settings remain unchanged.
  • The Gemini Interactions API is still in beta, so future upstream schema changes may require further adapter updates.
  • An authenticated live generation was not run because no Gemini API credential was available in the verification environment.

@chenyme
chenyme force-pushed the fix/gemini-interactions-adapter branch from fb51710 to 3d1eb3f Compare August 16, 2026 05:12
# Conflicts:
#	backend/internal/infra/llm/gemini_interactions.go
#	backend/internal/infra/llm/gemini_interactions_test.go
@chenyme
chenyme self-requested a review August 16, 2026 05:56
@chenyme
chenyme merged commit 31fde58 into DEEIX-AI:dev Aug 16, 2026
10 checks passed
@ADabbler
ADabbler deleted the fix/gemini-interactions-adapter branch August 16, 2026 06:02
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.

3 participants