Skip to content

fix(google): retry stalled Gemini first response - #79668

Merged
joshavant merged 3 commits into
mainfrom
fix/google-gemini-idle-retry-78502
May 9, 2026
Merged

joshavant merged 3 commits into
mainfrom
fix/google-gemini-idle-retry-78502

Conversation

@joshavant

Copy link
Copy Markdown
Collaborator

Summary

  • Problem: Direct Google Gemini 3.1 Pro / 3 Flash main-session runs can stall before the first model response when high thinking and the full coding tool profile are present.
  • Why it matters: The direct Google API-key path can hit the OpenClaw LLM idle watchdog even though direct provider calls and isolated/simple paths may work.
  • What changed: Add a Google native transport first-response retry for Gemini 3 Pro/Flash families that retries once with a lean thinking payload while preserving tools/content, and move Gemini tool-schema normalization into the shared Google provider hooks so direct Google and Gemini CLI paths both receive it.
  • What did NOT change (scope boundary): No changelog entry, no Vertex retry behavior, no Gemini 2.5 retry policy change, and no generic agent idle-timeout policy change.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor required for the fix
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

Real behavior proof (required for external PRs)

  • Behavior or issue addressed: Direct Google Gemini main-session idle timeout before a reply with high thinking and coding tools.
  • Real environment tested: macOS local checkout, Node 22+, direct Google Generative AI API key from a private env file, isolated OpenClaw HOME/state/config/workspace/trajectory dirs.
  • Exact steps or command run after this patch: node dist/entry.js agent --local --session-id <case> --message "Reply exactly <marker> and nothing else." --model <google model> --thinking high --timeout 240 --json with tools.profile: "coding" and direct google-generative-ai provider config.
  • Evidence after fix: copied live output from fresh runs below.
  • Observed result after fix: Gemini 3.1 Pro and Gemini 3 Flash return final text and trajectory session.ended success with idleTimedOut:false.
  • What was not tested: Human chat-channel delivery; Vertex-specific Google path.
  • Before evidence: Earlier A/B on the same issue reproduced LLM idle timeout on the main-session direct Google path for Gemini 3.1 Pro / Gemini 3 Flash with coding tools.

Live results on the current fix branch:

current_g31_high_coding: google/gemini-3.1-pro-preview, exit 0, 20s, text CURRENT_G31_HIGH_CODING_OK, trajectory success, idleTimedOut:false
current_g3flash_high_coding: google/gemini-3-flash-preview, exit 0, 52s, text CURRENT_G3FLASH_HIGH_CODING_OK, trajectory success, idleTimedOut:false
current_g25pro_high_coding_control: google/gemini-2.5-pro, exit 0, 11s, live response, trajectory success, idleTimedOut:false

Live results with the same code patch applied to v2026.5.7:

rel57_g31_high_coding: google/gemini-3.1-pro-preview, exit 0, 52s, text REL57_G31_HIGH_CODING_OK, trajectory success, idleTimedOut:false
rel57_g3flash_high_coding: google/gemini-3-flash-preview, exit 0, 52s, text REL57_G3FLASH_HIGH_CODING_OK, trajectory success, idleTimedOut:false
rel57_g25pro_high_coding_control: google/gemini-2.5-pro, exit 0, 159s, final success after existing same-model retry; one first-attempt internal idle timeout was observed before recovery

Root Cause (if applicable)

  • Root cause: Gemini 3 preview direct API requests can accept the full main-session/coding-tool payload but fail to produce the first SSE chunk before OpenClaw's idle watchdog. The direct Google provider also missed the Gemini tool-schema compatibility hook that Gemini CLI already had.
  • Missing detection / guardrail: No transport-level test covered zero-first-response Gemini 3 SSE stalls, and hook tests only asserted Gemini CLI schema normalization.
  • Contributing context (if known): The issue appears sensitive to the direct Google API surface, Gemini 3 preview families, high thinking, and full main-session/coding-tool payload shape.

Regression Test Plan (if applicable)

  • Coverage level that should have caught this:
    • Unit test
    • Seam / integration test
    • End-to-end test
    • Existing coverage already sufficient
  • Target test or file: extensions/google/transport-stream.test.ts, extensions/google/index.test.ts, plus live openclaw agent --local validation.
  • Scenario the test should lock in: Gemini 3 first attempt hangs before first SSE chunk, then transport retries once with lean thinking and preserved tools; direct Google and Gemini CLI both expose Gemini tool schema normalization hooks.
  • Why this is the smallest reliable guardrail: The transport test controls the exact no-first-response failure deterministically; live proof covers the user-visible main-session behavior.
  • Existing test that already covers this (if any): None before this patch.
  • If no new test is added, why not: N/A.

User-visible / Behavior Changes

Direct Google Gemini 3 preview main-session calls that stall before the first response now retry once with a lean first-response payload instead of waiting for the outer idle timeout.

Diagram (if applicable)

Before:
main session -> direct Google Gemini 3 high-thinking request -> no first SSE chunk -> OpenClaw idle timeout

After:
main session -> direct Google Gemini 3 high-thinking request -> no first SSE chunk by retry deadline -> lean retry -> final reply

Security Impact (required)

  • New permissions/capabilities? No
  • Secrets/tokens handling changed? No
  • New/changed network calls? Yes
  • Command/tool execution surface changed? No
  • Data access scope changed? No
  • If any Yes, explain risk + mitigation: A retry may make one additional request to the same official Google Generative AI endpoint for Gemini 3 Pro/Flash only after no first response. It preserves the same auth and request content, and is not enabled for Vertex or custom base URLs.

Repro + Verification

Environment

  • OS: macOS local checkout
  • Runtime/container: Node 22+, local built OpenClaw runtime
  • Model/provider: Direct Google Generative AI API key; google/gemini-3.1-pro-preview, google/gemini-3-flash-preview, google/gemini-2.5-pro
  • Integration/channel (if any): openclaw agent --local main session, isolated state/config/workspace/trajectory dirs
  • Relevant config (redacted): Google provider configured as api: "google-generative-ai", official https://generativelanguage.googleapis.com/v1beta, tools.profile: "coding", high thinking

Steps

  1. Configure isolated OpenClaw state with direct Google provider and coding tools.
  2. Run node dist/entry.js agent --local ... --model google/gemini-3.1-pro-preview --thinking high --json.
  3. Run the same shape for google/gemini-3-flash-preview.
  4. Inspect JSON output and trajectory session.ended events.

Expected

  • Gemini 3.1 Pro / Gemini 3 Flash produce a final assistant reply without an OpenClaw idle-timeout failure.

Actual

  • Both Gemini 3 cases produced final marker replies on current branch and on a patched v2026.5.7 worktree.

Evidence

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

Human Verification (required)

What you personally verified (not just CI), and how:

  • Verified scenarios: Direct Google Gemini 3.1 Pro and Gemini 3 Flash high-thinking coding-tool main-session live runs on current branch; same code patch applied to v2026.5.7; Gemini 2.5 Pro control.
  • Edge cases checked: Official Google API only; direct Google and Gemini CLI provider hook wiring; transport retry preserves tools and strips only retry thinking fields.
  • What you did not verify: Vertex live path; chat-channel delivery path.

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

Compatibility / Migration

  • Backward compatible? Yes
  • Config/env changes? Yes
  • Migration needed? No
  • If yes, exact upgrade steps: No migration. Optional diagnostic/tuning env OPENCLAW_GOOGLE_GEMINI_FIRST_RESPONSE_RETRY_MS can override the default 45s first-response retry deadline.

Risks and Mitigations

  • Risk: Retrying a request that might still later produce a response could duplicate provider work.
    • Mitigation: The retry is limited to Gemini 3 Pro/Flash, direct official Google Generative AI API, no first response/no first SSE chunk only, and a single retry.
  • Risk: Lean retry could alter model output quality.
    • Mitigation: It only runs after the original high-thinking request has produced no visible response; tools/content are preserved, and the retry uses the smallest supported Gemini 3 thinking level to recover a reply.

@openclaw-barnacle openclaw-barnacle Bot added size: M maintainer Maintainer-authored PR labels May 9, 2026
@clawsweeper

clawsweeper Bot commented May 9, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

Summary
The branch adds a direct Google Gemini 3 first-response retry in the Google transport, shares Gemini tool-schema normalization across direct Google and Gemini CLI providers, updates tests, and adds a changelog entry.

Reproducibility: yes. The linked issue and PR body give a concrete direct Google Gemini 3 main-session high-thinking/coding-tools path with timeout logs and live before/after output, while source inspection confirms current main lacks the retry and direct Google schema hook; I did not independently run live credentials in this read-only review.

Real behavior proof
Sufficient (live_output): The PR body contains copied live output from real direct Google API-key main-session runs after the fix, including Gemini 3.1 Pro and Gemini 3 Flash successes with idleTimedOut:false.

Next step before merge
No automated repair target is present; this is an active implementation PR with no discrete blocking finding, so the remaining action is maintainer review plus normal required checks/live validation.

Security
Cleared: No concrete security or supply-chain regression found; the diff adds no dependencies, workflows, permissions, or secret handling changes, and the extra network call is constrained to the same official Google endpoint with the same request/auth material.

Review details

Best possible solution:

Land the provider-owned retry and shared Gemini tool-schema hook after required code checks and maintainer review, then let the linked issue at #78502 close through the merge.

Do we have a high-confidence way to reproduce the issue?

Yes. The linked issue and PR body give a concrete direct Google Gemini 3 main-session high-thinking/coding-tools path with timeout logs and live before/after output, while source inspection confirms current main lacks the retry and direct Google schema hook; I did not independently run live credentials in this read-only review.

Is this the best way to solve the issue?

Yes. The PR keeps the change in the Google plugin transport, limits retry behavior to direct official Gemini 3 no-first-response streams, preserves the existing payload content/tools, and adds focused tests for the recovery path and shared hook wiring.

What I checked:

Likely related people:

  • steipete: GitHub commit history for the Google transport shows recent Gemini replay/thought-signature fixes on the same stream path, and provider hook/tool-schema files also have recent maintainer work by this account. (role: recent maintainer; confidence: high; commits: a428568157c3, 85b914a4e186, cc0f3067a003; files: extensions/google/transport-stream.ts, extensions/google/provider-hooks.ts, src/plugin-sdk/provider-tools.ts)
  • obviyus: Authored the recent Gemini thinking-stream activity fix that touched the same Google transport area and is referenced by the linked issue discussion as adjacent but insufficient for this stall. (role: adjacent recent owner; confidence: medium; commits: a55b2af7a5d3; files: extensions/google/transport-stream.ts)
  • vincentkoc: Recent public commit history shows provider runtime selection and bundled provider contract work involving the Gemini CLI/provider surface that this PR adjusts. (role: adjacent provider/runtime owner; confidence: medium; commits: aa27e27f3606, 48c4a026dd65; files: extensions/google/gemini-cli-provider.ts, extensions/google/provider-hooks.ts)

Remaining risk / open question:

  • The retry intentionally can make one extra same-endpoint Google request if the first stream later recovers after the retry deadline, though the PR limits it to one no-first-chunk Gemini 3 direct API-key retry.
  • I did not run local tests or live Google calls in this read-only review, and public check-runs visible through the API did not yet show a code test gate result.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 5fdef4c39e75.

@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 9, 2026
@joshavant
joshavant force-pushed the fix/google-gemini-idle-retry-78502 branch from d2ed3f1 to b29e120 Compare May 9, 2026 05:46
@joshavant
joshavant force-pushed the fix/google-gemini-idle-retry-78502 branch from b29e120 to 9f3f153 Compare May 9, 2026 05:46
@joshavant
joshavant merged commit 3af8148 into main May 9, 2026
105 checks passed
@joshavant
joshavant deleted the fix/google-gemini-idle-retry-78502 branch May 9, 2026 05:52
@clawsweeper clawsweeper Bot mentioned this pull request May 15, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
* fix(google): retry stalled gemini first response

* docs(changelog): note gemini first-response retry

* fix(google): clear gemini first-response deadline
jameslcowan pushed a commit to jameslcowan/openclaw that referenced this pull request Jun 2, 2026
* fix(google): retry stalled gemini first response

* docs(changelog): note gemini first-response retry

* fix(google): clear gemini first-response deadline
sablehead pushed a commit to sablehead/openclaw that referenced this pull request Jun 10, 2026
* fix(google): retry stalled gemini first response

* docs(changelog): note gemini first-response retry

* fix(google): clear gemini first-response deadline
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR proof: sufficient ClawSweeper judged the real behavior proof convincing. size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Google Gemini models (3.1 Pro & 2.5 Pro) hang/timeout on all main sessions, but work fine via direct API & isolated subagents

1 participant