Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix: surface workspace delete failures from AgentsPage archive flow - #26900

Merged
johnstcn merged 6 commits into
mainfrom
cian/fix-archive-delete-workspace-silent-failure
Jul 1, 2026
Merged

fix: surface workspace delete failures from AgentsPage archive flow#26900
johnstcn merged 6 commits into
mainfrom
cian/fix-archive-delete-workspace-silent-failure

Conversation

@johnstcn

@johnstcn johnstcn commented Jun 30, 2026

Copy link
Copy Markdown
Member

Right-clicking Archive & delete workspace on an agent chat could leave the workspace behind without the user noticing. The archive step ran first and removed the chat from the sidebar, so when the delete enqueue failed the user lost the surface to retry and the workspace lingered.

Fix

  • Delete the workspace first, archive the chat second. If the delete enqueue fails for anything other than 404/410, the chat stays in the list so the user can retry. 404/410 are still treated as "already gone" so the archive proceeds.
  • Errors are wrapped in ArchiveAndDeleteError tagged with step: "delete" | "archive". The toast branches on the tag: delete failures show an actionable "Open workspace" link, archive failures explain the delete already ran so no manual deletion is needed.
  • Both mutation call sites navigate away on onSuccess only (previously onSettled), so a delete failure keeps the chat's retry surface reachable. The confirm dialog still closes on onSettled.
  • When the archive step fails after a successful delete, workspace-related caches are invalidated to keep the rest of the app in sync with the ongoing deletion.
  • On successful enqueue, warn when the build response's matched_provisioners.count is 0. That field is populated on POST /workspacebuilds; job.queue_position / job.queue_size are not.

No backend changes. No new API surface.

Out of scope

  • Builds that stall after enqueue. A 2xx response on POST /workspacebuilds only means the build was queued; the workspace page already surfaces builds that fail to run, and the underlying cause is server/infra.
  • Activate-then-delete for dormant workspaces. Server inspection confirmed delete builds are not gated on DormantAt today (only start is), so the normal delete path already accepts dormant workspaces.
Implementation notes

Problem

archiveChatAndDeleteWorkspace used to archive first, then delete. On delete failure the chat was already archived and removed from the sidebar, so the user lost the entry point to retry. A generic toast fired, but by then they had usually moved on.

Approach

  1. Reorder. Delete first, archive second. 404/410 still swallowed so an already-gone workspace does not block archiving.
  2. Tag failures. ArchiveAndDeleteError { step: "delete" | "archive" } is thrown from the helper. Callers can produce a message that matches the step that actually failed.
  3. Branch the toast.
    • delete failed → "Failed to delete workspace {name}." with description "The chat was not archived. Open the workspace to delete it manually." and an "Open workspace" action.
    • archive failed → "Deleting {name}, but failed to archive the chat. {cause}." No action button: the delete is already on its way.
    • Non-tagged errors fall through to the delete branch as the safer default.
  4. Fix navigation-on-error. Both archiveAndDeleteMutation.mutate call sites moved from onSettled to onSuccess for the navigation callback. The confirm dialog still uses onSettled to close itself.
  5. Refresh caches on archive-failure. When archive fails after delete, invalidateWorkspaceMutationQueries runs from onError so any other view reflects the deletion.
  6. Queue signal from a real field. POST /workspacebuilds hardcodes job.queue_position = 0 and never sets queue_size, so the earlier queue-based branching would have been dead code. matched_provisioners.count is populated on POST, so the toast branches on that instead and only warns when count is 0.

Files

  • site/src/pages/AgentsPage/utils/agentWorkspaceUtils.ts
  • site/src/pages/AgentsPage/utils/agentWorkspaceUtils.test.ts
  • site/src/pages/AgentsPage/AgentsPage.tsx

This PR was generated by Coder Agents on behalf of @johnstcn.

…elete fails

Delete the workspace first, archive the chat second. If the delete
fails for anything other than 404/410, the chat stays in the sidebar
so the user can retry. The error toast names the workspace and links
to it for manual deletion.

On success, surface queue context from the build response: warn when
no provisioners are available (queue_size = 0) or note the queue
depth when queued behind other jobs.

Copy link
Copy Markdown
Member Author

/coder-agents-review

@coder-agents-review

coder-agents-review Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Chat: Review posted | View chat
Requested: 2026-07-01 11:47 UTC by @johnstcn
Spend: $84.44 / $100.00

Review history
  • R1 (2026-06-30), 1 P2, COMMENT. Review
  • R2 (2026-06-30): 17 reviewers, 4 Nit, 3 Note, 2 P2, 5 P3, COMMENT. Review
  • R3 (2026-07-01): 13 reviewers, 5 Nit, 5 Note, 2 P2, 5 P3, APPROVE. Review
  • R4 (2026-07-01): 11 reviewers, 6 Nit, 5 Note, 2 P2, 5 P3, APPROVE. Review

deep-review v0.9.0 | Round 4 | d219f96..34f7903

Last posted: Round 4, 18 findings (2 P2, 5 P3, 6 Nit, 5 Note), APPROVE. Review

Finding inventory

Findings

# Sev Status Location Summary Round Reviewer Posted
CRF-1 P2 Author fixed (45a1e63) agentWorkspaceUtils.ts:245 notifyDeleteFailed shows misleading "Failed to delete workspace" when only archive failed after successful delete R1 Netero Yes
CRF-2 P2 Author fixed (3914ad3) agentWorkspaceUtils.ts:250 notifyDeleteQueueState reads queue_position/queue_size from POST response, but server never populates them; every delete shows a toast, queue_position branch is dead code R2 Chopper P2, Pariston P2 Yes
CRF-3 P3 Author fixed (3914ad3) AgentsPage.tsx:431 onSettled navigates user away on error, undermining the PR's retry-surface goal; should use onSuccess R2 Kite P3, Hisoka Note Yes
CRF-4 P3 Author fixed (3914ad3) AgentsPage.tsx:268 onError skips workspace cache invalidation when archive fails after successful delete R2 Meruem Yes
CRF-5 P3 Author fixed (3914ad3) agentWorkspaceUtils.ts:273 notifyDeleteFailed name misleads; function handles archive failures too R2 Gon Yes
CRF-6 P3 Author fixed (3914ad3) agentWorkspaceUtils.ts:97 ArchiveAndDeleteError manually declares cause instead of using ES2022 Error cause chain R2 Ging-TS P3, Zoro Nit Yes
CRF-7 P3 Author fixed (3914ad3) agentWorkspaceUtils.test.ts:854 Non-tagged error test doesn't verify action button or onOpen callback R2 Bisky Yes
CRF-8 Nit Author fixed (3914ad3) agentWorkspaceUtils.test.ts:703 buildDeleteBuild factory name stutters R2 Gon Yes
CRF-9 Nit Author fixed (3914ad3) agentWorkspaceUtils.ts:92 Doc comments consistently restate what function signatures show; could be trimmed R2 Gon Yes
CRF-10 Nit Dropped by orchestrator (squash-merge replaces individual commit subjects) (commit) R2 commit subject is 93 chars, exceeds 72-char convention R2 Leorio Yes
CRF-11 Note Author fixed (3914ad3) agentWorkspaceUtils.test.ts:824 notifyDeleteFailed with step=archive and workspace=undefined is not tested R2 Bisky Yes
CRF-12 Note Author fixed (3914ad3) (PR description) Implementation plan in PR description is stale after R2 changes re queue toast wording R2 Leorio Yes
CRF-13 Note Author accepted R3 (Note observation; design maintained intentionally) agentWorkspaceUtils.ts:250 Toast side effects in a previously pure utility module R2 Zoro Yes
CRF-14 Nit Author fixed (3914ad3) agentWorkspaceUtils.ts:290 Fallback message says "Failed to archive and delete workspace" when only delete was attempted R2 Chopper Yes
CRF-15 Note Author fixed (34f7903) agentWorkspaceUtils.ts:267 Archive-failure toast says "Deleting" when delete step was a 404 swallow, not an actual enqueue R3 Hisoka Yes
CRF-16 Note Author accepted R4 (Note observation; no action requested by reviewer) agentWorkspaceUtils.ts:92 Doc comments still restate what signatures show after CRF-9 trimming; pattern recurs at smaller scale R3 Gon Yes
CRF-17 Nit Author fixed (34f7903) agentWorkspaceUtils.test.ts:695 Test factory verb inconsistency: buildWorkspace vs makeDeleteBuild R3 Gon Yes
CRF-18 Nit Open (PR title) PR title is 83 chars; will exceed 72-char subject convention after squash-merge R4 Leorio Yes

Contested and acknowledged

(none)

Round log

Round 1

Netero-only. 1 P2. Reviewed against d219f96..e8b7b8d.

Round 4

Panel (11 reviewers). CRF-15 through CRF-17 resolved (2 fixed, 1 accepted). 0 P2, 0 P3, 1 Nit new. Reviewed against d219f96..34f7903.

About deep-review

CRF = Coder Review Finding (P0-P4, Nit, Note)

Reviewer Focus
Bisky tests
Chopper ops/errors
Churn-guard change verification
Ging language modernization
Gon naming
Hisoka edge cases
Killua perf
Kite change integrity
Knov contracts
Knuckle SQL
Komugi flake/determinism
Kurapika security
Law decomposition
Leorio docs
Luffy product
Mafu-san process
Mafuuu contracts
Melody dispatch/pairing
Meruem structural
Nami frontend
Netero mechanical checks
Pariston premise testing
Pen-botter product gaps
Razor verification
Robin duplication
Ryosuke Go arch
Takumi concurrency
Zoro shape

🤖 Managed by Coder Agents.

@coder-agents-review coder-agents-review Bot left a comment

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.

First-pass review (mechanical checks only). The full review panel has not yet reviewed this PR; the panel will review after this finding is addressed.

The swap to delete-first is sound and the test coverage is good (66% test density, all new exports covered). One defect in the error path needs fixing before the panel round.

1 P2.

🤖 This review was automatically generated with Coder Agents.

Comment thread site/src/pages/AgentsPage/utils/agentWorkspaceUtils.ts Outdated

Copy link
Copy Markdown
Member Author

/coder-agents-review

@coder-agents-review coder-agents-review Bot left a comment

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.

CRF-1 (R1) is fixed: ArchiveAndDeleteError tags which step failed and notifyDeleteFailed branches correctly. Clean.

The ordering swap is the right call and the error-handling improvements are solid. Test coverage is good (64% density, all new exports covered, both error branches and the fallback tested). One issue in the queue-feedback feature needs attention before merge.

Severity counts: 1 P2, 5 P3, 3 Nit, 3 Note.

R2 commit subject is 93 chars (72-char convention). Two changes in one subject line; the primary fix alone would fit.

The implementation plan in the PR description is stale: it promises the queue_size=0 toast says "no provisioners available," but the R2 code changed it to "Delete enqueued." A reviewer reading the description gets a wrong mental model.

"The user sees 'enqueued' and moves on, missing that something might be wrong." (Leorio)


site/src/pages/AgentsPage/AgentsPage.tsx:431

P3 [CRF-3] onSettled navigates the user away on error, undermining the PR's retry-surface goal.

Both .mutate() call sites (line 431 for "proceed", line 464 for "confirm") use onSettled for navigateAfterArchive, which fires on error too. With the delete-first reordering, a delete failure now leaves the chat visible in the sidebar, but the user gets redirected to /agents anyway.

The author already applied the correct principle for the archive-only path at line 447 (onSuccess, with the comment "a failed archive should not redirect the user"). The same reasoning now applies here: a failed delete leaves the user with an entry point they shouldn't be navigated away from.

Fix: move navigateAfterArchive into onSuccess at both call sites. For the confirm path (line 464), keep setPendingArchiveAndDelete(null) in onSettled so the dialog closes regardless.

(Kite P3, Hisoka Note)

🤖

🤖 This review was automatically generated with Coder Agents.

Comment thread site/src/pages/AgentsPage/utils/agentWorkspaceUtils.ts Outdated
Comment thread site/src/pages/AgentsPage/AgentsPage.tsx
Comment thread site/src/pages/AgentsPage/utils/agentWorkspaceUtils.ts Outdated
Comment thread site/src/pages/AgentsPage/utils/agentWorkspaceUtils.ts
Comment thread site/src/pages/AgentsPage/utils/agentWorkspaceUtils.test.ts Outdated
Comment thread site/src/pages/AgentsPage/utils/agentWorkspaceUtils.test.ts Outdated
Comment thread site/src/pages/AgentsPage/utils/agentWorkspaceUtils.ts Outdated
Comment thread site/src/pages/AgentsPage/utils/agentWorkspaceUtils.ts Outdated
Comment thread site/src/pages/AgentsPage/utils/agentWorkspaceUtils.ts Outdated
Comment thread site/src/pages/AgentsPage/utils/agentWorkspaceUtils.ts

johnstcn commented Jul 1, 2026

Copy link
Copy Markdown
Member Author

/coder-agents-review

@coder-agents-review coder-agents-review Bot left a comment

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.

All R2 findings addressed. The queue feedback now reads matched_provisioners.count (populated on POST). Navigation callbacks use onSuccess. Cache invalidation runs on archive-failure. ArchiveAndDeleteError uses ES2022 cause chain. Tests cover every branch. Clean.

11 of 13 reviewers found no issues. 2 Note, 1 Nit remaining (none blocking).

"I tried to build a case against this and could not. The problem is correctly understood, the solution is proportional, and the fix is at the right causal level." (Pariston)

🤖 This review was automatically generated with Coder Agents.

Comment thread site/src/pages/AgentsPage/utils/agentWorkspaceUtils.ts
Comment thread site/src/pages/AgentsPage/utils/agentWorkspaceUtils.ts Outdated
Comment thread site/src/pages/AgentsPage/utils/agentWorkspaceUtils.test.ts Outdated

johnstcn commented Jul 1, 2026

Copy link
Copy Markdown
Member Author

/coder-agents-review

@coder-agents-review coder-agents-review Bot left a comment

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.

All R3 findings resolved. CRF-15 fixed cleanly with deleteEnqueued flag on ArchiveAndDeleteError. CRF-17 fixed (consistent make prefix). 54 tests pass. No regressions.

10 of 11 reviewers found no issues. 1 Nit remaining (PR title length for squash-merge subject).

This PR has been through 4 rounds and 18 findings. Every substantive finding was fixed. The ordering swap, step-tagged errors, onSuccess navigation, cache invalidation, and matched_provisioners.count queue signal are all correct and well-tested.

🤖 This review was automatically generated with Coder Agents.

Comment thread site/src/pages/AgentsPage/utils/agentWorkspaceUtils.ts Outdated
@johnstcn johnstcn changed the title fix(site/src/pages/AgentsPage): surface workspace delete failures from archive flow fix: surface workspace delete failures from AgentsPage archive flow Jul 1, 2026
@johnstcn
johnstcn marked this pull request as ready for review July 1, 2026 12:43

Copilot AI left a comment

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.

Pull request overview

This PR fixes a UX failure mode in the AgentsPage “Archive & delete workspace” flow where archiving could remove the chat from the sidebar before a failed workspace-delete enqueue was surfaced, leaving users without a retry entry point and potentially leaving the workspace behind unnoticed.

Changes:

  • Reorders the archive/delete helper to delete first, archive second, and wraps failures in a typed ArchiveAndDeleteError tagged by failing step.
  • Updates AgentsPage mutation handlers to navigate away only on success, and to toast actionable, step-specific error messages (including an “Open workspace” action on delete failures).
  • Adds queue-state warning logic based on matched_provisioners.count from the POST /workspacebuilds response, plus unit tests for the new behaviors.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
site/src/pages/AgentsPage/utils/agentWorkspaceUtils.ts Reorders delete+archive flow, adds typed step errors, and adds toast helpers for queue-state warnings and step-specific failures.
site/src/pages/AgentsPage/utils/agentWorkspaceUtils.test.ts Adds/updates unit tests covering new error-wrapping, ordering, and toast branching behavior.
site/src/pages/AgentsPage/AgentsPage.tsx Integrates the new helper outputs, improves navigation-on-error behavior, invalidates caches appropriately, and uses the new toast helpers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@DanielleMaywood DanielleMaywood left a comment

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.

I'm approving although I'm going to be honest... I think maybe this is a symptom of the existing mess but the approach taken here feels quite messy

Comment thread site/src/pages/AgentsPage/AgentsPage.tsx Outdated
Comment thread site/src/pages/AgentsPage/AgentsPage.tsx Outdated
Comment thread site/src/pages/AgentsPage/utils/agentWorkspaceUtils.ts Outdated
Comment thread site/src/pages/AgentsPage/utils/agentWorkspaceUtils.ts Outdated
@johnstcn
johnstcn merged commit 679eb00 into main Jul 1, 2026
26 of 27 checks passed
@johnstcn
johnstcn deleted the cian/fix-archive-delete-workspace-silent-failure branch July 1, 2026 14:33
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 1, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants