Skip to content

Gemini web_search provider returns malformed JSON response on plain searches #88528

Closed

Description

@TarsTriggerBot

Summary

OpenClaw web search is configured to use the Gemini provider. Provider-specific validation errors confirm requests are reaching the Gemini-backed provider, but plain searches fail with:

Gemini API error: malformed JSON response

Environment

  • OpenClaw version: 2026.5.28 (e932160)
  • Installed npm package: openclaw@2026.5.28
  • Platform: Windows / PowerShell
  • Config path: C:\Users\Porygon\.openclaw\openclaw.json
  • Relevant config:
{
  "tools": {
    "web": {
      "search": {
        "provider": "gemini",
        "enabled": true
      }
    }
  },
  "plugins": {
    "entries": {
      "google": {
        "enabled": true,
        "config": {
          "webSearch": {
            "apiKey": "[configured]"
          }
        }
      }
    }
  }
}

Reproduction

Using the OpenClaw web_search tool:

  1. Search with a country filter:
{
  "query": "OpenClaw Gemini web search test current date May 31 2026",
  "count": 3,
  "country": "US"
}

Result:

{
  "error": "unsupported_country",
  "message": "country filtering is not supported by the gemini provider. Only Brave and Perplexity support country filtering.",
  "provider": "gemini"
}
  1. Search with a language filter:
{
  "query": "OpenClaw Gemini web search test current date May 31 2026",
  "count": 3,
  "language": "en"
}

Result:

{
  "error": "unsupported_language",
  "message": "language filtering is not supported by the gemini provider. Only Brave and Perplexity support language filtering.",
  "provider": "gemini"
}
  1. Search without unsupported filters:
{
  "query": "OpenClaw Gemini web search test current date May 31 2026",
  "count": 3
}

Result:

Gemini API error: malformed JSON response
  1. Minimal plain search:
{
  "query": "current date today",
  "count": 1
}

Result:

Gemini API error: malformed JSON response

Expected Behavior

For plain searches without unsupported filters, the Gemini provider should return normalized search results or a structured provider/API error.

Actual Behavior

Plain Gemini-backed web searches fail with Gemini API error: malformed JSON response.

Notes

The unsupported_country and unsupported_language responses indicate the request is reaching the Gemini provider path. The failure appears to occur when parsing or normalizing the successful Gemini search response.

Activity

  1. clawsweeper commented on May 31, 2026

    @clawsweeper
    Contributor

    Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed May 31, 2026, 1:47 AM ET / 05:47 UTC.

    Summary
    Keep open: current main still contains the Gemini web_search plain-query path that can emit the reported malformed JSON error, and the related issues in the context cover different Gemini/web_search problems rather than this plain-search failure.

    Reproducibility: no. high-confidence live reproduction was run in this read-only review. The reporter provides concrete v2026.5.28 steps, and current source still contains the same plain Gemini search path that emits the exact malformed JSON error when the provider response does not match the expected object shape.

    Ways to help us reproduce this

    • Add a screenshot or short recording showing the behavior.
    • Add expected vs actual behavior.

    Next step
    Manual review should capture or run a live Gemini plain-search response before choosing the parser/API repair; the source path is narrow but the failing response shape is not in the issue.

    Review details

    Best possible solution:

    Fix the Gemini web_search provider against the live plain generateContent response shape so it returns wrapped content and citations when grounded, or a structured provider/API error when Gemini returns a valid but unusable response.

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

    No high-confidence live reproduction was run in this read-only review. The reporter provides concrete v2026.5.28 steps, and current source still contains the same plain Gemini search path that emits the exact malformed JSON error when the provider response does not match the expected object shape.

    Is this the best way to solve the issue?

    Yes on direction, unclear on exact patch. The best repair is narrow in the Google plugin runtime/tests, but it should be based on a captured live response or official contract variant rather than guessing a new response shape.

    AGENTS.md: found and applied where relevant.

    Remaining risk / open question:

    • The issue does not include the raw Gemini response body or headers for the failing plain search, so the exact parser/API mismatch still needs live or captured-response proof before a safe fix is selected.

    Codex review notes: model gpt-5.5, reasoning high; reviewed against 0303f3a8f086.

    Label changes

    Label changes:

    • add P2: This is a normal-priority provider bug with a concrete repro on the latest release and limited blast radius to Gemini-backed web_search.
    • add impact:other: The issue breaks a maintainer-visible web_search provider path, which is outside the more specific owned impact labels.
    • add issue-rating: 🐚 platinum hermit: Current issue advisory state selects this label.
    • add clawsweeper:needs-live-repro: Current issue advisory state selects this label.
    • add clawsweeper:no-new-fix-pr: Current issue advisory state selects this label.
    • add clawsweeper:needs-maintainer-review: Current issue advisory state selects this label.

    Label justifications:

    • P2: This is a normal-priority provider bug with a concrete repro on the latest release and limited blast radius to Gemini-backed web_search.
    • impact:other: The issue breaks a maintainer-visible web_search provider path, which is outside the more specific owned impact labels.
    Evidence reviewed

    What I checked:

    • Current source reaches Gemini provider before fetch validation: The Gemini provider returns structured unsupported_country/unsupported_language responses before making a network call, matching the reporter's evidence that the request is routed to the Gemini provider. (extensions/google/src/gemini-web-search-provider.runtime.ts:276, 0303f3a8f086)
    • Plain searches still parse provider JSON through the malformed-response path: Without unsupported filters, current main builds a Gemini generateContent request and throws Gemini API error: malformed JSON response when the HTTP 200 response is not the expected object/candidates/content/groundingMetadata shape. (extensions/google/src/gemini-web-search-provider.runtime.ts:199, 0303f3a8f086)
    • Existing tests cover generic malformed JSON, not the reported live plain-search failure: The current test suite asserts the stable malformed JSON error for invalid provider JSON, while the mocked success response uses the expected candidates/content/groundingMetadata shape. (extensions/google/web-search-provider.test.ts:197, 0303f3a8f086)
    • Docs define plain Gemini search as supported: The Gemini search docs say Gemini supports query and accepts count, so a plain { query, count } call is expected to work rather than fail at response parsing. Public docs: docs/tools/gemini-search.md. (docs/tools/gemini-search.md:82, 0303f3a8f086)
    • Shipped/current parity check: git tag --contains 37fbc8cd8f includes v2026.5.28, so the current Gemini provider parser is present in the same release the reporter tested; no newer local history shows a plain-search parser fix. (37fbc8cd8f94)
    • Dependency contract check: Google's current Grounding with Google Search REST docs show tools: [{ google_search: {} }] and successful responses containing candidates, content.parts[].text, and groundingMetadata.groundingChunks, which matches the parser's intended contract but does not explain the reporter's live malformed body.

    Likely related people:

    • @steipete: Blame and recent history attribute the current Gemini web-search runtime and tests to Peter Steinberger, including the parser and malformed-response path under review. (role: recent area contributor; confidence: high; commits: 37fbc8cd8f94, e93216080aa1, 9f47892bef71; files: extensions/google/src/gemini-web-search-provider.runtime.ts, extensions/google/web-search-provider.test.ts, extensions/google/src/gemini-web-search-provider.ts)
    • @vincentkoc: History shows multiple web-search/provider-runtime changes around unsupported filter handling, runtime provider resolution, and plugin seams that are adjacent to this provider path. (role: adjacent web-search contributor; confidence: medium; commits: 6c7526f8a0d8, e56dde815e3a, 7343d1b2ad1b; files: src/web-search/runtime.ts, src/agents/tools/web-search-provider-common.ts, extensions/google/src/gemini-web-search-provider.runtime.ts)
    • @Takhoffman: History shows Tak Hoffman worked on moving provider execution and web-search config ownership into extension/plugin seams used by this provider. (role: provider runtime refactor contributor; confidence: medium; commits: 3de973ffff2e, 112d1d3a7c40, 59aea1e74d7c; files: src/web-search/runtime.ts, extensions/google/src/gemini-web-search-provider.ts, src/agents/tools/web-search-provider-common.ts)
    • @gumadeiras: History shows Gustavo Madeira Santana touched web-search contract/runtime-load tests, which may be relevant for validating a narrow provider fix. (role: adjacent test contributor; confidence: low; commits: 2482e70fb8c0, 3da66718f448; files: extensions/google/src/gemini-web-search-provider.runtime.ts, src/web-search/runtime.ts)
    How this review workflow works
    • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
    • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
    • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
    • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
    • Maintainers can also comment @clawsweeper review to request a fresh review only.
    • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
    • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
    • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
  2. added
    P2Normal backlog priority with limited blast radius.
    impact:otherThis issue has meaningful maintainer-visible impact outside the owned taxonomy.
    issue-rating: 🐚 platinum hermitGood issue quality with a plausible reproduction path needing some confirmation.
    clawsweeper:needs-live-reproClawSweeper needs live local, crabbox, or manual validation to confirm this issue.
    clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.
    clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.
    on May 31, 2026
  3. TarsTriggerBot commented on Jun 1, 2026

    @TarsTriggerBot
    Author

    Additional live repro evidence from the original reporter environment:

    • OpenClaw CLI/package: 2026.5.28 (e932160)
    • Platform: Windows / PowerShell
    • Provider: gemini
    • Model: gemini-2.5-flash
    • Endpoint shape: POST https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent
    • Request body shape:
    {
      "contents": [
        {
          "parts": [
            {
              "text": "current date today"
            }
          ]
        }
      ],
      "tools": [
        {
          "google_search": {}
        }
      ]
    }

    Running through OpenClaw still reproduces:

    openclaw infer web search --provider gemini --query "current date today" --limit 1 --json
    Error: Gemini API error: malformed JSON response
    Assertion failed: !(handle->flags & UV_HANDLE_CLOSING), file src\win\async.c, line 94
    

    A direct API call with the same request shape returns HTTP 200 and valid JSON. Sanitized response-shape summary:

    {
      "status": 200,
      "contentType": "application/json; charset=UTF-8",
      "topLevelKeys": [
        "candidates",
        "usageMetadata",
        "modelVersion",
        "responseId"
      ],
      "candidateCount": 1,
      "firstCandidateKeys": [
        "content",
        "finishReason",
        "index",
        "groundingMetadata"
      ],
      "finishReason": "STOP",
      "contentKeys": [
        "parts",
        "role"
      ],
      "partCount": 1,
      "partKeys": [
        "text"
      ],
      "textLength": 37,
      "textPreview": "Today's date is Monday, June 1, 2026.",
      "hasGroundingMetadata": true,
      "groundingKeys": [],
      "groundingChunksCount": 0
    }

    The original longer repro query behaves the same way:

    {
      "query": "OpenClaw Gemini web search test current date May 31 2026",
      "status": 200,
      "candidateCount": 1,
      "firstCandidateKeys": [
        "content",
        "finishReason",
        "index",
        "groundingMetadata"
      ],
      "finishReason": "STOP",
      "partCount": 1,
      "partKeys": [
        "text"
      ],
      "textPreview": "The current date is May 31, 2026.",
      "hasGroundingMetadata": true,
      "groundingKeys": [],
      "groundingChunksCount": 0
    }

    Likely failure point:

    extensions/google/src/gemini-web-search-provider.runtime.ts appears to allow groundingMetadata === undefined by treating it as [], but when Gemini returns groundingMetadata: {} without groundingChunks, the provider treats it as malformed.

    Likely fix direction:

    Treat missing/non-array groundingMetadata.groundingChunks as an empty citation list when text content is present, rather than throwing Gemini API error: malformed JSON response.

    Separate observation:

    The CLI also emits this Windows assertion after the provider error:

    Assertion failed: !(handle->flags & UV_HANDLE_CLOSING), file src\win\async.c, line 94
    

    That may be separate from the Gemini parser bug, but it reproduces after the malformed-response error path.

  4. self-assigned this
    on Jun 2, 2026
  5. added a commit that references this issue on Jun 7, 2026
    0551af9
  6. added a commit that references this issue on Jun 7, 2026
    51026d9
  7. locked as resolved and limited conversation to collaborators on Jun 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2Normal backlog priority with limited blast radius.clawsweeper:needs-live-reproClawSweeper needs live local, crabbox, or manual validation to confirm this issue.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.impact:otherThis issue has meaningful maintainer-visible impact outside the owned taxonomy.issue-rating: 🐚 platinum hermitGood issue quality with a plausible reproduction path needing some confirmation.

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions