Skip to content

Fix/delete branch#2955

Open
shagun-singh-inkeep wants to merge 5 commits intomainfrom
fix/delete-branch
Open

Fix/delete branch#2955
shagun-singh-inkeep wants to merge 5 commits intomainfrom
fix/delete-branch

Conversation

@shagun-singh-inkeep
Copy link
Copy Markdown
Collaborator

@shagun-singh-inkeep shagun-singh-inkeep commented Apr 1, 2026

Fixes project deletion to clean up all branches and runtime entities, not just the main branch. Previously, deleting a project left orphaned Doltgres branches and branch-scoped runtime rows behind.

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 1, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
agents-api Ready Ready Preview, Comment Apr 2, 2026 9:42pm
agents-docs Ready Ready Preview, Comment Apr 2, 2026 9:42pm
agents-manage-ui Ready Ready Preview, Comment Apr 2, 2026 9:42pm

Request Review

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 1, 2026

⚠️ No Changeset found

Latest commit: adb68da

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@pullfrog
Copy link
Copy Markdown
Contributor

pullfrog bot commented Apr 1, 2026

TL;DR — Fixes project deletion to clean up all branches and runtime entities, not just the main branch. Previously, deleting a project left orphaned Doltgres branches and branch-scoped runtime rows behind.

Key changes

  • Delete all project branches on project deletiondeleteProjectWithBranch now enumerates every Doltgres branch matching the {tenantId}_{projectId}_ prefix and deletes them all, instead of only deleting the main branch.
  • Remove branch scoping from cascadeDeleteByProject — The fullBranchName parameter and all ref->>'name' WHERE clauses are dropped so runtime entities are deleted across all branches in a single pass.
  • Update tests to reflect cross-branch deletion — Assertions now expect entities from all branches to be removed, not just the targeted branch.

Summary | 6 files | 5 commits | base: mainfix/delete-branch


Delete all Doltgres branches for a project

Before: deleteProjectWithBranch deleted only project.mainBranchName from Doltgres, leaving feature/draft branches orphaned.
After: It calls doltListBranches, filters by the {tenantId}_{projectId}_ prefix, and iterates through all matches — each deletion is individually try/caught so one failure doesn't block the rest.

Partial failures are tracked in a failedBranches array and logged as a warning with both failure and success counts, giving operators visibility without aborting the entire cleanup.

projectLifecycle.ts · projectFull.ts · projects.ts


Remove branch scoping from runtime cascade delete

Before: cascadeDeleteByProject required a fullBranchName parameter and filtered every delete query with ref->>'name' = $branch, leaving rows on other branches untouched.
After: The function accepts only { scopes: ProjectScopeConfig } and deletes by tenantId + projectId alone, covering all branches.

This affects deletes on contextCache, conversations, tasks, triggerInvocations, scheduledTriggerInvocations, datasetRun, and evaluationRun.

cascade-delete.ts · cascadeDelete.test.ts · projectLifecycle.test.ts

Pullfrog  | View workflow run | Triggered by Pullfrog | Using Claude Opus𝕏

Copy link
Copy Markdown
Contributor

@pullfrog pullfrog bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall. The change to delete all branches and runtime entities across all branches when deleting a project is a sensible fix — branch-scoped deletion left orphaned data. Two stale comment/doc issues to clean up.

Pullfrog  | Fix all ➔Fix 👍s ➔View workflow run | Using Claude Opus𝕏

fullBranchName: string;
}): Promise<CascadeDeleteResult> => {
const { scopes, fullBranchName } = params;
async (params: { scopes: ProjectScopeConfig }): Promise<CascadeDeleteResult> => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The JSDoc above (lines 172–174) still says "Delete all runtime entities for a project on a specific branch" and "Used when deleting a project from a branch." These are stale after removing the fullBranchName parameter — update to reflect cross-branch deletion.

Comment on lines +4 to +10
import {
doltBranch,
doltBranchExists,
doltCheckout,
doltDeleteBranch,
doltListBranches,
} from '../../dolt/branch';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The JSDoc for deleteProjectWithBranch (lines 108–113 in the original) still says "Delete a project and its branch" (singular) and step 1 says "Gets the project from runtime DB to find the branch name." These should be updated to reflect the new all-branches behavior. The function name itself (deleteProjectWithBranch) is also now slightly misleading — consider renaming to deleteProjectWithBranches if you want to keep it accurate, though that's optional.

Copy link
Copy Markdown
Contributor

@claude claude bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Review Summary

(4) Total Issues | Risk: High

🔴❗ Critical (1) ❗🔴

🔴 1) projectLifecycle.test.ts Missing doltListBranches mock will break tests

Issue: The unit test mock at lines 12-17 does not include doltListBranches, but the updated deleteProjectWithBranch implementation now calls doltListBranches(configDb)(). This will cause all deleteProjectWithBranch tests to fail with an error like "doltListBranches is not a function".

Why: All existing tests in the deleteProjectWithBranch describe block will fail immediately when run against the updated code. This is a blocking regression that prevents the test suite from passing.

Fix: Add doltListBranches to the mock factory:

// In the vi.mock block (line 12-17):
vi.mock('../../dolt/branch', () => ({
  doltBranch: vi.fn(),
  doltBranchExists: vi.fn(),
  doltCheckout: vi.fn(),
  doltDeleteBranch: vi.fn(),
  doltListBranches: vi.fn(),  // ADD THIS
}));

// Import and type it (after line 20):
import { doltListBranches } from '../../dolt/branch';
const mockedDoltListBranches = doltListBranches as ReturnType<typeof vi.fn>;

// In each deleteProjectWithBranch test, add mock setup:
const mockDoltListBranchesFn = vi.fn().mockResolvedValue([
  { name: `${testTenantId}_delete-lifecycle-project_main` }
]);
mockedDoltListBranches.mockReturnValue(mockDoltListBranchesFn);

Refs:

Inline Comments:

  • 🔴 Critical: cascade-delete.ts:172-178 Stale docstring contradicts function behavior

🟠⚠️ Major (2) 🟠⚠️

🟠 1) projectLifecycle.ts:107-119 Docstring describes single-branch deletion but function now deletes all branches

Issue: The docstring says "Gets the project from runtime DB to find the branch name" (singular) and "Deletes the project branch from config DB" (singular), but the implementation now lists ALL branches matching the project prefix and deletes each one.

Why: A maintainer reading the docstring would expect this function to only delete the main branch. They might incorrectly think they need additional code to clean up feature branches.

Fix: Update the docstring to reflect the new behavior:

/**
 * Delete a project and ALL its branches
 *
 * This utility:
 * 1. Gets the project from runtime DB
 * 2. Lists and deletes ALL branches matching the project prefix from config DB (Doltgres)
 * 3. Deletes the project record from runtime DB
 *
 * Note: Callers should handle cascade deletion of runtime entities (conversations, etc.)
 * before calling this function.
 */

Refs:

🟠 2) projectLifecycle.ts:146-157 Partial branch deletion failures silently continue with misleading success log

Issue: The inner try/catch catches individual branch deletion failures and logs at ERROR level, but then the function logs "Deleted all project branches" at line 154 even when some branches failed to delete. This creates a misleading success state.

Why: When a branch deletion fails mid-loop, orphaned branches persist in Doltgres. The success log doesn't reflect that cleanup was partial. An engineer debugging later would see conflicting signals.

Fix: Track failed branches and adjust the summary log:

const failedBranches: string[] = [];
for (const branch of projectBranches) {
  try {
    await doltDeleteBranch(configDb)({ name: branch.name, force: true });
    logger.debug({ branchName: branch.name }, 'Deleted project branch');
  } catch (error) {
    failedBranches.push(branch.name);
    logger.error(
      { error, branchName: branch.name },
      'Failed to delete project branch, continuing with remaining branches'
    );
  }
}

if (failedBranches.length > 0) {
  logger.warn(
    { tenantId, projectId, failedBranches, successCount: projectBranches.length - failedBranches.length },
    'Some project branches could not be deleted'
  );
} else {
  logger.info(
    { tenantId, projectId, branchCount: projectBranches.length },
    'Deleted all project branches'
  );
}

Refs:

Inline Comments:

  • 🟠 Major: cascade-delete.ts:185 Stale inline comment
  • 🟠 Major: cascade-delete.ts:191 Stale inline comment
  • 🟠 Major: cascade-delete.ts:197 Stale inline comment
  • 🟠 Major: cascade-delete.ts:200 Stale inline comment
  • 🟠 Major: cascade-delete.ts:221 Stale inline comment
  • 🟠 Major: cascade-delete.ts:229 Stale inline comment

🟡 Minor (1) 🟡

Inline Comments:

  • 🟡 Minor: cascadeDelete.test.ts:358 Stale test comment

🚫 REQUEST CHANGES

Summary: The core logic change (deleting across all branches instead of a single branch) is correct and the test assertions have been updated appropriately. However, the projectLifecycle.test.ts mock is missing doltListBranches which will cause test failures. Additionally, multiple comments and docstrings throughout the code still reference the old "single branch" behavior and need to be updated to avoid confusing future maintainers. Please add the missing mock and update the stale documentation before merging.

Reviewers (4)
Reviewer Returned Main Findings Consider While You're Here Inline Comments Pending Recs Discarded
pr-review-comments 9 2 0 0 7 0 0
pr-review-tests 4 1 0 0 1 0 2
pr-review-errors 3 1 0 0 0 0 2
pr-review-standards 7 0 0 0 0 0 7
Total 23 4 0 0 8 0 11

Note: Standards reviewer findings were duplicates of comments reviewer findings and were discarded. Error reviewer's minor findings about return types were assessed as low priority and discarded.

async (params: { scopes: ProjectScopeConfig }): Promise<CascadeDeleteResult> => {
const { scopes } = params;

// Delete contextCache for this project on this branch
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 MAJOR: Stale inline comment references branch filtering

Issue: Comment says "on this branch" but code no longer filters by branch.

Fix: (1-click apply)

Suggested change
// Delete contextCache for this project on this branch
// Delete contextCache for this project (across all branches)

.where(projectScopedWhere(contextCache, scopes))
.returning();

// Delete conversations for this project on this branch (cascades to messages)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 MAJOR: Stale inline comment

Fix: (1-click apply)

Suggested change
// Delete conversations for this project on this branch (cascades to messages)
// Delete conversations for this project (cascades to messages)

.where(projectScopedWhere(conversations, scopes))
.returning();

// Delete tasks for this project on this branch (cascades to ledgerArtifacts, taskRelations)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 MAJOR: Stale inline comment

Fix: (1-click apply)

Suggested change
// Delete tasks for this project on this branch (cascades to ledgerArtifacts, taskRelations)
// Delete tasks for this project (cascades to ledgerArtifacts, taskRelations)

.returning();
const tasksResult = await db.delete(tasks).where(projectScopedWhere(tasks, scopes)).returning();

// Delete trigger invocations for this project on this branch
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 MAJOR: Stale inline comment

Fix: (1-click apply)

Suggested change
// Delete trigger invocations for this project on this branch
// Delete trigger invocations for this project

@github-actions github-actions bot deleted a comment from claude bot Apr 1, 2026
Copy link
Copy Markdown
Contributor

@claude claude bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Review Summary

(0) Total Issues | Risk: Low

✅ All Previous Issues Addressed

The commit 74e0588a4 successfully addresses all 4 issues (1 Critical, 2 Major, 1 Minor) raised in the previous review:

# Severity Issue Resolution
1 🔴 Critical Missing doltListBranches mock in tests ✅ Added mock, import, and test setup
2 🔴 Critical Stale docstring in cascade-delete.ts ✅ Updated to "across all branches"
3 🟠 Major Stale docstring in projectLifecycle.ts ✅ Updated to describe all-branches deletion
4 🟠 Major Misleading success log on partial failures ✅ Now tracks and logs failedBranches separately
5-10 🟠 Major Stale inline comments in cascade-delete.ts ✅ All updated to remove branch-specific wording
11 🟡 Minor Stale test comment ✅ Updated to reflect project-wide cascade

Delta Review Summary

The delta since the last review consists of a single commit that updates comments and documentation to correctly reflect the new behavior where project deletion:

  1. Deletes all Doltgres branches matching the {tenantId}_{projectId}_ prefix
  2. Deletes all runtime entities across all branches (not just the targeted branch)

The code changes are documentation/comment-only and correctly align the prose with the previously-reviewed implementation.


✅ APPROVE

Summary: All previously raised issues have been addressed. The PR now correctly documents that project deletion cleans up all branches and runtime entities across all branches. Good work on the follow-up fixes! 🎉

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 2, 2026

Preview URLs

Use these stable preview aliases for testing this PR:

These point to the same Vercel preview deployment as the bot comment, but they stay stable and easier to find.

Raw Vercel deployment URLs

Copy link
Copy Markdown
Contributor

@claude claude bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Review Summary

(0) Total Issues | Risk: Low

✅ Previous Approval Stands

This re-review was triggered by a merge commit (362b208 — merging main into fix/delete-branch).

Delta analysis:

  • Commits since last review: 1 (merge commit only)
  • PR-specific files changed: 0 — all 6 files are identical to when approved
  • Merge conflicts: None

The merge simply brings this branch up to date with main. No new code review is needed.

Prior Review Reference

The PR was approved on 2026-04-02 after all 4 issues (1 Critical, 2 Major, 1 Minor) from the initial review were addressed:

Resolution Issue
Missing doltListBranches mock in tests
Stale docstring in cascade-delete.ts
Stale docstring in projectLifecycle.ts
Misleading success log on partial failures
Stale inline comments (6 locations)

✅ APPROVE

Summary: Merge from main only — no PR changes since prior approval. Ship it! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant