Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog.d/pan-5990.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#### Fixed

- **Closed-issue cleanup keeps work that `git status` cannot see:** before it removes a merged issue's workspace, cleanup now also keeps the folder, both branches and the stack's volumes when a checkout holds a commit that neither the target branch nor the merged feature branch holds (on a detached HEAD, another branch or a `.swarm/` worker branch, or in the branches or stash of a repository that lives inside the workspace folder), or has a rebase, merge, cherry-pick, revert or bisect in progress. It also keeps them when a gitignored `.env` or `.env.*` file (not `.env.example`), a `.sql`, `.dump`, `.sqlite` or `.db` file outside `node_modules/`, or anything under `.tmp/` is present. Build and cache output never blocks cleanup, and neither does an `.env` that Overdeck rendered from `workspace.env.template`. ([#5990](https://github.com/eltmon/overdeck/issues/5990))
- **Cleanup recognises Overdeck's own files by exact path:** only the files Overdeck writes under `.overdeck/` (such as `continue.json`, `pipeline.jsonl` and `verification/`) count as runtime. Any other untracked file there, for example a new file under `.overdeck/context/`, keeps the workspace. Synced skills and agents that are unchanged since the sync, the project agent template's files, the rendered `.mcp.json` and an unchanged `.hume-config` no longer keep old polyrepo workspaces forever. A file you add to `.claude/skills/` yourself still keeps the workspace, even when `.claude/` is gitignored. ([#5990](https://github.com/eltmon/overdeck/issues/5990))
- **GitLab merges are proven like GitHub ones:** a merged GitLab merge request now counts for cleanup only if it comes from the same project, merged into the target branch, and has its merge or squash commit on that branch. If GitLab does not report one of these facts, nothing is removed. ([#5990](https://github.com/eltmon/overdeck/issues/5990))
2 changes: 2 additions & 0 deletions configuration/polyrepo.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ The workspace root becomes a small local repository (no remote) when planning co

If a workspace was created before Overdeck started writing these entries, the next agent start from the dashboard repairs it automatically; no manual step is needed. Anything else left uncommitted at the workspace root still stops a start, exactly as before.

When a closed issue's workspace is cleaned up, the root repository's commits may touch only its `.gitignore` and Overdeck's pipeline records (such as `.pan/continues/` and `.pan/specs/`). A commit of anything else, such as a PRD draft under `.pan/drafts/`, keeps the workspace. Cleanup recognises the files Overdeck wrote at the root by exact path, even in a workspace created before the `.gitignore` entries: synced skills and agents that `.claude/.overdeck-manifest.json` lists and that are unchanged, the agent template's `copy_dirs` files and rendered templates such as `.mcp.json`, and an unchanged `.hume-config`. A file you add to `.claude/skills/` yourself keeps the workspace.

## Template Placeholders

| Placeholder | Example | Description |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ describe('reapIssueResidue when the forge reports a merged PR (PAN-5959)', () =>
describe('uncommitted work in a merged workspace (PAN-5979)', () => {
it('reaps nothing when a tracked file has an uncommitted change', async () => {
writeFileSync(join(workspacePath, 'feature.txt'), 'edited, not committed\n');
await expectNothingReaped('uncommitted work kept');
await expectNothingReaped('work kept');
});

it('reaps nothing when a change is staged', async () => {
Expand Down Expand Up @@ -264,6 +264,20 @@ describe('reapIssueResidue when the forge reports a merged PR (PAN-5959)', () =>
});
});

describe('work git status cannot see (PAN-5990)', () => {
it('reaps nothing when a detached HEAD holds a commit on neither main nor the feature branch', async () => {
git(workspacePath, 'switch', '-q', '--detach');
commitFile(workspacePath, 'detached.txt', 'detached work\n', 'detached work');
await expectNothingReaped('detached HEAD');
});

it('reaps nothing when the workspace holds a gitignored .env', async () => {
writeFileSync(join(projectPath, '.git', 'info', 'exclude'), '.env\n');
writeFileSync(join(workspacePath, '.env'), 'SECRET=local\n');
await expectNothingReaped('gitignored files the reap would delete');
});
});

describe('the merged PR must have merged into the target (PAN-5979)', () => {
it('reaps nothing when the PR merged into another base', async () => {
mocks.mergedPr = { ...mocks.mergedPr!, baseRefName: 'release' };
Expand Down
2 changes: 1 addition & 1 deletion src/lib/cloister/__tests__/reap-issue-residue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ describe('reapIssueResidue', () => {
expect(mocks.reapWorkerWorktrees).not.toHaveBeenCalled();
expect(mocks.exec.mock.calls.some((call) => String(call[0]).startsWith('git branch -D'))).toBe(false);
expect(mocks.exec.mock.calls.some((call) => String(call[0]).startsWith('git push origin --delete'))).toBe(false);
expect(actions.some((action) => action.includes('uncommitted work kept') && action.includes('src/wip.ts'))).toBe(true);
expect(actions.some((action) => action.includes('work kept') && action.includes('src/wip.ts'))).toBe(true);
});

it('keeps everything when the uncommitted-work check itself throws (PAN-5979)', async () => {
Expand Down
5 changes: 4 additions & 1 deletion src/lib/cloister/reap-issue-residue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ export async function reapIssueResidue(projectPath: string, issueId: string): Pr
// A merged branch proves nothing about the working trees: the folder (and
// every `.swarm/worker-<n>` worktree in it) is force-removed below, so any
// uncommitted work keeps the folder, the branches and the volumes (PAN-5979).
// So do commits the merged branch does not hold, a rebase or merge in
// progress, precious gitignored files (`.env*`, dumps, `.tmp/`) and files in
// the synced `.claude/` folders that pan sync did not write (PAN-5990).
// Decided before the teardown, which wipes volumes exactly when reapDisk.
let dirtyReason: string | null = null;
if (reapDisk) {
Expand Down Expand Up @@ -115,7 +118,7 @@ export async function reapIssueResidue(projectPath: string, issueId: string): Pr

if (!reapDisk) {
actions.push(dirtyReason
? `skipped disk reap for ${issueId} — uncommitted work kept (${dirtyReason})`
? `skipped disk reap for ${issueId} — work kept (${dirtyReason})`
: `skipped disk reap for ${issueId} — merge not proven (${mergeProof})`);
return actions;
}
Expand Down
48 changes: 32 additions & 16 deletions src/lib/forge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ export interface CreateReviewArtifactResult extends ReviewArtifactRef {
/** Merged lookups: the artifact's head commit when the forge reports it. */
headSha?: string;
/**
* GitHub merged lookups (PAN-5964): the PR's base branch, its merge commit,
* and whether it came from a fork, when the forge reports them. The
* closed-issue reaper refuses a merge it cannot prove with all three
* (`mergedIntoTargetRefusal`, PAN-5979).
* Merged lookups (GitHub PAN-5964, GitLab PAN-5990): the PR's or MR's base
* branch, its merge commit, and whether it came from a fork, when the forge
* reports them. The closed-issue reaper refuses a merge it cannot prove with
* all three (`mergedIntoTargetRefusal`, PAN-5979).
*/
baseRefName?: string;
mergeCommitOid?: string;
Expand Down Expand Up @@ -408,25 +408,41 @@ async function findMergedGitLabArtifact(
encoding: 'utf-8',
timeout: FORGE_OBSERVATION_TIMEOUT_MS,
});
const artifacts = target ? [JSON.parse(stdout.trim())] : JSON.parse(stdout.trim() || '[]') as Array<{
iid?: number; web_url?: string; state?: string; source_branch?: string;
target_branch?: string; sha?: string;
}>;
const merged = artifacts.find((artifact: {
iid?: number; web_url?: string; state?: string; source_branch?: string;
target_branch?: string; sha?: string;
}) => artifact.state === 'merged' && matchesCurrentArtifact(input, {
sourceBranch: artifact.source_branch,
targetBranch: artifact.target_branch,
headSha: artifact.sha,
}));
const artifacts = (target ? [JSON.parse(stdout.trim())] : JSON.parse(stdout.trim() || '[]')) as GlabMergedMr[];
// PAN-5990: a fork's MR can share the branch name, as with GitHub; a listed
// MR known to come from another project is dropped, as `gh pr list` rows are.
const merged = artifacts.find((artifact) => artifact.state === 'merged'
&& (target !== undefined || glabIsCrossProject(artifact) !== true)
&& matchesCurrentArtifact(input, {
sourceBranch: artifact.source_branch,
targetBranch: artifact.target_branch,
headSha: artifact.sha,
}));
return merged ? {
forge: 'gitlab', created: false, url: merged.web_url,
id: merged.iid ? String(merged.iid) : input.artifactId,
headSha: merged.sha,
baseRefName: merged.target_branch,
// A merge-commit MR records `merge_commit_sha`; a fast-forward squash
// records only `squash_commit_sha`. Either is the commit on the target.
mergeCommitOid: merged.merge_commit_sha || merged.squash_commit_sha || undefined,
isCrossRepository: glabIsCrossProject(merged),
} : null;
}

type GlabMergedMr = {
iid?: number; web_url?: string; state?: string; source_branch?: string;
target_branch?: string; sha?: string;
merge_commit_sha?: string | null; squash_commit_sha?: string | null;
source_project_id?: number | null; target_project_id?: number | null;
};

/** Whether the MR comes from another project (a fork), or undefined when GitLab does not say. */
function glabIsCrossProject(mr: GlabMergedMr): boolean | undefined {
if (typeof mr.source_project_id !== 'number' || typeof mr.target_project_id !== 'number') return undefined;
return mr.source_project_id !== mr.target_project_id;
}

function delay(ms: number): Promise<void> {
return new Promise((resolve) => setTimeout(resolve, ms));
}
Expand Down
34 changes: 30 additions & 4 deletions src/lib/lifecycle/verify-merged.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,10 @@ export async function verifyBranchMergedImpl(

interface GitLabMergeLookupCache {
attempted: boolean;
artifact?: { id?: string; url?: string; headSha?: string } | null;
artifact?: {
id?: string; url?: string; headSha?: string;
baseRefName?: string; mergeCommitOid?: string; isCrossRepository?: boolean;
} | null;
}

/** The PAN-2406 / FR-5 post-merge delta judgment, shared by the GitHub PR and GitLab MR paths. */
Expand Down Expand Up @@ -477,6 +480,24 @@ async function verifySquashMergedMrByBranch(
const artifact = lookup.artifact;
if (!artifact?.headSha) return null;

// PAN-5990: the same proof the GitHub path demands (PAN-5979), checked
// before the head match: same project, based on the target, merge commit
// on the target. A missing fact is a refusal.
if (root.requireBranchCovered) {
const refusal = await mergedIntoTargetRefusal(root, {
headRefOid: artifact.headSha,
baseRefName: artifact.baseRefName,
mergeCommitOid: artifact.mergeCommitOid,
isCrossRepository: artifact.isCrossRepository,
}, comparison.ref, artifact.id ? `MR !${artifact.id}` : 'the merged GitLab MR');
if (refusal) {
return {
result: stepFailed('close-out:verify-merged', `Merge into ${root.targetBranch} not proven for ${branchRef}: ${refusal}`),
reused,
};
}
}

if (tipSha === artifact.headSha) {
const label = artifact.id ? `MR !${artifact.id}` : 'GitLab MR';
const url = artifact.url ? ` (${artifact.url})` : '';
Expand All @@ -503,10 +524,15 @@ async function verifySquashMergedMrByBranch(
* or null when it does. The PR must come from this repository (a fork's PR
* can share the branch name, and `gh pr list --head` does not filter by
* owner), its base must be the target, and its merge commit must be on the
* target ref. A missing field is a refusal.
* target ref. A missing field is a refusal. PAN-5990: a merged GitLab MR is
* judged the same way, under its own `label`.
*/
async function mergedIntoTargetRefusal(root: MergeVerificationRoot, pr: MergedPrFacts, targetRef: string): Promise<string | null> {
const label = typeof pr.number === 'number' ? `PR #${pr.number}` : 'the merged GitHub PR';
async function mergedIntoTargetRefusal(
root: MergeVerificationRoot,
pr: MergedPrFacts,
targetRef: string,
label = typeof pr.number === 'number' ? `PR #${pr.number}` : 'the merged GitHub PR',
): Promise<string | null> {
if (pr.isCrossRepository !== false) {
return pr.isCrossRepository === true
? `${label} comes from another repository (a fork)`
Expand Down
Loading
Loading