Repository navigation
Description
Bug type
Regression (worked before, now fails)
Summary
When using Gemini 3 Flash Preview, the API occasionally returns finishReason: "MALFORMED_RESPONSE". This value is not handled by @mariozechner/pi-ai's mapStopReason() function in google-shared.ts, causing it to throw Unhandled stop reason: MALFORMED_RESPONSE.
This crashes the active agent run. In Telegram DM mode, all subsequent messages in the same session also fail because the corrupted response is persisted in the session history.
Environment
- OpenClaw: v2026.3.8
-
- Model:
google/gemini-3-flash-previewvia AI Studio (GEMINI_API_KEY)
- Model:
-
-
- Channel: Telegram
-
-
-
-
- OS: Ubuntu 24.04 on GCE (e2-medium)
-
-
Upstream
Filed as an issue in the pi-mono repo: earendil-works/pi#2028
Workaround
Hot-patch node_modules/@mariozechner/pi-ai/dist/providers/google-shared.js: replace the throw in the default branch of mapStopReason() with return "error".
Steps to reproduce
- Use OpenClaw v2026.3.8 with google/gemini-3-flash-preview via AI Studio
- Have a cron systemEvent inject a reminder into an active conversation
- The model responds with finishReason: "MALFORMED_RESPONSE"
- Agent run fails with Unhandled stop reason: MALFORMED_RESPONSE
- All subsequent messages in the same session also fail (corrupted conversation history)
Expected behavior
The agent should gracefully handle unknown finish reasons by treating them as generic errors, instead of throwing and crashing the runtime.
Actual behavior
This crashes the active agent run. In Telegram DM mode, all subsequent messages in the same session also fail because the corrupted response is persisted in the session history.
OpenClaw version
v2026.3.8
Operating system
Ubuntu 24.04 on GCE (e2-medium)
Install method
npm global
Model
google/gemini-3-flash-preview
Provider / routing chain
openclaw -> AI Studio
Config file / key location
~/.openclaw/openclaw.json
Additional provider/model setup details
Using GEMINI_API_KEY directly with AI Studio. No proxy or routing middleware.
Logs, screenshots, and evidence
Impact and severity
Affected: All users using Gemini preview models via AI Studio
Severity: High (crashes agent, blocks all replies until manual intervention)
Frequency: Intermittent (triggered by specific API responses)
Consequence: Bot becomes unresponsive, requires manual session cleanup and gateway restart
Additional information
Upstream issue filed: earendil-works/pi#2028
Workaround: Hot-patch node_modules/@mariozechner/pi-ai/dist/providers/google-shared.js - replace throw in mapStopReason default branch with return "error"
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity