Repository navigation
fix: notify origins and close runs for work interrupted by a gateway restart #6066
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
Open
praisonai-triage-agent
wants to merge
4
commits into
main
Choose a base branch
from
claude/issue-6038-20261026
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+727
−148
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1a967c5
fix: notify origins and close runs for work interrupted by a gateway …
MervinPraison 8a65b5a
fix: route job recovery notices by delivery rules and reclaim kanban …
MervinPraison de8c650
fix: drop duplicate reclaim run-close and failure count after rebase …
MervinPraison be05884
fix: never reconcile jobs owned by this process and require every rec…
MervinPraison 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
113 changes: 113 additions & 0 deletions
113
src/praisonai-agents/tests/unit/background/test_reconcile_notifies_lost.py
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 |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| """Restart reconciliation announces LOST jobs (Issue #6038).""" | ||
|
|
||
| from praisonaiagents.background.job_manager import ( | ||
| BackgroundJobManager, JobInfo, JobStatus, | ||
| ) | ||
| from praisonaiagents.background.sqlite_store import SqliteBackgroundJobStore | ||
| from praisonaiagents.hooks import add_hook | ||
| from praisonaiagents.hooks.registry import remove_hook | ||
|
|
||
|
|
||
| def _store(tmp_path): | ||
| return SqliteBackgroundJobStore(str(tmp_path / "jobs.db")) | ||
|
|
||
|
|
||
| def _orphan(store, origin): | ||
| store.upsert(JobInfo(job_id="job-42", status=JobStatus.RUNNING, | ||
| started_at=1.0, origin=origin)) | ||
|
|
||
|
|
||
| ORIGIN = {"deliver": "telegram:12345", "task": "audit all 40 repos"} | ||
|
|
||
|
|
||
| def test_lost_job_fires_hook_once_and_is_redelivered(tmp_path): | ||
| store = _store(tmp_path) | ||
| _orphan(store, ORIGIN) | ||
| heard = [] | ||
| hook_id = add_hook("job_completed", lambda inp: heard.append(inp) or None) | ||
| try: | ||
| _check_lost_flow(store, heard) | ||
| finally: | ||
| remove_hook(hook_id) | ||
|
|
||
|
|
||
| def _check_lost_flow(store, heard): | ||
|
|
||
| # First pass (get_job_manager's lazy one): no redeliver. | ||
| BackgroundJobManager(store=store).reconcile_on_start() | ||
| info = store.get("job-42") | ||
| assert info.status == JobStatus.LOST | ||
| assert info.error and "restart" in info.error | ||
| assert not info.delivered | ||
| assert len(heard) == 1 | ||
| assert heard[0].job_id == "job-42" | ||
| assert heard[0].status == "lost" | ||
|
|
||
| # Boot pass with redeliver: exactly one notice, then delivered. | ||
| sent = [] | ||
| counts = BackgroundJobManager(store=store).reconcile_on_start(redeliver=sent.append) | ||
| assert [j.status for j in sent] == [JobStatus.LOST] | ||
| assert counts["redelivered"] == 1 | ||
| assert store.get("job-42").delivered | ||
| assert len(heard) == 1 # hook not re-fired | ||
|
|
||
| sent.clear() | ||
| BackgroundJobManager(store=store).reconcile_on_start(redeliver=sent.append) | ||
| assert sent == [] | ||
|
|
||
|
|
||
| def test_failed_redeliver_retries_next_boot(tmp_path): | ||
| store = _store(tmp_path) | ||
| _orphan(store, ORIGIN) | ||
|
|
||
| def boom(job): | ||
| raise RuntimeError("transport down") | ||
|
|
||
| BackgroundJobManager(store=store).reconcile_on_start(redeliver=boom) | ||
| assert not store.get("job-42").delivered | ||
| sent = [] | ||
| BackgroundJobManager(store=store).reconcile_on_start(redeliver=sent.append) | ||
| assert len(sent) == 1 | ||
|
|
||
|
|
||
| def test_lost_job_without_origin_is_not_redelivered(tmp_path): | ||
| store = _store(tmp_path) | ||
| _orphan(store, {}) | ||
| sent = [] | ||
| BackgroundJobManager(store=store).reconcile_on_start(redeliver=sent.append) | ||
| assert sent == [] | ||
| assert store.list_unreconciled() == [] | ||
|
|
||
|
|
||
| def test_repeat_call_skips_jobs_live_in_this_process(tmp_path): | ||
| import threading | ||
|
|
||
| store = _store(tmp_path) | ||
| mgr = BackgroundJobManager(store=store) | ||
| gate = threading.Event() | ||
| job_id = mgr.start_job(lambda: gate.wait(5)) | ||
| try: | ||
| mgr.reconcile_on_start(redeliver=lambda j: None) | ||
| assert mgr.get_job_info(job_id).status in (JobStatus.PENDING, JobStatus.RUNNING) | ||
| finally: | ||
| gate.set() | ||
| mgr.shutdown() | ||
|
|
||
|
|
||
| def test_job_completing_during_scan_is_not_marked_lost(tmp_path): | ||
| store = _store(tmp_path) | ||
| mgr = BackgroundJobManager(store=store) | ||
| job_id = mgr.start_job(lambda: "done", origin=ORIGIN) | ||
| mgr.get_result(job_id, timeout=5) | ||
| # Stale RUNNING snapshot, as if listed before the worker finished. | ||
| stale = JobInfo(job_id=job_id, status=JobStatus.RUNNING, origin=ORIGIN) | ||
| mgr._store = type("S", (), { | ||
| "list_unreconciled": lambda self: [stale], | ||
| "upsert": store.upsert, "get": store.get, | ||
| })() | ||
| sent = [] | ||
| counts = mgr.reconcile_on_start(redeliver=sent.append) | ||
| assert counts["lost"] == 0 and sent == [] | ||
| assert mgr.get_job_info(job_id).status == JobStatus.COMPLETED | ||
| assert store.get(job_id).status == JobStatus.COMPLETED | ||
| mgr.shutdown() |
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.