Skip to content

fix(portrait): reap running jobs whose lease expired - #12

Merged
zhx8702 merged 2 commits into
mainfrom
fix/portrait-lease-reaper
Sep 15, 2026
Merged

zhx8702 merged 2 commits into
mainfrom
fix/portrait-lease-reaper

Conversation

@zhx8702

@zhx8702 zhx8702 commented Sep 14, 2026

Copy link
Copy Markdown
Owner

Summary

  • Production had portrait job #100 (小海, incremental) stuck in running since 2026-09-07 05:23 UTC: the scheduler restarted mid-job, and nothing ever reclaims a lapsed lease.
  • due_hot_updates excluded portraits with any queued/running job, so that speaker never got a new incremental job; pending grew to 1,195 messages.
  • Add 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.py
  • ruff check plugins/speaker_portrait
  • After deploy, 回复风格 page shows a new incremental job for 小海 and 待处理 drops

Made with Cursor

zhx8702 and others added 2 commits September 14, 2026 11:38
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>
@zhx8702
zhx8702 merged commit 90ede88 into main Sep 15, 2026
1 check failed
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.

1 participant