fix: keep underscores literal while streaming#2902
Conversation
SummaryReading the diff at Code referenceThe wrapper at function _smdRendererWithoutUnderscoreEmphasis(renderer){
if(!renderer||!window.smd) return renderer;
const baseAddToken=renderer.add_token;
const baseEndToken=renderer.end_token;
const baseAddText=renderer.add_text;
const tokenStack=[];
renderer.add_token=(data,token)=>{
if(token===window.smd.ITALIC_UND||token===window.smd.STRONG_UND){
const marker=token===window.smd.STRONG_UND?'__':'_';
tokenStack.push(marker);
baseAddText(data,marker);
return;
}
tokenStack.push(null);
baseAddToken(data,token);
};
renderer.end_token=(data)=>{
const marker=tokenStack.pop();
if(marker){
baseAddText(data,marker);
return;
}
baseEndToken(data);
};
return renderer;
}Matches the settled-renderer policy in Diagnosis / RecommendationThe shape is correct. A few observations worth flagging:
Test planThe new test class runs both static checks (presence of the wrapper, correct symbol use in
LGTM as a focused fix. The wrapper is minimal, the testing is solid, and it routes through the existing |
|
Holding for rebase — base is stale (pre-batch15 master). Once you rebase onto current The actual fix in Thanks @george-andraws! |
83862e6
# Conflicts: # CHANGELOG.md
Thinking Path
streaming-markdownfor live assistant tokens, then replaces the live DOM with the settledrenderMd()output when the turn finishes.renderMd()only treats asterisk emphasis as Markdown emphasis, butstreaming-markdownemits separate underscore emphasis tokens._look italicized until the final settled render corrected it.smd, but wrap its renderer so underscore emphasis tokens emit literal_/__markers while asterisk emphasis still renders normally.What Changed
smdrenderer in_smdRendererWithoutUnderscoreEmphasis().ITALIC_UNDandSTRONG_UNDtokens by writing literal underscores.*emphasis*and**strong**still pass through the base renderer.tests/test_streaming_markdown.pyusing the vendoredsmd.min.jsmodule.Why It Matters
Live streamed Markdown now matches the final settled renderer for ordinary identifiers and prose such as
agent_response,foo_bar, and_not emphasis_. Users no longer see a paragraph temporarily turn italic during a response only to fix itself at completion.Verification
Passed:
Additional check:
Full-suite note:
/Users/georgeandraws/.hermes/hermes-agent/venv/bin/python -m pytest tests/ -q # 6539 passed, 5 skipped, 3 xpassed, 8 subtests passed, 5 failedThe five full-suite failures appear unrelated to this diff:
Systematic Debugging.git initcreatesmaster, but this machine creates a different default branch.CHANGELOG.md,static/messages.js, andtests/test_streaming_markdown.py.Risks / Follow-ups
smdunderscore emphasis token IDs and forwards all other tokens to the existing renderer.streaming-markdownupgrade that renames token constants should keep the focused regression red.Model Used
npx -y @openai/codex exec --full-autofor investigation and implementation.gpt-5.5.