fix(app): expose refused chat watches without losing readable history

This commit is contained in:
2026-10-21 20:09:36 +01:00
parent e0ec91ed28
commit c970aa5d16
4 changed files with 43 additions and 4 deletions
@@ -35,6 +35,7 @@ class ChatThreadController extends ChangeNotifier {
String? _error;
bool _subscribed = false;
String? _subscriptionError;
bool _disposed = false;
int _generation = 0;
bool _resyncing = false;
@@ -49,6 +50,8 @@ class ChatThreadController extends ChangeNotifier {
/// The server's opaque older-page cursor. Never interpreted, only passed back.
String get cursor => _cursor;
String? get error => _error;
bool get subscribed => _subscribed;
String? get subscriptionError => _subscriptionError;
/// Subscribes this session, then loads its newest history page.
Future<void> load() async {
@@ -93,7 +96,7 @@ class ChatThreadController extends ChangeNotifier {
/// The reconnect/resync repair: settle the held turn, re-attach the session,
/// then replace the conversation with the newest authoritative page. Activity
/// replayed while re-attaching (a running step, a form) is fresh native state
/// replayed while re-attaching (a running step) is fresh native state
/// and survives the replacement. A resync frame also lands here.
Future<void> resync() async {
if (_disposed) return;
@@ -111,6 +114,7 @@ class ChatThreadController extends ChangeNotifier {
Future<void> _resyncOnce() async {
final token = ++_generation;
_loading = true;
// A socket drop removed the frames feeding the turn, so no held turn may
// keep claiming to run until the re-subscribe proves otherwise.
_running = false;
@@ -159,10 +163,12 @@ class ChatThreadController extends ChangeNotifier {
await _repository.subscribe(sessionId);
if (_disposed) return;
_subscribed = true;
} catch (_) {
// The history path remains usable; resync re-attempts the subscribe.
_subscriptionError = null;
} catch (error) {
// History stays usable, but the UI must report that live updates failed.
if (_disposed) return;
_subscribed = false;
_subscriptionError = '$error';
}
}