Skip to content

fix(worker): reclaim expired processing task leases#2578

Closed
Cybercommanders wants to merge 1 commit into
vectorize-io:mainfrom
Cybercommanders:fix/worker-lease-reaper
Closed

fix(worker): reclaim expired processing task leases#2578
Cybercommanders wants to merge 1 commit into
vectorize-io:mainfrom
Cybercommanders:fix/worker-lease-reaper

Conversation

@Cybercommanders

Copy link
Copy Markdown

Summary

  • add HINDSIGHT_API_WORKER_TASK_LEASE_SECONDS with nonnegative validation
  • let workers periodically reset stale processing rows from dead workers back to pending
  • keep payload-less parent rows and locally active tasks untouched

Verification

  • uv run pytest tests/test_worker.py::TestWorkerLeaseReaper tests/test_worker_retry_knobs.py::test_worker_task_lease_seconds_env_var tests/test_worker_retry_knobs.py::test_worker_task_lease_seconds_rejects_negative -q
  • uv run ruff check hindsight_api/worker/poller.py hindsight_api/config.py hindsight_api/api/http.py hindsight_api/worker/main.py tests/test_worker.py tests/test_worker_retry_knobs.py
  • uv run ty check hindsight_api/worker/poller.py hindsight_api/config.py hindsight_api/api/http.py hindsight_api/worker/main.py tests/test_worker.py tests/test_worker_retry_knobs.py
  • ./scripts/hooks/lint.sh
  • git diff --check

Copilot AI review requested due to automatic review settings July 6, 2026 06:09

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 (default 3600, 0 disables) to config, docs, and env templates.
  • Implement periodic lease reaping in WorkerPoller to reset stale processing tasks back to pending while 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()
@Cybercommanders Cybercommanders force-pushed the fix/worker-lease-reaper branch from ae0c79c to 028b8d3 Compare July 7, 2026 00:24
@Cybercommanders

Copy link
Copy Markdown
Author

Closing at maintainer/requester direction.

@Cybercommanders Cybercommanders deleted the fix/worker-lease-reaper branch July 7, 2026 03:59
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.

2 participants