Skip to content

The agent that grows with you

fix: reconcile Ink replay receipts with current execution

Teknium8a589010ebea
diff --git a/ui-tui/src/__tests__/receiptBusyRenderer.test.tsx b/ui-tui/src/__tests__/receiptBusyRenderer.test.tsx
index d35883b1281..e6a53edfdb4 100644
--- a/ui-tui/src/__tests__/receiptBusyRenderer.test.tsx
+++ b/ui-tui/src/__tests__/receiptBusyRenderer.test.tsx
@@ -105,9 +105,8 @@ it('reconciles terminal and unknown retries to idle so queued follow-ups can dra
await expect.poll(() => h.submits.length).toBe(2)
h.submits[1]!.resolve(h.receipt(item.submissionId!, status))
await expect.poll(() => h.queue.queueRef.current.length).toBe(0)
- // The unfixed path never requests a snapshot and remains optimistically busy.
- await new Promise(resolve => setTimeout(resolve, 20))
- h.snapshots[0]?.resolve(h.snapshot(false, 1))
+ await expect.poll(() => h.snapshots.length).toBe(1)
+ h.snapshots[0]!.resolve(h.snapshot(false, 1))
await expect.poll(() => getUiState().busy).toBe(false)
expect(getUiState().status).toBe('ready')
h.queue.enqueue('follow-up')
@@ -127,9 +126,9 @@ it('preserves a newer running generation across old receipts and delayed idle sn
if (!delayed) { h.emit('message.start', 2) }
h.submits[0]!.resolve(h.receipt(item.submissionId!, 'terminal'))
await expect.poll(() => h.queue.queueRef.current.length).toBe(0)
- await new Promise(resolve => setTimeout(resolve, 20))
+ await expect.poll(() => h.snapshots.length).toBe(1)
if (delayed) { h.emit('message.start', 2) }
- h.snapshots[0]?.resolve(h.snapshot(!delayed, delayed ? 1 : 2))
+ h.snapshots[0]!.resolve(h.snapshot(!delayed, delayed ? 1 : 2))
await new Promise(resolve => setTimeout(resolve, 20))
expect(getUiState()).toMatchObject({ busy: true, status: 'running…', info: { execution_generation: 2 } })
h.queue.enqueue('must wait')
diff --git a/ui-tui/src/app/submissionCore.ts b/ui-tui/src/app/submissionCore.ts
index 3d3a2063002..864b101c4a7 100644
--- a/ui-tui/src/app/submissionCore.ts
+++ b/ui-tui/src/app/submissionCore.ts
@@ -1,12 +1,12 @@
import type { GatewayClient } from '../gatewayClient.js'
-import type { InputDetectDropResponse, PromptSubmitResponse } from '../gatewayTypes.js'
+import type { InputDetectDropResponse, PromptSubmitResponse, SessionActivateResponse } from '../gatewayTypes.js'
import type { QueueItem } from '../hooks/useQueue.js'
import { savePendingInput } from '../lib/pendingInputs.js'
import type { Msg } from '../types.js'
import { captureDestination, isCurrentDestination, type SubmissionDestination } from './submissionDestination.js'
import { turnController } from './turnController.js'
-import { patchUiState } from './uiStore.js'
+import { getUiState, patchUiState } from './uiStore.js'
const SESSION_BUSY_RE = /session busy|waiting for model response/i
@@ -118,6 +118,38 @@ export function submitPrompt(
item.settle?.(accepted)
+ // A replay receipt ends this admission, not necessarily the current
+ // execution. Refresh the same live attachment without its transcript.
+ if (accepted && focused() && ['terminal', 'unknown'].includes(r.status ?? '')) {
+ const observed = getUiState().info
+
+ void deps.gw.request<SessionActivateResponse>('session.activate', { session_id: sid, omit_messages: true })
+ .then(snapshot => {
+ const current = getUiState().info
+ const info = snapshot.info
+
+ // Push lifecycle events (including same-generation completion)
+ // win over an in-flight snapshot; attachment changes win too.
+ if (!focused() || current !== observed || snapshot.session_id !== sid ||
+ (snapshot.session_key || info?.stored_session_id) !== destination.storedSid ||
+ typeof snapshot.running !== 'boolean' ||
+ (current?.execution_generation !== undefined &&
+ (info?.execution_epoch !== current.execution_epoch ||
+ !Number.isSafeInteger(info?.execution_generation) ||
+ (info?.execution_generation ?? -1) < current.execution_generation))) {
+ return
+ }
+
+ patchUiState({ busy: snapshot.running, status: snapshot.running ? 'running…' : 'ready',
+ info: current && { ...current, execution_epoch: info?.execution_epoch ?? current.execution_epoch,
+ execution_generation: info?.execution_generation ?? current.execution_generation,
+ running: snapshot.running } })
+ })
+ .catch((error: Error) => {
+ if (focused()) { deps.sys(`execution status unconfirmed: ${error.message}`) }
+ })
+ }
+
if (!accepted && focused()) {
deps.sys('admission not confirmed — input retained; use Alt+K to retry with the same identity')
patchUiState({ status: 'admission unconfirmed' })