Kill hung runs early when a pinned pool model is delisted#621
Merged
Conversation
Extend the model-pool watchdog and fatal-failure classification with model-unavailable signatures (OpenRouter 'No endpoints found' / 'not a valid model ID', OpenAI-style model_not_found, ProviderModelNotFoundError) so a delisted pinned free model is killed within the poll interval and skipped instead of burning the candidate run budget. Sanitize ':' in per-candidate file names so ':free' candidates survive Windows and actions/upload-artifact. Review timing (timeouts, deadlines, context caps) is untouched. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR hardens the OpenCode model-pool runner so it can fail over quickly when a pinned OpenRouter free-tier model is delisted (model-unavailable errors), avoiding long hangs that consume the entire retry budget and delay org-wide PR governance workflows.
Changes:
- Extend fatal-provider detection to include model-unavailable signatures (e.g., “No endpoints found”, “not a valid model”,
model_not_found) and treat them as non-retryable for the current model candidate. - Classify these failures as
class=model-unavailablein sanitized diagnostics while keeping provider-controlled content suppressed. - Sanitize per-candidate filenames to replace
:as well as/, preventing Windows andactions/upload-artifactpath issues for:freemodel suffixes.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| scripts/ci/run_opencode_review_model_pool.sh | Detects model-unavailable error events to kill hung runs early, skips futile retries for delisted models, emits model-unavailable diagnostics, and sanitizes : in candidate-derived filenames. |
| tests/test_opencode_model_pool_runner.py | Adds a regression test ensuring an OpenRouter “No endpoints found … :free” error kills a hung run quickly, skips remaining attempts, and logs class=model-unavailable. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…dog-model-unavailable
Live run 30120972549 cycled the pool 102 times over ~3h re-sending the full review prompt to paid OpenRouter models and exhausted the org's entire credit; run 30122360773 kept cycling 700+ attempts into HTTP 402 until the retry budget elapsed. Three spend guards (timing untouched): - Credit exhaustion (HTTP 402 / 'Insufficient credits' / payment required) marks the candidate failed for the rest of the run via structured error events and stderr diagnostics, with a new class=credit-exhausted failure metadata label. - Control-rejected output now returns a distinct status and is capped per candidate (OPENCODE_INVALID_CONTROL_OUTPUT_CAP, default 3) so a model that cannot satisfy the control contract stops burning paid requests on identical rejections. - A per-run provider attempt ceiling (OPENCODE_POOL_MAX_TOTAL_ATTEMPTS, default 30 = ~3 cycles of the live 10-candidate pool) ends the pool as exhausted before unlimited cycles can accrue spend; when every candidate is marked failed the pool ends immediately instead of sleeping between empty cycles. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
| fi | ||
| [ -s "$opencode_json_file" ] || return 1 | ||
| grep -Eiq 'budget limit|insufficient_quota' "$opencode_json_file" | ||
| grep -Eiq 'budget limit|insufficient_quota|insufficient credits|payment required|model_not_found|model not found|ModelNotFoundError|not a valid model|no endpoints' "$opencode_json_file" |
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.
Follow-up hardening after #619/#622 pinned OpenRouter models in the OpenCode review pool. Two commits:
Commit 1 — kill hung runs when a pinned model is delisted
has_fatal_provider_error_event): also matches model-unavailable signatures (no endpoints,not a valid model,model_not_found,ModelNotFoundError) on structured"type":"error"events, so a delisted model is killed within the poll interval instead of burning the candidate run budget.is_fatal_provider_failure: same signatures → skip remaining attempts (class=model-unavailablein sanitized metadata).:(OpenRouter:freesuffix broke Windows filenames /actions/upload-artifact).Commit 2 — bound paid-provider spend (live incident response)
Run 30120972549 cycled the pool 102 times over ~3h, re-sending the full review prompt to both paid OpenRouter models on every cycle and exhausting the org's entire $20 credit; run 30122360773 then cycled 700+ attempts into HTTP 402 until the retry budget elapsed. Three spend guards, no timing constants touched:
Insufficient credits/payment required(structured error events + stderr diagnostics) marks that candidate failed for the rest of the run — no more per-cycle re-attempts against a provider with no credit. Newclass=credit-exhaustedfailure metadata.OPENCODE_INVALID_CONTROL_OUTPUT_CAP, default 3): control-rejected output now returns a distinct status; a candidate that repeatedly fails control validation is marked failed for the run instead of retrying forever on identical rejections.OPENCODE_POOL_MAX_TOTAL_ATTEMPTS, default 30 ≈ 3 cycles of the live 10-candidate pool): hard bound on total provider attempts per run. When every candidate is marked failed, the pool exits immediately instead of sleeping between empty cycles.All guards are env-disable-able (
=0). Timeouts, deadlines, and context caps are untouched.Tests
New:
test_delisted_openrouter_model_error_kills_hung_run_early,test_credit_exhausted_402_ends_pool_without_further_spend,test_invalid_control_output_cap_marks_candidate_failed,test_attempt_ceiling_bounds_provider_spend.tests/test_opencode_model_pool_runner.py: 21 passed;tests/test_opencode_agent_contract.py+ shell-syntax: 36 passed (1 deselected locally: pre-existing WSL-bash hang on Windows, unrelated);bash -nclean.