Skip to content

fix(desktop): stop logging a handler stack for expected session-probe 404s - #79266

Open
hernanda-git wants to merge 1 commit into
NousResearch:mainfrom
hernanda-git:fix/desktop-quiet-expected-session-404-ipc-logging
Open

fix(desktop): stop logging a handler stack for expected session-probe 404s#79266
hernanda-git wants to merge 1 commit into
NousResearch:mainfrom
hernanda-git:fix/desktop-quiet-expected-session-404-ipc-logging

Conversation

@hernanda-git

Copy link
Copy Markdown

Fixes #79265

Symptom

hermes desktop prints a full stack trace for a routine, already-handled session lookup — several times on startup, and again on every session switch:

Error occurred in handler for 'hermes:api': Error: 404: {"detail":"Session not found"}
    at IncomingMessage.<anonymous> (.../dist/electron-main.mjs:16394:20)
    at IncomingMessage.emit (node:events:521:24)
    at endReadableNT (node:internal/streams/readable:1729:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:90:21)

Nothing is broken — but it reads as a crash, and it buries genuine hermes:api handler failures in the same stream.

Root cause

Session resolution is a deliberate probe ladderresolveStoredSession() in apps/desktop/src/app/session/hooks/use-session-actions/utils.ts:

  1. the sidebar cache;
  2. a bare by-id GET /api/sessions/{id} on the active backend;
  3. the same GET scoped to each other profile, until one hits.

A miss on rungs 2 and 3 is the ladder working as designed. The backend correctly answers 404 {"detail":"Session not found"} (hermes_cli/web_routers/sessions.py), and the renderer's catch exists precisely to fall to the next rung — the code even says so:

} catch {
  // Not on the active profile — fall through to the cross-profile probe.
}

fetchSessionLinkTitle documents the same 404 as "no title".

The noise is a pure transport artifact: ipcMain.handle logs Error occurred in handler for '<channel>' with a full stack for every rejected invoke, and Electron has no per-handler opt-out. So a designed fall-through is reported as a handler crash. More profiles → more probes → more stack traces.

The fix

Extract the handler body into handleHermesApiRequest, and for that one expected case resolve with a sentinel instead of rejecting. preload.ts — our own code on the other side of the same seam — rethrows it as an Error carrying the identical 404: <body> message.

The renderer contract is byte-identical: the ladder, its catch blocks, and its existing tests are untouched. Only Electron's default handler logging is bypassed, and only for this case. Every other failure rejects as before and still logs in full.

The shared literal and both helpers live in a new electron/api-expected-404.ts so main and preload can't drift apart, with the reasoning documented at the top of the file.

Why not just swallow it in main? The renderer must still see a rejection — the ladder branches on it. Returning null would make "not on this profile" indistinguishable from a real empty response.

Why is the sentinel check narrow? isExpectedNotFoundSentinel accepts only a plain object whose only key is the sentinel and whose value is a string, so no backend payload (including one that happened to carry that key alongside real data) can be mistaken for one.

Tests

New apps/desktop/electron/api-expected-404.test.ts (5 tests):

  • a handler-produced sentinel is recognized;
  • 10 non-sentinel shapes — null, arrays, a wrapped sentinel, wrong value type, right key with real data alongside — are all rejected;
  • unwrap rethrows with the exact original message;
  • real responses pass through by reference (no copy, no churn);
  • the rethrown message still satisfies the renderer's 404-shaped probe predicate — the seam can't silently change what the ladder sees.
✓ electron/api-expected-404.test.ts (5 tests)
  Tests  5 passed (5)

Existing consumers still green:

✓ src/app/session/hooks/use-session-actions/resolve-stored-session.test.ts (7 tests)
✓ src/hermes.test.ts (19 tests)
  Tests  26 passed (26)

Full electron project: 18 failing on main → 17 with this branch (+5 new passing). The remaining failures are pre-existing and unrelated to this change (ssh-config, ssh-connection, wsl-path-bridge, windows-hermes-path, before-pack, stage-native-deps — POSIX/env-dependent tests that fail on a Windows checkout).

npx tsc -p tsconfig.electron.json --noEmit is clean.

Verified on Windows 10.

Note

Same log excerpt as #79245 / #79250, but a genuinely separate bug — that one is simple-git warning spam from the git review ops; this one is IPC error logging for a designed fall-through. Kept as separate issues and separate PRs so each can be judged on its own merits. This branch is cut from main and does not depend on #79250.

… 404s

resolveStoredSession() is a probe ladder — cache, then a by-id GET on the
active backend, then the same GET scoped to each other profile until one
hits. A miss on rungs 2 and 3 is expected and already handled: the backend
answers 404 {"detail":"Session not found"} and the renderer falls to the
next rung.

But ipcMain.handle logs "Error occurred in handler for 'hermes:api'" with a
full stack for every rejected invoke, with no per-handler opt-out — so each
designed fall-through printed a multi-line stack on startup and on every
session switch, burying real hermes:api failures.

Extract the handler body, and for that one expected case resolve with a
sentinel instead of rejecting; preload — our own code on the other side of
the same seam — rethrows it as an Error with the identical '404: <body>'
message. The renderer contract is byte-identical (the ladder and its tests
are untouched); only Electron's logging is bypassed. Every other failure
still rejects and still logs in full.

The sentinel check is deliberately narrow (a plain object whose only key is
the sentinel, with a string value) so no backend payload can be mistaken
for one.

Fixes NousResearch#79265
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/desktop Electron desktop app (apps/desktop/*) P3 Low — cosmetic, nice to have type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Desktop logs a handler stack trace for every expected "Session not found" 404 in the session probe ladder

2 participants