From fbc63468fb282132ae4495f2302155aa1ab2b6ca Mon Sep 17 00:00:00 2001 From: Emilia <100027345+sovietspaceship@users.noreply.github.com> Date: Tue, 6 Oct 2026 09:46:47 +0100 Subject: [PATCH] fix(core): Shut the regex engine down on every exit path, document the getter override shape exitSuccessFully() was the only path that shut the regex engine down; one-off commands and the engine v2 data plane both exit without it, so a future engine with real teardown would leak there. Also note that needsRegexEngine, unlike its sibling needs* flags, must be overridden as a getter, not a field. Co-Authored-By: Claude Sonnet 5 --- packages/cli/src/commands/base-command.ts | 4 +++- packages/cli/src/commands/engine.ts | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/cli/src/commands/base-command.ts b/packages/cli/src/commands/base-command.ts index 9e48a3dda1d..b791cd8e39a 100644 --- a/packages/cli/src/commands/base-command.ts +++ b/packages/cli/src/commands/base-command.ts @@ -115,7 +115,8 @@ export abstract class BaseCommand { /** * Whether to init the regex engine. Defaults to `needsExpressionEngine`: a command * that evaluates workflow expressions also evaluates a user's regexes. Override only - * where the two genuinely diverge. + * where the two genuinely diverge, and as a getter (`override get needsRegexEngine()`): + * unlike the other `needs*` flags, this one can't be overridden as a field. */ get needsRegexEngine(): boolean { return this.needsExpressionEngine; @@ -612,6 +613,7 @@ export abstract class BaseCommand { async finally(error: Error | undefined) { if (error?.message) this.logger.error(error.message); if (inTest || this.constructor.name === 'Start') return; + if (this.needsRegexEngine) this.regexEngineService.shutdown(); if (this.dbConnection.connectionState.connected) { await sleep(100); // give any in-flight query some time to finish await this.dbConnection.close(); diff --git a/packages/cli/src/commands/engine.ts b/packages/cli/src/commands/engine.ts index 630421c308b..bdcbb087df0 100644 --- a/packages/cli/src/commands/engine.ts +++ b/packages/cli/src/commands/engine.ts @@ -77,6 +77,7 @@ export class Engine extends BaseCommand { await this.responseSender?.stop(); } await Expression.disposeExpressionEngine(); + if (this.needsRegexEngine) this.regexEngineService.shutdown(); } catch (error) { await this.exitWithCrash('There was an error shutting down the engine.', error); }