From 70b2927c88d9a0d86c81dc253cc700a24755d611 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fibili=C5=9Fim?= <96491510+Fibilisim-Tekno@users.noreply.github.com> Date: Sun, 13 Sep 2026 10:29:18 +0300 Subject: [PATCH] fix(cli): use the static spinner when starting the embedding daemon The managed local-embeddings daemon started through the animated clack spinner, which takes stdin over via @clack/core's block() and calls setRawMode(true). Nothing ever restores cooked mode, and a console in raw mode does not translate Ctrl-C into a signal at all, so `ktx ingest` became impossible to interrupt for the rest of the run. clack.ts already documents this hazard directly above createStaticCliSpinner, which writes to stderr only and never touches stdin. Switch the call site to it. Fixes #361 --- packages/cli/src/managed-local-embeddings.ts | 9 ++-- .../cli/test/managed-local-embeddings.test.ts | 46 ++++++++++++++++++- 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/packages/cli/src/managed-local-embeddings.ts b/packages/cli/src/managed-local-embeddings.ts index 999b38c1..bca1349d 100644 --- a/packages/cli/src/managed-local-embeddings.ts +++ b/packages/cli/src/managed-local-embeddings.ts @@ -1,6 +1,6 @@ import type { KtxEmbeddingConfig } from './llm/types.js'; import type { KtxCliIo } from './cli-runtime.js'; -import { createCliSpinner } from './clack.js'; +import { createStaticCliSpinner } from './clack.js'; import { ensureManagedPythonCommandRuntime, type KtxManagedPythonInstallPolicy, @@ -66,8 +66,11 @@ export async function ensureManagedLocalEmbeddingsDaemon( io: options.io, feature: 'local-embeddings', }); - const spinner = createCliSpinner(options.io); - spinner.start('Starting ktx embedding daemon (first run downloads the model)…'); + // Static, stderr-only spinner on purpose: the animated clack spinner seizes + // stdin through @clack/core's block() and leaves the tty in raw mode, which + // stops Ctrl-C from generating SIGINT for the rest of the ingest. + const spinner = createStaticCliSpinner(options.io); + spinner.start('Starting ktx embedding daemon (first run downloads the model)\u2026'); let daemon: ManagedPythonDaemonStartResult; try { daemon = await startDaemon({ diff --git a/packages/cli/test/managed-local-embeddings.test.ts b/packages/cli/test/managed-local-embeddings.test.ts index 004e9302..e53e3ddf 100644 --- a/packages/cli/test/managed-local-embeddings.test.ts +++ b/packages/cli/test/managed-local-embeddings.test.ts @@ -8,12 +8,13 @@ import type { ManagedPythonCommandRuntime } from '../src/managed-python-command. import type { ManagedPythonDaemonStartResult } from '../src/managed-python-daemon.js'; import type { ManagedPythonDaemonLayout } from '../src/managed-python-runtime.js'; -function makeIo() { +function makeIo(stdoutIsTty = false) { let stdout = ''; let stderr = ''; return { io: { stdout: { + isTTY: stdoutIsTty, write: (chunk: string) => { stdout += chunk; }, @@ -161,6 +162,49 @@ describe('ensureManagedLocalEmbeddingsDaemon', () => { expect(io.stderr()).toContain('Using ktx daemon: http://127.0.0.1:61234'); }); + + it('keeps the spinner static on a TTY so the daemon start cannot leave stdin in raw mode', async () => { + // Regression test for #361. On a TTY the animated clack spinner takes + // stdin over through @clack/core's block(), which calls setRawMode(true) + // and is never undone, killing Ctrl-C for the rest of the ingest. The + // static spinner writes to stderr only and never touches stdin, so the + // giveaway is that stdout stays completely empty even when it is a TTY. + const io = makeIo(true); + + await ensureManagedLocalEmbeddingsDaemon({ + cliVersion: '0.2.0', + projectDir: '/work/proj', + installPolicy: 'auto', + io: io.io, + ensureRuntime: vi.fn(async () => runtime()), + startDaemon: vi.fn(async () => daemonResult('started')), + }); + + expect(io.stdout()).toBe(''); + expect(io.stderr()).toContain('Starting ktx embedding daemon'); + expect(io.stderr()).toContain('Started ktx daemon: http://127.0.0.1:61234'); + }); + + it('reports the failure through the same static spinner and rethrows', async () => { + const io = makeIo(true); + const boom = new Error('daemon exploded'); + + await expect( + ensureManagedLocalEmbeddingsDaemon({ + cliVersion: '0.2.0', + projectDir: '/work/proj', + installPolicy: 'auto', + io: io.io, + ensureRuntime: vi.fn(async () => runtime()), + startDaemon: vi.fn(async () => { + throw boom; + }), + }), + ).rejects.toBe(boom); + + expect(io.stdout()).toBe(''); + expect(io.stderr()).toContain('ktx embedding daemon failed to start'); + }); }); describe('tryUseManagedLocalEmbeddingsDaemon', () => {