Skip to content

The agent that grows with you

test(gateway): pin legacy replay_epoch refusal scope and restart detection

Teknium26d994b62bd3
diff --git a/apps/shared/src/json-rpc-gateway-legacy-replay.test.ts b/apps/shared/src/json-rpc-gateway-legacy-replay.test.ts
index e8d8aa1a8cf..14c950408cd 100644
--- a/apps/shared/src/json-rpc-gateway-legacy-replay.test.ts
+++ b/apps/shared/src/json-rpc-gateway-legacy-replay.test.ts
@@ -128,4 +128,36 @@ describe('reconnect replay against a legacy backend', () => {
})
client.close()
})
+
+ it('detects a backend restart from the answer epoch without sending the process epoch', async () => {
+ const client = makeClient()
+ const first = client.connect('ws://x')
+ const firstSock = FakeWebSocket.instances.at(-1)!
+ firstSock.open()
+ await first
+ firstSock.serverFrame(ready('proc-1'))
+ firstSock.serverFrame({ jsonrpc: '2.0', method: 'event', params: { type: 'message.delta', session_id: 's1', seq: 97 } })
+ expect(client.getSeqWatermarks()).toEqual({ s1: 97 })
+
+ // Reconnect to a restarted serve: no gateway.ready yet, so the client still holds proc-1.
+ client.invalidate('drop')
+ const pending = client.connect('ws://x')
+ const sock = FakeWebSocket.instances.at(-1)!
+ sock.open()
+ await pending
+ await vi.waitFor(() => expect(sock.request('session.events.since')).toBeDefined())
+ const req = sock.request('session.events.since')!
+ expect(req.params).toEqual({ session_id: 's1', last_seen: 97 })
+
+ sock.serverFrame({
+ jsonrpc: '2.0', id: req.id,
+ result: { events: [], latest_seq: 0, truncated: false, count: 0, epoch: 'proc-2', open_requests: [] }
+ })
+
+ // The stale cursor is dropped, so new-process seqs are not swallowed as already seen.
+ await vi.waitFor(() => expect(client.getSeqWatermarks()).toEqual({}))
+ sock.serverFrame({ jsonrpc: '2.0', method: 'event', params: { type: 'message.delta', session_id: 's1', seq: 3 } })
+ expect(client.getSeqWatermarks()).toEqual({ s1: 3 })
+ client.close()
+ })
})
diff --git a/tests/tui_gateway/test_legacy_events_since_replay_epoch.py b/tests/tui_gateway/test_legacy_events_since_replay_epoch.py
index 2131fed54a5..5093833f928 100644
--- a/tests/tui_gateway/test_legacy_events_since_replay_epoch.py
+++ b/tests/tui_gateway/test_legacy_events_since_replay_epoch.py
@@ -46,6 +46,22 @@ def test_legacy_events_since_still_refuses_other_unknown_keys():
assert problem is not None and "bogus" in problem
+def test_legacy_events_since_dispatch_refuses_other_unknown_keys():
+ # Through the production dispatch, not just the model: ``replay_epoch`` is the only new key.
+ from tui_gateway import server
+
+ response = server.handle_request(
+ {
+ "id": "r0",
+ "method": "session.events.since",
+ "params": {"session_id": "s1", "last_seen": 3, "replay_epoch": "proc-1", "bogus": 1},
+ }
+ )
+
+ assert "bogus" in response["error"]["message"], response
+ assert "replay_epoch" not in response["error"]["message"], response
+
+
@pytest.mark.parametrize(
"params",
[