Repository navigation
fix(acp): reclaim run dirs kiro-cli and memory consolidation leave - #16039
Conversation
Design Review (Opus 5.5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS Check that memory-consolidation folders on Windows (no marker, no sweep) are acceptable to leave growing until a follow-up closes the by-name walk gap. [DESIGN-REVIEWED] 91ed141 Description read[DESCRIPTION-READ] e836e11440b52b7d05852f2e75b3ea86048495f51aca682160ab2ea3bdb66103 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 |
GPT 6.1 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
First Principles Review (Opus 5.5, fork) — 🟡 CONCERNSPremise-level review of First-Principles-Verdict: CONCERNS
Not justified as shipped
What this change shipsInventory (6 items) — 5 justifiedIntent: one-run work folders that subagents, stateless crons and memory consolidation leave behind are removed when the run ends. This is a FIX.
[FIRST-PRINCIPLES-REVIEWED] 91ed141 Description read[DESCRIPTION-READ] e335580c0063057a4a75679923d8fb6ed729ce6831cfd20bf6db23fa5ee4a932 That sha256 names the PR description this verdict read. Recompute it with |
This comment has been minimized.
This comment has been minimized.
Opus 5.5 Review (fork) — ✅ no blocking findingsReviewed |
7e20d34 to
9f9cd07
Compare
This comment has been minimized.
This comment has been minimized.
9f9cd07 to
676438f
Compare
This comment has been minimized.
This comment has been minimized.
676438f to
57af4e4
Compare
This comment has been minimized.
This comment has been minimized.
57af4e4 to
6fc4404
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
6fc4404 to
747c93d
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
10b3c6e to
6324dce
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
6324dce to
ac549ad
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Reviewed for merge triage, not approving from my side: it reclaims run directories that kiro-cli and memory consolidation leave behind, i.e. it deletes files. A deletion path needs a maintainer to confirm the ownership check cannot match a live run or user data. CI is green. |
|
The ownership check is main's and this PR does not change it. The PR widens what can pass it in two places: kiro-cli's empty
One test drives every gate through a single sweep and asserts each kept folder: live, under an hour old, this process's, another home's, a retained pid, an unreadable marker, a long-lived session's, one holding a user file, and an unmarked one. A liveness probe raises if called (test_session_work_dir.py#L746). The |
kiro-cli creates an empty .kiro/agents in the folder it starts in, which for a subagent or a stateless cron run is the run's own work directory. The reclaim accepted only Crew's .kiro/settings chain, so that folder made every such directory unreclaimable, at shutdown and in the gateway sweep. An empty .kiro/agents is now residue: it is checked empty, removed with rmdir before any residue file is unlinked, and refused when it is a link or holds anything. A memory consolidation call runs under a fresh memory-consolidation:<store>:<uuid hex> key whose derived directory nothing revisits, but the key was not a one-run shape, so those directories were never marked or reclaimed. The shape table now carries that key, so the provider marks and reclaims them and the sweep and the doctor census see them.
|
Reviewed, not approving (crew-pr-reviewer). It adds reclamation, meaning deletion, of run directories that kiro-cli and memory consolidation leave behind ( |
|
@iamwhatever The selection rules are the same as when I answered this on Oct 4: #16039 (comment). The head has been rebased since (now 91ed141) but the patch is unchanged. A folder is only reclaimed when it carries Crew's one-run marker for this data home, its gateway has exited, nothing in it changed in the last hour, and removal is rmdir-only for directories, so a live run or anything a user put inside it is never matched. |
bolichen97
left a comment
There was a problem hiding this comment.
Reviewed on behalf of the maintainers (sweep 2026-10-06): full diff read, callers verified against current main, readiness passed, required checks green, no blocking review threads. Owner confirmation on the deletion path: a run folder is reclaimed only when it carries Crew's own marker for this data home, its gateway pid has exited, nothing in it changed for >= 1h, and every directory goes through rmdir on the descriptor-pinned walk -- a live run or any user file keeps the whole tree. Windows reclaim is unchanged; only the doctor census widens. Approving and merging.
Problem / Motivation
Goal: Run folders that subagents, stateless crons and memory consolidation calls leave in the workspace are removed once the run ends.
Each one-run session gets its own folder under the workspace root. Crew removes it at shutdown, and the gateway's sweep catches what a dead gateway left. In practice neither removes them. One host held 2,068 of these folders, each holding only setup files, and gained about 8 an hour.
Two gaps keep them:
.kiro/agentsin the folder it starts in. For a subagent or a stateless cron run, that is the run's own folder. The reclaim accepts only Crew's.kiro/settingsfiles, so this empty folder makes it keep the whole tree.memory-consolidation:<store>:<uuid hex>. That key is not one of the one-run shapes, so its folder is never marked and never reclaimed.Why it matters
The workspace root grows on every host that runs subagents or crons, and nothing shrinks it. Every spawn that derives its folder lists that root again. The doctor's manual remedy names folders holding only
.kiro/settings/cli.json, which skips nearly every folder that piles up.Not a goal
.kiro/settings/lsp.jsonkiro-cli writes. The reclaim still unlinks only files Crew writes, so those folders stay..kiroagainst a junction swapped in after the check, so it still keeps folders holding kiro-cli's.kiro/agents, and memory consolidation folders stay unmarked there. The doctor counts the memory consolidation folders with the unmarked ones. A marked folder kept for its.kiro/agentsis in neither of its figures, as on main.What changed (motivation → approach → change)
Both gaps close inside the existing reclaim rule in
src/kiro_crew/session_work_dir.py..kiro/agentsrmdirbefore any file is unlinked. A link, a file, or any entry inside it keeps the whole tree. Only the descriptor walk does this, because it removes the folder relative to a.kiroit holds open. The by-name walk used on Windows cannot pin.kiro, so it keeps a tree that holds the folder.memory-consolidation:<store>:<32 hex>joins the one-run shape table, with the store-name grammarmemory_storesvalidates. Where the walk pins.kiro, the provider marks and reclaims these folders and the sweep sees them. On the by-name walk one gate keeps both the key and the folder name long-lived, so those folders are never marked or swept. The doctor's census counts them on either walk.The safety rule stays as it was. The reclaim unlinks only Crew's
cli.jsonand its lock, and every folder goes throughrmdir. The doctor indoctor_checks/resources.pynames the empty.kiro/agentsin its remedy and says an unmarked folder can be a kind this platform never marks.docs/system-specs/modules/acp-client.mddescribes both changes.Backwards compatibility
Compatible: the reclaim accepts one more empty folder and one more key shape. A folder holding anything a run wrote is still kept, and every folder reclaimed today is still reclaimed.
Tests
test/test_session_work_dir.py: where the walk pins.kiro, an empty.kiro/agentsis reclaimed, alone or beside Crew's settings; the by-name walk keeps those trees untouched. A spec, a folder or a file namedagentskeeps the tree as it was. A linkedagentsis refused. A freshagentsfolder makes an old folder young. A file that lands inagentsafter the check stops the reclaim withcli.jsonstill in place. The sweep reclaims a dead predecessor's memory consolidation folder where the walk pins.kiroand leaves it on the by-name walk. Memory consolidation keys and folder names are one-run shapes only where the walk pins.kiro, and the provider factory follows the same rule. The store part accepts exactly the sampled namesmemory_store_name_defectaccepts, and its pattern is pinned to the onememory_storesvalidates with. The doctor's census counts every run shape on either walk.test/test_cli_doctor.py: the manual remedy names the empty.kiro/agents, and an unmarked memory consolidation backlog is counted and named on either walk.Manual verification
kiro-cli acp --agent kirocrew-lite, an agent with no MCP servers, started in a folder holding only.kiro/settings/cli.json, had created.kiro/agentsthere by the timeinitializeanswered. A second folder, passed as the session'scwd, got none..kiro/agents. The 178 memory consolidation folders had no marker.Screenshots / video
N/A: no frontend change.
Related Issues
Related: #16049 records the other one-run session keys whose folders this PR leaves for a follow-up.
no linked issue: this PR closes no issue; the leak was found by counting one host's workspace root.
Pattern harvest
Rule candidate: review-prompt
Pattern: a cleanup's list of what it may remove covers only what the parent writes, and misses what the child process it starts writes into the same folder.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)