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.

Make terminal batching regression independent of host load

Dee9c9810a8aa64
diff --git a/desktop/lib/terminal/terminal_session.dart b/desktop/lib/terminal/terminal_session.dart
index 834a6d052..55ac0c626 100644
--- a/desktop/lib/terminal/terminal_session.dart
+++ b/desktop/lib/terminal/terminal_session.dart
@@ -80,6 +80,10 @@ class TerminalSession extends ChangeNotifier {
final TerminalBinarySender sendBinary;
final Duration resyncTimeout;
+ /// Lets input batching tests hold the clock inside the four-millisecond window under host load.
+ @visibleForTesting
+ DateTime Function() inputClockForTest = DateTime.now;
+
/// Forces a fresh transport dial (see `WsConn.forceReconnect`) — called once when the very first
/// `terminal_open` never gets a `terminal_ready` back within [resyncTimeout]. Covers the relay
/// going stale silently (the relayed machine's own Harness process restarted, dropping its E2EE
@@ -1028,7 +1032,7 @@ class TerminalSession extends ChangeNotifier {
final last = _lastInputFlushAt;
final idle =
last == null ||
- DateTime.now().difference(last) >= _inputCoalesceWindow;
+ inputClockForTest().difference(last) >= _inputCoalesceWindow;
if (_inputTimer == null && idle) {
unawaited(_flushInput());
} else {
@@ -1049,7 +1053,7 @@ class TerminalSession extends ChangeNotifier {
}
final bytes = List<int>.from(_inputBytes);
_inputBytes.clear();
- _lastInputFlushAt = DateTime.now();
+ _lastInputFlushAt = inputClockForTest();
final currentStreamId = streamId;
if (currentStreamId == null) return;
final generation = _generation;
diff --git a/desktop/test/terminal_session_test.dart b/desktop/test/terminal_session_test.dart
index d0c937fed..907e11142 100644
--- a/desktop/test/terminal_session_test.dart
+++ b/desktop/test/terminal_session_test.dart
@@ -281,6 +281,9 @@ void main() {
test(
'terminal input batches, preserves Enter boundary and is never retried',
() async {
+ // Real sleeps can overshoot the 4 ms window on a busy test host. Hold the input clock
+ // inside it while exercising the real send queue and trailing timer.
+ session.inputClockForTest = () => DateTime.utc(2026, 9, 17);
await ready();
await session.handleBinary(
output(0, utf8.encode(r'prompt> '), keyframe: true, cols: 80, rows: 24),