fix(security): cancel RLM work on host teardown - #1253
Open
sethkarten wants to merge 1 commit into
Open
Conversation
| @@ -1501,10 +1518,10 @@ export class KernelManager { | |||
| return (async () => { | |||
| // Final namespace flush while the kernel is still live (session end / reload). | |||
| await this.flushSnapshotForDispose(); | |||
There was a problem hiding this comment.
🟡 Medium kernel/index.ts:1520
In-flight host requests (e.g. rlm.run) continue running for up to 5 seconds during disposal because abortHostRequests is called after flushSnapshotForDispose(). The snapshot enqueues via enqueueExecute, which serializes behind the busy host-request execution. Since the abort signal hasn't been delivered yet, the snapshot flush blocks on its SNAPSHOT_DISPOSE_TIMEOUT_MS guard before abortHostRequests ever fires. Move abortHostRequests before the flush so the host request is cancelled immediately and the snapshot can proceed (or skip) without the 5-second stall. The same ordering issue exists in shutdown() (line 1374) when opts.snapshot is true.
🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file @packages/coding-agent/src/core/kernel/index.ts around line 1520:
In-flight host requests (e.g. `rlm.run`) continue running for up to 5 seconds during disposal because `abortHostRequests` is called *after* `flushSnapshotForDispose()`. The snapshot enqueues via `enqueueExecute`, which serializes behind the busy host-request execution. Since the abort signal hasn't been delivered yet, the snapshot flush blocks on its `SNAPSHOT_DISPOSE_TIMEOUT_MS` guard before `abortHostRequests` ever fires. Move `abortHostRequests` before the flush so the host request is cancelled immediately and the snapshot can proceed (or skip) without the 5-second stall. The same ordering issue exists in `shutdown()` (line 1374) when `opts.snapshot` is true.
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
rlm.runbridgeThis is the host-cancellation portion extracted from #1159 and proposed directly against current
main.Risk
Medium. Cancellation remains cooperative; an unresponsive child can outlive the cancellation request until the existing bounded kernel-disposal wait expires. The new behavior only applies when the owning kernel host is torn down.
Provenance
Extracted from independently authored commits
a3ba5dba6e8c280caa20cdca88f057810c35bb1aand8d47a2e9191b6d2b516c979b19c7a8fb9b3b2999in #1159. Their exact SHAs are recorded in the commit message. The separate clipboard changes from the first source commit are intentionally excluded here.Validation
npm run checknpm run test -- test/agent-session-recursion.test.ts— 97 passedgit diff --check origin/main...HEADReview focus
Please focus on abort-signal lifetime, listener cleanup, idempotent child cancellation, and disposal/restart ordering.
Note
Cursor Bugbot is generating a summary for commit ee15990. Configure here.
Note
Cancel in-flight RLM child runs when the kernel host is torn down
AbortController(hostRequestController) toKernelManagerthat is aborted on shutdown, kill, dispose, and cleanup, propagating a reason-specific error to all in-flight host requests.HostRequestHandler,handleHostRequest,runRlmChild, and_startRlmChildRunto accept and forward an optionalAbortSignal, so cancellation reaches the RLM child run._startRlmChildRunnow checks for abort before authentication/model resolution and before session-name assertion, and registers an abort listener that marks the run as cancelled with the abort reason.AbortControlleris created ondoStartif the previous one was already aborted, so restarted kernels are not pre-aborted.rlm.runsubagent work will be cancelled (and marked cancelled) whenever the kernel shuts down, is killed, or is disposed — previously these runs would continue until they completed or timed out.📊 Macroscope summarized ee15990. 3 files reviewed, 0 issues evaluated, 0 issues filtered, 0 comments posted
🗂️ Filtered Issues
No issues evaluated.