Skip to content

fix(issues): Recover interrupted unmerge reads and handoffs - #130381

Draft
yuvmen wants to merge 7 commits into
masterfrom
codex/unmerge-recovery
Draft

yuvmen wants to merge 7 commits into
masterfrom
codex/unmerge-recovery

Conversation

@yuvmen

@yuvmen yuvmen commented Nov 8, 2026 •

Copy link
Copy Markdown
Member

An unmerge can set its SQL fingerprint locks and then lose a worker while loading events. On redelivery, those locks are excluded, so the task loses track of its own fingerprints and can leave them stuck. Handing off the next batch also has a window where delivery may succeed without the current worker receiving confirmation.

This records fingerprint ownership in Redis and keeps one checkpoint per operation with its current batch and stage. A retry can resume reading events or resend a saved continuation. SQL locks are reused only when Redis confirms ownership; conflicting ownership or missing recovery state causes an error. Event payloads are loaded before resetting source aggregates, and batches interrupted after mutations begin require inspection rather than automatic replay.

Separately, this lowers the default batch size from 500 to 250 events for new unmerge chains. This is independent of the recovery mechanism, but loading fewer payloads at once and doing less work per task may also mitigate worker memory pressure and processing timeouts. Existing chains retain the batch size in their task arguments.

Deploy the API and all issue workers before enabling organizations:unmerge-recovery. Legacy lock acquisition also respects Redis ownership; reservation cleanup failures are logged without aborting processing.

This is a temporary mitigation. Existing orphaned locks and coordination between concurrent merge/unmerge operations remain outside its scope.

Persist operation ownership before SQL locking and checkpoint each batch
before mutations and continuation delivery. Redeliveries can resume reads
or saved handoffs while refusing to replay potentially partial mutations.

Gate new operations by organization, cap event batches at a configurable
50 events, and restrict Postgres and Snuba replacements to owned hashes.
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Nov 8, 2026
Treat legacy reservation release as best-effort so a Redis cleanup failure cannot abort processing after SQL locks commit. Cover continued processing and preservation of the original exception.

Set the recoverable unmerge batch cap to 250 events to halve the previous 500-event batch while limiting additional per-batch overhead.
Default new unmerge chains to 250 events per batch. Remove the newly introduced option and runtime cap so existing chains retain the batch size carried in their task arguments.
Track the current batch and stage in one operation checkpoint. Use SET NX for fingerprint ownership, resume reads and saved handoffs, and reject replay after mutations start.

Remove partial ownership, separate child checkpoints, explicit expiry arguments, and source-specific recovery handling. Reuse Redis release helpers and keep the conditional checkpoint write in a named Lua script.
Comment thread src/sentry/tasks/unmerge.py Resolved
Comment thread src/sentry/tasks/unmerge.py Resolved
Checkpoint SQL unlocks separately from Redis owner removal so cancellation can resume safely after a worker interruption. Retire rejected requests and release their ownership when fingerprints have moved or disappeared before validation.
Comment thread src/sentry/tasks/unmerge.py Resolved
Keep empty successive batches resumable until their lock cleanup completes. Preserve the mutation guard before initial truncation and nonempty batches, and reuse staged lock release for completion.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant