Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

fix(github): a 304 poll still prompts boards to re-read; approvals reach open boards

reviewb4b1da05100c
diff --git a/src/core/github/host.test.ts b/src/core/github/host.test.ts
index b89063a6d..38d1a2c3f 100644
--- a/src/core/github/host.test.ts
+++ b/src/core/github/host.test.ts
@@ -27,7 +27,10 @@ const project: Project = {
}
}
-function fixture(options: { onRevoked?: (projectId: string) => Promise<void> } = {}) {
+function fixture(options: {
+ onRevoked?: (projectId: string) => Promise<void>
+ onApprovalChanged?: (projectId: string) => void
+} = {}) {
let current: Project = project
let state: GitHubControlState = {
version: 1,
@@ -122,6 +125,7 @@ function fixture(options: { onRevoked?: (projectId: string) => Promise<void> } =
: { status: 'unauthorized' }),
client: vi.fn(() => client),
...(options.onRevoked ? { onRevoked: options.onRevoked } : {}),
+ ...(options.onApprovalChanged ? { onApprovalChanged: options.onApprovalChanged } : {}),
rate: (userId: string) => userId === '1'
? {
status: { resource: 'core', limit: 5_000, remaining: 7, resetAt: 9, observedAt: 1 },
@@ -220,6 +224,22 @@ describe('GitHubHostController', () => {
expect(order).toEqual(['revoke', 'clear:project-1'])
})
+ it('tells open boards the approval changed, on approve and on a revoke whose cache clear failed', async () => {
+ const changed = vi.fn()
+ const { controller } = fixture({
+ onApprovalChanged: changed,
+ onRevoked: async () => { throw new Error('EBUSY') }
+ })
+ await controller.approve({ projectId: 'project-1', repository: 'owner/repo', expectedRevision: 0 })
+ expect(changed).toHaveBeenCalledWith('project-1')
+ changed.mockClear()
+ // A successful clear already prompts the board (it empties the cache it shows); a failed one
+ // does not, and the board must still learn it is no longer approved.
+ await expect(controller.revoke({ projectId: 'project-1', expectedRevision: 1 }))
+ .rejects.toMatchObject({ code: 'revoked-cache-kept' })
+ expect(changed).toHaveBeenCalledWith('project-1')
+ })
+
it('rejects approval for a repository other than the configured or detected repository', async () => {
const { controller } = fixture()
await expect(controller.approve({
diff --git a/src/core/github/host.ts b/src/core/github/host.ts
index bd8d179e4..f9466bdf2 100644
--- a/src/core/github/host.ts
+++ b/src/core/github/host.ts
@@ -82,6 +82,9 @@ type HostDependencies = {
onCredentialBoundaryChange?(): void
/** Runs after a revoke is recorded: deletes this project's private issue cache from disk. */
onRevoked?(projectId: string): Promise<void>
+ /** An approval was given or withdrawn: the project's open boards must re-read (read only, the
+ * mapping approval) now, not at the next poll. */
+ onApprovalChanged?(projectId: string): void
}
type ResolvedProject = ProjectRecord & {
@@ -167,6 +170,7 @@ export class GitHubHostController {
repository: project.repository,
mappingDigest: githubMappingDigest(project.repository, project.config)
})
+ this.dependencies.onApprovalChanged?.(input.projectId)
return this.status(input.projectId)
}
@@ -186,6 +190,8 @@ export class GitHubHostController {
await this.dependencies.onRevoked?.(input.projectId)
} catch {
throw new GitHubHostError('revoked-cache-kept')
+ } finally {
+ this.dependencies.onApprovalChanged?.(input.projectId)
}
return this.status(input.projectId)
}
diff --git a/src/core/github/integration.test.ts b/src/core/github/integration.test.ts
index f7b6fbcfb..746512104 100644
--- a/src/core/github/integration.test.ts
+++ b/src/core/github/integration.test.ts
@@ -5,6 +5,7 @@ import path from 'node:path'
import type { Project } from '../../shared/types'
import type { CorePlatform } from '../platform'
import { registerGitHubIntegration } from './integration'
+import { IPC } from '../../shared/ipc'
import type { CommandRunner, GitHubSecretStore } from './credentials'
let userDataDir: string
@@ -209,3 +210,53 @@ describe('registerGitHubIntegration revoke', () => {
expect(await fs.readdir(path.join(userDataDir, 'github-issues-bindings'))).toEqual([])
})
})
+
+describe('registerGitHubIntegration approval reaches the board', () => {
+ it('prompts the project\'s subscribers to re-read when its approval changes', async () => {
+ globalThis.fetch = (async (input: RequestInfo | URL) => String(input).endsWith('/user')
+ ? new Response(JSON.stringify({ id: 1, login: 'octocat' }), { status: 200 })
+ : new Response('[]', { status: 200, headers: { etag: 'W/"top"' } })
+ ) as typeof globalThis.fetch
+ const sent: Array<[number, string, unknown]> = []
+ const platform = {
+ ...fakePlatform(),
+ sendTo: (uiId: number, channel: string, payload: unknown) => { sent.push([uiId, channel, payload]) }
+ } as unknown as CorePlatform
+ let current: Project = project
+ const { controller, service } = registerGitHubIntegration({
+ platform,
+ userDataDir,
+ project: async (id) => id === current.id ? { project: current, localApprovalId: 'local-1' } : null,
+ detectRepository: async () => 'owner/repo',
+ secret: {
+ availability: 'encrypted',
+ readForHost: async () => 'stored-token',
+ save: async () => undefined,
+ clear: async () => undefined
+ },
+ run: async () => ({ ok: false, stdout: '', stderr: 'not logged in' })
+ })
+ const initial = await controller.status('project-1')
+ await controller.approve({ projectId: 'project-1', repository: 'owner/repo', expectedRevision: initial.control.revision })
+ await service.subscribe(5, { projectId: 'project-1' })
+
+ // A pulled commit changes the mapping: the board is read only until this machine approves it.
+ current = { ...project, kanban: { ...project.kanban!, github: { ...project.kanban!.github!, completionColumnId: 'todo' } } }
+ expect((await service.query({ projectId: 'project-1', columnId: null, pageSize: 50 })).mappingNotApproved).toBe(true)
+ sent.length = 0
+
+ const status = await controller.status('project-1')
+ await controller.approve({ projectId: 'project-1', repository: 'owner/repo', expectedRevision: status.control.revision })
+
+ // The Settings overlay leaves the board mounted; without this prompt it stayed read only
+ // until something changed on GitHub.
+ expect(sent).toContainEqual([5, IPC.githubIssuesChanged('project-1'), []])
+ expect((await service.query({ projectId: 'project-1', columnId: null, pageSize: 50 })).mappingNotApproved)
+ .toBeUndefined()
+
+ sent.length = 0
+ const approved = await controller.status('project-1')
+ await controller.revoke({ projectId: 'project-1', expectedRevision: approved.control.revision })
+ expect(sent.some(([uiId, channel]) => uiId === 5 && channel === IPC.githubIssuesChanged('project-1'))).toBe(true)
+ })
+})
diff --git a/src/core/github/integration.ts b/src/core/github/integration.ts
index b0d690c07..ab36a4b8b 100644
--- a/src/core/github/integration.ts
+++ b/src/core/github/integration.ts
@@ -60,7 +60,8 @@ export function registerGitHubIntegration(dependencies: Dependencies): {
resolver.invalidate()
},
// `service` is declared below; this only runs on a revoke, long after both exist.
- onRevoked: (projectId) => service.clearCache({ projectId })
+ onRevoked: (projectId) => service.clearCache({ projectId }),
+ onApprovalChanged: (projectId) => service.notifyProject(projectId)
})
const service = new GitHubIssueService({
cache: new GitHubIssueCache(dependencies.userDataDir),
diff --git a/src/core/github/service.test.ts b/src/core/github/service.test.ts
index 2cf5125cb..96f9e956e 100644
--- a/src/core/github/service.test.ts
+++ b/src/core/github/service.test.ts
@@ -1,4 +1,4 @@
-import { afterEach, beforeEach, describe, expect, it } from 'vitest'
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { promises as fs } from 'node:fs'
import os from 'node:os'
import path from 'node:path'
@@ -1009,11 +1009,33 @@ describe('GitHubIssueService heartbeat', () => {
onDelta: (_uiId, _projectId, numbers) => deltas.push(numbers)
})
- await service.refresh({ projectId: 'project-1' })
+ // Opening the board refreshes in the background (a snapshot is cached, so it renders at once).
+ await service.subscribe(1, { projectId: 'project-1' })
+ await vi.waitFor(() => expect(client.heartbeats).toHaveLength(1))
+ await vi.waitFor(() => expect(deltas).toHaveLength(1))
expect(client.heartbeats).toEqual([client.currentHeartbeatEtag()])
expect(scans).toEqual([])
- expect(deltas).toEqual([])
+ // Nothing changed on GitHub, but subscribers still re-read their pages (from the local cache,
+ // at no GitHub cost) — as every refresh always made them do. What a page says is not only
+ // issues: read only, the mapping approval and the completion column are derived by the host
+ // at query time, and a board that is never prompted keeps showing the old answer.
+ expect(deltas).toEqual([[]])
+ })
+
+ it('does not let a 304 freeze an incomplete repository: it keeps scanning', async () => {
+ const client = new FixtureClient([issue(1)])
+ const scans = counting(client)
+ const cache = await seeded([issue(1)], { heartbeat: client.currentHeartbeatEtag() })
+ await cache.saveIncompleteAttempt('user-1', 'o/r', { reason: 'issue-limit', observedAt: 5_000 })
+ const service = new GitHubIssueService({
+ cache, coordinator: new GitHubRequestCoordinator(),
+ contextForProject: async () => context(client), now: () => 10_000
+ })
+
+ await service.refresh({ projectId: 'project-1' })
+
+ expect(scans).toHaveLength(1)
})
it('runs the incremental since scan when the heartbeat reports a change, and persists the new ETag', async () => {
@@ -1345,8 +1367,28 @@ describe('GitHubIssueService throttle lift', () => {
expect(deltas.slice(held)).toEqual([[]])
expect((await service.query({ projectId: 'project-1', columnId: null, pageSize: 50 })).throttle)
.toBeUndefined()
- // Said once, not on every later minute.
+ // And a hold that comes back later is announced again rather than taken for the old one.
+ coordinator.noteRateSample('user-1', { resource: 'core', limit: 5_000, remaining: 12, resetAt: 2_000_000 + 3_600_000 })
await timers[0]()
- expect(deltas.slice(held)).toEqual([[]])
+ expect(deltas.slice(held)).toEqual([[], []])
+ })
+})
+
+describe('GitHubIssueService notifyProject', () => {
+ it('prompts only that project\'s subscribers to re-read', async () => {
+ const client = new FixtureClient([issue(1)])
+ const deltas: Array<[number, string, number[]]> = []
+ const service = new GitHubIssueService({
+ cache: new GitHubIssueCache(userDataDir), coordinator: new GitHubRequestCoordinator(),
+ contextForProject: async (projectId) => context(client, { projectId }), now: () => 10_000,
+ onDelta: (uiId, projectId, numbers) => deltas.push([uiId, projectId, numbers])
+ })
+ await service.subscribe(7, { projectId: 'project-1' })
+ await service.subscribe(8, { projectId: 'project-2' })
+ deltas.length = 0
+
+ service.notifyProject('project-1')
+
+ expect(deltas).toEqual([[7, 'project-1', []]])
})
})
diff --git a/src/core/github/service.ts b/src/core/github/service.ts
index fba8ace88..ab1ecd841 100644
--- a/src/core/github/service.ts
+++ b/src/core/github/service.ts
@@ -808,7 +808,14 @@ export class GitHubIssueService {
.catch((error: unknown) =>
error instanceof ConfigurationChangedError ? null : Promise.reject(error))
if (!beat) return
- if (beat.notModified && !full && previous && !state.incomplete) return
+ if (beat.notModified && !full && previous && !state.incomplete) {
+ // Nothing to fetch — but subscribers still re-read their pages, from the local cache, as every
+ // successful refresh has always made them do. A page is not only issues: read only, the
+ // mapping approval and the completion column are derived by the host at query time, and a
+ // board never prompted keeps showing the old answer (e.g. read only after its approval).
+ this.emitDelta(state, [], true)
+ return
+ }
const heartbeatEtag = beat.etag
const etags: Record<string, string> = heartbeatEtag ? { [HEARTBEAT_ETAG_KEY]: heartbeatEtag } : {}
let page = 1
@@ -914,8 +921,9 @@ export class GitHubIssueService {
// would stop us ever trying the next subscriber's context.
// It IS a background refresh, though, so the rate budget may hold it.
const throttle = await this.refreshWithinFloor({ projectId }, undefined, true)
+ // A refresh that ran prompted its subscribers itself (a 304 included), which is also what
+ // clears a lifted "held until" line from the board.
if (throttle) this.announceThrottle(state, throttle.until)
- else this.announceThrottleLifted(state)
return
} catch (error) {
const failure = classifyGitHubFailure(error)
@@ -935,12 +943,15 @@ export class GitHubIssueService {
this.emitDelta(state, [], true)
}
- /** The poll ran again. A 304 heartbeat emits nothing, so without this the board would keep
- * saying "paused until HH:MM" long after that time — prompt a re-read once when the hold ends. */
- private announceThrottleLifted(state: RepositoryState): void {
- if (state.announcedThrottleUntil === undefined) return
- delete state.announcedThrottleUntil
- this.emitDelta(state, [], true)
+ /** Prompts one project's subscribers to re-read their pages. For a change the host makes that
+ * no refresh would report — an approval given or withdrawn — so the board does not wait for the
+ * next poll (or, before polls re-prompted, for something to change on GitHub). */
+ notifyProject(projectId: string): void {
+ const key = this.projectKeys.get(projectId)
+ const state = key ? this.repositories.get(key) : undefined
+ for (const uiId of state?.subscribers.get(projectId) ?? []) {
+ this.options.onDelta?.(uiId, projectId, [])
+ }
}
private migrateProjectState(projectId: string, key: string, target: RepositoryState): void {