Skip to content

The agent that grows with you

fix(desktop): keep new chats working against a pre-Ultrafast backend

kshitijk4poorbb2a08495ffb
diff --git a/apps/desktop/src/app/session/hooks/use-session-actions/index.ts b/apps/desktop/src/app/session/hooks/use-session-actions/index.ts
index 4e7b9934a75..83c90e92837 100644
--- a/apps/desktop/src/app/session/hooks/use-session-actions/index.ts
+++ b/apps/desktop/src/app/session/hooks/use-session-actions/index.ts
@@ -392,7 +392,9 @@ async function desktopSessionCreateParams(
: {}),
...(selection.effort ? { reasoning_effort: selection.effort } : {}),
fast: selection.fast,
- ...(selection.serviceTier ? { service_tier: selection.serviceTier } : {})
+ // Only Ultrafast needs the tier: `fast` already pins Priority/normal, and a
+ // pre-Ultrafast backend rejects the field (createGatewaySession drops it).
+ ...(selection.serviceTier === 'ultrafast' ? { service_tier: 'ultrafast' } : {})
}
: {})
}
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.ts
index 47cb7ff1fbe..2a45b0af6cc 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,7 +9,7 @@ vi.mock('@/store/gateway', () => ({
import { createGatewaySession } from './session-create-request'
-// Verbatim admission rejections from backends predating #122899 (tui_gateway/contracts/registry.py).
+// Verbatim admission rejections from older backends (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
@@ -49,6 +49,20 @@ describe('createGatewaySession', () => {
expect(requestGateway.mock.calls.map(call => call[1])).toEqual([params, withoutFlag])
})
+ it('drops service_tier (fast kept) for a pre-Ultrafast backend, one rejected field at a time', async () => {
+ const tiered = { ...params, fast: true, service_tier: 'ultrafast' }
+ const { cwd_explicit: _flag, service_tier: _tier, ...legacy } = tiered
+
+ const requestGateway = vi
+ .fn()
+ .mockRejectedValueOnce(rejection('service_tier', OUT_OF_SYNC))
+ .mockRejectedValueOnce(V0213_REJECTION)
+ .mockResolvedValueOnce({ session_id: 's3' })
+
+ await expect(createGatewaySession(null, tiered, requestGateway)).resolves.toEqual({ session_id: 's3' })
+ expect(requestGateway.mock.calls.map(call => call[1])).toEqual([tiered, { ...legacy, cwd_explicit: true }, legacy])
+ })
+
it('never resends on any other failure, even one that mentions the field', async () => {
const cases: Array<[Error, Record<string, unknown>]> = [
[new Error('request timed out'), params],
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.ts
index c9fd08be826..fcc281d077a 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
@@ -4,18 +4,23 @@ import type { SessionCreateResponse } from '@/types/hermes'
type RequestGateway = <T>(method: string, params?: Record<string, unknown>) => Promise<T>
-/** A backend predating #122899 (contract without `cwd_explicit`) rejects the
- * whole create at admission (`tui_gateway/contracts/registry.py::validate_params`,
- * 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.
+/** A backend predating a `session.create` field rejects the whole create at
+ * admission (`tui_gateway/contracts/registry.py::validate_params`, code 4000,
+ * handler never runs) — e.g. a Hermes Cloud backend behind a Desktop that
+ * updates from main (#128971). Each field below is safe to drop for them:
+ * - `cwd_explicit` (#122899): those backends always honoured the client `cwd`.
+ * - `service_tier` (Ultrafast): `fast` still rides, so they get Priority.
* 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. */
-const CWD_EXPLICIT_REJECTED = /invalid params for session\.create: cwd_explicit:/
+ * Delete a field once no supported backend predates it. */
+const DROPPABLE_CREATE_FIELDS = ['cwd_explicit', 'service_tier'] as const
-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))
+function rejectedField(params: Record<string, unknown>, error: unknown): string | undefined {
+ const message = error instanceof Error ? error.message : String(error)
+
+ return DROPPABLE_CREATE_FIELDS.find(
+ field => field in params && message.includes(`invalid params for session.create: ${field}:`)
+ )
}
/** `session.create` on the captured owner route (or the window's gateway). */
@@ -37,15 +42,22 @@ export async function createGatewaySession(
)
: requestGateway<SessionCreateResponse>('session.create', requestParams)
- try {
- return await send(params)
- } catch (error) {
- if (!rejectsCwdExplicit(params, error)) {
- throw error
- }
+ // One resend per dropped field: a backend predating both rejects them one at a time.
+ const create = async (requestParams: Record<string, unknown>): Promise<SessionCreateResponse> => {
+ try {
+ return await send(requestParams)
+ } catch (error) {
+ const field = rejectedField(requestParams, error)
+
+ if (!field) {
+ throw error
+ }
- const { cwd_explicit: _cwdExplicit, ...compatible } = params
+ const { [field]: _dropped, ...compatible } = requestParams
- return send(compatible)
+ return create(compatible)
+ }
}
+
+ return create(params)
}