Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: contain throwing onRunStarted hook in emitRunStarted so TUI PTY runs can't orphan (#6002)

[._.]/ Adam Eivyc6d579ec4ca2
diff --git a/server/services/runner.js b/server/services/runner.js
index 4cd3eb42ba..285f4abed6 100644
--- a/server/services/runner.js
+++ b/server/services/runner.js
@@ -244,11 +244,16 @@ export async function resolveRunCwd({ runId, workspacePath, label, startTime = D
* run tracking sees TUI runs as active.
*/
export function emitRunStarted({ runId, provider, model }) {
- runnerConfig.hooks?.onRunStarted?.({
- runId,
- provider: provider?.name || provider?.id,
- model: model ?? provider?.defaultModel,
- });
+ // Fire-and-forget lifecycle notification — a throwing hook must not take
+ // down the already-registered PTY run (same orphaned-run shape as #5792).
+ safeSettle(
+ () => runnerConfig.hooks?.onRunStarted?.({
+ runId,
+ provider: provider?.name || provider?.id,
+ model: model ?? provider?.defaultModel,
+ }),
+ `Run ${runId} onRunStarted hook`,
+ );
}
/**
diff --git a/server/services/runner.test.js b/server/services/runner.test.js
index e5fc76ea33..426fb5e1d8 100644
--- a/server/services/runner.test.js
+++ b/server/services/runner.test.js
@@ -1205,6 +1205,25 @@ describe('emitRunStarted — payload-flattening contract', () => {
model: 'gpt-4',
})).not.toThrow();
});
+
+ it('contains a throwing onRunStarted hook instead of rejecting the TUI spawn path (#6002)', () => {
+ // emitRunStarted fires after the PTY is already registered in the
+ // active-run map (tuiPromptRunner.js), so a throw here would reject the
+ // spawn with a live PTY and no terminal settlement — the same orphaned
+ // shape #5792 closed for the CLI path.
+ const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
+ setAIToolkit(fakeToolkit(), {
+ dataDir: '/tmp/test-runner',
+ hooks: { onRunStarted: () => { throw new Error('tui started hook boom'); } },
+ });
+ expect(() => emitRunStarted({
+ runId: 'r-tui-throw',
+ provider: { name: 'codex', defaultModel: 'gpt-5' },
+ model: 'gpt-4o',
+ })).not.toThrow();
+ expect(errorSpy).toHaveBeenCalledWith(expect.stringContaining('onRunStarted hook threw during recovery'));
+ errorSpy.mockRestore();
+ });
});
describe('executeCliRun — workspace validation (#3180)', () => {