-
Notifications
You must be signed in to change notification settings - Fork 3k
fix(review): make agent launches and cleanup resilient #7259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
wenshao
merged 11 commits into
QwenLM:main
from
wenshao:fix/review-agent-launch-cleanup
Jul 21, 2026
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
c783167
fix(review): make agent launches and cleanup resilient
wenshao e6b3cac
fix(review): address worktree cleanup feedback
wenshao 9c964d1
fix(review): harden cleanup follow-ups
wenshao 89881c7
Merge origin/main into fix/review-agent-launch-cleanup
wenshao 685524e
fix(review): merge main into agent-launch-cleanup branch
qwen-code-dev-bot e3392c1
Merge remote-tracking branch 'wenshao/fix/review-agent-launch-cleanup…
wenshao 3ff0839
fix(ci): sync autofix workflow assertions
wenshao bfb0c96
Merge branch 'main' into fix/review-agent-launch-cleanup
yiliang114 0729433
Merge remote branch updates into review cleanup fix
wenshao 27dfbeb
fix(review): close cancellation cleanup gaps
wenshao 7a74214
test(review): cover remaining review-cleanup feedback suggestions (#7…
qwen-code-ci-bot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| // Copyright 2026 Qwen Team | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import { beforeEach, describe, expect, it, vi } from 'vitest'; | ||
|
|
||
| const mocks = vi.hoisted(() => ({ | ||
| execFileSync: vi.fn(), | ||
| existsSync: vi.fn(() => false), | ||
| readdirSync: vi.fn(() => []), | ||
| rmSync: vi.fn(), | ||
| writeStdoutLine: vi.fn(), | ||
| writeStderrLine: vi.fn(), | ||
| clearReviewWorktreeLease: vi.fn(), | ||
| refExists: vi.fn(() => true), | ||
| releaseWorktree: vi.fn(() => ({ | ||
| existed: false, | ||
| freed: false, | ||
| reason: undefined, | ||
| })), | ||
| })); | ||
|
|
||
| vi.mock('node:child_process', async (importOriginal) => { | ||
| const actual = await importOriginal<typeof import('node:child_process')>(); | ||
| return { | ||
| ...actual, | ||
| default: { ...actual, execFileSync: mocks.execFileSync }, | ||
| execFileSync: mocks.execFileSync, | ||
| }; | ||
| }); | ||
|
|
||
| vi.mock('node:fs', async (importOriginal) => { | ||
| const actual = await importOriginal<typeof import('node:fs')>(); | ||
| return { | ||
| ...actual, | ||
| default: { | ||
| ...actual, | ||
| existsSync: mocks.existsSync, | ||
| readdirSync: mocks.readdirSync, | ||
| rmSync: mocks.rmSync, | ||
| }, | ||
| existsSync: mocks.existsSync, | ||
| readdirSync: mocks.readdirSync, | ||
| rmSync: mocks.rmSync, | ||
| }; | ||
| }); | ||
|
|
||
| vi.mock('../../utils/stdioHelpers.js', () => ({ | ||
| writeStdoutLine: mocks.writeStdoutLine, | ||
| writeStderrLine: mocks.writeStderrLine, | ||
| })); | ||
|
|
||
| vi.mock('../../services/review-worktree-lease.js', () => ({ | ||
| clearReviewWorktreeLease: mocks.clearReviewWorktreeLease, | ||
| })); | ||
|
|
||
| vi.mock('./lib/git.js', () => ({ | ||
| refExists: mocks.refExists, | ||
| releaseWorktree: mocks.releaseWorktree, | ||
| })); | ||
|
|
||
| vi.mock('./lib/paths.js', () => ({ | ||
| worktreePath: (prNumber: string) => `/repo/.qwen/tmp/review-pr-${prNumber}`, | ||
| probeWorktreePath: (path: string) => `${path}-probe`, | ||
| reviewBranch: (prNumber: string) => `qwen-review/pr-${prNumber}`, | ||
| REVIEW_TMP_DIR: '/repo/.qwen/tmp', | ||
| tmpPrefix: (target: string) => `qwen-review-${target}-`, | ||
| })); | ||
|
|
||
| import { runCleanup } from './cleanup.js'; | ||
|
|
||
| describe('runCleanup', () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| mocks.existsSync.mockReturnValue(false); | ||
| mocks.refExists.mockReturnValue(true); | ||
| mocks.releaseWorktree.mockReturnValue({ | ||
| existed: false, | ||
| freed: false, | ||
| reason: undefined, | ||
| }); | ||
| }); | ||
|
|
||
| it('keeps the lease when branch deletion fails', () => { | ||
| mocks.execFileSync.mockImplementation(() => { | ||
| throw new Error('branch is locked'); | ||
| }); | ||
|
|
||
| runCleanup('pr-123'); | ||
|
|
||
| expect(mocks.execFileSync).toHaveBeenCalledWith( | ||
| 'git', | ||
| ['branch', '-D', 'qwen-review/pr-123'], | ||
| { stdio: 'pipe' }, | ||
| ); | ||
| expect(mocks.writeStderrLine).toHaveBeenCalledWith( | ||
| expect.stringContaining('Failed to delete branch qwen-review/pr-123'), | ||
| ); | ||
| expect(mocks.clearReviewWorktreeLease).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('clears the lease when cleanup succeeds', () => { | ||
| mocks.execFileSync.mockReturnValue(Buffer.from('')); | ||
|
|
||
| runCleanup('pr-123'); | ||
|
|
||
| expect(mocks.clearReviewWorktreeLease).toHaveBeenCalledWith( | ||
| process.cwd(), | ||
| 'pr-123', | ||
| ); | ||
| }); | ||
| }); | ||
|
wenshao marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.