Skip to content

fix(relaykit): emit summary on reasoning items announced without one - #7833

Merged
seefs001 merged 1 commit into
QuantumNous:mainfrom
rjchien728:fix/relaykit-reasoning-summary
Oct 16, 2026
Merged

seefs001 merged 1 commit into
QuantumNous:mainfrom
rjchien728:fix/relaykit-reasoning-summary

Conversation

@rjchien728

@rjchien728 rjchien728 commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Agent

  • Tool: Claude Code
  • Tool version: 2.1.280
  • Model (full id): claude-opus-5-5
  • Host (CLI / IDE / GitHub coding agent / other): VS Code extension (devcontainer)
  • Date (UTC): 2026-10-15
  • AI disclosure: the code and the body of this PR were generated / assisted by Claude Code. The submitter's git identity Roger Chien <[email protected]> is not among the historical core developers in git log (no commits by Roger or rjchien728 before 45fbb149), so this is stated here per AGENTS.md.

Links

User request

  • Verbatim: (paraphrased and translated into English at the requester's request; the original was in Chinese) After fixing this in our own deployment, also send the fix to new-api as a PR from my GitHub account rjchien728.
  • Later constraints or corrections from the user (quote, or none): (paraphrased, same as above) Only fix it upstream if it is a real bug, and make clear which fix goes upstream, since the symptom we first noticed was resolved by adding summary.

Out of scope — refuse

  • Matched: no. Not a Coding Plan / reverse-engineered channel / third-party wrapper / Codex channel-type change; not pass-through (the change is in chat→Responses serialization, which pass-through does not use); that summary is required comes from the official OpenAI SDKs, not Codex-specific behavior; not a usage / configuration question.
  • If yes, what was told to the user (stop here; do not open a PR): not applicable

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
  • 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): not applicable

Kind

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

Issue facts

  • Actual behavior: the reasoning response.output_item.added emitted by the chat→Responses stream conversion has no summary in its item (the empty slice is dropped by omitempty). output_item.done and the output in response.completed carry the summary text and are not affected.
  • Impact: ResponseReasoningItem.summary is required in the official OpenAI SDKs. Codex CLI 0.162.1 fails to parse the item without summary, and then logs a without active item error for every following reasoning_summary_part.added / reasoning_summary_text.delta; the task still completes.
  • Frequency: deterministic. Every reasoning item is affected whenever a streamed response goes through the chat→Responses conversion and the upstream returns reasoning_content.
  • Evidence that the problem is in new-api rather than the client or upstream: the Responses events are synthesized by new-api (the upstream speaks chat); the converter explicitly sets an empty Summary, which omitempty cancels; with the same Codex 0.162.1 and only the two SSE streams swapped (with / without "summary":[]), the log lines go from 2 to 0.
  • Applicable types and their fields (relay / billing / frontend / deployment; write "not applicable" otherwise): Relay: client POST /v1/responses (stream), chat upstream, RelayFormatOpenAI → RelayFormatOpenAIResponses, pass-through off; not tested against a server, reproduced at the relaykit level. Billing / Frontend / Deployment: not applicable.

Change

Adds case "reasoning" to ResponsesOutput.MarshalJSON in relaykit/dto/openai_response.go:

  • Summary has content: encodes through the existing alias, byte-for-byte the same output as before.
  • Summary is empty: additionally emits "summary":[] (an anonymous struct embedding the alias, with an outer Summary field tagged json:"summary" without omitempty; the shallower outer field overrides the embedded one of the same name).

Only items with Type == "reasoning" are affected; message / function_call and other items keep their existing branches and output. Test: a 6-line assertion added to the existing TestChatCompletionsStreamToResponsesEmitsReasoningSummaryPartLifecycle (the serialized reasoning added event contains "summary":[]); no new test file.

Research

Duplicate / prior art

Docs and code

  • https://docs.newapi.ai/ : opened the home page, /en/docs/api, /zh/docs/api/ai-model/chat/openai/createresponse. The Responses page only lists request parameters and response fields; it has no reasoning item summary or SSE event fields, and no configuration option. Not a usage / configuration question.
  • https://deepwiki.com/QuantumNous/new-api : could not be read; repeated requests (WebFetch, curl) all returned HTTP 429.
  • README / repo docs: README.md and README.zh_CN.md only list POST /v1/responses in the feature table; searching docs/ for output_item|reasoning_summary|relayconvert finds nothing.
  • Code paths and what they imply for this change:
    • relaykit/dto/openai_response.go:371 — Summary has omitempty; the default branch of MarshalJSON encodes through an alias, so an empty slice is omitted.
    • relaykit/relayconvert/internal/oai_chat/to_oai_responses_stream_resp.go:488-497 — the reasoning added event explicitly sets Summary: []dto.ResponsesReasoningSummaryPart{}, i.e. it means to emit summary:[].
    • relay/channel/openai/responses_via_chat.go:73, :86-87, :159 — streaming for a chat upstream and a /v1/responses client, converting per chunk and serializing with common.Marshal(event.Payload); confirmed to go through this defect.
    • relay/channel/claude/relay_responses.go:22, relay/channel/gemini/relay_responses.go:86 — in text_converter_registry.go both response conversions end with ConverterOpenAIChatToOpenAIResponses, and Claude thinking_delta / Gemini thought parts become reasoning_content; by reading the code they should be affected the same way; not tested.
    • relay/channel/openai/relay_responses.go:26-44, :83-97 — native Responses forwarding: the decoded struct is only used to read usage, and the client receives the original bytes, not ResponsesOutput serialization, so this change does not affect it.
    • Schema: openai-python src/openai/types/responses/response_reasoning_item.py has summary: List[Summary] (no default); openai-node src/resources/responses/responses.ts has ResponseReasoningItem.summary: Array<...> (not optional); Codex rust-v0.162.1 has summary: Vec<...> at codex-rs/protocol/src/models.rs:1054.

Alternatives considered

  • Option A: drop omitempty from Summary. Every item that goes through the default branch (e.g. message) would then also emit summary (null when nil), changing the output of other item types and requiring golden file updates. Not tried.
  • Option B: add the field only where to_oai_responses_stream_resp.go emits the reasoning added event. That code already sets an empty slice; it is the serialization step that drops it, so fixing it there means working around the DTO's encoding, and any other place that builds a reasoning item with an empty Summary would still lose the field.
  • Why this approach: adding summary only for the reasoning type in MarshalJSON. The schema requires summary on every reasoning item, and doing it at DTO serialization covers every path; the output is unchanged when Summary has content and for every other item type, and the diff is 16 lines (10 of production code).

Files

Path Why
relaykit/dto/openai_response.go adds case "reasoning" to ResponsesOutput.MarshalJSON, emitting "summary":[] when Summary is empty
relaykit/relayconvert/internal/oai_chat/to_oai_responses_resp_test.go adds a 6-line assertion to the existing TestChatCompletionsStreamToResponsesEmitsReasoningSummaryPartLifecycle

Behavior

  • Before: in the chat→Responses stream, the reasoning response.output_item.added item is {"type":"reasoning","id":"r1_reasoning_0","status":"in_progress","role":"","content":null,"quality":"","size":""}, with no summary.
  • After: the same event ends with an extra "summary":[]. Reasoning items with a non-empty Summary and all other item types are unchanged.
  • Explicit non-goals / leftover work: in the chat→Responses stream, an item is only closed at finish_reason, after the next item's output_item.added (interleaved events). There is no evidence of a client failing on this, so it is not part of this PR.

Verification

  • Commands and results:
    1. cd relaykit && GOWORK=off go test ./relayconvert/internal/oai_chat/ -run TestChatCompletionsStreamToResponsesEmitsReasoningSummaryPartLifecycle -count=1: FAIL on upstream main 45fbb149 (unfixed) with "{\"type\":\"response.output_item.added\",\"item\":{\"type\":\"reasoning\",\"id\":\"resp_1_reasoning_0\",\"status\":\"in_progress\",\"role\":\"\",\"content\":null,\"quality\":\"\",\"size\":\"\"},\"output_index\":0}" does not contain "\"summary\":[]"; PASS on this branch.
    2. cd relaykit && GOWORK=off go build ./... succeeds; GOWORK=off go test ./dto/ ./relayconvert/... -count=1 all ok, including the golden test TestGoldenResponseConversionMatrix (golden files unchanged).
    3. Root module: go test ./relay/channel/openai/ ./relay/channel/claude/ ./relay/channel/gemini/ ./service/ -count=1 all ok.
    4. gofmt -l relaykit/dto/openai_response.go relaykit/relayconvert/internal/oai_chat/to_oai_responses_resp_test.go prints nothing.
  • Manual steps and observed result:
    1. Minimal program (same as the Reproduction in relaykit: reasoning output_item.added in chat→Responses streams is missing the required summary field #7832: relaykit public API NewResponseStreamState + ConvertStreamResponseChunk fed one reasoning_content:"think" chunk): the reasoning added item from 45fbb149 has no summary; this branch outputs the same plus "summary":[], and all other events are identical.
    2. End to end: a standalone program (replace github.com/QuantumNous/new-api/relaykit => <fork>/relaykit) uses NewResponseStreamState(RelayFormatOpenAI → RelayFormatOpenAIResponses, EmitSequenceNumber: true), feeds 4 chat chunks (reasoning_content:"think" → tool_call shell announced → arguments {"command":["echo","hi"]} → finish_reason:"tool_calls"), then FinalizeStreamResponse, and prints the SSE. Reasoning added from upstream main: {"type":"reasoning","id":"r1_reasoning_0","status":"in_progress","role":"","content":null,"quality":"","size":""}; this branch: the same plus "summary":[]. Both SSE streams were served by a local mock Responses server to codex exec --skip-git-repo-check "run echo hi" < /dev/null (Codex CLI 0.162.1): upstream main exit 0 with 2 without active item lines on stderr (ReasoningSummaryPartAdded 1, ReasoningSummaryDelta 1); this branch exit 0 with 0 lines. Codex ran the tool and sent the follow-up request both times.
  • UI: screenshot or recording (or why none): not applicable, no frontend change.
  • Tests added or updated, or why none: updated an existing test (6-line assertion); no new test file, per AGENTS.md.
  • Databases / providers / platforms exercised: no database involved; no real upstream, hand-written chat chunks; Go 1.27.0 linux/arm64; the only client used was Codex CLI 0.162.1.
  • Not verified: no upstream new-api server deployed and tested; no clients other than Codex; the Claude / Gemini to Responses paths only confirmed by reading the code to go through the same conversion step, not run; sqlite / mysql / postgres not tested (the change does not touch the database); DeepWiki could not be opened.

Risks

  • Failure modes: any path that serializes a ResponsesOutput with Type == "reasoning" and an empty Summary now emits an extra "summary":[]. This matches the required field in the official OpenAI SDKs; per the code, native Responses forwarding (relay_responses.go) writes the original bytes and is not affected. The output is unchanged when Summary is non-empty.
  • Billing / quota / auth impact: none. Only reasoning item JSON serialization changes; usage, ratios, charges and auth are untouched.
  • Follow-ups: none. Interleaved events are listed under Behavior non-goals.

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

The Responses schema requires summary on every reasoning item, but the
chat-to-Responses stream announces a reasoning item with an empty
summary that omitempty drops. Strict clients reject the item and then
see every summary event that follows as having no active item.

Items that already carry summary text keep their existing encoding.
@coderabbitai

coderabbitai Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6a284c64-5dc3-47ee-b85e-7bf10ffaa5f8
📥 Commits

Reviewing files that changed from the base of the PR and between 45fbb14 and 1f2572f.

📒 Files selected for processing: 2
  • relaykit/dto/openai_response.go
  • relaykit/relayconvert/internal/oai_chat/to_oai_responses_resp_test.go

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

Walkthrough

Reasoning output items now serialize with "summary":[] when their summary is empty. A reasoning lifecycle test verifies this field before summary text arrives.

Changes

Reasoning Summary Serialization

Layer / File(s) Summary
Reasoning summary marshaling and validation
relaykit/dto/openai_response.go, relaykit/relayconvert/internal/oai_chat/to_oai_responses_resp_test.go
ResponsesOutput.MarshalJSON emits an empty summary array for reasoning items with no summary entries and preserves existing marshaling for nonempty summaries. The lifecycle test checks the empty array before summary text arrives.

Priority: ➖ Normal

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 1f257

Chat-to-Responses reasoning items now include an empty summary array before summary text arrives, addressing the stated strict-client compatibility issue. No actionable merge-blocking risk was identified.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Linked Issues check Passed Issue #7832 requires summary:[] for reasoning items with an empty summary, while preserving nonempty reasoning output and leaving other item types unchanged. ResponsesOutput.MarshalJSON adds a `re…
Out of Scope Changes check Passed The diff changes only relaykit/dto/openai_response.go and the related streaming conversion test. Both changes directly implement or verify issue #7832. The change is limited to chat-to-Responses rea…
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: emitting an empty summary for reasoning items announced without one.
  • Fix all pre-merge checks with AI
✨ 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 checks the stream at dawn
An empty summary hops along
The field stays clear before words arrive
Then summary text joins the drive
The rabbit bounds away, content

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

@seefs001
seefs001 merged commit ca2cae6 into QuantumNous:main Oct 16, 2026
1 check passed
@rjchien728
rjchien728 deleted the fix/relaykit-reasoning-summary branch October 16, 2026 19:55
shirosoralumie648 added a commit to shirosoralumie648/newapi-rev that referenced this pull request Oct 17, 2026
Sync 54 upstream commit(s) via merge (fork history preserved).
Behavior changes from upstream:
- 4013729 fix: disable sensitive word filtering by default and clear the default word list (QuantumNous#7814)

Upstream commits:
- 5e95951 feat(channels): add drag mode for channel priority ordering
- 5a59d69 fix(pricing): hide task prices left at zero when another price is set
- 3e2ce2c fix: align model card summary with status bar hours (QuantumNous#7847)
- b0a98ac fix(web): apply theme class before first paint so Dark Reader detects dark mode (QuantumNous#7571)
- f92c576 fix(web): cover Cloudflare clef and NVIDIA model families in provider rules (QuantumNous#7840)
- ff36846 fix(relayconvert): 保留 Chat/Claude → Responses 转换中 input_image 的 detail 字段 (QuantumNous#7855)
- 09109ec fix(middleware): 过载哨兵改用容器口径并加入连续性与新鲜度判定 (QuantumNous#7317)
- d032204 feat(aws): add Mantle Messages API support
- ca2cae6 fix(relaykit): emit summary on reasoning items announced without one (QuantumNous#7833)
- 45fbb14 fix(rate-limit): count each group with its own limit separately
- 6549a17 fix(dashboard): draw flow chart labels in the theme text color (QuantumNous#7821)
- c9179d3 fix(playground): support the reasoning field in chat responses (QuantumNous#7831)
- 908f94d fix(web): hide pages the user cannot open from console search
- 19d435e fix(relay): mask only the custom upstream address in error messages (QuantumNous#7822)
- 718a4e7 fix(vertex): use the multi-region hostnames for us and eu
- f196934 feat(plugins): bind Hailuo, Vidu and Veo plugins to New API channels
- bfdad29 fix(vidu): bill the model, duration and resolution Vidu generates
- 150ab3c chore(licenses): refresh the third-party dependency inventory
- 76cd511 build: upgrade moejs to v0.1.0-alpha.7
- 1b63c28 fix(claude): preserve explicit zero usage and cache-only billing (QuantumNous#7816)
- c9f7b62 fix(web): sort pricing models by input, output and per-request price (QuantumNous#7813)
- a0bf6a8 fix(vertex): pass project_id in API Key mode to avoid 404 on official endpoints (QuantumNous#6330)
- 4013729 fix: disable sensitive word filtering by default and clear the default word list (QuantumNous#7814)
- 7de10f2 feat(token): let an API key read its owner's quota
- ef60ef2 fix(relay): keep the cause of a failed body read for every later reader
- d10eafb fix(relay): report the real cause when a request body cannot be read
- 63cecab feat(channel): support Sub2API balance queries (QuantumNous#7749)
- b4be2a7 feat(ui): show newly added pricing groups at the top (QuantumNous#7782)
- 633b4c5 feat(logs): export usage logs from the common log page (QuantumNous#7774)
- dd59854 chore(deps-dev): bump undici from 6.28.0 to 6.29.0 in /electron (QuantumNous#7624)
- 93cf4ba chore(deps-dev): bump js-yaml from 4.3.1 to 4.3.2 in /electron (QuantumNous#7327)
- 3c9fb2a chore(deps-dev): bump brace-expansion from 1.1.16 to 1.1.21 in /electron (QuantumNous#7623)
- 9f04810 chore(deps): bump ai from 7.0.31 to 7.0.136 in /web (QuantumNous#7767)
- 3fe394c chore(deps): bump github.com/gorilla/websocket from 1.5.0 to 1.5.3 (QuantumNous#7001)
- 1c58f3d chore(deps-dev): bump fast-uri from 3.1.5 to 3.1.7 in /electron (QuantumNous#7169)
- 7f51a97 chore(deps-dev): bump js-yaml from 4.3.1 to 4.3.2 in /electron (QuantumNous#7327)
- 7e25797 chore(deps-dev): bump electron from 39.8.10 to 41.10.6 in /electron (QuantumNous#7625)
- bf4e1eb build(deps-dev): bump oxfmt from 0.57.0 to 0.72.0 in /web (QuantumNous#7766)
- 82306b3 build(deps-dev): bump @tanstack/router-plugin in /web (QuantumNous#7768)
- c730add build(deps): bump stream-markdown-parser from 1.1.3 to 1.2.18 in /web (QuantumNous#7769)
- b8c2dc1 build(deps): bump yace from 1.1.0 to 1.1.1 in /web (QuantumNous#7770)
- ba29f06 chore(deps-dev): bump @xmldom/xmldom from 0.8.13 to 0.8.15 in /electron (QuantumNous#7187)
- 767a82b fix(claude): forward thinking.block_binding and every anthropic-beta value (QuantumNous#7732)
- 2b85a8f fix(auth): show legal consent warning on password login (QuantumNous#7771)
- 2ed0587 fix(ci): stabilize checks and configure Bun dependency updates (QuantumNous#7765)
- 9948b1e fix(pricing): accept declared endpoint arrays in pricing conversion (QuantumNous#7724)
- 4bfcf28 chore(web): bump @lobehub/icons to 5.22.0 (QuantumNous#7764)
- fc08b76 fix(web): preserve recorded billing tiers in usage log previews (QuantumNous#7763)
- ba0e478 fix(relaykit): preserve assistant text with tool calls (QuantumNous#6871)
- 34b1942 fix(pricing): allow root access when the model square is disabled (QuantumNous#7761)
- b22a43b fix: mark task settlement logs with is_task for tiered billing display (QuantumNous#7446)
- bbf60b4 fix(logs): vertically align billing source icons on mobile (QuantumNous#7760)
- 3f926c3 fix(metrics): count completed streams after context cancellation (QuantumNous#7638)
- 3827fd8 fix(web): show cache read price on expression model cards (QuantumNous#7757)

Local tests not run (CI-only).
lizhongyi1209 pushed a commit to lizhongyi1209/new-api that referenced this pull request Oct 17, 2026
…uantumNous#7833)

The Responses schema requires summary on every reasoning item, but the
chat-to-Responses stream announces a reasoning item with an empty
summary that omitempty drops. Strict clients reject the item and then
see every summary event that follows as having no active item.

Items that already carry summary text keep their existing encoding.
cicioln pushed a commit to cicioln/new-api that referenced this pull request Oct 25, 2026
…uantumNous#7833)

The Responses schema requires summary on every reasoning item, but the
chat-to-Responses stream announces a reasoning item with an empty
summary that omitempty drops. Strict clients reject the item and then
see every summary event that follows as having no active item.

Items that already carry summary text keep their existing encoding.

(cherry picked from commit ca2cae6)
kyuhwi-choi pushed a commit to attodev/new-api that referenced this pull request Oct 30, 2026
…uantumNous#7833)

The Responses schema requires summary on every reasoning item, but the
chat-to-Responses stream announces a reasoning item with an empty
summary that omitempty drops. Strict clients reject the item and then
see every summary event that follows as having no active item.

Items that already carry summary text keep their existing encoding.

(cherry picked from commit ca2cae6)
timwenx pushed a commit to timwenx/new-api that referenced this pull request Nov 18, 2026
…uantumNous#7833)

The Responses schema requires summary on every reasoning item, but the
chat-to-Responses stream announces a reasoning item with an empty
summary that omitempty drops. Strict clients reject the item and then
see every summary event that follows as having no active item.

Items that already carry summary text keep their existing encoding.
xiaolanawaqaq pushed a commit to xiaolanawaqaq/new-apiaaa that referenced this pull request Nov 26, 2026
…uantumNous#7833)

The Responses schema requires summary on every reasoning item, but the
chat-to-Responses stream announces a reasoning item with an empty
summary that omitempty drops. Strict clients reject the item and then
see every summary event that follows as having no active item.

Items that already carry summary text keep their existing encoding.
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.

relaykit: reasoning output_item.added in chat→Responses streams is missing the required summary field

2 participants