Skip to content

fix(acp): delete kiro-cli transcripts off the event loop on teardown - #31395

Merged
KiroCrewCaptain merged 1 commit into
mainfrom
fix/23959-transcript-delete-off-loop
Nov 7, 2026
Merged

KiroCrewCaptain merged 1 commit into
mainfrom
fix/23959-transcript-delete-off-loop

Conversation

@bolichen97

@bolichen97 bolichen97 commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

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 + .jsonl directly on the event loop: AcpProvider.cleanup_session (an incognito or temporary chat's shutdown) and AcpSessionHandle.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). destroy runs for titles, suggestions, folders and nav on nearly every chat, so this is a hot path, not a rare one.

Not a goal

  • Teaching scripts/check_sync_io_in_async.py to follow same-module sync helpers (the issue's separate suggestion).
  • Changing acp/runtime_start.py or acp/session_provider.py, which already run this delete in a thread.
  • Changing which files are deleted, or when.

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 way acp/runtime_start.py already calls cleanup_transcript_files.

Path Change
AcpProvider.cleanup_session (providers/acp_lifecycle.py) the kiro-cli delete moves into _delete_kiro_session_files and runs through drained_to_thread, as the Claude branch beside it already does
AcpSessionHandle.destroy (acp/session_handle_lifecycle.py) its finally awaits drained_to_thread(self._cleanup_transcript)
AcpProvider.shutdown (providers/acp_lifecycle.py) the work-dir reclaim sits in a nested finally, so a cancel that lands during the now-awaited delete still reclaims a disposable work dir
cleanup_transcript_files its two log lines say transcript cleanup: instead of destroy:, since three callers share it

drained_to_thread, not a bare asyncio.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.py drives both paths against real files and watches the real Path.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 raises CancelledError with both files gone. With a bare asyncio.to_thread both cases fail every run.
  • test_a_cancel_during_the_delete_still_reclaims_the_work_dir: shutdown whose transcript delete raises CancelledError still runs the work-dir reclaim. It fails without the nested finally.

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=2 with test_acp_session_provider_shutdown.py and test_acp_provider_cov80.py as 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

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision fb53bc81d36680fbba02c800813bbb1f9797a42d touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 6, 2026
@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of fb53bc81d36680fbba02c800813bbb1f9797a42d — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

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

  • acp/session_handle_lifecycle.py now imports drained_to_thread from dashboard/. The acp package already imports from dashboard/ in other places, but this is another case of the ACP layer depending on the dashboard. A generic helper like this one could live in a neutral module as a follow-up.

[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 .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of fb53bc81d36680fbba02c800813bbb1f9797a42d — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

The fix moves the transcript delete off the loop at the code that did the blocking; the nested finally is needed because of the new await. The one note is an older duplicate that this PR keeps.

Notes

  • Item 1 — duplicate of src/kiro_crew/acp/session_handle_lifecycle.py:385 (cleanup_transcript_files): the new _delete_kiro_session_files is the base's inline kiro-cli unlink loop moved into its own function. It is a second copy of the same <sid>.json/.jsonl delete with its own traversal guard. The copy predates this PR, so this is a note, not a blocker. Subtraction: delete _delete_kiro_session_files and call drained_to_thread(AcpSessionHandle.cleanup_transcript_files, session_id), the way runtime_start.py:606 and session_provider.py:691 already do.

What this change ships

Inventory (4 items) — 3 justified

Intent: stop a finished session's kiro-cli transcript delete from stalling the gateway event loop on a slow home mount. FIX.

  1. An incognito or temporary chat's shutdown deletes its kiro-cli transcript in a worker thread, and waits for it if cancelled — duplicate of acp/session_handle_lifecycle.py:cleanup_transcript_files
  2. Every ephemeral session's destroy deletes its transcript in a worker thread, and waits for it if cancelled — justified
  3. A cancel that lands during the transcript delete in provider shutdown still reclaims the disposable work dir — justified
  4. The shared transcript-cleanup log lines say transcript cleanup: instead of destroy: — rides along

[FIRST-PRINCIPLES-REVIEWED] fb53bc8

Description read

[DESCRIPTION-READ] cbcb5203d916dc3d854cbbd7de9118312172abd43db7cca5e6ae21f736e9d66f

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@bolichen97
bolichen97 enabled auto-merge (squash) November 6, 2026 12:13
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 6, 2026
@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of fb53bc81d36680fbba02c800813bbb1f9797a42d and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] fb53bc8

False positive or not applicable? A repository writer can comment:
/ai-review override gpt fb53bc81d36680fbba02c800813bbb1f9797a42d false-positive: <reason, 20 to 500 characters>

@bolichen97
bolichen97 force-pushed the fix/23959-transcript-delete-off-loop branch from a32ac6d to 42cd694 Compare November 6, 2026 14:49
@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in src/kiro_crew/acp/client_class.py, src/kiro_crew/acp/client_start.py, src/kiro_crew/acp/kas_agents.py and 50 more files this PR imports or sits beside since this head went green (b764e20 -> 85ce466); CI re-running.

[operator: bolichen97]

@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Nov 6, 2026
@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed fb53bc81d36680fbba02c800813bbb1f9797a42d — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] fb53bc8

Verdict parsed from the review's SHA-scoped output markers for commit fb53bc81d36680fbba02c800813bbb1f9797a42d.

False positive or not applicable? A repository writer can comment:
/ai-review override fable fb53bc81d36680fbba02c800813bbb1f9797a42d false-positive: <reason, 20 to 500 characters>

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 6, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] The only red on this head is test/test_security_gate_liveness.py::test_the_package_stays_within_its_line_budget (Linux and Windows shard 2, plus the Coverage Gate that follows them). It fails the same way on main: the kiro_crew.security package is 34,733 lines on main against a budget of 34,699, and this PR changes no file in that package. #31469 fixes it on main. This PR waits for that to merge, then rebases onto it.

@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] Update on the same red: #31469 merged and raised the budget to 34733, but main grew again after it (now 34753 lines in the kiro_crew.security package; this PR still touches no file there), so a rebase today would fail test_the_package_stays_within_its_line_budget the same way. The follow-up fix is #31625. This PR waits for it, then rebases onto it.

@bolichen97
bolichen97 force-pushed the fix/23959-transcript-delete-off-loop branch from 42cd694 to a707a73 Compare November 6, 2026 23:42
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Nov 6, 2026
@github-actions github-actions Bot added the readiness: action required A blocking check or review needs attention label Nov 7, 2026
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.
@bolichen97
bolichen97 force-pushed the fix/23959-transcript-delete-off-loop branch from a707a73 to fb53bc8 Compare November 7, 2026 01:58
@bolichen97

Copy link
Copy Markdown
Contributor Author

self-added: yes
mechanism: nested finally so the work-dir reclaim survives a cancel during the transcript delete

  • Cancellation skips disposable work-directory cleanup span=72bf040f40bc

fixed in fb53bc8: shutdown now runs _reclaim_work_dir() in a nested finally around the transcript cleanup, so a CancelledError raised by the now-awaited delete still reclaims a disposable work dir before it propagates. test_a_cancel_during_the_delete_still_reclaims_the_work_dir fails without the nested finally and passes with it.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Nov 7, 2026

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved for the on-call. Review lanes pass on fb53bc8, no conflict, no open change request.

@KiroCrewCaptain
KiroCrewCaptain merged commit 3fb2a88 into main Nov 7, 2026
97 of 105 checks passed
@KiroCrewCaptain
KiroCrewCaptain deleted the fix/23959-transcript-delete-off-loop branch November 7, 2026 02:59
buluoray pushed a commit that referenced this pull request Nov 9, 2026
…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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

readiness: passed Eligible automated validation passed for the current revision

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(acp): two more transcript deletions run on the event loop behind a sync helper

2 participants