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.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
fix(swarm): fall back promptly when local PR reading is unavailable
tony2b38e9dc872f
diff --git a/cli/src/lib/pullRequestsStatus.spec.ts b/cli/src/lib/pullRequestsStatus.spec.tsindex e4909274e..e9a7c7f70 100644--- a/cli/src/lib/pullRequestsStatus.spec.ts+++ b/cli/src/lib/pullRequestsStatus.spec.ts@@ -79,6 +79,16 @@ describe('linked pull requests read directly from GitHub', () => {] })expect((await createPullRequestsStatusReader(run)([url(2)])).error).toBeUndefined()})+ it.each(['HTTP 403: Resource protected by organization SAML enforcement', 'HTTP 403: Resource not accessible by integration'])('keeps a repository access refusal apart: %s', async stderr => {+ const read = createPullRequestsStatusReader(async () => { throw { stderr } })+ expect(await read([url()])).toMatchObject({ rows: [{ status: 'no_access' }] })+ expect((await read([url()])).error).toBeUndefined()+ })+ it('still treats a 403 with rate-limit wording as a whole-machine rate limit', async () => {+ const read = createPullRequestsStatusReader(async () => { throw { stderr: 'HTTP 403: secondary rate limit' } })+ expect(await read([url()])).toMatchObject({ error: 'RATE_LIMITED' })+ })+it.each([[{ code: 'ENOENT' }, 'GH_MISSING'], [{ stderr: 'To get started run gh auth login' }, 'GH_SIGNED_OUT'],[{ stderr: 'API rate limit exceeded' }, 'RATE_LIMITED'], [{ killed: true }, 'TIMEOUT'], [{ stderr: 'bad gateway' }, 'GH_FAILED'],diff --git a/cli/src/lib/pullRequestsStatus.ts b/cli/src/lib/pullRequestsStatus.tsindex 1de0b628f..0665757fb 100644--- a/cli/src/lib/pullRequestsStatus.ts+++ b/cli/src/lib/pullRequestsStatus.ts@@ -43,7 +43,8 @@ export function createPullRequestsStatusReader(run: Run = ghRun, now: () => numb} catch (error) {const e = ghError(error)const stderr = String((error as { stderr?: unknown } | null)?.stderr ?? '')- if (e.code === 'GH_FAILED' && /could not resolve to a (?:repository|pullrequest)|could not find|not found|HTTP 404|not accessible/i.test(stderr)) {+ const denied = /HTTP 403/i.test(stderr) && !/rate limit|secondary rate/i.test(stderr)+ if (denied || e.code === 'GH_FAILED' && /could not resolve to a (?:repository|pullrequest)|could not find|not found|HTTP 404|not accessible/i.test(stderr)) {return { url, status: 'no_access' }}return { url, status: 'unavailable', error: e.code }diff --git a/desktop/integration_test/super_tab_pull_requests_native_test.dart b/desktop/integration_test/super_tab_pull_requests_native_test.dartindex 87fad17e5..86258aa0b 100644--- a/desktop/integration_test/super_tab_pull_requests_native_test.dart+++ b/desktop/integration_test/super_tab_pull_requests_native_test.dart@@ -1,4 +1,5 @@import 'dart:io';+import 'dart:async';import 'dart:convert';import 'dart:ui' as ui;@@ -8,8 +9,13 @@ import 'package:flutter_test/flutter_test.dart';import 'package:integration_test/integration_test.dart';import 'package:window_manager/window_manager.dart';import 'package:harness/core/test_run.dart';+import 'package:harness/widgets/desktop_chrome.dart';import 'package:harness/shared/theme/app_theme.dart' as grid;import 'package:harness/super_tabs/pull_requests.dart';+import 'package:harness/ws/ws_conn.dart';+import 'package:harness/ws/local_daemon_transport.dart';++import '../test/swarm_state_test.dart' show createApp;import '../test/super_tab_pull_requests_test.dart'show prServer, allPrStates, prUrl;@@ -41,13 +47,17 @@ void main() {final boundary = GlobalKey();await tester.pumpWidget(MaterialApp(+ debugShowCheckedModeBanner: false,theme: grid.buildAppTheme(brightness: Brightness.dark),home: Scaffold(body: RepaintBoundary(key: boundary,- child: SuperTabPullRequests(- controller: c!,- read: (_) async => fail ? {'error': 'TIMEOUT'} : {'rows': rows},+ child: Material(+ color: DesktopChrome.surface,+ child: SuperTabPullRequests(+ controller: c!,+ read: (_) async => fail ? {'error': 'TIMEOUT'} : {'rows': rows},+ ),),),),@@ -73,6 +83,9 @@ void main() {await tester.runAsync(() => shot('pull-requests-all-states'));await tester.tap(find.text('Show 1 more'));await tester.pumpAndSettle();+ await tester.drag(find.byType(ListView), const Offset(0, -600));+ await tester.pumpAndSettle();+ await tester.ensureVisible(find.text('Closed 1'));await tester.tap(find.text('Closed 1'));await tester.pumpAndSettle();expect(find.byKey(ValueKey('super-pr-${prUrl(16)}')), findsOneWidget);@@ -86,6 +99,8 @@ void main() {find.textContaining("GitHub didn't answer. Showing what it said"),findsOneWidget,);+ await tester.drag(find.byType(ListView), const Offset(0, 1200));+ await tester.pumpAndSettle();expect(find.text('Pull request 1'), findsOneWidget);await tester.runAsync(() => shot('pull-requests-stale'));final receipt = Platform.environment['SUPER_TAB_PR_REAL_RECEIPT'];@@ -110,13 +125,17 @@ void main() {});await tester.pumpWidget(MaterialApp(+ debugShowCheckedModeBanner: false,theme: grid.buildAppTheme(brightness: Brightness.dark),home: Scaffold(body: RepaintBoundary(key: boundary,- child: SuperTabPullRequests(- controller: realController!,- read: (_) async => {'rows': real},+ child: Material(+ color: DesktopChrome.surface,+ child: SuperTabPullRequests(+ controller: realController!,+ read: (_) async => {'rows': real},+ ),),),),@@ -131,6 +150,75 @@ void main() {await tester.runAsync(realController.flush);realController.dispose();}+ // Opt-in manual compatibility check, explicitly pointed at the installed CLI.+ // Normal native runs retain fixture traffic only.+ final oldSocket = Platform.environment['SUPER_TAB_PR_OLD_SOCKET'];+ final oldMachine = Platform.environment['SUPER_TAB_PR_OLD_MACHINE'];+ if (oldSocket != null && oldMachine != null) {+ await tester.pumpWidget(const SizedBox());+ final connection = WsConn(+ wsBaseUrl: 'ws://127.0.0.1:18473',+ autonomousEnv: 'prod',+ machineId: oldMachine,+ accessTokenProvider: (_, _) async => '',+ onAuthFailure: (_) {},+ onEvent: (_) {},+ onStatus: (_) {},+ transportKind: WsTransportKind.localPlaintext,+ localWsUri: Uri.parse('ws://127.0.0.1:18473/api/local-ws'),+ localTransport: LocalDaemonTransport(candidate: oldSocket),+ localToolClient: true,+ );+ await tester.runAsync(() async {+ await connection.connect();+ await connection.waitUntilReady(timeout: const Duration(seconds: 5));+ });+ final app = createApp(connectionForTest: (_) => connection);+ app.stateOf('m')!.localOnly = true;+ final oldController = await tester.runAsync(() async {+ final c = prServer([1494]).controller();+ await c.refresh();+ return c;+ });+ final answered = Completer<void>(), elapsed = Stopwatch()..start();+ await tester.pumpWidget(+ MaterialApp(+ theme: grid.buildAppTheme(brightness: Brightness.dark),+ home: Scaffold(+ body: RepaintBoundary(+ key: boundary,+ child: Material(+ color: DesktopChrome.surface,+ child: SuperTabPullRequests(+ controller: oldController!,+ app: app,+ read: (urls) async {+ final answer = await app.readPullRequestsStatus(urls);+ answered.complete();+ return answer;+ },+ ),+ ),+ ),+ ),+ ),+ );+ await tester.runAsync(+ () => answered.future.timeout(const Duration(seconds: 5)),+ );+ await tester.pumpAndSettle();+ elapsed.stop();+ expect(find.textContaining('View status on GitHub'), findsOneWidget);+ expect(find.textContaining("GitHub didn't answer"), findsNothing);+ debugPrint(+ 'Installed CLI fallback displayed in ${elapsed.elapsedMilliseconds} ms',+ );+ await tester.runAsync(() => shot('pull-requests-installed-cli-fallback'));+ await tester.pumpWidget(const SizedBox());+ oldController.dispose();+ app.dispose();+ await connection.close();+ }expect(tester.takeException(), isNull);await tester.pumpWidget(const SizedBox());await tester.runAsync(c.flush);diff --git a/desktop/lib/state/app_state.dart b/desktop/lib/state/app_state.dartindex 887305747..819fe36f4 100644--- a/desktop/lib/state/app_state.dart+++ b/desktop/lib/state/app_state.dart@@ -13454,7 +13454,7 @@ class AppNotifier extends ChangeNotifier {/// An agent changing branch or stopping must not change whose account reads a link.Future<Map<String, dynamic>> readPullRequestsStatus(List<String> urls) async {final machine = localMachineState, revision = _authRevision;- if (machine == null) return {'error': 'UNAVAILABLE'};+ if (machine == null) return {'error': 'LOCAL_GITHUB_UNAVAILABLE'};try {final result = await _conn(machine.machine.machineId).request('git_pull_requests_status',diff --git a/desktop/lib/super_tabs/pull_requests.dart b/desktop/lib/super_tabs/pull_requests.dartindex 3d42dd63e..04856ac54 100644--- a/desktop/lib/super_tabs/pull_requests.dart+++ b/desktop/lib/super_tabs/pull_requests.dart@@ -6,6 +6,7 @@ import 'package:url_launcher/url_launcher.dart';import '../core/pull_request_status.dart';import '../core/open_in_browser.dart';import '../shared/theme/pull_request_icon.dart';+import '../shared/theme/app_theme.dart' as grid;import 'pull_request_entry.dart';import '../shared/theme/app_icons.dart';import '../state/app_state.dart';@@ -233,7 +234,12 @@ class _SuperTabPullRequestsState extends State<SuperTabPullRequests> {) ??<String, dynamic>{'error': 'UNAVAILABLE'};if (!mounted || revision != _revision) return;- if (answer['error'] == 'UNSUPPORTED') {+ if (const [+ 'UNSUPPORTED',+ 'E2EE_REQUIRED',+ 'OWNER_REQUIRED',+ 'LOCAL_GITHUB_UNAVAILABLE',+ ].contains(answer['error'])) {_unsupported = true;break;}@@ -385,6 +391,10 @@ class _SuperTabPullRequestsState extends State<SuperTabPullRequests> {? Align(alignment: Alignment.centerLeft,child: TextButton.icon(+ style: TextButton.styleFrom(+ backgroundColor: Colors.transparent,+ foregroundColor: DesktopChrome.muted,+ ),onPressed: () => setState(() => _closed = !_closed),icon: Icon(_closed ? AppIcons.chevronDown : AppIcons.chevronRight,@@ -422,6 +432,10 @@ class _SuperTabPullRequestsState extends State<SuperTabPullRequests> {child: Padding(padding: const EdgeInsets.only(left: 78),child: TextButton(+ style: TextButton.styleFrom(+ backgroundColor: Colors.transparent,+ foregroundColor: DesktopChrome.accent,+ ),onPressed: () => setState(() => _showMerged = true),child: Text('Show ${rows.length - shown.length} more'),),@@ -575,8 +589,7 @@ class _SuperTabPullRequestsState extends State<SuperTabPullRequests> {brightness: Theme.of(context).brightness,),PullRequestKind.review => DesktopChrome.accent,- PullRequestKind.behind ||- PullRequestKind.running => Theme.of(context).colorScheme.tertiary,+ PullRequestKind.behind || PullRequestKind.running => grid.AppPalette.warn,_ => DesktopChrome.muted,};Widget _row(SuperTabPullRequestEntry entry, Set<String> groups) {@@ -597,7 +610,20 @@ class _SuperTabPullRequestsState extends State<SuperTabPullRequests> {if (entry.status == 'found') {if (entry.kind != PullRequestKind.failed &&entry.kind != PullRequestKind.running) {- bit(entry.checksLabel);+ bit(+ entry.checksLabel,+ color: entry.failed > 0+ ? Theme.of(context).colorScheme.error+ : entry.pending > 0+ ? grid.AppPalette.warn+ : entry.total > 0+ ? pullRequestIconColor(+ 'Open',+ null,+ brightness: Theme.of(context).brightness,+ )+ : null,+ );}bit('+${entry.additions} −${entry.deletions}');}diff --git a/desktop/test/super_tab_pull_request_state_test.dart b/desktop/test/super_tab_pull_request_state_test.dartindex 3dc384a55..05a63f15f 100644--- a/desktop/test/super_tab_pull_request_state_test.dart+++ b/desktop/test/super_tab_pull_request_state_test.dart@@ -113,6 +113,8 @@ void main() {connection.pending.last.completeError(StateError('Disconnected'));expect(await failed, {'error': 'UNAVAILABLE'});app.stateOf('m')!.localOnly = false;- expect(await app.readPullRequestsStatus([]), {'error': 'UNAVAILABLE'});+ expect(await app.readPullRequestsStatus([]), {+ 'error': 'LOCAL_GITHUB_UNAVAILABLE',+ });});}diff --git a/desktop/test/super_tab_pull_requests_test.dart b/desktop/test/super_tab_pull_requests_test.dartindex d4396bee1..c2031ad1f 100644--- a/desktop/test/super_tab_pull_requests_test.dart+++ b/desktop/test/super_tab_pull_requests_test.dart@@ -306,13 +306,23 @@ void main() {);},);- testWidgets('older daemon uses the existing agent-based fallback', (- tester,- ) async {- await mount(tester, prServer([1]), (_) async => {'error': 'UNSUPPORTED'});- expect(find.textContaining('View status on GitHub'), findsOneWidget);- expect(find.textContaining("GitHub didn't answer"), findsNothing);- });+ for (final code in [+ 'UNSUPPORTED',+ 'E2EE_REQUIRED',+ 'OWNER_REQUIRED',+ 'LOCAL_GITHUB_UNAVAILABLE',+ ]) {+ testWidgets(+ '$code falls back immediately instead of claiming GitHub did not answer',+ (tester) async {+ await mount(tester, prServer([1]), (_) async => {'error': code});+ expect(find.textContaining('View status on GitHub'), findsOneWidget);+ expect(find.textContaining("GitHub didn't answer"), findsNothing);+ expect(find.textContaining('Trying again'), findsNothing);+ await tester.pumpWidget(const SizedBox());+ },+ );+ }testWidgets('refreshes only open PRs every minute and stops when the pane is hidden',(tester) async {