Repository navigation
fix(agents): crew delete removes the crew's private template copy - #11222
Conversation
Design Review (Fable 5) — ✅ PASSDesign-level review of Design-Verdict: PASS Verify #8540 accepted leaving already-orphaned copies in place — this stops new leaks but ships no sweep, so existing dead-crew templates keep surfacing. Suggestions
[DESIGN-REVIEWED] e6db862 |
GPT 5.6 Review — ✅ no blocking findingsGPT 5.6 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
First Principles Review (Fable 5) — 🟡 CONCERNSPremise-level review of First-Principles-Verdict: CONCERNS Fix stops at the dashboard handler: CLI Not justified as shipped
What this change shipsInventory (5 items) — 3 justifiedIntent: deleting a crew should also remove the private template copy that existed only for it — a FIX (issue #8540; new test fails on base).
[FIRST-PRINCIPLES-REVIEWED] e6db862 |
Opus 4.8 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
247d6b1 to
04c9eda
Compare
04c9eda to
95b7e74
Compare
95b7e74 to
9037d0f
Compare
Deleting a crew left the private copy the fork-on-edit flow created for it, plus the copy's fork lineage in the agent_state sidecar, so a template named after a dead crew kept listing in the Agent Templates tab. The delete handler now removes the copy when both sides agree it was the crew's alone: the sidecar names the crew as private_to AND the crew's persisted binding pointed at it. The check, unlink and lineage prune reuse the reset endpoint's helpers and run inside the same config lock as the rest of the delete. Removal is best-effort: an ambiguous name, a foreign binding, or a file that will not unlink leaves the copy and its lineage in place, and the crew is still deleted. Closes #8540
9037d0f to
e6db862
Compare
|
|
|
chenmingwei23
left a comment
There was a problem hiding this comment.
Tier 1 auto-approve: fix (2 files): crew delete left an orphaned private template copy that surfaced under a dead crew name; fix prunes it, corroborated by private_to and the persisted binding, best-effort. Criteria: no conflict, no requested changes, security path denylist clean, design-doc gate clean, SAST annotations clean, security checklist all-NO, AI reviewers green.
…rodotdev#11222) Deleting a crew left the private copy the fork-on-edit flow created for it, plus the copy's fork lineage in the agent_state sidecar, so a template named after a dead crew kept listing in the Agent Templates tab. The delete handler now removes the copy when both sides agree it was the crew's alone: the sidecar names the crew as private_to AND the crew's persisted binding pointed at it. The check, unlink and lineage prune reuse the reset endpoint's helpers and run inside the same config lock as the rest of the delete. Removal is best-effort: an ambiguous name, a foreign binding, or a file that will not unlink leaves the copy and its lineage in place, and the crew is still deleted. Closes kirodotdev#8540
What
DELETE /api/agents/{name}(crew delete) now removes the crew's private template copy and prunes the copy's fork lineage record from theagent_statesidecar — when, and only when, both sides corroborate that the copy was this crew's alone.Why
The fork-on-first-edit flow gives a crew a private copy of its template, named after the crew, with
forked_from/private_torecorded in the sidecar. Deleting the crew never consulted that lineage, so the copy file and its record survived and a template named after a dead crew kept surfacing in the Agent Templates tab (Design Review finding on #8307, tracked as #8540).How
_prune_private_copy_of_deleted_crew(crew, bound_template)indashboard/handlers/agents.py, called fromapi_kirocrew_agent_deleteright after the avatar cleanup, inside the same config lock (so a same-name recreation cannot fork a fresh copy that this cleanup then removes).private_to == crew, AND the crew's persistedkiro_agentbinding — captured inside the configmutatecritical section at delete time — names that copy. Lineage alone or binding alone leaves the file untouched._load_template_specsresolves the copy's ACTUAL file (a stem/name divergence is not missed; an ambiguous name is refused),_spec_path_is_safepath-confines it, and_unlink_copy_unless_referenceddoes the foreign-binding check and unlink as one critical section under the config advisory lock andagents_spec_lock.agent_state.pruneruns only after the file is actually gone.list_agentscache and pushes anagentsrefresh._unlink_copy_unless_referenced(shared with reset and publish cleanup) now reads crew bindings from BOTH config layers: the lockedconfig.jsondocument and the user-ownedconfig.local.jsonoverlay, which deep-merges over it at load and can hold a crew's effectivekiro_agenton its own. The overlay is read inside a nested hold of its own sidecar lock (config set --localwrites under that lock, not the base's) and the unlink runs while both are held, so an overlay binding cannot land between the check and the unlink. An unreadable overlay fails closed (file kept), like an unreadable base.Tests
test/test_agent_delete_prunes_private_copy.py(11 tests, all call the handler directly against an isolatedKIROCREW_HOME):main: the file survives);private_tonames another crew → left alone;config.json, or only in theconfig.local.jsonoverlay) → left alone;PermissionError) → crew still deleted, file and lineage kept, refusal logged (asserted via caplog);Run:
python -m pytest -n0 test/test_agent_delete_prunes_private_copy.py -q. Sibling suitestest_agent_reset_endpoint.py,test_agent_fork_endpoint.py,test_agent_publish_endpoint.py,test_config_overlay.py,test_crew_memory_store_binding.py,test_agent_avatar.py,test_config_api.py,test_crew_reasoning_effort.pypass (365 tests). isort, flake8, mypy, black (baselined gate), comment-history and subprocess-encoding gates pass on the changed files.Other
Backend-only change with no UI surface; labeled
no-screenshots. No new endpoints, no generalized cleanup of orphaned copies — only the deleted crew's own corroborated copy, as scoped in #8540.Pattern harvest
Rule candidate: Design Review
Pattern: when a feature introduces a per-entity derived artifact (private copy + lineage), the entity's DELETE handler must be listed among the writers that consult that artifact's record.
Closes #8540