Skip to content

fix: make project deletion tolerant of stale session state#2628

Closed
tamish560 wants to merge 2 commits into
AgentWrapper:mainfrom
tamish560:fix/project-delete-stale-state
Closed

fix: make project deletion tolerant of stale session state#2628
tamish560 wants to merge 2 commits into
AgentWrapper:mainfrom
tamish560:fix/project-delete-stale-state

Conversation

@tamish560

Copy link
Copy Markdown

What

Makes project deletion (DELETE /api/v1/projects/{id}) robust to stale, legacy, or inconsistent session state by making session teardown errors non-fatal during project removal.

Why

When a project has stale sessions (locked worktrees, archived project refs, missing runtime handles, etc.), TeardownProject returns an error and the entire Remove call fails with INTERNAL_ERROR. The project stays registered and the user has no recovery path from the UI.

The issue (#2598) explicitly says: "local project removal must be robust to stale, legacy, partially missing, or otherwise inconsistent AO-managed state. If the user asks to remove a local project registration, AO should work around bad session/worktree/runtime records and complete the unregister flow wherever it can do so without deleting unpurged session state."

Closes #2598

How

Changed Service.Remove in backend/internal/service/project/service.go to ignore the error from m.sessions.TeardownProject(ctx, id) instead of propagating it. The project is still archived (soft-deleted) regardless of whether session teardown succeeded.

This means:

  • Sessions that can be torn down, will be
  • Sessions that cannot (stale, locked, missing) are left for later cleanup
  • The project is always archived, so the user can re-add it without a blocked delete

Testing

Updated TestManager_RemoveDoesNotArchiveWhenTeardownFails to TestManager_RemoveToleratesTeardownFailure. The test now verifies that:

  • Remove succeeds (no error) even when teardown fails
  • The project is archived (no longer active) after Remove returns

Run: cd backend && go test ./internal/service/project/...

@tamish560

Copy link
Copy Markdown
Author

Closing this in favor of #2599 by @AgentWrapper which addresses the same issue (#2598). Should have checked for existing PRs before opening this one.

@tamish560 tamish560 closed this Jul 12, 2026
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.

bug(projects): project deletion should tolerate stale legacy local state

1 participant