Repository navigation
fix(acp): delete kiro-cli transcripts off the event loop on teardown - #31395
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: the fix moves both deletes to a worker thread with the same drained-to-thread step the Claude branch and the other callers already use, and nothing is taken away. Notes
[DESIGN-REVIEWED] fb53bc8 Description read[DESCRIPTION-READ] f5c19925799957ccc45a5ae6603a91c949525482b992087ba06e7c30e18c33ef 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 moves the transcript delete off the loop at the code that did the blocking; the nested Notes
What this change shipsInventory (4 items) — 3 justifiedIntent: stop a finished session's kiro-cli transcript delete from stalling the gateway event loop on a slow home mount. FIX.
[FIRST-PRINCIPLES-REVIEWED] fb53bc8 Description read[DESCRIPTION-READ] cbcb5203d916dc3d854cbbd7de9118312172abd43db7cca5e6ae21f736e9d66f That sha256 names the PR description this verdict read. Recompute it with |
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: |
a32ac6d to
42cd694
Compare
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: |
|
[operator: bolichen97] The only red on this head is |
|
[operator: bolichen97] Update on the same red: #31469 merged and raised the budget to 34733, but |
42cd694 to
a707a73
Compare
AcpProvider.cleanup_session and AcpSessionHandle.destroy resolved and unlinked kiro-cli's <sid>.json + .jsonl on the gateway event loop, so a slow home mount stalled every session and could trip the loop watchdog. Both now hand the delete to a worker thread through drained_to_thread, which keeps a cancelled caller waiting until the delete has finished: teardown is where cancellations land, and a dropped delete leaves a transcript nothing else removes. The shared transcript helper now logs under a caller-neutral "transcript cleanup:" prefix. Builds on #24003 by @chenmingwei23.
a707a73 to
fb53bc8
Compare
|
self-added: yes
|
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Approved for the on-call. Review lanes pass on fb53bc8, no conflict, no open change request.
…31395) AcpProvider.cleanup_session and AcpSessionHandle.destroy resolved and unlinked kiro-cli's <sid>.json + .jsonl on the gateway event loop, so a slow home mount stalled every session and could trip the loop watchdog. Both now hand the delete to a worker thread through drained_to_thread, which keeps a cancelled caller waiting until the delete has finished: teardown is where cancellations land, and a dropped delete leaves a transcript nothing else removes. The shared transcript helper now logs under a caller-neutral "transcript cleanup:" prefix. Builds on #24003 by @chenmingwei23. (cherry picked from commit 3fb2a88)
Problem / Motivation
Goal: Deleting a finished session's kiro-cli transcript no longer runs file I/O on the gateway event loop.
Two teardown paths resolve and unlink kiro-cli's
<sid>.json+.jsonldirectly on the event loop:AcpProvider.cleanup_session(an incognito or temporary chat's shutdown) andAcpSessionHandle.destroy(every ephemeral session on a shared runtime). The sync-IO gate does not see either, because the calls sit behind a sync helper.Why it matters
On a slow or unresponsive home mount, each of those stats and unlinks stalls every session the gateway serves, and a long enough stall makes the loop watchdog kill the gateway (#3057, #1572).
destroyruns for titles, suggestions, folders and nav on nearly every chat, so this is a hot path, not a rare one.Not a goal
scripts/check_sync_io_in_async.pyto follow same-module sync helpers (the issue's separate suggestion).acp/runtime_start.pyoracp/session_provider.py, which already run this delete in a thread.What changed (motivation → approach → change)
The two deletes block the loop because they call the filesystem straight from an
async def. Both now hand that work to a worker thread, the same wayacp/runtime_start.pyalready callscleanup_transcript_files.AcpProvider.cleanup_session(providers/acp_lifecycle.py)_delete_kiro_session_filesand runs throughdrained_to_thread, as the Claude branch beside it already doesAcpSessionHandle.destroy(acp/session_handle_lifecycle.py)finallyawaitsdrained_to_thread(self._cleanup_transcript)AcpProvider.shutdown(providers/acp_lifecycle.py)finally, so a cancel that lands during the now-awaited delete still reclaims a disposable work dircleanup_transcript_filestranscript cleanup:instead ofdestroy:, since three callers share itdrained_to_thread, not a bareasyncio.to_thread: teardown is where cancellations land, and a bare await cancelled while its worker is still queued drops the delete. Nothing else removes that transcript. The helper keeps a cancelled caller waiting until the delete has finished, then re-raises, so the old synchronous call's guarantee stays.Backwards compatibility
Compatible: the same files are deleted under the same conditions, and the caller still returns only after the delete has finished.
Removes nothing: only the thread the delete runs on and the prefix of two log lines change.
Tests
test/test_acp_transcript_delete_off_loop.pydrives both paths against real files and watches the realPath.unlink:test_the_delete_runs_off_the_event_loop[cleanup_session|destroy]: the sessions-dir lookup and both unlinks run on a thread other than the loop's, and both files are gone.test_a_cancelled_caller_unwinds_only_once_the_delete_finished[cleanup_session|destroy]: the caller is cancelled while its first unlink is in flight; it is still pending when the cancellation has been delivered, then raisesCancelledErrorwith both files gone. With a bareasyncio.to_threadboth cases fail every run.test_a_cancel_during_the_delete_still_reclaims_the_work_dir:shutdownwhose transcript delete raisesCancelledErrorstill runs the work-dir reclaim. It fails without the nestedfinally.Proof: PROVEN test/test_acp_transcript_delete_off_loop.py::test_the_delete_runs_off_the_event_loop[cleanup_session], test/test_acp_transcript_delete_off_loop.py::test_the_delete_runs_off_the_event_loop[destroy], test/test_acp_transcript_delete_off_loop.py::test_a_cancelled_caller_unwinds_only_once_the_delete_finished[cleanup_session], test/test_acp_transcript_delete_off_loop.py::test_a_cancelled_caller_unwinds_only_once_the_delete_finished[destroy], test/test_acp_transcript_delete_off_loop.py::test_a_cancel_during_the_delete_still_reclaims_the_work_dir (head 6e3589e13108)
Determinism: 20 runs at
-n0; 10 runs at-n 4 --dist loadgroup --max-worker-restart=2withtest_acp_session_provider_shutdown.pyandtest_acp_provider_cov80.pyas co-tenants; one shuffled order with that shutdown file (seed 4812). All green.Manual verification
N/A — unit coverage sufficient: the tests run the real teardown code against real files and assert on the thread that performs the real unlink.
Screenshots / video
N/A — no user-visible surface changes.
Related Issues
Closes #23959
Builds on #24003 by @chenmingwei23.
Sibling sweep
Swept: git grep -nE "cleanup_transcript_files|_cleanup_session_files_sync|_cleanup_transcript(" -- src/
Sibling: src/kiro_crew/acp/runtime_start.py:606 -- not affected -- already off the loop through a bare asyncio.to_thread; whether to drain it is outside this issue
Sibling: src/kiro_crew/acp/session_provider.py:691 -- not affected -- already off the loop through a bare asyncio.to_thread; whether to drain it is outside this issue
Sibling: src/kiro_crew/subagent_manager/continuation.py:1333 -- not affected -- sync code that runs on a worker thread
Sibling: src/kiro_crew/subagent_persistence.py:799 -- not affected -- the tombstone prune runs on the maintenance executor
Pattern harvest
Rule candidate: lint
Pattern: blocking filesystem I/O reached from an async def through a same-module sync helper, which check_sync_io_in_async.py does not follow
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement