Skip to content

✨ feat: add generation error business hook#14195

Merged
tjx666 merged 3 commits into
canaryfrom
feat/moderation
Apr 26, 2026
Merged

✨ feat: add generation error business hook#14195
tjx666 merged 3 commits into
canaryfrom
feat/moderation

Conversation

@tjx666

@tjx666 tjx666 commented Apr 26, 2026

Copy link
Copy Markdown
Member

πŸ’» Change Type

  • ✨ feat
  • πŸ› fix
  • ♻️ refactor
  • πŸ’„ style
  • πŸ‘· build
  • ⚑️ perf
  • βœ… test
  • πŸ“ docs
  • πŸ”¨ chore

πŸ”— Related Issue

Related to LOBE-8248

πŸ”€ Description of Change

  • Add a minimal business hook for generation prompt moderation errors.
  • Call the hook when image or video generation creation fails, while keeping the default implementation as a no-op.
  • Cover image create/recreate error paths with hook invocation assertions.

πŸ§ͺ How to Test

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

Validation:

  • bunx eslint --fix src/business/client/handleGenerationPromptModerationError.ts src/store/image/slices/createImage/action.ts src/store/image/slices/createImage/action.test.ts src/store/video/slices/createVideo/action.ts
  • VS Code diagnostics: clean for modified files

Note: running bunx vitest run --silent=passed-only src/store/image/slices/createImage/action.test.ts in this local checkout currently fails during test bootstrap with localStorage.getItem is not a function before collecting tests.

πŸ“Έ Screenshots / Videos

Before After
N/A N/A

πŸ“ Additional Information

The new submodule hook is intentionally generic and contains no cloud-specific implementation details.

@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 @tjx666, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@vercel

vercel Bot commented Apr 26, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lobehub Ready Ready Preview, Comment Apr 26, 2026 8:22am

Request Review

@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. feature:image AI image labels Apr 26, 2026

@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: e558d3b947

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 πŸ‘.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

// 3. Refresh generation batches to show the real data
await store.refreshGenerationBatches();
} catch (error) {
handleGenerationPromptModerationError(error);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Limit moderation hook to prompt-policy errors

This catch now covers removeGenerationBatch and refreshGenerationBatches in addition to imageService.createImage, so non-moderation failures (for example, the existing batch-removal failure path) will also call handleGenerationPromptModerationError. That can misclassify infra/state-sync errors as prompt moderation events in business builds and trigger the wrong error handling side effects; the hook should be invoked only when the creation call fails with a moderation-related error (or after explicit error-type filtering).

Useful? React with πŸ‘Β / πŸ‘Ž.

@codecov

codecov Bot commented Apr 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 64.70588% with 6 lines in your changes missing coverage. Please review.
βœ… Project coverage is 67.85%. Comparing base (196c0a7) to head (62fcb07).
⚠️ Report is 4 commits behind head on canary.

Additional details and impacted files
@@            Coverage Diff             @@
##           canary   #14195      +/-   ##
==========================================
- Coverage   67.85%   67.85%   -0.01%     
==========================================
  Files        2227     2228       +1     
  Lines      191364   191383      +19     
  Branches    23747    19160    -4587     
==========================================
+ Hits       129847   129854       +7     
- Misses      61388    61400      +12     
  Partials      129      129              
Flag Coverage Ξ”
app 61.09% <64.70%> (-0.01%) ⬇️
database 92.22% <ΓΈ> (ΓΈ)
packages/agent-runtime 79.82% <ΓΈ> (ΓΈ)
packages/context-engine 83.25% <ΓΈ> (ΓΈ)
packages/conversation-flow 92.40% <ΓΈ> (ΓΈ)
packages/file-loaders 87.02% <ΓΈ> (ΓΈ)
packages/memory-user-memory 74.74% <ΓΈ> (ΓΈ)
packages/model-bank 99.89% <ΓΈ> (ΓΈ)
packages/model-runtime 84.28% <ΓΈ> (+<0.01%) ⬆️
packages/prompts 70.14% <ΓΈ> (ΓΈ)
packages/python-interpreter 92.90% <ΓΈ> (ΓΈ)
packages/ssrf-safe-fetch 0.00% <ΓΈ> (ΓΈ)
packages/utils 88.41% <ΓΈ> (ΓΈ)
packages/web-crawler 88.66% <ΓΈ> (ΓΈ)

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

Components Coverage Ξ”
Store 67.21% <57.14%> (-0.01%) ⬇️
Services 53.36% <ΓΈ> (ΓΈ)
Server 67.60% <ΓΈ> (-0.02%) ⬇️
Libs 53.30% <ΓΈ> (ΓΈ)
Utils 80.04% <ΓΈ> (ΓΈ)
πŸš€ 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.

… paths

await expect(act(...)).rejects.toThrow() can settle before the inner
async catch handler runs when act schedules React commits between
multiple awaited setState calls. Move try/catch inside act so the test
waits for the full createImage/recreateImage rejection chain before
asserting the moderation error handler was called.
@tjx666 tjx666 merged commit cc48e9f into canary Apr 26, 2026
35 checks passed
@tjx666 tjx666 deleted the feat/moderation branch April 26, 2026 08:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature:image AI image size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant