fix(security): cancel RLM work on host teardown - #1253
Conversation
jonaowen
left a comment
There was a problem hiding this comment.
The cancellation ownership is coherent at exact head: each request captures its kernel-generation signal; all teardown paths abort the controller, restart replaces it before new admission, admission is fenced around awaits, and the once-listener closes the post-registration/pre-publication gap. _cancelRlmChildRun is idempotent, late runtime publication observes cancelled status, and listener cleanup is in the run finally. The real-child dispose and handler-abort tests gate the central lifecycle. A restart-generation regression would be useful but is not merge-blocking. GO at ee15990840fa9db51e45827653bd4c675e04b330.
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 0c0c75c. Configure here.

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
Medium Risk
Cooperative cancellation on kernel teardown affects all in-flight
rlm.runcomm work and RLM child lifecycle; stuck children may still run until the existing bounded dispose wait expires.Overview
Kernel host requests now receive an
AbortSignalfrom a sharedAbortControllerthat is aborted on shutdown, kill, dispose, and resource cleanup; the signal is passed throughHostRequestHandlerand therlm.runbridge intorunRlmChild/_startRlmChildRun.RLM child spawns honor that signal with
throwIfAborted()at admission checkpoints, a one-shot abort listener that calls_cancelRlmChildRun(including aborting an admitted child session), and removal of the listener when the run settles. If cancellation or validation fails after a child session directory was created, that directory is recursively removed so orphanedsub-*dirs are not left behind.On kernel restart, a fresh controller is created when the previous signal was already aborted. A related TODO about plumbing abort through
AgentSession.promptis removed because host-request cancellation is now wired.Reviewed by Cursor Bugbot for commit 6a6ed7d. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Cancel in-flight RLM child runs when the IPython kernel host tears down
AbortController(hostRequestController) toKernelManagerthat is aborted onshutdown,kill,dispose, anddisposeSync, propagating anAbortSignalto all active host request handlers.HostRequestHandler,createRlmRunHostHandler, andAgentSession.runRlmChild/_startRlmChildRunto accept and forward theAbortSignal, so in-flight RLM child runs are cancelled when the kernel stops._startRlmChildRuncheckssignal.throwIfAborted()at key checkpoints and registers an abort listener that transitions the child run to cancelled with a descriptive reason.AbortControlleris created indoStartif the previous one was already aborted, so restarted kernels accept new host requests.rlm.runhost request will now receive a cancellation error on kernel teardown rather than running to completion.Changes since #1253 opened
Macroscope summarized 0c0c75c.