Skip to content

refactor(lease): centralized LeaseManager decouples heartbeats from poll loop#400

Merged
v1r3n merged 1 commit intomainfrom
lease-manager-centralized
Apr 20, 2026
Merged

refactor(lease): centralized LeaseManager decouples heartbeats from poll loop#400
v1r3n merged 1 commit intomainfrom
lease-manager-centralized

Conversation

@v1r3n
Copy link
Copy Markdown
Contributor

@v1r3n v1r3n commented Apr 20, 2026

Summary

  • Replaces inline heartbeat logic in both TaskRunner and AsyncTaskRunner with a process-wide LeaseManager singleton
  • Background daemon thread + ThreadPoolExecutor(4) — heartbeat API calls and retries never block task polling
  • Fork-safe (PID-based singleton detection), thread-safe, lazy-start on first track() call
  • task_handler.py stays clean — no LeaseManager knowledge needed

What changed

File Change
lease_tracker.py Added LeaseManager class (singleton, background thread, thread pool, retry logic)
task_runner.py Removed inline _send_due_heartbeats/_send_heartbeat, delegates to LeaseManager.track/untrack
async_task_runner.py Same delegation; creates a sync TaskResourceApi for LeaseManager (heartbeats run in thread pool, not event loop)
test_lease_manager.py 21 unit tests: track/untrack, heartbeat dispatch, retries, non-blocking, singleton/fork, thread safety

Test plan

  • All 690 unit tests pass (pytest tests/unit/ -x -q)
  • E2E verified: heartbeat-enabled task COMPLETED, no-heartbeat task TIMED_OUT
  • Adversarial code review (/dg) completed — accepted findings addressed

🤖 Generated with Claude Code

…oll loop

Replace inline heartbeat logic in TaskRunner with a process-wide
LeaseManager singleton. A background daemon thread checks for due
heartbeats at ~1s intervals and dispatches them to a ThreadPoolExecutor(4),
so heartbeat API calls and retries never block task polling.

Key changes:
- LeaseManager: singleton with background thread + thread pool, fork-safe
  via PID check, lazy start on first track() call
- TaskRunner: delegates to LeaseManager.track/untrack instead of inline
  _send_due_heartbeats/_send_heartbeat methods
- task_handler.py: clean — no LeaseManager knowledge needed
- 21 unit tests covering track/untrack, heartbeat dispatch, retries,
  non-blocking behavior, singleton/fork safety, thread safety

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 20, 2026

Codecov Report

❌ Patch coverage is 94.82759% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/conductor/client/automator/task_runner.py 75.00% 4 Missing ⚠️
src/conductor/client/automator/lease_tracker.py 98.00% 2 Missing ⚠️
Files with missing lines Coverage Δ
src/conductor/client/automator/lease_tracker.py 98.18% <98.00%> (ø)
src/conductor/client/automator/task_runner.py 78.03% <75.00%> (-1.69%) ⬇️

... and 56 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@v1r3n v1r3n merged commit 1da5a3f into main Apr 20, 2026
2 checks passed
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