Skip to content

[T-040b] Worker heartbeat thread, registration and worker status #81

Closed

Description

@CodewithJha

Task T-040b · Milestone M3 — Oracles + runner + store · Size S · Priority P0 · Epic #3

Implements FR-RUN-002 · NFR-REL-001

Branch feat/t-040b-worker-heartbeat-thread-registration-and — one task = one branch = one PR (doc 32 §6)

Summary

Add WorkerProcess.heartbeat() on a background thread every worker.heartbeat_interval_s, worker registration (<prefix>:<pid>:<slot>, capabilities, version), status updates (IDLE/BUSY/DRAINING/OFFLINE/UNHEALTHY) and worker.updated events.

Context / motivation

Heartbeats let the reaper re-queue runs of crashed workers (no run lost — NFR-REL-001).

Scope

In scope

  • runner/heartbeat.py (thread with its own DB session; never shares sessions across threads).
  • Health endpoint via core.health.serve_health reporting heartbeat age.

Implementation guidance

  • Use threading.Event for stop; heartbeat failures are logged and retried with bounded backoff (runner.retry.*).
  • Standards: respect the layering contracts (doc 16 §2) and conventions in doc 34; no hard-coded tunables — thresholds/defaults come from typed settings (doc 27); no magic numbers (ruff PLR2004); public APIs typed (mypy strict) and documented.

Configuration keys

From the configuration reference (doc 27). Keys marked (new) must be added to the typed settings models and appear in the generated reference (T-003c).

  • worker.heartbeat_interval_s
  • worker.id_prefix
  • worker.health_port

Acceptance criteria

  • Fake-clock test: heartbeats at the configured interval; overridden interval honoured.
  • Worker row shows BUSY with current_run_id during a run.
  • Tests listed below added and green in CI; coverage of new code meets the gate in doc 18 §3.
  • Docs, config reference and CHANGELOG Unreleased updated where behaviour, keys or interfaces changed.
  • Definition of Done (doc 32 §3) satisfied.

Tests required

  • tests/unit/runner/test_heartbeat.py, integration with Postgres.

Dependencies

Blocked by: #80 (T-040a)

Blocks: #83 (T-040c)

Parallelization notes

Files / paths owned by this task — avoid editing other paths; shared files (pyproject.toml entry points, cli/main.py, api/routers/__init__.py, router.tsx, docker/compose.yaml, ci.yml) are append-only:

  • backend/src/roboprobe/runner/heartbeat.py
  • backend/src/roboprobe/runner/worker.py (hook)

Sequential after T-040a; parallel with T-041a/b.

Definition of Done

Per doc 32 §3 and AGENTS.md §5: lint, format, mypy strict and import-linter green; tests added and passing; docs updated; PR template completed with Closes #<this issue>; Conventional Commit messages referencing T-040b (doc 16 §6); commits authored only by the repository owner identity (AGENTS.md §4); CI green; reviewer checklist (doc 32 §5.1) satisfied.

References

Design docs: doc 05 §5.2 · doc 02 §3.3 · doc 21 §5.4 · doc 34 §8

Requirements: FR-RUN-002 · NFR-REL-001 (traceability: doc 28)

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:runnerQueue, workers, campaign orchestrationmilestone:M3M3 — Oracles + runner + storepriority:P0Critical path / blocks otherssize:S<= 1 daytaskChild task of a milestone epictype:featureNew functionality

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions