Handle stuck pending runs with stale sweep - #6749
Open
suhaibmujahid wants to merge 3 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a reconciliation “stale sweep” path to ensure agent runs don’t remain stuck in pending when the Cloud Run completion event is lost or when old executions are garbage-collected (404 on GetExecution).
Changes:
- Introduces an internal maintenance endpoint (
/internal/maintenance/finalize-stale-runs) to periodically finalize old, unfinalized runs via the samefinalize_runlogic as the event-driven path. - Treats Cloud Run execution 404s as a terminal “gone” state and allows finalization based on
summary.jsonwhen the execution record has been deleted. - Adds targeted tests for execution-status mapping, stale-run sweeping behavior, and finalize behavior when executions are “gone” or missing.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| services/hackbot-api/app/jobs.py | Adds ExecutionStatus.gone and maps Cloud Run GetExecution 404 to gone. |
| services/hackbot-api/app/routers/runs.py | Avoids asserting on missing execution_name; adjusts terminal-status logic to allow gone with summary.json. |
| services/hackbot-api/app/routers/maintenance.py | New internal maintenance router implementing the stale-run sweep endpoint. |
| services/hackbot-api/app/routers/init.py | Exports the new maintenance router. |
| services/hackbot-api/app/main.py | Includes the maintenance router in the FastAPI app. |
| services/hackbot-api/tests/test_jobs_execution_status.py | New tests for 404→gone mapping and normal completion mapping. |
| services/hackbot-api/tests/test_finalize_stale_runs.py | New tests covering sweep behavior (finalized, dry-run, still-running, per-run failure isolation). |
| services/hackbot-api/tests/test_finalize_run.py | New tests for finalizing from summary.json when execution is gone, and for missing execution_name. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #6748