The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: carry the CAS revision on the pending fanout so post-turn mutations do not conflict
Teknium26cc96eb5476
diff --git a/apps/desktop/src/api/canonical-protocol.test.ts b/apps/desktop/src/api/canonical-protocol.test.tsindex 46b8eb48201..beec6939092 100644--- a/apps/desktop/src/api/canonical-protocol.test.ts+++ b/apps/desktop/src/api/canonical-protocol.test.ts@@ -73,3 +73,10 @@ test('composer branch and model switch become canonical prepared mutations withexpect(protocol.result('slash.exec', model, { session_id: 's', revision: 6, operation: 'model', model: 'switched', provider: 'custom' })).toMatchObject({ type: 'exec', output: expect.stringContaining('switched') })expect(protocol.wire('slash.exec', protocol.prepare('slash.exec', { session_id: 's', command: 'help' }))).toBe('slash.exec')})++test('a session.info fanout after a turn refreshes the CAS revision the next mutation presents', () => {+ const protocol = new CanonicalDesktopProtocol()+ protocol.result('session.resume', { session_id: 's' }, { session_id: 's', revision: 2, execution_generation: 1 })+ protocol.event({ type: 'session.info', session_id: 's', payload: { pending: [], running: false, execution_generation: 2, revision: 5 } })+ expect(protocol.prepare('session.branch', { session_id: 's' })).toMatchObject({ expected_revision: 5, expected_generation: 2 })+})diff --git a/apps/desktop/src/api/canonical-protocol.ts b/apps/desktop/src/api/canonical-protocol.tsindex 5ea66d79182..31b557133b8 100644--- a/apps/desktop/src/api/canonical-protocol.ts+++ b/apps/desktop/src/api/canonical-protocol.ts@@ -142,6 +142,10 @@ export class CanonicalDesktopProtocol {this.generations.set(sid, payload.execution_generation)}+ // Turns advance the CAS revision without a session.updated event; the+ // pending fanout is where a viewer learns the value its next mutation must present.+ if (event.type === 'session.info' && typeof payload.revision === 'number') { this.revisions.set(sid, payload.revision) }+if (typeof payload.prompt_id === 'string') {if (event.type.endsWith('.settled')) { this.prompts.delete(payload.prompt_id);diff --git a/gateway/session_authority.py b/gateway/session_authority.pyindex 18fd385339d..c155902b077 100644--- a/gateway/session_authority.py+++ b/gateway/session_authority.py@@ -149,10 +149,14 @@ class SessionAuthority:handle = self._handle(ref)pending = [asdict(self._pending_receipt(row)) for row inlist_session_admissions(self.db, session_id=ref.session_id)]+ # Turns bump runtime_revision without any session.updated event, so+ # this is the only place a viewer learns the CAS revision a later+ # prepared mutation must present.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,+ 'revision': handle.revision,}, event_type='session.info')def _schedule(self, ref):diff --git a/tests/gateway/test_session_mutation_rpc.py b/tests/gateway/test_session_mutation_rpc.pyindex 9e2265001fc..40f694f6dd6 100644--- a/tests/gateway/test_session_mutation_rpc.py+++ b/tests/gateway/test_session_mutation_rpc.py@@ -4,6 +4,7 @@ from types import SimpleNamespaceimport pytestfrom gateway.session_authority import LiveSession, SessionAuthority+from gateway.session_contract import SessionReffrom gateway.session_controls import AuthorityConnectionfrom hermes_state import SessionDBfrom hermes_state_runtime import begin_runtime_epoch@@ -45,3 +46,20 @@ async def test_mutation_rpc_fences_retries_and_competing_viewers(tmp_path):finally:await owner.close()await viewer.close()+++async def test_pending_fanout_carries_the_revision_a_later_mutation_must_present(tmp_path):+ """A turn bumps runtime_revision; viewers only ever see session.info, so it must carry it."""+ with SessionDB(db_path=tmp_path / 'state.db') as db:+ db.create_session('s', source='test')+ epoch = begin_runtime_epoch(db, instance_id='current')+ runner = SimpleNamespace(_draining=False)+ authority = SessionAuthority(runner, profile_id='owned', instance_id='current', db=db, epoch=epoch)+ live = authority.sessions['s'] = LiveSession(None, 'route')+ published = []+ live.event_stream.publish = lambda sid, payload, *, event_type='message.complete': published.append((event_type, payload))+ db._execute_write(lambda conn: conn.execute("UPDATE sessions SET runtime_revision=runtime_revision+3 WHERE id='s'"))+ authority._publish_pending(SessionRef('owned', 's'))+ assert published and published[-1][0] == 'session.info'+ assert published[-1][1]['revision'] == db.get_session('s')['runtime_revision']