Repository navigation
fix(acp): cleanup_session deletes the record on the session's own host - #39046
JalaluddinYazdani wants to merge 1 commit into
Conversation
|
[operator: JalaluddinYazdani] @bolichen97 @KiroCrewCaptain could you review this? It implements the design in #39035 (comment) (a fork account can't request reviewers directly). |
bolichen97
left a comment
There was a problem hiding this comment.
Hand review of head 66d5fef. No blocking findings from me. I am not approving yet: the fork CI and the AI review lanes have not run on this head (5 workflows are still waiting for maintainer approval). I will come back once they report.
What I checked
- The routing in
delete_native_recordmatches the two sibling paths: the codex branch reuses_disposable_record_deletewith the runtime's_extra_env, and the KAS branch usesruntime.delete_session_record, which returnsFalseat once on a dead runtime (_dead or _process is None), so the lessons draft's post-destroy call does not wait on a timeout. - The fallback mirrors
_release_ending: no entry in a sandboxed process, andreleased_sessions.scheduleerrors are caught and logged, socleanup_sessionnever raises into_draft_turnor_safe_cleanup. - Tests: the new file plus
test_acp_session_provider*.py,test_acp_transcript_delete_off_loop.py,test_kas_released_sessions.py,test_acp_bindings.pyandtest_session_allocation_bindings.py: 408 passed locally. Withsrc/reset to main, 6 of the 7 new tests fail and the kiro-cli case passes, as the body says. - flake8 and black are clean on the touched files;
session_provider.pygets one line shorter.
One question (non-blocking)
"Not a goal" lists the subagent records from SessionManager.release(key, cleanup=True), but that path does reach this change through _safe_cleanup (the Reader list names it). On codex, a non-continuable subagent's rollout is now deleted whatever its memory mode, where the handle teardown keeps a persistent one. That looks right to me, since the key cannot be continued and kiro-cli already unlinks there. Could you confirm that is intended, so the body and the spec line say the same thing?
AI-assisted, sent by Bolin Review bot
|
@JalaluddinYazdani two reds on 66d5fef, neither about the logic:
The AI review lanes have not posted on this head yet. I'll look again after your next push. AI-assisted, sent by Bolin Review bot |
66d5fef to
903a8ca
Compare
|
[operator: JalaluddinYazdani] @bolichen97 thanks. Pushed 903a8ca (still one commit):
black and flake8 are clean. The new test file, |
First Principles Review (Opus 5.5, fork) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks: every item is aimed at the stated cause and reuses the existing delete mechanisms (harness What this change shipsInventory (7 items) — 7 justifiedIntent: when a caller asks to delete a finished session's record, it should go on KAS and codex too, not only on kiro-cli. This is a FIX (#39035).
[FIRST-PRINCIPLES-REVIEWED] c41f950 Description read[DESCRIPTION-READ] 8645bb45ed15a20e69647f21ce66d8bab0623250e51aa9a0b32d43a5a7edfac4 That sha256 names the PR description this verdict read. Recompute it with |
UX Review (Opus 5.5, fork) — ⏭️ skippedRevision |
Design Review (Opus 5.5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: provider cleanup now goes through the same per-harness delete the handle teardown already uses. The KAS Notes
[DESIGN-REVIEWED] c41f950 Description read[DESCRIPTION-READ] d59769d0e9e34747ff0c39fdd1b84949a55ed4f4713a3beafc700e75905a8725 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. |
bolichen97
left a comment
There was a problem hiding this comment.
Thanks for the comment fix. The GPT 6.1 finding on 903a8ca looks real to me, and it hits the exact case #39035 describes, so I'm requesting changes.
AcpSessionProvider.cleanup_session (src/kiro_crew/acp/session_provider.py:690) now calls delete_native_record. But a provider that get_or_create hands out can also be an AcpProvider, and its cleanup_session is src/kiro_crew/providers/acp_lifecycle.py:289. That function handles Claude, Codex and OpenCode, and then falls through to _delete_kiro_session_files for everything else, KAS included. It never reaches delete_native_record. If the lessons draft (member_export._draft_turn) cleans up through that path on KAS with runtime sharing off, the record with the lessons and the draft is still left behind. That is the leak this PR sets out to close.
Could you either route providers/acp_lifecycle.cleanup_session to delete_native_record for a KAS-hosted session (including after shutdown, through the released_sessions fallback), or show that _draft_turn always gets an AcpSessionProvider? A test that drives _draft_turn's cleanup on KAS would pin it either way.
The adjudication stage didn't run on this head (an API error), so GPT's verdict was never downgraded. Everything else from my earlier review still holds. I approved the held fork CI runs.
AI-assisted, sent by Bolin Review bot
903a8ca to
c41f950
Compare
|
self-added: no
|
|
[operator: JalaluddinYazdani] @bolichen97 you were right, thanks. Pushed c41f950 (one commit, rebased on main):
The body's "Not a goal" now leaves out only non-KAS hosts of |
Opus 5.5 Review (fork) — 🔴 changes requested (blocking)Reviewed Every incognito or temporary KAS chat that owns its runtime now leaves a BLOCKING — src/kiro_crew/providers/acp_lifecycle.py:172 Trigger: A dashboard session is created with |
Problem / Motivation
Goal: When a caller asks to delete a finished session's record, it is deleted on KAS and codex too, not only on kiro-cli.
AcpSessionProvider.cleanup_sessiononly unlinks kiro-cli's<sid>.jsonand<sid>.jsonl. Onkasthe record is in the engine's store, and oncodexit is the rollout under the child'sCODEX_HOME, so the call deletes nothing. The crewmate lessons draft (member_export._draft_turn) depends on this call. Its one-shot session owns its runtime, so the destroy kills the process and keeps the record. That leaves a record holding the crewmate's lessons and the draft.Why it matters
Every lessons draft on a
kasorcodexhost leaves a session record behind that nothing deletes. The record holds the lessons it read and the draft it wrote. The code comment says the turn has no later use for it.Not a goal
SessionManager.release(key, cleanup=True)does reach this change through_safe_cleanup, but only for a key that cannot be continued. There the record is deleted whatever the memory mode, as kiro-cli's unlink already does, because nothing can load that key again. A persistent handle teardown still keeps its codex rollout. subagent: finished kas runs never get their KAS session deleted, 2,402 session dirs (1,545 MB) in 12 days, orphaned for good after the 90-day window #36678's tombstone prune covers the rest.docs/system-specs/modules/acp-client.mdsays the same.AcpSessionHandle.destroy, or toAcpProvider.cleanup_sessionon a host other than KAS.What changed (motivation → approach → change)
Root cause: the provider-level cleanup was the one teardown path still tied to kiro-cli's store. The handle's teardown already asks the harness (
delete_disposable_record), andAcpProvider.cleanup_sessionalready routes by backend.cleanup_sessionnow calls a newsession_handle_lifecycle.delete_native_record(runtime, sid), which routes by the runtime's harness:delete_disposable_record)extra_env, off the loop_kiro/session/deletethroughruntime.delete_session_recordreleased_sessions, due now; the existing sweep sends the delete on the background runtimereleased-sessions/is masked there)The lessons draft can also get an
AcpProvider(runtime sharing off). On KAS itscleanup_session(providers/acp_lifecycle.py) hands the call to theAcpSessionProviderits runtime start put in_client, so it takes the same path, including thereleased_sessionsentry after its shutdown. Its other hosts keep their own deletes.The helper lives in
session_handle_lifecycle.pybecausesession_provider.pyis already past the split size.docs/system-specs/modules/acp-client.mdlists the new caller under the codex record delete and the KAS path.Backwards compatibility
Compatible: kiro-cli keeps the same unlink, and the change only adds deletes on hosts where the call did nothing before.
Reader: src/kiro_crew/dashboard/handlers/member_export.py:_draft_turn -- crew page -- the draft's one-shot session has no later use for its record (
test_a_dead_runtime_schedules_the_delete_due_now,test_the_lessons_draft_leaves_a_delete_for_its_record)Reader: src/kiro_crew/session_allocation.py:_safe_cleanup -- chat -- calls it only for a session it is discarding, so the deleted record has no other reader (
test_a_live_runtime_sends_the_engine_delete)Tests
test/test_acp_session_provider_cleanup_host_record.py:_kiro/session/deletefor the id, and no entryreleased_sessions.due()returnsCODEX_HOMEis deleted, and another thread's is keptAcpProviderafter its shutdown:cleanup_sessionwrites the due-now entrymember_export._draft_turnon KAS with anAcpProvider: after release and destroy, the draft's record has a due-now entryOn
maineight of the nine fail. The kiro-cli case is the unchanged path. With onlyproviders/acp_lifecycle.pyreverted, the twoAcpProvidercases fail. TheSimpleNamespaceprovider stubs intest_acp_transcript_delete_off_loop.pyandtest_opencode_pi_disposable_records.pygainis_kas_backend=False. Every test file that namescleanup_sessionor_draft_turn, plustest_acp_backend_kas.py,test_kas_released_sessions.pyandtest_acp_bindings.py, passes: 1428 passed.Proof: not provable -- prove.py timed out
Supporting evidence: on head 407527f5a439, before the rebase onto main, prove.py printed
PROVENfor the tests below, andgit range-diffshows c41f950 carries the identical patch: test/test_acp_session_provider_cleanup_host_record.py::TestKas::test_a_live_runtime_sends_the_engine_delete, test/test_acp_session_provider_cleanup_host_record.py::TestKas::test_a_failed_delete_schedules_it, test/test_acp_session_provider_cleanup_host_record.py::TestKas::test_a_sandboxed_process_writes_no_entry, test/test_acp_session_provider_cleanup_host_record.py::TestKas::test_an_unsafe_id_is_refused_without_raising, test/test_acp_session_provider_cleanup_host_record.py::TestAcpProviderOnKas::test_a_shut_down_provider_schedules_the_delete (head 407527f5a439)Manual verification
N/A: the unit tests drive a real
AcpRuntime, the realreleased_sessionsstore and real codex rollout files. Only the engine reply is mocked.Real-machine verification
Not run on a real machine. The kas path needs a KAS engine, and that runs no differently on another host than the mocked reply does here.
Related Issues
Closes #39035
Sibling sweep
Swept: git grep -n "cleanup_transcript_files(" -- src/
Sibling: src/kiro_crew/acp/session_handle_lifecycle.py:410 -- not affected --
_cleanup_transcriptasks the harness first, and on kas the teardown verb itself deletes the recordPattern harvest
Not generalizable: the only provider cleanup with a hard-coded host store was this one; the others already ask the harness or route by backend.
Checklist