Repository navigation
0.2.31: Report classified model failures as failed delivery outcomes - #53
Conversation
A hosted delivery whose turn ended because the model provider refused or
could not serve it now reports { state: "failed", code } from eventState,
with code model_quota_exceeded, model_auth_failed or model_unavailable.
The code is stored on the failed turn and on the delivery receipt, so it
survives a restart. Unclassified failures keep their existing outcome.
Bump to 0.2.31.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| @@ -1320,6 +1323,7 @@ export function createSessionManager( | |||
| retryCount, | |||
| retryAt: undefined, | |||
| state: latest.companion ? "paused" : "failed", | |||
There was a problem hiding this comment.
A Companion turn that fails with ModelTurnError stays stuck reporting "pending" instead of { state: "failed", code }.
First, latest.state === "submitted" retries 5 times even for a terminal ModelTurnError. Then line 1325 sets state: "paused" alongside failureCode for Companion turns. DeliveryWork.stateOf() (src/gateway/delivery-work.ts:181-188) only returns failure(...) when turn.state === "failed", so "paused" falls into pending = true and eventState() returns "pending" indefinitely (and keeps activity() non-zero). Also, the non-retryable fallback at lines 1347-1351 drops failureCode.
Fix: settle ModelTurnError immediately without retrying as state: "failed" with failureCode and executionFenced: true for both companion and non-companion turns (and handle turn.state === "paused" explicitly in stateOf() so it never reports "pending").
There was a problem hiding this comment.
Confirmed. A quota or key ModelTurnError now settles the turn at once as failed with its code, Companion turns included (no paused); only model_unavailable keeps the retry budget. Both failure paths store failureCode. The provider-failure test now asserts a single attempt and fails on the old code. Fixed in 0feea40
There was a problem hiding this comment.
Keeping this one as is. Settling model_unavailable on the first attempt is intentional (afec3f7): a retried turn re-enters completion(), which re-reads the same session and parent message and hits the same stored error. No new model call is made, and OpenCode has already done its own provider retries before it writes that error. Keeping the retry budget would only delay settlement by the backoff. Retrying for real would mean resubmitting the prompt, which is a separate decision.
| for (const id of sources) { | ||
| current[id]!.outstanding = Math.max(0, (current[id]!.outstanding ?? 0) - 1); | ||
| if (failed) current[id]!.failed = true; | ||
| if (code) current[id]!.failureCode = code; |
There was a problem hiding this comment.
Skipping current[id]!.failed = true when code is set breaks two paths in stateOf():
- If a tracked task rejects with
ModelTurnErrorwhile any associated turn is still non-terminal (such as a"paused"companion turn),stateOf()skips thereceipt.failedcheck at line 169 and returns"pending"instead of settling. receipt.failureCodeis never cleared, so the fallback at line 189 (return receipt.failureCode ? failure(receipt.failureCode) : "completed") overrides a receipt whose turns all settled normally (delivered/context_only/interrupted).
Fix: keep setting receipt.failed = true on any rejection alongside failureCode, return failure(code) only when a turn actually failed (or no turn ran and receipt.failed && receipt.failureCode), and drop the unconditional receipt.failureCode fallback when all turns completed.
There was a problem hiding this comment.
Partly addressed, partly not a defect.
- The paused case is gone: classified failures no longer leave a Companion turn
paused(0feea40).stateOfalso waits for a delivery's other turns before reporting a failed one. Settingreceipt.failedwould instead turn every classified failure intouncertainthrough the early check. receipt.failureCoderecords a tracked part that failed. The retry path schedules and returns without rejecting the tracked task, so a turn that later succeeds never left a code behind. A delivery whose failed part was untracked and whose other turn delivered is meant to report the failure, whichkeeps a classified failure pending until its other work settlescovers. No change.
There was a problem hiding this comment.
Partly agreed, fixed in 1a4deca.
Skipping failed/!routed when a code is set is intended: when a route rejects with a classified refusal, capture() records the code and the delivery should settle with it. The existing route-rejection test pins that, so letting receipt.failed win would break it.
What did hold is ?? receipt.failureCode in the failed-turn loop, which stamped a captured code onto an unclassified failed turn. The loop now uses only each turn's own code. The dispatch catch sets failed only when there is no code, and the line 168 condition is receipt.failed || (!receipt.routed && !receipt.failureCode). A new test covers a classified capture plus an unclassified failed turn, which settles as plain failed.
A quota or key refusal fails the turn on the first attempt, Companion turns included, and keeps its code on every failure path. A delivery reports its failure only after its other turns finish. Billing matches need an error or details wording. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- A delivery whose route rejected with a classified refusal settles with its code instead of staying uncertain. - A delivery reports a code only when every failed turn has one, in any order. - Settled classified failures expire under the receipt retention like completions. - Every classified refusal settles on the first attempt; a retry only re-read the same errored session. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…the plugin The smoke's cleanup escalates to SIGKILL when the host ignores SIGTERM, the first plugin load gets 180 seconds on a cold runner, and the job times out after 20 minutes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…turn - The synthetic record for a failed V2 run carries the run's last provider error, so 401, 402 and 429 refusals still classify on V2 hosts. - A delivery reports a failed turn's own code only; a captured refusal's code is no longer stamped onto an unclassified failed turn, and a routing failure without a code stays unknown. - Before recording a classified refusal, the terminal reply receipt is checked: an accepted reply settles the turn as delivered, and an unconfirmed one leaves it uncertain. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…oad from when the host listens A cold host installs its own plugin package before loading any plugin, which can take minutes on some runners and made the minimum-host smoke time out before this plugin ever ran. The smoke now installs that package for the running host version into the config and project directories first, waits for the host to listen, and gives the plugin load its own budget within an overall cap. This plugin still goes through the host's real loader. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… classify V2 compaction errors - A refused turn with a confirmed explicit WhatsApp send settles as answered, and one with an unconfirmed send stays uncertain; a rejected send keeps the failure code. - If the turn's lease moves to another owner while a found reply settles, the refusal no longer overwrites that owner's state, and other finish errors leave the outcome uncertain instead of recording the code. - A failed V2 compaction keeps its provider error, and the classifier reads V2 response bodies. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dimavrem22
left a comment
There was a problem hiding this comment.
Verified a1c680878: refusal branch preserves lease-loss ownership and handles explicit sent/unconfirmed WhatsApp replies, and V2 compaction errors + response.body are classified. All blockers resolved — LGTM!
Executive Summary
A hosted delivery whose turn ended because the model provider refused or could not serve it is now reported as
{ state: "failed", code }instead ofuncertain. The code is one ofmodel_quota_exceeded,model_auth_failedormodel_unavailable. Anything that cannot be classified keeps today's outcome. Version 0.2.31.Description
src/gateway/model-failure.ts(new):classifyModelFailure()maps a host assistant error (status code, error name, message and response body) to one of the three codes, andModelTurnErrorcarries the code.src/gateway/sessions.ts: when the finished run carries an assistant error, the turn fails with aModelTurnErrorif the error is classified. The failed turn storesfailureCodein the gateway journal.src/gateway/delivery-work.ts: a tracked task that rejects with aModelTurnErrorrecordsfailureCodeon the receipt instead of marking itfailed(which reads back asuncertain).status()returnsDeliveryOutcome: the existing state string, or{ state: "failed", code }for a failed turn or receipt that has a valid code. Pending work still reportspendinguntil it settles.eventStateanddispatchVerifiedreturnDeliveryOutcome.payment_required, so a billing refusal that carries only that code maps tomodel_quota_exceeded.failedwith its code on the first attempt, Companion turns included: a retry only re-read the same errored session. Both failure paths keep the code.uncertain.src/host/v2-history.ts: the synthetic failed-run record carries the run's real provider error, so a 401, 402 or 429 on a V2 host still classifies.failedonly when it has no code.response.body, so a 429 whoseinsufficient_quotaappears only there maps tomodel_quota_exceeded.scripts/smoke-loader.sh: before starting the host, the smoke preinstalls the host's own plugin package for the exact running host version, so a cold host has nothing to install at startup; our plugin still goes through the host's real loader. It waits for the host to listen, then gives the plugin its own 240 s load budget, with a 360 s overall cap.Reason
A turn that ended with a provider refusal (for example, an exhausted key) is over: nothing is still running, and it is never replayed. Reporting it as
uncertainmakes the host treat the agent as having unknown work, which can keep it awake indefinitely and hides the actual cause. A codedfailedoutcome lets the host settle the delivery and show why it failed.Decisions
model_not_found), and provider unavailability (429 rate limits, 5xx, overload, connection resets) are classified. Any other error, including errors that are not model errors, stays on its existing path.model_quota_exceeded.failedwithout a code is unchanged. This includes quarantined deliveries and failed hosted calls.Testing
npx vitest run: 102 files, 1768 passed, 1 skipped.npx biome check src tests scripts binandnpm run buildpass. Biome reports warnings only.tests/gateway/model-failure.test.ts: the classifier mapping, plus cases that stay unclassified.tests/gateway/delivery-work.test.ts:{ state: "failed", code }, including after a reopen.uncertain.pendingwhile other work is open.tests/gateway/sessions.test.ts: a failed run with a quota or auth error stores the code on the failed turn. An unclassified error stores no code.main. I checked this by reverting the source changes and rerunning them.{"error":{"code":"payment_required"}}message; it fails without the change. typecheck, lint and tests (1769 passed) pass.scripts/smoke-loader.shpasses locally on hosts 1.17.18 and 1.19.0.delivery-workcases: a running sibling turn, mixed coded and uncoded failures in both orders, a route rejected with a classified refusal, and expiry of 20,000 settled failures. The session test asserts a single attempt for a quota or key refusal. Each fails on the previous code. typecheck, lint and tests (1775 passed) pass.model_quota_exceeded) and a following run without an error (no inherited code); a captured refusal plus an unclassified failed turn (plainfailed); an accepted and an unconfirmed reply before a refusal. Each fails on the previous code. typecheck, lint and tests (102 files, 1780 passed, 1 skipped) pass.response.bodyclassification. Each fails on the previous code. Full suite: 102 files, 1784 passed, 1 skipped; typecheck and biome clean.scripts/smoke-loader.shfrom a cold state: host 1.17.18 loaded the plugin 1 s after listening (smoke 38 s); host 1.19.6 loaded it 1 s after listening (smoke 33 s).Related PRs
None.
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.