Skip to content

perf(chat): finalize live-reply renderer in-place instead of innerHTML replace on agent path #74

Description

@jdmanring

Problem

When a thinking-block agent response finishes, chat.js currently does:

if (_liveReplyEl && _finalReply) {
  var _replyHtml = markdownModule.mdToHtml(markdownModule.squashOutsideCode(_finalReply));
  _liveReplyEl.innerHTML = _replyHtml;

_liveReplyEl._streamRenderer was built up incrementally during streaming and already holds the correct content. The innerHTML = mdToHtml() call creates an entirely new DOM tree and discards the streamed one — one complete response-worth of detached Oilpan nodes per agent exchange.

Fix

When _liveReplyEl._streamRenderer exists, call update(_finalReply) to sync to the final post-processed text, then finalize() to freeze in place. Fall back to the existing innerHTML path only when the renderer is absent.

Impact

Eliminates the largest single-event Oilpan deposition per agent response — one full response-worth of DOM nodes freed per exchange rather than discarded as detached garbage.

Related to the OOM investigation in the fork.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions