Chat and runs: tell a slow client to resync instead of dropping it silently; join queued deltas
A chat subscriber whose queue fills is detached and its writer ends the stream with a resync frame (the app re-attaches and re-reads history); a run subscriber gets a final runs_resync and the app subscribes again and re-reads the Runs list and open detail. Consecutive text/reasoning deltas of one part are joined in a chat subscriber's queue; joined numbered frames carry seq_from and delta_lens so the app trims exactly the prefix a history page already holds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -140,6 +140,37 @@ void main() {
|
||||
expect(session.subscriptionError, contains('too many run subscriptions'));
|
||||
});
|
||||
|
||||
test('runs_resync watches again and advances the runs epoch', () async {
|
||||
// The server detached this connection's run watch because it fell behind
|
||||
// and discarded the frames it held; without a new subscribe the Runs
|
||||
// list and detail froze until the next reconnect.
|
||||
final channel = FakeChannel()..readyCompleter.complete();
|
||||
final client = PipelinesClient(channelFactory: (_) => channel);
|
||||
final session = AppSession(
|
||||
endpoint: Uri.parse('ws://example.test/connect'),
|
||||
client: client,
|
||||
);
|
||||
addTearDown(session.dispose);
|
||||
|
||||
await session.start();
|
||||
await flush();
|
||||
final subscribe =
|
||||
jsonDecode(channel.outgoing.single as String) as Map<String, dynamic>;
|
||||
channel.incoming.add(
|
||||
jsonEncode({'id': subscribe['id'], 'type': 'subscribe'}),
|
||||
);
|
||||
await flush();
|
||||
final epoch = session.runsEpoch;
|
||||
final connection = session.connectionEpoch;
|
||||
|
||||
channel.incoming.add(jsonEncode({'type': 'runs_resync'}));
|
||||
await flush();
|
||||
expect(types(channel), ['subscribe', 'subscribe']);
|
||||
expect(session.runsEpoch, greaterThan(epoch));
|
||||
expect(session.connectionEpoch, connection);
|
||||
expect(session.subscription, RunSubscriptionState.pending);
|
||||
});
|
||||
|
||||
test('dispose drops the watch and releases the client', () async {
|
||||
final channel = FakeChannel()..readyCompleter.complete();
|
||||
final client = PipelinesClient(channelFactory: (_) => channel);
|
||||
|
||||
Reference in New Issue
Block a user