Skip to content

The agent that grows with you

fix(desktop): queue cards in other windows refresh after a paused head is cancelled

Teknium7218b9a94354
diff --git a/apps/desktop/src/lib/execution-authority.frames.json b/apps/desktop/src/lib/execution-authority.frames.json
index cf1580c84dc..76393ef37bb 100644
--- a/apps/desktop/src/lib/execution-authority.frames.json
+++ b/apps/desktop/src/lib/execution-authority.frames.json
@@ -13,7 +13,7 @@
"stored_session_id": "shared",
"pending": [
{
- "admission_id": "ca34f607de944aa89307c78b5e8ad417",
+ "admission_id": "18a08054e76d4b2f983351b834e068d5",
"ref": {
"profile_id": "p",
"session_id": "shared"
@@ -32,7 +32,7 @@
"execution_generation": 0,
"revision": 0
},
- "replay_epoch": "6c1b60170eff42c0a449ad6dea5f865c",
+ "replay_epoch": "8aba8ea3b220447e97d3914a386a3c80",
"seq": 1
}
},
@@ -42,11 +42,11 @@
"params": {
"authority_epoch": 1,
"execution_generation": 1,
- "admission_id": "ca34f607de944aa89307c78b5e8ad417",
+ "admission_id": "18a08054e76d4b2f983351b834e068d5",
"type": "message.start",
"session_id": "shared",
"payload": {},
- "replay_epoch": "6c1b60170eff42c0a449ad6dea5f865c",
+ "replay_epoch": "8aba8ea3b220447e97d3914a386a3c80",
"seq": 2
}
},
@@ -56,14 +56,14 @@
"params": {
"authority_epoch": 1,
"execution_generation": 1,
- "admission_id": "ca34f607de944aa89307c78b5e8ad417",
+ "admission_id": "18a08054e76d4b2f983351b834e068d5",
"type": "session.info",
"session_id": "shared",
"payload": {
"stored_session_id": "shared",
"pending": [
{
- "admission_id": "ca34f607de944aa89307c78b5e8ad417",
+ "admission_id": "18a08054e76d4b2f983351b834e068d5",
"ref": {
"profile_id": "p",
"session_id": "shared"
@@ -82,7 +82,7 @@
"execution_generation": 1,
"revision": 0
},
- "replay_epoch": "6c1b60170eff42c0a449ad6dea5f865c",
+ "replay_epoch": "8aba8ea3b220447e97d3914a386a3c80",
"seq": 3
}
},
@@ -92,17 +92,17 @@
"params": {
"authority_epoch": 1,
"execution_generation": 1,
- "admission_id": "ca34f607de944aa89307c78b5e8ad417",
+ "admission_id": "18a08054e76d4b2f983351b834e068d5",
"type": "message.complete",
"session_id": "shared",
"payload": {
"text": "answer:epoch1",
"content": "answer:epoch1",
- "admission_id": "ca34f607de944aa89307c78b5e8ad417",
+ "admission_id": "18a08054e76d4b2f983351b834e068d5",
"outcome": "completed",
"status": "complete"
},
- "replay_epoch": "6c1b60170eff42c0a449ad6dea5f865c",
+ "replay_epoch": "8aba8ea3b220447e97d3914a386a3c80",
"seq": 4
}
},
@@ -112,7 +112,7 @@
"params": {
"authority_epoch": 1,
"execution_generation": 1,
- "admission_id": "ca34f607de944aa89307c78b5e8ad417",
+ "admission_id": "18a08054e76d4b2f983351b834e068d5",
"type": "session.info",
"session_id": "shared",
"payload": {
@@ -123,7 +123,7 @@
"execution_generation": 1,
"revision": 1
},
- "replay_epoch": "6c1b60170eff42c0a449ad6dea5f865c",
+ "replay_epoch": "8aba8ea3b220447e97d3914a386a3c80",
"seq": 5
}
}
@@ -142,7 +142,7 @@
"stored_session_id": "shared",
"pending": [
{
- "admission_id": "206dc02f7ede4393aa847ac53c805d9f",
+ "admission_id": "a382bc01bdc04a5fb4d65e4c132cb3f4",
"ref": {
"profile_id": "p",
"session_id": "shared"
@@ -161,7 +161,7 @@
"execution_generation": 1,
"revision": 1
},
- "replay_epoch": "2565ef4c47d34fe18f78c74af26e5c7c",
+ "replay_epoch": "4a4cd7cb29f84e46b0b2741ed0bcbb1b",
"seq": 1
}
},
@@ -171,11 +171,11 @@
"params": {
"authority_epoch": 2,
"execution_generation": 2,
- "admission_id": "206dc02f7ede4393aa847ac53c805d9f",
+ "admission_id": "a382bc01bdc04a5fb4d65e4c132cb3f4",
"type": "message.start",
"session_id": "shared",
"payload": {},
- "replay_epoch": "2565ef4c47d34fe18f78c74af26e5c7c",
+ "replay_epoch": "4a4cd7cb29f84e46b0b2741ed0bcbb1b",
"seq": 2
}
},
@@ -185,14 +185,14 @@
"params": {
"authority_epoch": 2,
"execution_generation": 2,
- "admission_id": "206dc02f7ede4393aa847ac53c805d9f",
+ "admission_id": "a382bc01bdc04a5fb4d65e4c132cb3f4",
"type": "session.info",
"session_id": "shared",
"payload": {
"stored_session_id": "shared",
"pending": [
{
- "admission_id": "206dc02f7ede4393aa847ac53c805d9f",
+ "admission_id": "a382bc01bdc04a5fb4d65e4c132cb3f4",
"ref": {
"profile_id": "p",
"session_id": "shared"
@@ -211,7 +211,7 @@
"execution_generation": 2,
"revision": 1
},
- "replay_epoch": "2565ef4c47d34fe18f78c74af26e5c7c",
+ "replay_epoch": "4a4cd7cb29f84e46b0b2741ed0bcbb1b",
"seq": 3
}
},
@@ -221,17 +221,17 @@
"params": {
"authority_epoch": 2,
"execution_generation": 2,
- "admission_id": "206dc02f7ede4393aa847ac53c805d9f",
+ "admission_id": "a382bc01bdc04a5fb4d65e4c132cb3f4",
"type": "message.complete",
"session_id": "shared",
"payload": {
"text": "answer:epoch2",
"content": "answer:epoch2",
- "admission_id": "206dc02f7ede4393aa847ac53c805d9f",
+ "admission_id": "a382bc01bdc04a5fb4d65e4c132cb3f4",
"outcome": "completed",
"status": "complete"
},
- "replay_epoch": "2565ef4c47d34fe18f78c74af26e5c7c",
+ "replay_epoch": "4a4cd7cb29f84e46b0b2741ed0bcbb1b",
"seq": 4
}
},
@@ -241,7 +241,7 @@
"params": {
"authority_epoch": 2,
"execution_generation": 2,
- "admission_id": "206dc02f7ede4393aa847ac53c805d9f",
+ "admission_id": "a382bc01bdc04a5fb4d65e4c132cb3f4",
"type": "session.info",
"session_id": "shared",
"payload": {
@@ -252,7 +252,7 @@
"execution_generation": 2,
"revision": 2
},
- "replay_epoch": "2565ef4c47d34fe18f78c74af26e5c7c",
+ "replay_epoch": "4a4cd7cb29f84e46b0b2741ed0bcbb1b",
"seq": 5
}
}
@@ -270,10 +270,81 @@
"operation": "rename",
"title": "Renamed while idle"
},
- "replay_epoch": "2565ef4c47d34fe18f78c74af26e5c7c",
+ "replay_epoch": "4a4cd7cb29f84e46b0b2741ed0bcbb1b",
"seq": 6
}
}
+ ],
+ "paused_cancel_frames": [
+ {
+ "jsonrpc": "2.0",
+ "method": "event",
+ "params": {
+ "type": "session.info",
+ "session_id": "shared",
+ "payload": {
+ "stored_session_id": "shared",
+ "pending": [
+ {
+ "admission_id": "081b0a8ffa494f5f8eaf1f57993138cf",
+ "ref": {
+ "profile_id": "p",
+ "session_id": "shared"
+ },
+ "sequence": 3,
+ "status": "queued",
+ "outcome": null,
+ "authority_epoch": 2,
+ "execution_generation": null,
+ "input_id": "queued",
+ "text": "queued"
+ }
+ ],
+ "desktop_protocol": "hermes-gateway-v1",
+ "running": false,
+ "execution_generation": 2,
+ "revision": 3
+ },
+ "replay_epoch": "4a4cd7cb29f84e46b0b2741ed0bcbb1b",
+ "seq": 7
+ }
+ },
+ {
+ "jsonrpc": "2.0",
+ "method": "event",
+ "params": {
+ "type": "session.info",
+ "session_id": "shared",
+ "payload": {
+ "stored_session_id": "shared",
+ "pending": [],
+ "desktop_protocol": "hermes-gateway-v1",
+ "running": false,
+ "execution_generation": 2,
+ "revision": 3
+ },
+ "replay_epoch": "4a4cd7cb29f84e46b0b2741ed0bcbb1b",
+ "seq": 8
+ }
+ },
+ {
+ "jsonrpc": "2.0",
+ "method": "event",
+ "params": {
+ "authority_epoch": 2,
+ "admission_id": "081b0a8ffa494f5f8eaf1f57993138cf",
+ "type": "message.complete",
+ "session_id": "shared",
+ "payload": {
+ "text": "",
+ "content": "",
+ "admission_id": "081b0a8ffa494f5f8eaf1f57993138cf",
+ "outcome": "cancelled"
+ },
+ "replay_epoch": "4a4cd7cb29f84e46b0b2741ed0bcbb1b",
+ "seq": 9
+ }
+ }
]
}
}
diff --git a/apps/desktop/src/lib/execution-authority.test.ts b/apps/desktop/src/lib/execution-authority.test.ts
index 13736437d68..08573acd99a 100644
--- a/apps/desktop/src/lib/execution-authority.test.ts
+++ b/apps/desktop/src/lib/execution-authority.test.ts
@@ -17,7 +17,7 @@ interface ServerFrame {
const owner1 = (frames as { epoch1: { frames: ServerFrame[] } }).epoch1.frames
-const owner2 = (frames as { epoch2: { frames: ServerFrame[]; idle_mutation_frames: ServerFrame[] } }).epoch2
+const owner2 = (frames as { epoch2: { frames: ServerFrame[]; idle_mutation_frames: ServerFrame[]; paused_cancel_frames: ServerFrame[] } }).epoch2
class FakeWebSocket extends EventTarget {
static OPEN = 1
@@ -94,4 +94,19 @@ describe('execution authority fence over real owner frames', () => {
expect(verdicts.at(-1)).toEqual(['session.updated', true])
expect(verdicts.filter(([type]) => type === 'message.complete')).toEqual([['message.complete', true]])
})
+
+ it('keeps idle queue snapshots after a stamped turn; a queued cancellation is not a turn completion', () => {
+ const { socket, received } = connectedClient()
+ const authorities = new Map()
+
+ // A viewer that watched owner 1's turn sees owner 2 admit its row (an idle snapshot), run it,
+ // then cancel the head of a paused queue: owner snapshots, then the admission's own frame.
+ for (const frame of [...owner1, ...owner2.frames, ...owner2.paused_cancel_frames]) { deliver(socket, frame) }
+
+ const verdicts = received.map(event => [event.type, fence(authorities, event)])
+ const tail = verdicts.slice(-owner2.paused_cancel_frames.length)
+ expect(verdicts[owner1.length]).toEqual(['session.info', true])
+ expect(tail).toEqual([['session.info', true], ['session.info', true], ['message.complete', false]])
+ expect(authorities.get('session')).toMatchObject({ epoch: '2', generation: 2, terminal: true })
+ })
})
diff --git a/apps/desktop/src/lib/execution-authority.ts b/apps/desktop/src/lib/execution-authority.ts
index ee8a986ee47..008c06f6abe 100644
--- a/apps/desktop/src/lib/execution-authority.ts
+++ b/apps/desktop/src/lib/execution-authority.ts
@@ -12,6 +12,7 @@ interface ExecutionAuthority {
* its string form because epochs are opaque identities, never ordered.
*/
export interface ExecutionStampedEvent {
+ admission_id?: unknown
authority_epoch?: unknown
execution_generation?: unknown
payload?: unknown
@@ -46,6 +47,21 @@ function fencedByPrevious(previous: ExecutionAuthority, type: string, epoch: str
return false
}
+/** An unstamped lifecycle frame: no execution is claimed, so it changes nothing the fence tracks. */
+function acceptUnstampedLifecycle(previous: ExecutionAuthority | undefined, type: string, event?: ExecutionStampedEvent): boolean {
+ // An admission-only frame (a queued row's cancellation: the owner's epoch and the row's
+ // admission, no execution generation) is never a turn's lifecycle, before or after one.
+ if (event?.authority_epoch !== undefined && typeof event.admission_id === 'string') {return false}
+
+ if (!previous) {return true}
+ const payload = event?.payload as Record<string, unknown> | undefined
+ // The owner's idle snapshot (queue, revision) carries the session's last generation in its
+ // payload; only an older owner's is stale.
+ const generation = payload?.execution_generation
+
+ return type === 'session.info' && payload?.running !== true && typeof generation === 'number' && generation >= previous.generation
+}
+
/** Each transport consumer owns its map; epochs are opaque, never ordered. */
export function acceptExecutionEvent(
authorities: Map<string, ExecutionAuthority>,
@@ -64,7 +80,7 @@ export function acceptExecutionEvent(
return !stamp || !previous || (previous.epoch === stamp.epoch && previous.generation === stamp.generation && !previous.terminal)
}
- if (!stamp) {return !previous}
+ if (!stamp) {return acceptUnstampedLifecycle(previous, type, event)}
const { epoch, generation } = stamp
const terminal = type === 'message.complete' || type === 'message.error' || payload?.running === false
diff --git a/tests/gateway/fixtures/execution_frames_capture.py b/tests/gateway/fixtures/execution_frames_capture.py
index 9ec0f34ef20..02c4c763126 100644
--- a/tests/gateway/fixtures/execution_frames_capture.py
+++ b/tests/gateway/fixtures/execution_frames_capture.py
@@ -1,7 +1,8 @@
"""Capture real ``SessionEvents.publish`` frames for the Desktop execution-authority fence tests.
Two successive owners (runtime epochs 1 and 2) each run one turn on the same
-session, then the second owner applies an idle ``rename`` mutation. The Desktop
+session, then the second owner applies an idle ``rename`` mutation and cancels
+the head of a paused queue. The Desktop
fixture ``apps/desktop/src/lib/execution-authority.frames.json`` is this
module's output; regenerate it with::
@@ -72,6 +73,12 @@ async def capture(tmp):
'operation': 'rename', 'payload': {'title': 'Renamed while idle'}}})
assert 'result' in response, response
owners[label]['idle_mutation_frames'] = peer.drain('session.updated')
+ # A paused FIFO (no drain claims its head): the queued row's snapshot and its
+ # cancellation are owner/admission frames, not frames of the finished turn.
+ authority._schedule = lambda _ref: None
+ queued = await authority.submit(conn.actor, Submission('queued', ref, {'text': 'queued'}, 'queue'))
+ await authority.cancel_queued(conn.actor, ref, queued.admission_id)
+ owners[label]['paused_cancel_frames'] = peer.drain('session.info') + peer.drain('message.complete')
await conn.close()
finally:
store.close_all_db_handles()