Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

fix(chat): an empty tail with history behind it is loading, not empty

review450e35a61728
diff --git a/src/renderer/nodes/ChatPanel.paging.test.tsx b/src/renderer/nodes/ChatPanel.paging.test.tsx
index cb8db26d3..818229079 100644
--- a/src/renderer/nodes/ChatPanel.paging.test.tsx
+++ b/src/renderer/nodes/ChatPanel.paging.test.tsx
@@ -320,4 +320,38 @@ describe('ChatPanel progressive loading', () => {
expect(pending).toHaveLength(4)
expect(pending[3].page).toEqual({ before: 1000, maxBytes: CHAT_OLDER_PAGE_BYTES })
})
+ // A tail window can hold no message at all and still have history behind it (its records were
+ // all metadata, or — before core grew such windows — one line bigger than the page). That is
+ // "still loading", never "No conversation yet.": the panel pages back by itself from there.
+ it('an EMPTY tail with history behind it shows the loading row, not the empty state', async () => {
+ await render()
+ await settle(0, { messages: [], olderCursor: 5000 })
+ expect(host.textContent).not.toContain('No conversation yet.')
+ expect(host.querySelector('[role="status"]')?.textContent).toContain('Loading conversation…')
+ expect(pending).toHaveLength(2) // it paged back on its own
+ expect(pending[1].page).toEqual({ before: 5000, maxBytes: CHAT_OLDER_PAGE_BYTES })
+ await settle(1, { messages: [say(0, 'older')], olderCursor: null })
+ expect(bubbles()).toEqual(['older'])
+ expect(host.textContent).not.toContain('Loading conversation…')
+ })
+
+ it('an empty tail whose older page FAILS offers the retry row, not an empty conversation', async () => {
+ await render()
+ await settle(0, { messages: [], olderCursor: 5000 })
+ await act(async () => pending[1].reject(new Error('host blip')))
+ expect(host.textContent).not.toContain('No conversation yet.')
+ expect(host.textContent).toContain("Couldn't load earlier messages.")
+ await act(async () => host.querySelector<HTMLButtonElement>('.term-chat__older .term-chat__retry')!.click())
+ expect(pending).toHaveLength(3)
+ expect(pending[2].page).toEqual({ before: 5000, maxBytes: CHAT_OLDER_PAGE_BYTES })
+ })
+
+ it('switching session to one whose read REJECTS clears the previous session\'s thread', async () => {
+ await render('s1')
+ await settle(0, { messages: [say(1000, 'OLD session')], olderCursor: null })
+ await render('s2')
+ await act(async () => pending[1].reject(new Error('boom')))
+ expect(bubbles()).toEqual([])
+ expect(host.textContent).toContain("Couldn't read the transcript.")
+ })
})
diff --git a/src/renderer/nodes/ChatPanel.tsx b/src/renderer/nodes/ChatPanel.tsx
index b134b3dad..9b3bbe51b 100644
--- a/src/renderer/nodes/ChatPanel.tsx
+++ b/src/renderer/nodes/ChatPanel.tsx
@@ -202,6 +202,9 @@ export function ChatPanel({
setLoadState('ok')
return
}
+ // …and, as there, a thread of ANOTHER transcript (the session changed under the panel) is
+ // cleared: the error message must not sit under the previous session's conversation.
+ if (t.identity !== identity) setThread(emptyThread(identity))
setLoadState(isUnsupported(e) ? 'unsupported' : 'error')
}
)
@@ -381,6 +384,16 @@ export function ChatPanel({
// the action instead of promising a chord that never fires.
const mdChip = chipFor('node.toggleMarkdown')
+ // A tail that yielded no message but has history behind it (all-metadata records, or a window a
+ // single huge record filled) is STILL LOADING — the panel pages back by itself from here. Saying
+ // "No conversation yet." there, until the older page landed, told the user a session with a
+ // whole conversation had none. A failed older page gets the retry row instead (below).
+ const historyPending = thread.identity === identity && thread.olderCursor !== null
+ const initialLoading =
+ messages.length === 0 &&
+ (loadState === 'loading' || (loadState === 'ok' && historyPending && olderState !== 'error'))
+ const showEmpty = messages.length === 0 && loadState !== 'loading' && !(loadState === 'ok' && historyPending)
+
return (
<div className="term-chat nodrag nowheel">
<div className="term-chat__bar">
@@ -398,7 +411,7 @@ export function ChatPanel({
</span>
</div>
<div className="term-chat__msgs" ref={msgsRef} onScroll={onScroll}>
- {messages.length === 0 && loadState === 'loading' && (
+ {initialLoading && (
<div className="term-chat__loading" role="status">
<span className="term-chat__spinner" aria-hidden="true" />
<span>{EMPTY_TEXT.loading.title}</span>
@@ -410,7 +423,7 @@ export function ChatPanel({
<span>Loading earlier messages…</span>
</div>
)}
- {messages.length > 0 && olderState === 'error' && (
+ {olderState === 'error' && (
<div className="term-chat__older term-chat__older--error">
<span>Couldn't load earlier messages.</span>
<button className="term-chat__retry" onClick={loadOlder}>
@@ -423,7 +436,7 @@ export function ChatPanel({
{olderState === 'idle' && thread.olderCursor === null && messages.some((m) => m.key !== undefined) && (
<div className="term-chat__older term-chat__older--start">Beginning of conversation</div>
)}
- {messages.length === 0 && loadState !== 'loading' && (
+ {showEmpty && (
<div className="term-chat__empty">
<div>{EMPTY_TEXT[loadState].title}</div>
{EMPTY_TEXT[loadState].detail && (