Skip to content

Forward-merge release/2.2 into develop - #368

Merged
GPUtester merged 1 commit into
developfrom
release/2.2
Jul 17, 2026
Merged

Forward-merge release/2.2 into develop#368
GPUtester merged 1 commit into
developfrom
release/2.2

Conversation

@rapids-bot

@rapids-bot rapids-bot Bot commented Jul 17, 2026

Copy link
Copy Markdown

Forward-merge triggered by push to release/2.2 that creates a PR to keep develop up-to-date. If this PR is unable to be immediately merged due to conflicts, it will remain open for the team to manually merge. See forward-merger docs for more info.

Closes #317.

## Summary

The ghost-job reaper is meant to mark abandoned `RUNNING` jobs as `FAILURE` when a Dask worker crashes or is OOM-killed without raising a Python exception. Its detection query, `_find_stale_jobs`, was driven from `job_events` with an **`INNER JOIN job_info`**, so a job that entered `RUNNING` but had **not persisted any events yet** produced zero rows and was invisible to the reaper.

That is exactly the failure the reaper's own docstring says it catches: the runner marks a job `RUNNING` before its first event is stored (and `BatchingEventStore` batches writes, widening the window). A worker crash/OOM in that pre-first-event window left the job stuck in `running` **forever** — status polling never reached a terminal state, and the job permanently counted against the active-job cap.

## Fix

Drive the query from `job_info LEFT JOIN job_events` and use `COALESCE(MAX(je.created_at), ji.updated_at)` as the staleness clock:

- Jobs **with** events keep the existing behavior (reaped when the last event is older than `GHOST_JOB_TIMEOUT_SECONDS`).
- Jobs with **no** events fall back to `job_info.updated_at` (set when the job entered `RUNNING`), so a never-emitted ghost past the timeout is now reaped.
- Added a guard for a missing `job_info` table (the query's new primary table).

I verified in a real SQLite DB that both timestamp columns compare correctly — `job_info.updated_at` (`YYYY-MM-DD HH:MM:SS.ffffff`) and `job_events.created_at` (`YYYY-MM-DD HH:MM:SS`) are both text and order correctly against SQLite `datetime()`; in Postgres both are `timestamptz` and compare natively.

## Tests

New `frontends/aiq_api/tests/test_ghost_reaper.py` runs against a real SQLite database so the SQL executes exactly as in production:

- `test_zero_event_running_job_past_timeout_is_reaped` — the regression: a zero-event RUNNING ghost is now reaped.
- `test_zero_event_running_job_within_timeout_is_not_reaped` — a freshly-started zero-event job is left alone.
- `test_running_job_with_stale_last_event_is_reaped` / `..._recent_event_is_not_reaped` — existing event-based behavior preserved.
- `test_non_running_job_is_never_reaped` — only RUNNING jobs are candidates.
- `test_missing_tables_returns_empty` — fresh deployment, nothing to reap.
- `test_mixed_fleet_reaps_only_ghosts` — realistic mix returns only the two genuine ghosts.

The three zero-event assertions **fail against the old INNER JOIN and pass with the fix**.

## Test plan

- [x] `pytest frontends/aiq_api/tests/test_ghost_reaper.py` — 7/7 pass
- [x] Full `frontends/aiq_api/tests/` suite — 311 passed, no regressions
- [x] `ruff check` + `ruff format --check` clean
- [x] Verified timestamp-format comparability in SQLite and reasoned through Postgres



## Summary by CodeRabbit

* **Bug Fixes**
  * Improved ghost-job cleanup so `RUNNING` jobs can be detected and reaped even when no job events have been persisted, using the latest heartbeat/lease timestamp fallback.
  * Hardened reaping to avoid race conditions by only transitioning jobs that are still `RUNNING`, and recording `GhostJobTimeout` when applicable.
  * Added a running-lease refresher to periodically extend leases for long-running workers.
  * Guarded `SUCCESS` persistence with a compare-and-set so it won’t overwrite terminal states.
* **Tests**
  * Expanded SQLite-backed coverage for stale detection, zero-event reaping, atomic transitions, lease refresh threading, missing-table behavior, and success compare-and-set semantics.

Authors:
  - Torkian (https://github.com/torkian)
  - Ajay Thorve (https://github.com/AjayThorve)

Approvers:
  - Ajay Thorve (https://github.com/AjayThorve)

URL: #318
@rapids-bot
rapids-bot Bot requested a review from a team July 17, 2026 21:06
@GPUtester
GPUtester merged commit 769dfd7 into develop Jul 17, 2026
5 checks passed
@rapids-bot

rapids-bot Bot commented Jul 17, 2026

Copy link
Copy Markdown
Author

SUCCESS - forward-merge complete.

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