Summary
The sandbox proxy setup path registers fresh process exit/signal handlers every time a proxy is started, but attempts to remove old handlers using a newly-created function identity. That does not actually detach the previously-registered handlers.
Evidence
In packages/cli/src/utils/sandbox.ts, both proxy setup paths create a new stopProxy closure and then call process.off('exit', stopProxy) / process.on('exit', stopProxy) (and similarly for SIGINT/SIGTERM). Because the function is recreated on each launch, process.off(...) only refers to the new closure and cannot remove earlier registrations.
Impact
Repeated sandbox launches in the same process can accumulate duplicate exit/signal handlers. This can cause duplicated cleanup attempts, noisy teardown behavior, and eventual listener-growth issues in long-lived CLI sessions.
Expected behavior
Proxy cleanup handlers should be registered once per live proxy instance and reliably removed when the proxy is torn down.
Suggested fix
Track the active cleanup handler explicitly and unregister the exact same function reference during teardown before installing a replacement.
Summary
The sandbox proxy setup path registers fresh
processexit/signal handlers every time a proxy is started, but attempts to remove old handlers using a newly-created function identity. That does not actually detach the previously-registered handlers.Evidence
In
packages/cli/src/utils/sandbox.ts, both proxy setup paths create a newstopProxyclosure and then callprocess.off('exit', stopProxy)/process.on('exit', stopProxy)(and similarly forSIGINT/SIGTERM). Because the function is recreated on each launch,process.off(...)only refers to the new closure and cannot remove earlier registrations.Impact
Repeated sandbox launches in the same process can accumulate duplicate exit/signal handlers. This can cause duplicated cleanup attempts, noisy teardown behavior, and eventual listener-growth issues in long-lived CLI sessions.
Expected behavior
Proxy cleanup handlers should be registered once per live proxy instance and reliably removed when the proxy is torn down.
Suggested fix
Track the active cleanup handler explicitly and unregister the exact same function reference during teardown before installing a replacement.