Repository navigation
fix(knowledge): retry ingest runs that failed only on transient provider errors - #5682
kojiwakayama wants to merge 8 commits into
Conversation
…ures The knowledge ingest task turned every failure into a terminal result, so a transient embedding failure such as a provider 503 ended the run on its first attempt even though the control plane would retry it. Report retryable when the failure is a provider error the provider classified as transient: in the canonical index mode and any thrown failure, from the error's cause chain; in the upload mode, only when every failed source failed on such an error while indexing. Policy refusals, 4xx rejections, version conflicts and missing inference authority stay terminal. Tests also pin that a remote upload ingest records the project upload path, not the runtime's download copy, as the generated document's resource.
…usal check Checking a neutral-route error for a Veryfront refusal cloned the response. Cloning moves the original onto a new body stream, so the body reference a sealed host response keeps is left locked. Provider error classification then could not read the body and fell back to status rules, so a hard quota error was treated as a retryable rate limit. Upstream errors now pass through on the live stream.
…ecisions A run whose sources failed on both a transient 503 and a permanent 401 stays terminal, and a gateway policy refusal sent as a 503 is never retried.
📦 Client bundle boundary
A server module in a client graph aborts hydration in the browser. New leaks fail CI; known leaks are tracked in |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@codex review |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e78e9b06c7
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
…instead of cloning The refusal check now tees the upstream body and reads a bounded prefix of one branch, then returns a response sealed with the host accessor binding, so its status, headers and body stay readable after project code replaces the Response.prototype getters. Cloning left Bun with an empty body on a response whose body getter had already been read.
…trinsics The retry decision no longer reads the live global Error or a replaceable Symbol.hasInstance, reads retryable as an own data property, and treats any failure while inspecting the error as terminal instead of replacing it.
|
@codex review |
|
Codex Review: Didn't find any major issues. Swish! Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
|
@codex review |
|
Codex Review: Didn't find any major issues. Hooray! Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3d75faab73
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| return await indexCanonical(indexInput); | ||
| } catch (error) { | ||
| if (isRetryableProviderFailure(error)) retryableIndexFailures++; | ||
| throw error; |
There was a problem hiding this comment.
Avoid the live Error constructor in ingest catches
When project code sets globalThis.Error to a non-callable value, or installs a throwing Symbol.hasInstance, while the embedding request is in flight, this wrapper counts the transient provider failure and rethrows it, but ingestResolvedSources then evaluates the live error instanceof Error at cli/commands/knowledge/command.ts:1162 and throws a TypeError; the outer errorMessage at src/server/handlers/request/project-run-execute.handler.ts:1127-1129 repeats the same unsafe check. Consequently, the handler never returns the newly intended retryable: true response. This missed downstream catch is fresh evidence beyond the corrected constructor checks, so these message-extraction paths should also use captured intrinsics.
AGENTS.md reference: AGENTS.md:L26-L28
Useful? React with 👍 / 👎.
|



Problem
A knowledge ingest run that failed on a transient provider error ended on its first attempt. When the embedding provider returned a 503 (overloaded), the run response never set
retryable, so the control plane did not start another attempt.Cause
executeKnowledgeIngestRuninsrc/server/handlers/request/project-run-execute.handler.tsreturned{ success: false, error }for every failure. Neither the outer catch nor the upload path setretryable. The embedding layers below (the runtime bridge and the embedding facade) do not wrap errors, so theProviderErrorfromprovider-http.tsreached the handler with its ownretryableclassification intact. The handler dropped it.While writing a handler test for a gateway policy refusal, I found a second problem on the vendor-neutral gateway routes.
normalizeNeutralGatewayRefusalinsrc/provider/veryfront-cloud/shared.tsclones an error response to check it for a Veryfront refusal. Cloning moves the original response onto a new body stream. The sealed host response keeps its ownbodyreference to the old stream, which the clone has locked. When the error was not a refusal, the original was passed through, and provider error classification failed with "ReadableStream is locked". It then fell back to status rules, which treat an OpenAI-formatinsufficient_quota429 as a retryable rate limit.Change
isRetryableProviderFailurewalks the error'scausechain (maximum depth 8, own data properties only). It returns the nearestProviderError's ownretryable === true. Any failure that is not a provider error stays terminal. Project code runs in the same realm, so the instance checks use the capturedErrorconstructor andFunction.prototype[Symbol.hasInstance], not the live globalErroror a replacedSymbol.hasInstance. If inspecting the error throws, the failure stays terminal and the original error is rethrown unchanged.index_existing_canonicalmode and any thrown failure, addsretryable: trueonly in that case.ProjectRunExecuteResponse.retryablenow covers knowledge ingest.normalizeNeutralGatewayRefusalno longer clones the response. It tees the upstream body with the capturedReadableStream.prototype.tee, reads a bounded prefix of one branch, and passes the other branch through on the truncated, unparseable and non-refusal exits. Refusals are rewritten as before, and the unused branch is cancelled. Every response it builds is sealed withbindHostResponseAccessors(now exported fromoutbound-fetch.ts), like the transport's own responses, so the classifier reads the upstream status, headers and body even after project code replaces theResponse.prototypegetters. Cloning also failed on Bun: after a clone, a body getter that had already been read returned an empty stream, so every upstream error body arrived empty.Retrying is safe. A retried upload run finds its already-published document through the ingest-source lookup and republishes it against the current version. Binary companions reconcile an existing identical asset. Canonical mode re-reads the same admitted version and checks its checksum.
Tests
src/server/handlers/request/project-run-execute.handler.test.ts:index_existing_canonical) addsprovider_overloaded(embeddings return 503) andprovider_policy_refused(a 503 carryingeu_inference_policy). Every case assertspayload.retryable:trueonly for the overload,undefinedfor authority, 401, policy refusal and 409.Errorwith another function, or definesSymbol.hasInstanceonErrorto return false. It assertsretryable: truefor every 503 case andundefinedotherwise. It also asserts that the generated document recordsresource: "uploads/topic.txt"and never the runtime's download directory.src/provider/veryfront-cloud/provider.test.ts:insufficient_quota429 throughcreateVeryfrontCloudFetchon the OpenAI neutral route and reads it throughresponse.body.insufficient_quota429 and a rewritten credit refusal, it replaces thebody,headers,ok,statusandstatusTextgetters onResponse.prototypeand asserts the response still reports the upstream values.Results, all run locally through
deno task test:filewith the named tests temporarily focused:retryableassertions failed with- undefined + true. Their "status 503" message assertions and the other five cases passed.shared.ts, the new neutral-route test failed withTypeError: ReadableStream is locked or disturbed.retryableIndexFailures === failedCountto> 0, the multi-source 401 case failed. I restored the rule before committing.shared.ts, the new prototype test failed: it read[200, true, "text/plain", "rate limited"]from the replaced getters instead of[429, false, "application/json", <upstream body>].isRetryableProviderFailure, both newErrorcases failed with- undefined + trueonretryable.provider.test.tsfailed in CI with an empty body. A Bun script that callscreateVeryfrontCloudFetchagainst the same stub responses returned empty bodies with the clone-basedshared.tsand the full upstream bodies with the tee-based one.provider.test.tspassed (4 tests, 75 steps), the fullproject-run-execute.handler.test.tspassed (19 tests, 602 steps), andoutbound-fetch.test.tspassed.deno fmt --check,deno lintanddeno checkpassed on the five changed files, and the anti-slop audit passed.Review round
Changes after review:
provider_policy_refusedcase. While writing it, I found that error bodies on the neutral route were unreadable after the refusal check, which is theshared.tsfix above. The case sends the refusal in the neutral envelope ({ error: { code, message } }), which the gateway normalizer rewrites before classification. On its own, this case does not fail against the unchanged handler, because that handler never setretryable. It guards against a later handler change that marks every 503 retryable.Not verified
Errorwith a value that is not callable, the retry check no longer throws, but the ingest still fails earlier, in existing code outside this change that usesinstanceof Error. This change does not address that.retryable: trueknowledge-ingest response as a second attempt.bindHostResponseAccessorsinoutbound-fetch.ts).