Skip to content

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

TypeScript

fix(control-ui): avoid resending saved credentials

Josué721cb640014d
diff --git a/control-ui/app/communication-channels/[name]/edit/page.tsx b/control-ui/app/communication-channels/[name]/edit/page.tsx
index 0fb35afe1..585e9ca72 100644
--- a/control-ui/app/communication-channels/[name]/edit/page.tsx
+++ b/control-ui/app/communication-channels/[name]/edit/page.tsx
@@ -143,6 +143,7 @@ export default function EditCommunicationChannelPage() {
const [loadError, setLoadError] = useState('')
const [saving, setSaving] = useState(false)
const [saveError, setSaveError] = useState('')
+ const [saveRefreshPending, setSaveRefreshPending] = useState(false)
function backToChannels() {
router.push(CONTROL_ROUTES.externalChannels.root)
@@ -208,6 +209,7 @@ export default function EditCommunicationChannelPage() {
setDraft(nextDraft)
setSavedDraft(nextDraft)
setCredentialEditStates({})
+ setSaveRefreshPending(false)
setActiveTab(communicationChannelInitialTab(nextItem))
setHosts(nextHosts)
} catch (error) {
@@ -249,7 +251,7 @@ export default function EditCommunicationChannelPage() {
[draft, savedDraft]
)
const credentialsDirty = Object.values(credentialEditStates).some(credentialStateIsDirty)
- const formDirty = specDirty || credentialsDirty
+ const formDirty = specDirty || credentialsDirty || saveRefreshPending
const activeConversations = draft ? conversationsForProvider(activeTab, draft) : []
// Gated on the DRAFT, not the persisted item. Slack's own order is manifest
// first, credentials second: the bot token only exists after the app has been
@@ -370,15 +372,19 @@ export default function EditCommunicationChannelPage() {
)
return
}
- if (!specDirty && plan.operations.length === 0) return
+ if (!specDirty && plan.operations.length === 0 && !saveRefreshPending) return
setSaving(true)
setSaveError('')
+ let mutationCommitted = saveRefreshPending
try {
if (specDirty) {
await apiSend('PUT', `/api/v1/admin/communication-channels/${encodeURIComponent(name)}`, {
spec,
})
+ mutationCommitted = true
+ setSavedDraft(draft)
+ setSaveRefreshPending(true)
}
const channelResponse = await apiGet(
@@ -424,21 +430,30 @@ export default function EditCommunicationChannelPage() {
)
}
successful.push(operation.key)
+ mutationCommitted = true
} catch {
failedLabels.push(operation.label)
}
}
- const [refreshedChannel] = await Promise.all([
+ if (successful.length) {
+ setCredentialEditStates(current => cleanCredentialStates(current, successful))
+ setSaveRefreshPending(true)
+ }
+
+ const [refreshedChannel, refreshedKeys] = await Promise.all([
apiGet(`/api/v1/admin/communication-channels/${encodeURIComponent(name)}`),
loadCredentialKeys(name),
])
+ if (!refreshedKeys) {
+ throw new Error('Could not refresh authoritative credential presence after saving.')
+ }
const refreshedItem = extractChannel(refreshedChannel, name) ?? authoritativeItem
const refreshedDraft = createCommunicationChannelDraft(refreshedItem)
setItem(refreshedItem)
setDraft(refreshedDraft)
setSavedDraft(refreshedDraft)
- setCredentialEditStates(current => cleanCredentialStates(current, successful))
+ setSaveRefreshPending(false)
if (failedLabels.length) {
setSaveError(
@@ -450,7 +465,16 @@ export default function EditCommunicationChannelPage() {
showToast(`Communication channel ${name} updated.`, { tone: 'success' })
backToChannels()
} catch (error) {
- setSaveError(error instanceof Error ? error.message : 'Failed to save communication channel')
+ if (mutationCommitted) {
+ setSaveRefreshPending(true)
+ setSaveError(
+ 'Channel settings were saved, but the authoritative refresh failed. Retry Save to refresh without resending successful credential changes.'
+ )
+ } else {
+ setSaveError(
+ error instanceof Error ? error.message : 'Failed to save communication channel'
+ )
+ }
} finally {
setSaving(false)
}
diff --git a/control-ui/components/__tests__/EditCommunicationChannelPage.test.tsx b/control-ui/components/__tests__/EditCommunicationChannelPage.test.tsx
index 1f6f7383c..8d05993e0 100644
--- a/control-ui/components/__tests__/EditCommunicationChannelPage.test.tsx
+++ b/control-ui/components/__tests__/EditCommunicationChannelPage.test.tsx
@@ -323,6 +323,54 @@ describe('EditCommunicationChannelPage channel credentials', () => {
expect(telegramToken.placeholder).toBe('Stored value unknown')
expect(telegramToken).toBeEnabled()
})
+
+ it('retries an authoritative refresh without resending a successful credential change', async () => {
+ navigation.params = { name: TELEGRAM_ONLY_CHANNEL }
+ let channelReads = 0
+ vi.mocked(api.apiGet).mockImplementation(async path => {
+ if (path === '/api/v1/admin/hosts') {
+ return { items: [{ metadata: { name: 'agent-a' } }] }
+ }
+ if (path === `/api/v1/admin/communication-channels/${TELEGRAM_ONLY_CHANNEL}/credentials`) {
+ return { keys: ['telegram-bot-token'] }
+ }
+ if (path === `/api/v1/admin/communication-channels/${TELEGRAM_ONLY_CHANNEL}`) {
+ channelReads += 1
+ if (channelReads === 3) throw new Error('refresh unavailable')
+ return {
+ item: {
+ metadata: { name: TELEGRAM_ONLY_CHANNEL, namespace: 'channels' },
+ spec: {
+ access: { users: [], teams: [] },
+ hostRef: 'agent-a',
+ ...TELEGRAM_ONLY_SPEC,
+ },
+ },
+ }
+ }
+ return { items: [] }
+ })
+ await renderLoadedPage()
+
+ fireEvent.change(screen.getByLabelText('Telegram Bot Token'), {
+ target: { value: 'replacement-token' },
+ })
+ fireEvent.click(screen.getByRole('button', { name: 'Save changes' }))
+
+ await waitFor(() =>
+ expect(screen.getByRole('alert')).toHaveTextContent('authoritative refresh failed')
+ )
+ expect(api.apiSend).toHaveBeenCalledTimes(1)
+ expect(api.apiSend).toHaveBeenCalledWith(
+ 'PUT',
+ `/api/v1/admin/communication-channels/${TELEGRAM_ONLY_CHANNEL}/credentials`,
+ { 'telegram-bot-token': 'replacement-token' }
+ )
+
+ fireEvent.click(screen.getByRole('button', { name: 'Save changes' }))
+ await waitFor(() => expect(navigation.push).toHaveBeenCalledWith('/external-channels'))
+ expect(api.apiSend).toHaveBeenCalledTimes(1)
+ })
})
/** Both strings are written out rather than imported: this copy IS the feature,
diff --git a/control-ui/package-lock.json b/control-ui/package-lock.json
index 61e0d702d..a17f30e52 100644
--- a/control-ui/package-lock.json
+++ b/control-ui/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-ui",
- "version": "0.1.619",
+ "version": "0.1.620",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-ui",
- "version": "0.1.619",
+ "version": "0.1.620",
"dependencies": {
"@clerum/display-field": "file:../packages/display-field",
"@clerum/frontend-components": "file:../packages/frontend-components",
diff --git a/control-ui/package.json b/control-ui/package.json
index ddc02d6f4..c4f2888bc 100644
--- a/control-ui/package.json
+++ b/control-ui/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-ui",
- "version": "0.1.619",
+ "version": "0.1.620",
"private": true,
"scripts": {
"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",