Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
8dce6ce
fix(app): decoded daemon streams cancel their connection immediately
retransmit Oct 4, 2026
c05cf5d
refactor(app): one NDJSON line parser for every stream
retransmit Oct 4, 2026
afa0c35
fix(app): agent close tears down open streams; SSH errors keep their …
retransmit Oct 4, 2026
50db547
feat(app): reconnect policy, lifecycle source and session state
retransmit Oct 4, 2026
fc1e97a
test(app): lifecycle source tests that fail on eager attach and misse…
retransmit Oct 4, 2026
efc9bf9
feat(app): stream supervisor with backoff, pause and resume
retransmit Oct 4, 2026
4477bc0
fix(app): supervisor recovers quiet streams and tolerates reentrant c…
retransmit Oct 4, 2026
352ea7f
feat(app): transport factory with host-key mismatch detection
retransmit Oct 4, 2026
2f700ba
feat(app): events hub with debounced list refresh and a session event…
retransmit Oct 4, 2026
dbdcd50
feat(app): docker session with auto-reconnect and lifecycle handling
retransmit Oct 4, 2026
db29db8
fix(app): a stale reconnect attempt never blocks a newer connection
retransmit Oct 4, 2026
531d631
feat(app): connect, disconnect and the events feed go through the ses…
retransmit Oct 4, 2026
81100f6
fix(app): event-driven refresh invalidates through the container
retransmit Oct 4, 2026
53d3356
feat(app): logs and stats survive reconnects and resume from where th…
retransmit Oct 4, 2026
28e1182
fix(app): log and stats streams reopen on the current connection
retransmit Oct 4, 2026
e09430c
fix(app): play and a returning session restart a stopped stream
retransmit Oct 4, 2026
75226d8
fix(app): the logs tail menu's All option works
retransmit Oct 4, 2026
8a09d76
fix(app): the logs screen keeps its buffer when the inspect refetch f…
retransmit Oct 4, 2026
a39d86d
feat(app): a reconnect refreshes lists in place and a new connection …
retransmit Oct 4, 2026
913a0cd
fix(app): play during a one-off log fetch starts following
retransmit Oct 4, 2026
a45bfe0
fix(app): a log resume keeps lines that share the cursor timestamp
retransmit Oct 4, 2026
788ad64
fix(app): streams wait for a new connection and stats skip the unprim…
retransmit Oct 4, 2026
5816a27
test(app): cover the stream reconnect notes and the foreground flag
retransmit Oct 4, 2026
4ade4d3
fix(app): pending refreshes are dropped when the connection is lost
retransmit Oct 4, 2026
daf4e91
feat(app): reconnect banner, old-daemon warning and inline connect er…
retransmit Oct 4, 2026
5971300
fix(app): save and connect returns to the list, which shows the progr…
retransmit Oct 4, 2026
1a7d82c
feat(app): exec sessions end on reconnect and offer a new session
retransmit Oct 4, 2026
d2a8579
fix(app): an ended exec session sends no more resizes and its teardow…
retransmit Oct 4, 2026
3881bc3
fix(app): a connect in flight can be cancelled from its row
retransmit Oct 4, 2026
7a2d900
fix(app): the failed banner stacks its buttons and the reconnecting o…
retransmit Oct 4, 2026
2ab0515
fix(app): a screen closed underneath a pending action is not popped t…
retransmit Oct 4, 2026
82f36c3
fix(app): only the connect that succeeded opens Home
retransmit Oct 4, 2026
25332ba
fix(app): a finished exec session releases its channel and every clos…
retransmit Oct 4, 2026
43391b3
fix(app): cancelling a connect has its own button
retransmit Oct 4, 2026
1c3265c
refactor(app): the connection forms share their save handling
retransmit Oct 4, 2026
52ec6e4
fix(app): a finished action closes its own screen, not whatever is on…
retransmit Oct 4, 2026
b703964
fix(app): a host key pinned during a cancelled connect still reaches …
retransmit Oct 4, 2026
ed2f782
fix(app): a reconnect that does not hold counts against the attempt l…
retransmit Oct 5, 2026
6c7f466
fix(app): a tls stream cancelled before its headers lets go of the co…
retransmit Oct 5, 2026
d642e48
fix(app): leaving Home ends the session
retransmit Oct 5, 2026
c42f5f6
fix(app): the dashboard is not refetched while its tab is hidden
retransmit Oct 5, 2026
665f269
fix(app): returning to the foreground refreshes what is on screen
retransmit Oct 5, 2026
ca9fe9b
fix(app): an ssh stream that gets no headers reports a daemon timeout
retransmit Oct 5, 2026
0f7b817
test(app): whole-app reconnect walk and the remaining stream cases
retransmit Oct 5, 2026
a92fc03
fix(app): a loss found on return to the foreground starts a fresh att…
retransmit Oct 5, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'src/state/theme_provider.dart';
import 'src/theme/app_theme.dart';
import 'src/ui/profiles_screen.dart';
import 'src/ui/widgets/session_banner.dart';

final _navigatorKey = GlobalKey<NavigatorState>();

void main() {
WidgetsFlutterBinding.ensureInitialized();
Expand All @@ -30,6 +33,8 @@ class DockerMobileApp extends ConsumerWidget {
theme: buildAppTheme(lightScheme),
darkTheme: buildAppTheme(darkScheme),
themeMode: settings.mode,
navigatorKey: _navigatorKey,
builder: (context, child) => SessionBannerHost(navigatorKey: _navigatorKey, child: child!),
home: const ProfilesScreen(),
);
},
Expand Down
119 changes: 42 additions & 77 deletions app/lib/src/api/docker_api_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,40 @@ class DockerApiClient {
Stream<List<int>> _postStream(String path, {Map<String, String>? query, Object? body}) =>
_wrapErrors(() => transport.postStream(_p(path), query: query, body: body));

/// Re-raises anything the transport emits as a [DockerError]. Cancelling the
/// returned stream cancels the source at the source's next event (an async*
/// generator suspended at an await cannot be cancelled earlier).
Stream<List<int>> _wrapErrors(Stream<List<int>> Function() open) async* {
/// Re-raises anything the transport emits as a [DockerError]. Built from
/// stream operators, not an async* generator, so cancelling the returned
/// stream cancels the transport stream immediately. A synchronous throw
/// from the transport becomes an error event.
Stream<List<int>> _wrapErrors(Stream<List<int>> Function() open) {
final Stream<List<int>> source;
try {
final source = open();
await for (final chunk in source) {
yield chunk;
}
source = open();
} catch (e, st) {
Error.throwWithStackTrace(DockerError.wrap(e), st);
return Stream<List<int>>.error(DockerError.wrap(e), st);
}
return source.handleError(
(Object e, StackTrace st) => Error.throwWithStackTrace(DockerError.wrap(e), st),
);
}

/// Splits an NDJSON byte stream into parsed values, skipping blank and
/// malformed lines. A trailing line without a newline is still parsed when
/// the stream ends. Cancelling the result cancels [raw] immediately.
static Stream<T> _ndjson<T>(Stream<List<int>> raw, T? Function(String line) parse) => raw
.transform(const Utf8Decoder(allowMalformed: true))
.transform(const LineSplitter())
.expand((line) {
final value = parse(line);
return value == null ? <T>[] : <T>[value];
});

static T? _parseJson<T>(String line, T Function(Map<String, dynamic>) fromJson) {
final t = line.trim();
if (t.isEmpty) return null;
try {
return fromJson(jsonDecode(t) as Map<String, dynamic>);
} catch (_) {
return null; // skip a malformed line
}
}

Expand Down Expand Up @@ -250,34 +273,8 @@ class DockerApiClient {
return (jsonDecode(resp.body) as List).map((e) => ImageHistoryLayer.fromJson(e as Map<String, dynamic>)).toList();
}

Stream<PullEvent> pullImage(String image, {String tag = 'latest'}) async* {
final raw = _postStream('/images/create', query: {'fromImage': image, 'tag': tag});
final buffer = <int>[]; // buffer BYTES so a multi-byte UTF-8 char split across chunks survives
await for (final chunk in raw) {
buffer.addAll(chunk);
var nl = buffer.indexOf(0x0A);
while (nl != -1) {
final ev = _parsePullLine(utf8.decode(buffer.sublist(0, nl), allowMalformed: true));
buffer.removeRange(0, nl + 1);
if (ev != null) yield ev;
nl = buffer.indexOf(0x0A);
}
}
if (buffer.isNotEmpty) {
final ev = _parsePullLine(utf8.decode(buffer, allowMalformed: true));
if (ev != null) yield ev;
}
}

PullEvent? _parsePullLine(String line) {
final t = line.trim();
if (t.isEmpty) return null;
try {
return PullEvent.fromJson(jsonDecode(t) as Map<String, dynamic>);
} catch (_) {
return null; // skip a fragment that isn't a complete JSON object
}
}
Stream<PullEvent> pullImage(String image, {String tag = 'latest'}) =>
_ndjson(_postStream('/images/create', query: {'fromImage': image, 'tag': tag}), (line) => _parseJson(line, PullEvent.fromJson));

Future<void> tagImage(String id, {required String repo, String tag = 'latest'}) async =>
_ensure(await _post('/images/$id/tag', query: {'repo': repo, 'tag': tag}), ok: const {201});
Expand Down Expand Up @@ -425,45 +422,13 @@ class DockerApiClient {
if (includeVolumes) await pruneVolumes();
}

Stream<ContainerStats> streamContainerStats(String id) async* {
final raw = _stream('/containers/$id/stats', query: {'stream': 'true'});
final buffer = <int>[];
await for (final chunk in raw) {
buffer.addAll(chunk);
var nl = buffer.indexOf(0x0A);
while (nl != -1) {
final line = utf8.decode(buffer.sublist(0, nl), allowMalformed: true).trim();
buffer.removeRange(0, nl + 1);
if (line.isNotEmpty) {
try {
yield ContainerStats.fromJson(jsonDecode(line) as Map<String, dynamic>);
} catch (_) {
// skip a malformed/partial line
}
}
nl = buffer.indexOf(0x0A);
}
}
}
Stream<ContainerStats> streamContainerStats(String id) => _ndjson(
_stream('/containers/$id/stats', query: {'stream': 'true'}),
(line) => _parseJson(line, ContainerStats.fromJson),
);

Stream<DockerEvent> streamEvents({String? since}) async* {
final raw = _stream('/events', query: since == null ? null : {'since': since});
final buffer = <int>[];
await for (final chunk in raw) {
buffer.addAll(chunk);
var nl = buffer.indexOf(0x0A);
while (nl != -1) {
final line = utf8.decode(buffer.sublist(0, nl), allowMalformed: true).trim();
buffer.removeRange(0, nl + 1);
if (line.isNotEmpty) {
try {
yield DockerEvent.fromJson(jsonDecode(line) as Map<String, dynamic>);
} catch (_) {
// skip a malformed/partial line
}
}
nl = buffer.indexOf(0x0A);
}
}
}
Stream<DockerEvent> streamEvents({String? since}) => _ndjson(
_stream('/events', query: since == null ? null : {'since': since}),
(line) => _parseJson(line, DockerEvent.fromJson),
);
}
75 changes: 38 additions & 37 deletions app/lib/src/api/stdcopy.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:async';
import 'dart:typed_data';

/// Upper bound on a single stdcopy frame's declared payload length. A header
Expand All @@ -16,46 +17,46 @@ class LogChunk {
/// Decodes Docker's stdcopy multiplexed stream (used for non-TTY containers):
/// repeating `[type, 0,0,0, len(uint32 big-endian), ...payload]` frames.
/// Reassembles frames split across input chunks; never throws on bad input.
Stream<LogChunk> decodeStdcopy(Stream<List<int>> input) async* {
/// Built as a transformer, so cancelling the result cancels [input] at once.
Stream<LogChunk> decodeStdcopy(Stream<List<int>> input) {
var acc = Uint8List(0);
await for (final chunk in input) {
if (chunk.isEmpty) continue;
final merged = Uint8List(acc.length + chunk.length)
..setRange(0, acc.length, acc)
..setRange(acc.length, acc.length + chunk.length, chunk);
acc = merged;
return input.transform(StreamTransformer<List<int>, LogChunk>.fromHandlers(
handleData: (chunk, sink) {
if (chunk.isEmpty) return;
final merged = Uint8List(acc.length + chunk.length)
..setRange(0, acc.length, acc)
..setRange(acc.length, acc.length + chunk.length, chunk);
acc = merged;

var offset = 0;
while (acc.length - offset >= 8) {
final type = acc[offset];
if (type > 2) {
// Malformed/desynced: surface the rest defensively and stop parsing.
yield LogChunk(LogStream.stderr, acc.sublist(offset));
offset = acc.length;
break;
var offset = 0;
while (acc.length - offset >= 8) {
final type = acc[offset];
if (type > 2) {
// Malformed/desynced: surface the rest defensively and stop parsing.
sink.add(LogChunk(LogStream.stderr, acc.sublist(offset)));
offset = acc.length;
break;
}
final len = (acc[offset + 4] << 24) |
(acc[offset + 5] << 16) |
(acc[offset + 6] << 8) |
acc[offset + 7];
if (len > _maxFrameLen) {
// Implausible length => corrupt header; surface the rest and stop.
sink.add(LogChunk(LogStream.stderr, acc.sublist(offset)));
offset = acc.length;
break;
}
if (acc.length - offset - 8 < len) break; // need more bytes
final payload = acc.sublist(offset + 8, offset + 8 + len);
sink.add(LogChunk(type == 2 ? LogStream.stderr : LogStream.stdout, payload));
offset += 8 + len;
}
final len = (acc[offset + 4] << 24) |
(acc[offset + 5] << 16) |
(acc[offset + 6] << 8) |
acc[offset + 7];
if (len > _maxFrameLen) {
// Implausible length => corrupt header; surface the rest and stop.
yield LogChunk(LogStream.stderr, acc.sublist(offset));
offset = acc.length;
break;
}
if (acc.length - offset - 8 < len) break; // need more bytes
final payload = acc.sublist(offset + 8, offset + 8 + len);
yield LogChunk(type == 2 ? LogStream.stderr : LogStream.stdout, payload);
offset += 8 + len;
}
acc = offset == 0 ? acc : acc.sublist(offset);
}
acc = offset == 0 ? acc : acc.sublist(offset);
},
));
}

/// TTY passthrough: TTY containers emit a single un-framed stream.
Stream<LogChunk> decodeRawLog(Stream<List<int>> input) async* {
await for (final chunk in input) {
yield LogChunk(LogStream.stdout, chunk);
}
}
Stream<LogChunk> decodeRawLog(Stream<List<int>> input) =>
input.map((chunk) => LogChunk(LogStream.stdout, chunk));
12 changes: 12 additions & 0 deletions app/lib/src/api/timestamps.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,15 @@ String? rfc3339ToUnixNanos(String ts) {
frac = frac.length > 9 ? frac.substring(0, 9) : frac.padRight(9, '0');
return '$secs.$frac';
}

/// An RFC3339(Nano) timestamp as epoch nanoseconds (fits in 64 bits until
/// the year 2262), keeping all nine fractional digits. Null if unparsable.
int? rfc3339ToEpochNanos(String ts) {
final s = rfc3339ToUnixNanos(ts);
if (s == null) return null;
final dot = s.indexOf('.');
final secs = int.tryParse(s.substring(0, dot));
final nanos = int.tryParse(s.substring(dot + 1));
if (secs == null || nanos == null) return null;
return secs * 1000000000 + nanos;
}
Loading
Loading