Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(desktop): preserve collapsed idle echo metadata on the authoritative row (R2-M1)

Diego Zacariasd8f45d34b38f
diff --git a/desktop-app/package-lock.json b/desktop-app/package-lock.json
index 73b5128c3..8e2fc2f2d 100644
--- a/desktop-app/package-lock.json
+++ b/desktop-app/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "evenfire",
- "version": "0.1.348",
+ "version": "0.1.349",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "evenfire",
- "version": "0.1.348",
+ "version": "0.1.349",
"license": "MPL-2.0",
"dependencies": {
"@tanstack/react-query": "5.100.10",
diff --git a/desktop-app/package.json b/desktop-app/package.json
index 19c8bd19a..fd6d13a7d 100644
--- a/desktop-app/package.json
+++ b/desktop-app/package.json
@@ -1,7 +1,7 @@
{
"name": "evenfire",
"productName": "Evenfire",
- "version": "0.1.348",
+ "version": "0.1.349",
"private": true,
"license": "MPL-2.0",
"description": "Evenfire desktop client for secure agent and workflow access",
diff --git a/desktop-app/src/__tests__/chatMessageMerge.test.ts b/desktop-app/src/__tests__/chatMessageMerge.test.ts
index d1e02b25d..e81093245 100644
--- a/desktop-app/src/__tests__/chatMessageMerge.test.ts
+++ b/desktop-app/src/__tests__/chatMessageMerge.test.ts
@@ -1417,10 +1417,14 @@ describe('mergeAuthoritativeServerMessages — R2-H1 idle echo liveness (§6.1,
),
// If active, the bubble is optimistic-live and must never collapse (I-5).
active: fc.boolean(),
+ // R2-M1: whether the optimistic bubble carries side metadata
+ // (toolSteps/attachments) that the reconciled server row does NOT have. When
+ // an idle echo collapses, that metadata must survive on the authoritative row.
+ withMeta: fc.boolean(),
})
fc.assert(
- fc.property(scenarioArb, ({ start, role, bubbleMode, active }) => {
+ fc.property(scenarioArb, ({ start, role, bubbleMode, active, withMeta }) => {
const turns = [
{ number: start, user_input: `q${start}`, started_at: new Date(start).toISOString() },
{
@@ -1451,12 +1455,21 @@ describe('mergeAuthoritativeServerMessages — R2-H1 idle echo liveness (§6.1,
: bubbleMode === 'stale-echo'
? staleContent
: `orphan-${start}`
+ // R2-M1: side metadata the reconciled server rows never carry. When the
+ // idle echo collapses it must be merged onto the authoritative row.
+ const bubbleToolSteps = [
+ { toolName: 'search', displayName: 'Search', state: 'completed' as const },
+ ]
+ const bubbleAttachments = [
+ { id: 'echo-file', type: 'response_file' as const, label: 'result.txt' },
+ ]
const bubble: ChatMessage = {
id: 'sandwiched-bubble',
role,
content: bubbleContent,
timestamp: 999,
task_id: 'the-task',
+ ...(withMeta ? { toolSteps: bubbleToolSteps, attachments: bubbleAttachments } : {}),
}
const existing: ChatMessage[] = [low!, bubble, diskHigh]
@@ -1470,10 +1483,24 @@ describe('mergeAuthoritativeServerMessages — R2-H1 idle echo liveness (§6.1,
// gate (b) plus the authoritative-comparison fix: no local text is lost.
if (bubbleMode === 'fresh-echo' && !active) {
expect(ids).not.toContain('sandwiched-bubble')
+ // R2-M1: the collapsed echo's side metadata survives on the surviving
+ // authoritative row (never dropped with the local, never rewriting content).
+ if (withMeta) {
+ const authRow = merged.find(m => m.serverTurnNumber === start + 1 && m.role === role)
+ expect(authRow?.toolSteps).toEqual(bubbleToolSteps)
+ expect(authRow?.attachments).toEqual(bubbleAttachments)
+ }
} else {
expect(ids).toContain('sandwiched-bubble')
// The surviving bubble keeps its original text in the output.
expect(merged.find(m => m.id === 'sandwiched-bubble')?.content).toBe(bubbleContent)
+ // R2-M1: an un-collapsed bubble keeps its own metadata and never leaks it
+ // onto the authoritative row (no false merge).
+ if (withMeta) {
+ expect(merged.find(m => m.id === 'sandwiched-bubble')?.toolSteps).toEqual(
+ bubbleToolSteps
+ )
+ }
}
// The authoritative higher turn always lands with its FRESH content.
expect(merged.find(m => m.serverTurnNumber === start + 1 && m.role === role)?.content).toBe(
@@ -1508,3 +1535,100 @@ describe('mergeAuthoritativeServerMessages — R2-H1 idle echo liveness (§6.1,
)
}, 120000)
})
+
+describe('mergeAuthoritativeServerMessages — R2-M1 idle echo metadata precedence (§6.2)', () => {
+ it('R2-M1: preserves a collapsed idle echo side metadata (toolSteps/attachments) on the authoritative row', () => {
+ // Regression for R2-M1 (regression of 40cc7afe): a drop-only collapse discarded
+ // the optimistic bubble's toolSteps/attachments that the reconciled server row
+ // does not carry. Server rows are derived from the real producer (T1) and carry
+ // NO tool_steps here, so the metadata lives only on the local bubble. After the
+ // idle collapse the metadata must land on the surviving authoritative row (T4).
+ const incoming = turnsToChatMessages([
+ { number: 1, user_input: 'q1', response: 'a1', started_at: new Date(1).toISOString() },
+ { number: 2, user_input: 'q2', response: 'a2', started_at: new Date(2).toISOString() },
+ ])
+ const optimisticEcho: ChatMessage = {
+ id: 'optimistic-assistant',
+ role: 'assistant',
+ content: 'a2', // mirrors turn-2-assistant → collapses once idle (I-1)
+ timestamp: 999,
+ task_id: 'done-task',
+ toolSteps: [{ toolName: 'search', displayName: 'Search', state: 'completed' }],
+ attachments: [{ id: 'echo-file', type: 'response_file', label: 'result.txt' }],
+ }
+ const existing: ChatMessage[] = [
+ {
+ id: 'turn-1-assistant',
+ role: 'assistant',
+ content: 'a1',
+ timestamp: 1,
+ serverTurnNumber: 1,
+ },
+ optimisticEcho,
+ {
+ id: 'turn-2-assistant',
+ role: 'assistant',
+ content: 'a2',
+ timestamp: 3,
+ serverTurnNumber: 2,
+ },
+ ]
+
+ const merged = mergeAuthoritativeServerMessages(existing, incoming, {
+ activeTaskIds: new Set(),
+ })
+
+ // The echo collapsed (drop of the local), the authoritative row survives.
+ expect(merged.map(m => m.id)).not.toContain('optimistic-assistant')
+ const outputTurn2Assistant = merged.find(m => m.id === 'turn-2-assistant')
+ expect(outputTurn2Assistant).toBeDefined()
+ // The side metadata the bubble accumulated survives on the authoritative row.
+ expect(outputTurn2Assistant?.toolSteps).toEqual(optimisticEcho.toolSteps)
+ expect(outputTurn2Assistant?.attachments).toEqual(optimisticEcho.attachments)
+ // content is NOT rewritten (loss-safety of text, §6.2).
+ expect(outputTurn2Assistant?.content).toBe('a2')
+ // Non-reintroduction of R1-B1: every numbered server row survives.
+ for (const server of incoming) {
+ if (messageServerTurnNumber(server) !== undefined) {
+ expect(merged.map(m => m.id)).toContain(server.id)
+ }
+ }
+ })
+
+ it('R2-M1: does not collapse a text-less idle bubble on empty-content coincidence', () => {
+ // The collapse gate used strict equality, so '' === '' fired on an
+ // attachment-only bubble sandwiched between two empty-content numbered turns.
+ // §6.2 requires truthy content on both sides: a text-less bubble is not a text
+ // echo and must survive with its attachment. Server rows come from the real
+ // producer (T1).
+ const incoming = turnsToChatMessages([
+ { number: 1, user_input: '', started_at: new Date(1).toISOString() },
+ { number: 2, user_input: '', started_at: new Date(2).toISOString() },
+ ])
+ const attachmentOnly: ChatMessage = {
+ id: 'attachment-only',
+ role: 'user',
+ content: '',
+ timestamp: 999,
+ task_id: 'done-task',
+ attachments: [{ id: 'file-9', type: 'uploaded_file', label: 'photo.png' }],
+ }
+ const existing: ChatMessage[] = [
+ { id: 'turn-1-user', role: 'user', content: '', timestamp: 1, serverTurnNumber: 1 },
+ attachmentOnly,
+ { id: 'turn-2-user', role: 'user', content: '', timestamp: 3, serverTurnNumber: 2 },
+ ]
+
+ const merged = mergeAuthoritativeServerMessages(existing, incoming, {
+ activeTaskIds: new Set(),
+ })
+
+ // The empty bubble is not a text echo: it survives with its attachment.
+ expect(merged.map(m => m.id)).toContain('attachment-only')
+ expect(merged.find(m => m.id === 'attachment-only')?.attachments).toEqual(
+ attachmentOnly.attachments
+ )
+ // Non-reintroduction of R1-B1: both numbered server rows survive.
+ expect(merged.map(m => m.id)).toEqual(expect.arrayContaining(['turn-1-user', 'turn-2-user']))
+ })
+})
diff --git a/desktop-app/src/chatMessageMerge.ts b/desktop-app/src/chatMessageMerge.ts
index 25ff1c963..1a43e811c 100644
--- a/desktop-app/src/chatMessageMerge.ts
+++ b/desktop-app/src/chatMessageMerge.ts
@@ -135,6 +135,13 @@ export function mergeAuthoritativeServerMessages(
const removedIndexes = new Set<number>()
const removedIndexByMessage = new Map<ChatMessage, number>()
const localByServerMessage = new Map<ChatMessage, ChatMessage>()
+ // Side metadata (toolSteps/attachments/tokens via copyLocalMetadata) of a
+ // collapsed idle echo, keyed by the authoritative row it merges onto. Kept
+ // SEPARATE from localByServerMessage: the collapse is not a positional 1↔1
+ // replacement, so it must not drive the local anchor index nor the single-claim
+ // filter — it only contributes metadata to a server row that always survives
+ // (§6.2, R2-M1).
+ const collapsedEchoMetadataByServerMessage = new Map<ChatMessage, ChatMessage>()
const consumedLocalMessages = new Set<ChatMessage>()
const markLocalReplacement = (serverMessage: ChatMessage, localMessage: ChatMessage) => {
@@ -147,16 +154,25 @@ export function mergeAuthoritativeServerMessages(
localByServerMessage.set(serverMessage, localMessage)
}
- // Drop-only sibling of markLocalReplacement: evicts a turnless idle echo from
- // the output WITHOUT associating it to any server row (no localByServerMessage
- // write). No server row changes content or presence, so this can never
- // reintroduce R1-B1 — property #1 still guards every numbered server row (§6.1).
- const dropLocalEcho = (localMessage: ChatMessage) => {
+ // Collapse sibling of markLocalReplacement: evicts a turnless idle echo from the
+ // output WITHOUT registering localByServerMessage (no positional 1↔1 anchoring),
+ // but DOES merge its side metadata (toolSteps/attachments/tokens via
+ // copyLocalMetadata) onto the authoritative row of its slot — the same echoRow
+ // its content matched. The server row never changes content or presence, so this
+ // can never reintroduce R1-B1 (property #1 still guards every numbered server
+ // row, §6.1) and never rewrites content (loss-safety of text, §6.2). It is no
+ // longer pure drop-only: it is drop of the local ∩ merge of its metadata into the
+ // surviving authoritative row, so toolSteps/attachments the optimistic bubble
+ // accumulated are not lost when the reconciled server row lacks them (R2-M1).
+ const dropLocalEcho = (localMessage: ChatMessage, echoRow: ChatMessage) => {
const index = existing.indexOf(localMessage)
if (index < 0 || consumedLocalMessages.has(localMessage)) return
consumedLocalMessages.add(localMessage)
removed.push(localMessage)
removedIndexes.add(index)
+ if (!collapsedEchoMetadataByServerMessage.has(echoRow)) {
+ collapsedEchoMetadataByServerMessage.set(echoRow, localMessage)
+ }
}
for (const serverMessage of authoritative) {
@@ -301,13 +317,19 @@ export function mergeAuthoritativeServerMessages(
}
const nextAuthoritative = authoritativeSlotRow(nextNumbered)
const previousAuthoritative = authoritativeSlotRow(previousNumbered)
- const echoRow =
- nextAuthoritative?.content === message.content
- ? nextAuthoritative
- : previousAuthoritative?.content === message.content
- ? previousAuthoritative
- : undefined
- if (echoRow) dropLocalEcho(message)
+ // Non-empty content gate (§6.2, R2-M1): strict equality would fire the
+ // collapse on '' === '' / undefined === undefined, treating a text-less
+ // bubble (e.g. attachment-only) as an echo. A collapse requires truthy
+ // content on BOTH the local and the authoritative row — an empty bubble is
+ // not a "text echo" and must survive.
+ const matchesAuthoritative = (row: ChatMessage | undefined): boolean =>
+ Boolean(message.content) && row?.content === message.content
+ const echoRow = matchesAuthoritative(nextAuthoritative)
+ ? nextAuthoritative
+ : matchesAuthoritative(previousAuthoritative)
+ ? previousAuthoritative
+ : undefined
+ if (echoRow) dropLocalEcho(message, echoRow)
}
continue
}
@@ -324,8 +346,19 @@ export function mergeAuthoritativeServerMessages(
const hydratedReplacements = authoritative.map(message => {
const local = localByServerMessage.get(message)
+ let hydrated = preferredServerMessage(message, local, { copyLocalMetadata: Boolean(local) })
+ // Merge the side metadata of a collapsed idle echo onto its authoritative slot
+ // row (§6.2, R2-M1). Chained after the positional local so the positional local
+ // keeps precedence for any field it supplies; the collapsed echo fills the rest
+ // (e.g. toolSteps/attachments the reconciled server row lacks). Content is never
+ // rewritten — preferredServerMessage only touches side fields. This does NOT
+ // affect localAnchorIndex: the collapse has no positional anchor of its own.
+ const collapsedEcho = collapsedEchoMetadataByServerMessage.get(message)
+ if (collapsedEcho) {
+ hydrated = preferredServerMessage(hydrated, collapsedEcho, { copyLocalMetadata: true })
+ }
return {
- message: preferredServerMessage(message, local, { copyLocalMetadata: Boolean(local) }),
+ message: hydrated,
localAnchorIndex: local ? removedIndexByMessage.get(local) : undefined,
}
})