Skip to content

fix(metadata): record post-refresh stale IDs against the canonical item - #38

Merged
Quick104 merged 1 commit into
Silo-Server:mainfrom
fluxis:fix/stale-id-record-canonical-id
Jun 6, 2026
Merged

Quick104 merged 1 commit into
Silo-Server:mainfrom
fluxis:fix/stale-id-record-canonical-id

Conversation

@fluxis

@fluxis fluxis commented Jun 1, 2026 •

Copy link
Copy Markdown
Contributor

Problem

processInternal cleared and re-recorded stale provider IDs against req.ContentID after mergeAndPersist. But mergeAndPersist can canonicalize the item into an existing one (provider-ID dedup), deleting req.ContentID and returning a different result.ContentID. In that case the post-merge DeleteByContentID/Upsert targeted the now-deleted source: the upsert hit the stale_media_ids content_id foreign key and the still-404ing providers were never recorded on the surviving canonical item — so the same providers get re-attempted (and re-404) on every subsequent refresh.

Approach

Target the canonical ID (result.ContentID, falling back to req.ContentID) for the stale-ID follow-up via a small refreshFollowUpContentID helper — matching what the adjacent refresh-debt sync already uses (result.ContentID).

Risks / follow-up

Low. When no canonicalization occurs, result.ContentID == req.ContentID and behavior is unchanged. This is a pre-existing caller-side issue surfaced during review of the stale-ID FK-violation fix (#37); it addresses the root cause of that race.

Verification

go test ./internal/metadata/ and go vet ./internal/metadata/ pass. The id-selection helper is unit-tested (nil / empty / blank / canonicalized). Note: the end-to-end wiring in processInternal is not covered by a test — the repo has no DB integration harness for that path.

AI-use disclosure

Implemented with Claude Code (Opus 4.8), TDD, surfaced by a multi-agent review.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Fixed follow-up logic so stale external identifiers are written against the canonical content identifier after merge/persist, keeping stale ID records associated with the surviving consolidated item.
  • Tests

    • Added unit test coverage for follow-up content ID resolution, including fallbacks when result data is missing, empty, or whitespace-only.

@coderabbitai

coderabbitai Bot commented Jun 1, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 25489c29-0180-4660-9337-ec4c1180130a

📥 Commits

Reviewing files that changed from the base of the PR and between 141d57db6a01b13394ac4fc6a95350fbe87031b5 and 1a43683.

📒 Files selected for processing (2)
  • internal/metadata/refresh_followup_test.go
  • internal/metadata/service.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • internal/metadata/refresh_followup_test.go
  • internal/metadata/service.go

📝 Walkthrough

Walkthrough

This PR makes stale-ID follow-up persistence use the canonical content ID returned by merge/refresh: follow-up deletions and re-upserts are applied against the canonical ID when available, otherwise they fall back to the originally requested ID.

Changes

Stale ID Canonicalization

Layer / File(s) Summary
refreshFollowUpContentID helper and unit test
internal/metadata/service.go, internal/metadata/refresh_followup_test.go
New refreshFollowUpContentID returns result.ContentID when present/valid, otherwise the requested content ID. Unit test TestRefreshFollowUpContentID covers nil, empty, whitespace, and valid result cases.
Service integration: stale ID follow-up canonicalization
internal/metadata/service.go
processInternal now derives followUpContentID via refreshFollowUpContentID(req.ContentID, result) and performs stale provider-404 deletion/upsert against that ID when non-empty, instead of using the originally requested req.ContentID.

Sequence Diagram(s)

sequenceDiagram
  participant processInternal
  participant mergeAndPersist
  participant refreshFollowUpContentID
  participant MetadataStore
  processInternal->>mergeAndPersist: refresh/merge and persist
  mergeAndPersist->>processInternal: return ProcessResult (may include canonical ContentID)
  processInternal->>refreshFollowUpContentID: compute followUpContentID(req.ContentID, ProcessResult)
  refreshFollowUpContentID->>processInternal: return followUpContentID
  processInternal->>MetadataStore: delete/upsert stale provider-404 IDs using followUpContentID
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🐰 I nibble code in moonlit loops,
A helper born from tidy groups,
When items merge and IDs align,
Stale trails follow the canonical line. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(metadata): record post-refresh stale IDs against the canonical item' clearly and concisely describes the main change: ensuring stale IDs are recorded against the canonical content ID after refresh operations.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/metadata/service.go`:
- Around line 1219-1231: The stale-ID cleanup currently runs whenever
followUpContentID is set, which can drop existing stale rows when provider404s
wasn't populated (e.g., req.ContentID was empty and result.ContentID was
canonicalized); change the guard so you only delete existing stale IDs if you
also tracked provider404s availability: wrap the DeleteByContentID call and the
subsequent Upsert loop behind a condition that verifies provider404s was
populated (for example check that req.ContentID != "" or provider404s is
non-empty) before calling s.staleIDRepo.DeleteByContentID(ctx,
followUpContentID) and s.staleIDRepo.Upsert(...); keep using s.staleIDRepo,
followUpContentID, provider404s, req.ContentID and result.ContentID to locate
and implement the check.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 5f03c95b-df12-49be-9ca7-55fa7f708275

📥 Commits

Reviewing files that changed from the base of the PR and between 4c5691f and 141d57db6a01b13394ac4fc6a95350fbe87031b5.

📒 Files selected for processing (2)
  • internal/metadata/refresh_followup_test.go
  • internal/metadata/service.go

Comment thread internal/metadata/service.go Resolved
processInternal cleared and re-recorded stale provider IDs against
req.ContentID after mergeAndPersist. But mergeAndPersist can canonicalize
the item into an existing one (provider-ID dedup), deleting req.ContentID
and returning a different result.ContentID. In that case the post-merge
DeleteByContentID/Upsert targeted the now-deleted source: the upsert hit
the stale_media_ids content_id foreign key and the still-404ing providers
were never recorded on the surviving canonical item — so the same providers
get re-attempted (and re-404) on every subsequent refresh.

Target the canonical ID (result.ContentID, falling back to req.ContentID)
for the stale-ID follow-up via refreshFollowUpContentID, matching what the
adjacent refresh-debt sync already uses. The block stays guarded on
provider404s != nil (allocated only when req.ContentID was set) so a
content-id-less refresh that canonicalizes into an existing item does not
clear that item's stale rows without re-recording any. Unit-tested for the
nil/empty/canonicalized cases.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@fluxis
fluxis force-pushed the fix/stale-id-record-canonical-id branch from 141d57d to 1a43683 Compare June 1, 2026 14:47
@Quick104
Quick104 merged commit cfd0bd5 into Silo-Server:main Jun 6, 2026
5 checks passed
Quick104 pushed a commit to thezak48/silo-server that referenced this pull request Jun 7, 2026
…em (Silo-Server#38)

processInternal cleared and re-recorded stale provider IDs against
req.ContentID after mergeAndPersist. But mergeAndPersist can canonicalize
the item into an existing one (provider-ID dedup), deleting req.ContentID
and returning a different result.ContentID. In that case the post-merge
DeleteByContentID/Upsert targeted the now-deleted source: the upsert hit
the stale_media_ids content_id foreign key and the still-404ing providers
were never recorded on the surviving canonical item — so the same providers
get re-attempted (and re-404) on every subsequent refresh.

Target the canonical ID (result.ContentID, falling back to req.ContentID)
for the stale-ID follow-up via refreshFollowUpContentID, matching what the
adjacent refresh-debt sync already uses. The block stays guarded on
provider404s != nil (allocated only when req.ContentID was set) so a
content-id-less refresh that canonicalizes into an existing item does not
clear that item's stale rows without re-recording any. Unit-tested for the
nil/empty/canonicalized cases.

Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
@fluxis
fluxis deleted the fix/stale-id-record-canonical-id branch June 9, 2026 17:32
Quick104 pushed a commit that referenced this pull request Jun 11, 2026
…em (#38)

processInternal cleared and re-recorded stale provider IDs against
req.ContentID after mergeAndPersist. But mergeAndPersist can canonicalize
the item into an existing one (provider-ID dedup), deleting req.ContentID
and returning a different result.ContentID. In that case the post-merge
DeleteByContentID/Upsert targeted the now-deleted source: the upsert hit
the stale_media_ids content_id foreign key and the still-404ing providers
were never recorded on the surviving canonical item — so the same providers
get re-attempted (and re-404) on every subsequent refresh.

Target the canonical ID (result.ContentID, falling back to req.ContentID)
for the stale-ID follow-up via refreshFollowUpContentID, matching what the
adjacent refresh-debt sync already uses. The block stays guarded on
provider404s != nil (allocated only when req.ContentID was set) so a
content-id-less refresh that canonicalizes into an existing item does not
clear that item's stale rows without re-recording any. Unit-tested for the
nil/empty/canonicalized cases.

Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Quick104 pushed a commit that referenced this pull request Jun 17, 2026
…em (#38)

processInternal cleared and re-recorded stale provider IDs against
req.ContentID after mergeAndPersist. But mergeAndPersist can canonicalize
the item into an existing one (provider-ID dedup), deleting req.ContentID
and returning a different result.ContentID. In that case the post-merge
DeleteByContentID/Upsert targeted the now-deleted source: the upsert hit
the stale_media_ids content_id foreign key and the still-404ing providers
were never recorded on the surviving canonical item — so the same providers
get re-attempted (and re-404) on every subsequent refresh.

Target the canonical ID (result.ContentID, falling back to req.ContentID)
for the stale-ID follow-up via refreshFollowUpContentID, matching what the
adjacent refresh-debt sync already uses. The block stays guarded on
provider404s != nil (allocated only when req.ContentID was set) so a
content-id-less refresh that canonicalizes into an existing item does not
clear that item's stale rows without re-recording any. Unit-tested for the
nil/empty/canonicalized cases.

Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Quick104 pushed a commit that referenced this pull request Jun 17, 2026
…em (#38)

processInternal cleared and re-recorded stale provider IDs against
req.ContentID after mergeAndPersist. But mergeAndPersist can canonicalize
the item into an existing one (provider-ID dedup), deleting req.ContentID
and returning a different result.ContentID. In that case the post-merge
DeleteByContentID/Upsert targeted the now-deleted source: the upsert hit
the stale_media_ids content_id foreign key and the still-404ing providers
were never recorded on the surviving canonical item — so the same providers
get re-attempted (and re-404) on every subsequent refresh.

Target the canonical ID (result.ContentID, falling back to req.ContentID)
for the stale-ID follow-up via refreshFollowUpContentID, matching what the
adjacent refresh-debt sync already uses. The block stays guarded on
provider404s != nil (allocated only when req.ContentID was set) so a
content-id-less refresh that canonicalizes into an existing item does not
clear that item's stale rows without re-recording any. Unit-tested for the
nil/empty/canonicalized cases.

Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Quick104 added a commit that referenced this pull request Jun 26, 2026
Resolves 8 open Dependabot alerts in web/pnpm-lock.yaml (all dev-only
transitive dependencies) by pinning patched versions through the existing
pnpm.overrides mechanism:

- undici  7.24.7 -> 7.28.0  (via jsdom; alerts #43-#49, incl. 2 high:
  TLS cert validation bypass & cross-origin routing via SOCKS5 ProxyAgent)
- js-yaml 4.1.1  -> 4.2.0   (via @eslint/eslintrc; alert #39, quadratic DoS)
- @babel/core 7.29.0 -> 7.29.6 (via @vitejs/plugin-react; alert #38,
  arbitrary file read via sourceMappingURL)

No vulnerable versions remain in the lockfile. Web build and lint pass;
the only failing tests (ServerStorageStep ResizeObserver) are pre-existing
on main and unrelated to these bumps.

Co-authored-by: Claude Opus 4.8 <[email protected]>
Quick104 added a commit to RXWatcher/silo-server that referenced this pull request Jul 10, 2026
…lo-Server#225)

Resolves 8 open Dependabot alerts in web/pnpm-lock.yaml (all dev-only
transitive dependencies) by pinning patched versions through the existing
pnpm.overrides mechanism:

- undici  7.24.7 -> 7.28.0  (via jsdom; alerts Silo-Server#43-Silo-Server#49, incl. 2 high:
  TLS cert validation bypass & cross-origin routing via SOCKS5 ProxyAgent)
- js-yaml 4.1.1  -> 4.2.0   (via @eslint/eslintrc; alert Silo-Server#39, quadratic DoS)
- @babel/core 7.29.0 -> 7.29.6 (via @vitejs/plugin-react; alert Silo-Server#38,
  arbitrary file read via sourceMappingURL)

No vulnerable versions remain in the lockfile. Web build and lint pass;
the only failing tests (ServerStorageStep ResizeObserver) are pre-existing
on main and unrelated to these bumps.

Co-authored-by: Claude Opus 4.8 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants