From 276c7d7bca5267bf24d7eb9b93d908ccd1282fc6 Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Thu, 8 Oct 2026 16:00:21 -0700 Subject: [PATCH] fix(desktop): route the composer model picker to the canonical model mutation The picker sends `config.set {key: 'model', value: ' --provider [--session]'}`. The canonical protocol adapter passed that through unchanged, but the authority's config.set accepts only busy/verbose/ YOLO preferences, so every picker selection on a local canonical session failed with invalid_params while a typed `/model ` worked through `session.mutate`. The adapter now prepares a picker value of exactly that shape as the existing fenced `session.mutate` operation `model` (payload {model, provider}, same retained request identity, CAS revision and execution generation as the typed directive) and settles its receipt as `ok`. `--session` is dropped: the canonical model mutation is always session policy and never rewrites config.yaml. Any other flag (e.g. --global) has no canonical field and stays on config.set, which the authority refuses explicitly. Legacy (non-canonical) transports are untouched. Not covered here (gateway side, lane acpapi / DECISION NEEDED): the shared selection-guard confirmation exchange (helix4u item 2) and a deferred next-turn selection while a turn runs; the authority still refuses a mid-turn mutation with session_busy, which the picker now reports instead of a misleading invalid_params. Review: https://github.com/NousResearch/hermes-agent/pull/106742#issuecomment-6067585232 --- .../src/api/canonical-protocol.test.ts | 17 ++++++++++++ apps/desktop/src/api/canonical-protocol.ts | 26 +++++++++++++++++-- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/apps/desktop/src/api/canonical-protocol.test.ts b/apps/desktop/src/api/canonical-protocol.test.ts index 8e7e63f53d..d94f89f124 100644 --- a/apps/desktop/src/api/canonical-protocol.test.ts +++ b/apps/desktop/src/api/canonical-protocol.test.ts @@ -209,3 +209,20 @@ test('the dedicated compress action becomes a fenced canonical mutation and sett expect(await protocol.settle('session.title', { session_id: 's' }, untouched, fakeRequest)).toBe(untouched) expect(calls).toHaveLength(1) }) + +test('the composer model picker travels as the canonical model mutation, not an unsupported config.set', () => { + const protocol = new CanonicalDesktopProtocol() + protocol.result('session.resume', { session_id: 's' }, { session_id: 's', revision: 3, execution_generation: 2 }) + + for (const value of ['gpt-5 --provider openrouter', 'gpt-5 --provider openrouter --session']) { + const pick = protocol.prepare('config.set', { session_id: 's', key: 'model', value }) + expect(protocol.wire('config.set', pick)).toBe('session.mutate') + expect(pick).toEqual({ session_id: 's', request_id: expect.any(String), expected_revision: 3, expected_generation: 2, operation: 'model', payload: { model: 'gpt-5', provider: 'openrouter' } }) + expect(protocol.result('config.set', pick, { session_id: 's', revision: 4, operation: 'model', model: 'gpt-5', provider: 'openrouter' })).toMatchObject({ ok: true, model: 'gpt-5' }) + protocol.result('session.resume', { session_id: 's' }, { session_id: 's', revision: 3, execution_generation: 2 }) + } + + // Other preferences, and model flags the mutation has no field for, keep their own route. + expect(protocol.wire('config.set', protocol.prepare('config.set', { session_id: 's', key: 'busy', value: 'queue' }))).toBe('config.set') + expect(protocol.wire('config.set', protocol.prepare('config.set', { session_id: 's', key: 'model', value: 'gpt-5 --global' }))).toBe('config.set') +}) diff --git a/apps/desktop/src/api/canonical-protocol.ts b/apps/desktop/src/api/canonical-protocol.ts index 6e7ecc77b8..d969505e86 100644 --- a/apps/desktop/src/api/canonical-protocol.ts +++ b/apps/desktop/src/api/canonical-protocol.ts @@ -38,6 +38,22 @@ export function slashMutation(command: string): { operation: string; payload: Re return { operation: name, payload: arg ? { [field]: arg } : {} } } +// The composer picker's `config.set key=model` value: ` --provider [--session]`. The +// canonical model mutation is always session-scoped policy (the authority never rewrites +// config.yaml from it), so `--session` carries no extra meaning; any other flag has no canonical +// field and stays on config.set for the authority to refuse explicitly. +export function pickerModelMutation(value: unknown): { model: string; provider: string } | null { + const [model, ...flags] = String(value ?? '').trim().split(/\s+/) + const sessionOnly = flags.at(-1) === '--session' + const rest = sessionOnly ? flags.slice(0, -1) : flags + + if (!model || model.startsWith('-') || rest.length !== 2 || rest[0] !== '--provider' || !rest[1] || rest[1].startsWith('-')) { + return null + } + + return { model, provider: rest[1] } +} + function mutationSummary(operation: string, value: Record): string { if (operation === 'model') { return `model: ${value.model}${value.provider ? ` (${value.provider})` : ''}` } @@ -93,7 +109,7 @@ export class CanonicalDesktopProtocol { // rebinds the live event transport and returns the same snapshot shape. if (method === 'session.activate') { return 'session.resume' } - return method === 'slash.exec' && typeof prepared.operation === 'string' ? 'session.mutate' : method + return (method === 'slash.exec' || method === 'config.set') && typeof prepared.operation === 'string' ? 'session.mutate' : method } private retainedMutation(sessionId: unknown, profile: unknown, operation: string, payload: Record, withGeneration: boolean): Record { @@ -179,6 +195,12 @@ export class CanonicalDesktopProtocol { return this.retainedMutation(parent, params.profile, 'branch', payload, true) } + if (method === 'config.set' && params.key === 'model') { + const pick = pickerModelMutation(params.value) + + if (pick) { return this.retainedMutation(params.session_id, params.profile, 'model', pick, true) } + } + if (method === 'slash.exec') { const directive = slashMutation(String(params.command ?? '')) @@ -277,7 +299,7 @@ export class CanonicalDesktopProtocol { this.revisions.set(canonicalSessionKey(value.session_id, params.profile), value.revision) } - if (MUTATION_METHODS.has(method) || (method === 'slash.exec' && typeof params.operation === 'string')) { + if (MUTATION_METHODS.has(method) || ((method === 'slash.exec' || method === 'config.set') && typeof params.operation === 'string')) { return this.mutationReceipt(method, params, value) }