Repository navigation
fix(server): agents can no longer delete a project's threads or No project through MCP - #33790
Closed
riskneutral00 wants to merge 1 commit into
Closed
riskneutral00 wants to merge 1 commit into
riskneutral00 wants to merge 1 commit into
Conversation
…oject through MCP Fixes pingdotgg#33766. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
ApprovabilityVerdict: Approved at Macroscope's review found this PR approvable — MCP agents can now delete only empty, non-scratch projects, with clearer refusals for projects containing threads. The change reduces destructive exposure while leaving app-based deletion unchanged. You can add or adjust custom eligibility rules. Learn more. |
Member
|
Thanks @riskneutral00 for the detailed investigation and regression coverage. #33773, by @juliusmarminge, covers the same scratch-project deletion defect with a smaller, tested change. I’m closing this as a duplicate; if the broader restriction on deleting other nonempty projects still matters, please propose that separately. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
One MCP call from an agent hid 1,872 threads on a real install, with no confirmation and no undo (#33766).
The agent was cleaning up after a test. It called
t3_project_deletewithforce: trueon the built-in "No project", because the test's threads had been launched witht3_thread_launch { scratch: true }and lived there. T3 deleted the project and every thread in it: 436 threads and their subagent threads, 1,872thread.deletedevents in 63 seconds. Pinned threads went too, and three runs that were still working were cancelled. The tool returned success. The agent never saw a count or a confirmation step. T3 has no restore command, so getting the threads back meant editingstatev2.sqliteby hand, and the attachment files of the deleted threads are removed at once (attachment.cleanupinThreadDeletion.ts), so 22 of 108 attachments were lost for good.The unpatched tool also invites this. A delete without
forceis refused with "The project is not empty; force=true is required to delete it.", so an agent that hits the refusal is told to retry withforce.Expected: deleting a project together with its threads is the user's decision. The app already treats it that way. Settings → Projects → Remove project asks for a destructive confirmation, with a message that counts the project's threads, before it sends
force: true(removeMembersinapps/web/src/components/settings/ProjectSettingsPanel.tsx, message fromplanProjectRemoval). An agent should not be able to skip that step.Change
All changes are in the MCP project toolkit; the agent path is the only one that changes.
t3_project_deleteno longer takesforce(apps/server/src/mcp/toolkits/project/tools.ts). The handler builds the delete fromprojectIdalone, so an agent can delete only a project with no threads. New description: "Delete one empty project. Folder on disk stays. Only the user deletes a project with threads."For a project with threads the agent gets
invalid_request, which says what the delete would have taken and where the user does it (apps/server/src/mcp/toolkits/project/handlers.ts):The count reads the same snapshot
ProjectService.deleteChildThreadsdeletes from (getShellSnapshot({ projectId }), threads plus archived threads). It counts them as the app's own removal confirmation does, listed threads only (isListedThreadLineage), so subagent threads and side chats are left out of the number, though they go with their parents. If the read fails or finds no listed thread, the refusal goes out without a count.The built-in "No project" is refused outright, using the existing
ManagedProjectFolders.isScratchProject:With
forcegone, a No project that still has threads is already refused by the rule above. This check gives that project a clearer message, also covers it when empty (T3 recreates it on the next scratch launch anyway), and keeps holding ifforceis ever brought back.apps/server/src/provider/agentContextBudget.json:mcpToolListJsonBytesgoes from 48217 to 48212. The shorter description and the removed parameter shrink the advertised tool list by 5 bytes.Deliberately not changed:
ProjectService, the WebSocket and HTTP project mutation routes, thet3 project remove --forceCLI and the web and mobile clients. The user's own deletes work exactly as before.request_secretcard, was considered. It would touch contracts, server, web and mobile, and the app already has the confirmation this sends users to. A confirming second call from the same agent was also considered and rejected: the agent confirming its own call is not the user's consent.Compatibility: an agent that still sends
force: truehas the extra key dropped by the tool's schema. An empty project is still deleted. A project with threads gets the refusal above instead of losing its threads. A search ofdocs,evalsand agent instructions finds nothing else that calls this tool withforce.Scope and approval
Fixes #33766.
The issue is not triaged yet, and removing a tool parameter changes behavior, so this needs a maintainer to agree with the direction (CONTRIBUTING.md, "Establish the problem and scope first"). I'm opening it now so the fix and its evidence are in one place. I'll reshape it however you prefer. If you would rather keep
forceand only refuse "No project", the smaller change is theisScratchProjectcheck, its message and its test. If you want the agent path to ask the user instead of refusing, I can do that.It solves one problem: an agent can delete a project's threads without the user.
Verification
Live, on a sandboxed dev server. I ran
vp run dev:server --home-dir <throwaway dir> --no-seed. An outside MCP client signed in through the server's own OAuth flow (register, approve with a code fromt3 auth pairing create, PKCE token exchange, full access). It then called the tools over/mcp. Threads were launched witht3_thread_launchon thedevReplayprovider. Results on this PR's head:t3_project_deletewithforce: true, project with 3 threadsforcet3_project_deletewithforce: trueon "No project" (1 thread)t3_project_deleteon an empty projectt3 project remove <id> --forceon the 3-thread projectBefore, with
main'shandlers.tsandtools.tsswapped in (the server reloads on save), the same server and calls:forceon a 2-thread project: "The project is not empty; force=true is required to delete it."force: true: deleted the project and both threads.force: trueon "No project": deleted it.Tests.
apps/server/src/mcp/toolkits/project/handlers.test.tsgets two tests. Their mockedProjectService.deleterefuses a project with threads unlessforceis true, as the real one does.force: trueand asserts that nothing was deleted and that the message begins "The project has 3 threads (1 pinned). Only the user can delete a project with its threads".isScratchProjectreports as scratch.main'shandlers.tsandtools.ts, both fail withexpected [ 'project:client-target' ] to deeply equal [], meaning the project was deleted. With the change, all 13 tests in the file pass.Checks, run locally on Node 26.12.1:
vp check(0 errors; its 4 warnings are in files this PR does not touch),vp run knip:check, and bothgenerate --check.vp run check:changedpasses every step, including typecheck of 41 packages andAgentContextBudget.test.ts.vp test run src/mcp src/project src/provider/AgentContextBudget.test.tsinapps/server: 511 of 512 pass. The failure,AgentSessionScanner"excludes sandboxes reached through a symlink into the worktrees dir", fails the same way onmainon this machine.Eval. The description change is covered by
mcp-tool-use --case archive-project-not-delete --samples 2(claude-sonnet-5-5): 2 of 2 pass, cost $0.15.Not checked:
Written with Claude Opus 5.5 (claude-opus-5-5) in Claude Code.
🤖 Generated with Claude Code