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.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
fix(github): record merge-driven move claims per PR, not per PR set
review1b37a400fc49
diff --git a/src/core/github/pull-memory.test.ts b/src/core/github/pull-memory.test.tsindex 013674c53..b882082da 100644--- a/src/core/github/pull-memory.test.ts+++ b/src/core/github/pull-memory.test.ts@@ -8,7 +8,8 @@ import {emptyPullMemory,rememberPulls,rememberedForBoard,- validPullMemory+ validPullMemory,+ waitKey} from './pull-memory'const status = (number: number, lifecycle: PullLifecycle, over: Partial<GitHubPullStatus> = {}): GitHubPullStatus =>@@ -74,13 +75,40 @@ describe('rememberedForBoard', () => {describe('claims', () => {it('the first claim for a key wins — and only for a card noted waiting on one of its PRs', () => {- const noted = noteWaitsInMemory(emptyPullMemory(), ['wait|n|1'])- expect(claimInMemory(emptyPullMemory(), 'p|n|1', ['wait|n|1']).claimed).toBe(false)- const first = claimInMemory(noted, 'p|n|1', ['wait|n|1'])+ const noted = noteWaitsInMemory(emptyPullMemory(), [waitKey('p', 'n', 1)])+ expect(claimInMemory(emptyPullMemory(), 'p', 'n', [1]).claimed).toBe(false)+ const first = claimInMemory(noted, 'p', 'n', [1])expect(first.claimed).toBe(true)- expect(claimInMemory(first.memory, 'p|n|1', ['wait|n|1']).claimed).toBe(false)- expect(claimInMemory(first.memory, 'p|n|1,2', ['wait|n|1', 'wait|n|2']).claimed).toBe(true)- expect(noteWaitsInMemory(noted, ['wait|n|1'])).toBe(noted)+ expect(claimInMemory(first.memory, 'p', 'n', [1]).claimed).toBe(false)+ // Another card is its own claim.+ expect(claimInMemory(noteWaitsInMemory(first.memory, [waitKey('p', 'm', 1)]), 'p', 'm', [1]).claimed)+ .toBe(true)+ expect(noteWaitsInMemory(noted, [waitKey('p', 'n', 1)])).toBe(noted)+ })++ it('a claim is per PR: the set shrinking or growing by a merge this card never waited on never re-moves it', () => {+ // The card waited on #1 and #2 and was moved when both merged; the user dragged it back.+ const waited = noteWaitsInMemory(emptyPullMemory(), [waitKey('p', 'n', 1), waitKey('p', 'n', 2)])+ const moved = claimInMemory(waited, 'p', 'n', [1, 2])+ expect(moved.claimed).toBe(true)+ // #2 ages off the pull board, so the linked set is now {1}: the same merge, not a new one.+ expect(claimInMemory(moved.memory, 'p', 'n', [1]).claimed).toBe(false)+ // A PR it never saw open joins the set: still no transition observed for THIS card.+ expect(claimInMemory(moved.memory, 'p', 'n', [1, 3]).claimed).toBe(false)+ // A new PR the card DID wait on merges: that is a new transition, and it moves the card again.+ const waitedOnFour = noteWaitsInMemory(moved.memory, [waitKey('p', 'n', 4)])+ expect(claimInMemory(waitedOnFour, 'p', 'n', [1, 4]).claimed).toBe(true)+ })++ it('reads a claim recorded under the older set-of-PRs key as a claim on each of its PRs', () => {+ const legacy = {+ ...noteWaitsInMemory(emptyPullMemory(), [waitKey('p', 'n', 1), waitKey('p', 'n', 2)]),+ claims: ['p\0n\x001,2']+ }+ expect(validPullMemory(legacy)).toBe(true)+ expect(claimInMemory(legacy, 'p', 'n', [1]).claimed).toBe(false)+ expect(claimInMemory(legacy, 'p', 'n', [2]).claimed).toBe(false)+ expect(claimInMemory(legacy, 'p', 'n', [1, 2]).claimed).toBe(false)})it('rejects a malformed memory file', () => {diff --git a/src/core/github/pull-memory.ts b/src/core/github/pull-memory.tsindex cbf36624e..61450972c 100644--- a/src/core/github/pull-memory.ts+++ b/src/core/github/pull-memory.ts@@ -12,10 +12,12 @@// (which carries every PR's state), so an old merge is still noticed; one the harvest does not have// keeps its last known lifecycle, which for an open PR means "wait" — the safe answer.//-// It also holds CLAIMS: one per (project, card, set of PRs) that has been moved. Every board in every+// It also holds CLAIMS: one per (project, card, PR) that has moved the card. Every board in every// window asks the host before it moves a card, and only the first ask wins — so two Server Edition// tabs cannot both move the card, and a card the user dragged back is not moved again for the same-// merges.+// merges. A claim is per PR, never per SET of PRs: the linked set changes on its own (a merged PR+// ages off the pull board, an unrelated PR on the same branch joins it), and a set-keyed claim read+// every such change as a new transition and moved a card the user had dragged back.//// And WAIT NOTES: "card X was linked to PR #N while #N was still open". `mergedSeenAt` is a fact// about a PR, not about a card, so on its own it would let a card that first appeared AFTER the@@ -55,8 +57,8 @@ export function emptyPullMemory(): PullMemory {}/** The memory keys. `\0` cannot occur in a project id, a card id (both validated) or a number. */-export function claimKey(projectId: string, cardId: string, pulls: number[]): string {- return `${projectId}\0${cardId}\0${[...new Set(pulls)].sort((a, b) => a - b).join(',')}`+export function claimKey(projectId: string, cardId: string, pull: number): string {+ return `claim\0${projectId}\0${cardId}\0${pull}`}export function waitKey(projectId: string, cardId: string, pull: number): string {@@ -173,17 +175,39 @@ export function withObservations(status: GitHubPullStatus, remembered: Remembere}}-/** Records a claim; `claimed` is false when it was already there, or when none of `waitKeys` was- * ever noted (the card was never seen waiting on one of these PRs while it was open). */+/** The PRs that have already moved this card. Reads both key shapes: the per-PR one, and the+ * `<project>\0<card>\0<n,n,…>` set key an earlier build wrote, as a claim on each PR it lists. */+function claimedPulls(memory: PullMemory, projectId: string, cardId: string): Set<number> {+ const claimed = new Set<number>()+ for (const claim of memory.claims) {+ const parts = claim.split('\0')+ if (parts.length === 4 && parts[0] === 'claim' && parts[1] === projectId && parts[2] === cardId) {+ claimed.add(Number(parts[3]))+ } else if (parts.length === 3 && parts[0] === projectId && parts[1] === cardId) {+ for (const pull of parts[2].split(',')) claimed.add(Number(pull))+ }+ }+ return claimed+}++/**+ * Records a claim for moving `cardId` because `pulls` merged. `claimed` is true only when the set+ * holds a NEW transition for this card: a PR that has not moved it before AND that it was noted+ * waiting on while the PR was open. The same merges (whatever else joins or leaves the set) are+ * refused, and so is a card that first appeared after the merge.+ */export function claimInMemory(memory: PullMemory,- key: string,- waitKeys: string[]+ projectId: string,+ cardId: string,+ pulls: number[]): { memory: PullMemory; claimed: boolean } {- if (memory.claims.includes(key)) return { memory, claimed: false }+ const claimed = claimedPulls(memory, projectId, cardId)+ const fresh = [...new Set(pulls)].filter((pull) => !claimed.has(pull))const noted = new Set(memory.waits)- if (!waitKeys.some((wait) => noted.has(wait))) return { memory, claimed: false }- return { memory: { ...memory, claims: [...memory.claims, key].slice(-PULL_CLAIMS_MAX) }, claimed: true }+ if (!fresh.some((pull) => noted.has(waitKey(projectId, cardId, pull)))) return { memory, claimed: false }+ const keys = fresh.map((pull) => claimKey(projectId, cardId, pull))+ return { memory: { ...memory, claims: [...memory.claims, ...keys].slice(-PULL_CLAIMS_MAX) }, claimed: true }}/** Records wait notes; the same memory object back when every one was already there. */diff --git a/src/core/github/pull-status-tracker.test.ts b/src/core/github/pull-status-tracker.test.tsindex aeda0a971..8c8cdd90f 100644--- a/src/core/github/pull-status-tracker.test.ts+++ b/src/core/github/pull-status-tracker.test.ts@@ -221,6 +221,18 @@ describe('GitHubPullStatusTracker', () => {const restarted = tracker(0, store)expect(await restarted.subject.claimMove(KEY, 'p', 'n', [1])).toBe(false)expect(await restarted.subject.claimMove(KEY, 'p', 'n', [2])).toBe(true)+ // Both merges have moved it now; the set shrinking back to one of them is not a new merge.+ expect(await restarted.subject.claimMove(KEY, 'p', 'n', [2])).toBe(false)+ expect(await restarted.subject.claimMove(KEY, 'p', 'n', [1, 2])).toBe(false)+ })++ it('a dragged-back card stays put when one of its merged PRs ages off the pull board', async () => {+ const { subject } = tracker()+ await subject.read(KEY, 'user-1', 'heartbeat', async () => read([facts(1), facts(2)]))+ expect(await subject.noteWaits(KEY, 'p', 'n', [1, 2])).toBe(2)+ expect(await subject.claimMove(KEY, 'p', 'n', [1, 2])).toBe(true)+ // The user drags the card back; #2 later leaves the board, so the planner now asks for {1}.+ expect(await subject.claimMove(KEY, 'p', 'n', [1])).toBe(false)})it('a card that first appears after the merge never wins a claim', async () => {diff --git a/src/core/github/pull-status-tracker.ts b/src/core/github/pull-status-tracker.tsindex 2bea02134..0e8b16433 100644--- a/src/core/github/pull-status-tracker.ts+++ b/src/core/github/pull-status-tracker.ts@@ -30,7 +30,6 @@ import {import type { PullStatusRead } from './graphql-pulls'import {claimInMemory,- claimKey,emptyPullMemory,noteWaitsInMemory,rememberPulls,@@ -137,21 +136,18 @@ export class GitHubPullStatusTracker {}/**- * The one-time permission to move a card for a set of merged PRs. The first caller for a key wins,- * whichever window it comes from, and the claim is persisted — a card the user dragged back is not- * moved again for the same merges. Refused unless this card was noted WAITING on one of those PRs- * while it was open (`noteWaits`): a card that first appeared after the merge never moves.+ * The one-time permission to move a card for a set of merged PRs. The first caller wins, whichever+ * window it comes from, and the claim is persisted PER PR — a card the user dragged back is not+ * moved again for the same merges, even when the linked set later shrinks or grows. Refused unless+ * the set holds a PR that has not moved this card yet and that this card was noted WAITING on while+ * it was open (`noteWaits`): a card that first appeared after the merge never moves.*/async claimMove(key: string, projectId: string, cardId: string, pulls: number[]): Promise<boolean> {const state = this.stateFor(key)const generation = state.generationconst memory = await this.memoryFor(key, state)if (generation !== state.generation) return false- const { memory: next, claimed } = claimInMemory(- state.memory ?? memory,- claimKey(projectId, cardId, pulls),- pulls.map((pull) => waitKey(projectId, cardId, pull))- )+ const { memory: next, claimed } = claimInMemory(state.memory ?? memory, projectId, cardId, pulls)if (!claimed) return falsestate.memory = nextthis.persist(key, state)