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 }