The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
Desktop: back in a chat left with everything read, keep the New messages line (#2231)
0xken1568d83ddaaf58
diff --git a/desktop/lib/super_tabs/controller.dart b/desktop/lib/super_tabs/controller.dartindex 0b8d42c34..694a28fb3 100644--- a/desktop/lib/super_tabs/controller.dart+++ b/desktop/lib/super_tabs/controller.dart@@ -613,6 +613,35 @@ class SuperTabController extends ChangeNotifier {/// ones read lately.static const _keepLeft = Duration(minutes: 15);+ /// Conversations opened again over messages held from an earlier visit,+ /// until a read of their newest messages lands: the held copy may end+ /// before what arrived meanwhile ([awaitsNewest]).+ final _staleHeld = <String>{};++ /// Whether [id]'s view waits for its newest messages before it places the+ /// New messages line, follows the end or marks anything read: reopened+ /// over a held copy whose read has not landed yet. A read that failed+ /// keeps it waiting while the held copy ends before the conversation's+ /// newest main-stream message; the next poll reads it again.+ bool awaitsNewest(String id) => _staleHeld.contains(id);++ /// A read of [id]'s newest messages landed, or failed: it waits no more,+ /// unless it failed with the held copy short of the newest message.+ /// Whether this ended a wait.+ bool _settleHeld(String id, {required bool read}) {+ if (!read && _heldBehind(id)) return false;+ return _staleHeld.remove(id);+ }++ /// Whether [id]'s held messages end before its newest main-stream message+ /// as the Swarm's state last said it.+ bool _heldBehind(String id) {+ final group = snapshot?.conversation(id);+ final tail = _messages[id]?.lastOrNull?.sequence;+ if (group == null || tail == null) return false;+ return tail < (group.lastMainSequence ?? group.lastMessageSequence);+ }+/// Each conversation's reads under way, newest and older apart: an older/// page asked for during a poll's read is a read of its own.final _reading = <(String, bool), Future<void>>{};@@ -1413,6 +1442,7 @@ class SuperTabController extends ChangeNotifier {_rows.remove(id);_keepRows(id, rows);_messages[id] = page;+ _staleHeld.remove(id);_before[id] = SuperTabPage.of(page.first);if (answer['next'] != null) {_readingBack.add(id);@@ -1530,6 +1560,7 @@ class SuperTabController extends ChangeNotifier {return false;}_messages.remove(id);+ _staleHeld.remove(id);_rows.remove(id);_before.remove(id);_quoted.remove(id);@@ -1653,6 +1684,7 @@ class SuperTabController extends ChangeNotifier {_parts = null;_partsReadAt = null;_messages.clear();+ _staleHeld.clear();_quoted.clear();_quoting.clear();_forgetThreads();@@ -1686,6 +1718,7 @@ class SuperTabController extends ChangeNotifier {snapshot = null;_parts = null;_messages.clear();+ _staleHeld.clear();_forgetNewer();_quoted.clear();_quoting.clear();@@ -2230,6 +2263,12 @@ class SuperTabController extends ChangeNotifier {if (group.closed) closedOpenProjects.add(group.projectId);}_moveView(to: id);+ // Held from an earlier visit: what arrived meanwhile is not among them.+ if (_messages[id]?.isNotEmpty ?? false) {+ _staleHeld.add(id);+ } else {+ _staleHeld.remove(id);+ }openedThread = null;_pruneThreadFiles();_viewVersion++;@@ -2355,6 +2394,7 @@ class SuperTabController extends ChangeNotifier {(id) => !next.projects.any((project) => project.id == id),);_messages.removeWhere((id, _) => !allowed.contains(id));+ _staleHeld.removeWhere((id) => !allowed.contains(id));_quoted.removeWhere((id, _) => !allowed.contains(id));_quoting.removeWhere((id, _) => !allowed.contains(id));_forgetThreads(allowed.contains);@@ -2765,6 +2805,7 @@ class SuperTabController extends ChangeNotifier {snapshot = null;_parts = null;_messages.clear();+ _staleHeld.clear();_forgetNewer();_quoted.clear();_quoting.clear();@@ -2988,6 +3029,7 @@ class SuperTabController extends ChangeNotifier {// An adapting read that found nothing new changes nothing on screen.final same = _policy.adapts && _sameMessages(_messages[id], next);_messages[id] = next;+ final settled = !older && _settleHeld(id, read: true);if (keepPlace) {_newer.add(id);_pagesBelow[id] = (_pagesBelow[id] ?? 0) + 1;@@ -3008,16 +3050,18 @@ class SuperTabController extends ChangeNotifier {}// Something new in the conversation on screen keeps the full poll.if (arrived && id == selectedId) _acted();- if (!same) {+ if (!same || settled) {if (id == selectedId) _viewVersion++;_changed();}} catch (failure) {+ if (!older) _settleHeld(id, read: false);// The state read waits for a machine within the grace: so do these.if (!_inConnectGrace(failure)) _readFailure(failure, revokeTab: false);if (failure is SuperTabFailure &&const {'FORBIDDEN', 'NOT_FOUND'}.contains(failure.code)) {_messages.remove(id);+ _staleHeld.remove(id);_forgetNewer(id);_quoted.remove(id);_quoting.remove(id);diff --git a/desktop/lib/super_tabs/view.dart b/desktop/lib/super_tabs/view.dartindex e3f77c0fc..c5009483a 100644--- a/desktop/lib/super_tabs/view.dart+++ b/desktop/lib/super_tabs/view.dart@@ -342,7 +342,10 @@ class _SuperTabViewState extends State<SuperTabView>_selected = id;setState(() {});final mark = c.readMark(id), shown = _shownMessages(id);- if (_unread.startHistory(+ if (c.awaitsNewest(id)) {+ // Held from an earlier visit: the line is placed, the end followed and+ // anything marked read once the newest messages have landed.+ } else if (_unread.startHistory(id,shown,mark,@@ -445,6 +448,7 @@ class _SuperTabViewState extends State<SuperTabView>void _readToEnd(String id, int sequence) {final scroll = _scroll[id];if (c.selectedId != id ||+ c.awaitsNewest(id) ||_unread.waitsForHistory(id) ||!_chatIsVisible ||scroll == null ||diff --git a/desktop/test/super_tab_new_messages_test.dart b/desktop/test/super_tab_new_messages_test.dartindex 6b5f9df19..f3bfc4ac0 100644--- a/desktop/test/super_tab_new_messages_test.dart+++ b/desktop/test/super_tab_new_messages_test.dart@@ -1,3 +1,5 @@+import 'dart:async';+import 'package:flutter/material.dart';import 'package:flutter/services.dart';import 'package:flutter_test/flutter_test.dart';@@ -220,6 +222,155 @@ void main() {expect(find.byKey(_line), findsOneWidget);});+ // Diego, 10-29: a chat left less than 15 minutes ago keeps its messages,+ // and the view redrew from that stale copy before the newest page landed.+ testWidgets('back in a chat left with everything read, the line sits above '+ 'what arrived meanwhile and nothing new is marked read', (tester) async {+ final server = _server(40)..markReadElsewhere('lead', 40);+ final c = await show(tester, server);+ await c.select('offline');+ await tester.pumpAndSettle();+ for (var i = 41; i <= 80; i++) {+ _fromLead(server, 'Update $i');+ }+ await c.refresh();+ await tester.pumpAndSettle();+ server.readMarkPosts.clear();+ // The newest page is still on its way when the chat is drawn again.+ final hold = server.holdReads = Completer<void>();+ unawaited(c.select('lead'));+ await tester.pump();+ await tester.pump();+ server.holdReads = null;+ hold.complete();+ await tester.pumpAndSettle();+ await tester.pump(const Duration(seconds: 5));+ expect(find.byKey(_line), findsOneWidget);+ expect(+ tester.getTopLeft(find.byKey(_line)).dy,+ greaterThan(tester.getTopLeft(find.text('Update 40')).dy),+ );+ expect(+ tester.getTopLeft(find.byKey(_line)).dy,+ lessThan(tester.getTopLeft(find.text('Update 41')).dy),+ );+ expect(+ server.readMarkPosts.where((p) => (p['sequence'] as int) > 40),+ isEmpty,+ );+ expect(c.readMark('lead'), 40);+ // Read to the end, the chat is read.+ final position = scroll(tester);+ position.jumpTo(position.maxScrollExtent);+ await tester.pumpAndSettle();+ await tester.pump(const Duration(seconds: 5));+ expect(c.readMark('lead'), 80);+ });++ /// Reads [server]'s Lead chat through 40, leaves it, and lets [arrive]+ /// more messages arrive while it is away.+ Future<SuperTabController> leaveRead(+ WidgetTester tester,+ ConversationServer server, {+ int arrive = 40,+ }) async {+ final c = await show(tester, server);+ await c.select('offline');+ await tester.pumpAndSettle();+ for (var i = 41; i <= 40 + arrive; i++) {+ _fromLead(server, 'Update $i');+ }+ await c.refresh();+ await tester.pumpAndSettle();+ server.readMarkPosts.clear();+ return c;+ }++ testWidgets('a read that fails on the way back waits; the next read places '+ 'the line', (tester) async {+ final server = _server(40)..markReadElsewhere('lead', 40);+ final c = await leaveRead(tester, server);+ server.failReads = true;+ await c.select('lead');+ await tester.pumpAndSettle();+ await tester.pump(const Duration(seconds: 5));+ expect(c.awaitsNewest('lead'), isTrue);+ expect(find.byKey(_line), findsNothing);+ server.failReads = false;+ await c.refresh();+ await tester.pumpAndSettle();+ await tester.pump(const Duration(seconds: 5));+ expect(c.awaitsNewest('lead'), isFalse);+ expect(+ tester.getTopLeft(find.byKey(_line)).dy,+ lessThan(tester.getTopLeft(find.text('Update 41')).dy),+ );+ expect(+ server.readMarkPosts.where((p) => (p['sequence'] as int) > 40),+ isEmpty,+ );+ });++ testWidgets('scrolled to the end of the held copy while the newest page is '+ 'on its way, nothing is marked read', (tester) async {+ final server = _server(40)..markReadElsewhere('lead', 30);+ final c = await show(tester, server);+ await c.select('offline');+ await tester.pumpAndSettle();+ for (var i = 41; i <= 80; i++) {+ _fromLead(server, 'Update $i');+ }+ await c.refresh();+ await tester.pumpAndSettle();+ server.readMarkPosts.clear();+ final hold = server.holdReads = Completer<void>();+ unawaited(c.select('lead'));+ await tester.pump();+ final position = scroll(tester);+ position.jumpTo(position.maxScrollExtent);+ await tester.pump();+ await tester.pump();+ expect(server.readMarkPosts, isEmpty);+ server.holdReads = null;+ hold.complete();+ await tester.pumpAndSettle();+ expect(c.readMark('lead'), 30);+ expect(+ tester.getTopLeft(find.byKey(_line)).dy,+ lessThan(tester.getTopLeft(find.text('Update 31')).dy),+ );+ });++ testWidgets('a read that fails over a held copy that is current does not '+ 'wait', (tester) async {+ final server = _server(40)..markReadElsewhere('lead', 40);+ final c = await leaveRead(tester, server, arrive: 0);+ server.failReads = true;+ await c.select('lead');+ await tester.pumpAndSettle();+ expect(c.awaitsNewest('lead'), isFalse);+ expect(find.byKey(_line), findsNothing);+ server.failReads = false;+ });++ testWidgets('access revoked while the newest page is on its way: the held '+ 'copy and the wait go, and the late answer is dropped', (tester) async {+ final server = _server(40)..markReadElsewhere('lead', 40);+ final c = await leaveRead(tester, server);+ final hold = server.holdReads = Completer<void>();+ unawaited(c.select('lead'));+ await tester.pump();+ c.revokeAccess('You no longer have access.');+ server.holdReads = null;+ hold.complete();+ await tester.pumpAndSettle();+ expect(c.awaitsNewest('lead'), isFalse);+ expect(c.messages('lead'), isEmpty);+ expect(find.text('Update 41'), findsNothing);+ expect(find.byKey(_line), findsNothing);+ expect(server.readMarkPosts, isEmpty);+ });+testWidgets('no line when everything is read', (tester) async {final server = _server(10)..markReadElsewhere('lead', 10);await show(tester, server);