fix(worker): reclaim expired processing task leases#2578
Closed
Cybercommanders wants to merge 1 commit into
Closed
fix(worker): reclaim expired processing task leases#2578Cybercommanders wants to merge 1 commit into
Cybercommanders wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces a worker “lease reaper” mechanism to reclaim async_operations rows stuck in processing when their heartbeat (updated_at) is stale, controlled via a new HINDSIGHT_API_WORKER_TASK_LEASE_SECONDS config/env var (with nonnegative validation). This helps recover work from dead/unreachable workers without incrementing retry counts.
Changes:
- Add
HINDSIGHT_API_WORKER_TASK_LEASE_SECONDS(default3600,0disables) to config, docs, and env templates. - Implement periodic lease reaping in
WorkerPollerto reset staleprocessingtasks back topendingwhile excluding payload-less parent rows and locally active tasks. - Add regression tests covering lease reaping and config parsing/validation.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| hindsight-api-slim/hindsight_api/worker/poller.py | Adds lease reaper implementation and integrates it into the poll loop. |
| hindsight-api-slim/hindsight_api/config.py | Introduces the new env var constant/default, config field, and validation. |
| hindsight-api-slim/hindsight_api/worker/main.py | Threads the new config value into worker CLI poller construction. |
| hindsight-api-slim/hindsight_api/api/http.py | Threads the new config value into in-process worker poller construction. |
| hindsight-api-slim/tests/test_worker.py | Adds tests ensuring stale leases are reclaimed and “disabled when zero” behavior. |
| hindsight-api-slim/tests/test_worker_retry_knobs.py | Adds tests for env parsing and negative-value rejection for the new knob. |
| hindsight-docs/docs/developer/configuration.md | Documents the new configuration variable and semantics. |
| .env.example | Adds the new env var to the root env template. |
| hindsight-embed/hindsight_embed/env.example | Mirrors the root env template update for embed mode. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
984
to
+985
| await self.recover_own_tasks() | ||
| await self.reap_expired_leases() |
Comment on lines
+847
to
+848
| cutoff = datetime.now(UTC) - timedelta(seconds=self._task_lease_seconds) | ||
| schemas = await self._get_schemas() |
ae0c79c to
028b8d3
Compare
Author
|
Closing at maintainer/requester direction. |
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
Verification