fix(chat): dedupe uploaded-file pending turns - #2906
1 commit merged into
Conversation
SummaryReading the diff at Code referenceThe change at function _mergePendingSessionMessage(session,messages){
if(!Array.isArray(messages)) return false;
const pendingMsg=typeof getPendingSessionMessage==='function'?getPendingSessionMessage(session,messages):null;
if(!pendingMsg) return false;
if(messages.some(existing=>_sameTranscriptMessage(existing,pendingMsg))) return false;
const liveAssistantIdx=messages.findIndex(m=>m&&m.role==='assistant'&&m._live);
if(liveAssistantIdx>=0) messages.splice(liveAssistantIdx,0,pendingMsg);
else messages.push(pendingMsg);
return true;
}The dedupe key is else if(uploaded.length)msgText=`${text}\n\n[Attached files: ${uploadedPaths.join(', ')}]`;So a server-pending message containing the suffix and a transcript copy without it (or vice versa) compare equal at the identity level. Diagnosis / RecommendationThe fix is correct and minimal. Specific observations:
pending_idx = src.find("function _mergePendingSessionMessage")
assert pending_idx >= 0, "pending session merge helper not found"
pending_block = src[pending_idx:pending_idx+500]
assert "_sameTranscriptMessage(existing,pendingMsg)" in pending_block, ...A 500-char window is tight enough that future refactors of the helper would have to keep the dedupe lookup adjacent, which is the invariant being preserved. Good.
Test planThe regression assertion in
LGTM. Small, surgical, and exactly mirrors #2723's contract on the other restore path. |
a0ab168
Thinking Path
[Attached files: ...]suffix._sameTranscriptMessageidentity check to that pending merge path so the same uploaded-file user turn is rendered once.What Changed
_sameTranscriptMessage(existing, pendingMsg)in_mergePendingSessionMessage()before inserting a server pending user message.Why It Matters
Verification
python3 -m pytest -q tests/test_regressions.py::test_inflight_merge_dedupes_uploaded_user_message tests/test_issue2341_pending_user_reattach.py -o addopts=''-> 3 passednode --check static/sessions.jsgit diff --check origin/master...HEADRisks / Follow-ups
Model Used