Repository navigation
fix(autoscan): poll at once after a marker reset, and not for a respelled URL - #2080
Conversation
…lled URL Clearing a source's marker on an edit made its next poll start from now, but last_run_at stayed, so the source still waited out its interval before that poll. Whatever the upstream imported in between was never reported. Clear last_run_at with the marker in UpdateSource and UpdateConnection, so the next cycle polls the source and the gap ends at the next run of the poll task. UpdateConnection also reset markers when the base URL was only spelled differently (a trailing slash, a different host case), which skipped history for no reason. Compare base URLs with the scheme and host lower-cased and trailing slashes dropped. Run the two reset tests as database contracts so CI covers them.
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:
|
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 22 minutes. View limit details
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. Comment |
|
The PR explains why a running capture was unavailable, but the database test output does not show the user-facing changes. Please add this evidence if available:
Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness. Posted via Macroscope — Visible change evidence |
… apart A connection URL change skipped bound sources that had no marker, such as one whose first poll failed, so after fixing the URL that source still waited out its interval. Clear last_run_at for those too. Clearing RawPath made an escaped slash (%2F) compare equal to a path separator. Trim the trailing slash from both forms instead.
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:
|
|
The latest commits add two user-visible cases: a connection change now clears Suggested fix: add before-and-after admin source-row captures and matching API excerpts for the failed-first-poll reset, plus a recording or same-query before-and-after showing pickup after an escaped-path upstream switch. Identify the build or commit, and include desktop and phone-width captures if the status change is visible at both widths. Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness. Posted via Macroscope — Visible change evidence |
Co-Authored-By: Claude Opus 5.5 <[email protected]>
comparableBaseURL trimmed Path and RawPath separately. For a path ending in %2F, Path lost its last slash but RawPath kept the escape, so the two no longer matched and String() fell back to the decoded path: http://host/a%2F compared equal to http://host/a. Trim the escaped path and derive the decoded one from it. Document in the admin API that a marker reset also clears last_run_at, and which base URL spellings count as the same server. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Quick104
left a comment
There was a problem hiding this comment.
Review of 7f7bfeb. The change is sound: clearing last_run_at in the same statement and under the same condition as the marker is the smallest correct way to get the poll at the next cycle, and the reset tests now run as DB contracts (they passed in Go DB pins on this head). There's one line-level finding (inline) and three more here.
Medium: the branch conflicts with main. Both sides appended to scripts/ci/db-contracts.txt. I'm resolving it by merging main and keeping both sets of entries, so there's no need to do anything yourself.
Low: docs/admin-api.md doesn't describe the new behavior. The repository rules ask for the relevant docs/*-api.md to change with the contract. The connection update section still says any change to an unlinked connection's base URL resets markers, and neither section says a reset also clears last_run_at, which the API then omits until the next poll. I'm updating both sections in a commit on this branch.
Not blocking, filed as #2202: a failed poll that overlaps the edit cancels the early poll. AdvanceMarker skips its write when the source or connection changed during the poll, but RecordError doesn't. It stamps last_run_at = now() and the old server's error unconditionally. If an admin repoints a source while a poll to the old server is running and that poll then fails (a likely case when the old server is down and the poll is stuck in a connect timeout), the stamp puts back the interval wait this PR removes. The unconditional write is already on main and the lines aren't in this diff, so I filed it separately and noted there that the fix should follow this PR.
One note that needs no change: after a reset, last_error stays, so a source whose old server was failing shows "Last poll failed" with no time until the next cycle. Your PR body already describes this.
Review by Claude Code (claude-opus-5-5), with a cross-provider pass by gpt-6.1-sol, run by @Quick104.
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:
|
Review summaryReviewed head: ec6329d (first reviewed at 7f7bfeb) Fit: 9/10 · Readiness: 8/10 — conditional Fit: this fixes a correctness gap in autoscan, a core 1.0 feature (#1230), at the boundary that owns it. The marker reset in Readiness: the approach is sound and every Go job passed on ec6329d, including
Addressed in this review
Remaining
Checks
Method: three focused reviewer passes and a validation-impact check (claude-opus-5-5 and Claude Sonnet 5.5 subagents), plus one cross-provider round (gpt-6.1-sol). All of them independently found the Review by Claude Code (claude-opus-5-5), run by @Quick104. |
|
Heads-up: #2205, the fix for #2202 that Quick filed from this review, changes |
#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
Related issue: #1230
Validation tasks: touches #1231 C3 and #1232 C1 (neither has a result yet)
When an admin edit resets an autoscan source's poll marker (#1935: a new connection or
source_config, or a connection pointed at another server), the source's next poll starts from now, which is the documented behaviour. Butlast_run_atstays, so the scheduler still waits out the source's interval from its last run before that first poll. Anything the upstream imports between the edit and that poll is never reported. With the default 10-minute cycle and a source set to poll hourly, that's up to an hour of imports that never get a targeted scan. This change clearslast_run_atalong with the marker, so the source polls at the next cycle.A second, smaller case:
UpdateConnectiontreats a base URL that is only spelled differently (http://Sonarr:8989saved ashttp://sonarr:8989/) as a new server and resets every bound source's marker, which skips history for no reason.Approach
UpdateSourceclearslast_run_atin the same statement and under the same condition as the marker (connection orsource_configchanged).UpdateConnectionclears it in the same statement as the bound sources' markers, including for a bound source that has run but has no marker yet (its first poll failed), so it retries the new URL at the next cycle. Other edits keep both.Service.pollalready treats a source with nolast_run_atas due, so the gap now ends at the next run of the poll task. If that first poll fails,RecordErrorstampslast_run_atagain and the normal interval applies.connectionUpstream.differsFromcompares base URLs with the scheme and host lower-cased, surrounding space trimmed and trailing slashes dropped. A different port, scheme or path still counts as a different server, and an escaped slash (%2F) still differs from a path separator.AdvanceMarkeruses the same comparison, so a poll that overlaps such an edit still stores its marker.docs/admin-api.mdnow says a reset also clearslast_run_at, and which base URL spellings count as the same server.TestUpdateSourceMarkerResetandTestUpdateConnectionMarkerResetare now database contracts, soGo DB pinsruns them. Today no CI job sets a database for them.What an admin sees: right after an edit that resets the marker, the source list shows "Not run yet" (or "Last poll failed" without a time, if the last poll failed) until the next cycle polls it, and the API returns
last_run_at: nullfor that source in the meantime. Webhook sources aren't affected.Validation
last_run_at: cleared with the marker on a connection switch, an unbind, asource_configchange and a connection URL change; kept on every edit that keeps the marker. Two new connection cases check that a trailing slash or a different host case keeps the markers, and every connection case includes a source whose first poll failed. Unit tests cover the URL comparison, including escaped paths. Against a local migrated PostgreSQL 18 database, all of these fail on ca186fe (last_run_atkept, markers reset for the respelled URLs) and pass on this branch.go test ./internal/autoscan/passes with and without a database.make lint-changed: clean.Go DB pins, which now runs the two reset tests (run)./a%2F) no longer compares equal to/a. The new cases inTestComparableBaseURLKeepsEscapedPathsfail on 7f7bfeb and pass after the fix. The branch also merges main to resolve a conflict inscripts/ci/db-contracts.txt.Benchmarks
Not applicable. One more column in two existing updates.
Evidence
Evidence: https://evidence.siloserver.org/r/silo-server/pr-2080/
The change a user can see is the status text and
last_run_atabove, between an edit and the next cycle. I don't have a capture from a running server; the evidence is the database test output.Risks
last_run_atthroughRecordError, which puts the interval wait back for that source. The unconditional write predates this change; it is tracked in [bug] Autoscan: a poll that fails after an admin edit records the old server's error on the source #2202.http://hostandhttp://host:80) still count as different servers, as before.Checklist
AI Disclosure
RecordErroroverlap, filed as [bug] Autoscan: a poll that fails after an admin edit records the old server's error on the source #2202.AI-assisted with Claude Opus. I directed the task and designed the work.
Note
Fix autoscan marker reset: poll once after reset, ignore respelled URLs
Repository.UpdateConnectionnow clears bothmarkerandlast_run_atfor bound sources when the resolved upstream changes, including sources with a timestamp but no marker. Scheduling-only edits (label, enabled, poll interval, path rewrites) keep both fields.comparableBaseURLin repository.go: trims whitespace, lowercases scheme and host, and drops trailing slashes before comparing base URLs. Port, scheme, and path differences still count as upstream changes, and escaped%2Fdistinctions are preserved.Repository.UpdateSourceapplies the same marker pluslast_run_atreset for connection or source configuration changes.last_run_atbut no marker now get reset on connection upstream changes; previously equivalent URL spellings triggered resets and now do not.Macroscope summarized ec6329d.