Skip to content

New Chat / /clear / archived-view skip MessageWindow.reset() → stale header count + window mis-tracking (#2 gap) #164

Description

@jdmanring

Summary

Three code paths that clear #chat-history do not call window.chatHistory.reset() first, violating the DOM-virtualization invariant introduced by the message-window work (#2): "reset() must precede innerHTML='' so observers/holders are released" (see static/js/chatHistory.js:12, static/js/sessions.js:40-41).

#2 retrofitted the guard to six wipe sites but missed these three:

Site Function Trigger
static/js/sessions.js:2086 createDirectChat New Chat button
static/js/slashCommands.js:1182 _cmdSessionClear /clear command
static/js/sessions.js:2680 archived-session view opening an archived chat

User-visible symptom (New Chat path)

Open Odysseus with a restored session of N messages, then click New Chat. The header shows "New Chat · N msgs" — a stale count leaking from the previous session — instead of a clean "New Chat".

Root cause

The header counter (static/app.js:344-351) treats window.chatHistory.messageCount() as authoritative and recomputes on every #chat-history mutation. messageCount() returns _serverTotal + _liveMsgs. Because createDirectChat clears the DOM without reset(), _serverTotal (= previous session's row count) survives, so the innerHTML='' mutation re-fires the counter and it reads the stale total. reset() sets _serverTotal = null, which makes messageCount() return null, and the counter then falls back to the (now empty) DOM count → the badge clears.

The /clear and archived-view paths have the same defect: stale header count and a live MutationObserver tracking a DOM it no longer matches.

Fix

Insert if (window.chatHistory) window.chatHistory.reset(); immediately before the innerHTML='' at each of the three sites, matching the six existing compliant sites. Add a source-assertion regression guard that asserts reset() precedes the wipe in each function.

Scope / classification

Regression introduced by #2 (the message-window feature). Fix belongs on fix/dom-oom-virtualization, cherry-picked to develop. No separate upstream PR — folds into #2.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions