Skip to content

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.

Merge batch 11-03 bo: #2711 (#2720)

0xken151d3ad2cca304
diff --git a/desktop/lib/super_tabs/controller.dart b/desktop/lib/super_tabs/controller.dart
index e6dd0e546..6d398ae8b 100644
--- a/desktop/lib/super_tabs/controller.dart
+++ b/desktop/lib/super_tabs/controller.dart
@@ -864,9 +864,10 @@ class SuperTabController extends ChangeNotifier {
/// A thread restored open, whose replies its first read of the Swarm brings.
bool _reopenThread = false;
- /// A thread restored open whose pane has not been on screen: the read mark
- /// is the account's on every device, and this controller may be open with
- /// nothing shown, so nothing counts as read until [threadPaneShown].
+ /// The open thread's pane is not on screen: restored open and not yet seen,
+ /// or hidden since ([threadPaneHidden]). The read mark is the account's on
+ /// every device, and this controller keeps reading with nothing shown, so
+ /// nothing counts as read until [threadPaneShown].
bool _threadUnshown = false;
/// The pane of the open thread is on screen.
@@ -876,6 +877,10 @@ class SuperTabController extends ChangeNotifier {
if (openedThread case final open?) _seeThread(open.root);
}
+ /// The pane of the open thread left the screen: the app went to the
+ /// background, another Swarm came to the front, or something covers it.
+ void threadPaneHidden() => _threadUnshown = true;
+
final _attachments = <String, HarnessAttachments>{};
/// The files waiting to go with the next reply of each thread, by its
diff --git a/desktop/lib/super_tabs/view.dart b/desktop/lib/super_tabs/view.dart
index 680a18fe0..6714cdf32 100644
--- a/desktop/lib/super_tabs/view.dart
+++ b/desktop/lib/super_tabs/view.dart
@@ -287,7 +287,12 @@ class _SuperTabViewState extends State<SuperTabView>
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
- if (state == AppLifecycleState.resumed) _readVisibleTailAfterFrame();
+ if (state == AppLifecycleState.resumed) {
+ _readVisibleTailAfterFrame();
+ } else {
+ // No frame follows: the poll goes on in the background.
+ _syncThreadPane();
+ }
}
@override
@@ -313,6 +318,7 @@ class _SuperTabViewState extends State<SuperTabView>
if (oldWidget.controller != c) {
_board.dispose();
_board = SuperTabProjectBoard(c);
+ oldWidget.controller.threadPaneHidden();
oldWidget.controller.removeListener(_changed);
if (oldWidget.controller.buddyChatOpener == _openBuddyChat) {
oldWidget.controller.buddyChatOpener = null;
@@ -510,18 +516,30 @@ class _SuperTabViewState extends State<SuperTabView>
final sequence = c.messages(id).lastOrNull?.sequence ?? 0;
WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted && !_jumpingToEnd) _readToEnd(id, sequence);
- // A thread restored open counts as read only once its pane is seen.
- if (mounted &&
- c.openedThread?.conversationId == c.selectedId &&
- _viewIsVisible) {
- c.threadPaneShown();
- }
});
+ _syncThreadPane();
// Widget updates already have a frame in progress. Reuse it so routine
// polling does not request an otherwise unnecessary frame after each build.
WidgetsBinding.instance.ensureVisualUpdate();
}
+ /// Whether the open thread's pane is on screen: beside its conversation's
+ /// chat, in a view a person can see.
+ bool get _threadPaneVisible =>
+ c.openedThread?.conversationId == c.selectedId && _viewIsVisible;
+
+ /// Tells the controller whether the open thread's pane is on screen, by the
+ /// rule the chat reads by: hidden at once, so a poll landing while it is
+ /// away marks no reply read; shown after the frame that draws it, which
+ /// marks through its newest reply.
+ void _syncThreadPane() {
+ if (c.openedThread == null) return;
+ if (!_threadPaneVisible) return c.threadPaneHidden();
+ WidgetsBinding.instance.addPostFrameCallback((_) {
+ if (mounted && _threadPaneVisible) c.threadPaneShown();
+ });
+ }
+
void _readToEnd(String id, int sequence) {
final scroll = _scroll[id];
if (c.selectedId != id ||
@@ -780,6 +798,8 @@ class _SuperTabViewState extends State<SuperTabView>
@override
void dispose() {
_noticesLeave(c);
+ // The controller outlives its view, reading another Swarm's replies.
+ c.threadPaneHidden();
WidgetsBinding.instance.removeObserver(this);
_board.dispose();
_facts.dispose();
@@ -4298,10 +4318,13 @@ class _SuperTabViewState extends State<SuperTabView>
// Every message's files ask this Swarm's controller for fresh links; another
// Swarm or account is another source, so a late answer is dropped.
@override
- Widget build(BuildContext context) => SuperTabFiles(
- fresh: widget.controller.readFileLink,
- child: _swarm(context),
- );
+ Widget build(BuildContext context) {
+ _syncThreadPane();
+ return SuperTabFiles(
+ fresh: widget.controller.readFileLink,
+ child: _swarm(context),
+ );
+ }
Widget _swarm(BuildContext context) => LayoutBuilder(
builder: (context, constraints) {
diff --git a/desktop/test/super_tab_thread_composer_test.dart b/desktop/test/super_tab_thread_composer_test.dart
index dc377d081..0193a9ed8 100644
--- a/desktop/test/super_tab_thread_composer_test.dart
+++ b/desktop/test/super_tab_thread_composer_test.dart
@@ -714,6 +714,44 @@ void main() {
expect(server.threadMarkPosts, isNotEmpty);
});
+ // A thread left open behind another Swarm or an app in the background:
+ // the Swarm is still read, and its replies must stay unread.
+ test(
+ 'a hidden thread pane marks no new reply read until it is shown again',
+ () async {
+ final server = threaded();
+ final c = server.controller();
+ addTearDown(c.dispose);
+ await c.refresh();
+ c.openThread('message-1');
+ await c.loadThread();
+ c.threadPaneShown();
+ await pumpEventQueue();
+ server.threadMarkPosts.clear();
+ c.threadPaneHidden();
+ server.append('A reply while the pane was hidden.');
+ server.messages.last
+ ..['thread'] = 'message-1'
+ ..['replyTo'] = 'message-1'
+ ..['author'] = {
+ 'kind': 'person',
+ 'id': 'member',
+ 'name': '[email protected]',
+ };
+ final reply = server.messages.last['sequence'] as int;
+ await c.refresh();
+ await pumpEventQueue();
+ expect(server.threadMarkPosts, isEmpty);
+ expect(c.threadUnread(c.thread('lead', 'message-1')!), isTrue);
+ c.threadPaneShown();
+ await pumpEventQueue();
+ expect(server.threadMarkPosts, [
+ {'conversationId': 'lead', 'root': 'message-1', 'sequence': reply},
+ ]);
+ expect(c.threadUnread(c.thread('lead', 'message-1')!), isFalse);
+ },
+ );
+
// A Swarm's view can be built while hidden: the canvas stays Offstage on a utility tab, and the app can start in the background.
Map<String, dynamic> savedOpen() => {
'tabId': 'tab',
@@ -796,6 +834,91 @@ void main() {
},
);
+ // A thread opened by hand and seen, then left open while the pane goes
+ // away: the poll goes on bringing replies, and none is marked read.
+ group('a pane seen, then hidden', () {
+ late ConversationServer server;
+ late int reply;
+ Future<SuperTabController> seen(WidgetTester tester) async {
+ await tester.binding.setSurfaceSize(const Size(1400, 900));
+ addTearDown(() => tester.binding.setSurfaceSize(null));
+ server = threaded();
+ final c = shown = server.controller();
+ addTearDown(c.dispose);
+ await c.refresh();
+ c.openThread('message-1');
+ await mountHidden(tester, c, hidden: false);
+ expect(server.threadMarkPosts, isNotEmpty);
+ server.threadMarkPosts.clear();
+ return c;
+ }
+
+ Future<void> replyArrives(
+ WidgetTester tester,
+ SuperTabController c,
+ ) async {
+ server.append('A reply while the pane was hidden.');
+ server.messages.last
+ ..['thread'] = 'message-1'
+ ..['replyTo'] = 'message-1'
+ ..['author'] = {
+ 'kind': 'person',
+ 'id': 'member',
+ 'name': '[email protected]',
+ };
+ reply = server.messages.last['sequence'] as int;
+ await c.refresh();
+ await tester.pump(const Duration(milliseconds: 50));
+ expect(server.threadMarkPosts, isEmpty);
+ }
+
+ List<Map<String, Object>> markedThroughReply() => [
+ {'conversationId': 'lead', 'root': 'message-1', 'sequence': reply},
+ ];
+
+ testThread(
+ 'sent to the background marks no new reply, and marks once it is back',
+ (tester) async {
+ addTearDown(
+ () => tester.binding.handleAppLifecycleStateChanged(
+ AppLifecycleState.resumed,
+ ),
+ );
+ final c = await seen(tester);
+ tester.binding.handleAppLifecycleStateChanged(
+ AppLifecycleState.inactive,
+ );
+ await replyArrives(tester, c);
+ tester.binding.handleAppLifecycleStateChanged(
+ AppLifecycleState.resumed,
+ );
+ await tester.pumpAndSettle();
+ expect(server.threadMarkPosts, markedThroughReply());
+ },
+ );
+
+ testThread(
+ 'put offstage marks no new reply, and marks once it is shown',
+ (tester) async {
+ final c = await seen(tester);
+ await mountHidden(tester, c, hidden: true);
+ await replyArrives(tester, c);
+ await mountHidden(tester, c, hidden: false);
+ expect(server.threadMarkPosts, markedThroughReply());
+ },
+ );
+
+ testThread('let go of, as for another Swarm, marks no new reply', (
+ tester,
+ ) async {
+ final c = await seen(tester);
+ await tester.pumpWidget(const SizedBox());
+ await replyArrives(tester, c);
+ await mountHidden(tester, c, hidden: false);
+ expect(server.threadMarkPosts, markedThroughReply());
+ });
+ });
+
testThread('the real pane says it is shown', (tester) async {
final server = threaded();
await show(
diff --git a/docs/plans/2026-11-03-hidden-thread-pane-read-plan.md b/docs/plans/2026-11-03-hidden-thread-pane-read-plan.md
new file mode 100644
index 000000000..4c451cb37
--- /dev/null
+++ b/docs/plans/2026-11-03-hidden-thread-pane-read-plan.md
@@ -0,0 +1,62 @@
+# A Hidden Thread Pane Marks Nothing Read Implementation Plan
+
+> **How this is worked:** by the project's instructions, task by task, each failing test committed before its code.
+
+**Goal:** A thread left open beside the chat marks its replies read only while its pane is on screen; hidden, it marks nothing until it is shown again, then marks through the newest reply.
+
+**Architecture:** `SuperTabController._seeThread` is already the single gate for the open thread's read mark, and it returns early while `_threadUnshown` is true. Today only a thread restored open sets that flag; nothing sets it when the pane goes off screen, so every poll that brings a reply (`_keepThreads` → `_seeThread`) sends the thread's read mark while the app is in the background or another Swarm is in front. The controller gains `threadPaneHidden()`, which sets the flag. The view tells it by the rule the main chat already reads by (`_viewIsVisible`): hidden at once whenever that turns false, and `threadPaneShown()` after the frame that shows the pane again.
+
+**Tech Stack:** Flutter 3.47.2 (Dart), flutter_test.
+
+**Spec:** Task #2298 (Diego): "Desktop: a thread left open beside the chat marks replies read only while it is on screen".
+
+## Global Constraints
+
+- The PR body starts with: `Requested by [email protected] through Harness.`
+- Desktop tests use a memory store and a fake sign-in; never run a test that signs this Mac out of the real CLI.
+- Swarm code stays out of `cli/src/core`. Temp files only in `mktemp -d` folders.
+- Owned paths: `desktop/lib/super_tabs/controller.dart`, `desktop/lib/super_tabs/view.dart`, `desktop/test`.
+- `_seeThread` stays the single gate for the thread read mark.
+
+## Review Focus
+
+1. A poll landing while the pane is hidden: the flag must be set at the moment the view goes away, not on its next frame, since the poll runs in the controller with no frame in between.
+2. A Swarm switched away: the view is disposed (the workspace builds only the active Swarm), while the controller keeps reading every 15 s. Dispose must hide.
+3. The app sent to the background with the window unchanged: the lifecycle changes without a build of the view. (`app.foreground` is fed by the workspace from the same lifecycle event, so the view's own lifecycle observer covers it.)
+4. Shown again with no new message: the pane must still be marked through its newest reply, once.
+5. A thread opened by hand stays read as before (`openThread` clears the flag); a thread whose conversation is not the selected one has no pane and counts as hidden.
+
+---
+
+### Task 1: The controller marks nothing read for a hidden pane
+
+**Files:**
+- Modify: `desktop/lib/super_tabs/controller.dart:867-877`
+- Test: `desktop/test/super_tab_thread_composer_test.dart` (the group 'a thread that opened again')
+
+**Interfaces:**
+- Produces: `void threadPaneHidden()` on `SuperTabController`: the open thread's pane is off screen; nothing counts as read until `threadPaneShown()`.
+
+- [ ] **Step 1: Write the failing test** 'a hidden thread pane marks no new reply read until it is shown again': open `message-1` by hand, `threadPaneShown()`, clear `server.threadMarkPosts`, `threadPaneHidden()`, append a reply from another member in the thread, `refresh()` → `server.threadMarkPosts` is empty and `threadUnread` is true; `threadPaneShown()` → exactly one mark, at the reply's sequence, and `threadUnread` is false.
+- [ ] **Step 2: Run it and watch it fail** (`threadPaneHidden` is not defined).
+- [ ] **Step 3: Implement `threadPaneHidden()`**, setting `_threadUnshown`; update the field's doc to say it covers a pane hidden since, not only one restored.
+- [ ] **Step 4: Run the test and the thread composer suite**: all pass.
+- [ ] **Step 5: Commit.**
+
+### Task 2: The view says when the pane leaves the screen
+
+**Files:**
+- Modify: `desktop/lib/super_tabs/view.dart` (`didChangeAppLifecycleState`, `didUpdateWidget`, `dispose`, `_readVisibleTailAfterFrame`, `build`)
+- Test: `desktop/test/super_tab_thread_composer_test.dart`
+
+**Interfaces:**
+- Consumes: `threadPaneHidden()`, `threadPaneShown()`.
+
+- [ ] **Step 1: Write the failing widget tests**, in a group 'a pane seen, then hidden', each mounting the real view with the thread open and shown (one mark), clearing the marks, hiding, then appending a reply and refreshing:
+ - 'sent to the background marks no new reply, and marks once it is back': lifecycle → `inactive`; no mark; `resumed` → one mark.
+ - 'put offstage marks no new reply, and marks once it is shown': remount with `hidden: true`; no mark; `hidden: false` → one mark.
+ - 'let go of, as for another Swarm, marks no new reply': unmount the view; no mark; mount it again → one mark.
+- [ ] **Step 2: Run them and watch them fail** (a mark is sent while hidden).
+- [ ] **Step 3: Implement `_syncThreadPane()`** in the view: with a thread open, when the pane is not on screen (`openedThread.conversationId != selectedId` or `!_viewIsVisible`) call `threadPaneHidden()` at once; otherwise call `threadPaneShown()` after the frame, if still visible. Call it from `build`, from `didChangeAppLifecycleState` (every state) and from `_readVisibleTailAfterFrame` in place of its own `threadPaneShown` call. `dispose` and a controller replaced in `didUpdateWidget` call `threadPaneHidden()` on the controller being left.
+- [ ] **Step 4: Run the new tests, the thread composer suite and the Super Tab view suites**: all pass.
+- [ ] **Step 5: Commit.**