Skip to content

fix(task): build text-only multipart requests from JSON - #8198

Merged
Calcium-Ion merged 2 commits into
QuantumNous:mainfrom
SkyKoo:codex/fix-task-plugin-json-multipart
Nov 20, 2026
Merged

Calcium-Ion merged 2 commits into
QuantumNous:mainfrom
SkyKoo:codex/fix-task-plugin-json-multipart

Conversation

@SkyKoo

@SkyKoo SkyKoo commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Agent

  • Tool: Codex;本修复及回归测试由 AI 辅助编写。
  • Tool version: 当前会话未提供可核验的桌面端版本号。
  • Model (full id): 当前会话未提供完整模型 ID,不推测。
  • Host (CLI / IDE / GitHub coding agent / other): Codex desktop,macOS arm64。
  • Date (UTC): 2026-11-04。

Links

User request

  • Verbatim:

我更新了 new-api 的代码,合并了源头项目的提交,你再看下,如果还有问题那就直接改 new-api,改完之后可以提交个pr给new-api

  • Later constraints or corrections from the user (quote, or none): 无。

Out of scope — refuse

  • Matched: no。修复通用任务插件宿主,不修改任何供应商插件、第三方封装或透传路径。
  • If yes, what was told to the user (stop here; do not open a PR): 不适用。

Open gate — do not open unless all are satisfied

  • Out of scope (including pass-through-only forwarding): no。
  • Usage / configuration / integration (answered instead of opening): no。
  • Required issue facts present without invention: yes,bug(task): JSON input fails when a plugin builds text-only multipart #8197。
  • Verification is actual commands or steps and observed results, not only go build or tests passed: yes,见修复前后复现及输出字段验证。
  • Body is short and factual; no unfiltered AI-generated text: yes,已按代码和运行结果整理。
  • Open: yes。
  • If no, what was told to the user (stop here): 不适用。

Kind

  • Bug fix
  • New feature
  • Performance / refactor
  • Docs
  • Other:

Issue facts

  • Actual behavior: 合法 JSON 经插件生成纯文本 multipart 描述符后,宿主返回 multipart boundary not found;实际 API 显示 HTTP 500 / build_request_failed。
  • Impact: 请求无法进入上游发送阶段。
  • Frequency: 用户提供一次失败截图;上游 ba5f736 的确定性本地复现执行一次、失败一次。
  • Evidence that the problem is in new-api rather than the client or upstream: 不连接供应商,仅调用宿主适配器即可复现。
  • Applicable types and their fields (relay / billing / frontend / deployment; write "not applicable" otherwise): Relay;JSON 输入、multipart 输出、类型61任务插件、测试模型 m、非透传。计费/UI/部署不适用;详见 bug(task): JSON input fails when a plugin builds text-only multipart #8197。

Change

BuildRequestBody 仅在遇到 parts[].fileRef 时解析原始 multipart 表单,解析一次并保留清理逻辑。没有文件引用的描述符直接编码文本字段并生成输出 boundary。

Research

Duplicate / prior art

Docs and code

  • https://docs.newapi.ai/ : 已阅读首页和 /en/docs/guide/console/channel-management,配置覆盖不能解决输入格式被误判的问题。
  • https://deepwiki.com/QuantumNous/new-api : 本次访问返回 HTTP 429,未引用未读内容。
  • README / repo docs: README 的异步任务扩展;docs/plugin-api/v1.md 的 Request body、Request building;输入 body kind 与输出描述符独立。
  • Code paths and what they imply for this change: adaptor.go 原来无条件调用 common.ParseMultipartFormReusable;common/gin.go 从客户端 Content-Type 提取 boundary;relay_task.go 在发送前返回构造错误。

Alternatives considered

  • Option A: 要求所有客户端改用 multipart;无法修复已接受 JSON 的通用宿主路径。
  • Option B: 只在文件引用需要原始上传内容时解析表单。
  • Why this approach: 保留现有编码、文件引用校验及输出请求头行为,修改范围小。

Files

Path Why
relay/channel/task/jsplugin/adaptor.go 延后解析原始上传表单
relay/channel/task/jsplugin/adaptor_test.go 覆盖 JSON 转文本 multipart,并确认 JSON 不能伪造上传文件

Behavior

  • Before: 仅含文本 parts 的输出也要求输入存在 multipart boundary。
  • After: JSON 可生成可解析的 multipart;重复字段和空值保留;文件引用仍要求真实上传表单。
  • Explicit non-goals / leftover work: 不修改插件契约、模型参数、计价、认证或数据库;不部署生产,也不调用真实供应商。

Verification

  • 工具链:Go 1.26.10,显式使用匹配的 GOROOT;独立临时 GOCACHE。
  • go test ./relay/channel/task/jsplugin -run '^TestTaskAdaptorBuildsMultipartFromJSON$' -count=1 -v:只加测试、未修复时,text_fields 返回 multipart boundary not found。
  • go test ./relay/channel/task/jsplugin -run '^TestTaskAdaptor(BuildsMultipartFromJSON|BuildsMultipartFromOpaqueFileReference|DoesNotEmitInjectedMultipartDispositionHeaders)$' -count=1 -v:修复后通过;HTTP 解析器读取到 model、prompt、重复 tag 和空字段;缺少上传的文件引用仍拒绝;已有文件内容转发及 header 注入防护通过。
  • go test ./relay/channel/task/jsplugin ./pkg/jsplugin ./common -count=1:三个包分别 ok(2.305s、0.573s、1.310s)。首轮因沙箱禁止本地端口监听中断,允许本机模拟服务后通过。
  • go vet ./relay/channel/task/jsplugin ./pkg/jsplugin ./common:退出0,无诊断。
  • git diff --check:退出0;修改文件已 gofmt。
  • Manual steps and observed result: 核对上游 ba5f736 与用户合并后的 fork;涉及的两个文件相同。未发送真实生成请求。
  • UI: screenshot or recording (or why none): 后端修复,不涉及 UI;复现不依赖截图。
  • Tests added or updated, or why none: 在现有测试文件增加一个包含成功与拒绝场景的表驱动回归用例。
  • Databases / providers / platforms exercised: macOS arm64;新增用例使用内存 HTTP 请求解析器,相关包测试包含本地模拟服务。
  • Not verified: 全仓库 CI、Linux/Windows、真实供应商生成、生产扣费和部署。

Risks

  • Failure modes: 仍会拒绝无效文件引用;输出头部继续使用宿主生成的 boundary。
  • Billing / quota / auth impact: 未修改用量、价格、结算或认证;没有真实费用测试。
  • Follow-ups: 等待上游 CI 和维护者审查。

Scope check

  • Single focused change: yes。
  • Secrets included: no。
  • Out of scope (Coding Plan / reverse-engineered channel / third-party wrapper / Codex / pass-through-only forwarding): no。

Summary by CodeRabbit

  • Bug Fixes
    • Text-only multipart requests can now be built from JSON input, including repeated fields and empty values.
    • Multipart request headers now retain the generated boundary, helping ensure the body and content type match.
    • Requests that reference an uploaded file still require valid multipart data. If the data is missing or cannot be parsed, request building returns an error.

@coderabbitai

coderabbitai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The task adaptor stores the generated multipart content type on the submit descriptor. It delays parsing the client form until a multipart part references an uploaded file. Tests cover multipart output from JSON input and the missing-upload error.

Changes

Task plugin multipart request building

Layer / File(s) Summary
Multipart content type and conditional form parsing
relay/channel/task/jsplugin/adaptor.go, relay/channel/task/jsplugin/adaptor_test.go
The adaptor sets the upstream Content-Type from the generated multipart content type stored on the descriptor. It parses the client form only for file references. Tests verify repeated and empty text fields from JSON input, the generated boundary, and the missing-upload error with no body.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: calcium-ion

Merge Risk: Minimal · up to f2c07

This change lets JSON task input produce text-only multipart requests that previously failed with a boundary error. File references still require an uploaded file. No concrete merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "fix(task): build text-only multipart requests from JSON" matches the main change. The summary and objectives describe JSON task input producing a multipart request with text-only fields, wi…
Linked Issues check Passed Issue #8197 is closed and supplies historical context only. No active directly linked issue remains. Therefore no linked-issue coding requirement applies to this pull request. The reviewed head f2c072…
Out of Scope Changes check Passed The whole-PR files are relay/channel/task/jsplugin/adaptor.go and adaptor_test.go. The adaptor.go change delays ParseMultipartFormReusable until a part has fileRef. This directly supports the stated f…
Full details: Title check

Explanation

The title "fix(task): build text-only multipart requests from JSON" matches the main change. The summary and objectives describe JSON task input producing a multipart request with text-only fields, with the form parsed only when a fileRef is present. The title is concise, specific, and follows a conventional-commit style. The commit message mentions content type preservation across retries, which the title does not cover, but the title still describes the primary change.

Full details: Linked Issues check

Explanation

Issue #8197 is closed and supplies historical context only. No active directly linked issue remains. Therefore no linked-issue coding requirement applies to this pull request. The reviewed head f2c0721 changes adaptor.go after the previous review head 0d2dd90. This change does not alter the conclusion, because no active requirement exists.

Full details: Out of Scope Changes check

Explanation

The whole-PR files are relay/channel/task/jsplugin/adaptor.go and adaptor_test.go. The adaptor.go change delays ParseMultipartFormReusable until a part has fileRef. This directly supports the stated fix for JSON input that produces text-only multipart output. The head also moves the multipart boundary Content-Type from the client request to the submit descriptor, applied in BuildRequestHeader. This is a multipart-output change in the same adapter. It keeps the upstream Content-Type aligned with the generated body boundary. It is not a provider, billing, authentication, or database change. The PR description does not mention this header change explicitly, and the commit message refers to retry content-type preservation. This is a documentation gap, not a demonstrated unrelated change. The source diff could not be read directly because the changed blobs are missing from the checkout. The header behavior was confirmed from the readable head file contents only.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

A rabbit packs text fields with care,
A boundary waits to mark the pair.
Repeated tags and blanks flow through,
No form is parsed unless files are due.
The missing file brings an error clear,
The request is ready when parts appear.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 023cb9cd-a93e-4b28-ad39-e410c4919746
Commits

Reviewing files that changed from the base of the PR and between 0d2dd90 and f2c0721.

Files selected for processing: 2

  • relay/channel/task/jsplugin/adaptor.go
  • relay/channel/task/jsplugin/adaptor_test.go

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

@Calcium-Ion
Calcium-Ion merged commit 5cc1592 into QuantumNous:main Nov 20, 2026
3 checks passed
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.

bug(task): JSON input fails when a plugin builds text-only multipart

2 participants