From 331c5922fe99ebd1db4d445fdfcf439cfeea3fc1 Mon Sep 17 00:00:00 2001 From: Brennan Benson <79079362+brennanb2025@users.noreply.github.com> Date: Tue, 17 Nov 2026 00:48:17 -0800 Subject: [PATCH] fix(native-chat): a non-string host id no longer crashes the terminal workbench (#43499) * fix(execution-host): a non-string saved host id no longer crashes the terminal workbench Crash d1e50ca3 (1.4.259, Windows): rendering a chat name passed a non-string executionHostId into normalizeHostPart, which threw 'e?.trim is not a function' and took down the terminal workbench boundary. Treat it as absent, as blank is. * fix(execution-host): take unknown at the host-id parse boundary instead of casting in the test * fix(execution-host): a repo with a non-string host id no longer proves it is local * fix(native-chat): guard only the chat-name host lookup, not the shared host-id parser Reviewers found that making the shared parser read a non-string as absent turns it into 'local' for worktree removal and trash cleanup, which could act on this machine's disk. Restore the shared parser and check the type at the one render path the crash report hit. --- .../structured-agent-session-owner.test.ts | 10 ++++++++++ .../structured-agent-session-owner.ts | 5 +++-- 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 src/renderer/src/runtime/native-chat/session-ownership/structured-agent-session-owner.test.ts diff --git a/src/renderer/src/runtime/native-chat/session-ownership/structured-agent-session-owner.test.ts b/src/renderer/src/runtime/native-chat/session-ownership/structured-agent-session-owner.test.ts new file mode 100644 index 00000000000..ad1c8c54b1a --- /dev/null +++ b/src/renderer/src/runtime/native-chat/session-ownership/structured-agent-session-owner.test.ts @@ -0,0 +1,10 @@ +import { describe, expect, it } from 'vitest' +import { structuredAgentSessionTargetForHost } from './structured-agent-session-owner' + +describe('structuredAgentSessionTargetForHost', () => { + // A non-string host id reached render and threw `e?.trim is not a function` (crash d1e50ca3). + it('serves no runtime for a non-string host id instead of throwing', () => { + expect(structuredAgentSessionTargetForHost(42)).toBeNull() + expect(structuredAgentSessionTargetForHost({ id: 'local' })).toBeNull() + }) +}) diff --git a/src/renderer/src/runtime/native-chat/session-ownership/structured-agent-session-owner.ts b/src/renderer/src/runtime/native-chat/session-ownership/structured-agent-session-owner.ts index 9824b9f4e3b..8e767d376e3 100644 --- a/src/renderer/src/runtime/native-chat/session-ownership/structured-agent-session-owner.ts +++ b/src/renderer/src/runtime/native-chat/session-ownership/structured-agent-session-owner.ts @@ -27,9 +27,10 @@ import type { RuntimeClientTarget } from '../../../../../shared/remote-runtime/h * runtime serves: an SSH host, or the catalog's unresolved-owner sentinel. */ export function structuredAgentSessionTargetForHost( - executionHostId: string | null | undefined + executionHostId: unknown ): RuntimeClientTarget | null { - const host = parseExecutionHostId(executionHostId) + // Render reads unchecked tab and wire stamps: a non-string owner has no runtime, not a crash. + const host = typeof executionHostId === 'string' ? parseExecutionHostId(executionHostId) : null return host ? runtimeRpcTargetForAuthorityKey(host.id) : null }