Skip to content

fix(autoscan): poll at once after a marker reset, and not for a respelled URL - #2080

Merged
Quick104 merged 4 commits into
Silo-Server:mainfrom
blurbery:fix/autoscan-reset-last-run
Oct 10, 2026
Merged

Quick104 merged 4 commits into
Silo-Server:mainfrom
blurbery:fix/autoscan-reset-last-run

Conversation

@blurbery

@blurbery blurbery commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

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. But last_run_at stays, 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 clears last_run_at along with the marker, so the source polls at the next cycle.

A second, smaller case: UpdateConnection treats a base URL that is only spelled differently (http://Sonarr:8989 saved as http://sonarr:8989/) as a new server and resets every bound source's marker, which skips history for no reason.

Approach

  • UpdateSource clears last_run_at in the same statement and under the same condition as the marker (connection or source_config changed). UpdateConnection clears 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.
  • The interval check in Service.poll already treats a source with no last_run_at as due, so the gap now ends at the next run of the poll task. If that first poll fails, RecordError stamps last_run_at again and the normal interval applies.
  • connectionUpstream.differsFrom compares 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. AdvanceMarker uses the same comparison, so a poll that overlaps such an edit still stores its marker.
  • docs/admin-api.md now says a reset also clears last_run_at, and which base URL spellings count as the same server.
  • TestUpdateSourceMarkerReset and TestUpdateConnectionMarkerReset are now database contracts, so Go DB pins runs 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: null for that source in the meantime. Webhook sources aren't affected.

Validation

  • The two reset tests now also check last_run_at: cleared with the marker on a connection switch, an unbind, a source_config change 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_at kept, 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.
  • CI on 7f7bfeb: every job passed, including Go DB pins, which now runs the two reset tests (run).
  • Review fix ec6329d: a path ending in an escaped slash (/a%2F) no longer compares equal to /a. The new cases in TestComparableBaseURLKeepsEscapedPaths fail on 7f7bfeb and pass after the fix. The branch also merges main to resolve a conflict in scripts/ci/db-contracts.txt.
  • Not run against a live Sonarr or Radarr. The only autoscan source on my server is disabled, so I have no production run to show.

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_at above, 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

  • A source whose marker was reset now polls at the next cycle even if its interval is longer. That's one extra poll, at most once per edit.
  • A poll that is running when the edit lands and then fails still stamps last_run_at through RecordError, 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.
  • Two URLs that differ only by a default port (http://host and http://host:80) still count as different servers, as before.

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

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.UpdateConnection now clears both marker and last_run_at for 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.
  • Adds comparableBaseURL in 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 %2F distinctions are preserved.
  • Repository.UpdateSource applies the same marker plus last_run_at reset for connection or source configuration changes.
  • Behavioral Change: sources with a last_run_at but no marker now get reset on connection upstream changes; previously equivalent URL spellings triggered resets and now do not.

Macroscope summarized ec6329d.

…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

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

@coderabbitai

coderabbitai Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You'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.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b97c9660-5ae1-4fb6-ab5e-ed5254c7bda8

📥 Commits

Reviewing files that changed from the base of the PR and between ade836a and ec6329d.


📒 Files selected for processing (5)
  • docs/admin-api.md
  • internal/autoscan/repository.go
  • internal/autoscan/repository_source_marker_test.go
  • internal/autoscan/repository_upstream_test.go
  • scripts/ci/db-contracts.txt

  • 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: polish Annoyance, cosmetic, or nice-to-have labels Oct 8, 2026 — with Cursor
@macroscopeapp

macroscopeapp Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

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:

  • Admin source list (internal/autoscan/repository.go, rendered in web/src/pages/admin/autoscan/sourceDisplay.ts): before-and-after screenshots of the same source row showing its status around a marker reset, at desktop and phone width, with the build or commit identified.
  • Earlier pickup of upstream-imported changes (internal/autoscan/repository.go enables the next poll): a short recording showing the reset through the next poll, plus before-and-after views of the same library/query if an item becomes visible sooner. Identify the build or commit.
  • Admin autoscan API (internal/autoscan/repository.go): before-and-after excerpts of the same response showing last_run_at before and after a reset, with the build or commit identified.

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

Posted via Macroscope — Visible change evidence

Comment thread internal/autoscan/repository.go Resolved
Comment thread internal/autoscan/repository.go Resolved
… 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

silo-kody Bot commented Oct 8, 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 ❌
⚠️ 1 Kody Rule(s) were not evaluated

These rules declare that they need repository context beyond this diff, and the review could not retrieve it, so they were not judged on this pull request:

  • Preserve optional store capabilities through production wrappers

@macroscopeapp

macroscopeapp Bot commented Oct 8, 2026

Copy link
Copy Markdown

The latest commits add two user-visible cases: a connection change now clears last_run_at for a source whose first poll failed, so it retries on the next cycle; and switching between an escaped-path URL and a path-separator URL now resets the upstream marker. The Evidence section still contains no captures or API excerpts, and its database-test reference does not show these outcomes. The PR explains that a running capture was unavailable, but these newly changed cases are not demonstrated.

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

Quick104 and others added 2 commits October 10, 2026 00:45
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 Quick104 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread internal/autoscan/repository.go Resolved
@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 ❌
⚠️ 1 Kody Rule(s) were not evaluated

These rules declare that they need repository context beyond this diff, and the review could not retrieve it, so they were not judged on this pull request:

  • Preserve optional store capabilities through production wrappers

@Quick104

Copy link
Copy Markdown
Contributor

Review summary

Reviewed 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 UpdateSource/UpdateConnection now also clears last_run_at, in the same statement and under the same condition. It costs at most one extra poll per edit that resets a marker, and it adds no setting or API surface.

Readiness: the approach is sound and every Go job passed on ec6329d, including Go DB pins, which ran TestUpdateSourceMarkerReset and TestUpdateConnectionMarkerReset. Two conditions remain:

Addressed in this review

  • A path ending in an escaped slash (http://host/a%2F) compared equal to http://host/a. Fixed in ec6329d with test cases that fail on 7f7bfeb.
  • docs/admin-api.md didn't say a reset clears last_run_at, or which base URL spellings count as the same server. Updated in ec6329d.
  • The branch conflicted with main in scripts/ci/db-contracts.txt. Resolved in 392bc34, keeping both sets of entries.
  • The UpdateSource doc comment was reflowed.

Remaining

  • [bug] Autoscan: a poll that fails after an admin edit records the old server's error on the source #2202: a poll that is running when the edit lands and then fails still stamps last_run_at (and the old server's error) through RecordError, which puts the interval wait back. The unconditional write predates this PR. It doesn't block merging, and the issue says its fix should follow this one.
  • Not changed: after a reset, last_error stays, so the row reads "Last poll failed" with no time until the next cycle. The PR body describes this.

Checks

  • Validated features: no passed case on the v1.0 board touches autoscan. Autoscan — Server #1231 C3 and Autoscan — Web admin #1232 C1 have not been run, so Validation tasks: none for passed cases. The PR body's note that it touches those two unrun cases is accurate.
  • User manual: unaffected. The siloserver.org autoscan page doesn't describe marker resets or the timing after an edit, and its troubleshooting advice ("whether its interval has passed") still holds.
  • Apple/Android: no change needed. These are admin autoscan routes used by the web admin.
  • jellycompat: not involved.
  • Evidence: the published evidence shows the database test output for the reset. ec6329d doesn't change that behavior, so it still applies.

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 RecordError overlap. Codex and one subagent found the escaped-slash collision. Codex also raised IPv6 zone IDs, which are case-sensitive and get lowercased with the host. I left that out: it needs two interfaces whose names differ only by case.

Review by Claude Code (claude-opus-5-5), run by @Quick104.

@blurbery

Copy link
Copy Markdown
Contributor Author

Heads-up: #2205, the fix for #2202 that Quick filed from this review, changes RecordError to take the rows the poll read (PollFailure). It merges with this branch without conflicts, but TestUpdateConnectionMarkerReset here calls RecordError with the old signature, so whichever of the two merges second needs that one call updated. I've checked that change on a local merge of both, and the autoscan tests pass. I'll make it on whichever branch is still open.

@Quick104
Quick104 merged commit 822f604 into Silo-Server:main Oct 10, 2026
20 of 22 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-reset-last-run 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: polish Annoyance, cosmetic, or nice-to-have priority: P2 Limited scope, workaround exists, or polish

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants