Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Render Assistant stream-event rows with <Index> so they stop re-mounting

rcourtmanc3cd811b98d1
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index 9528193c1d..800e4d1c11 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -2299,9 +2299,20 @@ during a turn. `ChatMessages` (`frontend-modern/src/components/AI/Chat/ChatMessa
reconciles the incoming array into a keyed `solid-js/store` mirror so each
message keeps a stable identity across updates; `MessageItem` already reads every
field through accessors, so only the genuinely changed text/rows update in place.
-This keeps the live transcript stable the way OpenCode's timeline is. (Residual
-in-place churn remains in the per-message stream-event/tool-row list, which is a
-separate, narrower follow-up.)
+This keeps the live transcript stable the way OpenCode's timeline is.
+
+The same stability rule applies one level down, to the per-message
+stream-event/tool-row list inside `MessageItem`. `groupStreamEventsForDisplay`
+remaps blocks to fresh objects on every tick and `StreamDisplayEvent` carries no
+id, but the grouped list is strictly append-ordered (the grouper only pushes new
+blocks or mutates the open content/thinking block in place — it never inserts
+mid-list or reorders). It therefore renders through `<Index>` (positional
+keying), not a reference-keyed `<For>`: each row keeps its DOM node across
+event-object rebuilds at a stable position, so the streaming answer block and
+completed tool rows update in place instead of re-mounting (and re-parsing
+markdown) on every content delta. Positional keying is correct here precisely
+because the list is append-only; a list that could reorder or key by identity
+must not use `<Index>`.
Assistant slash-command availability is part of the command runtime contract,
not only visual polish. The OpenCode reference at fetched `origin/dev` commit
diff --git a/frontend-modern/src/components/AI/Chat/MessageItem.tsx b/frontend-modern/src/components/AI/Chat/MessageItem.tsx
index 6a4f558ca4..139f2688a2 100644
--- a/frontend-modern/src/components/AI/Chat/MessageItem.tsx
+++ b/frontend-modern/src/components/AI/Chat/MessageItem.tsx
@@ -1,7 +1,7 @@
import {
Component,
Show,
- For,
+ Index,
Switch,
Match,
createEffect,
@@ -649,37 +649,38 @@ export const MessageItem: Component<MessageItemProps> = (props) => {
{/* Stream events - chronological display */}
<Show when={hasRenderableStreamEvents()}>
- <For each={groupedEvents()}>
+ <Index each={groupedEvents()}>
{(evt, index) => {
const contentText = () =>
- stripAssistantOutputArtifacts(evt?.content || '').text;
+ stripAssistantOutputArtifacts(evt()?.content || '').text;
const visibleWorkflowStatus = () =>
- evt?.type === 'workflow_status'
- ? shouldPaceWorkflowStatusEvent(evt, index())
- ? pacedWorkflowStatus() || evt.workflowStatus
- : evt.workflowStatus
+ evt()?.type === 'workflow_status'
+ ? shouldPaceWorkflowStatusEvent(evt(), index)
+ ? pacedWorkflowStatus() || evt().workflowStatus
+ : evt().workflowStatus
: undefined;
return (
<Switch>
<Match
when={
- evt?.type === 'thinking' &&
- evt.thinking?.trim() &&
- isLeadingThinkingEvent(index())
+ evt()?.type === 'thinking' &&
+ evt().thinking?.trim() &&
+ isLeadingThinkingEvent(index)
}
>
<ThinkingBlock
- content={evt?.thinking || ''}
+ content={evt()?.thinking || ''}
isStreaming={props.message.isStreaming}
- startedAt={evt?.startedAt}
- updatedAt={evt?.updatedAt}
+ startedAt={evt()?.startedAt}
+ updatedAt={evt()?.updatedAt}
/>
</Match>
<Match
when={
- evt?.type === 'workflow_status' && shouldRenderWorkflowStatusEvent(evt)
+ evt()?.type === 'workflow_status' &&
+ shouldRenderWorkflowStatusEvent(evt())
}
>
<div
@@ -709,22 +710,22 @@ export const MessageItem: Component<MessageItemProps> = (props) => {
</div>
</Match>
- <Match when={evt?.type === 'pending_tool' ? evt.pendingTool : undefined}>
+ <Match when={evt()?.type === 'pending_tool' ? evt().pendingTool : undefined}>
{(pendingTool) => <PendingToolBlock tool={pendingTool()} />}
</Match>
- <Match when={evt?.type === 'tool_cancel' ? evt.toolCancel : undefined}>
+ <Match when={evt()?.type === 'tool_cancel' ? evt().toolCancel : undefined}>
{(toolCancel) => <ToolCancellationBlock tool={toolCancel()} />}
</Match>
- <Match when={evt?.type === 'tool' ? evt.tool : undefined}>
+ <Match when={evt()?.type === 'tool' ? evt().tool : undefined}>
{(tool) => (
<ToolExecutionBlock
- startedAt={evt?.startedAt}
- completedAt={evt?.updatedAt}
+ startedAt={evt()?.startedAt}
+ completedAt={evt()?.updatedAt}
live={props.message.isStreaming}
- settleUntil={evt?.settleUntil}
- compact={shouldCompactCompletedToolEvent(evt, index())}
+ settleUntil={evt()?.settleUntil}
+ compact={shouldCompactCompletedToolEvent(evt(), index)}
tool={{
name: tool().name || 'unknown',
input: tool().input || '{}',
@@ -737,7 +738,9 @@ export const MessageItem: Component<MessageItemProps> = (props) => {
</Match>
<Match
- when={evt?.type === 'model_switch' && evt.model?.trim() ? evt : undefined}
+ when={
+ evt()?.type === 'model_switch' && evt().model?.trim() ? evt() : undefined
+ }
>
{(modelEvent) => {
const event = modelEvent();
@@ -789,15 +792,15 @@ export const MessageItem: Component<MessageItemProps> = (props) => {
</Match>
{/* Content/text block */}
- <Match when={evt?.type === 'content' && contentText()}>
+ <Match when={evt()?.type === 'content' && contentText()}>
<AssistantMarkdownBlock
text={contentText()}
streaming={props.message.isStreaming}
- paceKey={`${props.message.id}:stream:${index()}`}
+ paceKey={`${props.message.id}:stream:${index}`}
/>
</Match>
- <Match when={evt?.type === 'approval' ? evt.approval : undefined}>
+ <Match when={evt()?.type === 'approval' ? evt().approval : undefined}>
{(approval) => (
<div class="my-4">
<ApprovalCard
@@ -809,7 +812,7 @@ export const MessageItem: Component<MessageItemProps> = (props) => {
)}
</Match>
- <Match when={evt?.type === 'question' ? evt.question : undefined}>
+ <Match when={evt()?.type === 'question' ? evt().question : undefined}>
{(question) => (
<div class="my-4">
<QuestionCard
@@ -823,7 +826,7 @@ export const MessageItem: Component<MessageItemProps> = (props) => {
</Switch>
);
}}
- </For>
+ </Index>
</Show>
{/* Fallback */}
<Show when={visibleMessageContent() && !hasRenderableStreamEvents()}>
diff --git a/frontend-modern/src/components/AI/Chat/__tests__/MessageItem.test.tsx b/frontend-modern/src/components/AI/Chat/__tests__/MessageItem.test.tsx
index aff211597b..32a866dfb7 100644
--- a/frontend-modern/src/components/AI/Chat/__tests__/MessageItem.test.tsx
+++ b/frontend-modern/src/components/AI/Chat/__tests__/MessageItem.test.tsx
@@ -2241,4 +2241,35 @@ describe('MessageItem', () => {
expect(prose).not.toBeInTheDocument();
});
});
+
+ describe('streaming row stability', () => {
+ // useChat rebuilds the streamEvents array on every stream tick, and
+ // groupStreamEventsForDisplay remaps blocks to fresh objects. Rendering that
+ // through a reference-keyed <For> re-mounted each row on every tick — tool
+ // rows and the streaming answer block flashing. The list is append-ordered,
+ // so it must render through <Index> (positional keying): a row keeps its DOM
+ // node across event-object rebuilds at a stable position, and only its
+ // changed fields update in place.
+ it('keeps a tool row mounted in place as its event object is rebuilt mid-stream', () => {
+ const toolEvent = (output: string): StreamDisplayEvent => ({
+ type: 'tool',
+ tool: { name: 'pulse_query', input: '{}', output, success: true },
+ });
+ const [msg, setMsg] = createSignal<ChatMessage>(
+ makeMessage({ role: 'assistant', content: '', isStreaming: true, streamEvents: [toolEvent('a')] }),
+ );
+ render(() => <MessageItem message={msg()} {...makeHandlers()} />);
+
+ const nodeBefore = screen.getByTestId('tool-execution-block');
+
+ // Next stream tick: brand-new array + brand-new tool event object (output
+ // grew), same position. <For> would recreate the row; <Index> keeps it.
+ setMsg(
+ makeMessage({ role: 'assistant', content: '', isStreaming: true, streamEvents: [toolEvent('ab')] }),
+ );
+
+ const nodeAfter = screen.getByTestId('tool-execution-block');
+ expect(nodeAfter).toBe(nodeBefore);
+ });
+ });
});