fix(celery): give reconcile_stuck_processing a soft time limit#3180
Merged
Conversation
reconcile_stuck_processing was the last periodic task still carrying a bare time_limit=300 with no soft_time_limit. Its inner loop makes unbounded per-row calls (a SQLite SELECT/UPDATE, a kombu .delay() publish to the Redis broker, and r.set/r.eval), so on a memory-pressured board a wedged Redis publish or SQLite lock can push the sweep past 300s. Tripping the hard limit SIGKILLs the pool child, which Sentry groups by the kill signature — the same ANTHIAS-A / ANTHIAS-9 / ANTHIAS-B trio the sibling pokes (asset probe, telemetry, display-power) already closed, leaving this task as the last contributor. Add a soft_time_limit (hard - 30s) and catch SoftTimeLimitExceeded inside the sweep so it aborts cleanly — the existing finally still releases the Redis lock and the next beat tick resumes. The hard limit stays as the backstop for a call stuck in C code where the soft signal can't land. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
There was a problem hiding this comment.
Pull request overview
This PR standardizes reconcile_stuck_processing with the project’s other periodic Celery tasks by adding a soft time limit (with headroom before the existing hard time limit) and handling SoftTimeLimitExceeded so a slow/blocked sweep aborts cleanly instead of being SIGKILLed.
Changes:
- Added
RECONCILE_STUCK_TIME_LIMIT_SandRECONCILE_STUCK_SOFT_TIME_LIMIT_Sconstants and applied them to thereconcile_stuck_processingtask decorator. - Caught
SoftTimeLimitExceededinsidereconcile_stuck_processingto log and exit cleanly while still releasing the Redis singleton lock infinally. - Added tests verifying the task’s soft/hard limits and that a soft-limit interruption still results in a successful tick and a released lock.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/anthias_server/celery_tasks.py |
Adds soft/hard time-limit constants, applies them to reconcile_stuck_processing, and cleanly handles SoftTimeLimitExceeded while preserving lock release behavior. |
tests/test_celery_tasks.py |
Adds TestReconcileTimeLimits covering the new limits and verifying soft-limit abort still releases the reconciler lock. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.



What
reconcile_stuck_processingwas the last periodic Celery task still carrying a baretime_limit=300with nosoft_time_limit. Its inner loop makes unbounded per-row calls (a SQLite SELECT/UPDATE, a kombu.delay()publish to the Redis broker, andr.set/r.eval), so on a memory-pressured board a wedged Redis publish or SQLite lock can push the sweep past 300s. Tripping the hard limit SIGKILLs the pool child.Why
Sentry groups that SIGKILL by the kill signature, so this one task kept the ANTHIAS-A / ANTHIAS-9 / ANTHIAS-B trio alive (251 + 232 + 292 events, almost all on pi3-64) after the earlier soft-limit work closed its three siblings (asset probe, telemetry POST, display-power CEC query). A deep audit of the still-open Sentry backlog found this was the only remaining unguarded contributor.
How
RECONCILE_STUCK_SOFT_TIME_LIMIT_S = RECONCILE_STUCK_TIME_LIMIT_S - 30and apply both limits to the task decorator, mirroring the three sibling tasks.SoftTimeLimitExceededinside the sweep so it aborts cleanly; the existingfinallystill releases the Redis singleton lock and the next beat tick resumes. The hard limit stays as the backstop for a call stuck in C code where the soft signal can't be delivered.Tests
New
TestReconcileTimeLimits: asserts the soft/hard headroom, and that a soft-limit mid-sweep ends as a clean success and releases the lock. Full non-integration suite green (1475 passed).🤖 Generated with Claude Code