Repository navigation
fix(autoscan): don't record a failed poll's error on a source reset during it - #2205
Conversation
…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 — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to 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 |
|
|
The PR changes what admins see in the Autoscan UI:
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.
|
Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness. Posted via Macroscope — Visible change evidence |
|
The evidence page now has the captures both of these comments asked for, from a live run on a local test server:
The Evidence section in the description says the same. |
#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]>
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_atis 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:
AdvanceMarkerskips its write when the source or its connection changed while the poll ran. This change gives a failed poll the same check.Approach
RecordErrornow takes the rows the poll read (PollFailure) and writeslast_errorandlast_run_atonly while they still hold: the source's marker, connection binding andsource_config, and the connection's upstream, readFOR SHARE. That's the checkAdvanceMarkermakes, and both now go through one helper so they can't drift apart. When the check fails, the error stays on the poll's own event in poll history, as [bug] Autoscan: a poll that fails after an admin edit records the old server's error on the source #2202 asks.failPolland the transient-resolve branch ofconsumeSourceChangespass those rows. If the poll failed before it could read its connection row, only the source's own columns are compared (see Risks).TestUpdateConnectionMarkerResetcallsRecordErrorwith the old signature, so whichever of the two merges second needs that one call moved toPollFailure. With that change, the autoscan package passes on the merge.Validation
TestRecordErrorSkipsStalePoll(9 cases) andTestRecordErrorRejectsAnotherConnectionsRow. Onmain, with the test adapted to main'sRecordErrorsignature, the 5 cases where an edit changes the upstream fail, and so does the another-connection check. All of them pass on this branch.go test -race ./internal/autoscan/with the test database passes, including the existingAdvanceMarkerand marker-reset tests after the shared-helper change.RecordErrorcall 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-linton the changed lines ofinternal/autoscan,go vetandgofmt: clean.TestRecordErrorSkipsStalePoll,TestRecordErrorUnknownSource,TestRecordErrorRejectsAnotherConnectionsRow, and, because this PR rewritesAdvanceMarker's body,TestAdvanceMarkerSkipsStalePollandTestAdvanceMarkerRequiresBoundConnectionRow) as DB contracts: every Go job passed, andGo DB pinsran all five against Postgres (run).scripts/makes CI run the web jobs, andmainfails 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 oncemain's web build is green.web/orscripts/changes (run).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,
mainat 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.mainthe 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 (onmaintoo), so the note is cut off there; the phone captures and the trimmed event excerpt on the page show the full text.mainthe 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
last_erroron a reset. A source repointed away from a dead server still shows the error its earlier polls stored until its next poll; with fix(autoscan): poll at once after a marker reset, and not for a respelled URL #2080 that's the next cycle.AdvanceMarker's error text for database faults now starts withadvance autoscan marker:, which can show on a poll event.errors.Is(err, ErrNotFound)still holds, and nothing matches on the old text.Checklist
AI Disclosure
AdvanceMarker's behaviour after the refactor, lock order againstUpdateSourceandUpdateConnectiononmainand 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: thedocs/admin-api.mdsentence, CI DB-contract coverage for the rewrittenAdvanceMarker, 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
RecordErrorto skip stale sources after a reset during a pollA 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
PollFailuresnapshot (source row, optional connection row, error message) and the write only applies when the marker, source config, and connection binding still match.autoscan.Repository.RecordErrorreturns whether the write committed; a stale snapshot returns false and leaveslast_errorandlast_run_atunchanged (repository.go)writeIfPollStateHoldsconditional-write helper;AdvanceMarkernow uses it too (repository.go)source changed during the poll; its error was not stored on the sourcewhen the write is skipped (service.go)autoscan.Store.RecordErrorchanged from(sourceID, message)to aPollFailuresnapshot returning(bool, error); out-of-treeStoreimplementations must be updated (service.go)Macroscope summarized 9ff6252.