fix(media): scale commit timeout with size; surface structured API errors - #4
Merged
Conversation
… errors
Large media commits run backend-side ffprobe that streams the whole object
from storage (~50s for 300MB), exceeding the fixed 30s request timeout and
aborting a succeeding commit with a spurious 408 (asset left in 'uploaded').
Add an optional per-request timeoutMs and pass a size-scaled window to commit.
Backend error envelopes wrap the message in { error: { message }, message },
so 'data.error ?? data.message' stringified the object as [object Object] for
every structured 4xx. Extract error.message / top-level message instead.
Also reuse the asset payload the backend echoes in a 409 (already-committed)
body instead of discarding objectKey.
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.
Summary
Found during a live-backend smoke test against staging (
api.ab-stg.agentbrain.sh, real Cloudflare R2). Two fixes + one robustness improvement, all verified live.1. Commit timeout too short for large media (HIGH)
putAbsoluteBytes(the PUT) already scales its abort window with size, but the commit POST used the fixed 30srequest()timeout.ffprobe; measured ~52s for a 300MB object → CLI aborted at 30s with a spurious408, leaving the asset stuck atstatus:"uploaded".timeoutMs;uploadMediapassescommitTimeoutMs(sizeBytes)(floor 60s, +1s/MB → 300s @300mb).2. API errors rendered
[object Object](MEDIUM){ success:false, error:{ id, code, status, message }, message }.data.error ?? data.messagestringified the object →[object Object]for every structured 4xx (413/422/…).extractApiErrorMessage()preferserror.message, then top-levelmessage, then string body, then statusText (preserves the existing string-errorcase).media: content stream probe mismatch: … ffprobe failed ….3. 409-as-success reuses echoed payload
data:{assetId,status,objectKey}; reuse it instead of discardingobjectKey.Tests
pnpm lintclean,pnpm buildOK.Follow-ups (not in this PR)
MAX_UPLOAD_BYTES=500MBignores per-kind backend caps (measured: raw_doc <100MB, image <300MB, video ~500MB) → client could pre-validate.application/octet-stream→raw_doc, which the backend rejects (invalid_mime_for_kind) → require--content-typefor unknown extensions.Smoke-test coverage (live)
me get✅ · smallmedia upload✅ (presign→PUT R2→commit ready) ·knowledge list✅ ·tag create✅ · 300MB upload PUT ✅ + commit path root-caused/fixed.