Skip to content

fix(models): preserve escaped newlines in MindIE XML JSON arguments - #6334

Merged
WillemJiang merged 3 commits into
bytedance:mainfrom
cangen185-sudo:codex/fix-mindie-json-newline-preservation
Oct 7, 2026
Merged

WillemJiang merged 3 commits into
bytedance:mainfrom
cangen185-sudo:codex/fix-mindie-json-newline-preservation

Conversation

@cangen185-sudo

@cangen185-sudo cangen185-sudo commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Why

MindIE's escaped-newline compatibility conversion currently runs over the entire response before XML tool-call extraction. JSON arguments such as {"text":"line1\nline2"} can then contain an unescaped control character and fall back to a string; literal backslashes can also change silently.

Parse structured arguments from the original response while retaining the gateway's existing multiline behavior for ordinary raw-string parameters. The reproduction is offline with mocked model responses; no live MindIE endpoint or production incident is claimed.

What changed

  • Extract XML tool calls before decoding escaped newlines in the remaining reply text. JSON and Python-literal arguments retain their original escapes during parsing.
  • Restore literal \n decoding for non-JSON raw-string fallback values, outside fenced code, including surrounding-whitespace trimming. Multi-line file contents and commands keep working. Raw strings cannot distinguish intended literal escapes from gateway-escaped newlines; that existing ambiguity is documented explicitly.
  • Preserve native tool calls, mixed calls, unparseable-XML content behavior and the numeric overflow/underflow protections now on main. Rejected numeric containers retain the entire original argument.
  • Move the provider parsing explanation into backend/docs/CONFIGURATION.md#mindie-xml-tool-arguments; the README configuration list now contains a short link. Update the model guidance to the same contract.
  • Cover synchronous/asynchronous generation and tool-enabled simulated streaming. No dependencies, configuration options or public APIs change. The separate no-tool native-stream decoder and inherited synchronous streaming remain outside this fix.

Current main at 35cdcab1c5492e27e5d4dc525861256344cc5133 has been merged into the branch, retaining its numeric parsing and structured tool-result changes and resolving the model-guidance conflict.

Surface area

  • Default behavior change — structured MindIE XML arguments retain their original escapes; ordinary raw parameters retain multiline compatibility.

Bug fix verification

  • Original JSON-preservation regressions on unfixed main (a558884c3ad1625caf5db2c78e8902b6c6feb0d9): 8 failed, 49 passed. This is the original submission's recorded reproduction.
  • Reviewer-follow-up regressions on the updated branch before the raw-string fix: 8 failed, 89 passed. After the fix: 97 passed in tests/test_mindie_provider.py.
  • Tests cover raw file contents and commands, fenced code, malformed JSON, existing newlines/HTML entities, Python-literal escape semantics, rejected numeric containers, native tool calls and sync/async/tool-stream generation.

Validation

Actual follow-up execution on Windows / Python 3.12:

  • MindIE, model factory and lead-agent model resolution: 317 passed with external socket connections/DNS denied and loopback permitted.
  • Backend blocking-I/O suite after synchronizing with current main: 213 passed, 15 skipped. The earlier pre-sync checkout encountered Windows temporary-path limitations; no claim is made that those runs passed.
  • Full backend Ruff lint: passed. Ruff format check: 1889 files already formatted.
  • Agent-guidance check against current main: 39 AGENTS.md, 0 errors, 0 warnings.
  • git diff --check: passed.

Broader Windows offline runs stop on the existing POSIX file-mode expectation in test_channel_file_attachments.py::TestInboundFileSandboxPerms::test_make_inbound_file_sandbox_readable_sets_group_other_read (0o666 versus 0o644): before synchronization 1 failed, 2748 passed, 108 skipped, 7 deselected; after this follow-up 1 failed, 2788 passed, 108 skipped, 7 deselected. No full Windows-suite pass is claimed. Linux CI results are recorded separately when available. No live model/API integration tests were run.

AI assistance

Tool(s) used: Codex desktop; Luna Max for a bounded, local read-only patch review.

How you used it: Codex reproduced the defects, implemented the patch and reviewer follow-up, synchronized the fork branch with current main, updated documentation and ran the checks above at the contributor's request. Luna Max reviewed the scoped patch without modifying files. The change is AI-authored. The contributor has confirmed reading and understanding every line and taking responsibility for the change. Maintainer approval and CLA acceptance are separate from automated checks.

  • I've read and understand every line of this change and take responsibility for it — it's not unreviewed AI output.

@willem-bd willem-bd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed against bb97fa1. The core fix is sound: parsing XML tool calls from the original payload before the display-oriented newline decode preserves JSON argument fidelity, the added strip after decode correctly retains the old trailing-whitespace trimming (the parser's strip cannot remove trailing literal \n that decode then turns into real newlines), the unparseable-XML else branch keeps the existing prose/fence behavior, and the now-unconditional parse early-returns cheaply when no <tool_call> marker is present. I ran backend/tests/test_mindie_provider.py at this head in an isolated worktree: 57 passed, and ruff check/format are clean. One important design concern below about non-JSON multi-line parameters, plus a README placement nit.

Comment thread README.md Resolved
@CLAassistant

CLAassistant commented Oct 7, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@cangen185-sudo
cangen185-sudo marked this pull request as ready for review October 7, 2026 03:41
@github-actions github-actions Bot added area:backend Gateway / runtime / core backend under backend/ area:docs Documentation and Markdown only risk:medium Medium risk: regular code changes size/M PR changes 100-300 lines labels Oct 7, 2026

cangen185-sudo commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor Author

Hi @willem-bd, both review points are addressed in 2670be1, with implementation details and regression results in the two inline replies. The contributor has confirmed the required human review/responsibility statement, and this PR is ready for review and no longer has merge conflicts.

Local verification: 97 MindIE tests passed; the combined MindIE/model-factory/lead-agent suite gives 317 passed. Blocking-I/O gives 213 passed, 15 skipped. Backend lint/format and agent-guidance checks passed. The broader Windows suite still encounters the pre-existing POSIX file-mode assertion, so I am not claiming a full-suite pass.

Update: the contributor has signed the CLA, and license/cla now reports SUCCESS for 2670be1.

The new upstream Actions runs still report action_required: Unit Tests, Backend Blocking IO, and the other pending workflows. Could you or a maintainer approve these runs and re-review the patch? I have left the review threads open for your confirmation.

@WillemJiang WillemJiang added this to the 2.2.0 milestone Oct 7, 2026
@WillemJiang
WillemJiang merged commit 4918bea into bytedance:main Oct 7, 2026
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:backend Gateway / runtime / core backend under backend/ area:docs Documentation and Markdown only risk:medium Medium risk: regular code changes size/M PR changes 100-300 lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants