Feat/review agent worktree cache#142
Conversation
OpenDiff SummaryThis PR replaces fresh per-job clones with a cached bare-repo plus ephemeral worktree model in
FindingsOpenDiff completed the review and found 1 warning to consider before merging. New Issues
Addressed Since Earlier Reviews
Rating: 86/100 Reviewed by opendiff |
Remediation Summary✅ 1 issue fixed automatically ✅ Fixed
|
| const git = simpleGit(meta.mirrorDir); | ||
| await removeWorktreeFromMirror(git, dir); | ||
| if (typeof meta.worktreeBranchRef === "string") { | ||
| await deleteRefIfExists(git, meta.worktreeBranchRef); |
There was a problem hiding this comment.
prepareCachedWorktree() serializes fetch/worktree creation with withRepoLock(), but cached worktree teardown in cleanupWorkspace() talks to the same bare mirror without acquiring that lock. That means one job can be running git fetch or git worktree add against meta.mirrorDir while another job concurrently runs git worktree remove and update-ref -d on the same repository, which can lead to intermittent ref-lock failures or corrupted worktree metadata under load. The metadata file already stores repoId, so cleanup can participate in the same per-repo lock instead of mutating the mirror out of band.
| const git = simpleGit(meta.mirrorDir); | |
| await removeWorktreeFromMirror(git, dir); | |
| if (typeof meta.worktreeBranchRef === "string") { | |
| await deleteRefIfExists(git, meta.worktreeBranchRef); | |
| const meta = JSON.parse(rawMeta) as { | |
| repoId?: unknown; | |
| mirrorDir?: unknown; | |
| worktreeBranchRef?: unknown; | |
| }; | |
| if (typeof meta.repoId !== "string" || typeof meta.mirrorDir !== "string") { | |
| throw new Error("Worktree metadata is missing repoId or mirrorDir"); | |
| } | |
| await withRepoLock(config, meta.repoId, async () => { | |
| const git = simpleGit(meta.mirrorDir); | |
| await removeWorktreeFromMirror(git, dir); | |
| if (typeof meta.worktreeBranchRef === "string") { | |
| await deleteRefIfExists(git, meta.worktreeBranchRef); | |
| } | |
| }); |
Buncha stuff