Skip to content

fix(scrobble): send stops that arrive with a short host deadline - #12

Closed
rmccawl wants to merge 1 commit into
Silo-Server:mainfrom
rmccawl:fix/short-deadline-defers-all-events
Closed

rmccawl wants to merge 1 commit into
Silo-Server:mainfrom
rmccawl:fix/short-deadline-defers-all-events

Conversation

@rmccawl

@rmccawl rmccawl commented Nov 4, 2026 •

Copy link
Copy Markdown

Problem

When a Jellyfin-compat client sends a clean Stopped report, Silo delivers the stop as a confirmed stop with a 5-second deadline. It spends part of that deadline before calling the plugin. The plugin always kept a fixed 5-second margin before the deadline, so its time box came out negative. It deferred the stop as TEMPORARY ("Floppy sync time limit reached; the event will be retried") without sending any request. Every retry carries the same deadline, so the stop never reaches Floppy. Silo retries about every 15 seconds until the play session expires (24 hours by default), then drops the stop. A completed play still reaches Floppy later through history-export reconciliation, but the progress of an incomplete stop is lost.

Observed on a real deployment with plugin v0.3.1: one clean stop retried about 3,000 times over 13 hours. Floppy logged nothing for the session. A stop for the same episode that ended by expiry, which Silo sends without a deadline, was delivered normally.

Related issue: #11

Fix

syncTimeBox and syncRequestLimit now share untilMargin. It keeps syncDeadlineMargin (5 s) when at least 20 s remain, and otherwise keeps a quarter of the remaining time. A 4.5-second deadline now leaves about 3.4 s for the request and about 1.1 s to return the result.

  • Deadlines of 20 s or more, and calls without a deadline, behave exactly as before.
  • A call whose deadline has already passed still starts nothing, and its request limit stays 0.
  • listRatings uses the same helpers, so a short-deadline rating page now reads titles instead of returning nothing.

Risk

  • Retries: a short-deadline stop is now attempted instead of deferred. If Floppy accepts it but the host deadline runs out before Silo records success, Silo retries it. Floppy's scrobble endpoint is convergent for incomplete stops, and completed stops already check history first, so the retry does not create a duplicate play.
  • A cold Floppy write that takes longer than the shortened request limit still times out and is retried. Only the host can give confirmed stops a longer deadline. That is a separate silo-server change.
  • Privacy and sync scope: unchanged.

Tests

  • New TestApplyEventsSendsAStopUnderAShortHostDeadline: an end-to-end call to ApplyEvents against an httptest Floppy, with 4.5 s and 2 s deadlines. It asserts that the stop is APPLIED and Floppy receives exactly one incomplete stop.
  • Existing tests that encoded the old rule ("a deadline under 5 s does nothing") are updated on purpose, because that rule is the bug:
    • TestApplyEventsDefersEventsPastTheTimeBox: "call deadline already too close" (3 s, no events) became "short call deadline" (4 s, three events start) plus a new "call deadline already passed" case, which keeps the guarantee that nothing starts after the deadline.
    • TestSyncRequestLimitEndsBeforeTheHostDeadline: the 1 s case expected 0. It is now a 4 s case expecting just under 3 s, plus an already-passed case expecting 0.
    • TestSyncTimeBox: adds a 4 s case.
    • TestListRatingsKeepsResolvedTitlesWhenTheDeadlineCutsARead: uses a 2 s deadline, so the cut read still ends 0.5 s before the deadline and the test stays fast.

Before the fix (new and updated tests against the old provider.go):

--- FAIL: TestApplyEventsSendsAStopUnderAShortHostDeadline (0.00s)
    --- FAIL: TestApplyEventsSendsAStopUnderAShortHostDeadline/4.5s (0.00s)
        provider_test.go:484: results = [event_id:"stop-1"  status:WATCH_SYNC_APPLY_STATUS_RETRY  fault:{code:WATCH_SYNC_FAULT_CODE_TEMPORARY  safe_message:"Floppy sync time limit reached; the event will be retried"}], fault = <nil>, Floppy requests = 0; want the stop applied
    --- FAIL: TestApplyEventsSendsAStopUnderAShortHostDeadline/2s (0.00s)
        provider_test.go:484: results = [event_id:"stop-1"  status:WATCH_SYNC_APPLY_STATUS_RETRY  fault:{code:WATCH_SYNC_FAULT_CODE_TEMPORARY  safe_message:"Floppy sync time limit reached; the event will be retried"}], fault = <nil>, Floppy requests = 0; want the stop applied
--- FAIL: TestSyncTimeBox (0.00s)
    ratings_test.go:987: time box with a 4s deadline = -1.000000661s, want just under 3s
--- FAIL: TestSyncRequestLimitEndsBeforeTheHostDeadline (0.00s)
    ratings_test.go:1330: limit with a 4s deadline = 0s, want just under 3s
FAIL

After the fix:

--- PASS: TestApplyEventsSendsAStopUnderAShortHostDeadline (0.00s)
    --- PASS: TestApplyEventsSendsAStopUnderAShortHostDeadline/2s (0.01s)
    --- PASS: TestApplyEventsSendsAStopUnderAShortHostDeadline/4.5s (0.01s)
PASS

Validation

Go 1.26.5 (linux/amd64), the version in go.mod:

$ GOWORK=off go test ./...
ok  	github.com/Silo-Server/silo-plugin-watchprovider-floppy	0.006s
ok  	github.com/Silo-Server/silo-plugin-watchprovider-floppy/provider	1.513s
$ GOWORK=off go vet ./...
(no output, exit 0)
$ GOWORK=off go build ./...
(no output, exit 0)
$ GOWORK=off go run . manifest >/dev/null
(exit 0)
$ gofmt -l .
(no output)

go test -count=10 ./provider also passed. go test -race ./... also passed. The fixed plugin has not yet been run against a live Silo.

AI Disclosure

  • Harness: Claude Code (Claude Agent SDK)
  • Tool(s): Claude Code built-in file read/edit and shell tools; Go 1.26.5 toolchain
  • Model(s): claude-opus-5-5 (analysis, fix, review); claude-sonnet-5-5 (orchestration, independent re-verification)
  • Involvement: Fully AI-generated, written by Claude under human guidance and testing. The submitter directed the investigation and the fix, and the change was reproduced and re-verified in a separate environment.
  • Adversarial review: An independent Claude Code subagent (claude-opus-5-5) reviewed the diff against the plugin and silo-server sources. It traced the host deadline path, checked edge cases (no deadline, at least 20 s, short, expired), listRatings, host work after the reply, and duplicate-resend safety, and ran the changed tests 20 times at -cpu=1,4 and against the old provider.go. It found no blockers. Of its two nits, the code comment now names the confirmed Jellyfin-compat stop; the slightly slower ratings test was kept as is.

Note

Fix scrobble stop delivery under short host deadlines in provider

Stops were dropped when the host deadline was shorter than the fixed five-second margin, leaving no time to send anything. Adds provider.untilMargin, which subtracts the smaller of the fixed margin and one quarter of the remaining time, and uses it in provider.syncTimeBox and provider.syncRequestLimit.

  • With a deadline shorter than four margins, the time box and per-request limit now allow work for three quarters of the remaining time; the limit stays zero after the deadline has passed.
  • Adds TestApplyEventsSendsAStopUnderAShortHostDeadline in provider_test.go, covering 4.5-second and two-second deadlines with one incomplete stop request each.
  • Updates tests in provider_test.go and ratings_test.go for the new margins, including already-passed and negative deadlines.

Macroscope summarized 067550e.

Silo delivers a Jellyfin-compat client's Stopped report as a confirmed
stop under a 5-second deadline and spends part of it before calling the
plugin. The plugin kept a fixed 5-second margin, so its time box was
negative and it deferred the stop as TEMPORARY without sending a request,
on every retry, until Silo dropped the stop at session expiry.

Keep syncDeadlineMargin when at least 20 seconds remain, otherwise keep a
quarter of the remaining time. Longer deadlines are unchanged, and a call
whose deadline has passed still starts nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 4, 2026

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ad04e6a8-4dbe-4a40-989e-864bc5d90270
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Tip

🎯 Customize your risk assessments

Guide how CodeRabbit assesses merge risk and security architecture risk. Highlight sensitive changes and explain your security boundaries using Merge Risk Instructions and Security Risk Instructions in your review settings. Security architecture risk assessments require the Advanced plan or above.

✅ Automatic approvals, with your rules

Let CodeRabbit approve pull requests once required threads are resolved, pre-merge checks pass, and your risk limits are met. Enable Automatic approvals in review settings, with overrides for teams or file paths.

@silo-triage silo-triage Bot added the size/M 50–199 added + deleted lines (all files); change volume, not priority. label Nov 4, 2026
@silo-kody

silo-kody Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

Comment thread provider/provider.go
limit := defaultRequestTimeout
if deadline, ok := ctx.Deadline(); ok {
limit = min(limit, max(time.Until(deadline)-syncDeadlineMargin, 0))
limit = min(limit, max(untilMargin(deadline), 0))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

kody code-review Kody Rules high

Short deadlines leave less than the required response reserve

For deadlines under 20 seconds, untilMargin reserves only a quarter of the remaining time, allowing ApplyEvents requests to exceed the required five-second reserve. Use syncDeadlineMargin to calculate the cutoff.

Also found in:

  • provider/provider_test.go:483-483
  • provider/provider.go:143-143
  • provider/provider_test.go:487-487
  • provider/ratings_test.go:907-907

Kody rule violation: Reserve response time before the ApplyEvents host deadline

Prompt for LLM
File provider/provider.go, line 133:

Short deadlines leave less than the required response reserve

Use the fixed five-second margin when calculating the ApplyEvents request cutoff. For deadlines less than 20 seconds away, untilMargin reserves only a quarter of the remaining time, allowing upstream requests to run past the required host-deadline-minus-five-seconds cutoff.

**Also found in:**
- `provider/provider_test.go:483-483`
- `provider/provider.go:143-143`
- `provider/provider_test.go:487-487`
- `provider/ratings_test.go:907-907`

Kody rule violation: [Reserve response time before the ApplyEvents host deadline](https://kodus.siloserver.org/settings/code-review/1324553393/kody-rules/1ab2c6d6-2601-4df9-bf6f-9e7e6ef0110d?teamId=ba9922fc-c0ea-4cf8-87bb-9d4f42ffc73e)

Suggested code:

limit = min(limit, max(time.Until(deadline)-syncDeadlineMargin, 0))

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.

​

​

@silo-triage silo-triage Bot added bug Something isn't working triaged High-confidence review completed; does not mean fixed, validated, or accepted for release. labels Nov 4, 2026
@rmccawl

rmccawl commented Nov 4, 2026

Copy link
Copy Markdown
Author

Closing this. The change goes against the reserve rule Kody flagged, and the right fix is in the host.

Kody is right that the plugin must keep its fixed 5-second reserve before the host deadline. My proportional margin only worked around the real cause: Silo delivers a confirmed stop under a 5-second timeout (compatSessionSyncTimeout), so a plugin that reserves 5 seconds can never start the write, and Silo retries the stop with the same deadline forever. Restoring the fixed margin, as the review suggests, brings that back.

I filed the host-side bug with the analysis, the raw logs and a reference fix on a branch: Silo-Server/silo-server#3506. I am closing this pull request and #11 with it; no plugin change is needed.

Thanks for the review.

@rmccawl rmccawl closed this Nov 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working size/M 50–199 added + deleted lines (all files); change volume, not priority. triaged High-confidence review completed; does not mean fixed, validated, or accepted for release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant