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.

fix(mobile): the kept screen of an agent read a moment ago is shown, not a blank page

deec7cb3435d615
diff --git a/mobile/lib/terminal/terminal_session.dart b/mobile/lib/terminal/terminal_session.dart
index e3e5703e6..4618f5489 100644
--- a/mobile/lib/terminal/terminal_session.dart
+++ b/mobile/lib/terminal/terminal_session.dart
@@ -439,7 +439,13 @@ class TerminalSession extends ChangeNotifier {
}
cols = _clampCols(initialCols);
rows = _clampRows(initialRows);
- if (!preserveTerminal) terminal = _newTerminal()..resize(cols, rows);
+ // ⚠️ A kept screen ([seedScreen]) is kept through the open, which is the
+ // whole of its job: it is seeded just before the first open, and a fresh
+ // terminal here threw it away in the same breath — the page then drew a
+ // blank terminal where the reader's last screen should have been, with
+ // [hasScreen] telling it not to show the skeleton either.
+ final keep = preserveTerminal || _showingKeptScreen;
+ if (!keep) terminal = _newTerminal()..resize(cols, rows);
status = TerminalSessionStatus.opening;
_openRequestId =
'term_${DateTime.now().microsecondsSinceEpoch}_${Random.secure().nextInt(1 << 31)}';
@@ -456,7 +462,7 @@ class TerminalSession extends ChangeNotifier {
}
cols = _clampCols(measured.cols);
rows = _clampRows(measured.rows);
- if (!preserveTerminal) terminal.resize(cols, rows);
+ if (!keep) terminal.resize(cols, rows);
notifyListeners();
} on TimeoutException {
// Keep the conservative fallback when the terminal viewport cannot be
diff --git a/mobile/test/app_state_terminals_test.dart b/mobile/test/app_state_terminals_test.dart
index cff823d44..e0e01ff3d 100644
--- a/mobile/test/app_state_terminals_test.dart
+++ b/mobile/test/app_state_terminals_test.dart
@@ -17,6 +17,14 @@ void main() {
if (open['agentId'] == agentId) open,
];
+ /// Everything on [session]'s screen, as text.
+ String screenOf(TerminalSession session) {
+ final lines = session.terminal.buffer.lines;
+ return [
+ for (var i = 0; i < lines.length; i++) lines[i].toString().trimRight(),
+ ].join('\n');
+ }
+
/// The pager warming [agentId] on `m`, its parked page measuring itself.
Future<void> warm(ViewerRig rig, String agentId) async {
final warming = rig.app.warmAgentPane('m', agentId);
@@ -316,6 +324,9 @@ void main() {
});
addTearDown(rig.app.dispose);
final session = await openAgent(rig, 'm', 'a');
+ await session.close();
+ await session.reopen();
+ await answerOpen(rig, session, screen: 'last words here');
final streamId = session.streamId;
await rig.app.closePane(rig.app.paneOfAgent('m', 'a')!.id);
@@ -336,10 +347,17 @@ void main() {
final again = rig.app.paneOfAgent('m', 'a')!.session!;
expect(again.showingKeptScreen, isTrue);
expect(again.hasScreen, isTrue);
+ expect(
+ screenOf(again),
+ contains('last words here'),
+ reason: 'the stand-in is what the reader last saw, not a blank page',
+ );
again.reportViewport(80, 24);
await reopening;
- await answerOpen(rig, again);
+ expect(screenOf(again), contains('last words here'));
+ await answerOpen(rig, again, screen: 'fresh');
expect(again.showingKeptScreen, isFalse);
+ expect(screenOf(again), contains('fresh'));
},
);
diff --git a/mobile/test/terminal_session_protocol_test.dart b/mobile/test/terminal_session_protocol_test.dart
index 433019357..415402659 100644
--- a/mobile/test/terminal_session_protocol_test.dart
+++ b/mobile/test/terminal_session_protocol_test.dart
@@ -673,8 +673,13 @@ void main() {
s.seedScreen(first.terminal);
expect(s.showingKeptScreen, isTrue);
expect(s.hasScreen, isTrue);
- await s.open();
+ final opening = s.open(waitForViewportSize: true);
+ expect(_screen(s), contains('last time'), reason: 'through the open');
+ s.reportViewport(100, 30);
+ await opening;
+ expect(_screen(s), contains('last time'));
final streamId = await ready(s);
+ expect(_screen(s), contains('last time'), reason: 'until a screen lands');
await s.handleBinary(_keyframe(streamId, text: 'now'));
expect(s.showingKeptScreen, isFalse);