Repository navigation
fix(markers): stop retrying contribution conflicts - #559
Conversation
📝 WalkthroughWalkthroughThe change classifies provider conflicts as terminal contribution outcomes, deduplicates identical provider payloads across media files, migrates historical HTTP 409 errors, preserves transient retries, and counts conflicts as skipped work. ChangesMarker contribution conflict handling
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant PluginProvider
participant ContributionWorkflow
participant ContributionStore
participant ContributionTask
PluginProvider->>ContributionWorkflow: return SubmissionConflictError
ContributionWorkflow->>ContributionStore: record conflict with HTTP status
ContributionWorkflow-->>ContributionTask: return conflict outcome
ContributionTask->>ContributionTask: count conflict as skipped
Possibly related PRs
Suggested labels: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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/markers/contribution_repo.go`:
- Around line 64-79: Replace the check-then-submit flow around
ContributionStore.AlreadySubmitted with an atomic provider-target claim
performed before SubmitMarker, using a globally unique
provider/segmentKind/contentHash constraint or equivalent claim operation.
Ensure concurrent workers receive only one successful claim, and release or mark
the claim as error when a retryable provider failure occurs so later attempts
can proceed; preserve successful claims as deduplication records.
In `@migrations/sql/20260807140637_settle_marker_contribution_conflicts.sql`:
- Around line 1-29: Update the migration to run without a transaction by adding
the Goose NO TRANSACTION directive and removing both StatementBegin/StatementEnd
blocks. Change the index operations for
marker_contributions_provider_hash_terminal_idx to CREATE INDEX CONCURRENTLY and
DROP INDEX CONCURRENTLY, preserving the existing data update and index
definition.
🪄 Autofix
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: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 1335aa48-0f9a-435a-a73d-68d3201f5a7f
📒 Files selected for processing (9)
internal/markers/contribute.gointernal/markers/contribute_test.gointernal/markers/contribution_repo.gointernal/markers/plugin_provider.gointernal/markers/plugin_provider_test.gointernal/markers/types.gointernal/taskmanager/tasks/contribute_markers.gointernal/taskmanager/tasks/contribute_markers_test.gomigrations/sql/20260807140637_settle_marker_contribution_conflicts.sql
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
internal/markers/contribution_repo.go (1)
101-115: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick winAdd an integration test for the claim path. The current
isContributionClaimConflictcheck correctly matches the standalone partial index name inpgconn.PgError.ConstraintNamefor23505. Do not add message or table matching. Test a second matching media file against the migrated schema and assert(false, nil).🤖 Prompt for 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. In `@internal/markers/contribution_repo.go` around lines 101 - 115, Add an integration test covering the contribution claim path with the migrated schema: create or claim one media file, then attempt to claim a second matching media file and assert the result is (false, nil). Exercise the existing isContributionClaimConflict handling and verify the standalone partial index constraint name is matched without adding message or table-name checks.
🤖 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/markers/contribute.go`:
- Around line 208-225: Update the claim flow around store.Claim and its
implementation to recover stale submitting claims: allow takeover when an
existing row has status submitting and its updated_at exceeds a defined lease
interval, while retaining normal active-claim protection for fresh rows. Ensure
the takeover refreshes the claim metadata consistently and preserves existing
behavior for inactive or non-submitting rows.
---
Nitpick comments:
In `@internal/markers/contribution_repo.go`:
- Around line 101-115: Add an integration test covering the contribution claim
path with the migrated schema: create or claim one media file, then attempt to
claim a second matching media file and assert the result is (false, nil).
Exercise the existing isContributionClaimConflict handling and verify the
standalone partial index constraint name is matched without adding message or
table-name checks.
🪄 Autofix
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: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 1c7ace5f-eab6-4bd6-80d7-cd29cf3cf938
📒 Files selected for processing (4)
internal/markers/contribute.gointernal/markers/contribute_test.gointernal/markers/contribution_repo.gomigrations/sql/20260807140637_settle_marker_contribution_conflicts.sql
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a2ba490074
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
🧹 Nitpick comments (2)
internal/markers/contribute.go (1)
225-227: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider a reason that covers in-flight claims.
Claimreturnsfalsein two distinct cases: a terminal row exists, or another worker holds a fresh claim. The fixed reason"already submitted"describes only the first case. An operator reading task output cannot separate a duplicate from a concurrent in-flight submission.♻️ Suggested wording
- return ContributionOutcome{Provider: providerID, Segment: seg.kind, Status: OutcomeStatusSkipped, Reason: "already submitted"}, true + return ContributionOutcome{Provider: providerID, Segment: seg.kind, Status: OutcomeStatusSkipped, Reason: "already submitted or claimed"}, true🤖 Prompt for 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. In `@internal/markers/contribute.go` around lines 225 - 227, Update the !claimed branch in the contribution flow to use a reason that covers both an existing terminal submission and a concurrent in-flight claim, rather than the narrower "already submitted" wording. Preserve the existing skipped outcome, provider, segment, and return behavior.internal/markers/contribution_repo_test.go (1)
95-103: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueDerive the backdate from
contributionClaimLease.The helper hardcodes one hour. The lease is 15 minutes today, so the value works. If a later change raises the lease above one hour, these tests stop expiring claims and fail with a misleading message. Deriving the interval from the constant keeps the helper correct.
♻️ Suggested change
func expireContributionClaim(t *testing.T, fixture contributionStoreFixture, id string) { t.Helper() + expired := int64((contributionClaimLease + time.Minute) / time.Second) if _, err := fixture.pool.Exec(context.Background(), ` UPDATE marker_contributions - SET updated_at = now() - interval '1 hour' - WHERE id = $1`, id); err != nil { + SET updated_at = now() - ($2 * interval '1 second') + WHERE id = $1`, id, expired); err != nil { t.Fatalf("expire contribution claim: %v", err) } }🤖 Prompt for 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. In `@internal/markers/contribution_repo_test.go` around lines 95 - 103, Update expireContributionClaim to derive the SQL backdate interval from the contributionClaimLease constant instead of hardcoding one hour, while preserving the existing expired-claim behavior and error handling.
🤖 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.
Nitpick comments:
In `@internal/markers/contribute.go`:
- Around line 225-227: Update the !claimed branch in the contribution flow to
use a reason that covers both an existing terminal submission and a concurrent
in-flight claim, rather than the narrower "already submitted" wording. Preserve
the existing skipped outcome, provider, segment, and return behavior.
In `@internal/markers/contribution_repo_test.go`:
- Around line 95-103: Update expireContributionClaim to derive the SQL backdate
interval from the contributionClaimLease constant instead of hardcoding one
hour, while preserving the existing expired-claim behavior and error handling.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: c219135c-445f-410d-b2ba-f70983a14ad6
📒 Files selected for processing (5)
internal/markers/contribute.gointernal/markers/contribute_test.gointernal/markers/contribution_repo.gointernal/markers/contribution_repo_test.gomigrations/sql/20260807140637_settle_marker_contribution_conflicts.sql
🚧 Files skipped from review as they are similar to previous changes (1)
- internal/markers/contribute_test.go
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 554d4b3a8c
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| CREATE UNIQUE INDEX CONCURRENTLY IF NOT EXISTS marker_contributions_provider_hash_active_uidx | ||
| ON public.marker_contributions (provider, segment_kind, content_hash) | ||
| WHERE claim_active; |
There was a problem hiding this comment.
Preserve global claims when the owning file is deleted
Once this index makes the claim provider-payload scoped, storing its only row under one arbitrary media_file_id is no longer safe: migration 182 still defines that foreign key with ON DELETE CASCADE, and the scanner deletes missing media_files in DeleteMissingByFolder. If duplicate files A and B share a payload, A's terminal row suppresses B; deleting A then cascades away the global claim, so the next run submits B's identical payload again. Preserve the provider-level claim independently of file lifetime, or retain equivalent claim state when its originating file is removed.
AGENTS.md reference: AGENTS.md:L12-L14
Useful? React with 👍 / 👎.
Fixes #558.
Problem
The daily marker-contribution task treated provider HTTP 409 responses as generic errors. Because duplicate suppression intentionally excludes retryable
errorrows, every unchanged conflict was sent again on the next scheduled run. The existing lookup was also scoped to a local media-file ID, allowing identical provider payloads from duplicate local files to be submitted independently.Approach
AlreadyExistsresponses and the deployed legacysubmit HTTP 409error shape to a typed terminal conflict.status = 'conflict'and HTTP status 409, and count them as skipped work instead of failed work.Validation
Focused tests:
Repository checks:
Known baseline/environment failures outside this backend-only change:
go test ./...passes the changed packages but fails two untouched Jellycompat process-lock tests:TestBeginWebOperationRecoversDeadProcessLockandTestBeginWebOperationRejectsLiveProcessLock. An isolatedinternal/playbackrerun also passed after one flaky full-tree failure.make test-webreports 36 failures and 1,775 passes. Thirty-five failures are in untouched appearance/storage tests where Node warns that--localstorage-filehas no valid path andlocalStorage.clearis unavailable; the remaining existing failure issettingValuesRealtime.test.tsx.Adversarial review
AlreadyExistsand the exact legacy submission-409 shape; a regression test proves HTTP 500 remains retryable.errorwould recreate the request flood. The down migration removes the supporting index but intentionally retains already-settled conflict rows.Risk
The legacy compatibility mapping depends on the deployed plugin error text containing
submit HTTP 409. StructuredAlreadyExistsremains the preferred long-term plugin contract.AI Disclosure
Summary by CodeRabbit
Bug Fixes
Improvements