From 462b981019a6d69b8a0547ffaeda0a7fbdd5e733 Mon Sep 17 00:00:00 2001
From: Chris Scott <99081550+chriswritescode-dev@users.noreply.github.com>
Date: Thu, 5 Nov 2026 18:04:35 -0500
Subject: [PATCH] fix: delete an emptied permissions or request block instead
of saving it empty (OM-179)
Returning every agent permission to Default now removes the permissions key, and clearing the last sampling value removes the request key, instead of leaving an empty array or an empty body in the config. Found while testing the Settings dialog in a browser.
---
.../components/settings/AgentDialog.test.tsx | 48 +++++++++++++++++++
.../src/components/settings/AgentDialog.tsx | 14 ++++--
2 files changed, 58 insertions(+), 4 deletions(-)
diff --git a/frontend/src/components/settings/AgentDialog.test.tsx b/frontend/src/components/settings/AgentDialog.test.tsx
index 52d3f40c..42ce0688 100644
--- a/frontend/src/components/settings/AgentDialog.test.tsx
+++ b/frontend/src/components/settings/AgentDialog.test.tsx
@@ -374,6 +374,54 @@ describe('AgentDialog', () => {
])
})
+ it('deletes the permissions key when every action returns to Default', async () => {
+ const onSubmit = vi.fn()
+ const user = userEvent.setup()
+ render(
+ ,
+ )
+
+ await user.click(screen.getByRole('combobox', { name: 'Shell' }))
+ await user.click(screen.getByRole('option', { name: 'Default' }))
+ await user.click(screen.getByRole('button', { name: 'Update' }))
+
+ const agent = onSubmit.mock.calls[0][1]
+ expect(agent.permissions).toBeNull()
+ })
+
+ it('deletes the request key when the last sampling value is cleared', async () => {
+ const onSubmit = vi.fn()
+ const user = userEvent.setup()
+ render(
+ ,
+ )
+
+ await user.clear(screen.getByLabelText('Temperature'))
+ await user.click(screen.getByRole('button', { name: 'Update' }))
+
+ const agent = onSubmit.mock.calls[0][1]
+ expect(agent.request).toBeNull()
+ })
+
it('writes no permissions for a prompt-only save of an agent without permission rules', async () => {
const onSubmit = vi.fn()
const user = userEvent.setup()
diff --git a/frontend/src/components/settings/AgentDialog.tsx b/frontend/src/components/settings/AgentDialog.tsx
index 91936f04..763f03a0 100644
--- a/frontend/src/components/settings/AgentDialog.tsx
+++ b/frontend/src/components/settings/AgentDialog.tsx
@@ -106,7 +106,8 @@ const requestBodyNumber = (agent: OpenCodeAgentConfig | undefined, key: string):
/**
* 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.
+ * otherwise, so the provider default applies. A request left with no fields is
+ * deleted instead of being saved as an empty object.
*/
const withSamplingValues = (
previous: OpenCodeAgentConfig | undefined,
@@ -121,8 +122,13 @@ const withSamplingValues = (
body[key] = null
}
}
- if (!previous?.request && Object.keys(body).length === 0) return {}
- return { request: { ...previous?.request, body } }
+ const request = { ...previous?.request, body }
+ const bodyHasValues = Object.values(body).some((value) => value !== null && value !== undefined)
+ const requestHasOtherFields = Object.entries(request).some(
+ ([key, value]) => key !== 'body' && value !== undefined && value !== null,
+ )
+ if (bodyHasValues || requestHasOtherFields) return { request }
+ return previous?.request ? { request: null } : {}
}
const agentFormSchema = z.object({
@@ -203,7 +209,7 @@ export function AgentDialog({ open, onOpenChange, onSubmit, editingAgent }: Agen
mode: values.mode,
model: values.model?.trim() || null,
disabled: values.disable,
- ...(permissions.length > 0 || previous?.permissions ? { permissions } : {}),
+ ...(permissions.length > 0 ? { permissions } : previous?.permissions ? { permissions: null } : {}),
...withSamplingValues(previous, { temperature: values.temperature, top_p: values.topP }),
}