From 2e3cf87d60079c1d0a4646cd2c8187097190cc02 Mon Sep 17 00:00:00 2001 From: atomic-sentry-bot Date: Wed, 2 Dec 2026 01:02:36 +0000 Subject: [PATCH] fix: address Sentry issue 7877309542 --- ...t-spawn-cause-on-litert-lm-probe-errors.md | 12 ++++++++++ docs/decisions/INDEX.md | 1 + .../host-process-spawn-cause.test.ts | 24 +++++++++++++++++++ src/runtime/litert-lm/host-process.ts | 5 +++- 4 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 docs/decisions/2026-12-02-preserve-host-spawn-cause-on-litert-lm-probe-errors.md create mode 100644 src/runtime/litert-lm/host-process-spawn-cause.test.ts diff --git a/docs/decisions/2026-12-02-preserve-host-spawn-cause-on-litert-lm-probe-errors.md b/docs/decisions/2026-12-02-preserve-host-spawn-cause-on-litert-lm-probe-errors.md new file mode 100644 index 00000000..2d54e0b5 --- /dev/null +++ b/docs/decisions/2026-12-02-preserve-host-spawn-cause-on-litert-lm-probe-errors.md @@ -0,0 +1,12 @@ +--- +date: 2026-12-02 +title: "Preserve the spawn error cause on LiteRT-LM host probe failures" +--- + +# 2026-12-02 — Preserve the spawn error cause on LiteRT-LM host probe failures + +- **Context:** `runLiteRtHostJson` in `src/runtime/litert-lm/host-process.ts` starts the `litert-host` child process and, when `spawn` itself fails, rejected from its `child.on('error')` branch with `new AtomicCoreError(failure.code, ': the LiteRT-LM host could not be started.', String(error))` and no options object. The OS error that caused the failure (`ENOENT`, `EACCES`, `EPERM`, …) was flattened into the scrubbed `details` string, so the `Error.cause` chain was severed. `errorChain(error)` at the `ControlServer` HTTP catch boundary therefore saw only the wrapper code (`ENGINE_INSTALL_FAILED` / `LITERT_LM_HOST_ERROR`), which is in neither the `EXPECTED` nor the `OPERATIONAL` table of `src/telemetry/diagnostics.ts`. The result was a report with `failure_category=unknown`, `failure_reason=unknown`, `cause_code=ENGINE_INSTALL_FAILED` and no `diagnostic_cause_code` — the `ENGINE_INSTALL_FAILED: http request: unknown` event that ATOMIC-CHAT-CORE-F8 shows for a LiteRT-LM build install on Apple Silicon. +- **Decision:** Pass `{ cause: error }` when the `child.on('error')` branch of `runLiteRtHostJson` constructs its `AtomicCoreError`; the code, message and `details` stay byte-identical. +- **Consequences:** `ErrorBody` and `toJSON()` are unchanged on the wire, so the caller still sees the same 500 and the same message. The preserved spawn `Error` puts a recognized OS code (`ENOENT` → `not_found`, `EACCES`/`EPERM` → `disk_permission`) into the cause chain, so `classifyFailure` yields an operational reason and the agent observer emits `diagnostic_cause_code`; the event is still reported, now with the fact that says why the host could not start. Nothing here repairs a missing or non-executable host binary on macOS — the next report names that condition instead of hiding it. +- **Owner:** team. +- **Links:** `src/runtime/litert-lm/host-process.ts`, `src/runtime/litert-lm/host-process-spawn-cause.test.ts`, `docs/decisions/2026-11-06-preserve-cause-on-staged-engine-install-errors.md`, `docs/decisions/2026-11-06-preserve-cause-on-llamacpp-engine-install-errors.md`. diff --git a/docs/decisions/INDEX.md b/docs/decisions/INDEX.md index 8908f90d..4ba975ed 100644 --- a/docs/decisions/INDEX.md +++ b/docs/decisions/INDEX.md @@ -299,3 +299,4 @@ add a new one that says which record it supersedes. - [2026-11-23 — Default every engine to the largest window that fits](2026-11-23-default-every-engine-to-the-largest-window-that-fits.md) - [2026-12-01 — Import local LoRA weights into Core storage](2026-12-01-import-local-lora-weights.md) - [2026-12-01 — Compare sd.cpp memory refusals on one Mac](2026-12-01-compare-sdcpp-memory-on-one-mac.md) +- [2026-12-02 — Preserve the spawn error cause on LiteRT-LM host probe failures](2026-12-02-preserve-host-spawn-cause-on-litert-lm-probe-errors.md) diff --git a/src/runtime/litert-lm/host-process-spawn-cause.test.ts b/src/runtime/litert-lm/host-process-spawn-cause.test.ts new file mode 100644 index 00000000..4bd8d59c --- /dev/null +++ b/src/runtime/litert-lm/host-process-spawn-cause.test.ts @@ -0,0 +1,24 @@ +import { expect, it } from 'vitest' +import { AtomicCoreError } from '../../contracts/index.js' +import { classifyFailure, diagnosticTags } from '../../telemetry/diagnostics.js' +import { runLiteRtHostProbe } from './host-process.js' + +it('keeps the operating-system code of a host spawn failure', async () => { + const error = await runLiteRtHostProbe( + { exe: '/nonexistent/atomic-chat-fixture/litert-host', args: [] }, + '/builds/fixture', + { timeoutMs: 5_000 } + ).then( + () => { + throw new Error('the probe unexpectedly resolved') + }, + (reason: unknown) => reason + ) + expect(error).toBeInstanceOf(AtomicCoreError) + expect((error as AtomicCoreError).code).toBe('ENGINE_INSTALL_FAILED') + expect((error as AtomicCoreError).message).toBe( + 'The LiteRT-LM build does not load: the LiteRT-LM host could not be started.' + ) + const tags = diagnosticTags(error, classifyFailure(error, { component: 'http', operation: 'request' })) + expect(tags).toMatchObject({ diagnostic_cause_code: 'ENOENT', cause_code: 'ENOENT' }) +}) diff --git a/src/runtime/litert-lm/host-process.ts b/src/runtime/litert-lm/host-process.ts index c708803b..4fbb63d4 100644 --- a/src/runtime/litert-lm/host-process.ts +++ b/src/runtime/litert-lm/host-process.ts @@ -95,11 +95,14 @@ export function runLiteRtHostJson( }, timeoutMs) child.on('error', (error) => { clearTimeout(timer) + // The spawn `Error` carries the OS code (ENOENT, EACCES, EPERM, ...) that says why the host + // could not start; keep it on the cause chain so the failure is classified and reported. reject( new AtomicCoreError( failure.code, `${failure.what}: the LiteRT-LM host could not be started.`, - String(error) + String(error), + { cause: error } ) ) })