From 58a9fcdc8e00c4da5b9b8a423a90c95b574fc251 Mon Sep 17 00:00:00 2001
From: Chris Scott <99081550+chriswritescode-dev@users.noreply.github.com>
Date: Thu, 5 Nov 2026 16:05:29 -0500
Subject: [PATCH] fix: leave agent temperature and top_p unset unless the user
sets them (OM-179)
The agent dialog no longer writes temperature 0.7 and top_p 1 on every save. The fields start empty with a Default placeholder when the agent stores no value; an empty field is omitted, or removed with a merge-patch null when the agent stored it, so the provider default applies.
---
.../components/settings/AgentDialog.test.tsx | 25 +++++++++
.../src/components/settings/AgentDialog.tsx | 52 ++++++++++++++-----
2 files changed, 63 insertions(+), 14 deletions(-)
diff --git a/frontend/src/components/settings/AgentDialog.test.tsx b/frontend/src/components/settings/AgentDialog.test.tsx
index a1bbd1f1..81fa30dc 100644
--- a/frontend/src/components/settings/AgentDialog.test.tsx
+++ b/frontend/src/components/settings/AgentDialog.test.tsx
@@ -359,6 +359,31 @@ describe('AgentDialog', () => {
const agent = onSubmit.mock.calls[0][1]
expect(agent.system).toBe('Review code carefully')
expect(agent).not.toHaveProperty('permissions')
+ expect(agent).not.toHaveProperty('request')
+ })
+
+ it('leaves sampling values unset by default and removes a cleared stored value', async () => {
+ const onSubmit = vi.fn()
+ const user = userEvent.setup()
+ render(
+ ,
+ )
+
+ expect(screen.getByLabelText('Top P')).toHaveValue(null)
+
+ await user.clear(screen.getByLabelText('Temperature'))
+ await user.click(screen.getByRole('button', { name: 'Update' }))
+
+ const agent = onSubmit.mock.calls[0][1]
+ expect(agent.request).toEqual({ body: { temperature: null, reasoning_effort: 'high' } })
})
it('shows the last matching wildcard effect and applies the form effect to every occurrence', async () => {
diff --git a/frontend/src/components/settings/AgentDialog.tsx b/frontend/src/components/settings/AgentDialog.tsx
index b92b1865..6ea68cab 100644
--- a/frontend/src/components/settings/AgentDialog.tsx
+++ b/frontend/src/components/settings/AgentDialog.tsx
@@ -67,18 +67,45 @@ const withManagedPermissionEffects = (
return [...fallbacks, ...updated]
}
+const optionalNumber = (value: string): number | undefined => {
+ const parsed = parseFloat(value)
+ return Number.isNaN(parsed) ? undefined : parsed
+}
+
const requestBodyNumber = (agent: OpenCodeAgentConfig | undefined, key: string): number | undefined => {
const value = agent?.request?.body?.[key]
return typeof value === 'number' ? value : undefined
}
+/**
+ * Writes each sampling value the form sets into `request.body`. A cleared value
+ * is removed with a merge-patch `null` when the agent stored it and omitted
+ * otherwise, so the provider default applies.
+ */
+const withSamplingValues = (
+ previous: OpenCodeAgentConfig | undefined,
+ values: Record<'temperature' | 'top_p', number | undefined>,
+): Pick => {
+ const previousBody = previous?.request?.body ?? {}
+ const body: NonNullable['body']> = { ...previousBody }
+ for (const [key, value] of Object.entries(values)) {
+ if (value !== undefined) {
+ body[key] = value
+ } else if (key in previousBody) {
+ body[key] = null
+ }
+ }
+ if (!previous?.request && Object.keys(body).length === 0) return {}
+ return { request: { ...previous?.request, body } }
+}
+
const agentFormSchema = z.object({
name: z.string().min(1, 'Agent name is required').regex(/^[a-z0-9-]+$/, 'Must be lowercase letters, numbers, and hyphens only'),
description: z.string().optional(),
prompt: z.string().min(1, 'Prompt is required'),
mode: z.enum(['subagent', 'primary', 'all']),
- temperature: z.number().min(0).max(2),
- topP: z.number().min(0).max(1),
+ temperature: z.number().min(0).max(2).optional(),
+ topP: z.number().min(0).max(1).optional(),
model: z.string().optional(),
editPermission: z.enum(['inherit', 'ask', 'allow', 'deny']),
shellPermission: z.enum(['inherit', 'ask', 'allow', 'deny']),
@@ -109,8 +136,8 @@ export function AgentDialog({ open, onOpenChange, onSubmit, editingAgent }: Agen
description: agent?.agent.description || '',
prompt: agent?.agent.system || '',
mode: agent?.agent.mode || 'subagent',
- temperature: requestBodyNumber(agent?.agent, 'temperature') ?? 0.7,
- topP: requestBodyNumber(agent?.agent, 'top_p') ?? 1,
+ temperature: requestBodyNumber(agent?.agent, 'temperature'),
+ topP: requestBodyNumber(agent?.agent, 'top_p'),
model: modelRef ? formatOpenCodeModelRef(modelRef) : '',
editPermission: permissionEffect(agent?.agent.permissions, 'edit'),
shellPermission: permissionEffect(agent?.agent.permissions, 'shell'),
@@ -141,14 +168,7 @@ export function AgentDialog({ open, onOpenChange, onSubmit, editingAgent }: Agen
model: values.model?.trim() || null,
disabled: values.disable,
...(permissions.length > 0 || previous?.permissions ? { permissions } : {}),
- request: {
- ...previous?.request,
- body: {
- ...previous?.request?.body,
- temperature: values.temperature,
- top_p: values.topP,
- },
- },
+ ...withSamplingValues(previous, { temperature: values.temperature, top_p: values.topP }),
}
onSubmit(values.name, agent)
@@ -268,7 +288,9 @@ export function AgentDialog({ open, onOpenChange, onSubmit, editingAgent }: Agen
min="0"
max="2"
step="0.1"
- onChange={(e) => field.onChange(parseFloat(e.target.value))}
+ placeholder="Default"
+ value={field.value ?? ''}
+ onChange={(e) => field.onChange(optionalNumber(e.target.value))}
/>
@@ -289,7 +311,9 @@ export function AgentDialog({ open, onOpenChange, onSubmit, editingAgent }: Agen
min="0"
max="1"
step="0.1"
- onChange={(e) => field.onChange(parseFloat(e.target.value))}
+ placeholder="Default"
+ value={field.value ?? ''}
+ onChange={(e) => field.onChange(optionalNumber(e.target.value))}
/>