Skip to content

Conversation

@alex-Arc
Copy link
Collaborator

No description provided.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 10, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

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.

Walkthrough

This change refactors state update logic in the runtime service, enhances and adds new utility functions for more precise update detection, updates type definitions to use new types, and removes the associated test file for rundown service utilities. The update consolidates and simplifies how state changes are detected and broadcast, with stricter equality checks and improved type handling.

Changes

Cohort / File(s) Change Summary
Runtime Service Refactor
apps/server/src/services/runtime-service/RuntimeService.ts
Refactored state broadcast logic to use new utility functions, stricter deep equality checks, and structured cloning. Removed deprecated force update logic and reorganized state update triggers for clock, timer, runtime, group, and flag.
Utility Functions Overhaul
apps/server/src/services/runtime-service/rundownService.utils.ts
Introduced new helper functions (isNewSecond, getShouldRuntimeUpdate, getShouldGroupUpdate, getShouldFlagUpdate), updated timer update logic to accept full state objects, and removed getForceUpdate. Enhanced equality checks and update detection.
Type Updates in Store
apps/server/src/stores/runtimeState.ts
Changed property types in RuntimeState (groupNow and nextFlag) to use new types (GroupState, UpcomingEntry) and updated assignment logic in loadGroupFlagAndEnd.
Test File Removal
apps/server/src/services/runtime-service/__tests__/rundownService.utils.test.ts
Deleted all unit tests for rundown service utility functions, including those for clock and timer update detection.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~40 minutes

Possibly related PRs

  • fix: getShouldClockUpdate test #1165: Modifies and improves tests in rundownService.utils.test.ts, which is deleted in this PR; both PRs directly affect the same test file and related functionality.

Suggested labels

priority

Suggested reviewers

  • cpvalente
✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor-runtime-service

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@alex-Arc
Copy link
Collaborator Author

@coderabbitai full review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 10, 2025

✅ Actions performed

Full review triggered.

1 similar comment
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 10, 2025

✅ Actions performed

Full review triggered.

Copy link
Contributor

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

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5964a9e and c17d6e8.

⛔ Files ignored due to path filters (3)
  • packages/types/src/definitions/runtime/CurrentGroupState.type.ts is excluded by none and included by none
  • packages/types/src/definitions/runtime/RuntimeStore.type.ts is excluded by none and included by none
  • packages/types/src/index.ts is excluded by none and included by none
📒 Files selected for processing (4)
  • apps/server/src/services/runtime-service/RuntimeService.ts (5 hunks)
  • apps/server/src/services/runtime-service/__tests__/rundownService.utils.test.ts (0 hunks)
  • apps/server/src/services/runtime-service/rundownService.utils.ts (2 hunks)
  • apps/server/src/stores/runtimeState.ts (3 hunks)
💤 Files with no reviewable changes (1)
  • apps/server/src/services/runtime-service/tests/rundownService.utils.test.ts
🔇 Additional comments (7)
apps/server/src/stores/runtimeState.ts (2)

2-3: Type refactoring looks good

The migration from CurrentGroupState to GroupState and EntryMetaData to UpcomingEntry is consistent throughout the type definitions.

Also applies to: 39-39, 41-41


807-807: No references to removed nextFlag properties found

Searches did not uncover any uses of nextFlag.actualStart or nextFlag.expectedEnd elsewhere in the codebase. The simplified shape—only id and expectedStart—matches its type definition and introduces no breaking dependencies.

apps/server/src/services/runtime-service/rundownService.utils.ts (2)

18-24: Well-designed utility for second-level change detection

The isNewSecond function properly handles timer direction and undefined values, providing a clean abstraction for detecting second transitions.


79-105: Consistent and well-structured update detection logic

The new update detection functions (getShouldGroupUpdate and getShouldFlagUpdate) follow a consistent pattern with clear handling of undefined values and optional deep equality checks. The inline comments effectively document which fields are intentionally excluded from comparisons.

apps/server/src/services/runtime-service/RuntimeService.ts (3)

16-16: Import updates align with refactored state management

The migration to strictDeepEqual and the new utility functions properly support the enhanced state update detection logic.

Also applies to: 37-41


685-741: Excellent refactoring of broadcast logic

The refactored broadcast logic is cleaner and more maintainable with consistent use of utility functions and structuredClone for state management.

Note: Ensure structuredClone is available in your Node.js version (requires Node.js 17+).


752-764: Improved event update detection

The simplified event update logic with strictDeepEqual provides more reliable change detection for complex event objects.


// 4. find if we need to update the timer
const shouldUpdateTimer = getShouldTimerUpdate(this.lastIntegrationTimerValue, newState.timer.current);
const shouldUpdateTimer = isNewSecond(this.lastIntegrationTimerValue, newState.timer.current);
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Verify timer update detection is sufficient

The change from getShouldTimerUpdate to isNewSecond narrows the update detection to only second-level changes. This might miss other timer state changes (e.g., playback state, phase changes) that should trigger integrations.


🏁 Script executed:

#!/bin/bash
# Check if there are other places where timer state changes trigger integrations
rg "TimerLifeCycle\.onUpdate" -A 5 -B 5 --type ts

Length of output: 1056


To compare the old and new behaviors, let’s inspect the implementations of getShouldTimerUpdate and isNewSecond. Please run:


🏁 Script executed:

#!/bin/bash
# Locate getShouldTimerUpdate definition and context
rg "getShouldTimerUpdate" -A 5 -B 5 --type ts

# Locate isNewSecond implementation
rg "isNewSecond" -A 5 -B 5 --type ts

Length of output: 7969


Ensure comprehensive timer update detection

The new code in apps/server/src/services/runtime-service/RuntimeService.ts (around line 147) only calls:

const shouldUpdateTimer = isNewSecond(
  this.lastIntegrationTimerValue,
  newState.timer.current
);

By replacing getShouldTimerUpdate(previousTimer, currentTimer) with a single isNewSecond check, integrations will no longer fire when any of these timer properties change:

  • secondaryTimer
  • addedTime
  • duration
  • phase
  • playback

Please restore or extend the logic—e.g. by invoking getShouldTimerUpdate(this.previousState.timer, newState.timer)—so that updates to all relevant timer fields (not just the second tick) trigger the integration.

🤖 Prompt for AI Agents
In apps/server/src/services/runtime-service/RuntimeService.ts at line 147, the
current code only checks for timer updates using isNewSecond, which misses
changes in other timer properties like secondaryTimer, addedTime, duration,
phase, and playback. Replace the isNewSecond call with getShouldTimerUpdate,
passing this.previousState.timer and newState.timer, to ensure all relevant
timer fields are checked and trigger integration updates accordingly.

Copy link
Owner

@cpvalente cpvalente left a comment

Choose a reason for hiding this comment

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

small changes necessary, but good to merge

@alex-Arc alex-Arc force-pushed the refactor-runtime-service branch from b11ab39 to ebd6a6f Compare August 10, 2025 16:16
@alex-Arc alex-Arc merged commit 0cd71d1 into alpha-2 Aug 10, 2025
4 checks passed
@alex-Arc alex-Arc deleted the refactor-runtime-service branch August 10, 2025 16:45
cpvalente pushed a commit that referenced this pull request Aug 18, 2025
* refactor: trim type

* refactor: update runtime service data push logic

* keep using just deep

* reword didDependencyUpdate

* remove dulicate
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.

3 participants