Skip to content

The agent that grows with you

fix(desktop): a stale started snapshot keeps an existing unknown card

Teknium3545d37ac631
diff --git a/apps/desktop/src/store/pending-submissions.test.ts b/apps/desktop/src/store/pending-submissions.test.ts
index ee9b7ccc284..63f2aa70df6 100644
--- a/apps/desktop/src/store/pending-submissions.test.ts
+++ b/apps/desktop/src/store/pending-submissions.test.ts
@@ -131,3 +131,17 @@ it('a delayed older empty snapshot never retires a receipt a newer frame still l
expect(readPendingSubmissions('fenced').q?.status).toBe('retired')
expect(getQueuedPrompts('fenced')).toEqual([])
})
+
+// A replayed or delayed snapshot that still lists an `unknown` admission as `started` is stale for
+// its status, not for its presence: the Discard card the owner's restart produced must stay.
+it('a stale started snapshot keeps an existing unknown card and its Discard control', () => {
+ reconcilePendingSubmissions('lost', [{ admission_id: 'b', status: 'started', user: 'lost' }])
+ reconcilePendingSubmissions('lost', [{ admission_id: 'b', status: 'unknown', user: 'lost' }])
+ reconcilePendingSubmissions('lost', [{ admission_id: 'b', status: 'started', user: 'lost' }])
+ expect(getQueuedPrompts('lost').map(entry => [entry.id, entry.serverStatus])).toEqual([['b', 'unknown']])
+ expect(readPendingSubmissions('lost').b?.status).toBe('unknown')
+
+ // Its real absence from a current snapshot still retires it.
+ reconcilePendingSubmissions('lost', [])
+ expect(getQueuedPrompts('lost')).toEqual([])
+})
diff --git a/apps/desktop/src/store/pending-submissions.ts b/apps/desktop/src/store/pending-submissions.ts
index 81f74895ad0..c04d1ff319c 100644
--- a/apps/desktop/src/store/pending-submissions.ts
+++ b/apps/desktop/src/store/pending-submissions.ts
@@ -96,12 +96,18 @@ function collectReceipts(value: RawReceipts, known: Record<string, PendingSubmis
const admissionByInput = new Map<string, string>()
for (const raw of value) {
- if (!raw || typeof raw.admission_id !== 'string' || !['queued', 'started', 'unknown'].includes(raw.status) ||
- isStale(raw, known)) {
+ if (!raw || typeof raw.admission_id !== 'string' || !['queued', 'started', 'unknown'].includes(raw.status)) {
continue
}
const id = raw.admission_id
+ const stale = isStale(raw, known)
+
+ // A stale status is still a listing: the admission is pending at its stronger observed state
+ // (a replayed `started` keeps an `unknown` card and its Discard). A retired one stays retired.
+ if (stale && known[id]?.status === 'retired') {
+ continue
+ }
if (typeof raw.input_id === 'string') {
admissionByInput.set(raw.input_id, id)
@@ -111,7 +117,7 @@ function collectReceipts(value: RawReceipts, known: Record<string, PendingSubmis
...known[id],
id,
text: typeof raw.user === 'string' ? raw.user : (known[id]?.text ?? ''),
- status: raw.status
+ status: stale ? known[id].status : raw.status
})
}