Skip to content

[Bug]: Citation comment box saves mid-word and closes when the timeline updates; the rest of the typing lands in the main composer #42595

Done

Description

@koerschner

Claude (claude-fable-5-2), assisting Nathan:

What happened

In Nathan's words: "I was clicked in to typing an in-context reply and the html doc I have open refreshed and I lost the state on the highlighted text."

He had cited text from an assistant reply and was typing in the citation comment box ("Add an optional comment..."). While he typed, the thread received a new update and the timeline re-rendered. The comment box closed by itself mid-word, the half-typed comment was saved onto the citation, the highlight on the quoted text disappeared, and focus moved to the main composer, so the rest of the sentence was typed there. An inline HTML render in the same timeline visibly reloaded at the same moment.

Expected: the comment box stays open with focus and the full draft until Enter, Save, Cancel or Escape. A timeline update never ends the typing.

Impact: a saved comment is silently cut mid-word and the stray text sits in the composer, where the next Enter sends it as a message.

Diagnosis

From reading the source (not from logs). The code below is the same at the client's commit 295a0a7332aa, the server's commit 6b7027b1f43e, and main at 31d95f850b.

  • observeAssistantCitationCommentSource runs a MutationObserver on the whole timeline viewport while the comment box is open. On any mutation, if the cited row is no longer connected (!source.isConnected || !viewport.contains(source)) or resolveAssistantCitationRange cannot re-find the quote, it calls onUnavailable, and its dispose() removes the t3-assistant-citation-comment highlight:
    export function observeAssistantCitationCommentSource({
    anchor,
    citation,
    onUnavailable,
    }: {
    anchor: AssistantCitationSourceAnchor;
    citation: AssistantCitation;
    onUnavailable: () => void;
    }): () => void {
    const { source, range, viewport } = anchor;
    const registry = typeof CSS !== "undefined" ? CSS.highlights : undefined;
    let highlight: Highlight | null = null;
    let stopped = false;
    const observer = new MutationObserver((records) => {
    if (stopped) return;
    const sourceChanged = records.some((record) => source.contains(record.target));
    validate(sourceChanged);
    });
    const dispose = () => {
    if (stopped) return;
    stopped = true;
    observer.disconnect();
    if (!highlight) return;
    highlight.delete(range);
    if (highlight.size === 0 && registry?.get(COMMENT_HIGHLIGHT_NAME) === highlight) {
    registry.delete(COMMENT_HIGHLIGHT_NAME);
    }
    };
    const unavailable = () => {
    if (stopped) return;
    dispose();
    onUnavailable();
    };
    const validate = (sourceChanged: boolean): boolean => {
    if (!source.isConnected || !viewport.contains(source)) {
    unavailable();
    return false;
    }
    if (
    sourceChanged ||
    range.collapsed ||
    !source.contains(range.startContainer) ||
    !source.contains(range.endContainer)
    ) {
    const repaired = resolveAssistantCitationRange(source, citation);
    if (!repaired) {
    unavailable();
    return false;
    }
    range.setStart(repaired.startContainer, repaired.startOffset);
    range.setEnd(repaired.endContainer, repaired.endOffset);
    }
    return true;
    };
    if (!validate(false)) return dispose;
    if (typeof Highlight !== "undefined" && registry) {
    const existing = registry.get(COMMENT_HIGHLIGHT_NAME);
    highlight = existing ?? new Highlight();
    highlight.add(range);
    if (!existing) registry.set(COMMENT_HIGHLIGHT_NAME, highlight);
    }
    observer.observe(viewport, { childList: true, subtree: true, characterData: true });
    return dispose;
    }
  • onSourceUnavailable in AssistantCitationChip then calls settleDraftOnClose("none"). resolveAssistantCitationCommentDismissal returns commit for any non-empty draft, so the partial comment is saved through onSave and onOpenChange(false) closes the popover:
    const settleDraftOnClose = (reason: string): boolean => {
    const dismissal = resolveAssistantCitationCommentDismissal({
    reason,
    draft: draftCommentRef.current,
    savedComment: citation.comment,
    });
    if (dismissal.kind === "commit") return commentEditor?.onSave(dismissal.comment) ?? true;
    return dismissal.kind !== "keep-open";
    };
    const onSourceUnavailable = useEffectEvent(() => {
    if (!sourceAnchor) return;
    if (settleDraftOnClose("none")) {
    commentEditor?.onOpenChange(false);
    } else {
    setUnavailableSourceAnchor(sourceAnchor);
    }
    });
    // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- observes the cited DOM source while the comment editor is open and reacts when it disappears
    useEffect(() => {
    if (!commentOpen || sourceAnchor === unavailableSourceAnchor) return;
    const anchor = sourceAnchor ?? findAssistantCitationSourceAnchor(document, citation);
    if (!anchor) return;
    return observeAssistantCitationCommentSource({
    anchor,
    citation,
    onUnavailable: onSourceUnavailable,
    });
    }, [citation, commentOpen, sourceAnchor, unavailableSourceAnchor]);
  • The popover's finalFocus calls onRestoreFocus in ComposerCitationNodeView, which focuses the composer right after the chip. That is where the following keystrokes go: https://github.com/pingdotgg/t3code/blob/31d95f850bd8f1dfb68676500606d44b923e4883/apps/web/src/components/ComposerPromptEditorTiptap.tsx
  • The timeline is a virtualized LegendList, and alwaysRenderKeys in MessagesTimeline.tsx pins only the first and last message rows, not the row whose comment box is open, so a routine update can unmount the cited row: https://github.com/pingdotgg/t3code/blob/31d95f850bd8f1dfb68676500606d44b923e4883/apps/web/src/components/chat/MessagesTimeline.tsx

The browser tests under "citation comment source disappearance" in AssistantCitationChip.browser.test.tsx assert this save-and-close, so it looks intended for a source that is truly gone. The problem is that an ordinary timeline update triggers it while the user is typing.

Not established: which timeline update removed the cited row here (follow-scroll unmounting it, or the row remounting). The HTML render iframe reloading at the same moment suggests a remount. This was not reproduced in a test thread.

Suggested fix: either keep the cited row mounted while its comment box is open (add it to alwaysRenderKeys), or on source loss keep the editor open and focused, anchored to the composer chip (the existing setUnavailableSourceAnchor path used for an over-length draft), instead of committing and closing.

Steps to reproduce

Observed once; not yet reduced to a deterministic repro.

  1. Open a thread whose agent is still working or about to post again, with an assistant reply above the newest row. Ours also had an inline HTML render in the timeline.
  2. Select text in that assistant reply and click Cite. The comment box opens under the quoted text, which is highlighted.
  3. Start typing a comment and keep typing without pressing Enter.
  4. While you type, the thread receives a new message or update and the timeline re-renders.
  5. The comment box closes mid-word, the partial comment is saved on the citation chip, and the remaining keystrokes go into the main composer.

Version

Client: T3 Code (Nightly) desktop 0.1.10-nightly.20261115.4749 (commit 295a0a7332aa). Server: 0.1.10-nightly.20261116.4761 (commit 6b7027b1f43e).

Environment

  • Client: T3 Code (Nightly) desktop app, Electron 44.10.1, Chrome 152, on a MacBook Pro (Apple M4 Pro, macOS 26.4.1), connected over Tailscale to a remote server.
  • Server: t3 serve (service-managed) on macOS 27.2.1, Apple Silicon.
  • Client settings: toolCallVisibility: "showAll", followUpBehavior: "steer", chatWidth: "full", panelAnimationDurationMs: 0. Response streaming: server default (paragraph).
  • Provider and model on the thread: Pi, truefoundry-chat/gemini-group/gemini-4-neon.

Evidence

No log lines; the evidence is the text itself. One sentence, typed without pausing, was split at the moment the timeline updated:

saved as the citation comment:  if it's a good bug rep
landed in the main composer:    ort and has a specific example then I'm down with it.

Related issues

Not a duplicate of #36193 (typing a citation comment scrolls the page; fix proposed in #36194). Same comment box, different failure. No issue or pull request was found for the box closing or saving early.

Fix applied or workaround

Nothing was changed on the machine. Workaround: press Enter to save the comment before the agent posts again, or type the comment in the main composer instead of the comment box.

Filed by

Claude (claude-fable-5-2), assisting Nathan. Investigated by hand from the source and the installed bundle, not with npx t3 triage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions