Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(control-ui): reset overview drafts on cancel so discarded edits never persist

Diego Zacariasaa42121a9add
diff --git a/control-ui/app/hosts/[name]/page.tsx b/control-ui/app/hosts/[name]/page.tsx
index f1f528128..1237b2550 100644
--- a/control-ui/app/hosts/[name]/page.tsx
+++ b/control-ui/app/hosts/[name]/page.tsx
@@ -100,6 +100,17 @@ export default function HostDetailsPage() {
const [hostNameDraft, setHostNameDraft] = useState(routeName)
const [hostDisplayDraft, setHostDisplayDraft] = useState('')
const [contextRefDraft, setContextRefDraft] = useState('')
+ // Last server-backed snapshot of the Overview-owned fields, captured at every
+ // (re)load. Cancel (and re-opening Edit) reverts the whole class of Overview
+ // drafts to THIS — the last SAVED state — so a discarded edit (e.g. a Display
+ // name typed then cancelled) can never leak into a later saveHost PUT.
+ const savedOverviewRef = useRef({
+ hostName: routeName,
+ hostDisplay: '',
+ contextRef: '',
+ channels: [] as string[],
+ stateless: false,
+ })
const [providerDraft, setProviderDraft] = useState<LlmProvider>('openai')
// Model options are the operator allowlist (enabled only). The host's saved
// model is always kept selectable even if it fell out of the allowlist
@@ -216,13 +227,20 @@ export default function HostDetailsPage() {
// built from it, so it is the correct precondition for the eventual save.
formResourceVersionRef.current = String(host.metadata?.resourceVersion || '')
if (resetDrafts === 'all' || resetDrafts === 'overview') {
- setHostNameDraft(String(host.metadata?.name || routeName))
- setHostDisplayDraft(String(spec.host || host.metadata?.name || routeName))
- setContextRefDraft(String(spec.contextRef || ''))
- setChannelsDraft(
- Array.isArray(spec.channels) ? spec.channels.map(String).filter(Boolean) : []
- )
- setStatelessDraft(spec.lifecycle?.stateless === true)
+ // Snapshot the saved Overview state so Cancel/Edit can revert to it.
+ const overview = {
+ hostName: String(host.metadata?.name || routeName),
+ hostDisplay: String(spec.host || host.metadata?.name || routeName),
+ contextRef: String(spec.contextRef || ''),
+ channels: Array.isArray(spec.channels) ? spec.channels.map(String).filter(Boolean) : [],
+ stateless: spec.lifecycle?.stateless === true,
+ }
+ savedOverviewRef.current = overview
+ setHostNameDraft(overview.hostName)
+ setHostDisplayDraft(overview.hostDisplay)
+ setContextRefDraft(overview.contextRef)
+ setChannelsDraft(overview.channels)
+ setStatelessDraft(overview.stateless)
}
const nextProvider = normalizeProvider(
String((spec.model as { provider?: string } | undefined)?.provider || 'openai')
@@ -321,6 +339,23 @@ export default function HostDetailsPage() {
setLlmPolicyDraft(next)
}
+ // Revert every Overview-owned draft to the last SAVED snapshot. Used by Cancel
+ // and by Edit-open so an edit session always starts from server-backed values
+ // — never a stale draft left behind by a prior discarded edit (any Overview
+ // field, not just Display name: the whole class shares this reset).
+ function resetOverviewDrafts() {
+ const saved = savedOverviewRef.current
+ setHostNameDraft(saved.hostName)
+ setHostDisplayDraft(saved.hostDisplay)
+ // contextRef is written by the Overview save (saveHost), so reset it here to
+ // block a stale leak — EXCEPT while the Context tab has a live edit open: it
+ // is a legitimate concurrent writer of contextRefDraft (its editingContext
+ // session), and reverting an in-progress selection would silently discard it.
+ if (!editingContext) setContextRefDraft(saved.contextRef)
+ setChannelsDraft(saved.channels)
+ setStatelessDraft(saved.stateless)
+ }
+
async function saveHost(): Promise<boolean> {
const nextHostName = hostNameDraft.trim()
if (!nextHostName) return false
@@ -634,7 +669,13 @@ export default function HostDetailsPage() {
<button
type="button"
className="cu-btn cu-btn--ghost cu-btn--sm"
- onClick={() => setEditingOverview(false)}
+ onClick={() => {
+ // Discard any unsaved Overview edits before leaving edit
+ // mode, so the read-only view and the next save reflect
+ // the last SAVED state — not the abandoned draft.
+ resetOverviewDrafts()
+ setEditingOverview(false)
+ }}
disabled={busy}
>
Cancel
@@ -658,7 +699,16 @@ export default function HostDetailsPage() {
<button
type="button"
className="cu-btn cu-btn--ghost cu-btn--sm"
- onClick={() => setEditingOverview(true)}
+ onClick={() => {
+ // Defensive: start every edit session from the last SAVED
+ // snapshot, so a stale draft never leaks into this Overview
+ // save. resetOverviewDrafts deliberately leaves contextRef
+ // untouched while the Context tab is mid-edit — that tab is a
+ // legitimate live writer of contextRefDraft, not a stale
+ // leftover, so its in-progress selection must be preserved.
+ resetOverviewDrafts()
+ setEditingOverview(true)
+ }}
disabled={busy}
>
Edit
diff --git a/control-ui/components/HostAccessTab/index.tsx b/control-ui/components/HostAccessTab/index.tsx
index 8e4a1e9e0..710a76626 100644
--- a/control-ui/components/HostAccessTab/index.tsx
+++ b/control-ui/components/HostAccessTab/index.tsx
@@ -489,7 +489,6 @@ function AccessGrantModal({
titleId,
value,
}: AccessGrantModalProps) {
- const blocked = busy
return (
<div
style={{
@@ -504,7 +503,7 @@ function AccessGrantModal({
}}
role="presentation"
onClick={e => {
- if (e.target === e.currentTarget && !blocked) onClose()
+ if (e.target === e.currentTarget && !busy) onClose()
}}
>
<div
@@ -521,7 +520,7 @@ function AccessGrantModal({
type="button"
className="cu-btn cu-btn--icon cu-btn--ghost"
onClick={onClose}
- disabled={blocked}
+ disabled={busy}
aria-label="Close"
>
<IconX width={18} height={18} />
@@ -534,7 +533,7 @@ function AccessGrantModal({
emptyLabel={emptyLabel}
id={id}
inline
- disabled={blocked}
+ disabled={busy}
onChange={onChange}
options={options}
placeholder={placeholder}
@@ -549,7 +548,7 @@ function AccessGrantModal({
type="button"
className="cu-btn cu-btn--ghost cu-btn--sm"
onClick={onClose}
- disabled={blocked}
+ disabled={busy}
>
Cancel
</button>
@@ -557,7 +556,7 @@ function AccessGrantModal({
type="button"
className="cu-btn cu-btn--primary"
onClick={() => void onConfirm()}
- disabled={blocked || value.length === 0}
+ disabled={busy || value.length === 0}
>
{submitLabel}
</button>
diff --git a/control-ui/components/__tests__/HostDetailsPage.identity.test.tsx b/control-ui/components/__tests__/HostDetailsPage.identity.test.tsx
index 360729758..f112c249c 100644
--- a/control-ui/components/__tests__/HostDetailsPage.identity.test.tsx
+++ b/control-ui/components/__tests__/HostDetailsPage.identity.test.tsx
@@ -229,4 +229,94 @@ describe('HostDetailsPage identity integration', () => {
expect(replaceMock).not.toHaveBeenCalledWith('/agents/Product Agents')
expect(pushMock).not.toHaveBeenCalledWith('/agents/Product Agents')
})
+
+ // Regression: Cancel must DISCARD the Display-name edit, not carry the stale
+ // draft into the read-only view and the next save. Before the resetOverview
+ // fix, a cancelled "Display name" edit silently persisted on the following
+ // Save (spec.host written to the abandoned value).
+ it('discards a cancelled Display name edit — read-only reverts and a later save keeps the saved value', async () => {
+ render(<HostDetailsPage />)
+
+ const [overviewEditButton] = await screen.findAllByRole('button', { name: 'Edit' })
+ await waitFor(() => expect(overviewEditButton).toBeEnabled())
+ fireEvent.click(overviewEditButton)
+
+ // Type a Display name the operator then abandons.
+ fireEvent.change(screen.getByLabelText('Display name'), {
+ target: { value: 'Discarded Draft' },
+ })
+ fireEvent.click(screen.getByRole('button', { name: 'Cancel' }))
+
+ // Observable #1 (T4): the read-only view shows the last-SAVED value, not the
+ // abandoned draft.
+ expect(screen.getByText('foo-display')).toBeInTheDocument()
+ expect(screen.queryByText('Discarded Draft')).not.toBeInTheDocument()
+
+ // Re-open Edit and Save without touching Display name again.
+ const [overviewEditButton2] = await screen.findAllByRole('button', { name: 'Edit' })
+ fireEvent.click(overviewEditButton2)
+ fireEvent.click(screen.getByRole('button', { name: 'Save' }))
+
+ await waitFor(() =>
+ expect(api.apiSend).toHaveBeenCalledWith('PUT', '/api/v1/admin/hosts/foo', expect.any(Object))
+ )
+
+ // Observable #2 (T4, PINNING): the persisted spec.host is the saved value,
+ // NOT the discarded draft. This assertion goes red pre-fix.
+ const putCall = (api.apiSend as unknown as ReturnType<typeof vi.fn>).mock.calls.find(
+ c => c[0] === 'PUT' && c[1] === '/api/v1/admin/hosts/foo'
+ )
+ expect(putCall![2].spec.host).toBe('foo-display')
+ })
+
+ // Collateral regression: resetOverviewDrafts must NOT clobber a LIVE Context-tab
+ // edit. contextRefDraft is written by both saveHost (Overview) and the Context
+ // tab's own editingContext session; reverting it on Overview Edit-open/Cancel
+ // while that session is open silently discards the operator's in-progress pick.
+ it('preserves a live Context-tab selection across an Overview Edit-open/Cancel', async () => {
+ // Two contexts so the Context tab can switch selection; saved = ctx-a.
+ ;(api.getHostDetailBundle as unknown as ReturnType<typeof vi.fn>).mockResolvedValue({
+ host: { ...host, spec: { ...host.spec, contextRef: 'ctx-a' } },
+ contexts: [
+ { metadata: { name: 'ctx-a' }, spec: { contextId: 'ctx-a' } },
+ { metadata: { name: 'ctx-b' }, spec: { contextId: 'ctx-b' } },
+ ],
+ secrets: [{ name: 'openai-secret' }],
+ users: [],
+ teams: [],
+ agentUsers: [],
+ agentTeams: [],
+ })
+
+ // Land on the Context tab, open its edit session, pick a DIFFERENT context.
+ mockParams = { name: 'foo', tab: 'contexts' }
+ const view = render(<HostDetailsPage />)
+ fireEvent.click(await screen.findByRole('button', { name: 'Edit context' }))
+ fireEvent.change(screen.getByRole('combobox'), { target: { value: 'ctx-b' } })
+ expect((screen.getByRole('combobox') as HTMLSelectElement).value).toBe('ctx-b')
+
+ // Switch to Overview and fire BOTH resetOverviewDrafts sites: Edit-open, Cancel.
+ mockParams = { name: 'foo' }
+ view.rerender(
+ <ToastProvider>
+ <HostDetailsPage />
+ </ToastProvider>
+ )
+ const [overviewEditButton] = await screen.findAllByRole('button', { name: 'Edit' })
+ await waitFor(() => expect(overviewEditButton).toBeEnabled())
+ fireEvent.click(overviewEditButton)
+ fireEvent.click(screen.getByRole('button', { name: 'Cancel' }))
+
+ // Back on the Context tab (still editing): the in-progress ctx-b must survive.
+ mockParams = { name: 'foo', tab: 'contexts' }
+ view.rerender(
+ <ToastProvider>
+ <HostDetailsPage />
+ </ToastProvider>
+ )
+
+ // PINNING (T4): the Context select still shows the unsaved ctx-b, not the
+ // reverted saved ctx-a. Pre-collateral-fix this reads 'ctx-a'.
+ expect((screen.getByRole('combobox') as HTMLSelectElement).value).toBe('ctx-b')
+ })
})
diff --git a/control-ui/package-lock.json b/control-ui/package-lock.json
index 3a0499606..eded39141 100644
--- a/control-ui/package-lock.json
+++ b/control-ui/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-ui",
- "version": "0.1.423",
+ "version": "0.1.424",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-ui",
- "version": "0.1.423",
+ "version": "0.1.424",
"dependencies": {
"@clerum/display-field": "file:../packages/display-field",
"@clerum/llm-providers": "file:../packages/llm-providers",
diff --git a/control-ui/package.json b/control-ui/package.json
index ce4545600..7d15b008c 100644
--- a/control-ui/package.json
+++ b/control-ui/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-ui",
- "version": "0.1.423",
+ "version": "0.1.424",
"private": true,
"scripts": {
"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",