Repository navigation
fix(kanban): trust fresh heartbeat over pid miss #50118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
GoliathInteractive
wants to merge
1
commit into
NousResearch:main
from
GoliathInteractive:goliath/kanban-liveness-guard
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -843,6 +843,86 @@ def test_detect_crashed_workers_grace_period_env_override( | |
| assert tid in kb.detect_crashed_workers(conn) | ||
|
|
||
|
|
||
| def test_detect_crashed_workers_trusts_fresh_current_run_heartbeat_on_pid_miss( | ||
| kanban_home, monkeypatch, | ||
| ): | ||
| """Fresh current-run heartbeat beats host-local PID mismatch. | ||
|
|
||
| This covers Docker / PID-namespace disagreement: the dispatcher may not see | ||
| the child PID, but the worker is still proving liveness through the shared | ||
| Kanban DB. Reclaiming in that state would spawn a duplicate live run. | ||
| """ | ||
| import hermes_cli.kanban_db as _kb | ||
|
|
||
| monkeypatch.setattr(_kb, "_pid_alive", lambda _pid: False) | ||
| monkeypatch.setenv("HERMES_KANBAN_CRASH_GRACE_SECONDS", "0") | ||
| monkeypatch.setenv("HERMES_KANBAN_CRASH_HEARTBEAT_FRESH_SECONDS", "120") | ||
|
|
||
| now = 3_000_000.0 | ||
| monkeypatch.setattr(_kb.time, "time", lambda: now) | ||
|
|
||
| with kb.connect() as conn: | ||
| host = _kb._claimer_id().split(":", 1)[0] | ||
| tid = kb.create_task(conn, title="pid namespace mismatch", assignee="a") | ||
| claimed = kb.claim_task(conn, tid, claimer=f"{host}:w") | ||
| assert claimed is not None and claimed.current_run_id is not None | ||
| kb._set_worker_pid(conn, tid, 424242) | ||
| assert kb.heartbeat_worker(conn, tid, expected_run_id=claimed.current_run_id) | ||
|
|
||
| # Past launch grace, PID probe says dead, but heartbeat is fresh. | ||
| monkeypatch.setattr(_kb.time, "time", lambda: now + 90) | ||
| assert kb.detect_crashed_workers(conn) == [] | ||
| task = kb.get_task(conn, tid) | ||
| assert task is not None | ||
| assert task.status == "running" | ||
| assert task.current_run_id == claimed.current_run_id | ||
|
|
||
| # Once the heartbeat is no longer fresh, PID death is authoritative. | ||
| monkeypatch.setattr(_kb.time, "time", lambda: now + 300) | ||
| assert kb.detect_crashed_workers(conn) == [tid] | ||
| task = kb.get_task(conn, tid) | ||
| assert task is not None | ||
| assert task.status == "ready" | ||
|
|
||
|
|
||
| def test_stale_run_completion_cannot_overwrite_new_current_run(kanban_home): | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Current main already covers this invariant in |
||
| """A duplicate/stale worker finishing late must not corrupt newer run state.""" | ||
| with kb.connect() as conn: | ||
| tid = kb.create_task(conn, title="stale duplicate completion", assignee="a") | ||
| first = kb.claim_task(conn, tid, claimer="host:first") | ||
| assert first is not None and first.current_run_id is not None | ||
| first_run = int(first.current_run_id) | ||
|
|
||
| with kb.write_txn(conn): | ||
| conn.execute( | ||
| "UPDATE tasks SET status='ready', claim_lock=NULL, " | ||
| "claim_expires=NULL, worker_pid=NULL, current_run_id=NULL " | ||
| "WHERE id=?", | ||
| (tid,), | ||
| ) | ||
| second = kb.claim_task(conn, tid, claimer="host:second") | ||
| assert second is not None and second.current_run_id is not None | ||
| second_run = int(second.current_run_id) | ||
| assert second_run != first_run | ||
|
|
||
| assert kb.complete_task( | ||
| conn, tid, result="late stale result", expected_run_id=first_run, | ||
| ) is False | ||
| task = kb.get_task(conn, tid) | ||
| assert task is not None | ||
| assert task.status == "running" | ||
| assert task.current_run_id == second_run | ||
| assert task.result is None | ||
|
|
||
| assert kb.complete_task( | ||
| conn, tid, result="current result", expected_run_id=second_run, | ||
| ) is True | ||
| task = kb.get_task(conn, tid) | ||
| assert task is not None | ||
| assert task.status == "done" | ||
| assert task.result == "current result" | ||
|
|
||
|
|
||
| def test_resolve_crash_grace_seconds_handles_bad_env(monkeypatch): | ||
| """Bad env values fall back to DEFAULT_CRASH_GRACE_SECONDS.""" | ||
| import hermes_cli.kanban_db as _kb | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This introduces a new non-secret, user-facing
HERMES_*behavioral setting. Repository policy requires such knobs to be exposed throughconfig.yaml; please keep the fixed bound or wire it throughkanban.*configuration instead.