fix(server): the PR of a branch renamed in the thread's worktree is found in the same turn #28508
ClosedGourav224(GitHub profile, opens in a new tab)wants to merge 8 commits into
main fromrefs/pull/28508/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/server/src/orchestration-v2/RunFinalizationService.ts lines 96 to 96OutdatedResolvedby maria-rcks@@ -54,0 +74,21 @@74+ const thread = yield* projections.getThreadShell(input.threadId);75+ if (76+ !thread ||77+ thread.branch === null ||78+ thread.branch === input.checkedOutBranch ||79+ thread.worktreePath !== input.cwd80+ ) {81+ return;82+ }83+ const worktrees = yield* projections.getThreadWorktreePaths({ includeArchived: true });84+ if (85+ worktrees.some((other) => other.threadId !== thread.id && other.worktreePath === input.cwd)86+ ) {87+ return;88+ }89+ yield* threads.dispatch({90+ type: "thread.metadata.update",91+ commandId: CommandId.make(`server:worktree-branch:${input.runId}`),92+ threadId: thread.id,93+ branch: input.checkedOutBranch,94+ expectedBranch: thread.branch,
- @@ -54,0 +76,21 @@76+ !thread ||77+ thread.branch === null ||78+ thread.branch === input.checkedOutBranch ||79+ thread.worktreePath !== input.cwd80+ ) {81+ return;82+ }83+ const worktrees = yield* projections.getThreadWorktreePaths({ includeArchived: true });84+ if (85+ worktrees.some((other) => other.threadId !== thread.id && other.worktreePath === input.cwd)86+ ) {87+ return;88+ }89+ yield* threads.dispatch({90+ type: "thread.metadata.update",91+ commandId: CommandId.make(`server:worktree-branch:${input.runId}`),92+ threadId: thread.id,93+ branch: input.checkedOutBranch,94+ expectedBranch: thread.branch,95+ expectedWorktreePath: input.cwd,96+ });@@ -139,0 +164,21 @@164+ otherWorktrees: [],165+ expected: [],166+ },167+ {168+ label: "keeps the recorded branch in a worktree another thread shares",169+ checkedOut: "feat/renamed",170+ worktreePath: "/repo",171+ otherWorktrees: ["/repo"],172+ expected: [],173+ },174+ ] as const175+ ).map((scenario) => [scenario.label, scenario] as const),176+)("%s", ([, scenario]) => {177+ const threadId = ThreadId.make("thread-branch-drift");178+ const runId = RunId.make("run-branch-drift");179+ const scopeId = CheckpointScopeId.make("scope-branch-drift");180+ const updates: Array<{181+ branch: unknown;182+ expectedBranch: unknown;183+ expectedWorktreePath: unknown;184+ }> = [];@@ -139,0 +206,21 @@206+ threadId: ThreadId.make("thread-other"),207+ worktreePath,208+ })),209+ ]),210+ }),211+ Layer.mock(ThreadManagement.ThreadManagementService)({212+ dispatch: (command) =>213+ Effect.sync(() => {214+ assert.equal(command.type, "thread.metadata.update");215+ if (command.type === "thread.metadata.update") {216+ updates.push({217+ branch: command.branch,218+ expectedBranch: command.expectedBranch,219+ expectedWorktreePath: command.expectedWorktreePath,220+ });221+ }222+ return {} as never;223+ }),224+ }),225+ Layer.succeed(RunFinalization.RunFinalizationObserver, {226+ refresh: () => Effect.succeed(scenario.checkedOut),@@ -139,0 +222,21 @@222+ return {} as never;223+ }),224+ }),225+ Layer.succeed(RunFinalization.RunFinalizationObserver, {226+ refresh: () => Effect.succeed(scenario.checkedOut),227+ refreshAfterTurn: () => Effect.void,228+ }),229+ ),230+ ),231+ );232+ return Effect.gen(function* () {233+ const service = yield* RunFinalization.RunFinalizationService;234+ yield* service.finalize({ threadId, runId, scopeId });235+ assert.deepEqual(236+ updates,237+ scenario.expected.map((branch) => ({238+ branch,239+ expectedBranch: "fix/original",240+ expectedWorktreePath: "/repo",241+ })),242+ );
TonybynMp4(GitHub profile, opens in a new tab) approved these changes
- apps/server/src/orchestration-v2/RunFinalizationService.ts line 98OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -54,0 +78,21 @@78+ thread.branch === input.checkedOutBranch ||79+ thread.worktreePath !== input.cwd80+ ) {81+ return;82+ }83+ const worktrees = yield* projections.getThreadWorktreePaths({ includeArchived: true });84+ if (85+ worktrees.some((other) => other.threadId !== thread.id && other.worktreePath === input.cwd)86+ ) {87+ return;88+ }89+ yield* threads.dispatch({90+ type: "thread.metadata.update",91+ commandId: CommandId.make(`server:worktree-branch:${input.runId}`),92+ threadId: thread.id,93+ branch: input.checkedOutBranch,94+ expectedBranch: thread.branch,95+ expectedWorktreePath: input.cwd,96+ });97+ // The first refresh skipped the PR lookup because the thread still had the old branch.98+ yield* observer.refresh({ cwd: input.cwd, threadId: thread.id, runId: input.runId });
juliusmarminge requested changes
tanstack-source added labelsbug
Gourav224(GitHub profile, opens in a new tab) linked this to fix #28463
Gourav224(GitHub profile, opens in a new tab) changed the title
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:L
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XS
juliusmarminge closed this
Sign in to join this conversation.





macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed