Skip to content

fix(artifacts): improve video previews - #298

Merged
alwaysmavs merged 2 commits into
mainfrom
codex/fix-video-preview
Aug 2, 2026
Merged

fix(artifacts): improve video previews#298
alwaysmavs merged 2 commits into
mainfrom
codex/fix-video-preview

Conversation

@alwaysmavs

@alwaysmavs alwaysmavs commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Wanta already rendered video artifacts with Chromium's native video element, but the main-process preview path rejected every audio or video file larger than 16 MiB before it could receive a streamable artifact URL. In practice, that made ordinary video outputs appear unsupported even though the custom resource protocol already supports byte ranges.

This change allows large media files to use the existing leased wanta-resource stream while preserving the size limit for the Base64 fallback path. It also recognizes AVI and MKV MIME types, falls back to common video filename extensions when MIME metadata is generic, and replaces a permanently broken video element with a localized codec/format error state that still lets the user open the file in a system application.

No player or transcoding dependency is added. Chromium continues to provide the playback controls and codec support, so formats such as MKV, AVI, MOV, or HEVC are attempted but remain dependent on the codecs available in the packaged Electron runtime.

Verification

  • pnpm run lint
  • pnpm run ts-check
  • pnpm test — 283 test files and 2144 tests passed
  • Focused formatting check for all changed files
  • git diff --check

Added regression coverage for large resource-backed MP4 previews, AVI/MKV MIME detection, and extension-based video recognition when MIME metadata is generic.

Safety and Compatibility

  • Large media remains behind Wanta's short-lived artifact resource lease and trusted-path validation.
  • Byte-range streaming is reused; large videos are not copied into renderer memory as Base64 data URLs.
  • The 16 MiB limit remains in place for the inline fallback path and for existing non-media previews.
  • No new runtime dependency, native binary, codec, permission, credential, or external network surface is introduced.
  • Existing image, audio, PDF, document, spreadsheet, archive, and text preview behavior is unchanged.
  • Unsupported codecs retain the system-application fallback, while network and resource failures now use the generic read-failure message and preserve the cache's single retry limit.

@coderabbitai

coderabbitai Bot commented Aug 2, 2026

Copy link
Copy Markdown

Review Change Stack

Summary by CodeRabbit

  • New Features

    • Added support for AVI and MKV video files.
    • Improved video detection when file metadata is incomplete.
    • Large local videos can now load through resource URLs.
    • Added clearer messaging and an option to open unsupported videos with the system application.
  • Bug Fixes

    • Improved video preview error handling, playback controls, and recovery from resource errors.
    • Added support for common video filename extensions in artifact previews.

Walkthrough

The change adds AVI and MKV MIME detection and extension-based video classification. Local media previews request resource URLs before applying the 16 MiB inline limit. A dedicated video preview component handles playback errors, reports resource errors, and offers a system-application action. English and Chinese localization messages describe unsupported video formats or codecs. Tests cover MIME mapping, artifact classification, and large-video resource leases.

Sequence Diagram(s)

sequenceDiagram
  participant ArtifactConsumablePreview
  participant ArtifactVideoPreview
  participant ResourceErrorHandler
  participant SystemApplication
  ArtifactConsumablePreview->>ArtifactVideoPreview: provide video source
  ArtifactVideoPreview->>ArtifactVideoPreview: render video controls
  ArtifactVideoPreview->>ResourceErrorHandler: report playback error
  ArtifactVideoPreview->>SystemApplication: open unsupported video
Loading
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title uses the required type(scope): subject format and accurately describes the video preview fixes.
Description check ✅ Passed The description includes the required summary, verification, and safety sections with relevant implementation details and test results.
✨ Finishing Touches
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch codex/fix-video-preview

Comment @coderabbitai help to get the list of available commands.

@alwaysmavs
alwaysmavs marked this pull request as ready for review August 2, 2026 15:18

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/routes/Chat/ArtifactPreviewPane.tsx`:
- Around line 452-454: Update the video error handling associated with the
source-reset effect and preview failure state to distinguish codec errors from
resource errors: map MEDIA_ERR_SRC_NOT_SUPPORTED to
artifacts.videoCodecUnsupported, while using the generic resource-error message
for network and other loading failures. Preserve the cache’s existing
one-reload-per-preview-key behavior and avoid adding an indefinite reload loop.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 673e12df-49b6-461f-8168-b37b1d86974b

📥 Commits

Reviewing files that changed from the base of the PR and between e44c850 and ddc6df3.

📒 Files selected for processing (9)
  • electron/chat/artifacts.test.ts
  • electron/chat/artifacts.ts
  • electron/chat/previews.test.ts
  • electron/chat/previews.ts
  • src/i18n/app-messages.en.ts
  • src/i18n/app-messages.zh.ts
  • src/routes/Chat/ArtifactPreviewPane.tsx
  • src/routes/Chat/GeneratedArtifacts.test.ts
  • src/routes/Chat/artifact-metadata.ts

Comment thread src/routes/Chat/ArtifactPreviewPane.tsx
@alwaysmavs alwaysmavs changed the title Fix video artifact previews fix(artifacts): improve video previews Aug 2, 2026
@alwaysmavs
alwaysmavs merged commit 7fcf2da into main Aug 2, 2026
3 checks passed
@alwaysmavs
alwaysmavs deleted the codex/fix-video-preview branch August 2, 2026 15:25
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.

1 participant