fix(app): expose refused chat watches without losing readable history
This commit is contained in:
+1
-1
@@ -41,7 +41,7 @@ or scratch servers only, never real operator sessions/runs/workflows.
|
||||
| Artifact actions | Source safe URL resolution | separate external-open/copy/download; SHARE REAL NAMED MIME FILES, not links; slow activation/cancel/errors |
|
||||
| Session audit/export repair facts | Missing UI | session.html read-only open, partial/missing/skipped/repair choices without fabricating complete evidence |
|
||||
| Chat session management | Source | normal Chat destination, directory groups/history/search, shared rename/star/close/reopen/create, local hide/undo/seen state |
|
||||
| Chat history/live transport | Source pure fold; active controller72 | authoritative reconnect, opaque older-page cursor, one-turn grouping and stable session navigation |
|
||||
| Chat history/live transport | Source controller72 + pure fold | integrate authoritative reconnect/paging/live-failure status and stable session navigation |
|
||||
| Chat message surfaces | Active native body70 | integrate thread, markdown (safe links/headings/lists/tables/fences), exact attachments and unknown-part retention |
|
||||
| Chat activity/reasoning/tools | Source raw fields only | one activity line, compaction, native reasoning/tools overlays, lifecycle/input/output/error/duration/edit diff |
|
||||
| Chat composer | Missing | per-chat persisted drafts, Enter newline/Ctrl-Cmd+Enter send, Send beside Stop, optimistic identity, queued/refused restore |
|
||||
|
||||
@@ -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';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
# C2 — Chat thread controller
|
||||
|
||||
Manager integration follow-up: exposes subscribed/subscriptionError separately
|
||||
from history errors, so readable stored history cannot hide a refused live watch.
|
||||
Resync marks history loading while retaining the current transcript. A focused
|
||||
regression covers refused subscribe + successful history, then successful resync.
|
||||
The controller does not claim to fold form events; those are a separate UI slice.
|
||||
|
||||
`lib/features/chat/conversation/chat_thread_controller.dart` owns one open
|
||||
conversation without any UI. It is constructed with the shared `ApiGateway` and
|
||||
one `sessionId`, reuses `ChatRepository` for the wire and
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_thread_controller.dart';
|
||||
|
||||
import 'chat_thread_fixtures.dart';
|
||||
|
||||
void main() {
|
||||
test('readable history never hides a refused live subscription', () async {
|
||||
final gateway = FakeChatGateway();
|
||||
gateway.subscribe = () async {
|
||||
throw StateError('live watch denied');
|
||||
};
|
||||
gateway.history = (_) async =>
|
||||
chatPage([chatMessage('stored', 'assistant')]);
|
||||
addTearDown(gateway.close);
|
||||
final controller = ChatThreadController(gateway, 's');
|
||||
addTearDown(controller.dispose);
|
||||
await controller.load();
|
||||
expect(controller.messages.single['id'], 'stored');
|
||||
expect(controller.error, isNull);
|
||||
expect(controller.subscribed, isFalse);
|
||||
expect(controller.subscriptionError, contains('live watch denied'));
|
||||
gateway.subscribe = () async => {};
|
||||
await controller.resync();
|
||||
expect(controller.subscribed, isTrue);
|
||||
expect(controller.subscriptionError, isNull);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user