fix(ui): match tool result snippet limit to backend (200 -> 4000 chars) - #3117
mysoul12138 wants to merge 2 commits into
Conversation
_cliToolResultSnippet truncated to 200 chars while the backend's _tool_result_snippet uses 4000. This caused tool card details to be more aggressively truncated after session reload than during live streaming. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
ReviewThe diagnosis is correct. The backend's Code referenceOrigin/master function _cliToolResultSnippet(raw){
const fullText=_cliToolResultText(raw);
if(_cliLooksLikePatchDiff(fullText)) return _clipCliToolSnippet(fullText);
return String(fullText||'').slice(0,200);
}Backend pair at _TOOL_RESULT_SNIPPET_MAX = 4000The PR aligns those two limits, which is the right symmetry. Layout / perf checkThe 20x bump is fine because if(s.length<=800){displaySnippet=s;}
else{
const cutoff=s.slice(0,800);
const lastBreak=Math.max(cutoff.lastIndexOf('. '),cutoff.lastIndexOf('\n'),cutoff.lastIndexOf('; '));
displaySnippet=lastBreak>80?s.slice(0,lastBreak+1):cutoff;
}So the rendered DOM stays the same size by default. The 4000-char One small caveat: the Diff-path branch
VerdictLGTM. The asymmetry was real (200 in WebUI vs 4000 in backend), the fix is the minimum delta, and the rendering path already gates the visible portion at 800 chars so this is a "Show more reveals more" change rather than a layout change. The test plan boxes are right; the easy verification is "reload a session whose live tool card showed 4000 chars and confirm the reloaded card's Show-more reveals the same content". One thing missing from the PR: a regression test asserting the JS constant matches the Python constant. Something like: # tests/test_tool_snippet_limit_parity.py
def test_tool_snippet_limit_parity():
py = (REPO / "api" / "streaming.py").read_text()
js = (REPO / "static" / "ui.js").read_text()
assert "_TOOL_RESULT_SNIPPET_MAX = 4000" in py
assert ".slice(0,4000)" in js…would prevent the limits from drifting apart again. Not blocking; ship as-is or with that two-assertion test added. |
1 similar comment
ReviewThe diagnosis is correct. The backend's Code referenceOrigin/master function _cliToolResultSnippet(raw){
const fullText=_cliToolResultText(raw);
if(_cliLooksLikePatchDiff(fullText)) return _clipCliToolSnippet(fullText);
return String(fullText||'').slice(0,200);
}Backend pair at _TOOL_RESULT_SNIPPET_MAX = 4000The PR aligns those two limits, which is the right symmetry. Layout / perf checkThe 20x bump is fine because if(s.length<=800){displaySnippet=s;}
else{
const cutoff=s.slice(0,800);
const lastBreak=Math.max(cutoff.lastIndexOf('. '),cutoff.lastIndexOf('\n'),cutoff.lastIndexOf('; '));
displaySnippet=lastBreak>80?s.slice(0,lastBreak+1):cutoff;
}So the rendered DOM stays the same size by default. The 4000-char One small caveat: the Diff-path branch
VerdictLGTM. The asymmetry was real (200 in WebUI vs 4000 in backend), the fix is the minimum delta, and the rendering path already gates the visible portion at 800 chars so this is a "Show more reveals more" change rather than a layout change. The test plan boxes are right; the easy verification is "reload a session whose live tool card showed 4000 chars and confirm the reloaded card's Show-more reveals the same content". One thing missing from the PR: a regression test asserting the JS constant matches the Python constant. Something like: # tests/test_tool_snippet_limit_parity.py
def test_tool_snippet_limit_parity():
py = (REPO / "api" / "streaming.py").read_text()
js = (REPO / "static" / "ui.js").read_text()
assert "_TOOL_RESULT_SNIPPET_MAX = 4000" in py
assert ".slice(0,4000)" in js…would prevent the limits from drifting apart again. Not blocking; ship as-is or with that two-assertion test added. |
Prevents the JS slice(0,N) and Python _TOOL_RESULT_SNIPPET_MAX from drifting apart again. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
Shipped in v0.51.159 (Release EE, stage-batch41) via release PR #3144 — thank you, @mysoul12138! 🎉 Your change (CLI tool-result snippet limit parity (200 → 4000)) is now on Two PRs in this batch needed a small semantic merge against code that landed in v0.51.158:
GitHub didn't auto-close this PR because the release merged resolved/reparented commits rather than your branch's exact head SHA, so closing manually. The full diff and tests are verified present on |
Summary
_cliToolResultSnippettruncated to 200 chars while the backend's_tool_result_snippetuses 4000. This caused tool card details to be more aggressively truncated after session reload than during live streaming.Impact
Test plan
🤖 Generated with Claude Code