Skip to content

fix(lint): derive the root duration with the parser's timing reader - #8032

Merged
jrusso1020 merged 2 commits into
heygen-com:mainfrom
zhengqiuyang:fix/lint-negative-start
Nov 17, 2026
Merged

jrusso1020 merged 2 commits into
heygen-com:mainfrom
zhengqiuyang:fix/lint-negative-start

Conversation

@zhengqiuyang

Copy link
Copy Markdown
Contributor

What

Derive a composition's root length from its clips through the same timing contract the renderer uses, instead of re-parsing data-start with a raw Number(). A clip authored at data-start="-2" no longer disappears from the derivation.

Why

deriveDurationFromClips read data-start with Number(), so -2 produced an end of -1. resolveCompositionDuration only counts positive ends, so the clip vanished and the composition was reported as root_composition_missing_duration_source — an error that blocks strict renders — even though the parser clamps the same start to zero and renders the clip for its full length.

The same mismatch made data-start="-0.5" report "at least 1.5s" while the renderer runs 2s.

Related work

Fixes #8031.

The derivation rule itself came from #4174 ("a composition with no authored length takes it from its clips"); this keeps that feature's behavior for media defaults while aligning the start parsing with readClipTiming.

How

  • deriveDurationFromClips now calls readClipTiming with the tag's attribute reader. timing.start is the parser's clamped start (or null for a reference start, which stays a runtime-pending clip), and timing.duration is the authored length, including the legacy data-end path.
  • The media branch is unchanged: untimed images still get their dropped-image default length.
  • Added a regression test: negative start derives "at least 1s" instead of the fatal error.

Test plan

  • Unit tests added/updated
    • composition.test.ts new case: data-start="-2" + data-duration="1" → root_composition_duration_derived "at least 1s"; fails on main with the missing-source error.
  • Typecheck: @hyperframes/lint typecheck passes.
  • comment-ratchet and oxfmt --check pass on the changed files.
  • Manual testing performed — not needed for a pure lint rule.
  • Documentation updated — not applicable.
  • Comments follow CONTRIBUTING.md.

Commands run:

vitest composition.test.ts -t "derives from a negative start" -> pass (fails on main)
bun run --filter @hyperframes/lint typecheck -> 0
node scripts/comment-ratchet.mjs -> 0
oxfmt --check on the changed files -> pass

`deriveDurationFromClips` read `data-start` with a raw `Number()`, so a clip
authored at `data-start="-2"` produced an end of `-1`. `resolveCompositionDuration`
only counts positive ends, so the clip vanished from the derivation and the
composition was reported as having no duration source at all — a hard error that
blocks strict renders, even though the parser clamps the same start to zero and
renders the clip for its full length.

Read the start through `readClipTiming`, the same contract parser the renderer
uses, and keep the media-duration default for untimed images.

@jrusso1020 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approving. Reading data-start through readClipTiming clamps an absolute start to 0, so a clip with a negative start now counts toward the derived duration instead of being dropped. The runtime (core/src/runtime/init.ts) and the parser clamp the same way, so lint now matches the renderer, including the -0.5 case in #8031.

fails without the fix: root_composition_missing_duration_source > derives from a negative start like the parser does. With main's composition.ts, that test fails (1 failed, 321 passed). At this head the full lint suite passes, 1328/1328, and tsc --noEmit is clean.

The one other behavior change: when data-duration is ≤0 or non-numeric and data-end is valid, the clip is now dropped instead of falling back to end - start. That input is malformed and this matches the parser, so it doesn't block. A test or a line in the PR body would make the change explicit.

Optional nits:

  • composition.ts:1974-1976 repeats readTagTiming(rawTag) (L84). readTagTiming(tag.raw) would do the same.
  • Follow-up, not for this PR: core/src/compiler/timingCompiler.ts (~L194) still adds start and duration without the clamp when it writes data-end. A negative start then yields data-end=-1 next to a clamped end of 1, which triggers conflicting-end.
  • #8037 edits a different hunk of the same file. Whichever lands second may need a rebase.

Review by Rames

`deriveDurationFromClips` read `data-start` with a raw `Number()`, so a clip
authored at `data-start="-2"` produced a negative end and vanished from the
derivation. Read the start through `readClipTiming`, which clamps it to zero,
and keep `readAuthoredDurationSeconds` for the authored length so a valid
`data-end` still backs an unparseable `data-duration`.
@zhengqiuyang

Copy link
Copy Markdown
Contributor Author

Thanks — fixed the data-end fallback regression and the nit in d30df74.

  • deriveDurationFromClips now uses readClipTiming only for the start (the clamp is the fix) and keeps readAuthoredDurationSeconds for the authored length, so an unparseable data-duration with a valid data-end still derives end - start as before.
  • Added falls back to a valid data-end when data-duration is not numeric; it fails with the item from your review and passes now.
  • Replaced the inline reader with readTagTiming(tag.raw).

pytest/vitest: the composition file still shows the same 42 pre-existing Windows failures as clean main for me; the new cases pass, lint typecheck and comment-ratchet are clean.

@jrusso1020 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-approving at d30df74. The new commit makes two changes:

  • The start is read with readTagTiming(tag.raw), which was my nit.
  • The authored length now comes from readAuthoredDurationSeconds(getAttr, start). When data-duration isn't numeric, it falls back to data-end - start again, as it did on main, and the start is now clamped.

That closes the behavior change I noted. The new test checks it: falls back to a valid data-end when data-duration is not numeric. With that line reverted to timing.duration, the test fails (1 failed, 322 passed). At this head, composition.test.ts passes 323/323 and tsc --noEmit in packages/lint is clean.

Review by Rames

@jrusso1020
jrusso1020 added this pull request to the merge queue Nov 17, 2026
Merged via the queue into heygen-com:main with commit 4019916 Nov 17, 2026
89 of 91 checks passed
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]: check: a negative data-start hides the composition's derived duration and blocks the render

2 participants