Skip to content

The agent that grows with you

fix: publish shared queue changes to attached viewers

Tekniumfb02973f611c
diff --git a/apps/desktop/src/api/canonical-protocol.test.ts b/apps/desktop/src/api/canonical-protocol.test.ts
index 251d16f6abe..6f68eb19460 100644
--- a/apps/desktop/src/api/canonical-protocol.test.ts
+++ b/apps/desktop/src/api/canonical-protocol.test.ts
@@ -42,3 +42,16 @@ test('canonical receipts preserve admission identity and replay restores fenced
protocol.event({ type: 'message.start', session_id: 's', payload: { execution_generation: 4 } })
expect(() => protocol.prepare('approval.respond', { session_id: 's', request_id: 'p', choice: 'once' })).toThrow('stale')
})
+
+test('pending resume and live updates share the existing queue projection', () => {
+ const protocol = new CanonicalDesktopProtocol()
+ const pending = [{ admission_id: 'a', input_id: 'original', text: 'queued text', status: 'queued' }]
+ const resumed = protocol.result('session.resume', {}, { session_id: 's', pending })
+ const event = { type: 'session.info', session_id: 's', payload: { pending } }
+ protocol.event(event)
+ expect(resumed.info.pending_submissions).toEqual([{ ...pending[0], user: 'queued text' }])
+ expect(event.payload).toHaveProperty('pending_submissions', resumed.info.pending_submissions)
+ const cleared = { type: 'session.info', session_id: 's', payload: { pending: [] } }
+ protocol.event(cleared)
+ expect(cleared.payload).toHaveProperty('pending_submissions', [])
+})
diff --git a/apps/desktop/src/api/canonical-protocol.ts b/apps/desktop/src/api/canonical-protocol.ts
index 851cda560b5..4e52ae9ec14 100644
--- a/apps/desktop/src/api/canonical-protocol.ts
+++ b/apps/desktop/src/api/canonical-protocol.ts
@@ -79,6 +79,10 @@ export class CanonicalDesktopProtocol {
if (!payload || !event.session_id) { return }
const sid = event.session_id
+ if (Array.isArray(payload.pending)) {
+ payload.pending_submissions = payload.pending.map(row => ({ ...row, user: row.text }))
+ }
+
if (typeof payload.execution_generation === 'number') {
const current = this.generations.get(sid) ?? -1
@@ -136,7 +140,7 @@ export class CanonicalDesktopProtocol {
return projected
})
- return { ...value, pending_approval: prompts.find((p: any) => p.kind === 'approval'), pending_clarify: prompts.find((p: any) => p.kind === 'clarify'), info: { ...value.info, execution_generation: value.execution_generation, running: value.running } }
+ return { ...value, pending_approval: prompts.find((p: any) => p.kind === 'approval'), pending_clarify: prompts.find((p: any) => p.kind === 'clarify'), info: { ...value.info, stored_session_id: value.stored_session_id, pending_submissions: value.pending_submissions, execution_generation: value.execution_generation, running: value.running } }
}
if (method === 'session.events.since') {
diff --git a/gateway/session_authority.py b/gateway/session_authority.py
index be55474771d..6e3615fe3a6 100644
--- a/gateway/session_authority.py
+++ b/gateway/session_authority.py
@@ -6,7 +6,7 @@ Transport attachment never constructs an agent or takes a turn lease.
from __future__ import annotations
import asyncio
-from dataclasses import dataclass, field
+from dataclasses import asdict, dataclass, field
import uuid
from gateway.session_contract import (
@@ -137,6 +137,18 @@ class SessionAuthority:
text = payload.get('native_text_v1', {}).get('event', {}).get('text', '')
return PendingAdmission(**vars(self._receipt(row)), input_id=row['request_id'], text=text)
+ def _publish_pending(self, ref):
+ live = self.sessions[ref.session_id]
+ with live.event_stream.lock:
+ handle = self._handle(ref)
+ pending = [asdict(self._pending_receipt(row)) for row in
+ list_session_admissions(self.db, session_id=ref.session_id)]
+ live.event_stream.publish(ref.session_id, {
+ 'stored_session_id': ref.session_id, 'pending': pending,
+ 'running': handle.execution_state == 'running',
+ 'execution_generation': handle.execution_generation,
+ }, event_type='session.info')
+
def _schedule(self, ref):
live = self.sessions[ref.session_id]
if live.task is None or live.task.done():
@@ -158,6 +170,7 @@ class SessionAuthority:
request_id=str(payload['native_text_v1']['event']['message_id'] or uuid.uuid4().hex),
payload=payload)
event._gateway_accepted = True
+ self._publish_pending(ref)
self._schedule(ref)
return self._receipt(row)
@@ -201,6 +214,7 @@ class SessionAuthority:
row = admit_session_input(self.db, epoch=self.epoch, principal_id=actor.subject,
session_id=request.ref.session_id, request_id=request.request_id,
payload=dict(request.payload), intent=request.intent)
+ self._publish_pending(request.ref)
self._schedule(request.ref)
return self._receipt(row)
@@ -215,7 +229,9 @@ class SessionAuthority:
async def cancel_queued(self, actor, ref, admission_id):
await self.receipt(actor, ref, admission_id)
- return self._receipt(cancel_session_input(self.db, epoch=self.epoch, admission_id=admission_id))
+ row = cancel_session_input(self.db, epoch=self.epoch, admission_id=admission_id)
+ self._publish_pending(ref)
+ return self._receipt(row)
async def interrupt(self, actor, ref, generation):
self.authorize(actor, ref, 'session:control')
@@ -309,6 +325,7 @@ class SessionAuthority:
'authority_epoch': self.epoch, 'execution_generation': row['generation'],
'admission_id': admission_id}
live.event_stream.publish(ref.session_id, {}, event_type='message.start')
+ self._publish_pending(ref)
try:
response = await execute_admission(self, ref, row)
outcome = 'completed'
@@ -319,6 +336,7 @@ class SessionAuthority:
settled = settle_session_input(self.db, epoch=self.epoch, admission_id=admission_id,
generation=row['generation'], outcome=outcome)
live.controls.snapshot(ref.session_id, None)
+ self._publish_pending(ref)
live.event_stream.publish(ref.session_id, {
'text': response, 'content': response, 'admission_id': admission_id,
'outcome': settled['outcome']})
diff --git a/tests/gateway/fixtures/authority_stream_peer.py b/tests/gateway/fixtures/authority_stream_peer.py
index 9768de318e4..c96d7278d5e 100644
--- a/tests/gateway/fixtures/authority_stream_peer.py
+++ b/tests/gateway/fixtures/authority_stream_peer.py
@@ -210,9 +210,10 @@ async def probe(peer, target):
assert [e['seq'] for e in events] == list(range(snapshot['last_sequence'] + 1, events[-1]['seq'] + 1))
for event in events:
assert event['session_id'] == ref.session_id
- assert event['execution_generation'] == rows[0]['generation']
- assert event['authority_epoch'] == authority.epoch
- assert event['admission_id'] == receipt['admission_id']
+ if event['type'] != 'session.info':
+ assert event['execution_generation'] == rows[0]['generation']
+ assert event['authority_epoch'] == authority.epoch
+ assert event['admission_id'] == receipt['admission_id']
assert event['replay_epoch'] == snapshot['replay_epoch']
assert all(isinstance(e['payload']['text'], str) for e in events if e['type'] == 'message.delta'), 'native segment sentinel leaked as text delta'
tools = [e for e in events if e['type'].startswith('tool.')]
diff --git a/tests/gateway/fixtures/shared_authority_peer.py b/tests/gateway/fixtures/shared_authority_peer.py
index 1dd9c27e3c1..a5e5dd33888 100644
--- a/tests/gateway/fixtures/shared_authority_peer.py
+++ b/tests/gateway/fixtures/shared_authority_peer.py
@@ -197,6 +197,9 @@ async def probe():
assert envelope is not None, 'ACK has no durable native source envelope'
assert envelope['source']['user_id'] == 'fixture-user'
assert envelope['route'] == entry.session_key
+ published = await until(lambda f: f.get('params', {}).get('type') == 'session.info'
+ and any(r.get('input_id') == 'fifo-2' for r in f['params'].get('payload', {}).get('pending', [])))
+ assert any(r['text'] == 'FIFO_SECOND' for r in published['params']['payload']['pending'])
await ws.send(json.dumps({'jsonrpc': '2.0', 'id': 'queue-snapshot',
'method': 'session.resume', 'params': {'session_id': entry.session_id}}))
projected = (await until(lambda f: f.get('id') == 'queue-snapshot'))['result']['pending']
diff --git a/tests/gateway/test_authority_events.py b/tests/gateway/test_authority_events.py
index eade595fade..693387e24d8 100644
--- a/tests/gateway/test_authority_events.py
+++ b/tests/gateway/test_authority_events.py
@@ -41,7 +41,7 @@ async def test_replay_matches_subscription_watermark_or_requires_snapshot(tmp_pa
# Small real rings exercise truncation and cross-session eviction without
# a timing race or a thousand model calls. Execution/storage are real;
# the runner's answer boundary is deliberately deterministic here.
- monkeypatch.setattr(event_replay, '_REPLAY_BUFFER_MAX', 2)
+ monkeypatch.setattr(event_replay, '_REPLAY_BUFFER_MAX', 5)
monkeypatch.setattr(event_replay, '_REPLAY_SESSIONS_MAX', 1)
db = SessionDB(tmp_path / 'replay.db')
async def answer(event):
diff --git a/website/docs/developer-guide/gateway-internals.md b/website/docs/developer-guide/gateway-internals.md
index 63d84f3f149..6a124c46215 100644
--- a/website/docs/developer-guide/gateway-internals.md
+++ b/website/docs/developer-guide/gateway-internals.md
@@ -16,6 +16,11 @@ This includes native messaging inputs and local-client inputs. Snapshots do not
private native routing, source, or authorization envelopes. Submission and receipt
ACKs retain their existing shape. Clients must use `admission_id` for cancellation
and receipt queries rather than assuming it equals the original input ID.
+Queue admission, claim, cancellation and settlement also publish `session.info` to
+attached viewers. Its `pending` rows use the same projection as resume. Settlement
+publishes this state before `message.complete`, retaining the terminal event as the
+last event of that turn. Desktop translates both paths into its existing
+`pending_submissions` queue store.
## Shared authority setup readiness