Skip to content

fix(mpris): publish a track id so absolute seeks reach spotatui - #809

Merged
LargeModGames merged 1 commit into
LargeModGames:mainfrom
Wassergeist:fix/mpris-trackid
Oct 13, 2026
Merged

LargeModGames merged 1 commit into
LargeModGames:mainfrom
Wassergeist:fix/mpris-trackid

Conversation

@Wassergeist

@Wassergeist Wassergeist commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #808. spotatui's MPRIS metadata had no mpris:trackid, so clients refused SetPosition (playerctl position 60: "Could not get track id to set position"). Relative seeks worked.

  • track_object_path(): /org/spotatui/track/<16 hex> from a hash of title, artists, album and length (DefaultHasher::new() has fixed keys, so it is stable). The same track gets the same id from every path that publishes it: the native player's track change and the driver's sync read the same native_track_info fields; a remote device or a local file only has one path.
  • build_metadata() sets it as mpris:trackid next to the existing fields.
  • set_position_targets_current(): a SetPosition with spotatui's id of another track is ignored, as the spec asks, so a seek sent right before a track change does not land in the next song. NoTrack and ids of a client's own still go through: since fix(mpris): Fix position tracking and seeking #85, widgets and KDE Connect seek without a real id, and I didn't want to break them.

All in src/infra/mpris.rs, plus a CHANGELOG entry; no caller changes. macOS and Windows have no track-id concept and are untouched.

Testing

  • cargo fmt --all -- --check: clean.
  • cargo clippy -- -D warnings and with --no-default-features for telemetry,tui, telemetry, telemetry,streaming and the gui leg: clean.
  • cargo test: 2037 passed, 0 failed, 7 ignored. cargo test --no-default-features --features telemetry,tui: 1555 passed. gui leg: 1741 passed.
  • tools/check_gates_ratchet.sh origin/main: ok.
  • 8 new tests in mpris.rs (stable id, different fields give different ids, no field run-together, valid id outside /org/mpris, the metadata carries it, the three SetPosition cases). Without .trackid(…) in build_metadata the metadata test fails.
  • Manually on Linux (NixOS, Ghostty), with playerctl and busctl --user call … SetPosition, on the local player and on a Sonos room (feat(spotify): play on Cast and Connect speakers on the LAN #795):
    • The metadata carries mpris:trackid (/org/spotatui/track/…), and playerctl position 60 jumps to 1:00 (on the room: PUT /v1/me/player/seek?position_ms=60000).
    • After next, a SetPosition with the previous track's id is ignored (no seek in the log), one with NoTrack and one with the current id both seek.
    • On main without the fix, playerctl position 60 still fails with "Could not get track id to set position".

Additional notes

  • The id comes from the metadata rather than the URI because that is what every caller of set_metadata already passes. Two different tracks with identical title, artists, album and length would share an id; then a stale seek is simply not filtered, which is the old behavior.
  • Right after an end of track the native snapshot can fall back to the polled context for a moment, so the id may briefly change for the same song if the context reports a different album or length.
  • Not changed: a SetPosition outside 0..length is still clamped rather than ignored.

Summary by CodeRabbit

  • New Features
    • MPRIS track metadata now includes a track ID, enabling media clients to identify the track associated with a seek request.
    • Clients that do not provide a track ID remain supported.
  • Bug Fixes
    • Seek requests targeting a track that has changed are ignored, preventing playback from jumping to an unintended position. Other clients’ track IDs remain accepted.

The MPRIS metadata had no mpris:trackid, so clients refused SetPosition
(playerctl: "Could not get track id to set position"); relative seeks
worked. Each track now gets /org/spotatui/track/<hash of its title,
artists, album and length>, the same from every path that publishes it.

A SetPosition carrying spotatui's id of another track is ignored, as the
spec asks, so a seek sent just before a track change does not land in the
next song. Clients that send NoTrack or an id of their own keep working
as they did since LargeModGames#85.

Fixes LargeModGames#808
@coderabbitai

coderabbitai Bot commented Oct 13, 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: c81380d4-5f50-48ad-806d-dfa7b01b014c
📥 Commits

Reviewing files that changed from the base of the PR and between 34ff1e6 and 8473581.

📒 Files selected for processing: 2
  • CHANGELOG.md
  • src/infra/mpris.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

MPRIS metadata now includes a track ID derived from track metadata. SetPosition ignores requests with a stale spotatui track ID. Requests with foreign or missing IDs remain accepted.

Changes: MPRIS absolute seeking

Layer / File(s) Summary
Derive and publish track IDs
src/infra/mpris.rs
The metadata builder derives a track ID from the title, artists, album, and duration, then adds it to published metadata.
Validate SetPosition track IDs
src/infra/mpris.rs, CHANGELOG.md
SetPosition ignores a mismatched spotatui track ID when a current ID exists. Tests cover track ID generation, metadata publication, and request matching. The changelog documents absolute-seek support and stale-ID handling.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 84735

MPRIS metadata now publishes a track ID, so absolute seeks from clients like playerctl work. Stale spotatui IDs are ignored, and no merge-blocking risk remains.

Pre-merge checks: Passed 4
Passed 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 fix(mpris): prefix, describes the main MPRIS track ID change, and uses a concise imperative subject.
Linked Issues check Passed Issue #808 requires mpris:trackid metadata and working absolute SetPosition calls. The PR adds a valid /org/spotatui/track/ ID to build_metadata, uses the same metadata fields for ID generatio…
Out of Scope Changes check Passed The changes stay within issue #808. They modify MPRIS metadata and SetPosition handling in src/infra/mpris.rs, add focused tests, and document the behavior in CHANGELOG.md. No unrelated product …
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
✨ Simplify code
  • Create a new PR
  • Autofix · 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 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.99099% with 10 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/infra/mpris.rs 90.9% 10 Missing ⚠️

📢 Thoughts on this report? Let us know!

@LargeModGames
LargeModGames merged commit 7011be0 into LargeModGames:main Oct 13, 2026
32 checks passed
@Wassergeist
Wassergeist deleted the fix/mpris-trackid branch October 13, 2026 20:40
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.

MPRIS: no mpris:trackid, so absolute seeking (SetPosition) is refused by clients

2 participants