Skip to content

fix(vegas): refresh scroll buffer on live score updates - #299

Merged
ChuckBuilds merged 2 commits into
mainfrom
fix/vegas-live-score-refresh
Mar 28, 2026
Merged

fix(vegas): refresh scroll buffer on live score updates#299
ChuckBuilds merged 2 commits into
mainfrom
fix/vegas-live-score-refresh

Conversation

@ChuckBuilds

@ChuckBuildsChuckBuilds commented Mar 28, 2026

Copy link
Copy Markdown
Owner

Summary

  • should_recompose() only checked for cycle completion or staging buffer content, but live plugin updates are queued in _pending_updates — not the staging buffer
  • The scroll display kept showing the old pre-rendered image until the full cycle ended, even though fresh scores were already fetched (visible in logs as "Vegas update tick: N plugin(s) updated")
  • Added has_pending_updates() to StreamManager and wired it into should_recompose() so hot_swap_content() triggers immediately when plugins report new data

Test plan

  • Deploy to test device and enable Vegas scroll mode with a live game plugin
  • Watch logs for "Vegas update tick: N plugin(s) updated"
  • Confirm display visually refreshes shortly after log message rather than waiting for full scroll cycle
  • Confirm no visual glitches during mid-scroll hot-swap

Fixes#230

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Improvements

    • Periodic live-priority monitoring added so the display automatically switches to higher-priority live modes and shows them immediately.
    • Timing for display loops improved for more reliable scheduling.
    • Rendering pipeline now detects pending updates affecting visible segments, enabling quicker recomposition and visual refreshes.
  • Performance

    • Throttling added to limit how often live-priority checks run, reducing unnecessary work.

@coderabbitai

coderabbitaiBot commented Mar 28, 2026

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@ChuckBuilds has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 10 minutes and 26 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 10 minutes and 26 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 706325d3-f1d5-47bd-b3f8-130d691089c9

📥 Commits

Reviewing files that changed from the base of the PR and between 738ba0a and 5cd9023.

📒 Files selected for processing (3)
  • src/display_controller.py
  • src/vegas_mode/render_pipeline.py
  • src/vegas_mode/stream_manager.py
📝 Walkthrough

Walkthrough

Added throttled, periodic live-priority preemption checks into the display controller (using monotonic timing) to allow immediate mode switches from long-running display loops; expanded Vegas render recomposition triggers to consider pending updates for currently visible segments via new StreamManager query methods.

Changes

Cohort / File(s)Summary
Display controller loop changes
src/display_controller.py
Introduced self._next_live_priority_check and switched timing to time.monotonic(). Both high-FPS and normal inner loops now perform a periodic (~30s when not self.on_demand_active) _check_live_priority() call that, if a different live_mode is returned, updates current_display_mode, sets force_change = True, best-effort updates current_mode_index, breaks the inner loop, and the outer loop continues to allow immediate live-mode display.
Render recomposition trigger
src/vegas_mode/render_pipeline.py
should_recompose() now also returns True when stream_manager.has_pending_updates_for_visible_segments() reports pending updates affecting currently visible segments, adding visible-segment update detection to recomposition criteria.
StreamManager query accessors
src/vegas_mode/stream_manager.py
Added thread-safe methods has_pending_updates() and has_pending_updates_for_visible_segments() that check _pending_updates (under _buffer_lock) and whether any pending updates target plugin IDs present in the active buffer's visible segments, respectively.

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check nameStatusExplanationResolution
Linked Issues check❓ InconclusiveThe PR addresses issue #230's LED board initialization reliability by implementing hot-swap on live updates and using monotonic clock timing to prevent NTP-induced issues, though the direct causation is not explicitly documented.Clarify how hot-swap triggering on live updates and monotonic clock timing directly resolve the LED board initialization failures described in #230, or update the issue link if this addresses a different problem.
✅ Passed checks (4 passed)
Check nameStatusExplanation
Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
Title check✅ PassedThe title accurately summarizes the main change: adding live score update detection to trigger immediate buffer refresh in Vegas mode.
Out of Scope Changes check✅ PassedAll changes are directly scoped to implementing live-update detection and monotonic timing for Vegas mode refresh, with no unrelated modifications detected.
Docstring Coverage✅ PassedNo functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/vegas-live-score-refresh

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.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/display_controller.py (1)

82-82: Use one monotonic helper for this 30s live-priority gate.

These two blocks are enforcing elapsed-time throttling, not wall-clock timestamps. On Raspberry Pi, time.time() can step when the system clock syncs, which can delay or bunch the next probe; moving this behind one helper backed by time.monotonic() keeps both loops consistent. If you make that switch, seed the loop start_time from the same clock as well.

Also applies to: 1794-1811, 1876-1890

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/display_controller.py` at line 82, Replace wall-clock time.time() uses
for the 30s live-priority gate with a single monotonic clock: initialize
self._next_live_priority_check using time.monotonic(), and change every
comparison and seeding of start_time/start_time-like variables used by the
live-priority gating logic to use time.monotonic() as well (or add a small
helper monotonic_now() and call it everywhere). Update the code paths that
set/compare self._next_live_priority_check and any start_time variables (the
live-priority probe loops mentioned in the comment) so they are all based on the
same monotonic clock to avoid clock-stepping issues on Raspberry Pi.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/vegas_mode/render_pipeline.py`:
- Around line 268-270: The current hot-swap check in render_pipeline (the call
to self.stream_manager.has_pending_updates()) triggers recomposition for any
queued plugin update; change this to only trigger when a pending update affects
visible segments by adding a StreamManager method like
has_pending_updates_for_visible_segments that checks whether any plugin_id in
self._pending_updates intersects the set of plugin_ids present in
self._active_buffer (only consider segments with images), and then replace the
render_pipeline call to has_pending_updates() with
has_pending_updates_for_visible_segments() so hot_swap_content() runs only for
updates that can change the current scroll.
---
Nitpick comments:
In `@src/display_controller.py`:
- Line 82: Replace wall-clock time.time() uses for the 30s live-priority gate
with a single monotonic clock: initialize self._next_live_priority_check using
time.monotonic(), and change every comparison and seeding of
start_time/start_time-like variables used by the live-priority gating logic to
use time.monotonic() as well (or add a small helper monotonic_now() and call it
everywhere). Update the code paths that set/compare
self._next_live_priority_check and any start_time variables (the live-priority
probe loops mentioned in the comment) so they are all based on the same
monotonic clock to avoid clock-stepping issues on Raspberry Pi.
🪄 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: 819c8ffd-56fd-459e-8a5e-1ceb91a35ebf

📥 Commits

Reviewing files that changed from the base of the PR and between 5ddf8b1 and 211ff59.

📒 Files selected for processing (3)
  • src/display_controller.py
  • src/vegas_mode/render_pipeline.py
  • src/vegas_mode/stream_manager.py

Comment threadsrc/vegas_mode/render_pipeline.py Outdated
ChuckBuildsand others added 2 commits March 28, 2026 13:17
should_recompose() only checked for cycle completion or staging buffer
content, but plugin updates go to _pending_updates — not the staging
buffer. The scroll display kept showing the old pre-rendered image
until the full cycle ended, even though fresh scores were already
fetched and logged.
Add has_pending_updates() check so hot_swap_content() triggers
immediately when plugins have new data.
Fixes#230
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1. Replace has_pending_updates() with has_pending_updates_for_visible_segments()
so hot_swap_content() only fires when a pending update affects a plugin that
is actually in the active scroll buffer (with images). Avoids unnecessary
recomposition when non-visible plugins report updates.
2. Switch all display-loop timing (start_time, elapsed, _next_live_priority_check)
from time.time() to time.monotonic() to prevent clock-stepping issues from
NTP adjustments on Raspberry Pi.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@ChuckBuilds
ChuckBuildsforce-pushed the fix/vegas-live-score-refresh branch from 738ba0a to 5cd9023CompareMarch 28, 2026 17:17
@ChuckBuilds
ChuckBuilds merged commit ee4149d into mainMar 28, 2026
1 check passed
@ChuckBuilds
ChuckBuilds deleted the fix/vegas-live-score-refresh branch March 28, 2026 17:18
ChuckBuilds added a commit that referenced this pull request Jul 12, 2026
…or (#395)
Investigating a user report that Vegas scroll mode doesn't update scores
or game status. Root cause: PR #299 (Mar 28) added a mechanism so a live
score change reached the ticker within a few seconds instead of waiting
for a full scroll cycle -- _tick_plugin_updates_for_vegas() diffed
plugin_last_update timestamps to detect which plugins got fresh data and
called coordinator.mark_plugin_updated() for each, and should_recompose()
checked has_pending_updates_for_visible_segments() to trigger an immediate
hot-swap.
PR #330 (May 14, multi-display wireless sync) refactored both call sites
while adding sync support and silently deleted this entire mechanism --
not just gated it behind the new sync-mode deferral it legitimately
needed, but removed it outright. The result: VegasModeCoordinator.
mark_plugin_updated() and StreamManager.has_pending_updates_for_visible_
segments() have been fully implemented but never called from anywhere
since. Vegas mode's only remaining freshness sources are a 5s content
cache TTL (fine) and full recompose at cycle boundaries, which depending
on min/max_cycle_duration can be minutes away -- so live scores/status
can sit stale far longer than a user would expect from a "live" ticker.
Fix:
- Restored _tick_plugin_updates_for_vegas() in display_controller.py,
wired as the Vegas coordinator's update callback in place of the plain
_tick_plugin_updates(). Diffs plugin_last_update before/after the tick
and calls vegas_coordinator.mark_plugin_updated(plugin_id) for each
plugin that actually got new data (rather than returning the list, since
the callback interface no longer consumes a return value).
- Restored the has_pending_updates_for_visible_segments() check in
render_pipeline.should_recompose(), positioned after (not instead of)
the sync-mode early return PR #330 added, so standalone installations
regain immediate refresh while synced leader/follower pairs correctly
keep deferring hot-swaps to cycle boundaries as PR #330 intended.
Test plan:
- Added test_display_controller_vegas_tick.py and
test_vegas_render_pipeline_recompose.py -- neither area had any prior
test coverage, which is very likely why this regression went unnoticed
for ~2.5 months.
- Verified both new test files fail against the pre-fix code (swapped in
the current main versions of both files) with exactly the expected
errors -- AttributeError for the deleted method, and the recompose
assertion returning False instead of True -- then pass against the fix.
- Confirmed the sync-mode deferral this restoration must not break still
holds: test_sync_active_defers_pending_updates_to_cycle_boundary.
- Full related suite (test_vegas_plugin_adapter, test_vegas_config,
test_display_controller_plugin_toggle, test_display_controller_
optimizations, test_plugin_system): 108 passed, 1 pre-existing failure
unrelated to this change (test_circuit_breaker, stale mock signature).
- Full CI plugin-safety suite (test_harness, test_visual_rendering,
test_plugin_matrix): 52 passed, 2 pre-existing skips.
ChuckBuilds added a commit that referenced this pull request Jul 12, 2026
…mutation (#398)
* fix(vegas): restore live plugin-update refresh dropped by sync refactor
Investigating a user report that Vegas scroll mode doesn't update scores
or game status. Root cause: PR #299 (Mar 28) added a mechanism so a live
score change reached the ticker within a few seconds instead of waiting
for a full scroll cycle -- _tick_plugin_updates_for_vegas() diffed
plugin_last_update timestamps to detect which plugins got fresh data and
called coordinator.mark_plugin_updated() for each, and should_recompose()
checked has_pending_updates_for_visible_segments() to trigger an immediate
hot-swap.
PR #330 (May 14, multi-display wireless sync) refactored both call sites
while adding sync support and silently deleted this entire mechanism --
not just gated it behind the new sync-mode deferral it legitimately
needed, but removed it outright. The result: VegasModeCoordinator.
mark_plugin_updated() and StreamManager.has_pending_updates_for_visible_
segments() have been fully implemented but never called from anywhere
since. Vegas mode's only remaining freshness sources are a 5s content
cache TTL (fine) and full recompose at cycle boundaries, which depending
on min/max_cycle_duration can be minutes away -- so live scores/status
can sit stale far longer than a user would expect from a "live" ticker.
Fix:
- Restored _tick_plugin_updates_for_vegas() in display_controller.py,
wired as the Vegas coordinator's update callback in place of the plain
_tick_plugin_updates(). Diffs plugin_last_update before/after the tick
and calls vegas_coordinator.mark_plugin_updated(plugin_id) for each
plugin that actually got new data (rather than returning the list, since
the callback interface no longer consumes a return value).
- Restored the has_pending_updates_for_visible_segments() check in
render_pipeline.should_recompose(), positioned after (not instead of)
the sync-mode early return PR #330 added, so standalone installations
regain immediate refresh while synced leader/follower pairs correctly
keep deferring hot-swaps to cycle boundaries as PR #330 intended.
Test plan:
- Added test_display_controller_vegas_tick.py and
test_vegas_render_pipeline_recompose.py -- neither area had any prior
test coverage, which is very likely why this regression went unnoticed
for ~2.5 months.
- Verified both new test files fail against the pre-fix code (swapped in
the current main versions of both files) with exactly the expected
errors -- AttributeError for the deleted method, and the recompose
assertion returning False instead of True -- then pass against the fix.
- Confirmed the sync-mode deferral this restoration must not break still
holds: test_sync_active_defers_pending_updates_to_cycle_boundary.
- Full related suite (test_vegas_plugin_adapter, test_vegas_config,
test_display_controller_plugin_toggle, test_display_controller_
optimizations, test_plugin_system): 108 passed, 1 pre-existing failure
unrelated to this change (test_circuit_breaker, stale mock signature).
- Full CI plugin-safety suite (test_harness, test_visual_rendering,
test_plugin_matrix): 52 passed, 2 pre-existing skips.
* fix(vegas): lock plugin_last_update snapshot/diff against concurrent mutation
_tick_plugin_updates_for_vegas() snapshotted and later re-iterated
plugin_manager.plugin_last_update from the Vegas background update-tick
thread while the main render loop (or other callers) could mutate the
same dict concurrently — a real race (unprotected dict iteration/mutation
across threads), not just a style nit.
Move the snapshot/update/diff into a new locked
PluginManager.run_scheduled_updates_with_changes() so all reads and
mutations of plugin_last_update happen under one lock, and update
DisplayController to use it. The lock is only held around the dict
accesses, not the update pass itself, so slow plugin update() calls don't
serialize against other callers.
Also add a regression test covering that the Vegas coordinator is wired
to the Vegas-aware tick callback rather than the plain one.
Skipped as not worth the change:
- Narrowing the broad `except Exception` around
vc.mark_plugin_updated(plugin_id) to specific types: it's a deliberate
per-plugin isolation boundary (matches the same pattern used elsewhere
in this file for plugin/coordinator calls) and there's no documented,
stable set of exceptions that call can raise to narrow to.
- Adding an inactive-DisplaySyncManager test to
test_vegas_render_pipeline_recompose.py: verified
VegasModeCoordinator.set_sync_manager() already normalizes a
SyncRole.STANDALONE manager to None before handing it to the render
pipeline (src/vegas_mode/coordinator.py:152-156), so should_recompose()'s
`is not None` check is correct in practice; the suggested case is
already covered by that normalization.
---------
Co-authored-by: Claude <noreply@anthropic.com>
Sign up for freeto 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.

Fresh Install / LED Board not initialized

1 participant

@ChuckBuilds