Repository navigation
fix(tool-parser): preserve whitespace in GLM string arguments - #2744
Conversation
Signed-off-by: ai-jz <ai-jz@users.noreply.github.com>
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (1)
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review. 📝 SummarySummary by CodeRabbit
WalkthroughGLM-4 MoE argument parsing now preserves captured whitespace for schema coercion and trims values before fallback inference. Tests cover both complete parsing and chunked streaming for GLM-4.5 and GLM-4.7. ChangesGLM-4 MoE argument parsing
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Merge Risk: ⚪ Minimal · up to No actionable merge risk remains in the supplied evidence; the change is ready for normal merge checks. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Description
Problem
The GLM parser removes leading indentation and trailing newlines from tool argument strings. A model can produce the correct code, but an editing tool receives different text:
" return 1\n"becomes"return 1". That can break Python indentation or prevent an exact-text edit from matching its target. This is a parser data-loss issue, independent of the verifier's expected answer.Both GLM-4.5/4.6 and GLM-4.7/5 use this shared Rust parser. This completes the schema-aware string preservation introduced by #1841. The MRE below reproduces the data loss without a model server.
Solution
Pass the text inside
<arg_value>to the existing schema-aware conversion before trimming it. Declared strings retain their whitespace; unknown-type inference still receives trimmed text. Numeric conversion and JSON-quoted string decoding retain their existing behavior.Changes
Test Plan
Minimal reproducible example — CPU only
From an SMG checkout, save the following as
crates/tool_parser/examples/repro_glm_whitespace.rs(create theexamplesdirectory if needed), then runcargo run -p tool-parser --example repro_glm_whitespace. No model endpoint or GPU is required.Remove the temporary example before running repository lint checks.
"return 1"; assertion fails" return 1\n"; assertion passes"total = 1"" total = 1\n"Tested on an independent patch against
c0d3efa4ff829694164d901bbe7a837923604fc1, with Rust 1.98.0: the MRE fails before and passes after the fix. Both GLM dialects pass complete and streaming checks; all 551 tool-parser tests pass with no skips. Parser Clippy and workspace formatting pass.This validation exercises the native parser directly. It does not claim a complete CodeAgent session or GPU serving run. Nullable/union string schemas retain the existing inference and are outside this fix.
Selected command output from the independent patch
The test line is the library test binary; the total across all tool-parser test binaries is reported above.
Repository checks
Workspace checks also passed with this patch and the two companion parser fixes (#2743 and #2745) applied together. The parser checks above tested this PR independently.
cargo +nightly fmt --all -- --checkcargo clippy --locked --all-targets --all-features -- -D warningscargo test --lockedWASM test fixtures were built. Fixture-dependent vision cases were not exercised because the CI vision-golden generation step was not run. Ignored external-service/campaign tests and GPU serving were not run; this is not a full hosted-CI result.
Hosted CI
Both workflows completed successfully for PR head
43873eb8077343b2f11eed8414d9a38318ca8f5e:Claude Respondandgo-bindings-benchmarkwere skipped by the workflow; they are not counted as passing tests.Checklist
cargo +nightly fmt --all -- --checkpassescargo testpasses with all three fixes applied; limits listed above