Repository navigation
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: the app MCP writer and the two app removals now ask the same shared-home guard the other spec writers already use, so this fixes the root cause. Notes
[DESIGN-REVIEWED] 0d4528a Description read[DESCRIPTION-READ] 0710b9b3f2ac52a3989f813c1157a176accdef6de68e3b8e7a069d96ed760cd1 That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS The fix is aimed at the cause: the app MCP writer and the two app removals were the shared-directory writers that skipped the ownership guard. Every other item exists to keep that fix working. What this change shipsInventory (8 items) — 8 justifiedIntent: stop a gateway on a scratch or preview
[FIRST-PRINCIPLES-REVIEWED] 0d4528a Description read[DESCRIPTION-READ] 5759962485afab6d865f58538f414d8ac2643a14bb3f34b7f53c21436ab8a804 That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 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: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 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: |
3a7ffb5 to
1f89dd8
Compare
1f89dd8 to
2a7b3f7
Compare
2a7b3f7 to
06c5d36
Compare
|
self-added: yes
|
06c5d36 to
f2a8e1a
Compare
36f7919 to
eca4b90
Compare
iamwhatever
left a comment
There was a problem hiding this comment.
Request changes at eca4b90: a deferred follow-up needs a tracking issue.
The PR's sibling sweep leaves publish_app_agent_launch as an unguarded writer into the shared ~/.kiro/agents directory, "left for a follow-up". The Design Review asks for an issue as well. I found no GitHub issue for it. Please either guard it here, or open one issue (guard the launch-copy writer with the shared-home check, plus a test) and link it in the description.
The rest reads as sound. The MCP writer asks the existing guard and writes nothing when refused (bridges_mcp_config.py#L154-L193). Both app removals check ownership and unlink under one agents_spec_lock section (bridges_agents.py#L1083-L1101), and remove_app_agent_launches takes no nested spec lock.
AI findings judged non-blocking:
- Design Review: when the agent prune is refused, the MCP prune is skipped and the caller logs a generic WARNING. The same guard would refuse that write anyway, and the exception message names the foreign owner.
- First Principles: the
refresh_app_agentscatch is not described in the PR. It only absorbs the new exception.
This PR also changes a deletion path and which data home is pinned as owner of the shared spec. Those changes still need a maintainer's review after the issue is linked.
CI is green on this head.
— crew-pr-reviewer (r138)
|
Hold at 366cd61 for a maintainer review. No defect found. The r138 change request is resolved. The unguarded Why this still needs a person: the PR changes deletion paths in the shared What I checked: each refused path writes or deletes nothing. The ownership check and the unlinks share one AI findings judged non-blocking:
CI is green on this head (77 success, 18 skipped). — crew-pr-reviewer (r149) |
1679820
366cd61 to
1679820
Compare
|
This changes behaviour users already rely on, so it needs a design sign-off from a maintainer before it can merge. A maintainer will post the decision here. To propose a design, follow the request-for-change process in CONTRIBUTING.md (docs/request-for-change/). Review result on 1679820: no blocking finding. PR Readiness is green on this head. The review checked these points:
Done well: the fix reuses the existing Optional:
|
Code change approver recommendation: A person should decideWhy: the decider thinks the change is probably fine but estimates a 20% chance that this change introduces a defect, above the 12% limit for approving on its own. The app MCP writer ( An automated recommendation, not a review: a maintainer still decides. It approves on its own only when the estimated chance of a defect is at most 12% and the change has at most 400 changed lines. Decider v3c (217fe607) · commit |
1679820 to
3b815bb
Compare
A gateway on a non-default KIROCREW_HOME rewrote one entry of the shared ~/.kiro/agents/kirocrew.json: mcpServers["auto-improvement:auto-improvement"] .command became that gateway's sys.executable. Every new live session then started the auto-improvement MCP server from a preview build tree, and deleting that tree breaks the server for all of them. The chain: reconcile_enabled_app_resources runs register_app for every enabled app at boot; _register_mcp_servers resolves the app's stdio command, and a server that launches a kiro_crew module gets command = sys.executable (resolve_stdio_command); the entry is written by _write_mcp_json_unlocked straight through atomic_write. That primitive is the one writer of kirocrew.json the shared-home guard never saw: the managed-spec rebuild and the derived specs ask _decline_shared_agent_home / _declined_foreign_spec_write, and _register_agents asks it per app agent, but the app MCP registry did not. The fix is at that primitive. _write_mcp_json_unlocked asks _declined_foreign_spec_write for kirocrew.json under the _mcp_lock it already holds and returns False, writing nothing, when the shared directory belongs to another home. _register_mcp_servers then registers nothing, _deregister_mcp_servers reports nothing removed, and the prune logs no prune. No new policy: the exemptions are the guard's own, so a default-home instance, a self-pinned instance, a private redirected target and isolated_agents_dir write exactly as before. Returning False rather than raising matches the sibling app writer, _register_agents, which skips a refused spec; the guard emits the WARNING and the SEL agent_home_write denial. A relocated home that creates kirocrew.json in the shared directory writes the managed kirocrew-core entry with it. That entry's KIROCREW_HOME pin is the provenance the guard reads, so the same home can later deregister and prune the app entries it wrote. Without it the new file has no owner and every later write from that home is refused. When the entry cannot be resolved, the writer creates no file. The same home also deleted the owner's files: _deregister_agents (run at boot for every app this instance denies) and the agent half of _prune_stale_app_resources unlink app specs and launch copies in the shared directory without asking. Both now ask the guard once per sweep, through _owned_agents_dir, and remove nothing when another home owns the directory. The answer and every unlink of the sweep run under agents_spec_lock, the lock every spec writer of the directory holds, so ownership cannot change between the check and a delete. The lock's sidecar, .kirocrew-agents.lock, already sits in any directory a spec writer touched; the denied-install test now allows it. A refused removal is a settled no-op, not an error: registration already declines every write there, so nothing in it is this home's to remove, and an error would make `kirocrew app disable` fail and the health watch retry on every sweep. A lock that cannot be opened or acquired is a transient failure, so it raises: deregister_app records it, app disable reports incomplete cleanup and the health watch retries. The upgrade prune logs it and still runs its MCP half, and the boot reconcile's denied-app branch revokes agents, skills and MCP servers in separate steps, so a failed agent sweep skips neither of the others. Cost of doing nothing: every preview or scratch-home gateway poisons the live spec on boot, and the agent cannot repair it because kirocrew.json is write-protected from tool calls, so the owner edits the file by hand.
The app removals asked the write guard, _declined_foreign_spec_write, whose ephemeral arms refuse any instance run from a linked worktree or a temp checkout. So a default-home gateway run from one removed nothing on disable, trust withdrawal or the boot revocation of a denied app, and still reported success: the denied app's MCP server stayed in kirocrew.json. A removal of this home's own app entries pins nothing of the running checkout into the shared specs, so those arms do not apply. Removals now ask _declined_foreign_spec_removal, which keeps only the ownership arm: specs another data home owns are still left untouched. _owned_agents_dir asks it for the agent sweeps, and the MCP entry removals pass removal=True to _write_mcp_json_unlocked. Writes are unchanged.
|
self-added: yes
|
|
The red Backend Tests shards on 0d4528a come from main, not this diff. Run 43653586092: Linux (3.12) shards 1, 2 and 8, and Windows shards 1, 2 and 8. Coverage Gate fails closed on Failing tests, all checking that persisted conversation rows are scrubbed of credentials:
They fail the same way on Linux and Windows, and on #37411, #37410, #37408 and #37359, so they are not a flake. This PR changes none of the redaction or history code. No open issue or flake-ledger entry covers them yet; #36640 ("scrub every persisted conversation row") is the recent main change in that area. No push on this PR for it. |
Problem / Motivation
Goal: A gateway started on a non-default
KIROCREW_HOMEleaves the shared~/.kiro/agentsdirectory that another home owns untouched, for app MCP entries and app agent files alike.A preview gateway on its own
KIROCREW_HOMErewrote one entry in the live~/.kiro/agents/kirocrew.json:mcpServers["auto-improvement:auto-improvement"].commandbecame the preview build's interpreter. Every new live session then started that MCP server from the preview tree, and deleting the tree broke it for all of them. The same boot pass can also delete the owner's app agent specs and launch copies.Why it matters
Any preview or scratch-home gateway poisons or prunes the live gateway's agent specs at boot. An agent cannot repair
kirocrew.jsonbecause tool calls are refused write access to it, so the owner has to edit the file by hand.Not a goal
_decline_shared_agent_home, unchanged.purge_uninstalled_agent_residue). It removes lock files only for specs that are already gone, and overlays in the instance's own overlay dir.What changed (motivation → approach → change)
_write_mcp_json_unlocked)kirocrew.jsonkirocrew.jsonwith no ownerkirocrew-coreentry, whoseKIROCREW_HOMEpin lets this home change the file later; writes nothing if that entry cannot be resolved_deregister_agents)<app>--*.jsonand launch copiesagents_spec_lock; deletes nothing and reports 0 removed_prune_stale_app_resources)At boot every gateway re-registers its enabled apps and deregisters the ones it denies, whatever its home. A stdio server that runs a
kiro_crewmodule getscommand = sys.executable. The managed-spec rebuild and the derived specs already ask_declined_foreign_spec_write, and_register_agentsasks it per app agent, but the app MCP writer and the two app removals did not. That is the root cause.The MCP writer now asks that guard and returns
Falsewhen refused. When it creates the file, it asks_new_shared_spec_needs_owner_pin(inagent_parts/shared_home.py, exported throughagent.py) whether the new file needs this home'skirocrew-corepin;bridges_mcp.pythen registers nothing and reports nothing removed. The agent removals ask it once per sweep, through_owned_agents_dirinbridges_agents.py, which holdsagents_spec_lockfrom the answer through the last unlink so ownership cannot change in between. When another home owns the directory they delete nothing and report 0 removed, the settled state registration already leaves there, sokirocrew app disablecompletes and the health watch does not retry it. A lock that cannot be opened or acquired raises instead, so disable reports the cleanup as incomplete and the watch retries; the denied-app branch ofbackend_runtime/startup.pyrevokes agents, skills and MCP servers in separate steps, so that failure skips neither of the others. Writes keep the guard's own exemptions: a default-home instance, a self-pinned instance, a private redirected target andisolated_agents_dirwrite as before. Removals ask a narrower question,_declined_foreign_spec_removal: do the specs belong to another data home? A removal of this home's own app entries pins nothing of the running checkout, so the ephemeral arms (a linked worktree, a temp checkout) do not refuse it. The MCP entry removals passremoval=Trueto_write_mcp_json_unlockedfor the same reason. The spec docs indocs/system-specs/modules/app-kit-platform.mdandconfig.mdand the guard's docstring inagent_parts/spec_files.pyname the new callers.Backwards compatibility
Compatible: removals behave as on main for every instance except a non-default home whose shared directory another home owns, which now deletes nothing. A default-home gateway run from a linked worktree or a temp checkout still removes a disabled or denied app's agents and MCP entries. Writes behave as on main for the default home, a self-pinned home and
isolated_agents_dir. One write changes on the default home: a default-home gateway run from a linked worktree or a temp checkout no longer registers app MCP entries into the sharedkirocrew.json, the same refusal every other spec writer already gives that instance.Removes nothing: a refused instance keeps the owner's files instead of deleting them; no key, record, validator or function is removed.
Tests
test/test_app_bridges_home_guard.py, 16 tests, temp dirs only:kirocrew.jsonstays byte-identical through app MCP registration and deregistration, with one SEL denial;_deregister_agentsand the upgrade prune;_deregister_agentsraises,deregister_appreports the cleanup as incomplete so the health watch retries, the upgrade prune still prunes MCP entries, and the boot reconcile still revokes a denied app's skills and MCP servers;isolated_agents_dirstill accepts registration;kirocrew.jsoncan deregister its own app entries, and creates no file when it cannot mark itself as the owner;agents_spec_lockis held (fails with the lock removed);.templaterecord and MCP entry are gone (fails with the removal routed back through the write guard);Proof: PROVEN test/test_app_bridges_home_guard.py::test_a_foreign_owned_shared_spec_is_left_byte_identical_by_app_mcp_registration, test/test_app_bridges_home_guard.py::test_a_foreign_owned_shared_spec_keeps_its_app_entries_through_deregistration, test/test_app_bridges_home_guard.py::test_a_relocated_home_creates_no_shared_spec_it_could_not_mark_as_its_own, test/test_app_bridges_home_guard.py::test_a_foreign_owned_shared_dir_keeps_app_agent_files_through_deregistration, test/test_app_bridges_home_guard.py::test_a_foreign_owned_shared_dir_keeps_app_agent_files_through_the_upgrade_prune (head 0d4528a)
The linked-worktree test (
test_a_default_home_gateway_in_a_linked_worktree_revokes_a_denied_app) is PROVEN against the first commit (prove.py --base 3b815bb81); against main it passes, because main's removals are unguarded.test_install_while_execution_denied_registers_nothingnow allows the lock's sidecar.kirocrew-agents.lock, which every spec writer of the directory leaves.Related suites (22 files: app bridges, agent launch, agent home isolation, app backend): 1269 passed, 8 skipped. One test failed in the first run and passed in the second (not in this diff's paths). Semgrep (
semgrep/, 1.78.0) is clean on every changed Python file.Manual verification
N/A -- the tests reproduce each write and removal path on a foreign-owned directory. A full preview-gateway boot was not replayed.
Related Issues
no linked issue: found while reproducing a preview gateway that rewrote the live agent spec; no GitHub issue tracks it.
Sibling sweep
Swept: git grep -nE ".unlink()|atomic_write(|_atomic_json_write(" -- src/kiro_crew/apps/
Sibling: src/kiro_crew/apps/bridges_mcp_config.py -- changed here
Sibling: src/kiro_crew/apps/bridges_agents.py -- changed here
Sibling: src/kiro_crew/apps/bridges_register.py -- changed here
Sibling: src/kiro_crew/apps/agent_launch.py -- tracked in #30989
remove_app_agent_launchesin that file is reached only from the two removals that now ask first;publish_app_agent_launchwrites through the guarded_atomic_json_write(agent_launch.py), pinned by #36847, so it already asks the write guard.Sibling: src/kiro_crew/apps/backend_runtime/startup.py -- changed here
Sibling: src/kiro_crew/apps/app_storage.py -- not affected -- writes the app's own data dir, not the agents dir
Pattern harvest
Rule candidate: review-prompt
Pattern: a new writer of a file under kiro_agents_dir() that does not ask _declined_foreign_spec_write, or a remover that does not ask _declined_foreign_spec_removal
Checklist