Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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, '<what>: 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`.
1 change: 1 addition & 0 deletions docs/decisions/INDEX.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
24 changes: 24 additions & 0 deletions src/runtime/litert-lm/host-process-spawn-cause.test.ts
Original file line number Diff line number Diff line change
@@ -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' })
})
5 changes: 4 additions & 1 deletion src/runtime/litert-lm/host-process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,14 @@ export function runLiteRtHostJson<T>(
}, 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 }
)
)
})
Expand Down
Loading