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:
@@ -53,6 +53,7 @@ class AppSession extends ChangeNotifier {
|
||||
bool _subscribed = false, _disposed = false;
|
||||
bool _everConnected;
|
||||
int _connectionEpoch = 0;
|
||||
int _runsResyncs = 0;
|
||||
RunSubscriptionState _subscription = RunSubscriptionState.pending;
|
||||
String _subscriptionError = '';
|
||||
String? _subscribeRequest;
|
||||
@@ -79,6 +80,11 @@ class AppSession extends ChangeNotifier {
|
||||
/// detail without remounting the screen or losing its selection.
|
||||
int get connectionEpoch => _connectionEpoch;
|
||||
|
||||
/// Advances on every connected transition and whenever the server detached
|
||||
/// this connection's run watch for falling behind (`runs_resync`). The Runs
|
||||
/// screen keys its re-read with this: frames were discarded either way.
|
||||
int get runsEpoch => _connectionEpoch + _runsResyncs;
|
||||
|
||||
/// Connects the shared socket. A missing endpoint is a configuration state,
|
||||
/// so this is a no-op rather than a guessed endpoint.
|
||||
Future<void> start() async {
|
||||
@@ -140,6 +146,13 @@ class AppSession extends ChangeNotifier {
|
||||
|
||||
void _onFrame(JsonMap frame) {
|
||||
if (_disposed) return;
|
||||
if (frame['type'] == 'runs_resync') {
|
||||
// The server dropped this watch because the connection fell behind and
|
||||
// discarded the frames it still held: watch again and re-read the runs.
|
||||
_runsResyncs++;
|
||||
resubscribe();
|
||||
return;
|
||||
}
|
||||
final id = frame['id'];
|
||||
if (id is! String || id != _subscribeRequest) return;
|
||||
switch (frame['type']) {
|
||||
|
||||
Reference in New Issue
Block a user