Repository navigation
fix(portrait): reap running jobs whose lease expired - #12
Merged
Merged
Conversation
A worker restart mid-job left the row in 'running' forever. Nothing reclaimed it and due_hot_updates treated it as in-flight, so that speaker never got another incremental update (job 100 sat for 165h with 1,195 pending messages). Sweep lapsed leases to 'failed' before each claim, and only treat a running job as in-flight while its lease is valid. Co-authored-by: Cursor <cursoragent@cursor.com>
The SDK returns the newest N messages. When pending exceeded the 800 batch cap, the oldest slice was never fetched, the cursor jumped past it, and pending was debited by the full claim, so those messages were lost for good (job 102: 1,195 claimed, 800 read, ~395 skipped). Fetch the whole claimed backlog, process the oldest slice first, and only debit what was covered. Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
runningsince 2026-09-07 05:23 UTC: the scheduler restarted mid-job, and nothing ever reclaims a lapsed lease.due_hot_updatesexcluded portraits with anyqueued/runningjob, so that speaker never got a new incremental job; pending grew to 1,195 messages.reap_expired_jobs(running+locked_until < now→failed/lease_expired), call it before each claim, and make the in-flight check respect the lease.Job #100 was released manually on production before this change; the fix stops it recurring.
Test plan
pytest tests/unit/test_speaker_portrait_lease_reaper.py tests/unit/test_speaker_portrait_hot_update.py tests/unit/test_speaker_portrait.pyruff check plugins/speaker_portraitMade with Cursor