The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): execution fence reads the owner's top-level authority_epoch stamp (X8, reported by @Xipong)
teknium16207b30e1e80
diff --git a/apps/desktop/src/app/session/hooks/use-message-stream/execution-authority.test.tsx b/apps/desktop/src/app/session/hooks/use-message-stream/execution-authority.test.tsxindex 5f88c01104f..b88527cc096 100644--- a/apps/desktop/src/app/session/hooks/use-message-stream/execution-authority.test.tsx+++ b/apps/desktop/src/app/session/hooks/use-message-stream/execution-authority.test.tsx@@ -8,27 +8,27 @@ afterEach(cleanup)it('rejects stale snapshots and terminal frames across generations and owner epochs', () => {const stream = renderMessageStream('authority-session')- const send = (type: string, execution_epoch: string | undefined, execution_generation: number | undefined, running?: boolean) =>- act(() => stream.handleEvent({ type, session_id: 'authority-session', payload: { execution_epoch, execution_generation, running } }))+ const send = (type: string, authority_epoch: number | undefined, execution_generation: number | undefined, running?: boolean) =>+ act(() => stream.handleEvent({ type, session_id: 'authority-session', authority_epoch, execution_generation, payload: { running } }))- send('message.start', 'owner-a', 9)- send('session.info', 'owner-a', 8, false)+ send('message.start', 1, 9)+ send('session.info', 1, 8, false)expect(stream.state().busy).toBe(true)send('message.complete', undefined, undefined)expect(stream.state().busy).toBe(true)- send('session.info', 'owner-b', 1, true)- send('message.complete', 'owner-a', 10)+ send('session.info', 2, 1, true)+ send('message.complete', 1, 10)expect(stream.state().busy).toBe(true)- send('session.info', 'owner-b', 1, false)+ send('session.info', 2, 1, false)expect(stream.state().busy).toBe(false)- send('session.info', 'owner-b', 1, true)+ send('session.info', 2, 1, true)expect(stream.state().busy).toBe(false)})it('accepts a versioned terminal snapshot before optimistic pre-start grace expires', () => {const stream = renderMessageStream('early-terminal')stream.states.set('early-terminal', { ...stream.state(), busy: true, awaitingResponse: true, turnLive: false, turnStartedAt: Date.now() })- act(() => stream.handleEvent({ type: 'session.info', session_id: 'early-terminal', payload: { execution_epoch: 'owner', execution_generation: 1, execution_state: 'error', running: false } }))+ act(() => stream.handleEvent({ type: 'session.info', session_id: 'early-terminal', authority_epoch: 1, execution_generation: 1, payload: { execution_state: 'error', running: false } }))expect(stream.state().busy).toBe(false)expect(stream.state().awaitingResponse).toBe(false)})diff --git a/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/index.ts b/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/index.tsindex 36bf25a2c73..ae60fa0e8af 100644--- a/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/index.ts+++ b/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/index.ts@@ -176,7 +176,7 @@ export function useGatewayEventHandler(deps: GatewayEventDeps) {const previousAuthority = executionAuthorities.current.get(authorityKey)- if (sessionId && !acceptExecutionEvent(executionAuthorities.current, authorityKey, event.type, payload)) {return}+ if (sessionId && !acceptExecutionEvent(executionAuthorities.current, authorityKey, event.type, event)) {return}const authority = executionAuthorities.current.get(authorityKey)diff --git a/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/session-info.ts b/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/session-info.tsindex b42e9304534..c9cc44faebf 100644--- a/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/session-info.ts+++ b/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/session-info.ts@@ -348,8 +348,8 @@ export function handleSessionInfoEvent(ctx: GatewayEventContext): boolean {const withinPreStartGrace =typeof armedAt === 'number' && Date.now() - armedAt < PRE_TURN_LIVE_SETTLE_GRACE_MS- const authoritative = typeof (payload as Record<string, unknown>)?.execution_epoch === 'string' &&- typeof (payload as Record<string, unknown>)?.execution_generation === 'number'+ // The owner stamps its claimed execution on the event params, not the payload.+ const authoritative = typeof event.authority_epoch === 'number' && typeof event.execution_generation === 'number'if (!authoritative && state.awaitingResponse && !state.sawAssistantPayload && !state.turnLive && withinPreStartGrace) {return statediff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/index.test.tsx b/apps/desktop/src/app/session/hooks/use-prompt-actions/index.test.tsxindex 1d6799ac60f..04d1c202a16 100644--- a/apps/desktop/src/app/session/hooks/use-prompt-actions/index.test.tsx+++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/index.test.tsx@@ -491,12 +491,12 @@ describe('terminal receipt settlement', () => {let pending!: Promise<boolean>act(() => { pending = handle!.submitTextRaw('old retry', { submission_id: 'old-terminal' }) })await waitFor(() => expect(finish).toBeTypeOf('function'))- handle!.handleEvent({ type: 'message.start', session_id: RUNTIME_SESSION_ID, payload: { execution_epoch: 'owner', execution_generation: 2 } })+ handle!.handleEvent({ type: 'message.start', session_id: RUNTIME_SESSION_ID, authority_epoch: 1, execution_generation: 2, payload: {} })await act(async () => { finish({ admission_id: 'old-terminal', status: 'terminal' } as never); expect(await pending).toBe(true) })expect(handle!.state()).toMatchObject({ busy: true, awaitingResponse: true, turnLive: true })expect(handle!.state().messages.filter(m => m.id === 'user-old-terminal')).toEqual([])- handle!.handleEvent({ type: 'message.delta', session_id: RUNTIME_SESSION_ID, payload: { execution_epoch: 'owner', execution_generation: 2, text: 'new answer' } })- handle!.handleEvent({ type: 'message.complete', session_id: RUNTIME_SESSION_ID, payload: { execution_epoch: 'owner', execution_generation: 2, text: 'new answer' } })+ handle!.handleEvent({ type: 'message.delta', session_id: RUNTIME_SESSION_ID, authority_epoch: 1, execution_generation: 2, payload: { text: 'new answer' } })+ handle!.handleEvent({ type: 'message.complete', session_id: RUNTIME_SESSION_ID, authority_epoch: 1, execution_generation: 2, payload: { text: 'new answer' } })expect(handle!.state().busy).toBe(false)expect(handle!.state().messages.at(-1)?.parts).toContainEqual(expect.objectContaining({ text: 'new answer' }))})@@ -505,7 +505,7 @@ describe('terminal receipt settlement', () => {describe('Stop and shared-owner execution', () => {afterEach(cleanup)- it.each([['owner-a', 5], ['owner-b', 1]])('retires Stop only for a newer execution: %s/%s', async (epoch, generation) => {+ it.each([[1, 5], [2, 1]])('retires Stop only for a newer execution: %s/%s', async (epoch, generation) => {const requestGateway = vi.fn(async (method: string, params?: Record<string, unknown>) =>(method === 'prompt.submit' ? { admission_id: params?.submission_id, status: 'started' } : {}) as never)@@ -513,26 +513,26 @@ describe('Stop and shared-owner execution', () => {await actRender(<Harness onReady={h => (handle = h)} rawAdmissionReceipts refreshSessions={async () => undefined} requestGateway={requestGateway} />)await handle!.submitText('first turn')- const send = (type: string, execution_epoch = 'owner-a', execution_generation = 4, extra = {}) =>- handle!.handleEvent({ type, session_id: RUNTIME_SESSION_ID, payload: { execution_epoch, execution_generation, ...extra } })+ const send = (type: string, authority_epoch = 1, execution_generation = 4, extra = {}) =>+ handle!.handleEvent({ type, session_id: RUNTIME_SESSION_ID, authority_epoch, execution_generation, payload: extra })send('message.start')expect(handle!.state().busy).toBe(true)await handle!.cancelRun()expect(requestGateway).toHaveBeenCalledWith('session.interrupt', { session_id: RUNTIME_SESSION_ID })send('message.start')- send('message.delta', 'owner-a', 4, { text: 'stopped tail' })+ send('message.delta', 1, 4, { text: 'stopped tail' })expect(handle!.state()).toMatchObject({ interrupted: true, busy: false })send('message.complete')- send('session.info', 'owner-a', 4, { running: false })+ send('session.info', 1, 4, { running: false })send('message.start', epoch, generation)send('session.info', epoch, generation, { running: true })expect(handle!.state()).toMatchObject({ interrupted: false, busy: true, awaitingResponse: true })send('message.delta', epoch, generation, { text: 'external answer' })- send('message.delta', 'owner-a', 4, { text: 'obsolete tail' })+ send('message.delta', 1, 4, { text: 'obsolete tail' })send('message.interim', epoch, generation)expect(handle!.state().messages.at(-1)?.parts).toContainEqual(expect.objectContaining({ text: 'external answer' }))- send('message.complete', 'owner-a', 4, { text: 'obsolete final' })+ send('message.complete', 1, 4, { text: 'obsolete final' })expect(handle!.state().busy).toBe(true)send('message.complete', epoch, generation, { text: 'external answer' })expect(handle!.state()).toMatchObject({ busy: false, awaitingResponse: false })diff --git a/apps/desktop/src/lib/execution-authority.frames.json b/apps/desktop/src/lib/execution-authority.frames.jsonnew file mode 100644index 00000000000..1a9b7e3f15a--- /dev/null+++ b/apps/desktop/src/lib/execution-authority.frames.json@@ -0,0 +1,277 @@+{+ "_generated_by": "tests/gateway/fixtures/execution_frames_capture.py",+ "epoch1": {+ "authority_epoch": 1,+ "frames": [+ {+ "jsonrpc": "2.0",+ "method": "event",+ "params": {+ "type": "session.info",+ "session_id": "shared",+ "payload": {+ "stored_session_id": "shared",+ "pending": [+ {+ "admission_id": "98fa1799e63d47f5bb880c2a2f23577a",+ "ref": {+ "profile_id": "p",+ "session_id": "shared"+ },+ "sequence": 1,+ "status": "queued",+ "outcome": null,+ "authority_epoch": 1,+ "execution_generation": null,+ "input_id": "epoch1",+ "text": "epoch1"+ }+ ],+ "desktop_protocol": "hermes-gateway-v1",+ "running": false,+ "execution_generation": 0,+ "revision": 0+ },+ "replay_epoch": "79542b8f038a48c99e95fff17bb10feb",+ "seq": 1+ }+ },+ {+ "jsonrpc": "2.0",+ "method": "event",+ "params": {+ "authority_epoch": 1,+ "execution_generation": 1,+ "admission_id": "98fa1799e63d47f5bb880c2a2f23577a",+ "type": "message.start",+ "session_id": "shared",+ "payload": {},+ "replay_epoch": "79542b8f038a48c99e95fff17bb10feb",+ "seq": 2+ }+ },+ {+ "jsonrpc": "2.0",+ "method": "event",+ "params": {+ "authority_epoch": 1,+ "execution_generation": 1,+ "admission_id": "98fa1799e63d47f5bb880c2a2f23577a",+ "type": "session.info",+ "session_id": "shared",+ "payload": {+ "stored_session_id": "shared",+ "pending": [+ {+ "admission_id": "98fa1799e63d47f5bb880c2a2f23577a",+ "ref": {+ "profile_id": "p",+ "session_id": "shared"+ },+ "sequence": 1,+ "status": "started",+ "outcome": null,+ "authority_epoch": 1,+ "execution_generation": 1,+ "input_id": "epoch1",+ "text": "epoch1"+ }+ ],+ "desktop_protocol": "hermes-gateway-v1",+ "running": true,+ "execution_generation": 1,+ "revision": 0+ },+ "replay_epoch": "79542b8f038a48c99e95fff17bb10feb",+ "seq": 3+ }+ },+ {+ "jsonrpc": "2.0",+ "method": "event",+ "params": {+ "authority_epoch": 1,+ "execution_generation": 1,+ "admission_id": "98fa1799e63d47f5bb880c2a2f23577a",+ "type": "session.info",+ "session_id": "shared",+ "payload": {+ "stored_session_id": "shared",+ "pending": [],+ "desktop_protocol": "hermes-gateway-v1",+ "running": false,+ "execution_generation": 1,+ "revision": 1+ },+ "replay_epoch": "79542b8f038a48c99e95fff17bb10feb",+ "seq": 4+ }+ },+ {+ "jsonrpc": "2.0",+ "method": "event",+ "params": {+ "authority_epoch": 1,+ "execution_generation": 1,+ "admission_id": "98fa1799e63d47f5bb880c2a2f23577a",+ "type": "message.complete",+ "session_id": "shared",+ "payload": {+ "text": "answer:epoch1",+ "content": "answer:epoch1",+ "admission_id": "98fa1799e63d47f5bb880c2a2f23577a",+ "outcome": "completed"+ },+ "replay_epoch": "79542b8f038a48c99e95fff17bb10feb",+ "seq": 5+ }+ }+ ]+ },+ "epoch2": {+ "authority_epoch": 2,+ "frames": [+ {+ "jsonrpc": "2.0",+ "method": "event",+ "params": {+ "type": "session.info",+ "session_id": "shared",+ "payload": {+ "stored_session_id": "shared",+ "pending": [+ {+ "admission_id": "cc80b8fbc2954b678b9fa765e2cdd60e",+ "ref": {+ "profile_id": "p",+ "session_id": "shared"+ },+ "sequence": 2,+ "status": "queued",+ "outcome": null,+ "authority_epoch": 2,+ "execution_generation": null,+ "input_id": "epoch2",+ "text": "epoch2"+ }+ ],+ "desktop_protocol": "hermes-gateway-v1",+ "running": false,+ "execution_generation": 1,+ "revision": 1+ },+ "replay_epoch": "a52a19f124b642389b2e3b48b45f2f42",+ "seq": 1+ }+ },+ {+ "jsonrpc": "2.0",+ "method": "event",+ "params": {+ "authority_epoch": 2,+ "execution_generation": 2,+ "admission_id": "cc80b8fbc2954b678b9fa765e2cdd60e",+ "type": "message.start",+ "session_id": "shared",+ "payload": {},+ "replay_epoch": "a52a19f124b642389b2e3b48b45f2f42",+ "seq": 2+ }+ },+ {+ "jsonrpc": "2.0",+ "method": "event",+ "params": {+ "authority_epoch": 2,+ "execution_generation": 2,+ "admission_id": "cc80b8fbc2954b678b9fa765e2cdd60e",+ "type": "session.info",+ "session_id": "shared",+ "payload": {+ "stored_session_id": "shared",+ "pending": [+ {+ "admission_id": "cc80b8fbc2954b678b9fa765e2cdd60e",+ "ref": {+ "profile_id": "p",+ "session_id": "shared"+ },+ "sequence": 2,+ "status": "started",+ "outcome": null,+ "authority_epoch": 2,+ "execution_generation": 2,+ "input_id": "epoch2",+ "text": "epoch2"+ }+ ],+ "desktop_protocol": "hermes-gateway-v1",+ "running": true,+ "execution_generation": 2,+ "revision": 1+ },+ "replay_epoch": "a52a19f124b642389b2e3b48b45f2f42",+ "seq": 3+ }+ },+ {+ "jsonrpc": "2.0",+ "method": "event",+ "params": {+ "authority_epoch": 2,+ "execution_generation": 2,+ "admission_id": "cc80b8fbc2954b678b9fa765e2cdd60e",+ "type": "session.info",+ "session_id": "shared",+ "payload": {+ "stored_session_id": "shared",+ "pending": [],+ "desktop_protocol": "hermes-gateway-v1",+ "running": false,+ "execution_generation": 2,+ "revision": 2+ },+ "replay_epoch": "a52a19f124b642389b2e3b48b45f2f42",+ "seq": 4+ }+ },+ {+ "jsonrpc": "2.0",+ "method": "event",+ "params": {+ "authority_epoch": 2,+ "execution_generation": 2,+ "admission_id": "cc80b8fbc2954b678b9fa765e2cdd60e",+ "type": "message.complete",+ "session_id": "shared",+ "payload": {+ "text": "answer:epoch2",+ "content": "answer:epoch2",+ "admission_id": "cc80b8fbc2954b678b9fa765e2cdd60e",+ "outcome": "completed"+ },+ "replay_epoch": "a52a19f124b642389b2e3b48b45f2f42",+ "seq": 5+ }+ }+ ],+ "idle_mutation_frames": [+ {+ "jsonrpc": "2.0",+ "method": "event",+ "params": {+ "type": "session.updated",+ "session_id": "shared",+ "payload": {+ "session_id": "shared",+ "revision": 3,+ "operation": "rename",+ "title": "Renamed while idle"+ },+ "replay_epoch": "a52a19f124b642389b2e3b48b45f2f42",+ "seq": 6+ }+ }+ ]+ }+}diff --git a/apps/desktop/src/lib/execution-authority.test.ts b/apps/desktop/src/lib/execution-authority.test.tsnew file mode 100644index 00000000000..13736437d68--- /dev/null+++ b/apps/desktop/src/lib/execution-authority.test.ts@@ -0,0 +1,97 @@+import { JsonRpcGatewayClient } from '@hermes/shared'+import type { GatewayEvent } from '@hermes/shared'+import { describe, expect, it } from 'vitest'++import { acceptExecutionEvent } from './execution-authority'+import frames from './execution-authority.frames.json'++/**+ * `execution-authority.frames.json` is captured from the real owner+ * (`tests/gateway/fixtures/execution_frames_capture.py`): two successive+ * authority epochs each running one turn on the same session, then an idle+ * `rename` mutation. Nothing here fabricates a wire shape.+ */+interface ServerFrame {+ params: GatewayEvent & { seq?: number }+}+++const owner1 = (frames as { epoch1: { frames: ServerFrame[] } }).epoch1.frames+const owner2 = (frames as { epoch2: { frames: ServerFrame[]; idle_mutation_frames: ServerFrame[] } }).epoch2++class FakeWebSocket extends EventTarget {+ static OPEN = 1+ readyState = 1+ send(): void {}+ close(): void {}+}++function connectedClient(): { client: JsonRpcGatewayClient; socket: FakeWebSocket; received: GatewayEvent[] } {+ const socket = new FakeWebSocket()++ const client = new JsonRpcGatewayClient({+ socketFactory: () => socket as unknown as WebSocket,+ heartbeatIntervalMs: 0,+ heartbeatDeadlineMs: 0,+ connectTimeoutMs: 1000+ })++ const connecting = client.connect('ws://owner')+ socket.dispatchEvent(new Event('open'))+ void connecting+ const received: GatewayEvent[] = []+ client.onEvent(event => received.push(event))++ return { client, socket, received }+}++function deliver(socket: FakeWebSocket, frame: ServerFrame): void {+ socket.dispatchEvent(new MessageEvent('message', { data: JSON.stringify({ jsonrpc: '2.0', method: 'event', ...frame }) }))+}++function fence(authorities: Map<string, unknown>, event: GatewayEvent): boolean {+ return acceptExecutionEvent(authorities as never, 'session', event.type, event as unknown as Record<string, unknown>)+}++describe('execution authority fence over real owner frames', () => {+ it('installs authority from the first claimed frame and fences a retired epoch', () => {+ const { socket, received } = connectedClient()+ const authorities = new Map()+ const verdicts: Array<[string, boolean]> = []++ const stop = owner1.findIndex(frame => frame.params.type === 'message.complete')+ const retiredCompletion = owner1[stop]+ const owner1Live = owner1.slice(0, stop)+ const owner2Start = owner2.frames.findIndex(frame => frame.params.type === 'message.start')++ // Owner 1 starts a turn; owner 2 (a restarted gateway) takes the session over+ // before owner 1's completion reaches the viewer.+ for (const frame of [...owner1Live, ...owner2.frames.slice(owner2Start)]) { deliver(socket, frame) }+ deliver(socket, retiredCompletion)++ for (const event of received) { verdicts.push([event.type, fence(authorities, event)]) }++ const installed = authorities.get('session') as { epoch: string; generation: number; terminal: boolean; retiredEpochs: Set<string> }+ expect(installed).toBeDefined()+ expect(installed.epoch).toBe(String(owner2.frames[owner2Start].params.authority_epoch))+ expect(installed.generation).toBe(owner2.frames[owner2Start].params.execution_generation)+ expect(installed.retiredEpochs.has(String(owner1[1].params.authority_epoch))).toBe(true)+ // Every frame stamped by the live owners is admitted in order...+ expect(verdicts.slice(0, -1).every(([, ok]) => ok)).toBe(true)+ // ...and the retired owner's late completion is rejected and mutates nothing.+ expect(verdicts.at(-1)).toEqual(['message.complete', false])+ expect(authorities.get('session')).toBe(installed)+ expect(installed.terminal).toBe(true)+ })++ it('admits an idle session.updated after the terminal frame of the same owner', () => {+ const { socket, received } = connectedClient()+ const authorities = new Map()++ for (const frame of [...owner2.frames, ...owner2.idle_mutation_frames]) { deliver(socket, frame) }++ const verdicts = received.map(event => [event.type, fence(authorities, event)])+ expect(verdicts.at(-1)).toEqual(['session.updated', true])+ expect(verdicts.filter(([type]) => type === 'message.complete')).toEqual([['message.complete', true]])+ })+})diff --git a/apps/desktop/src/lib/execution-authority.ts b/apps/desktop/src/lib/execution-authority.tsindex 2120a909ac6..e1e077cdd86 100644--- a/apps/desktop/src/lib/execution-authority.ts+++ b/apps/desktop/src/lib/execution-authority.ts@@ -5,17 +5,31 @@ interface ExecutionAuthority {retiredEpochs: Set<string>}+/**+ * The owner's wire stamp: `SessionEvents.publish` spreads the claimed+ * execution onto the event params, beside `type`/`payload`, never inside the+ * payload. `authority_epoch` is the integer runtime epoch; the fence keys on+ * its string form because epochs are opaque identities, never ordered.+ */+export interface ExecutionStampedEvent {+ authority_epoch?: unknown+ execution_generation?: unknown+ payload?: unknown+}+/** Each transport consumer owns its map; epochs are opaque, never ordered. */export function acceptExecutionEvent(authorities: Map<string, ExecutionAuthority>,key: string,type: string,- payload?: Record<string, unknown>+ event?: ExecutionStampedEvent): boolean {const lifecycle = ['session.info', 'message.start', 'message.complete', 'message.error'].includes(type)const previous = authorities.get(key)- const epoch = payload?.execution_epoch- const generation = payload?.execution_generation+ const payload = event?.payload as Record<string, unknown> | undefined+ const rawEpoch = event?.authority_epoch+ const epoch = typeof rawEpoch === 'number' && Number.isSafeInteger(rawEpoch) ? String(rawEpoch) : rawEpoch+ const generation = event?.execution_generationconst versioned = typeof epoch === 'string' && epoch.length > 0 && typeof generation === 'number' && Number.isSafeInteger(generation) && generation >= 0// Output may follow the current owner, but cannot establish another one.diff --git a/apps/desktop/src/store/gateway.ts b/apps/desktop/src/store/gateway.tsindex e0a98a6813a..31d5f8adc0f 100644--- a/apps/desktop/src/store/gateway.ts+++ b/apps/desktop/src/store/gateway.ts@@ -1320,7 +1320,7 @@ function releaseTerminalTurnLease(scope: string, event: GatewayEvent): void {const key = turnLeaseKey(scope, sessionId)- if (!acceptExecutionEvent(turnExecutionAuthorities, key, event.type, event.payload as Record<string, unknown> | undefined)) {return}+ if (!acceptExecutionEvent(turnExecutionAuthorities, key, event.type, event)) {return}if (event.type === 'message.start' || (event.type === 'session.info' && (event.payload as Record<string, unknown>)?.running === true)) {// The gateway emits settled session.info before immediately chaining adiff --git a/apps/desktop/src/types/hermes.ts b/apps/desktop/src/types/hermes.tsindex 4bd731604da..45549bb7f51 100644--- a/apps/desktop/src/types/hermes.ts+++ b/apps/desktop/src/types/hermes.ts@@ -547,6 +547,10 @@ export interface PaginatedSessions {export interface RpcEvent<T = unknown> {payload?: T+ /** Owner execution stamp on canonical gateways: the integer runtime epoch and+ * the claimed generation, spread onto the params beside `type`/`payload`. */+ authority_epoch?: number+ execution_generation?: numberprofile?: string/** Registry connection whose socket delivered the event (renderer-side tag;* absent for the local/legacy primary path). */diff --git a/apps/shared/src/json-rpc-gateway.ts b/apps/shared/src/json-rpc-gateway.tsindex 6eed34c81a8..21dc9559521 100644--- a/apps/shared/src/json-rpc-gateway.ts+++ b/apps/shared/src/json-rpc-gateway.ts@@ -30,6 +30,10 @@ export type GatewayEventName =export interface GatewayEvent<P = unknown> {payload?: P+ /** Owner execution stamp on canonical gateways: the integer runtime epoch and+ * the claimed generation, spread onto the params beside `type`/`payload`. */+ authority_epoch?: number+ execution_generation?: number/** Renderer-side source tag added by the Desktop gateway registry. */profile?: string/** Registry connection whose socket delivered the event (renderer-side tag;diff --git a/tests/gateway/fixtures/execution_frames_capture.py b/tests/gateway/fixtures/execution_frames_capture.pynew file mode 100644index 00000000000..7dfccb96bac--- /dev/null+++ b/tests/gateway/fixtures/execution_frames_capture.py@@ -0,0 +1,86 @@+"""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+fixture ``apps/desktop/src/lib/execution-authority.frames.json`` is this+module's output; regenerate it with::++ PYTHONPATH=. .venv/bin/python tests/gateway/fixtures/execution_frames_capture.py \+ apps/desktop/src/lib/execution-authority.frames.json+"""+import asyncio+import json+import os+import queue+import sys+import tempfile+from pathlib import Path+from types import SimpleNamespace+++class Peer:+ def __init__(self):+ self.frames = queue.Queue()++ def write(self, frame):+ self.frames.put(frame)+ return True++ def drain(self, until):+ """Fanout writes land from a writer thread; collect through the terminal *until* type."""+ out = []+ while not out or out[-1]['params']['type'] != until:+ out.append(self.frames.get(timeout=5))+ return out+++async def capture(tmp):+ from gateway.config import GatewayConfig, Platform+ from gateway.session import SessionSource, SessionStore+ from gateway.session_authority import LiveSession, initialize_session_authority+ from gateway.session_contract import SessionRef, Submission+ from gateway.session_controls import AuthorityConnection++ store = SessionStore(tmp / 'sessions', GatewayConfig())+ db = store._db++ async def answer(event):+ return 'answer:' + event.text++ ref = SessionRef('p', 'shared')+ source = SessionSource(platform=Platform.TELEGRAM, chat_id='c')+ db.create_session('shared', source='telegram')+ owners = {}+ try:+ for label, instance in (('epoch1', 'owner-1'), ('epoch2', 'owner-2')):+ runner = SimpleNamespace(_session_db=db, session_store=store, _draining=False,+ _handle_message=answer, _adapter_for_source=lambda s: None)+ authority = await initialize_session_authority(runner, profile_id='p', instance_id=instance)+ authority.sessions['shared'] = LiveSession(source, 'shared')+ peer = Peer()+ conn = AuthorityConnection(authority, peer, {'user_id': 'viewer'})+ await conn.resume(ref, {})+ await authority.submit(conn.actor, Submission(label, ref, {'text': label}, 'queue'))+ await authority.sessions['shared'].task+ owners[label] = {'authority_epoch': authority.epoch, 'frames': peer.drain('message.complete')}+ if label == 'epoch2':+ revision = db.get_session('shared')['runtime_revision']+ response = await conn.dispatch({'id': 1, 'method': 'session.mutate', 'params': {+ 'session_id': 'shared', 'request_id': 'rename', 'expected_revision': revision,+ 'operation': 'rename', 'payload': {'title': 'Renamed while idle'}}})+ assert 'result' in response, response+ owners[label]['idle_mutation_frames'] = peer.drain('session.updated')+ await conn.close()+ finally:+ store.close_all_db_handles()+ return {'_generated_by': 'tests/gateway/fixtures/execution_frames_capture.py', **owners}+++def main():+ tmp = Path(tempfile.mkdtemp())+ os.environ['HERMES_HOME'] = str(tmp)+ Path(sys.argv[1]).write_text(json.dumps(asyncio.run(capture(tmp)), indent=1) + '\n')+++if __name__ == '__main__':+ main()