@app-vitals/agent-admin 1.80.0 → 1.82.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/openapi.platform.json +48 -2
  2. package/package.json +2 -2
  3. package/src/admin-boot.boot-order.unit.test.ts +11 -0
  4. package/src/admin-boot.ts +42 -2
  5. package/src/admin-ui-installation-repos-pages.ts +89 -25
  6. package/src/admin-ui-installation-repos.smoke.test.ts +71 -0
  7. package/src/admin-ui-pages.ts +13 -1
  8. package/src/admin-ui.ts +16 -4
  9. package/src/agents-api.smoke.test.ts +85 -5
  10. package/src/agents-api.ts +32 -3
  11. package/src/github-access-backfill.ts +9 -1
  12. package/src/github-access-backfill.unit.test.ts +16 -0
  13. package/src/github-agent-installation-crawler.ts +4 -1
  14. package/src/github-agent-installation-crawler.unit.test.ts +14 -0
  15. package/src/github-enterprise-apps.integration.test.ts +11 -0
  16. package/src/github-enterprise-apps.ts +10 -0
  17. package/src/github-installation-wiring.ts +86 -4
  18. package/src/github-installation-wiring.unit.test.ts +8 -4
  19. package/src/github-installation.fixtures.ts +12 -1
  20. package/src/github-repo-cache.integration.test.ts +14 -0
  21. package/src/github-repo-cache.ts +30 -0
  22. package/src/github-repo-crawler.ts +6 -0
  23. package/src/github-repo-crawler.unit.test.ts +36 -0
  24. package/src/github-repo-refresh-discovery.ts +241 -0
  25. package/src/github-repo-refresh-discovery.unit.test.ts +237 -0
  26. package/src/github-repo-refresher.integration.test.ts +179 -0
  27. package/src/github-repo-refresher.ts +640 -0
  28. package/src/github-repo-refresher.unit.test.ts +735 -0
  29. package/src/installation-repos-service.ts +174 -50
  30. package/src/installation-repos-service.unit.test.ts +157 -52
@@ -3528,6 +3528,29 @@
3528
3528
  "appId": {
3529
3529
  "type": "integer"
3530
3530
  },
3531
+ "complete": {
3532
+ "type": "boolean",
3533
+ "description": "Whether the cached crawl is complete. While false the list may be partial."
3534
+ },
3535
+ "syncedAt": {
3536
+ "type": "string",
3537
+ "description": "When the completed crawl finished (ISO 8601)."
3538
+ },
3539
+ "reposSeen": {
3540
+ "type": "integer",
3541
+ "description": "Repos in the cache (the N of 'N of M')."
3542
+ },
3543
+ "totalCount": {
3544
+ "type": "integer",
3545
+ "description": "GitHub's repo count, when known (the M)."
3546
+ },
3547
+ "lastError": {
3548
+ "type": "string"
3549
+ },
3550
+ "rateLimitResetAt": {
3551
+ "type": "string",
3552
+ "description": "When the GitHub rate limit resets (ISO 8601)."
3553
+ },
3531
3554
  "orgs": {
3532
3555
  "type": "array",
3533
3556
  "items": {
@@ -3536,6 +3559,29 @@
3536
3559
  "org": {
3537
3560
  "type": "string"
3538
3561
  },
3562
+ "complete": {
3563
+ "type": "boolean",
3564
+ "description": "Whether the cached crawl is complete. While false the list may be partial."
3565
+ },
3566
+ "syncedAt": {
3567
+ "type": "string",
3568
+ "description": "When the completed crawl finished (ISO 8601)."
3569
+ },
3570
+ "reposSeen": {
3571
+ "type": "integer",
3572
+ "description": "Repos in the cache (the N of 'N of M')."
3573
+ },
3574
+ "totalCount": {
3575
+ "type": "integer",
3576
+ "description": "GitHub's repo count, when known (the M)."
3577
+ },
3578
+ "lastError": {
3579
+ "type": "string"
3580
+ },
3581
+ "rateLimitResetAt": {
3582
+ "type": "string",
3583
+ "description": "When the GitHub rate limit resets (ISO 8601)."
3584
+ },
3539
3585
  "repos": {
3540
3586
  "type": "array",
3541
3587
  "items": {
@@ -3546,7 +3592,7 @@
3546
3592
  },
3547
3593
  "userCanPush": {
3548
3594
  "type": "boolean",
3549
- "description": "Whether the agent's bound GitHub user can push. Omitted when no username is bound or the org's access lookup is incomplete; never reported as false for unknown."
3595
+ "description": "Whether the agent's bound GitHub user can push, from cached access rows. Omitted when no username is bound or the org's access data is incomplete (a missing or errored pair is never reported as false)."
3550
3596
  }
3551
3597
  },
3552
3598
  "required": [
@@ -7879,7 +7925,7 @@
7879
7925
  "/agents/{id}/github-installation/repos": {
7880
7926
  "get": {
7881
7927
  "summary": "List the repos on the agent App's installation",
7882
- "description": "Platform-admin only (session members, ops keys and agent keys get 403). Per org the agent's own GitHub App (its GH_APP_ID) is installed on, lists the installation's repos. When the agent has a bound githubUsername, each repo carries `userCanPush` from the access lookup only when that org's lookup result is complete; otherwise the field is omitted (never false). 404 for an unknown agent; 422 when the agent has no GH_APP_ID.",
7928
+ "description": "Platform-admin only (session members, ops keys and agent keys get 403). Per org the agent's own GitHub App (its GH_APP_ID) is installed on, lists the installation's repos from the background-synced cache; it makes no GitHub call. Sync detail (`complete`, `syncedAt`, `reposSeen`, `totalCount`, `lastError`, `rateLimitResetAt`) is reported per org and overall. When the agent has a bound githubUsername, each repo carries `userCanPush` from cached access rows only when that org's snapshot is complete and every repo has an answer; otherwise the field is omitted (never false). 404 for an unknown agent; 422 when the agent has no GH_APP_ID.",
7883
7929
  "parameters": [
7884
7930
  {
7885
7931
  "schema": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@app-vitals/agent-admin",
3
- "version": "1.80.0",
3
+ "version": "1.82.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/app-vitals/agent.git",
@@ -43,7 +43,7 @@
43
43
  },
44
44
  "dependencies": {
45
45
  "@anthropic-ai/sdk": "0.137.0",
46
- "@app-vitals/agent-lib": "1.80.0",
46
+ "@app-vitals/agent-lib": "1.82.0",
47
47
  "@hono/zod-openapi": "^1.0.0",
48
48
  "@prisma/adapter-pg": "^7.10.0",
49
49
  "@prisma/client": "^7.10.0",
@@ -43,6 +43,7 @@ describe("admin-boot.ts boot sequence", () => {
43
43
  "new TrialExpirySweeper(",
44
44
  "new AccountTrialWarningSweeper(",
45
45
  "new AccountTrialExpirySweeper(",
46
+ "new GithubRepoRefresher(",
46
47
  "startBackgroundPasses(resolvedExtensions.backgroundPasses)",
47
48
  "const server = Bun.serve(",
48
49
  "const shutdown = registerGracefulShutdown(",
@@ -51,6 +52,16 @@ describe("admin-boot.ts boot sequence", () => {
51
52
  ]);
52
53
  });
53
54
 
55
+ it("registers the GitHub repo refresher on its own interval, with env-driven config (GLC-1.4)", () => {
56
+ assertOrdered([
57
+ "resolveRefreshConfig(process.env)",
58
+ "new GithubRepoRefresher(",
59
+ "createStoredAppRefreshDiscovery(",
60
+ "[github-repo-refresher] tick error:",
61
+ "githubRefreshConfig.intervalMs",
62
+ ]);
63
+ });
64
+
54
65
  it("applies the template seed after migrations, through the template service, without blocking serving (TMK-3.2)", () => {
55
66
  assertOrdered([
56
67
  "await runMigrations();",
package/src/admin-boot.ts CHANGED
@@ -99,6 +99,7 @@ import {
99
99
  } from "./caller-scope.ts";
100
100
  import { parseChatCredentialConfig } from "./chat-credential-config.ts";
101
101
  import { HttpChatServiceProvisioningClient } from "./chat-service-provisioning-client.ts";
102
+ import { SystemClock } from "./clock.ts";
102
103
  import { CronRunNowService } from "./cron-run-now.ts";
103
104
  import { parseCronRunNowConfig } from "./cron-run-now-config.ts";
104
105
  import { CronRunTranscriptService } from "./cron-run-transcripts.ts";
@@ -113,9 +114,13 @@ import { GitHubEnterpriseAppService } from "./github-enterprise-apps.ts";
113
114
  import {
114
115
  createGithubInstallationRepos,
115
116
  createGithubSync,
117
+ createStoredAppRefreshDiscovery,
116
118
  } from "./github-installation-wiring.ts";
117
-
118
119
  import { GitHubRepoCacheService } from "./github-repo-cache.ts";
120
+ import {
121
+ GithubRepoRefresher,
122
+ resolveRefreshConfig,
123
+ } from "./github-repo-refresher.ts";
119
124
  import { PrincipalLookupService } from "./principal-lookup.ts";
120
125
  import { createPrincipalsApp } from "./principals-api.ts";
121
126
  import { HttpGoogleAuthClient } from "./google-auth-client.ts";
@@ -194,6 +199,9 @@ export async function startAdmin(
194
199
  prisma,
195
200
  makeStrictTokenCrypto(),
196
201
  );
202
+ // One repo-snapshot cache shared by githubLookup (reads) and the background
203
+ // GithubRepoRefresher (writes) so both see the same store.
204
+ const githubRepoCache = new GitHubRepoCacheService(prisma);
197
205
 
198
206
  // Construct TokenCrypto — reads SHIPWRIGHT_ENCRYPTION_KEY at call time
199
207
  const crypto = makeTokenCrypto();
@@ -423,7 +431,7 @@ export async function startAdmin(
423
431
  provisioner,
424
432
  githubLookup: createGithubLookupService({
425
433
  appService: githubEnterpriseAppService,
426
- cache: new GitHubRepoCacheService(prisma),
434
+ cache: githubRepoCache,
427
435
  }),
428
436
  },
429
437
  };
@@ -844,6 +852,38 @@ export async function startAdmin(
844
852
  );
845
853
  }
846
854
 
855
+ // GitHub repo/access cache refresher (GLC-1.4) — keeps the repo cache and
856
+ // per-user access rows current in the background so no request path calls
857
+ // GitHub. Registered HERE, never inside an app factory, like the sweepers
858
+ // above. Each tick is bounded by its time budget, a tick still running makes
859
+ // the next a no-op, and the per-org snapshot lease lets only one admin
860
+ // replica work an org at a time. Without stored GitHub Apps discovery finds
861
+ // nothing and every tick is idle.
862
+ {
863
+ const githubRefreshConfig = resolveRefreshConfig(process.env);
864
+ const githubRepoRefresher = new GithubRepoRefresher({
865
+ discovery: createStoredAppRefreshDiscovery({
866
+ prisma,
867
+ appService: githubEnterpriseAppService,
868
+ agentEnv: agentEnvService,
869
+ store: githubRepoCache,
870
+ clock: SystemClock(),
871
+ }),
872
+ store: githubRepoCache,
873
+ config: githubRefreshConfig,
874
+ });
875
+ setInterval(() => {
876
+ githubRepoRefresher
877
+ .tick()
878
+ .catch((err) =>
879
+ console.error("[github-repo-refresher] tick error:", err),
880
+ );
881
+ }, githubRefreshConfig.intervalMs);
882
+ console.log(
883
+ `[admin] github repo refresher started (interval: ${githubRefreshConfig.intervalMs}ms, ttl: ${githubRefreshConfig.ttlMs}ms, staleness cap: ${githubRefreshConfig.stalenessCapMs}ms, budget: ${githubRefreshConfig.timeBudgetMs}ms)`,
884
+ );
885
+ }
886
+
847
887
  // Extension background passes (AEP-2.1) — after every platform sweeper,
848
888
  // same "registered here, never inside an app factory" rule.
849
889
  startBackgroundPasses(resolvedExtensions.backgroundPasses);
@@ -24,12 +24,67 @@ export interface OpenWorkView {
24
24
  }
25
25
 
26
26
  /** JSON body of GET /agents/:id/github-installation/repos. */
27
- export interface InstallationReposView {
27
+ export interface InstallationSyncView {
28
+ /** False while the cached crawl is incomplete. Absent (older API): treated as complete. */
29
+ complete?: boolean;
30
+ syncedAt?: string;
31
+ reposSeen?: number;
32
+ totalCount?: number;
33
+ lastError?: string;
34
+ rateLimitResetAt?: string;
35
+ }
36
+
37
+ export interface InstallationReposView extends InstallationSyncView {
28
38
  appId?: number;
29
- orgs: {
39
+ orgs: ({
30
40
  org: string;
31
41
  repos: { fullName: string; userCanPush?: boolean }[];
32
- }[];
42
+ } & InstallationSyncView)[];
43
+ }
44
+
45
+ /** True unless the view says its snapshot is incomplete. */
46
+ export const installationSnapshotComplete = (
47
+ view: InstallationSyncView,
48
+ ): boolean => view.complete !== false;
49
+
50
+ /** True when the view carries any sync detail worth showing. */
51
+ const hasSyncDetail = (v: InstallationSyncView): boolean =>
52
+ v.complete !== undefined ||
53
+ v.syncedAt !== undefined ||
54
+ v.reposSeen !== undefined ||
55
+ v.lastError !== undefined ||
56
+ v.rateLimitResetAt !== undefined;
57
+
58
+ /**
59
+ * One-line sync status: synced-at, "N of M repos", last error and the rate-limit
60
+ * reset. Empty when the view has no sync detail (older API).
61
+ */
62
+ export function renderInstallationSyncStatus(v: InstallationSyncView): string {
63
+ if (!hasSyncDetail(v)) return "";
64
+ const complete = installationSnapshotComplete(v);
65
+ const parts: string[] = [];
66
+ parts.push(
67
+ v.syncedAt
68
+ ? `Synced ${escapeHtml(v.syncedAt.slice(0, 16).replace("T", " "))} UTC`
69
+ : complete
70
+ ? "Synced"
71
+ : "Sync in progress",
72
+ );
73
+ if (v.reposSeen !== undefined) {
74
+ parts.push(
75
+ v.totalCount !== undefined
76
+ ? `${v.reposSeen} of ${v.totalCount} repos`
77
+ : `${v.reposSeen} repos`,
78
+ );
79
+ }
80
+ if (v.lastError) parts.push(`Last error: ${escapeHtml(v.lastError)}`);
81
+ if (v.rateLimitResetAt) {
82
+ parts.push(
83
+ `GitHub rate limit resets ${escapeHtml(v.rateLimitResetAt.slice(0, 16).replace("T", " "))} UTC`,
84
+ );
85
+ }
86
+ const cls = v.lastError || v.rateLimitResetAt ? "alert alert-warning" : "";
87
+ return `<div class="${cls}" data-installation-sync="${complete ? "complete" : "incomplete"}" style="color:#6b7280;font-size:12px;margin:8px 0">${parts.join(" &middot; ")}</div>`;
33
88
  }
34
89
 
35
90
  /** JSON body of GET /agents/:id/repos/:owner/:name/removal-preview. */
@@ -198,31 +253,40 @@ export function renderInstallationReposBody(
198
253
  view: InstallationReposView,
199
254
  opts: { appIdMismatch?: boolean } = {},
200
255
  ): string {
201
- if (view.orgs.length === 0) {
256
+ const sync = renderInstallationSyncStatus(view);
257
+ if (view.orgs.length === 0 || view.orgs.every((o) => o.repos.length === 0)) {
202
258
  if (opts.appIdMismatch) {
203
- return `<div class="alert alert-warning" data-reason="app-id-mismatch">${escapeHtml(APP_ID_MISMATCH_MESSAGE)}</div>`;
259
+ return `${sync}<div class="alert alert-warning" data-reason="app-id-mismatch">${escapeHtml(APP_ID_MISMATCH_MESSAGE)}</div>`;
260
+ }
261
+ if (!installationSnapshotComplete(view)) {
262
+ return `${sync}<p class="empty-state">The installation repos have not finished syncing yet.</p>`;
263
+ }
264
+ if (view.orgs.length === 0) {
265
+ return `${sync}<p class="empty-state">The agent App is not installed on any organization the installer can reach.</p>`;
204
266
  }
205
- return `<p class="empty-state">The agent App is not installed on any organization the installer can reach.</p>`;
206
267
  }
207
- return view.orgs
208
- .map((o) => {
209
- const rows =
210
- o.repos.length === 0
211
- ? `<tr><td colspan="2" class="empty-state">No repos.</td></tr>`
212
- : o.repos
213
- .map((r) => {
214
- const hint =
215
- r.userCanPush === undefined
216
- ? ""
217
- : r.userCanPush
218
- ? '<span class="badge badge-green" title="The bound user can push">user can push</span>'
219
- : '<span class="badge badge-warning" title="The bound user cannot push">user cannot push</span>';
220
- return `<tr><td class="mono">${escapeHtml(r.fullName)}</td><td>${hint}</td></tr>`;
221
- })
222
- .join("");
223
- return `<div class="github-installation-org" data-org="${escapeHtml(o.org)}" style="margin-bottom:16px"><div style="font-weight:600;margin-bottom:6px">${escapeHtml(o.org)}</div><table class="detail-table"><thead><tr><th>Repo</th><th>Bound user</th></tr></thead><tbody>${rows}</tbody></table></div>`;
224
- })
225
- .join("");
268
+ return (
269
+ sync +
270
+ view.orgs
271
+ .map((o) => {
272
+ const rows =
273
+ o.repos.length === 0
274
+ ? `<tr><td colspan="2" class="empty-state">No repos.</td></tr>`
275
+ : o.repos
276
+ .map((r) => {
277
+ const hint =
278
+ r.userCanPush === undefined
279
+ ? ""
280
+ : r.userCanPush
281
+ ? '<span class="badge badge-green" title="The bound user can push">user can push</span>'
282
+ : '<span class="badge badge-warning" title="The bound user cannot push">user cannot push</span>';
283
+ return `<tr><td class="mono">${escapeHtml(r.fullName)}</td><td>${hint}</td></tr>`;
284
+ })
285
+ .join("");
286
+ return `<div class="github-installation-org" data-org="${escapeHtml(o.org)}" style="margin-bottom:16px"><div style="font-weight:600;margin-bottom:6px">${escapeHtml(o.org)}</div>${renderInstallationSyncStatus(o)}<table class="detail-table"><thead><tr><th>Repo</th><th>Bound user</th></tr></thead><tbody>${rows}</tbody></table></div>`;
287
+ })
288
+ .join("")
289
+ );
226
290
  }
227
291
 
228
292
  /** Why the card body could not be shown, distinct per cause. */
@@ -430,6 +430,77 @@ describe("admin UI — GitHub sync card (IRM-3.2)", () => {
430
430
  );
431
431
  });
432
432
 
433
+ describe("cached snapshot states (GLC-2.2)", () => {
434
+ const seeded = (over: Record<string, unknown>) => ({
435
+ appId: 123,
436
+ orgs: [
437
+ {
438
+ org: "acme",
439
+ repos: [{ fullName: "acme/api" }, { fullName: "acme/web" }],
440
+ },
441
+ ],
442
+ ...over,
443
+ });
444
+ const page = async (view: unknown) => {
445
+ const { app, calls } = setup({
446
+ repos: ["acme/api", "other/gone"],
447
+ agentsApi: () => json(view),
448
+ });
449
+ const html = await (await get(app, "/configuration")).text();
450
+ return { html, calls };
451
+ };
452
+
453
+ it("complete: shows synced-at and N of M, and the coverage warning", async () => {
454
+ const { html, calls } = await page(
455
+ seeded({
456
+ complete: true,
457
+ syncedAt: "2026-11-20T10:00:00.000Z",
458
+ reposSeen: 2,
459
+ totalCount: 2,
460
+ }),
461
+ );
462
+ expect(html).toContain('data-installation-sync="complete"');
463
+ expect(html).toContain("2 of 2 repos");
464
+ expect(html).toContain("2026-11-20");
465
+ expect(html).toContain('id="repos-uncovered-warning"');
466
+ // The page reads the cached view only: no GitHub-backed route.
467
+ expect(
468
+ calls.every((c) => c.path.endsWith("/github-installation/repos")),
469
+ ).toBe(true);
470
+ });
471
+
472
+ it("partial: shows N of M and suppresses the coverage warning", async () => {
473
+ const { html } = await page(
474
+ seeded({ complete: false, reposSeen: 1, totalCount: 3 }),
475
+ );
476
+ expect(html).toContain('data-installation-sync="incomplete"');
477
+ expect(html).toContain("1 of 3 repos");
478
+ expect(html).not.toContain("repos-uncovered-warning");
479
+ expect(html).not.toContain('data-uncovered="1"');
480
+ });
481
+
482
+ it("errored: shows the last error and rate-limit reset, no warning", async () => {
483
+ const { html } = await page(
484
+ seeded({
485
+ complete: false,
486
+ reposSeen: 0,
487
+ lastError: "GitHub said <no>",
488
+ rateLimitResetAt: "2026-11-20T11:00:00.000Z",
489
+ }),
490
+ );
491
+ expect(html).toContain("GitHub said &lt;no&gt;");
492
+ expect(html).toContain("rate limit resets");
493
+ expect(html).toContain("2026-11-20");
494
+ expect(html).not.toContain("repos-uncovered-warning");
495
+ });
496
+
497
+ it("a view with no sync fields (older API) still warns", async () => {
498
+ const { html } = await page(seeded({}));
499
+ expect(html).toContain('id="repos-uncovered-warning"');
500
+ expect(html).not.toContain("data-installation-sync");
501
+ });
502
+ });
503
+
433
504
  it("confirm step lists the affected open work", async () => {
434
505
  const { app, calls } = setup({ repos: ["acme/web"], agentsApi: api });
435
506
  const res = await get(app, "/repos/removal-confirm?repo=acme/web");
@@ -18,7 +18,10 @@ import {
18
18
  renderGithubUsernameRow,
19
19
  } from "./admin-ui-github-identity-pages.ts";
20
20
  import {
21
+ type InstallationSyncView,
22
+ installationSnapshotComplete,
21
23
  renderGithubSyncCard,
24
+ renderInstallationSyncStatus,
22
25
  renderUncoveredBadge,
23
26
  uncoveredRepos,
24
27
  } from "./admin-ui-installation-repos-pages.ts";
@@ -1156,6 +1159,12 @@ export function renderAgentDetailPage(
1156
1159
  * could be listed. Absent means unknown: no coverage warning is shown.
1157
1160
  */
1158
1161
  installationRepos?: readonly string[];
1162
+ /**
1163
+ * GLC-2.2: sync detail of the cached installation view (synced-at, N of M,
1164
+ * last error, rate-limit reset). When `complete` is false the coverage
1165
+ * warning is suppressed.
1166
+ */
1167
+ installationSync?: InstallationSyncView;
1159
1168
  /**
1160
1169
  * ATP-2.4: present when agent templates are available. Turns on the
1161
1170
  * inherited/custom badges, the detach/reattach toggle and the per-item
@@ -1723,7 +1732,9 @@ export function renderAgentDetailPage(
1723
1732
  })();
1724
1733
  </script>`;
1725
1734
  const uncovered = new Set(
1726
- opts?.installationRepos
1735
+ opts?.installationRepos &&
1736
+ (!opts.installationSync ||
1737
+ installationSnapshotComplete(opts.installationSync))
1727
1738
  ? uncoveredRepos(agent.repos, opts.installationRepos)
1728
1739
  : [],
1729
1740
  );
@@ -1737,6 +1748,7 @@ export function renderAgentDetailPage(
1737
1748
  <button type="submit" class="btn btn-primary">Add</button>
1738
1749
  </div>
1739
1750
  </form>
1751
+ ${opts?.installationSync ? renderInstallationSyncStatus(opts.installationSync) : ""}
1740
1752
  <div class="data-table-wrapper">
1741
1753
  <table class="data-table">
1742
1754
  <thead>
package/src/admin-ui.ts CHANGED
@@ -62,6 +62,7 @@ import {
62
62
  type GithubSyncApplyView,
63
63
  type GithubSyncPreviewView,
64
64
  type InstallationReposView,
65
+ type InstallationSyncView,
65
66
  type OpenWorkView,
66
67
  type RepoRemovalPreviewView,
67
68
  renderInstallationReposBody,
@@ -2223,7 +2224,7 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
2223
2224
  // No installation matched the numeric GH_APP_ID. If the agent still has an
2224
2225
  // installation by slug (the Installations card), the id is probably wrong.
2225
2226
  let appIdMismatch = false;
2226
- if (view.orgs.length === 0) {
2227
+ if (view.orgs.every((o) => o.repos.length === 0)) {
2227
2228
  const snap = await callApi(
2228
2229
  c,
2229
2230
  agentsApi,
@@ -2512,6 +2513,7 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
2512
2513
  // list's coverage warning. Best effort: unknown means no warning.
2513
2514
  const enterpriseConfigured = await githubEnterpriseConfigured(c);
2514
2515
  let installationRepos: string[] | undefined;
2516
+ let installationSync: InstallationSyncView | undefined;
2515
2517
  if (
2516
2518
  enterpriseConfigured &&
2517
2519
  agentsApi &&
@@ -2524,9 +2526,18 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
2524
2526
  );
2525
2527
  if (res?.ok) {
2526
2528
  try {
2527
- installationRepos = (
2528
- (await res.json()) as InstallationReposView
2529
- ).orgs.flatMap((o) => o.repos.map((r) => r.fullName));
2529
+ const view = (await res.json()) as InstallationReposView;
2530
+ installationRepos = view.orgs.flatMap((o) =>
2531
+ o.repos.map((r) => r.fullName),
2532
+ );
2533
+ installationSync = {
2534
+ complete: view.complete,
2535
+ syncedAt: view.syncedAt,
2536
+ reposSeen: view.reposSeen,
2537
+ totalCount: view.totalCount,
2538
+ lastError: view.lastError,
2539
+ rateLimitResetAt: view.rateLimitResetAt,
2540
+ };
2530
2541
  } catch {
2531
2542
  // unknown: no coverage warning
2532
2543
  }
@@ -2562,6 +2573,7 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
2562
2573
  agent.accountId ?? null,
2563
2574
  ),
2564
2575
  ...(installationRepos ? { installationRepos } : {}),
2576
+ ...(installationSync ? { installationSync } : {}),
2565
2577
  ...(agentsApi
2566
2578
  ? { template: { detached: agent.templateDetached === true } }
2567
2579
  : {}),
@@ -7303,6 +7303,9 @@ describe("admin API — agent App installation repos and GitHub Sync (IRM-1.2, I
7303
7303
  agentRepos?: string[];
7304
7304
  pushable?: string[];
7305
7305
  openWork?: Partial<OpenWorkPort> | null;
7306
+ /** Seeded GLC cache rows read by the list route. */
7307
+ snapshots?: Array<Record<string, unknown>>;
7308
+ accessRows?: Array<Record<string, unknown>>;
7306
7309
  } = {},
7307
7310
  ) {
7308
7311
  const audits: Array<Record<string, unknown>> = [];
@@ -7376,6 +7379,12 @@ describe("admin API — agent App installation repos and GitHub Sync (IRM-1.2, I
7376
7379
  state.repos = args.data.repos;
7377
7380
  },
7378
7381
  },
7382
+ gitHubRepoSnapshot: {
7383
+ findMany: async () => opts.snapshots ?? [],
7384
+ },
7385
+ gitHubRepoAccess: {
7386
+ findMany: async () => opts.accessRows ?? [],
7387
+ },
7379
7388
  gitHubReconcileAudit: {
7380
7389
  create: async (args: { data: Record<string, unknown> }) => {
7381
7390
  events.push(["audit"]);
@@ -7459,26 +7468,96 @@ describe("admin API — agent App installation repos and GitHub Sync (IRM-1.2, I
7459
7468
  body: JSON.stringify(body),
7460
7469
  });
7461
7470
 
7462
- it("GET lists repos per org with push hints from the access lookup", async () => {
7463
- const { app } = setup();
7471
+ const T0 = new Date("2026-11-20T10:00:00.000Z");
7472
+ const seededSnapshot = (over: Record<string, unknown> = {}) => ({
7473
+ org: "acme-eng",
7474
+ completedAt: T0,
7475
+ totalCount: 2,
7476
+ lastError: null,
7477
+ rateLimitResetAt: null,
7478
+ repos: [{ fullName: "acme-eng/repo-1" }, { fullName: "acme-eng/repo-2" }],
7479
+ ...over,
7480
+ });
7481
+ const accessRow = (repo: string, status: string, canPush = false) => ({
7482
+ repo,
7483
+ status,
7484
+ canPush,
7485
+ });
7486
+
7487
+ it("GET reads the cache: repos with push hints from cached access rows, no GitHub call", async () => {
7488
+ const { app, gh } = setup({
7489
+ snapshots: [seededSnapshot()],
7490
+ accessRows: [
7491
+ accessRow("repo-1", "ok", true),
7492
+ accessRow("repo-2", "ok", false),
7493
+ ],
7494
+ });
7464
7495
  const res = await app.request(url(), { headers: asAdmin });
7465
7496
  expect(res.status).toBe(200);
7466
7497
  expect(await res.json()).toEqual({
7467
7498
  appId: 777,
7499
+ complete: true,
7500
+ reposSeen: 2,
7501
+ totalCount: 2,
7502
+ syncedAt: T0.toISOString(),
7468
7503
  orgs: [
7469
7504
  {
7470
7505
  org: "acme-eng",
7506
+ complete: true,
7507
+ reposSeen: 2,
7508
+ totalCount: 2,
7509
+ syncedAt: T0.toISOString(),
7471
7510
  repos: [
7472
7511
  { fullName: "acme-eng/repo-1", userCanPush: true },
7473
- { fullName: "acme-eng/repo-2" },
7512
+ { fullName: "acme-eng/repo-2", userCanPush: false },
7474
7513
  ],
7475
7514
  },
7476
7515
  ],
7477
7516
  });
7517
+ expect(gh).toEqual([]);
7518
+ });
7519
+
7520
+ it("GET omits hints for a partial or errored cache, never reporting false", async () => {
7521
+ for (const snapshots of [
7522
+ [seededSnapshot({ completedAt: null, totalCount: 5 })],
7523
+ [seededSnapshot({ completedAt: null, lastError: "boom" })],
7524
+ ]) {
7525
+ const { app, gh } = setup({
7526
+ snapshots,
7527
+ accessRows: [accessRow("repo-1", "ok", true)],
7528
+ });
7529
+ const body = (await (
7530
+ await app.request(url(), { headers: asAdmin })
7531
+ ).json()) as {
7532
+ complete: boolean;
7533
+ orgs: { repos: Record<string, unknown>[] }[];
7534
+ };
7535
+ expect(body.complete).toBe(false);
7536
+ expect(body.orgs[0]?.repos.map((r) => "userCanPush" in r)).toEqual([
7537
+ false,
7538
+ false,
7539
+ ]);
7540
+ expect(gh).toEqual([]);
7541
+ }
7542
+ const errored = setup({
7543
+ snapshots: [seededSnapshot()],
7544
+ accessRows: [
7545
+ accessRow("repo-1", "ok", true),
7546
+ accessRow("repo-2", "error"),
7547
+ ],
7548
+ });
7549
+ const eb = (await (
7550
+ await errored.app.request(url(), { headers: asAdmin })
7551
+ ).json()) as { orgs: { repos: Record<string, unknown>[] }[] };
7552
+ expect(eb.orgs[0]?.repos.some((r) => r.userCanPush === false)).toBe(false);
7478
7553
  });
7479
7554
 
7480
- it("GET omits the hint entirely for an agent with no bound username", async () => {
7481
- const { app } = setup({ username: null });
7555
+ it("GET with no bound username omits hints and makes no GitHub call", async () => {
7556
+ const { app, gh } = setup({
7557
+ username: null,
7558
+ snapshots: [seededSnapshot()],
7559
+ accessRows: [accessRow("repo-1", "ok", true)],
7560
+ });
7482
7561
  const body = (await (
7483
7562
  await app.request(url(), { headers: asAdmin })
7484
7563
  ).json()) as {
@@ -7488,6 +7567,7 @@ describe("admin API — agent App installation repos and GitHub Sync (IRM-1.2, I
7488
7567
  false,
7489
7568
  false,
7490
7569
  ]);
7570
+ expect(gh).toEqual([]);
7491
7571
  });
7492
7572
 
7493
7573
  it("the direct add and remove routes are gone", async () => {