Skip to content

[bug] Webhook sync can apply same-item deliveries out of order across API nodes #2192

Open

Description

@Quick104

What happened

Found in code review of #2178 and #2179; not reproduced on a deployment.

Webhook sync processes each delivery as separate steps with no lock: read the item state for the external user and item, check freshness against the profile's Silo progress, write watch state, then save the item state. Two deliveries for the same external user and item can run at the same time on different API nodes, or as concurrent requests on one node. Their steps can then interleave:

  • An older completion can read the item state before a newer mark-unplayed saves its own, then finish last. The item ends up watched, and the saved last_event_at moves back to the older event.
  • For a mark-unplayed, a native Silo progress write can land after the freshness check passes but before RemoveHistoryItems runs. The removal then deletes that newer progress and can hide its history.

Every progress event already has the same check-then-write gap on main; #2178 adds Jellyfin played and unplayed marks, which take the same path.

Steps to reproduce

  1. Map a Jellyfin user to a Silo profile through Webhook Sync.
  2. Send two UserDataSaved / TogglePlayed deliveries for the same item at the same moment, an older played: true and a newer played: false, so that two API nodes handle them concurrently.
  3. Repeat until the older one finishes last.

For the second case, start native playback of the item in Silo while a delayed played: false delivery for it is being processed.

Expected behavior

Deliveries for one external user and item apply in timestamp order, and a mark-unplayed never removes progress that is newer than the event. This is the ordering the watch-state rules in docs/settings-api.md describe.

Silo version / commit

main at the time of #2178 and #2179.

Area

Webhook Sync (internal/webhooksync) and the user stores' progress removal.

Technical notes

Possible fixes:

  • Serialize processing per connection, external user, and item across nodes, for example with a transaction-scoped Postgres advisory lock around the read, apply, and save steps. The lock has to cover the user-store writes too, which may be SQLite.
  • Make the writes conditional instead: save item state only when last_event_at is not newer, and give the user stores a removal that skips progress newer than the event time.

Review threads: #2178 (comment) and #2179 (comment)

Activity

  1. added
    bug
    on Oct 9, 2026
  2. Quick104 commented on Nov 26, 2026

    @Quick104
    ContributorAuthor

    A second form of this race, from agent runtime testing for validation task #1238 (C2) on build 2970 · a16a24720, one API server: sending an older "played" and a newer "unplayed" Jellyfin webhook event at the same moment ended with the item played in 7 of 160 rounds. The older event writes Silo progress; before it saves its item state, the newer event reads it, sees no matching own write and is skipped as "local watch progress is newer". All 7 failures were rounds where both timestamps fell in the same whole second (0 of 5 cross-second rounds failed). Same unlocked check-then-write gap as described above.

    Evidence: https://evidence.siloserver.org/r/silo-server/v1-validation-1238/

    Posted with Claude Code (claude-sonnet-5-5 testing, claude-opus-5-5 verification) and GitHub CLI at the maintainer's direction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions