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): bound check-detail reads; never auto-move a relay tab's board

reviewbf4ffd8b4a99
diff --git a/src/core/github/service.pulls.test.ts b/src/core/github/service.pulls.test.ts
index 5de8c1ff6..750978890 100644
--- a/src/core/github/service.pulls.test.ts
+++ b/src/core/github/service.pulls.test.ts
@@ -139,10 +139,34 @@ describe('GitHubIssueService pull status', () => {
h.client.failChecks = Object.assign(new Error('insufficient-permission'), { code: 'insufficient-permission', status: 403 })
expect(await h.service.pullChecks({ projectId: 'project-1', pullNumber: 1 })).toEqual({ status: 'hidden' })
h.client.failChecks = Object.assign(new Error('request-failed'), { code: 'request-failed', status: 502 })
+ h.advance(15_000)
expect(await h.service.pullChecks({ projectId: 'project-1', pullNumber: 1 })).toEqual({ status: 'unavailable' })
expect(await h.service.pullChecks({ projectId: 'project-1', pullNumber: -3 })).toEqual({ status: 'unavailable' })
})
+ it('bounds check-detail reads: one per PR per 15 s, ten per project per minute', async () => {
+ const h = harness()
+ h.client.checks = { status: 'no-checks' }
+ await h.service.pullChecks({ projectId: 'project-1', pullNumber: 1 })
+ await h.service.pullChecks({ projectId: 'project-1', pullNumber: 1 })
+ expect(h.client.checkReads).toBe(1)
+ for (let number = 2; number <= 10; number++) {
+ await h.service.pullChecks({ projectId: 'project-1', pullNumber: number })
+ }
+ expect(h.client.checkReads).toBe(10)
+ const contexts = h.contexts()
+ for (let number = 11; number <= 20; number++) {
+ expect(await h.service.pullChecks({ projectId: 'project-1', pullNumber: number }))
+ .toEqual({ status: 'unavailable' })
+ }
+ expect(h.client.checkReads).toBe(10)
+ // Refused before a context (the credential chain) is resolved.
+ expect(h.contexts()).toBe(contexts)
+ h.advance(60_000)
+ await h.service.pullChecks({ projectId: 'project-1', pullNumber: 21 })
+ expect(h.client.checkReads).toBe(11)
+ })
+
it('does not ask for check detail once the list read showed the token cannot read checks', async () => {
const h = harness()
h.client.pullRequestStatuses = async () => {
diff --git a/src/core/github/service.ts b/src/core/github/service.ts
index c3e00bd38..e0dbfdb13 100644
--- a/src/core/github/service.ts
+++ b/src/core/github/service.ts
@@ -46,6 +46,13 @@ export const HEARTBEAT_ETAG_KEY = 'heartbeat'
export const REFRESH_MIN_INTERVAL_MS = 30_000
export const FULL_REFRESH_MIN_INTERVAL_MS = 120_000
+/** Check detail is read when a PR's modal opens — reachable from the renderer AND a relay guest,
+ * and each read is a GraphQL request plus a credential resolve. So: the same PR within this window
+ * shares one read, and a project gets at most `PULL_CHECKS_PER_MINUTE` reads a minute. Both are
+ * checked before anything is resolved or sent. */
+export const PULL_CHECKS_REUSE_MS = 15_000
+export const PULL_CHECKS_PER_MINUTE = 10
+
export interface GitHubIssuesClientLike {
listIssues(repository: string, options: ListIssueOptions): Promise<IssuePageResult>
issuesHeartbeat(repository: string, etag?: string): Promise<IssueHeartbeatResult>
@@ -213,6 +220,8 @@ export class GitHubIssueService {
private readonly refreshFloors = new Map<string, { any: number; full: number }>()
/** Pull request CI/mergeability per repository key — see pull-status-tracker.ts. */
private readonly pulls: GitHubPullStatusTracker
+ private readonly checkReads = new Map<string, { at: number; result: Promise<GitHubPullChecksResult> }>()
+ private readonly checkStarts = new Map<string, number[]>()
private operationSequence = 0
private readonly now: () => number
private readonly schedule: NonNullable<ServiceOptions['setInterval']>
@@ -712,6 +721,25 @@ export class GitHubIssueService {
if (!Number.isSafeInteger(request.pullNumber) || request.pullNumber < 1) {
return { status: 'unavailable' }
}
+ const now = this.now()
+ const key = `${request.projectId}\0${request.pullNumber}`
+ const recent = this.checkReads.get(key)
+ if (recent && now - recent.at < PULL_CHECKS_REUSE_MS) return recent.result
+ const starts = (this.checkStarts.get(request.projectId) ?? []).filter((at) => now - at < 60_000)
+ if (starts.length >= PULL_CHECKS_PER_MINUTE) {
+ this.checkStarts.set(request.projectId, starts)
+ return { status: 'unavailable' }
+ }
+ this.checkStarts.set(request.projectId, [...starts, now])
+ for (const [candidate, entry] of this.checkReads) {
+ if (now - entry.at >= PULL_CHECKS_REUSE_MS) this.checkReads.delete(candidate)
+ }
+ const result = this.readPullChecks(request)
+ this.checkReads.set(key, { at: now, result })
+ return result
+ }
+
+ private async readPullChecks(request: { projectId: string; pullNumber: number }): Promise<GitHubPullChecksResult> {
let captured: GitHubIssueServiceContext
try {
captured = await this.options.contextForProject(request.projectId)
diff --git a/src/renderer/components/kanban/usePullAutoMove.test.tsx b/src/renderer/components/kanban/usePullAutoMove.test.tsx
new file mode 100644
index 000000000..42bacf079
--- /dev/null
+++ b/src/renderer/components/kanban/usePullAutoMove.test.tsx
@@ -0,0 +1,63 @@
+// @vitest-environment jsdom
+import { act } from 'react'
+import { createRoot } from 'react-dom/client'
+import { beforeEach, describe, expect, it, vi } from 'vitest'
+import type { ProjectKanban } from '@shared/types'
+import type { GitHubPullBoard } from '@shared/github-pull-status'
+import { useProjects } from '../../state/projects'
+import { useSettings } from '../../state/settings'
+import { usePullAutoMove } from './usePullAutoMove'
+
+;(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true
+
+const board: ProjectKanban = {
+ columns: [{ id: 'doing', title: 'Doing', color: '#fff' }, { id: 'done', title: 'Done', color: '#fff' }],
+ assignments: [{ nodeId: 'card-1', columnId: 'doing' }],
+ github: { columnMappings: [], repository: 'o/r' }
+}
+const cards = [{ id: 'card-1', kind: 'terminal', worktreeBranch: 'feat/x' }]
+const merged: GitHubPullBoard = {
+ pulls: [{ number: 12, lifecycle: 'merged', headRefName: 'feat/x', closes: [] }],
+ observedAt: 1, stale: false, access: { ci: true, merge: true }, undecided: false, truncated: false
+}
+
+function Probe(props: { pullBoard: GitHubPullBoard; onAutoMove: (...args: unknown[]) => void }): null {
+ usePullAutoMove({ projectId: 'p1', cards, board, pullBoard: props.pullBoard, onAutoMove: props.onAutoMove })
+ return null
+}
+
+function arm(remote = false): void {
+ useProjects.setState({
+ activeProjectId: 'p1',
+ projects: [{ id: 'p1', name: 'P', color: '#fff', viewport: { x: 0, y: 0, zoom: 1 }, nodes: [], ...(remote ? { remote: true } : {}) }]
+ } as never)
+ useSettings.setState((state) => ({
+ settings: {
+ ...state.settings,
+ kanbanPullAutoMove: { projects: { p1: { columnId: 'done', seen: { 'card-1': { '12': 'open' } } } } }
+ }
+ }))
+}
+
+beforeEach(() => arm())
+
+describe('usePullAutoMove', () => {
+ it('moves once on the observed merge and records it, so a re-run does not move again', () => {
+ const onAutoMove = vi.fn()
+ const host = document.createElement('div')
+ const root = createRoot(host)
+ act(() => root.render(<Probe pullBoard={merged} onAutoMove={onAutoMove} />))
+ act(() => root.render(<Probe pullBoard={{ ...merged }} onAutoMove={onAutoMove} />))
+ expect(onAutoMove).toHaveBeenCalledTimes(1)
+ expect(onAutoMove).toHaveBeenCalledWith('card-1', 'doing', 'done', 'PR #12 merged')
+ expect(useSettings.getState().settings.kanbanPullAutoMove?.projects.p1.seen)
+ .toEqual({ 'card-1': { '12': 'merged' } })
+ })
+
+ it('never moves a card on a relay tab — that board belongs to the other machine', () => {
+ arm(true)
+ const onAutoMove = vi.fn()
+ act(() => createRoot(document.createElement('div')).render(<Probe pullBoard={merged} onAutoMove={onAutoMove} />))
+ expect(onAutoMove).not.toHaveBeenCalled()
+ })
+})
diff --git a/src/renderer/components/kanban/usePullAutoMove.ts b/src/renderer/components/kanban/usePullAutoMove.ts
index e8fa5adc0..f408b3441 100644
--- a/src/renderer/components/kanban/usePullAutoMove.ts
+++ b/src/renderer/components/kanban/usePullAutoMove.ts
@@ -4,6 +4,7 @@ import type { GitHubIssuesApi } from '@shared/github-issues'
import type { GitHubPullBoard } from '@shared/github-pull-status'
import { sanitizeKanbanPullAutoMove } from '@shared/kanban-pull-links'
import { useSettings } from '../../state/settings'
+import { useProjects } from '../../state/projects'
import { autoMoveNote, planPullAutoMoves } from '../../lib/pullAutoMove'
import { documentChaseDeps, startPullChase } from '../../lib/pullChase'
@@ -21,9 +22,12 @@ export function usePullAutoMove(input: {
onAutoMove?: (cardId: string, fromColumnId: string | null, toColumnId: string, note: string) => void
}): void {
const raw = useSettings((state) => state.settings.kanbanPullAutoMove)
+ // A relay tab is another machine's project: that machine decides whether its board moves itself.
+ // Settings refuses to arm one; this is the backstop for a hand-edited settings.json.
+ const relay = useProjects((state) => !!state.projects.find((item) => item.id === input.projectId)?.remote)
const entry = useMemo(
- () => sanitizeKanbanPullAutoMove(raw).projects[input.projectId],
- [raw, input.projectId]
+ () => relay ? undefined : sanitizeKanbanPullAutoMove(raw).projects[input.projectId],
+ [raw, input.projectId, relay]
)
const { projectId, cards, board, pullBoard, onAutoMove } = input
useEffect(() => {