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.

Reuse one resource summary per toolbar update (#589)

Dee0bf533da2dbf
diff --git a/desktop/lib/screens/swarm_screen.dart b/desktop/lib/screens/swarm_screen.dart
index 6cb38565b..5c70e71df 100644
--- a/desktop/lib/screens/swarm_screen.dart
+++ b/desktop/lib/screens/swarm_screen.dart
@@ -1762,6 +1762,7 @@ class _SwarmScreenState extends State<SwarmScreen> {
void _syncNative() {
_syncMachines();
+ final monitor = _harnessMonitor.summary;
final focused = WorkspacePaneContext.focused(app);
final prefs = appearancePrefsStore.value.prompt;
final parts = focused?.format(prefs);
@@ -1812,30 +1813,30 @@ class _SwarmScreenState extends State<SwarmScreen> {
'interactive': _shortcutsEnabled,
},
'harnessMonitor': {
- 'text': _harnessMonitor.label,
- 'label': _harnessMonitor.detail,
- 'detail': _harnessMonitor.detail,
+ 'text': monitor.label,
+ 'label': monitor.detail,
+ 'detail': monitor.detail,
'segments': [
- {'text': _harnessMonitor.label},
+ {'text': monitor.label},
],
'interactive': _shortcutsEnabled,
},
'machineResources': {
- 'text': _harnessMonitor.metricsLabel(),
- 'label': _harnessMonitor.resourceDetail,
- 'detail': _harnessMonitor.resourceDetail,
+ 'text': monitor.metricsLabel(),
+ 'label': monitor.resourceDetail,
+ 'detail': monitor.resourceDetail,
'segments': [
- {'text': _harnessMonitor.metricsLabel()},
+ {'text': monitor.metricsLabel()},
],
'noStorageSegments': [
- {'text': _harnessMonitor.metricsLabel(storage: false)},
+ {'text': monitor.metricsLabel(storage: false)},
],
'compactSegments': [
- {'text': _harnessMonitor.metricsLabel(gpu: false, storage: false)},
+ {'text': monitor.metricsLabel(gpu: false, storage: false)},
],
'minimalSegments': [
{
- 'text': _harnessMonitor.metricsLabel(
+ 'text': monitor.metricsLabel(
ram: false,
gpu: false,
storage: false,
@@ -7317,34 +7318,37 @@ class _SwarmScreenState extends State<SwarmScreen> {
constraints: BoxConstraints(maxWidth: monitorWidth),
child: ListenableBuilder(
listenable: _harnessMonitor,
- builder: (context, _) => WorkspaceBarControl(
- key: const ValueKey('workspace-harness-monitor'),
- label: _harnessMonitor.detail,
- tooltip: _harnessMonitor.detail,
- onPressed: _shortcutsEnabled
- ? () => _toggleHarnessControls()
- : null,
- builder: (context, emphasized) => Padding(
- padding: EdgeInsets.symmetric(horizontal: cell.width),
- child: SizedBox(
- height: workspaceBarControlHeight(context),
- child: Center(
- widthFactor: 1,
- child: Text.rich(
- workspaceBarGroupTextSpan(
- _harnessMonitor.label,
- cellWidth: cell.width,
- ),
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
- style: workspaceBarTextStyle(
- emphasized: emphasized,
+ builder: (context, _) {
+ final summary = _harnessMonitor.summary;
+ return WorkspaceBarControl(
+ key: const ValueKey('workspace-harness-monitor'),
+ label: summary.detail,
+ tooltip: summary.detail,
+ onPressed: _shortcutsEnabled
+ ? () => _toggleHarnessControls()
+ : null,
+ builder: (context, emphasized) => Padding(
+ padding: EdgeInsets.symmetric(horizontal: cell.width),
+ child: SizedBox(
+ height: workspaceBarControlHeight(context),
+ child: Center(
+ widthFactor: 1,
+ child: Text.rich(
+ workspaceBarGroupTextSpan(
+ summary.label,
+ cellWidth: cell.width,
+ ),
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: workspaceBarTextStyle(
+ emphasized: emphasized,
+ ),
),
),
),
),
- ),
- ),
+ );
+ },
),
),
SizedBox(width: resourceGap),
diff --git a/desktop/lib/state/harness_monitor.dart b/desktop/lib/state/harness_monitor.dart
index 913b6d211..1b2856b53 100644
--- a/desktop/lib/state/harness_monitor.dart
+++ b/desktop/lib/state/harness_monitor.dart
@@ -12,8 +12,10 @@ import 'harness_sessions.dart';
/// A single, demand-driven sampler shared by the footer and its open panel.
/// It never starts an agent, opens a connection, or scans conversation files.
class HarnessMonitor extends ChangeNotifier {
- HarnessMonitor(this.app);
+ HarnessMonitor(this.app, {DateTime Function()? now})
+ : _now = now ?? DateTime.now;
final AppNotifier app;
+ final DateTime Function() _now;
final _samples = <String, (MachineState, MachineHarnessResources)>{};
Timer? _timer;
bool _started = false, _disposed = false, _busy = false, _expanded = false;
@@ -36,107 +38,46 @@ class HarnessMonitor extends ChangeNotifier {
bool _fresh(String id) =>
_receivedAt[id] != null &&
- DateTime.now().difference(_receivedAt[id]!) <=
- const Duration(seconds: 45);
+ _now().difference(_receivedAt[id]!) <= const Duration(seconds: 45);
/// Shared-server RSS belongs to the server, not to each conversation.
/// Count it once per machine/profile and label it separately in the panel.
- List<HarnessResources> get sharedReadings {
- final rows = live;
- return [
- for (final entry in _samples.entries)
- if (identical(app.stateOf(entry.key), entry.value.$1) &&
- _fresh(entry.key))
- for (final shared in entry.value.$2.shared)
- if (rows.any(
- (row) =>
- row.machineId == entry.key &&
- shared.$1.contains(row.agent.id),
- ))
- shared.$2,
- ];
- }
-
- String? get sharedLabel {
- final rows = sharedReadings;
- if (rows.isEmpty) return null;
- final known = rows.where((r) => r.memoryBytes != null).toList();
- final memory = known.fold<double>(0, (sum, r) => sum + r.memoryBytes!);
- return 'Shared Codex servers · ${formatHarnessMemory(known.isEmpty ? null : memory)}${known.isNotEmpty && known.length < rows.length ? '+' : ''} RAM';
- }
-
- String get label => 'Harnesses ${live.length}';
+ List<HarnessResources> get sharedReadings => _sharedReadings(live);
- /// CPU percentages share a denominator (one core), not host capacities.
- /// Totals include available readings; the tooltip explains partial coverage.
- String metricsLabel({bool ram = true, bool gpu = true, bool storage = true}) {
- final readings = [...live.map(reading), ...sharedReadings];
- String total(
- double? Function(HarnessResources) value,
- String Function(double) format,
- ) {
- final known = readings
- .map((r) => r == null ? null : value(r))
- .whereType<double>()
- .toList();
- if (readings.isEmpty) return format(0);
- if (known.isEmpty) return '—';
- return format(known.fold(0, (a, b) => a + b));
- }
+ List<HarnessResources> _sharedReadings(List<HarnessSession> rows) => [
+ for (final entry in _samples.entries)
+ if (identical(app.stateOf(entry.key), entry.value.$1) &&
+ _fresh(entry.key))
+ for (final shared in entry.value.$2.shared)
+ if (rows.any(
+ (row) =>
+ row.machineId == entry.key && shared.$1.contains(row.agent.id),
+ ))
+ shared.$2,
+ ];
- final cpu = total((r) => r.cpuPercent, (v) => '${v.round()}%');
- final memory = total((r) => r.memoryBytes, _wholeBytes);
- final graphics = total((r) => r.gpuPercent, (v) => '${v.round()}%');
- return 'CPU $cpu'
- '${ram ? '${workspaceBarGroupSeparator}RAM $memory' : ''}'
- '${gpu ? '${workspaceBarGroupSeparator}GPU $graphics' : ''}'
- '${storage ? '${workspaceBarGroupSeparator}SSD ${_storageLabel()}' : ''}';
- }
+ String? get sharedLabel => _sharedMemoryLabel(sharedReadings);
- static String _wholeBytes(double bytes) => bytes >= 1e9
- ? '${(bytes / 1e9).round()} GB'
- : '${(bytes / 1e6).round()} MB';
+ String get label => 'Harnesses ${live.length}';
- String _storageLabel() {
- final folders = <String, Map<String, double?>>{};
- for (final row in live) {
- final resource = reading(row), path = resource?.workspacePath;
- if (path == null || resource?.workspaceBytes == null) {
- continue;
- }
- (folders[row.machineId] ??= {})[path] = resource!.workspaceBytes;
- }
- var bytes = 0.0, count = 0;
- for (final machine in folders.values) {
- final included = <String>[];
- for (final path
- in machine.keys.toList()
- ..sort((a, b) => a.length.compareTo(b.length))) {
- if (included.any(
- (parent) => path == parent || path.startsWith('$parent/'),
- )) {
- continue;
- }
- included.add(path);
- count++;
- bytes += machine[path]!;
- }
- }
- if (live.isNotEmpty && count == 0) return '—';
- return _wholeBytes(bytes);
+ /// Capture once per render/update, then reuse for every width and tooltip.
+ /// This is not retained between updates: changes in scope, liveness or sample
+ /// age are visible immediately without an invalidation cache or another timer.
+ HarnessMonitorSummary get summary {
+ final rows = live;
+ return HarnessMonitorSummary._fromReadings([
+ for (final row in rows) (row.machineId, reading(row)),
+ ], _sharedReadings(rows));
}
- String get resourceDetail =>
- '${live.length} open harnesses across connected machines. Totals cover these harnesses only.\n'
- '${metricsLabel()}\n'
- 'CPU: 100% is one core. RAM includes child processes and shared servers counted once; shared memory pages can overlap.\n'
- 'GPU: harness process GPU use on supported macOS and Linux NVIDIA drivers. First samples and unavailable counters show —. Cloud model GPU usage is not reported.\n'
- 'SSD: workspace disk space, shared and nested folders counted once per machine. Files remain after stopping.\n'
- 'Totals include available readings and may be partial. — means unavailable. Click to open Harness Monitor.';
+ String metricsLabel({
+ bool ram = true,
+ bool gpu = true,
+ bool storage = true,
+ }) => summary.metricsLabel(ram: ram, gpu: gpu, storage: storage);
- String get detail =>
- '${live.length} open across connected machines, including idle and starting harnesses. Click to open Harness Monitor.\n'
- '${HarnessResources.explanation}${sharedLabel == null ? '' : '\n$sharedLabel, included once in the session monitor.'}';
+ String get resourceDetail => summary.resourceDetail;
+ String get detail => summary.detail;
void start() {
if (_started || _disposed) return;
@@ -199,7 +140,7 @@ class HarnessMonitor extends ChangeNotifier {
for (final (id, machine, result) in readings) {
if (result != null && identical(machine, app.stateOf(id))) {
_samples[id] = (machine, result);
- _receivedAt[id] = DateTime.now();
+ _receivedAt[id] = _now();
}
}
notifyListeners();
@@ -224,3 +165,109 @@ class HarnessMonitor extends ChangeNotifier {
super.dispose();
}
}
+
+/// Value-only presentation of one resource reading. Native toolbar fields and
+/// responsive Flutter labels can share it without rescanning the session roster.
+class HarnessMonitorSummary {
+ const HarnessMonitorSummary._(
+ this.liveCount,
+ this.cpu,
+ this.memory,
+ this.gpu,
+ this.storage,
+ this.sharedLabel,
+ );
+
+ factory HarnessMonitorSummary._fromReadings(
+ List<(String, HarnessResources?)> sessions,
+ List<HarnessResources> shared,
+ ) {
+ final readings = [for (final row in sessions) row.$2, ...shared];
+ String total(
+ double? Function(HarnessResources) value,
+ String Function(double) format,
+ ) {
+ var sum = 0.0, known = false;
+ for (final reading in readings) {
+ final number = reading == null ? null : value(reading);
+ if (number != null) {
+ sum += number;
+ known = true;
+ }
+ }
+ return known || readings.isEmpty ? format(sum) : '—';
+ }
+
+ final folders = <String, Map<String, double>>{};
+ for (final (machine, resource) in sessions) {
+ final path = resource?.workspacePath, bytes = resource?.workspaceBytes;
+ if (path != null && bytes != null) {
+ (folders[machine] ??= {})[path] = bytes;
+ }
+ }
+ var bytes = 0.0, count = 0;
+ for (final machine in folders.values) {
+ final included = <String>[];
+ for (final path
+ in machine.keys.toList()
+ ..sort((a, b) => a.length.compareTo(b.length))) {
+ if (included.any(
+ (parent) => path == parent || path.startsWith('$parent/'),
+ )) {
+ continue;
+ }
+ included.add(path);
+ count++;
+ bytes += machine[path]!;
+ }
+ }
+ return HarnessMonitorSummary._(
+ sessions.length,
+ total((r) => r.cpuPercent, (v) => '${v.round()}%'),
+ total((r) => r.memoryBytes, _wholeBytes),
+ total((r) => r.gpuPercent, (v) => '${v.round()}%'),
+ sessions.isNotEmpty && count == 0 ? '—' : _wholeBytes(bytes),
+ _sharedMemoryLabel(shared),
+ );
+ }
+
+ final int liveCount;
+ final String cpu, memory, gpu, storage;
+ final String? sharedLabel;
+
+ static String _wholeBytes(double bytes) => bytes >= 1e9
+ ? '${(bytes / 1e9).round()} GB'
+ : '${(bytes / 1e6).round()} MB';
+
+ String get label => 'Harnesses $liveCount';
+
+ /// CPU uses one core as its denominator. The tooltip explains partial totals.
+ String metricsLabel({
+ bool ram = true,
+ bool gpu = true,
+ bool storage = true,
+ }) =>
+ 'CPU $cpu'
+ '${ram ? '${workspaceBarGroupSeparator}RAM $memory' : ''}'
+ '${gpu ? '${workspaceBarGroupSeparator}GPU ${this.gpu}' : ''}'
+ '${storage ? '${workspaceBarGroupSeparator}SSD ${this.storage}' : ''}';
+
+ String get resourceDetail =>
+ '$liveCount open harnesses across connected machines. Totals cover these harnesses only.\n'
+ '${metricsLabel()}\n'
+ 'CPU: 100% is one core. RAM includes child processes and shared servers counted once; shared memory pages can overlap.\n'
+ 'GPU: harness process GPU use on supported macOS and Linux NVIDIA drivers. First samples and unavailable counters show —. Cloud model GPU usage is not reported.\n'
+ 'SSD: workspace disk space, shared and nested folders counted once per machine. Files remain after stopping.\n'
+ 'Totals include available readings and may be partial. — means unavailable. Click to open Harness Monitor.';
+
+ String get detail =>
+ '$liveCount open across connected machines, including idle and starting harnesses. Click to open Harness Monitor.\n'
+ '${HarnessResources.explanation}${sharedLabel == null ? '' : '\n$sharedLabel, included once in the session monitor.'}';
+}
+
+String? _sharedMemoryLabel(List<HarnessResources> rows) {
+ if (rows.isEmpty) return null;
+ final known = rows.where((r) => r.memoryBytes != null).toList();
+ final memory = known.fold<double>(0, (sum, r) => sum + r.memoryBytes!);
+ return 'Shared Codex servers · ${formatHarnessMemory(known.isEmpty ? null : memory)}${known.isNotEmpty && known.length < rows.length ? '+' : ''} RAM';
+}
diff --git a/desktop/lib/widgets/workspace_harness_resources.dart b/desktop/lib/widgets/workspace_harness_resources.dart
index f95d03d6a..213dbe8fa 100644
--- a/desktop/lib/widgets/workspace_harness_resources.dart
+++ b/desktop/lib/widgets/workspace_harness_resources.dart
@@ -21,20 +21,21 @@ class WorkspaceHarnessResources extends StatelessWidget {
listenable: monitor,
builder: (context, _) => LayoutBuilder(
builder: (context, constraints) {
+ final summary = monitor.summary;
final cell = workspaceBarCellSizeOf(context).width;
final padding = EdgeInsets.only(
left: cell,
right: trailingPadding ?? cell,
);
- var label = monitor.metricsLabel(
+ var label = summary.metricsLabel(
ram: false,
gpu: false,
storage: false,
);
for (final candidate in [
- monitor.metricsLabel(),
- monitor.metricsLabel(storage: false),
- monitor.metricsLabel(gpu: false, storage: false),
+ summary.metricsLabel(),
+ summary.metricsLabel(storage: false),
+ summary.metricsLabel(gpu: false, storage: false),
]) {
if (workspaceBarTextSizeOf(context, candidate, grouped: true).width +
padding.horizontal <=
@@ -44,8 +45,8 @@ class WorkspaceHarnessResources extends StatelessWidget {
}
}
return WorkspaceBarControl(
- label: monitor.resourceDetail,
- tooltip: monitor.resourceDetail,
+ label: summary.resourceDetail,
+ tooltip: summary.resourceDetail,
onPressed: onPressed,
builder: (context, emphasized) => Padding(
padding: padding,
diff --git a/desktop/test/benchmarks/harness_monitor_summary_benchmark.dart b/desktop/test/benchmarks/harness_monitor_summary_benchmark.dart
new file mode 100644
index 000000000..180de77f1
--- /dev/null
+++ b/desktop/test/benchmarks/harness_monitor_summary_benchmark.dart
@@ -0,0 +1,151 @@
+// Explicit component benchmark. No real agents, network, windows, or disk scans.
+// Copy this fixture to the baseline checkout and pass
+// --dart-define=HARNESS_RESOURCE_BENCH_LEGACY=true to use its original getters.
+import 'dart:convert';
+import 'dart:io';
+
+import 'package:flutter_test/flutter_test.dart';
+import 'package:harness/auth/auth_session.dart';
+import 'package:harness/core/config.dart';
+import 'package:harness/core/harness_resources.dart';
+import 'package:harness/core/models.dart';
+import 'package:harness/state/app_state.dart';
+import 'package:harness/state/harness_monitor.dart';
+import 'package:harness/state/harness_sessions.dart';
+
+class _App extends AppNotifier {
+ _App(int liveCount, int savedCount)
+ : super(
+ config: AppConfig.dev,
+ authSession: AuthSession(),
+ configStore: null,
+ ) {
+ for (var m = 0; m < 3; m++) {
+ final id = 'machine-$m';
+ machineStates[id] =
+ MachineState(Machine(machineId: id, authMode: MachineAuthMode.remote))
+ ..nodeOnline = true
+ ..connectionStatus = ConnectionStatus.connected
+ ..agents = [
+ for (var i = m; i < liveCount; i += 3)
+ Agent(id: 'a$i', name: 'Live $i', terminalAvailable: true),
+ for (var i = m; i < savedCount; i += 3)
+ Agent(id: 'saved$i', name: 'Saved $i', status: 'stopped'),
+ ];
+ for (var i = m; i < savedCount; i += 3) {
+ rememberOpenedHarness(id, 'saved$i');
+ }
+ }
+ }
+
+ @override
+ Future<MachineHarnessResources?> readHarnessResources(String id) async =>
+ MachineHarnessResources(
+ sampledAt: DateTime.now(),
+ agents: {
+ for (final agent in machineStates[id]!.agents)
+ if (!agent.isStopped)
+ agent.id: const HarnessResources(
+ cpuPercent: 1.5,
+ memoryBytes: 150e6,
+ gpuPercent: 0,
+ workspacePath: '/fixture/workspace',
+ workspaceBytes: 1e9,
+ ),
+ },
+ shared: [
+ (
+ machineStates[id]!.agents.map((a) => a.id).toSet(),
+ const HarnessResources(memoryBytes: 400e6, cpuPercent: 2),
+ ),
+ ],
+ );
+}
+
+class _Monitor extends HarnessMonitor {
+ _Monitor(super.app);
+ int inventoryReads = 0;
+ @override
+ List<HarnessSession> get sessions {
+ inventoryReads++;
+ return super.sessions;
+ }
+}
+
+// Match the monitor fields constructed by SwarmScreen._syncNative.
+List<String> _footer(_Monitor monitor) {
+ // Dynamic only at this benchmark seam: the exact baseline has no `summary`.
+ dynamic summary = monitor;
+ if (!const bool.fromEnvironment('HARNESS_RESOURCE_BENCH_LEGACY')) {
+ summary = summary.summary;
+ }
+ return [
+ summary.label,
+ summary.detail,
+ summary.detail,
+ summary.label,
+ summary.metricsLabel(),
+ summary.resourceDetail,
+ summary.resourceDetail,
+ summary.metricsLabel(),
+ summary.metricsLabel(storage: false),
+ summary.metricsLabel(gpu: false, storage: false),
+ summary.metricsLabel(ram: false, gpu: false, storage: false),
+ ];
+}
+
+void main() {
+ test('resource summary workload', () async {
+ final results = <Map<String, Object>>[];
+ for (final (live, saved) in [(16, 64), (25, 1000), (105, 4096)]) {
+ final app = _App(live, saved);
+ final monitor = _Monitor(app);
+ try {
+ await monitor.refresh();
+ final expected = _footer(monitor);
+ for (var warmup = 0; warmup < 20; warmup++) {
+ expect(_footer(monitor), expected);
+ }
+ final rounds = <double>[];
+ monitor.inventoryReads = 0;
+ _footer(monitor);
+ final reads = monitor.inventoryReads;
+ for (var round = 0; round < 7; round++) {
+ final watch = Stopwatch()..start();
+ for (var i = 0; i < 40; i++) {
+ final fields = _footer(monitor);
+ if (fields.length != expected.length ||
+ fields.first != expected.first) {
+ fail('Footer changed during the fixed fixture');
+ }
+ }
+ watch.stop();
+ rounds.add(watch.elapsedMicroseconds / 40);
+ }
+ expect(_footer(monitor), expected);
+ final result = <String, Object>{
+ 'live': live,
+ 'saved': saved,
+ 'legacy': const bool.fromEnvironment('HARNESS_RESOURCE_BENCH_LEGACY'),
+ 'inventoryReadsPerFooter': reads,
+ 'microsecondsPerFooterByRound': rounds,
+ 'footer': expected,
+ };
+ results.add(result);
+ // ignore: avoid_print
+ print('HARNESS_RESOURCE_SUMMARY_BENCH ${jsonEncode(result)}');
+ } finally {
+ monitor.dispose();
+ app.dispose();
+ }
+ }
+ final path = Platform.environment['HARNESS_RESOURCE_BENCH_OUTPUT'];
+ if (path != null) {
+ final file = File(path);
+ if (file.existsSync()) fail('Refusing to overwrite benchmark evidence');
+ file.writeAsStringSync(
+ '${jsonEncode({'scope': 'Headless Debug monitor-field construction; not whole-app CPU, energy or frame latency.', 'at': DateTime.now().toUtc().toIso8601String(), 'results': results})}\n',
+ );
+ }
+ });
+}
diff --git a/desktop/test/harness_monitor_summary_test.dart b/desktop/test/harness_monitor_summary_test.dart
new file mode 100644
index 000000000..af688a69f
--- /dev/null
+++ b/desktop/test/harness_monitor_summary_test.dart
@@ -0,0 +1,237 @@
+import 'package:flutter/material.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:harness/auth/auth_session.dart';
+import 'package:harness/core/config.dart';
+import 'package:harness/core/harness_resources.dart';
+import 'package:harness/core/models.dart';
+import 'package:harness/state/app_state.dart';
+import 'package:harness/state/harness_monitor.dart';
+import 'package:harness/state/harness_sessions.dart';
+import 'package:harness/widgets/workspace_harness_resources.dart';
+
+class _App extends AppNotifier {
+ _App()
+ : super(
+ config: AppConfig.dev,
+ authSession: AuthSession(),
+ configStore: null,
+ );
+ final values = <String, MachineHarnessResources>{};
+ final requests = <String>[];
+
+ void machine(
+ String id,
+ List<Agent> agents, {
+ bool shared = false,
+ bool online = true,
+ }) {
+ machineStates[id] =
+ MachineState(
+ Machine(
+ machineId: id,
+ authMode: MachineAuthMode.remote,
+ isShared: shared,
+ ),
+ )
+ ..agents = agents
+ ..nodeOnline = online
+ ..connectionStatus = ConnectionStatus.connected;
+ }
+
+ @override
+ Future<MachineHarnessResources?> readHarnessResources(String id) async {
+ requests.add(id);
+ return values[id];
+ }
+
+ void changed() => notifyListeners();
+}
+
+class _Monitor extends HarnessMonitor {
+ _Monitor(super.app, {super.now});
+ int inventoryReads = 0;
+ @override
+ List<HarnessSession> get sessions {
+ inventoryReads++;
+ return super.sessions;
+ }
+}
+
+const _live = Agent(id: 'a', name: 'Work', terminalAvailable: true);
+MachineHarnessResources _resources(
+ Map<String, HarnessResources> agents, {
+ List<(Set<String>, HarnessResources)> shared = const [],
+}) => MachineHarnessResources(
+ sampledAt: DateTime(2026, 10, 2),
+ agents: agents,
+ shared: shared,
+);
+
+void main() {
+ test('one snapshot preserves partial totals, shared servers, machine scope and nested storage', () async {
+ final app = _App();
+ final monitor = _Monitor(app);
+ addTearDown(monitor.dispose);
+ addTearDown(app.dispose);
+ app.machine('m', [
+ _live,
+ const Agent(id: 'b', name: 'Other', terminalAvailable: true),
+ const Agent(id: 'starting', name: 'Starting', launchState: 'starting'),
+ const Agent(id: 'saved', name: 'Saved', status: 'stopped'),
+ ]);
+ app.machine('r', [_live]);
+ app.machine('shared', [_live], shared: true);
+ app.machine('offline', [_live], online: false);
+ app.values['m'] = _resources(
+ {
+ 'a': const HarnessResources(
+ memoryBytes: 1e9,
+ cpuPercent: 125.5,
+ gpuPercent: 20,
+ workspaceBytes: 1.4e9,
+ workspacePath: '/project',
+ ),
+ 'b': const HarnessResources(
+ memoryBytes: .2e9,
+ cpuPercent: 0,
+ gpuPercent: 0,
+ workspaceBytes: .4e9,
+ workspacePath: '/project/child',
+ ),
+ 'starting': const HarnessResources(memoryBytes: 90e9, cpuPercent: 900),
+ 'saved': const HarnessResources(memoryBytes: 90e9, cpuPercent: 900),
+ },
+ shared: [
+ (
+ {'a', 'b'},
+ const HarnessResources(memoryBytes: .4e9, cpuPercent: 4.5),
+ ),
+ ({'saved'}, const HarnessResources(memoryBytes: 90e9, cpuPercent: 900)),
+ ],
+ );
+ app.values['r'] = _resources(
+ {
+ 'a': const HarnessResources(
+ memoryBytes: 3e9,
+ cpuPercent: 0,
+ gpuPercent: 5,
+ workspaceBytes: 2e9,
+ workspacePath: '/project',
+ ),
+ },
+ shared: [
+ ({'a'}, const HarnessResources()),
+ ],
+ );
+ await monitor.refresh();
+ expect(app.requests, ['m', 'r']);
+ monitor.inventoryReads = 0;
+ final summary = monitor.summary;
+ expect(summary.label, 'Harnesses 4');
+ expect(summary.metricsLabel(), 'CPU 130% RAM 5 GB GPU 25% SSD 3 GB');
+ expect(
+ summary.metricsLabel(storage: false),
+ 'CPU 130% RAM 5 GB GPU 25%',
+ );
+ expect(
+ summary.metricsLabel(gpu: false, storage: false),
+ 'CPU 130% RAM 5 GB',
+ );
+ expect(
+ summary.metricsLabel(ram: false, gpu: false, storage: false),
+ 'CPU 130%',
+ );
+ expect(summary.sharedLabel, 'Shared Codex servers · 400 MB+ RAM');
+ expect(summary.detail, contains('400 MB+ RAM, included once'));
+ expect(summary.resourceDetail, contains(summary.metricsLabel()));
+ expect(monitor.inventoryReads, 1);
+ expect(app.requests, ['m', 'r']);
+
+ // A captured value is coherent, but the next update always reads current scope.
+ app.machineStates['m']!.nodeOnline = false;
+ app.machineStates['r']!.agents = [];
+ expect(summary.label, 'Harnesses 4');
+ final empty = monitor.summary;
+ expect(empty.label, 'Harnesses 0');
+ expect(empty.metricsLabel(), 'CPU 0% RAM 0 MB GPU 0% SSD 0 MB');
+ expect(empty.sharedLabel, isNull);
+ });
+
+ test(
+ 'expired and replaced-machine readings never enter a new summary',
+ () async {
+ var now = DateTime(2026, 10, 2, 12);
+ final app = _App()..machine('m', [_live]);
+ final monitor = _Monitor(app, now: () => now);
+ addTearDown(monitor.dispose);
+ addTearDown(app.dispose);
+ app.values['m'] = _resources(
+ {'a': const HarnessResources(memoryBytes: 1e9, cpuPercent: 2)},
+ shared: [
+ ({'a'}, const HarnessResources(memoryBytes: .4e9)),
+ ],
+ );
+ await monitor.refresh();
+ final original = monitor.summary;
+ expect(original.metricsLabel(), 'CPU 2% RAM 1 GB GPU — SSD —');
+ now = now.add(const Duration(seconds: 46));
+ final stale = monitor.summary;
+ expect(stale.label, 'Harnesses 1');
+ expect(stale.metricsLabel(), 'CPU — RAM — GPU — SSD —');
+ expect(stale.sharedLabel, isNull);
+ expect(original.metricsLabel(), 'CPU 2% RAM 1 GB GPU — SSD —');
+ await monitor.refresh();
+ expect(monitor.summary.sharedLabel, isNotNull);
+ app.machine('m', [_live]);
+ expect(monitor.summary.metricsLabel(), 'CPU — RAM — GPU — SSD —');
+ expect(monitor.summary.sharedLabel, isNull);
+ },
+ );
+
+ testWidgets(
+ 'responsive footer reuses one summary and refreshes after stopping',
+ (tester) async {
+ final app = _App()..machine('m', [_live]);
+ app.values['m'] = _resources({
+ 'a': const HarnessResources(memoryBytes: 1e9, cpuPercent: 2),
+ });
+ final monitor = _Monitor(app)..start();
+ await tester.pump();
+ for (final width in [600.0, 220.0, 100.0]) {
+ monitor.inventoryReads = 0;
+ await tester.pumpWidget(
+ MaterialApp(
+ home: Center(
+ child: SizedBox(
+ width: width,
+ child: WorkspaceHarnessResources(monitor: monitor),
+ ),
+ ),
+ ),
+ );
+ expect(tester.takeException(), isNull);
+ expect(monitor.inventoryReads, 1);
+ expect(find.byType(Tooltip), findsWidgets);
+ final text = tester
+ .widgetList<Text>(find.byType(Text))
+ .map((t) => t.data ?? t.textSpan?.toPlainText() ?? '')
+ .join();
+ expect(text, startsWith('CPU 2%'));
+ }
+ app.machineStates['m']!.agents = [
+ const Agent(id: 'a', name: 'Saved', status: 'stopped'),
+ ];
+ app.changed();
+ await tester.pump();
+ final text = tester
+ .widgetList<Text>(find.byType(Text))
+ .map((t) => t.data ?? t.textSpan?.toPlainText() ?? '')
+ .join();
+ expect(text, startsWith('CPU 0%'));
+ expect(app.requests, ['m']);
+ await tester.pumpWidget(const SizedBox());
+ monitor.dispose();
+ app.dispose();
+ },
+ );
+}
diff --git a/docs/performance/2026-10-02-resource-summary.json b/docs/performance/2026-10-02-resource-summary.json
new file mode 100644
index 000000000..2ab47b857
--- /dev/null
+++ b/docs/performance/2026-10-02-resource-summary.json
@@ -0,0 +1,250 @@
+{
+ "scope": "Headless Debug monitor-field construction; not whole-app CPU, energy or frame latency.",
+ "baselineCommit": "ea5afd5ad19758e4bcf7b690aafe8dba017591c9",
+ "runtime": {
+ "flutter": "3.47.2",
+ "dart": "3.13.2",
+ "platform": "macOS-26.6.2-arm64-arm-64bit-Mach-O"
+ },
+ "method": "Separate sequential headless Debug runs of exact baseline and candidate with the same final fixture, 20 warmups, seven rounds of 40 footer constructions each. Other workstation apps remained running; no other test or build from this task ran during the timed loops. No energy or frame-latency claim.",
+ "allFooterTextIdentical": true,
+ "sourceSha256": {
+ "desktop/lib/state/harness_monitor.dart": "edf9b4cee82d89c04dda68d99c20ada439e5a749b29035026189477687354359",
+ "desktop/lib/screens/swarm_screen.dart": "4206919ffb3cdfa76afb4a8b364cfe8bfd124bf1c32ca5eb3b81b6fa4cd3fc49",
+ "desktop/lib/widgets/workspace_harness_resources.dart": "7f67707f89453427919925b1161fec55a6c7009795e9916d03891496921a1b03",
+ "desktop/test/benchmarks/harness_monitor_summary_benchmark.dart": "4f723d1257f405faa1fd5f70ebf890162c54e1b2063d32784821026a73e98a44"
+ },
+ "comparisons": [
+ {
+ "live": 16,
+ "saved": 64,
+ "inventoryPassesBefore": 32,
+ "inventoryPassesAfter": 1,
+ "medianMicrosecondsBefore": 301.1,
+ "medianMicrosecondsAfter": 48.45,
+ "reductionPercent": 83.91,
+ "identicalText": true
+ },
+ {
+ "live": 25,
+ "saved": 1000,
+ "inventoryPassesBefore": 32,
+ "inventoryPassesAfter": 1,
+ "medianMicrosecondsBefore": 2650.725,
+ "medianMicrosecondsAfter": 95.225,
+ "reductionPercent": 96.41,
+ "identicalText": true
+ },
+ {
+ "live": 105,
+ "saved": 4096,
+ "inventoryPassesBefore": 32,
+ "inventoryPassesAfter": 1,
+ "medianMicrosecondsBefore": 10998.4,
+ "medianMicrosecondsAfter": 350.5,
+ "reductionPercent": 96.81,
+ "identicalText": true
+ }
+ ],
+ "baseline": {
+ "scope": "Headless Debug monitor-field construction; not whole-app CPU, energy or frame latency.",
+ "at": "2026-10-02T04:56:24.547086Z",
+ "results": [
+ {
+ "live": 16,
+ "saved": 64,
+ "legacy": true,
+ "inventoryReadsPerFooter": 32,
+ "microsecondsPerFooterByRound": [
+ 397.975,
+ 333.0,
+ 315.375,
+ 301.1,
+ 267.675,
+ 260.05,
+ 262.05
+ ],
+ "footer": [
+ "Harnesses 16",
+ "16 open across connected machines, including idle and starting harnesses. Click to open Harness Monitor.\nRAM includes child processes and may include shared memory. CPU: 100% is one core. Unavailable readings show \u2014.\nShared Codex servers \u00b7 1.2 GB RAM, included once in the session monitor.",
+ "16 open across connected machines, including idle and starting harnesses. Click to open Harness Monitor.\nRAM includes child processes and may include shared memory. CPU: 100% is one core. Unavailable readings show \u2014.\nShared Codex servers \u00b7 1.2 GB RAM, included once in the session monitor.",
+ "Harnesses 16",
+ "CPU 30% RAM 4 GB GPU 0% SSD 3 GB",
+ "16 open harnesses across connected machines. Totals cover these harnesses only.\nCPU 30% RAM 4 GB GPU 0% SSD 3 GB\nCPU: 100% is one core. RAM includes child processes and shared servers counted once; shared memory pages can overlap.\nGPU: harness process GPU use on supported macOS and Linux NVIDIA drivers. First samples and unavailable counters show \u2014. Cloud model GPU usage is not reported.\nSSD: workspace disk space, shared and nested folders counted once per machine. Files remain after stopping.\nTotals include available readings and may be partial. \u2014 means unavailable. Click to open Harness Monitor.",
+ "16 open harnesses across connected machines. Totals cover these harnesses only.\nCPU 30% RAM 4 GB GPU 0% SSD 3 GB\nCPU: 100% is one core. RAM includes child processes and shared servers counted once; shared memory pages can overlap.\nGPU: harness process GPU use on supported macOS and Linux NVIDIA drivers. First samples and unavailable counters show \u2014. Cloud model GPU usage is not reported.\nSSD: workspace disk space, shared and nested folders counted once per machine. Files remain after stopping.\nTotals include available readings and may be partial. \u2014 means unavailable. Click to open Harness Monitor.",
+ "CPU 30% RAM 4 GB GPU 0% SSD 3 GB",
+ "CPU 30% RAM 4 GB GPU 0%",
+ "CPU 30% RAM 4 GB",
+ "CPU 30%"
+ ]
+ },
+ {
+ "live": 25,
+ "saved": 1000,
+ "legacy": true,
+ "inventoryReadsPerFooter": 32,
+ "microsecondsPerFooterByRound": [
+ 2635.025,
+ 2697.8,
+ 2694.8,
+ 2650.725,
+ 2638.375,
+ 2640.6,
+ 2692.5
+ ],
+ "footer": [
+ "Harnesses 25",
+ "25 open across connected machines, including idle and starting harnesses. Click to open Harness Monitor.\nRAM includes child processes and may include shared memory. CPU: 100% is one core. Unavailable readings show \u2014.\nShared Codex servers \u00b7 1.2 GB RAM, included once in the session monitor.",
+ "25 open across connected machines, including idle and starting harnesses. Click to open Harness Monitor.\nRAM includes child processes and may include shared memory. CPU: 100% is one core. Unavailable readings show \u2014.\nShared Codex servers \u00b7 1.2 GB RAM, included once in the session monitor.",
+ "Harnesses 25",
+ "CPU 44% RAM 5 GB GPU 0% SSD 3 GB",
+ "25 open harnesses across connected machines. Totals cover these harnesses only.\nCPU 44% RAM 5 GB GPU 0% SSD 3 GB\nCPU: 100% is one core. RAM includes child processes and shared servers counted once; shared memory pages can overlap.\nGPU: harness process GPU use on supported macOS and Linux NVIDIA drivers. First samples and unavailable counters show \u2014. Cloud model GPU usage is not reported.\nSSD: workspace disk space, shared and nested folders counted once per machine. Files remain after stopping.\nTotals include available readings and may be partial. \u2014 means unavailable. Click to open Harness Monitor.",
+ "25 open harnesses across connected machines. Totals cover these harnesses only.\nCPU 44% RAM 5 GB GPU 0% SSD 3 GB\nCPU: 100% is one core. RAM includes child processes and shared servers counted once; shared memory pages can overlap.\nGPU: harness process GPU use on supported macOS and Linux NVIDIA drivers. First samples and unavailable counters show \u2014. Cloud model GPU usage is not reported.\nSSD: workspace disk space, shared and nested folders counted once per machine. Files remain after stopping.\nTotals include available readings and may be partial. \u2014 means unavailable. Click to open Harness Monitor.",
+ "CPU 44% RAM 5 GB GPU 0% SSD 3 GB",
+ "CPU 44% RAM 5 GB GPU 0%",
+ "CPU 44% RAM 5 GB",
+ "CPU 44%"
+ ]
+ },
+ {
+ "live": 105,
+ "saved": 4096,
+ "legacy": true,
+ "inventoryReadsPerFooter": 32,
+ "microsecondsPerFooterByRound": [
+ 10998.4,
+ 11109.925,
+ 11043.2,
+ 11005.4,
+ 10996.05,
+ 10991.675,
+ 10988.175
+ ],
+ "footer": [
+ "Harnesses 105",
+ "105 open across connected machines, including idle and starting harnesses. Click to open Harness Monitor.\nRAM includes child processes and may include shared memory. CPU: 100% is one core. Unavailable readings show \u2014.\nShared Codex servers \u00b7 1.2 GB RAM, included once in the session monitor.",
+ "105 open across connected machines, including idle and starting harnesses. Click to open Harness Monitor.\nRAM includes child processes and may include shared memory. CPU: 100% is one core. Unavailable readings show \u2014.\nShared Codex servers \u00b7 1.2 GB RAM, included once in the session monitor.",
+ "Harnesses 105",
+ "CPU 164% RAM 17 GB GPU 0% SSD 3 GB",
+ "105 open harnesses across connected machines. Totals cover these harnesses only.\nCPU 164% RAM 17 GB GPU 0% SSD 3 GB\nCPU: 100% is one core. RAM includes child processes and shared servers counted once; shared memory pages can overlap.\nGPU: harness process GPU use on supported macOS and Linux NVIDIA drivers. First samples and unavailable counters show \u2014. Cloud model GPU usage is not reported.\nSSD: workspace disk space, shared and nested folders counted once per machine. Files remain after stopping.\nTotals include available readings and may be partial. \u2014 means unavailable. Click to open Harness Monitor.",
+ "105 open harnesses across connected machines. Totals cover these harnesses only.\nCPU 164% RAM 17 GB GPU 0% SSD 3 GB\nCPU: 100% is one core. RAM includes child processes and shared servers counted once; shared memory pages can overlap.\nGPU: harness process GPU use on supported macOS and Linux NVIDIA drivers. First samples and unavailable counters show \u2014. Cloud model GPU usage is not reported.\nSSD: workspace disk space, shared and nested folders counted once per machine. Files remain after stopping.\nTotals include available readings and may be partial. \u2014 means unavailable. Click to open Harness Monitor.",
+ "CPU 164% RAM 17 GB GPU 0% SSD 3 GB",
+ "CPU 164% RAM 17 GB GPU 0%",
+ "CPU 164% RAM 17 GB",
+ "CPU 164%"
+ ]
+ }
+ ]
+ },
+ "candidate": {
+ "scope": "Headless Debug monitor-field construction; not whole-app CPU, energy or frame latency.",
+ "at": "2026-10-02T04:56:54.996347Z",
+ "results": [
+ {
+ "live": 16,
+ "saved": 64,
+ "legacy": false,
+ "inventoryReadsPerFooter": 1,
+ "microsecondsPerFooterByRound": [
+ 91.625,
+ 61.8,
+ 62.15,
+ 48.45,
+ 39.05,
+ 39.7,
+ 42.325
+ ],
+ "footer": [
+ "Harnesses 16",
+ "16 open across connected machines, including idle and starting harnesses. Click to open Harness Monitor.\nRAM includes child processes and may include shared memory. CPU: 100% is one core. Unavailable readings show \u2014.\nShared Codex servers \u00b7 1.2 GB RAM, included once in the session monitor.",
+ "16 open across connected machines, including idle and starting harnesses. Click to open Harness Monitor.\nRAM includes child processes and may include shared memory. CPU: 100% is one core. Unavailable readings show \u2014.\nShared Codex servers \u00b7 1.2 GB RAM, included once in the session monitor.",
+ "Harnesses 16",
+ "CPU 30% RAM 4 GB GPU 0% SSD 3 GB",
+ "16 open harnesses across connected machines. Totals cover these harnesses only.\nCPU 30% RAM 4 GB GPU 0% SSD 3 GB\nCPU: 100% is one core. RAM includes child processes and shared servers counted once; shared memory pages can overlap.\nGPU: harness process GPU use on supported macOS and Linux NVIDIA drivers. First samples and unavailable counters show \u2014. Cloud model GPU usage is not reported.\nSSD: workspace disk space, shared and nested folders counted once per machine. Files remain after stopping.\nTotals include available readings and may be partial. \u2014 means unavailable. Click to open Harness Monitor.",
+ "16 open harnesses across connected machines. Totals cover these harnesses only.\nCPU 30% RAM 4 GB GPU 0% SSD 3 GB\nCPU: 100% is one core. RAM includes child processes and shared servers counted once; shared memory pages can overlap.\nGPU: harness process GPU use on supported macOS and Linux NVIDIA drivers. First samples and unavailable counters show \u2014. Cloud model GPU usage is not reported.\nSSD: workspace disk space, shared and nested folders counted once per machine. Files remain after stopping.\nTotals include available readings and may be partial. \u2014 means unavailable. Click to open Harness Monitor.",
+ "CPU 30% RAM 4 GB GPU 0% SSD 3 GB",
+ "CPU 30% RAM 4 GB GPU 0%",
+ "CPU 30% RAM 4 GB",
+ "CPU 30%"
+ ]
+ },
+ {
+ "live": 25,
+ "saved": 1000,
+ "legacy": false,
+ "inventoryReadsPerFooter": 1,
+ "microsecondsPerFooterByRound": [
+ 134.425,
+ 110.95,
+ 108.175,
+ 94.225,
+ 95.225,
+ 92.05,
+ 92.125
+ ],
+ "footer": [
+ "Harnesses 25",
+ "25 open across connected machines, including idle and starting harnesses. Click to open Harness Monitor.\nRAM includes child processes and may include shared memory. CPU: 100% is one core. Unavailable readings show \u2014.\nShared Codex servers \u00b7 1.2 GB RAM, included once in the session monitor.",
+ "25 open across connected machines, including idle and starting harnesses. Click to open Harness Monitor.\nRAM includes child processes and may include shared memory. CPU: 100% is one core. Unavailable readings show \u2014.\nShared Codex servers \u00b7 1.2 GB RAM, included once in the session monitor.",
+ "Harnesses 25",
+ "CPU 44% RAM 5 GB GPU 0% SSD 3 GB",
+ "25 open harnesses across connected machines. Totals cover these harnesses only.\nCPU 44% RAM 5 GB GPU 0% SSD 3 GB\nCPU: 100% is one core. RAM includes child processes and shared servers counted once; shared memory pages can overlap.\nGPU: harness process GPU use on supported macOS and Linux NVIDIA drivers. First samples and unavailable counters show \u2014. Cloud model GPU usage is not reported.\nSSD: workspace disk space, shared and nested folders counted once per machine. Files remain after stopping.\nTotals include available readings and may be partial. \u2014 means unavailable. Click to open Harness Monitor.",
+ "25 open harnesses across connected machines. Totals cover these harnesses only.\nCPU 44% RAM 5 GB GPU 0% SSD 3 GB\nCPU: 100% is one core. RAM includes child processes and shared servers counted once; shared memory pages can overlap.\nGPU: harness process GPU use on supported macOS and Linux NVIDIA drivers. First samples and unavailable counters show \u2014. Cloud model GPU usage is not reported.\nSSD: workspace disk space, shared and nested folders counted once per machine. Files remain after stopping.\nTotals include available readings and may be partial. \u2014 means unavailable. Click to open Harness Monitor.",
+ "CPU 44% RAM 5 GB GPU 0% SSD 3 GB",
+ "CPU 44% RAM 5 GB GPU 0%",
+ "CPU 44% RAM 5 GB",
+ "CPU 44%"
+ ]
+ },
+ {
+ "live": 105,
+ "saved": 4096,
+ "legacy": false,
+ "inventoryReadsPerFooter": 1,
+ "microsecondsPerFooterByRound": [
+ 361.725,
+ 350.5,
+ 349.925,
+ 350.95,
+ 342.275,
+ 369.85,
+ 344.825
+ ],
+ "footer": [
+ "Harnesses 105",
+ "105 open across connected machines, including idle and starting harnesses. Click to open Harness Monitor.\nRAM includes child processes and may include shared memory. CPU: 100% is one core. Unavailable readings show \u2014.\nShared Codex servers \u00b7 1.2 GB RAM, included once in the session monitor.",
+ "105 open across connected machines, including idle and starting harnesses. Click to open Harness Monitor.\nRAM includes child processes and may include shared memory. CPU: 100% is one core. Unavailable readings show \u2014.\nShared Codex servers \u00b7 1.2 GB RAM, included once in the session monitor.",
+ "Harnesses 105",
+ "CPU 164% RAM 17 GB GPU 0% SSD 3 GB",
+ "105 open harnesses across connected machines. Totals cover these harnesses only.\nCPU 164% RAM 17 GB GPU 0% SSD 3 GB\nCPU: 100% is one core. RAM includes child processes and shared servers counted once; shared memory pages can overlap.\nGPU: harness process GPU use on supported macOS and Linux NVIDIA drivers. First samples and unavailable counters show \u2014. Cloud model GPU usage is not reported.\nSSD: workspace disk space, shared and nested folders counted once per machine. Files remain after stopping.\nTotals include available readings and may be partial. \u2014 means unavailable. Click to open Harness Monitor.",
+ "105 open harnesses across connected machines. Totals cover these harnesses only.\nCPU 164% RAM 17 GB GPU 0% SSD 3 GB\nCPU: 100% is one core. RAM includes child processes and shared servers counted once; shared memory pages can overlap.\nGPU: harness process GPU use on supported macOS and Linux NVIDIA drivers. First samples and unavailable counters show \u2014. Cloud model GPU usage is not reported.\nSSD: workspace disk space, shared and nested folders counted once per machine. Files remain after stopping.\nTotals include available readings and may be partial. \u2014 means unavailable. Click to open Harness Monitor.",
+ "CPU 164% RAM 17 GB GPU 0% SSD 3 GB",
+ "CPU 164% RAM 17 GB GPU 0%",
+ "CPU 164% RAM 17 GB",
+ "CPU 164%"
+ ]
+ }
+ ]
+ },
+ "validation": {
+ "targetedTests": 52,
+ "targetedTestsPassed": 52,
+ "coverage": {
+ "entireHarnessMonitor": {
+ "hit": 137,
+ "total": 144
+ },
+ "summaryAndFormatting": {
+ "hit": 49,
+ "total": 49
+ }
+ },
+ "analysis": {
+ "exitCode": 0,
+ "preExistingInfoFindings": 14,
+ "newChangedFileFindings": 0
+ },
+ "wholeAppEnergyImprovementMeasured": false,
+ "fullSuitePassClaimed": false
+ }
+}
diff --git a/docs/performance/2026-10-02-resource-summary.md b/docs/performance/2026-10-02-resource-summary.md
new file mode 100644
index 000000000..8835e390a
--- /dev/null
+++ b/docs/performance/2026-10-02-resource-summary.md
@@ -0,0 +1,76 @@
+# Build one resource summary per toolbar update
+
+Constructing the resource fields for a native toolbar update walked the entire
+session inventory 32 times. Each count, tooltip, full label, and narrow label
+independently rebuilt the live-session list and recomputed totals. This included
+saved sessions that did not contribute to those totals.
+
+The toolbar now captures one immutable `HarnessMonitorSummary` for that update.
+The Flutter resource footer does the same for each layout. Width variants,
+accessibility descriptions, and tooltips reuse the resulting values. The next
+update reads current state again; there is no persistent summary cache, new
+timer, additional sampling, or change to session lifecycle.
+
+Shared Codex servers still contribute once, storage is deduplicated within each
+machine, and unavailable or expired readings remain unknown. A test clock checks
+the 45-second expiry boundary without waiting or changing production cadence.
+
+## Measurements
+
+[Raw evidence](2026-10-02-resource-summary.json) compares the exact 1.2.47 source
+at `ea5afd5ad19758e4bcf7b690aafe8dba017591c9` with the candidate. Both use the same
+final synthetic fixture on macOS ARM64, Flutter 3.47.2 / Dart 3.13.2, in headless
+Debug mode. Runs are sequential, with 20 warmups and seven rounds of 40 resource
+field constructions. Values below are medians of those round averages. Other
+workstation apps remained running; this task ran no other test or build during
+the timed loops.
+
+| Live / saved sessions | Before | After | Less time |
+| --- | ---: | ---: | ---: |
+| 16 / 64 | 301.1 µs | 48.45 µs | 83.9% |
+| 25 / 1,000 | 2,650.725 µs | 95.225 µs | 96.4% |
+| 105 / 4,096 | 10,998.4 µs | 350.5 µs | 96.8% |
+
+Inventory walks were **32 → 1** in every case. Every resulting label and tooltip
+matched the baseline exactly. This measures one UI component's computation,
+excluding native painting, transport, the daemon, agent processes, GPU and
+battery. It does not establish equivalent whole-app energy or CPU savings.
+
+## Reproduction and validation
+
+From `desktop/`:
+
+```sh
+HARNESS_RESOURCE_BENCH_OUTPUT=/tmp/resource-after.json flutter test --no-pub \
+ test/benchmarks/harness_monitor_summary_benchmark.dart --concurrency=1
+```
+
+Copy the same benchmark file into an isolated checkout of the baseline commit,
+prepare its Flutter dependencies, and run with
+`--dart-define=HARNESS_RESOURCE_BENCH_LEGACY=true` and a separate output file.
+That flag uses the baseline's original getters; it does not reimplement them.
+Compare the `footer` arrays as well as timings, and keep all rounds. The JSON
+records the benchmark and changed production-file hashes.
+
+The 52 targeted tests cover resource parsing, shared-server accounting, partial
+readings, machine replacement and disconnect, stale data, responsive widths,
+stopped-session updates, saved-session visibility, native toolbar updates,
+workspace activity/event isolation, and opening/reusing Harness Monitor through
+both footer controls. Coverage includes all 49 executable lines in the new summary
+and formatting code (137/144 in the entire monitor). Analysis passes with 14
+pre-existing informational findings and none in the changed files. No real agent
+is started by these fixtures.
+
+```sh
+flutter test --no-pub --concurrency=1 \
+ test/harness_monitor_summary_test.dart test/harness_resources_test.dart \
+ test/harness_monitor_visibility_test.dart test/swarm_screen_test.dart \
+ test/workspace_activity_test.dart test/workspace_event_isolation_test.dart \
+ test/harness_monitor_test.dart
+flutter analyze --no-pub --no-fatal-infos
+```
+
+These are component and workspace tests, not 100% end-to-end coverage. The prior
+[full-suite audit](2026-10-02-buffered-diagnostic-validation.json) records
+unrelated baseline failures and stalled tests; a green targeted run does not
+mean the whole repository suite passes.