Skip to content

fix: avoid false early decode failures#233

Merged
siddharthvaddem merged 4 commits intomainfrom
codex/issue-230
Mar 18, 2026
Merged

fix: avoid false early decode failures#233
siddharthvaddem merged 4 commits intomainfrom
codex/issue-230

Conversation

@siddharthvaddem
Copy link
Owner

@siddharthvaddem siddharthvaddem commented Mar 18, 2026

Pull Request Template

Description

The problem is a mismatch between:

  • what the recorded .webm file says its duration is
  • how many video frames are actually decodable near the end

Motivation

Type of Change

  • New Feature
  • Bug Fix
  • Refactor / Code Cleanup
  • Documentation Update
  • Other (please specify)

Related Issue(s)

fixes #230

Screenshots / Video

Screenshot (if applicable):

![Screenshot Description](path/to/screenshot.png)

Video (if applicable):

<video src="path/to/video.mp4" controls width="600"></video>

Testing

Checklist

  • I have performed a self-review of my code.
  • I have added any necessary screenshots or videos.
  • I have linked related issue(s) and updated the changelog if applicable.

Thank you for contributing!

Summary by CodeRabbit

  • Tests

    • Added unit tests for streaming decode termination edge cases and updated the GIF export end-to-end assertion to not depend on a specific path text.
  • Refactor

    • Centralized and clarified decoder end-condition logic for consistent early-end validation.
  • Bug Fix

    • Export handling now requires a valid saved path before treating exports as successful; missing paths surface an error.

@coderabbitai
Copy link

coderabbitai bot commented Mar 18, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: eb2ac9b3-d962-407e-a3ff-935079dd6832

📥 Commits

Reviewing files that changed from the base of the PR and between 1680ef9 and 7e65d52.

📒 Files selected for processing (3)
  • src/lib/exporter/streamingDecoder.test.ts
  • src/lib/exporter/streamingDecoder.ts
  • tests/e2e/gif-export.spec.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/lib/exporter/streamingDecoder.ts
  • src/lib/exporter/streamingDecoder.test.ts

📝 Walkthrough

Walkthrough

Centralizes early video-decode end detection into an exported helper shouldFailDecodeEndedEarly, adds unit tests for that helper, and tightens export success handling to require a valid saveResult.path before treating an export as saved.

Changes

Cohort / File(s) Summary
Test Coverage
src/lib/exporter/streamingDecoder.test.ts
Adds unit tests for shouldFailDecodeEndedEarly covering full-segment success, decoding ending far before required end, missing decoded frames on a non-empty timeline, and decoder not reaching reported stream end.
Core Logic Refactor
src/lib/exporter/streamingDecoder.ts
Introduces exported shouldFailDecodeEndedEarly and internal EarlyDecodeEndCheck type; replaces inline early-end checks with the helper and updates error reporting to include a decodedAtLabel.
Export Result Handling (UI)
src/components/video-editor/VideoEditor.tsx
Changes export success handling to require saveResult.success && saveResult.path before calling handleExportSaved; otherwise surface the error via setExportError.
E2E Test Adjustment
tests/e2e/gif-export.spec.ts
Updates GIF export test to assert a success toast containing "GIF exported successfully" (no longer depends on a specific path message).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped through frames and chased each tick,
Found the moment when decoding stopped too quick.
Tests stand guard where timelines might part,
Exports now saved only with a true path to start.
A jittery rabbit clap—code whole and slick! 🥕✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The PR description identifies the core problem (duration mismatch in webm files) and links to issue #230, but lacks implementation details, testing instructions, and other template sections. Provide testing steps, describe how the fix addresses the mismatch, and indicate which template checklist items were completed.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix: avoid false early decode failures' directly and concisely describes the main objective of the PR—preventing false early decode failures when exporting webm files.
Linked Issues check ✅ Passed The PR successfully addresses the core requirement from issue #230: preventing false early decode failures by extracting and improving the early-end detection logic, adding unit tests, and strengthening export error handling.
Out of Scope Changes check ✅ Passed All changes are within scope: the new streamingDecoder logic directly fixes the early decode issue, test updates reflect the fix, and VideoEditor changes strengthen export error handling per the issue requirements.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/issue-230
📝 Coding Plan
  • Generate coding plan for human review comments

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

Copy link

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

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: de18a2f46f

ℹ️ 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".

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
src/lib/exporter/streamingDecoder.test.ts (1)

4-40: Add guard-branch tests for cancelled and empty timeline.

The helper has explicit early returns for cancelled and segmentsLength === 0, but they are not currently asserted.

🧪 Proposed test additions
 describe("shouldFailDecodeEndedEarly", () => {
+	it("does not fail when decode was cancelled", () => {
+		expect(
+			shouldFailDecodeEndedEarly({
+				cancelled: true,
+				segmentsLength: 2,
+				completedSegments: 0,
+				lastDecodedFrameSec: null,
+				requiredEndSec: 10,
+			}),
+		).toBe(false);
+	});
+
+	it("does not fail for an empty timeline", () => {
+		expect(
+			shouldFailDecodeEndedEarly({
+				cancelled: false,
+				segmentsLength: 0,
+				completedSegments: 0,
+				lastDecodedFrameSec: null,
+				requiredEndSec: 0,
+			}),
+		).toBe(false);
+	});
+
 	it("does not fail once every segment has been satisfied", () => {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/lib/exporter/streamingDecoder.test.ts` around lines 4 - 40, Add two unit
tests for shouldFailDecodeEndedEarly to cover the early-return branches: one
where cancelled: true (verify it returns false regardless of other fields) and
one where segmentsLength: 0 (empty timeline, verify it returns false even if
lastDecodedFrameSec is null or requiredEndSec > 0). Locate the helper by its
name shouldFailDecodeEndedEarly in streamingDecoder.test.ts and add small
it(...) blocks that pass appropriate payloads asserting the expected false
result.
src/lib/exporter/streamingDecoder.ts (1)

44-44: Replace the hardcoded 1s tolerance with a named constant.

Line 44 uses a magic number, which makes future tuning harder and less discoverable.

♻️ Proposed refactor
+const EARLY_DECODE_TOLERANCE_SEC = 1;
+
 export function shouldFailDecodeEndedEarly({
 	cancelled,
 	segmentsLength,
 	completedSegments,
 	lastDecodedFrameSec,
 	requiredEndSec,
 }: EarlyDecodeEndCheck): boolean {
@@
-	return requiredEndSec - lastDecodedFrameSec > 1;
+	return requiredEndSec - lastDecodedFrameSec > EARLY_DECODE_TOLERANCE_SEC;
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/lib/exporter/streamingDecoder.ts` at line 44, Replace the magic numeric
literal in the expression "requiredEndSec - lastDecodedFrameSec > 1" with a
named constant (e.g., FRAME_END_TOLERANCE_SEC or DECODING_TOLERANCE_SEC)
declared at the top of streamingDecoder.ts (module- or file-scope) so the
tolerance is discoverable and easy to tune; update the comparison to use that
constant and add a brief comment on its units (seconds) where the constant is
defined.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/lib/exporter/streamingDecoder.test.ts`:
- Around line 4-40: Add two unit tests for shouldFailDecodeEndedEarly to cover
the early-return branches: one where cancelled: true (verify it returns false
regardless of other fields) and one where segmentsLength: 0 (empty timeline,
verify it returns false even if lastDecodedFrameSec is null or requiredEndSec >
0). Locate the helper by its name shouldFailDecodeEndedEarly in
streamingDecoder.test.ts and add small it(...) blocks that pass appropriate
payloads asserting the expected false result.

In `@src/lib/exporter/streamingDecoder.ts`:
- Line 44: Replace the magic numeric literal in the expression "requiredEndSec -
lastDecodedFrameSec > 1" with a named constant (e.g., FRAME_END_TOLERANCE_SEC or
DECODING_TOLERANCE_SEC) declared at the top of streamingDecoder.ts (module- or
file-scope) so the tolerance is discoverable and easy to tune; update the
comparison to use that constant and add a brief comment on its units (seconds)
where the constant is defined.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b7ee5dcf-ffe3-4e09-9502-4c23defcfec6

📥 Commits

Reviewing files that changed from the base of the PR and between 7a6efc5 and de18a2f.

📒 Files selected for processing (2)
  • src/lib/exporter/streamingDecoder.test.ts
  • src/lib/exporter/streamingDecoder.ts

@siddharthvaddem siddharthvaddem merged commit d968689 into main Mar 18, 2026
5 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Mar 18, 2026
8 tasks
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.

[Bug]: Using screen recorder fails to export to gif

1 participant