Skip to content

Prevent server crash on malformed player config entries#3967

Merged
marcelveldt merged 2 commits into
devfrom
fix-malformed-player-config-crash
May 24, 2026
Merged

Prevent server crash on malformed player config entries#3967
marcelveldt merged 2 commits into
devfrom
fix-malformed-player-config-crash

Conversation

@marcelveldt
Copy link
Copy Markdown
Member

What does this implement/fix?

A race between delete_player_config() and a stale player update_state() could leave a partial player config in settings.json (only default_name and values, no player_id). On the next read, get_player_configs crashed with KeyError: 'player_id', breaking the players UI until the file was manually repaired.

Changes:

  • get_player_configs / get_player_config now tolerate (and auto-clean) entries missing the player_id base key, with a warning log.
  • set_player_default_name and set_player_type no-op when the player config root has been deleted, so a late update_state can't resurrect a partial entry via nested set().
  • remove_provider_config cleanup loop uses .get() instead of bracket access, so it survives the same kind of partial entry.

Related issue (if applicable):

  • N/A

Types of changes

  • Bugfix (non-breaking change which fixes an issue) — bugfix
  • New feature (non-breaking change which adds functionality) — new-feature
  • Enhancement to an existing feature — enhancement
  • New music/player/metadata/plugin provider — new-provider
  • Breaking change (fix or feature that would cause existing functionality to not work as expected) — breaking-change
  • Refactor (no behaviour change) — refactor
  • Documentation only — documentation
  • Maintenance / chore — maintenance
  • CI / workflow change — ci
  • Dependencies bump — dependencies

Checklist

  • The code change is tested and works locally.
  • `pre-commit run --all-files` passes.
  • `pytest` passes, and tests have been added/updated under `tests/` where applicable.
  • For changes to shared models, the companion PR in `music-assistant/models` is linked.
  • For changes affecting the UI, the companion PR in `music-assistant/frontend` is linked.
  • I have read and complied with the project's AI Policy for any AI-assisted contributions.

A race between delete_player_config() and a stale player update_state()
could leave a partial player config in settings.json (only default_name
and values, no player_id). The next config/players read then crashed
with KeyError: 'player_id', breaking the players UI.

Harden both sides:
- get_player_configs / get_player_config tolerate (and auto-clean)
  entries missing the player_id base key.
- set_player_default_name and set_player_type no-op when the player
  config root has been deleted, so a late update can't resurrect a
  partial entry via nested set().
- remove_provider_config cleanup loop uses .get() instead of bracket
  access, so it survives the same kind of partial entry.
Copilot AI review requested due to automatic review settings May 24, 2026 18:25
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens player configuration persistence against partially-written/malformed entries in settings.json, preventing crashes in the players UI after a race between config deletion and stale player state updates.

Changes:

  • Auto-detect and remove malformed player config entries missing player_id during get_player_configs, with warning logs.
  • Make get_player_config more tolerant of missing player_id for unavailable players by defaulting/sanitizing fields.
  • Prevent set_player_default_name and set_player_type from recreating partial config roots after deletion; make provider-config cleanup resilient to partial entries.

Comment thread music_assistant/controllers/config.py Outdated
@marcelveldt marcelveldt merged commit 4ce897b into dev May 24, 2026
9 checks passed
@marcelveldt marcelveldt deleted the fix-malformed-player-config-crash branch May 24, 2026 18:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants