The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): also retry against v0.21.3, whose rejection lacks the out-of-sync suffix
kshitijk4poordd3bc8f48545
diff --git a/apps/desktop/src/app/session/hooks/use-session-actions/session-create-request.test.ts b/apps/desktop/src/app/session/hooks/use-session-actions/session-create-request.test.tsindex 1ce40c3efe6..e40626ea2b4 100644--- a/apps/desktop/src/app/session/hooks/use-session-actions/session-create-request.test.ts+++ b/apps/desktop/src/app/session/hooks/use-session-actions/session-create-request.test.ts@@ -9,12 +9,17 @@ vi.mock('@/store/gateway', () => ({import { createGatewaySession } from './session-create-request'-// Verbatim admission rejection from a backend predating #122899 (tui_gateway/contracts/registry.py).-const PRE_122899_REJECTION = new JsonRpcGatewayError(- 'invalid params for session.create: cwd_explicit: Extra inputs are not permitted — the client and the ' +- 'Hermes backend are out of sync (different versions); run `hermes update` and restart both',- { code: 4000 }-)+// Verbatim admission rejections from backends predating #122899 (tui_gateway/contracts/registry.py).+const rejection = (field: string, suffix = '') =>+ new JsonRpcGatewayError(`invalid params for session.create: ${field}: Extra inputs are not permitted${suffix}`, {+ code: 4000+ })++const OUT_OF_SYNC =+ ' — the client and the Hermes backend are out of sync (different versions); run `hermes update` and restart both'++const PRE_122899_REJECTION = rejection('cwd_explicit', OUT_OF_SYNC) // v0.21.4 – v0.21.5 wording+const V0213_REJECTION = rejection('cwd_explicit') // v0.21.3 wording, no out-of-sync suffixconst params = { cols: 96, cwd: '/work/repo', cwd_explicit: true, profile: 'default', source: 'desktop' }const route = { connectionId: 'cloud', profile: 'default' }@@ -23,20 +28,22 @@ describe('createGatewaySession', () => {beforeEach(() => requestGatewayForAgent.mockReset())it('resends once without cwd_explicit (cwd kept) when a pre-#122899 backend rejects the flag', async () => {- requestGatewayForAgent.mockRejectedValueOnce(PRE_122899_REJECTION).mockResolvedValueOnce({ session_id: 's1' })+ const { cwd_explicit: _flag, ...withoutFlag } = params+ requestGatewayForAgent.mockRejectedValueOnce(PRE_122899_REJECTION).mockResolvedValueOnce({ session_id: 's1' })await expect(createGatewaySession(route, params, vi.fn())).resolves.toEqual({ session_id: 's1' })+ expect(requestGatewayForAgent.mock.calls.map(call => call[3])).toEqual([params, withoutFlag])- const sent = requestGatewayForAgent.mock.calls.map(call => call[3])- const { cwd_explicit: _flag, ...withoutFlag } = params-- expect(sent).toEqual([params, withoutFlag])+ const requestGateway = vi.fn().mockRejectedValueOnce(V0213_REJECTION).mockResolvedValueOnce({ session_id: 's2' })+ await expect(createGatewaySession(null, params, requestGateway)).resolves.toEqual({ session_id: 's2' })+ expect(requestGateway.mock.calls.map(call => call[1])).toEqual([params, withoutFlag])})it('never resends on any other failure, even one that mentions the field', async () => {const failures = [new Error('request timed out'),new Error('handler error: could not resolve cwd_explicit workspace'),+ rejection('some_newer_field', OUT_OF_SYNC),PRE_122899_REJECTION]diff --git a/apps/desktop/src/app/session/hooks/use-session-actions/session-create-request.ts b/apps/desktop/src/app/session/hooks/use-session-actions/session-create-request.tsindex 327758d8bc4..c9fd08be826 100644--- a/apps/desktop/src/app/session/hooks/use-session-actions/session-create-request.ts+++ b/apps/desktop/src/app/session/hooks/use-session-actions/session-create-request.ts@@ -1,4 +1,3 @@-import { isOutOfSyncRpcParams } from '@/lib/gateway-rpc'import { requestGatewayForAgent } from '@/store/gateway'import type { AgentProfileRoute } from '@/store/profile'import type { SessionCreateResponse } from '@/types/hermes'@@ -10,11 +9,13 @@ type RequestGateway = <T>(method: string, params?: Record<string, unknown>) => P* code 4000, handler never runs) — e.g. a Hermes Cloud backend behind a* Desktop that updates from main (#128971). Those backends always honoured the* client `cwd`, so resending without the flag reproduces their behaviour.+ * Matched on the stable prefix, not `isOutOfSyncRpcParams`: v0.21.3 already+ * rejects but predates the "out of sync" suffix.* Delete once no supported backend predates #122899. */-function rejectsCwdExplicit(params: Record<string, unknown>, error: unknown): boolean {- const message = error instanceof Error ? error.message : String(error)+const CWD_EXPLICIT_REJECTED = /invalid params for session\.create: cwd_explicit:/- return 'cwd_explicit' in params && isOutOfSyncRpcParams(message) && /:\s*cwd_explicit:/.test(message)+function rejectsCwdExplicit(params: Record<string, unknown>, error: unknown): boolean {+ return 'cwd_explicit' in params && CWD_EXPLICIT_REJECTED.test(error instanceof Error ? error.message : String(error))}/** `session.create` on the captured owner route (or the window's gateway). */