Skip to content

fix: send multipart content_type before the file part on asset upload#13

Merged
wei-hai merged 2 commits into
mainfrom
fix/multipart-order-and-notfound
Jul 22, 2026
Merged

fix: send multipart content_type before the file part on asset upload#13
wei-hai merged 2 commits into
mainfrom
fix/multipart-order-and-notfound

Conversation

@wei-hai

@wei-hai wei-hai commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

Asset upload against public-api failed with:

422 invalid_body: content_type is required and must be sent before the file field

public-api streams the multipart upload and needs content_type (and the other metadata fields) to arrive before the file part so it can route the file stream without buffering. postAssets appended file first.

Fix: append the metadata fields (content_type, file_path, expected_hash, tags) first and file last. The stub server now rejects a file-before-content_type body (mirroring public-api), so the existing postAssets tests guard against a regression. vitest 112/112, tsc/oxfmt/hygiene clean.

🤖 Generated with Claude Code

public-api streams the multipart upload and requires content_type (and the
other metadata fields) to arrive before the file part, or it rejects with
422 "content_type is required and must be sent before the file field". The
SDK appended `file` first, so every asset upload against public-api failed.

Append the metadata fields (content_type, file_path, expected_hash, tags)
first and `file` last. The stub server now enforces the same ordering, so
the existing upload tests guard against a regression.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@wei-hai
wei-hai requested review from a team as code owners July 22, 2026 01:05
@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@wei-hai, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 57 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 078286f0-9194-44b0-9149-0fb73e7773c6

📥 Commits

Reviewing files that changed from the base of the PR and between f672d36 and 60a8cc1.

📒 Files selected for processing (2)
  • src/low/errors.test.ts
  • src/low/errors.ts

Warning

.coderabbit.yaml has a parsing error

The CodeRabbit configuration file in this repository has a parsing error and default settings were used instead. Please fix the error(s) in the configuration file. You can initialize chat with CodeRabbit to get help with the configuration file.

💥 Parsing errors (1)
Validation error: Too big: expected string to have <=250 characters at "tone_instructions"
⚙️ Configuration instructions
  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
📝 Walkthrough

Walkthrough

postAssets now sends multipart metadata before the file. The test stub validates this ordering, and a transport test confirms correctly ordered uploads succeed.

Changes

Asset upload multipart ordering

Layer / File(s) Summary
Multipart ordering and validation
src/low/transport.ts, test/support/stub-server.ts, src/low/transport.test.ts
postAssets appends metadata before file; the stub returns 422 invalid_body when content_type is missing or follows file; the test verifies a successful upload and one recorded request.
🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/multipart-order-and-notfound
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch fix/multipart-order-and-notfound

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

public-api returns entity-specific 404 error codes (job_not_found,
asset_not_found) even though the spec documents the generic not_found, so
a missing job/asset surfaced as a bare ApiError instead of the typed
NotFound the SDK promises. Map both to NotFound. (Server/spec reconciliation
of the code set is a separate follow-up.)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@test/support/stub-server.ts`:
- Around line 390-393: Update the multipart ordering validation around the body
field searches to inspect only parsed multipart Content-Disposition field names,
not arbitrary body content. Extract the ordered headers with a multipart parser
or equivalent and enforce that the file field precedes content_type only when
those actual fields are present, preserving the existing malformed-request
rejection behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 16107771-8b44-4141-91da-185565a94985

📥 Commits

Reviewing files that changed from the base of the PR and between bdb7bbb and f672d36.

📒 Files selected for processing (3)
  • src/low/transport.test.ts
  • src/low/transport.ts
  • test/support/stub-server.ts

Comment thread test/support/stub-server.ts
@wei-hai
wei-hai merged commit 5425e93 into main Jul 22, 2026
7 checks passed
@wei-hai
wei-hai deleted the fix/multipart-order-and-notfound branch July 22, 2026 01:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant