fix(lifecycle): overlap refinement drain with kernel teardown - #1265
Closed
sethkarten wants to merge 16 commits into
Closed
fix(lifecycle): overlap refinement drain with kernel teardown#1265sethkarten wants to merge 16 commits into
sethkarten wants to merge 16 commits into
Conversation
7 tasks
sethkarten
marked this pull request as ready for review
August 12, 2026 06:00
…ifecycle-teardown
…ifecycle-teardown
…ifecycle-teardown
sethkarten
force-pushed
the
core07-lifecycle-teardown
branch
from
August 12, 2026 18:34
1c5b9c0 to
034c229
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit ed8324b. Configure here.
Contributor
Author
sethkarten
added a commit
that referenced
this pull request
Aug 13, 2026
Reconstruct the unique net delta from PR #1265, excluding propagation merges.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Validation
biome check(changed files)tsgo --noEmitremains blocked by pre-existing Core06 mismatch:sdk-mcp-boundary.test.tsimports missinginvokeHostRequestfromhost-request-context.tsNote
Run refinement drain and kernel teardown concurrently in
AgentSession.disposeAsyncdisposeAsyncnow starts_drainPendingRefinementForDisposal()and_ipythonKernelProvisioner?.dispose()concurrently usingPromise.allSettled, then aggregates failures into anAggregateErrorif more than one occurs._disposedis already true) receive the same shared teardown promise result, including any rejection._buildRuntimeandreloadnow throw immediately if called after async teardown has started, guarded by the new_asyncTeardownStartedflag set before anyawait._disposeAsyncOnce; errors are now surfaced rather than swallowed._disposeAsyncOnceare now propagated to callers ofdisposeAsync.Macroscope summarized c954d4d.
Note
Medium Risk
Changes session teardown ordering and error semantics for IPython kernel snapshots and refinement drain; mistakes could affect graceful quit or concurrent disposal behavior.
Overview
AgentSession.disposeAsyncnow runs the pending refinement drain and IPython kernel provisioner teardown in parallel (Promise.allSettled) instead of awaiting the kernel only after the drain finishes. Final session cleanup still runs afterward, with afinallythat callsdispose()and awaits dispose callbacks even when drain or kernel steps fail; callers get a single thrown error or anAggregateErrorwhen both paths fail.Concurrent
disposeAsynccallers always join the same in-flight promise (including after_disposedis set), so late callers see the same terminal rejection instead of resolving early.A new
_asyncTeardownStartedflag blocksreloadand_buildRuntimeduring async teardown so the runtime cannot replace the kernel mid-disposal. Kerneldisposeis invoked fromdisposeAsyncrather than_disposeAsyncOnce.Tests cover parallel start ordering, shared failures across concurrent/late callers, reload blocking, and aggregated errors.
Reviewed by Cursor Bugbot for commit c954d4d. Bugbot is set up for automated code reviews on this repo. Configure here.