Skip to content

💄 style: enhance handling of blocked content on Gemini #13270

Merged
arvinxx merged 2 commits into
lobehub:canaryfrom
sxjeru:32666
Mar 27, 2026
Merged

💄 style: enhance handling of blocked content on Gemini #13270
arvinxx merged 2 commits into
lobehub:canaryfrom
sxjeru:32666

Conversation

@sxjeru

@sxjeru sxjeru commented Mar 26, 2026

Copy link
Copy Markdown
Contributor

💻 Change Type

  • ✨ feat
  • 🐛 fix
  • ♻️ refactor
  • 💄 style
  • 👷 build
  • ⚡️ perf
  • ✅ test
  • 📝 docs
  • 🔨 chore

🔗 Related Issue

🔀 Description of Change

在 Gemini 输出被截断后正确显示中断原因,此前未显示该报错提示。

image

🧪 How to Test

  • Tested locally
  • Added/updated tests
  • No tests needed

📸 Screenshots / Videos

Before After
... ...

📝 Additional Information

Copilot AI review requested due to automatic review settings March 26, 2026 02:12
@vercel

vercel Bot commented Mar 26, 2026

Copy link
Copy Markdown

@sxjeru is attempting to deploy a commit to the LobeHub OSS Team on Vercel.

A member of the Team first needs to authorize it.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @sxjeru, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@lobehubbot

Copy link
Copy Markdown
Member

@ONLY-yours @arvinxx - This PR enhances blocked content handling for Gemini streaming, touching the model-runtime stream parser, chat agent executor, and Conversation UI. Please take a look.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f16c141f8c

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +83 to +87
if (blockedReason) {
const convertedUsage = convertGoogleAIUsage(usageMetadata, payload?.pricing);
const humanFriendlyMessage = getBlockReasonMessage(blockedReason);

return [

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve candidate text when handling blocked finishes

This branch returns usage + error immediately for blocked finishReason, which skips the text/tool parsing paths later in the same function. If Google sends a terminal chunk that includes both finishReason and new content.parts (or a non-streaming single chunk with partial text), the newly generated text is dropped instead of being emitted before the error, so users lose part of the model output.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

经多次测试,认为末尾块不会包含 content

@codecov

codecov Bot commented Mar 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.66667% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.94%. Comparing base (b76db6b) to head (9cb4648).
⚠️ Report is 28 commits behind head on canary.

Additional details and impacted files
@@            Coverage Diff             @@
##           canary   #13270      +/-   ##
==========================================
+ Coverage   66.91%   66.94%   +0.03%     
==========================================
  Files        1869     1870       +1     
  Lines      147974   148158     +184     
  Branches    14201    16988    +2787     
==========================================
+ Hits        99018    99187     +169     
- Misses      48845    48860      +15     
  Partials      111      111              
Flag Coverage Δ
app 58.21% <95.00%> (+0.05%) ⬆️
database 97.89% <ø> (+<0.01%) ⬆️
packages/agent-runtime 89.61% <ø> (ø)
packages/context-engine 83.59% <ø> (ø)
packages/conversation-flow 92.36% <ø> (ø)
packages/file-loaders 87.02% <ø> (ø)
packages/memory-user-memory 66.68% <ø> (ø)
packages/model-bank 99.85% <ø> (ø)
packages/model-runtime 84.53% <88.63%> (-0.01%) ⬇️
packages/prompts 74.60% <ø> (ø)
packages/python-interpreter 92.90% <ø> (ø)
packages/ssrf-safe-fetch 0.00% <ø> (ø)
packages/utils 90.41% <ø> (ø)
packages/web-crawler 88.82% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
Store 66.11% <95.00%> (+0.04%) ⬆️
Services 49.56% <ø> (ø)
Server 68.13% <ø> (-0.01%) ⬇️
Libs 45.46% <ø> (+2.25%) ⬆️
Utils 91.01% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves the Gemini (Google) streaming UX when content is blocked/truncated by ensuring the interruption reason is surfaced to the user while preserving any partial output that was already streamed.

Changes:

  • Emit a ProviderBizError stream event when Google returns a terminal blocked finishReason (e.g. PROHIBITED_CONTENT), and add/update corresponding tests.
  • Localize Google blocked-content errors in the agent executor before updating message error state.
  • Force the assistant message UI to show errors for Google blocked-content cases even when partial content exists; update copy for Google block-reason messages.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/store/chat/agents/createAgentExecutors.ts Localizes Google blocked-content errors before persisting them to message error state.
src/store/chat/agents/tests/createAgentExecutors/call-llm.test.ts Adds coverage ensuring partial output is preserved while error state is updated.
src/locales/default/error.ts Updates default locale strings for Google block reasons.
src/features/Conversation/Messages/Assistant/index.tsx Forces error display for Google blocked-content scenarios even with partial message text.
packages/model-runtime/src/core/streams/google/index.ts Adds handling for blocked terminal candidate finishReason and emits an error event.
packages/model-runtime/src/core/streams/google/google-ai.test.ts Updates expectations and adds a new test for blocked terminal candidate finishReason.
packages/model-runtime/src/core/streams/google/const.ts Updates the human-friendly messages mapped from Google block reasons.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/model-runtime/src/core/streams/google/index.ts
Comment thread src/features/Conversation/Messages/Assistant/index.tsx
},
onErrorHandle: async (error) => {
await context.get().optimisticUpdateMessageError(assistantMessageId, error, {
const localizedError = localizeGoogleBlockedError(error);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

localizeGoogleBlockedError 太具体了,应该是一个 localizeError

@sxjeru sxjeru requested a review from arvinxx March 26, 2026 03:23
@arvinxx arvinxx merged commit 48b5927 into lobehub:canary Mar 27, 2026
20 of 21 checks passed
@lobehubbot

Copy link
Copy Markdown
Member

❤️ Great PR @sxjeru ❤️

The growth of project is inseparable from user feedback and contribution, thanks for your contribution! If you are interesting with the lobehub developer community, please join our discord and then dm @arvinxx or @canisminor1990. They will invite you to our private developer channel. We are talking about the lobe-chat development or sharing ai newsletter around the world.

@sxjeru sxjeru deleted the 32666 branch March 27, 2026 03:16
ONLY-yours added a commit that referenced this pull request Mar 27, 2026
# 🚀 release: 20260326

This release includes **91 commits**. Key updates are below.


- **Agent can now execute background tasks** — Agents can perform
long-running operations without blocking your conversation.
[#13289](#13289)
- **Better error messages** — Redesigned error UI across chat and image
generation with clearer explanations and recovery options.
[#13302](#13302)
- **Smoother topic switching** — No more full page reloads when
switching topics while an agent is responding.
[#13309](#13309)
- **Faster image uploads** — Large images are now automatically
compressed to 1920px before upload, reducing wait times.
[#13224](#13224)
- **Improved knowledge base** — Documents are now properly parsed before
chunking, improving retrieval accuracy.
[#13221](#13221)

### Bot Platform

- **WeChat Bot support** — You can now connect LobeChat to WeChat, in
addition to Discord.
[#13191](#13191)
- **Richer bot responses** — Bots now support custom markdown rendering
and context injection.
[#13294](#13294)
- **New bot commands** — Added `/new` to start fresh conversations and
`/stop` to halt generation.
[#13194](#13194)
- **Discord stability fixes** — Fixed thread creation issues and Redis
connection drops.
[#13228](#13228)
[#13205](#13205)

### Models & Providers

- **GLM-5** is now available in the LobeHub model list.
[#13189](#13189)
- **Coding Plan providers** — Added support for code planning assistant
providers. [#13203](#13203)
- **Tencent Hunyuan 3.0 ImageGen** — New image generation model from
Tencent. [#13166](#13166)
- **Gemini content handling** — Better handling when Gemini blocks
content due to safety filters.
[#13270](#13270)
- **Claude token limits fixed** — Corrected max window tokens for
Anthropic Claude models.
[#13206](#13206)

### Skills & Tools

- **Auto credential injection** — Skills can now automatically request
and use required credentials.
[#13124](#13124)
- **Smarter tool permissions** — Built-in tools skip confirmation for
safe paths like `/tmp`.
[#13232](#13232)
- **Model switcher improvements** — Quick access to provider settings
and visual highlight for default model.
[#13220](#13220)

### Memory

- **Bulk delete memories** — You can now delete all memory entries at
once. [#13161](#13161)
- **Per-agent memory control** — Memory injection now respects
individual agent settings.
[#13265](#13265)

### Desktop App

- **Gateway connection** — Desktop app can now connect to LobeHub
Gateway for enhanced features.
[#13234](#13234)
- **Connection status indicator** — See gateway connection status in the
titlebar. [#13260](#13260)
- **Settings persistence** — Gateway toggle state now persists across
app restarts. [#13300](#13300)

### CLI

- **API key authentication** — CLI now supports API key auth for
programmatic access.
[#13190](#13190)
- **Shell completion** — Tab completion for bash/zsh/fish shells.
[#13164](#13164)
- **Man pages** — Built-in manual pages for CLI commands.
[#13200](#13200)

### Security

- **XSS protection** — Sanitized search result image titles to prevent
script injection.
[#13303](#13303)
- **Workflow hardening** — Fixed potential shell injection in release
automation. [#13319](#13319)
- **Dependency update** — Updated nodemailer to address security
advisory. [#13326](#13326)

### Bug Fixes

- Fixed skill page not redirecting correctly after import.
[#13255](#13255)
[#13261](#13261)
- Fixed token counting in group chats.
[#13247](#13247)
- Fixed editor not resetting when switching to empty pages.
[#13229](#13229)
- Fixed manual tool toggle not working.
[#13218](#13218)
- Fixed Search1API response parsing.
[#13207](#13207)
[#13208](#13208)
- Fixed mobile topic menus rendering issues.
[#12477](#12477)
- Fixed history count calculation for accurate context.
[#13051](#13051)
- Added missing Turkish translations.
[#13196](#13196)

### Credits

Huge thanks to these contributors:

@bakiburakogun @hardy-one @Zhouguanyang @sxjeru @hezhijie0327 @arvinxx
@cy948 @CanisMinor @Innei @lijian @lobehubbot @neko @rdmclin2
@rivertwilight @tjx666
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.

4 participants