Skip to content

fix(vscode): persist installed agent removal - #12542

Merged
bagatao-anaconda merged 9 commits into
Kilo-Org:mainfrom
Githubguy132010:codex/fix-agent-removal-persistence
Aug 14, 2026
Merged

fix(vscode): persist installed agent removal#12542
bagatao-anaconda merged 9 commits into
Kilo-Org:mainfrom
Githubguy132010:codex/fix-agent-removal-persistence

Conversation

@Githubguy132010

@Githubguy132010 Githubguy132010 commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Issue

Fixes #11579

Context

Agent configuration loading merges every supported JSON/JSONC source, but removal only edited one preferred global file and one preferred project file. A legacy definition in another loaded source could therefore survive a successful removal response and reappear after state refreshed or VS Code restarted. Marketplace agent removal also used a separate file-only path, so it could uninstall the marketplace package while leaving the surviving legacy definition active.

Implementation

Agent removal now reconciles matching definitions across every existing editable config source in the requested scope, while continuing to reject organization-managed agents. Callers can select project or global scope; when scope is omitted, Settings-style removal reconciles all writable scopes. After a successful disk change, the endpoint disposes cached instance state so the next access reloads it.

Settings and Marketplace now share one extension-side CLI removal helper and surface backend failures. Helpful backend removal messages are preserved in HTTP 400 responses, and empty client errors use friendly fallbacks. The Settings UI also carries agent source metadata so organization-managed agents no longer show a removal action.

Screenshots / Video

before after
N/A — persistence defect N/A — no layout change

How to Test

Manual/local verification

  • Agent-executed: reproduced removal with the same slug in .kilo/kilo.jsonc and .kilo/opencode.jsonc; focused tests confirm duplicate definitions and stale default_agent values are removed when scope is omitted.
  • Agent-executed: verified project-only removal preserves the global copy and global-only removal preserves the project copy.
  • Agent-executed: ran the VS Code extension build, focused CLI, HTTP API, and Marketplace tests, typechecks, lint, knip, and affected repository guards.

Reviewer test steps

  1. Define the same custom agent slug in .kilo/kilo.jsonc and .kilo/opencode.jsonc.
  2. Restart the extension host, then remove the agent from Settings > Agent Behaviour > Available Agents.
  3. Confirm the agent disappears, both config definitions are removed, and it does not return after restarting VS Code.
  4. Install the same Marketplace agent at project and global scope, remove only the project copy, and confirm the global copy remains; then remove the global copy.

Blocked checks and substitute verification

  • None. All relevant checks completed locally.

Checklist

  • Issue linked above, or exception explained
  • Tests/verification described
  • Screenshots/video included for visual changes, or marked N/A
  • Changeset considered for user-facing changes
  • I personally reviewed the diff and can explain the changes, including any AI-assisted work.

Get in Touch

GitHub: @Githubguy132010

@Githubguy132010
Githubguy132010 marked this pull request as ready for review July 26, 2026 18:04
Comment thread packages/opencode/src/kilocode/server/httpapi/handlers/kilocode.ts Outdated
@kilo-code-bot

kilo-code-bot Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

The latest commit (704f67b7) addresses all previous review feedback: the extension removal helper now threads an optional scope through to the backend, Marketplace removal targets the correct directory per scope, the unreachable ?? fallbacks were replaced with || so empty backend error messages get friendly fallbacks, the HTTP handler now preserves backend removal messages via InvalidRequestError (HTTP 400 with message), and KiloAgent.remove reconciles only the selected writable scope (or every scope when omitted), with the file-kind filter generalized to *-file. The new scope-limiting test is sandboxed by the test preload's XDG_CONFIG_HOME override, so it does not touch the real global config.

Files Reviewed (8 files changed since last review)
  • packages/kilo-vscode/src/services/agent-removal.ts
  • packages/kilo-vscode/src/services/marketplace/actions.ts
  • packages/kilo-vscode/tests/unit/marketplace-actions.test.ts
  • packages/opencode/src/kilocode/agent/index.ts
  • packages/opencode/src/kilocode/server/httpapi/groups/kilocode.ts
  • packages/opencode/src/kilocode/server/httpapi/handlers/kilocode.ts
  • packages/opencode/test/kilocode/agent-remove.test.ts
  • packages/opencode/test/kilocode/server/httpapi-exercise-scenarios.ts
Previous Review Summaries (2 snapshots, latest commit bfeb3ae)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit bfeb3ae)

Status: No Issues Found | Recommendation: Merge

The latest commit removes the post-removal verification step (store.provide + !remaining.native check) that the previous review flagged as an unnecessary synchronous instance/bootstrap reload. The core reconciliation logic in KiloAgent.remove (via removeConfigAgent, which iterates every editable source from KilocodeConfigSources.list) is unchanged, so the fix for the original persistence bug still holds without the extra reload cost.

Files Reviewed (1 file changed since last review)
  • packages/opencode/src/kilocode/server/httpapi/handlers/kilocode.ts

Previous review (commit 5d713f7)

Status: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 0
SUGGESTION 1
Issue Details (click to expand)

SUGGESTION

File Line Issue
packages/opencode/src/kilocode/server/httpapi/handlers/kilocode.ts 82 Post-removal verification forces a full instance/bootstrap reload synchronously inside the removal request
Files Reviewed (14 files)
  • .changeset/clean-agent-removal.md
  • packages/kilo-vscode/src/KiloProvider.ts
  • packages/kilo-vscode/src/services/agent-removal.ts
  • packages/kilo-vscode/src/services/marketplace/actions.ts
  • packages/kilo-vscode/tests/unit/agent-behaviour-patches.test.ts
  • packages/kilo-vscode/tests/unit/marketplace-actions.test.ts
  • packages/kilo-vscode/webview-ui/src/components/settings/AgentBehaviourTab.tsx
  • packages/kilo-vscode/webview-ui/src/components/settings/ModeEditView.tsx
  • packages/kilo-vscode/webview-ui/src/components/settings/agent-behaviour-patches.ts
  • packages/kilo-vscode/webview-ui/src/types/messages/agents.ts
  • packages/opencode/src/kilocode/agent/index.ts
  • packages/opencode/src/kilocode/server/httpapi/handlers/kilocode.ts
  • packages/opencode/test/kilocode/agent-remove.test.ts
  • packages/opencode/test/kilocode/server/httpapi-exercise-scenarios.ts

The core fix (reconciling removal across every editable config source reported by KilocodeConfigSources.list, and re-verifying no custom definition remains before reporting success) is sound and well tested with real fixtures (no over-mocking). The organization-agent guard, client-side removable() gating, and shared removeAgent helper between Settings and Marketplace are consistent and correctly wired. Only a minor performance note was raised on the post-removal verification path.

Fix these issues in Kilo Cloud


Reviewed by kimi-k3 · Input: 242K · Output: 10.6K · Cached: 2M

Review guidance: REVIEW.md from base branch main

Githubguy132010 and others added 4 commits July 26, 2026 20:20
…oval-persistence

# Conflicts:
#	packages/kilo-vscode/tests/unit/agent-behaviour-patches.test.ts
#	packages/kilo-vscode/webview-ui/src/components/settings/AgentBehaviourTab.tsx
#	packages/kilo-vscode/webview-ui/src/components/settings/agent-behaviour-patches.ts
Co-Authored-By: Thomas Brugman <thomas.brugman.teb3@gmail.com>

@bagatao-anaconda bagatao-anaconda left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for tracking this down 🙂 Good catch on the root cause (removal only touching one file per scope while loading merges several). The fix itself is solid and the test coverage for the duplicate-source case is a nice addition.

I left a few comments inline, but the main one worth resolving before merge is the marketplace scope change (removing an agent now seems to wipe it from both project and global config regardless of which scope you pick, which is a behavior change from how MCPs/skills are removed). Want to double check that's intentional?

The others (lost error message on failure, the hardcoded source-kind list, a couple of small nits) aren't blockers but worth a look.

Comment thread packages/kilo-vscode/src/services/marketplace/actions.ts
Comment thread packages/kilo-vscode/src/services/agent-removal.ts Outdated
Comment thread packages/kilo-vscode/src/services/agent-removal.ts Outdated
Comment thread packages/opencode/src/kilocode/agent/index.ts Outdated
@bagatao-anaconda

Copy link
Copy Markdown
Collaborator

The description says the endpoint "reloads the instance and only reports success when no custom agent with that name remains," but I don't see that check in the diff (it just passes worktree through now).

Right now it succeeds as long as removal happened in at least one file, not because it verified nothing's left. Might just be a wording thing, but wanted to flag it in case the stronger guarantee was meant to be there.

@bagatao-anaconda

Copy link
Copy Markdown
Collaborator

This code is also relevant to the PR.

RemoveError has a helpful message (like "cannot remove organization agent" or "no agent file found on disk"), but it gets thrown away here in favor of an empty BadRequest({}).

Since this PR adds a toast to actually show removal errors to the user, they'll just see a generic/blank message instead of the real reason. Can we pass the message through, e.g. new HttpApiError.BadRequest({ message: err.message })?

@Githubguy132010

Copy link
Copy Markdown
Contributor Author

Hey @bagatao-anaconda

Thanks for the review. The issues should now be adressed.

@bagatao-anaconda

Copy link
Copy Markdown
Collaborator

@Githubguy132010 Thanks for the great work on this, and for addressing all the review feedback so thoroughly.

I've merged main in and turned on auto-merge; it'll merge automatically once CI passes, no further action needed on your end. Really appreciate the contribution!

@bagatao-anaconda
bagatao-anaconda merged commit e781e72 into Kilo-Org:main Aug 14, 2026
32 checks passed
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] Cannot Remove Installed Agents

2 participants