Skip to content

fix: prevent undesired timelines reaching TSR#1627

Open
ianshade wants to merge 3 commits intoSofie-Automation:mainfrom
tv2norge-collab:contribute/EAV-737
Open

fix: prevent undesired timelines reaching TSR#1627
ianshade wants to merge 3 commits intoSofie-Automation:mainfrom
tv2norge-collab:contribute/EAV-737

Conversation

@ianshade
Copy link
Contributor

@ianshade ianshade commented Jan 29, 2026

About the Contributor

This pull request is posted on behalf of TV 2 Norge.

Type of Contribution

This is a:

Bug fix

Current Behavior

Timeline might be saved and fast-tracked to TSR (Playout Gateway) before it is certain that the result of the playout job will be committed.
Moreover, it happens before onRundownActivate/onRundownDeactivate callbacks run. Consequence is twofold:

  • when an exceptions is thrown during one of those callbacks, an unwanted timeline is still sent to the TSR as if activation/deactivation succeeded
  • those callbacks, even though capable, thanks to their contexts, can't be used to perform TSR actions (e.g. initializations and cleanups) that need to execute before the timeline changes from/to the studio baseline, which is crucial to avoid intermittent states (when the rundown timeline briefly reaches a device that has not been fully initialized)

New Behavior

This pull request refactors and improves how and when timeline updates are triggered, generated, and published for both playlists and studios in the playout worker. The key change is to decouple timeline generation from immediate execution, instead marking that a timeline update is needed and regenerating timelines just before saving the model - when it is definitely correct and safe to do so. The operations are ordered so that lenghty execution of the callbacks does not contribute to the latency measured between timeline generation and its resolution in TSR.

Testing

  • I have added one or more unit tests for this PR
  • I have updated the relevant unit tests
  • No unit test changes are needed for this PR

Affected areas

Playout logic - generating, fast-tracking and saving the timeline

Time Frame

Other Information

Status

  • PR is ready to be reviewed.
  • The functionality has been tested by the author. (before porting to release53)
  • Relevant unit tests has been added / updated.
  • Relevant documentation (code comments, system documentation) has been added / updated.

prevents from submitting an incorrect timeline before the model is ready to be saved (if `updateTimeline` is not the last thing before saving, something might still throw, leading to disposal of the model);
makes sure it runs after deferBeforeSave callback, as they might need to run before submitting the timeline (e.g. in order for onRundownActivate to complete device preparation before the rundown baseline reaches TSR)
…ing the timeline

moves timeline generation to `saveAllToDatabase`
@ianshade ianshade requested a review from a team as a code owner January 29, 2026 22:08
@coderabbitai
Copy link

coderabbitai bot commented Jan 29, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

  • 🔍 Trigger a full review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@codecov
Copy link

codecov bot commented Jan 29, 2026

@ianshade ianshade added the Contribution from TV 2 Norge Contributions sponsored by TV 2 Norge (tv2.no) label Jan 29, 2026
Copy link
Member

@nytamin nytamin left a comment

Choose a reason for hiding this comment

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

Sounds like a reasonable change to me.

Should we update the documentation of onRundownActivate / onRundownDeactivate to claify their capabilities while we're at it?

// Generate timeline if needed
if (this.#timelineNeedsRegeneration) {
await this.#regenerateStudioTimeline()
this.#timelineNeedsRegeneration = false
Copy link
Member

Choose a reason for hiding this comment

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

Should this.#timelineNeedsRegeneration = false be moved into this.#regenerateStudioTimeline()?

Since this.#regenerateStudioTimeline() is async, this.#timelineNeedsRegeneration = false should be done in the beginning of that method, I think.

Copy link
Member

Choose a reason for hiding this comment

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

I dont think it really makes a difference, as this is inside saveAllToDatabase which if anything else tries to modify the StudioPlayoutModel at the same time will be a race condition

@PeterC89 PeterC89 changed the base branch from release53 to main February 4, 2026 12:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Contribution from TV 2 Norge Contributions sponsored by TV 2 Norge (tv2.no)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants