Skip to content

fix(autoscan): don't record a failed poll's error on a source reset during it - #2205

Merged
Quick104 merged 3 commits into
Silo-Server:mainfrom
blurbery:fix/autoscan-stale-poll-error
Oct 15, 2026
Merged

Quick104 merged 3 commits into
Silo-Server:mainfrom
blurbery:fix/autoscan-stale-poll-error

Conversation

@blurbery

@blurbery blurbery commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Closes #2202
Related issue: N/A
Validation tasks: none

If an admin points an autoscan source at a different server, or changes its settings, while a poll of that source is running, and that poll then fails, the failure lands on the source as if it came from the new setup. The admin autoscan source list shows the old server's error ("Last poll failed: dial tcp: i/o timeout") for a server the source no longer uses, and last_run_at is stamped, so the source waits out its interval before its first poll of the new server. Once #2080 lands, that stamp also cancels the early poll #2080 sets up. This is most likely when the admin is repointing a source because its old server stopped answering, which is exactly when a poll sits in a connect timeout long enough to overlap the edit.

A successful poll already handles this: AdvanceMarker skips its write when the source or its connection changed while the poll ran. This change gives a failed poll the same check.

Approach

Validation

  • New DB tests, run against a disposable migrated Postgres 18 with pgvector: TestRecordErrorSkipsStalePoll (9 cases) and TestRecordErrorRejectsAnotherConnectionsRow. On main, with the test adapted to main's RecordError signature, the 5 cases where an edit changes the upstream fail, and so does the another-connection check. All of them pass on this branch.
  • Service tests check that a failed poll's error carries the rows the poll read (a plugin error, a connection that failed after its row was read, and a connection lookup that failed outright), and that the event says when the error was kept off the source.
  • go test -race ./internal/autoscan/ with the test database passes, including the existing AdvanceMarker and marker-reset tests after the shared-helper change.
  • Merged with fix(autoscan): poll at once after a marker reset, and not for a respelled URL #2080 (ec6329d): no textual conflicts. After moving fix(autoscan): poll at once after a marker reset, and not for a respelled URL #2080's one RecordError call to the new signature, the autoscan package passes, and the source stays "Not run yet" and due at the next cycle after the stale poll fails.
  • golangci-lint on the changed lines of internal/autoscan, go vet and gofmt: clean.
  • CI on 88cfac0, which pinned the five autoscan DB tests (TestRecordErrorSkipsStalePoll, TestRecordErrorUnknownSource, TestRecordErrorRejectsAnotherConnectionsRow, and, because this PR rewrites AdvanceMarker's body, TestAdvanceMarkerSkipsStalePoll and TestAdvanceMarkerRequiresBoundConnectionRow) as DB contracts: every Go job passed, and Go DB pins ran all five against Postgres (run).
  • 9ff6252 takes those pins back out for now. Any change under scripts/ makes CI run the web jobs, and main fails the web launch bundle budget until fix(web): keep the download storage API out of the launch bundle #2204 lands ([bug] Web build fails the launch bundle budget on main after #2168 #2203); this PR changes no web code. It changes no code either, so the results above apply to it. I'll add the pins back once main's web build is green.
  • CI on 9ff6252: every job passed, with the web jobs skipped because nothing under web/ or scripts/ changes (run).
  • Not run against a live Sonarr or Radarr.

Evidence

Evidence: https://evidence.siloserver.org/r/silo-server/pr-2205/

The latest version has before-and-after captures from a live run on a local test server, main at bf63b3d and then 9ff6252, with the Sonarr & Radarr Autoscan plugin and two local Sonarr stand-ins. A first poll succeeds. A second poll hangs on the old server, the connection is repointed to the new one while it runs, and the poll then fails.

  • Autoscan Activity, Polls, at phone and desktop width: on main the failed poll's event shows only the old server's timeout. With this change the same error ends with "source changed during the poll; its error was not stored on the source". The desktop poll table doesn't wrap long errors (on main too), so the note is cut off there; the phone captures and the trimmed event excerpt on the page show the full text.
  • Source list: on main the source ends at "Last poll failed" with the old server's timeout. With this change it keeps "Last checked" from the earlier poll.

The previous version of the page has the Go test runs and the run merged with #2080, where the source stays "Not run yet" and polls at the next cycle.

Risks

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • The Evidence section shows every change a user can see, or says there is none.

AI Disclosure

  • Harness: Claude Code (desktop app)
  • Tool(s): Claude Code, with subagents for the evidence runs and an independent review of this diff; go, gh, golangci-lint, a disposable Postgres 18 with pgvector, playwright-core driving Chrome for the evidence captures
  • Model(s): claude-opus-5-5
  • Involvement: AI-assisted
  • Adversarial review: A separate Claude Code subagent reviewed the diff against the source: AdvanceMarker's behaviour after the refactor, lock order against UpdateSource and UpdateConnection on main and with fix(autoscan): poll at once after a marker reset, and not for a respelled URL #2080, the nil-connection and webhook paths, the SQL the shared helper builds, the docs, and test coverage. It found no blockers. Its should-fix items and nits are done in 88cfac0: the docs/admin-api.md sentence, CI DB-contract coverage for the rewritten AdvanceMarker, an API key rotation case, service tests for a skipped write and the resolve-failure branches, the binding check moved into the shared helper, the event note, and the out-of-date comments. A second subagent ran the evidence and found that fix(autoscan): poll at once after a marker reset, and not for a respelled URL #2080's test needs the one-line update described above.

AI-assisted with Claude Opus. I directed the task and designed the work.

Note

Fix autoscan RecordError to skip stale sources after a reset during a poll

A poll failure used to be written to the source by ID alone, so it could land on a source that was reset or changed while the poll was running. Now the poll captures a PollFailure snapshot (source row, optional connection row, error message) and the write only applies when the marker, source config, and connection binding still match.

  • autoscan.Repository.RecordError returns whether the write committed; a stale snapshot returns false and leaves last_error and last_run_at unchanged (repository.go)
  • Adds a shared writeIfPollStateHolds conditional-write helper; AdvanceMarker now uses it too (repository.go)
  • Poll and webhook events append the note source changed during the poll; its error was not stored on the source when the write is skipped (service.go)
  • Risk: autoscan.Store.RecordError changed from (sourceID, message) to a PollFailure snapshot returning (bool, error); out-of-tree Store implementations must be updated (service.go)

Macroscope summarized 9ff6252.

…uring it

RecordError stamped last_error and last_run_at unconditionally. A poll
that was running when an admin repointed or reconfigured its source, and
that then failed, wrote the old server's error onto the source, and its
last_run_at stamp made the source wait out its interval before polling the
new upstream.

RecordError now takes the rows the poll read and writes only while they
still hold, using the same check AdvanceMarker uses: the source's marker,
connection binding and source_config, and the connection's upstream read
FOR SHARE. When they don't, the error stays on the poll's event only.

Closes Silo-Server#2202
…eview's cases

- The poll event says when a failed poll's error was kept off the source
  because an admin reset it during the poll, as a skipped marker advance
  already does.
- The shared write helper rejects a connection row that isn't the source's
  binding, for both AdvanceMarker and RecordError.
- docs/admin-api.md describes the failure path next to the success path.
- Tests: an API key rotation still records the error, each dropping edit
  is checked to have reset the source, a skipped write still finishes the
  event as an error holding the marker, and a resolve failure carries the
  connection row only when it was read. The AdvanceMarker stale-poll tests
  and the unknown-source test now run as DB contracts in CI.
@silo-kody

silo-kody Bot commented Oct 10, 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 ❌

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-10T07:50:14.735990Z 88cfac0 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Oct 10, 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: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 87757a31-d4b4-4382-9a8b-3faf2d3432d5







📥 Commits

Reviewing files that changed from the base of the PR and between bf63b3d and 88cfac0.








📒 Files selected for processing (6)
  • docs/admin-api.md
  • internal/autoscan/repository.go
  • internal/autoscan/repository_record_error_test.go
  • internal/autoscan/service.go
  • internal/autoscan/service_test.go
  • scripts/ci/db-contracts.txt







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









📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough

Walkthrough

Autoscan source error writes now use the poll’s source and optional connection snapshots. Stale polls do not overwrite source error or run-time fields. The poll event still records the failure and notes when the source write was skipped.

Changes

Autoscan poll failure handling

Layer / File(s) Summary
Conditional source writes
internal/autoscan/repository.go, internal/autoscan/repository_record_error_test.go, scripts/ci/db-contracts.txt
A shared writer checks the source marker, connection binding, and source_config against the poll snapshot. RecordError uses this check and returns whether it stored the error. Tests cover stale snapshots, missing sources, and mismatched connection rows.
Snapshot-aware poll failures
internal/autoscan/service.go, internal/autoscan/service_test.go, docs/admin-api.md
The service passes source and available connection snapshots with poll failures. When a stale snapshot prevents a source write, the poll event remains an error and includes a notice. The admin API documentation describes this behavior.

Priority: ➖ Normal

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

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant AutoscanService
  participant Provider
  participant Store
  participant PollEvent
  AutoscanService->>Provider: Poll using source and connection snapshots
  Provider-->>AutoscanService: Return poll failure
  AutoscanService->>Store: RecordError with PollFailure
  Store-->>AutoscanService: Return stored status
  AutoscanService->>PollEvent: Record failure and, if not stored, add notice
Loading

Suggested reviewers: quick104























Merge Risk: ⚪ Minimal · up to 9ff62

The change is mergeable after normal checks. A narrow early-failure case can still leave stale source error information after an upstream edit, but this change does not worsen that case.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 54.55% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 4 files. (2 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check Passed For directly linked issue #2202, RecordError now receives the poll snapshots and uses the shared state check for the source marker, connection binding, source_config, and available connection upst…
Out of Scope Changes check Passed The changed repository and service code implements #2202. The shared helper keeps success and failure snapshot checks consistent. The documentation, repository tests, service tests, and database-contr…
Title check Passed The title clearly and concisely describes the main change: preventing a failed autoscan poll from recording stale errors on a source reset during the poll.
Description check Passed The description directly explains the stale-error problem, implementation approach, validation, risks, and interaction with the related changes.

Full details: Docstring Coverage

Explanation

Docstring coverage is 54.55% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 4 files. (2 skipped: 2 unsupported.)


  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR







🧪 Generate unit tests (beta)
  • 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.

@Quick104 Quick104 added priority: P2 Limited scope, workaround exists, or polish impact: usability Core flow broken or severely blocked labels Oct 10, 2026 — with Cursor
@macroscopeapp

macroscopeapp Bot commented Oct 10, 2026

Copy link
Copy Markdown

The PR changes what admins see in the Autoscan UI:

  • internal/autoscan/repository.go, shown in the Sources panel: after a stale failed poll, the source keeps the status and last-run time left by the reset instead of showing the old poll error. The body says Evidence: publishing shortly but includes no captures or link; add before-and-after captures of the same source scenario, naming the surface and build/commit.
  • internal/autoscan/service.go, shown in the Activity panel: the stale poll event now says its error was not stored on the source. Add a before-and-after capture of the event in that scenario, naming the surface and build/commit.

Include desktop and mobile captures where the change is visible at phone width.

Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness.

Posted via Macroscope — Visible change evidence

…is green

Any change under scripts/ makes CI run the web jobs, and main fails the web
launch bundle budget until Silo-Server#2204 lands (Silo-Server#2203). This PR changes no web code,
so the pins wait for that. CI's Go DB pins job already ran all five
contracts on 88cfac0, whose code this commit leaves as it is, and they
passed.
@macroscopeapp

macroscopeapp Bot commented Oct 10, 2026

Copy link
Copy Markdown

internal/autoscan/service.go also changes the error text shown for a stale poll in the Autoscan Activity panel; the linked evidence is described as covering the source row and test runs, not this event. Please add before-and-after captures of the same poll-history event, including desktop and phone-width views where the panel is visible.

Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness.

Posted via Macroscope — Visible change evidence

@blurbery

Copy link
Copy Markdown
Contributor Author

The evidence page now has the captures both of these comments asked for, from a live run on a local test server: main at bf63b3d before, 9ff6252 after, with the Sonarr & Radarr Autoscan plugin. A poll hangs on the old server, the connection is repointed while it runs, and the poll then fails.

  • Activity panel, Polls, at phone and desktop width: the failed poll's error now ends with "source changed during the poll; its error was not stored on the source". The desktop poll table doesn't wrap long errors (on main too), so the note is cut off at that width. The phone captures and the trimmed event excerpt show the full text.
  • Sources panel, at phone and desktop width: on main the source shows "Last poll failed" with the old server's timeout. With this change it keeps "Last checked" from the earlier poll.

The Evidence section in the description says the same.

@Quick104
Quick104 merged commit 236b0bc into Silo-Server:main Oct 15, 2026
16 checks passed
Quick104 added a commit that referenced this pull request Oct 15, 2026
#2080 added a subtest that calls RecordError(ctx, id, message). #2205
changed RecordError to take a PollFailure without that subtest on its
base, so the package's tests stopped compiling on main.

Closes #2538

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@blurbery
blurbery deleted the fix/autoscan-stale-poll-error branch November 6, 2026 00:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

impact: usability Core flow broken or severely blocked priority: P2 Limited scope, workaround exists, or polish

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Autoscan: a poll that fails after an admin edit records the old server's error on the source

2 participants