Skip to content

fix(playback): keep the track-end poll when a command lands early in the track - #725

Merged
LargeModGames merged 1 commit into
LargeModGames:mainfrom
Wassergeist:fix/end-poll-after-command
Oct 8, 2026
Merged

LargeModGames merged 1 commit into
LargeModGames:mainfrom
Wassergeist:fix/end-poll-after-command

Conversation

@Wassergeist

@Wassergeist Wassergeist commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #721, from @2570165831's review there.

poll_playback_soon moved the last-poll time back and always spent the track-end poll. Volume, shuffle and repeat don't change Spotify's timestamp, so a command early in a track used up that track's end poll and the next track showed up to playback_poll_seconds late.

The poll after a command now has its own deadline (command_poll_at) instead of moving the last-poll time, so the regular and the track-end poll keep their timing and nothing gets spent. The track-end poll is only spent when it actually fired.

This also fixes the thing I mentioned in #721: a poll already queued when the command lands no longer swallows the poll a second later, the deadline survives it.

Smaller things while at it:

  • the 429 log line is built outside warn! so the tests run it
  • tests for a podcast episode and an Unknown item (ads), using the episode() fixture from media_metadata (its test module is pub(crate) now, like the one in network/metadata.rs)

Testing

$ cargo fmt --all -- --check
(no diff)
$ cargo clippy --locked --no-default-features --features telemetry,tui -- -D warnings
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 6.52s
$ cargo test --locked --no-default-features --features telemetry,tui
test result: ok. 1464 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 8.90s
$ cargo clippy --locked -- -D warnings
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 6.60s
$ cargo test --locked
test result: ok. 1871 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 9.45s

a_command_early_in_the_track_keeps_its_end_poll keeps the same timestamp for the follow-up poll, as suggested, and fails with the old spend_track_end_poll() in poll_playback_soon.

Also tested with a release build (--debug):

  • Spotify web player playing, volume changed in spotatui a minute before the end: poll 1 s after the command, no state change reported for the volume, and the track-end poll still came, next track showed in about 1 s
  • iPhone playing, repeat changed early in the track: same

Summary by CodeRabbit

  • Bug Fixes
    • Playback status now refreshes shortly after a successful Web API command, without delaying a scheduled track-end update.
    • A command-triggered refresh no longer replaces an already scheduled track-end poll. Failed commands do not schedule an early playback refresh.

…the track

The poll after a Web API command moved the last-poll time back and marked
the track-end poll as spent. Volume, shuffle and repeat leave Spotify's
timestamp alone, so a command early in a track cancelled that track's end
poll. The command poll now has its own deadline. It also survives a poll
that is already in flight.

The 429 log line is built outside the macro so the tests run it, and
episodes and unknown items get a test.
@coderabbitai

coderabbitai Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: LargeModGames/spotatui/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 29966621-6c8a-44d1-bbf5-001ab50ee959
📥 Commits

Reviewing files that changed from the base of the PR and between 9f4f956 and 082bcca.

📒 Files selected for processing (6)
  • src/core/app/construction.rs
  • src/core/app/mod.rs
  • src/core/app/tick.rs
  • src/infra/media_metadata.rs
  • src/infra/network/playback.rs
  • src/infra/network/requests.rs

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

The app now stores a separate deadline for playback polling after a Web API command. Poll dispatch checks that deadline without replacing regular or track-end polling. Tests cover command-poll timing and related polling cases. The 429 warning path formats its message before logging.

Changes

Command-triggered Playback Polling

Layer / File(s) Summary
Store and schedule command-poll deadlines
src/core/app/mod.rs, src/core/app/construction.rs, src/core/app/tick.rs
App stores a separate command-poll deadline, initializes it to None, and sets it after a Web API command without shifting the regular poll timestamp or consuming the track-end poll.
Dispatch polls and verify deadline behavior
src/core/app/tick.rs, src/infra/media_metadata.rs, src/infra/network/playback.rs
Polling dispatch checks the command deadline and clears it when a fetch starts. Tests cover due and repeated deadlines, in-flight fetches, track-end polling, regular polling, and command outcomes.

429 Warning Formatting

Layer / File(s) Summary
Format the 429 warning
src/infra/network/requests.rs
The 429 path formats the warning string before logging it. The logged content is unchanged.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 082bc

No actionable merge-blocking risk is identified; the change is ready for normal merge checks.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title uses the allowed conventional-commit prefix fix(playback):, clearly describes the main playback polling fix, and uses a concise imperative subject.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
✨ Simplify code
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@codecov

codecov Bot commented Oct 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@LargeModGames
LargeModGames merged commit a92fbe4 into LargeModGames:main Oct 8, 2026
31 checks passed
@kapok-4o

kapok-4o commented Oct 8, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the quick follow-up, @Wassergeist! This is the cleaner of the two fixes, and I checked it locally: a volume change 60 s before the end no longer uses up the track-end poll (the same test fails on main), and the poll-already-in-flight case is fixed too. Looks good to me.

Two small, non-blocking ideas:

  1. Maybe keep a_command_near_the_track_end_still_waits_a_second from fix(playback): poll another device at the configured interval #721. It still passes as written and guards "no immediate poll inside the track-end window".
  2. a_command_never_delays_a_poll_that_is_already_due now passes trivially; it could also check the poll a second after the command.

Totally fine to leave both for later.

@Wassergeist

Copy link
Copy Markdown
Contributor Author

@2570165831 Thanks for checking it locally! Since it's merged already, I'll keep both in mind for the next time I'm in that code.

@Wassergeist
Wassergeist deleted the fix/end-poll-after-command branch October 8, 2026 16:54
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