Skip to content

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

TypeScript

fix(control-ui): stop the set-mode latch from sticking after a recreate

Jose Ramirez20d34cf23d1b
diff --git a/control-ui/components/UpdateConnectorCredentials/index.tsx b/control-ui/components/UpdateConnectorCredentials/index.tsx
index ac7dfddac..a49721e65 100644
--- a/control-ui/components/UpdateConnectorCredentials/index.tsx
+++ b/control-ui/components/UpdateConnectorCredentials/index.tsx
@@ -224,10 +224,14 @@ export function UpdateConnectorCredentials({
// No verdict either way inside the budget — an inconclusive
// timeout, distinct from a diagnosed failure.
setPhase('timeout')
+ // Diagnostic only. The "what to try next" sentence is mode-specific
+ // (nothing was rotated in set mode) and is appended by the timeout
+ // banner, which reads `submittedMode` at render time — keeping this
+ // effect free of a dependency that would restart the poll.
setPhaseMessage(
`The rollout did not finish within ${Math.round(POLL_TIMEOUT_MS / 1000)}s. Run ` +
`"kubectl get mcpserver ${serverName} -o yaml" to see the current DeploymentReady ` +
- 'condition, or try the rotation again.'
+ 'condition.'
)
}
}
@@ -242,8 +246,16 @@ export function UpdateConnectorCredentials({
}
}, [phase, rotationCutoff, serverName])
+ // `secretCreated` gates BOTH set-mode sources, not just the `surface` prop.
+ // It latches the moment a create succeeds, and the Secret it created exists
+ // from then on — whether the form got here from a stale `surface` prop or
+ // from a rotate PUT that 404'd (`recreateRequired`). Leaving `recreateRequired`
+ // outside the guard made it a one-way latch: nothing resets it (resetToIdle
+ // does not), so after a successful recreate the form kept "set" copy, forced
+ // every key, and offered a confirm dialog promising to create a Secret that
+ // now exists.
const mode: 'set' | 'rotate' =
- recreateRequired || (surface === 'set' && !secretCreated) ? 'set' : 'rotate'
+ !secretCreated && (recreateRequired || surface === 'set') ? 'set' : 'rotate'
if (!envSecret) {
return (
@@ -366,6 +378,13 @@ export function UpdateConnectorCredentials({
// (HCC would answer SecretMissingKey). Demand every key instead.
if ((putError as { status?: number })?.status === 404) {
setRecreateRequired(true)
+ // A 404 is proof the Secret does NOT exist right now, so the
+ // "a create already landed" latch has to be cleared with it — it is
+ // what gates set mode. Without this, a Secret deleted a SECOND time
+ // in the same session (after a successful recreate) would leave the
+ // form on the rotate button while the error below demands every key,
+ // and every retry would just 404 again.
+ setSecretCreated(false)
setPhase('idle')
setValidationError('This Secret no longer exists. Enter every key to recreate it.')
return
@@ -379,7 +398,14 @@ export function UpdateConnectorCredentials({
} catch (e) {
setPhase('failed')
setPhaseMessage(e instanceof Error ? e.message : 'Failed to save credentials')
- showToast('Failed to save credentials.', { tone: 'error' })
+ // `mode` — not the `submittedMode` state — is what this submit IS: the
+ // setSubmittedMode(mode) above does not update this closure's copy, so
+ // reading the state here would report the PREVIOUS submit's mode. Keeps
+ // the toast in step with the failure banner ("Rotation failed:" /
+ // "Could not set credentials:").
+ showToast(mode === 'set' ? 'Failed to set credentials.' : 'Failed to rotate credentials.', {
+ tone: 'error',
+ })
}
}
@@ -498,7 +524,10 @@ export function UpdateConnectorCredentials({
{phase === 'timeout' ? (
<div className="cu-banner cu-banner--warning" role="alert">
- {phaseMessage}
+ {phaseMessage}{' '}
+ {submittedMode === 'set'
+ ? 'You can also try setting the credentials again.'
+ : 'You can also try the rotation again.'}
</div>
) : null}
diff --git a/control-ui/components/UpdateConnectorCredentials/types.ts b/control-ui/components/UpdateConnectorCredentials/types.ts
index a10ab7e49..34d0ebb74 100644
--- a/control-ui/components/UpdateConnectorCredentials/types.ts
+++ b/control-ui/components/UpdateConnectorCredentials/types.ts
@@ -24,13 +24,19 @@ export type UpdateConnectorCredentialsProps = {
}
/**
+ * The phases are shared by BOTH write directions, so "the write" below means
+ * the PUT to /admin/mcp-secrets/:name in rotate mode and the POST to
+ * /admin/mcp-secrets in set mode (including its merge-patch retry). Which one
+ * a given phase refers to is recorded separately, in `submittedMode`.
+ *
* - idle: form is editable, nothing in flight.
- * - saving: the PUT to /admin/mcp-secrets/:name is in flight.
- * - rotating: the PUT returned 200; polling getMcpServer() for a fresh
- * DeploymentReady condition.
- * - success: a fresh DeploymentReady=True was observed after the PUT.
- * - failed: the PUT itself failed, OR a fresh DeploymentReady=False was
- * observed after the PUT.
+ * - saving: the write is in flight.
+ * - rotating: the write returned 2xx; polling getMcpServer() for a fresh
+ * DeploymentReady condition (the connector restarting after a
+ * rotation, or starting for the first time after a create).
+ * - success: a fresh DeploymentReady=True was observed after the write.
+ * - failed: the write itself failed, OR a fresh DeploymentReady=False was
+ * observed after it.
* - timeout: the bounded poll window elapsed without a fresh terminal
* condition. Never reported as success.
*/
diff --git a/control-ui/components/__tests__/UpdateConnectorCredentials.test.tsx b/control-ui/components/__tests__/UpdateConnectorCredentials.test.tsx
index e479d5aa0..2f2c3c24d 100644
--- a/control-ui/components/__tests__/UpdateConnectorCredentials.test.tsx
+++ b/control-ui/components/__tests__/UpdateConnectorCredentials.test.tsx
@@ -247,11 +247,44 @@ describe('UpdateConnectorCredentials — PUT rejection', () => {
expect(screen.getByText(/Rotation failed/i)).toBeInTheDocument()
expect(screen.getByText(/not a valid Secret key/i)).toBeInTheDocument()
expect(screen.queryByText(/Credentials rotated/i)).not.toBeInTheDocument()
+ // The toast must keep the rotate wording that matches the banner. A single
+ // mode-blind string ("Failed to save credentials.") reads as a regression on
+ // the default path, where the banner right next to it says "Rotation failed".
+ expect(screen.getByText('Failed to rotate credentials.')).toBeInTheDocument()
// The PUT was actually attempted (not blocked client-side), and the failure
// short-circuits before any DeploymentReady poll.
expect(mockUpdateMcpSecret).toHaveBeenCalledTimes(1)
expect(mockGetMcpServer).not.toHaveBeenCalled()
})
+
+ // The 404 branch is the ONLY status the rotate path may treat as "the Secret
+ // vanished". Widening it (e.g. `>= 400`) would swallow this real 409 —
+ // control-api/src/routes/admin/secrets.ts returns it for a WorkflowRecipe-owned
+ // Secret — into a silent mode flip that tells the operator to re-enter every
+ // key, hiding the message that actually points them at /admin/recipe-secrets.
+ // Every other rotate-rejection mock in this file carries NO `.status`, so
+ // `undefined >= 400` is false and none of them can catch that widening.
+ it('rethrows a status-carrying non-404 PUT rejection (409 recipe-owned) instead of flipping to set mode', async () => {
+ mockUpdateMcpSecret.mockRejectedValue(
+ Object.assign(
+ new Error(
+ '409 - Secret "linear-credentials" is owned by a WorkflowRecipe; rotate it through /admin/recipe-secrets'
+ ),
+ { status: 409 }
+ )
+ )
+ await renderPanel(ENV_SECRET, 'rotate')
+ await submitRotation({ 'api-key': 'new-key-value' })
+
+ // The operator sees the backend's own message, verbatim.
+ expect(screen.getByText(/Rotation failed:.*owned by a WorkflowRecipe/)).toBeInTheDocument()
+ expect(screen.getByText(/\/admin\/recipe-secrets/)).toBeInTheDocument()
+ // ...and NOT the vanished-Secret recovery, which would demand every key.
+ expect(screen.queryByText(/This Secret no longer exists\./)).not.toBeInTheDocument()
+ expect(screen.queryByRole('button', { name: 'Set credentials' })).not.toBeInTheDocument()
+ expect(screen.getByRole('button', { name: 'Rotate again' })).toBeInTheDocument()
+ expect(mockCreateMcpSecret).not.toHaveBeenCalled()
+ })
})
describe('UpdateConnectorCredentials — rotate mode against a vanished Secret', () => {
@@ -272,6 +305,96 @@ describe('UpdateConnectorCredentials — rotate mode against a vanished Secret',
// The form is now in set mode, demanding every key.
expect(screen.getByRole('button', { name: 'Set credentials' })).toBeInTheDocument()
})
+
+ // The recovery is a ROUND TRIP, and only its return leg proves the set-mode
+ // latch is not one-way. `recreateRequired` is never reset (resetToIdle does
+ // not touch it), so it must sit BEHIND the `secretCreated` guard: once the
+ // recreate lands, the Secret exists and every set-mode surface is a lie —
+ // "needs credentials before it can start", `Required` placeholders, all keys
+ // forced on the next submit, and a confirm dialog offering to create a Secret
+ // that is already there.
+ it('returns to rotate semantics once the recreate succeeds', async () => {
+ mockUpdateMcpSecret.mockRejectedValue(
+ Object.assign(new Error('404 - Secret "linear-credentials" not found in mcp-server'), {
+ status: 404,
+ })
+ )
+ mockCreateMcpSecret.mockResolvedValue({ name: ENV_SECRET.name, namespace: 'mcp-server' })
+ mockGetMcpServer.mockResolvedValue(
+ serverWithCondition({
+ status: 'True',
+ message: 'Running',
+ lastTransitionTime: '2026-01-01T00:00:30.000Z',
+ })
+ )
+ await renderPanel(ENV_SECRET, 'rotate')
+
+ // Leg 1: rotate against a Secret that vanished — the form latches to set.
+ await submitRotation({ 'api-key': 'only-one' })
+ expect(screen.getByRole('button', { name: 'Set credentials' })).toBeInTheDocument()
+
+ // Leg 2: recreate it with every key, and let the connector come up.
+ await submitSet(ALL_KEYS)
+ await act(async () => {
+ vi.advanceTimersByTime(POLL_INTERVAL_MS)
+ })
+ await flush()
+ expect(screen.getByText(/Credentials set\./)).toBeInTheDocument()
+
+ // Leg 3: back to an editable form. The Secret EXISTS now, so every surface
+ // must have returned to rotate semantics.
+ fireEvent.click(screen.getByRole('button', { name: 'Done' }))
+
+ expect(screen.getByRole('button', { name: 'Rotate credentials' })).toBeInTheDocument()
+ expect(screen.queryByRole('button', { name: 'Set credentials' })).not.toBeInTheDocument()
+ expect(screen.queryByText(/needs credentials before it can start/i)).not.toBeInTheDocument()
+ expect(screen.getByText(/Rotate values stored in Secret/i)).toBeInTheDocument()
+ // The per-field tell: `Required` is what forces every key on the next submit.
+ expect(screen.getByLabelText('api-key')).toHaveAttribute(
+ 'placeholder',
+ 'Leave blank to keep current value'
+ )
+ })
+
+ // The other direction of the same latch. `secretCreated` means "a create
+ // already landed", and it is what GATES set mode — so a later 404, which is
+ // proof the Secret is gone again, has to clear it. Otherwise the second
+ // vanish would leave the rotate button on screen while the error text demands
+ // every key, and each retry would 404 forever.
+ it('flips back to set mode when the Secret vanishes a SECOND time in the same session', async () => {
+ mockUpdateMcpSecret.mockRejectedValue(
+ Object.assign(new Error('404 - Secret "linear-credentials" not found in mcp-server'), {
+ status: 404,
+ })
+ )
+ mockCreateMcpSecret.mockResolvedValue({ name: ENV_SECRET.name, namespace: 'mcp-server' })
+ mockGetMcpServer.mockResolvedValue(
+ serverWithCondition({
+ status: 'True',
+ message: 'Running',
+ lastTransitionTime: '2026-01-01T00:00:30.000Z',
+ })
+ )
+ await renderPanel(ENV_SECRET, 'rotate')
+
+ // First vanish, recreate, and return to the rotate form.
+ await submitRotation({ 'api-key': 'only-one' })
+ await submitSet(ALL_KEYS)
+ await act(async () => {
+ vi.advanceTimersByTime(POLL_INTERVAL_MS)
+ })
+ await flush()
+ fireEvent.click(screen.getByRole('button', { name: 'Done' }))
+ expect(screen.getByRole('button', { name: 'Rotate credentials' })).toBeInTheDocument()
+
+ // Deleted again out-of-band: the rotate PUT 404s a second time.
+ await submitRotation({ 'api-key': 'only-one-again' })
+
+ expect(screen.getByText(/This Secret no longer exists\./)).toBeInTheDocument()
+ expect(screen.getByRole('button', { name: 'Set credentials' })).toBeInTheDocument()
+ // Still no partial create.
+ expect(mockCreateMcpSecret).toHaveBeenCalledTimes(1)
+ })
})
// ─── Polling / DeploymentReady correlation — the CRD contract (Fase 3 §6) ───
@@ -747,14 +870,43 @@ describe('UpdateConnectorCredentials — set mode submit', () => {
expect(screen.getByText(new RegExp(`${SERVER_NAME} started`))).toBeInTheDocument()
})
- it('shows a set-mode failure banner, not "Rotation failed", when both the create and the retry fail', async () => {
+ it('shows a set-mode failure banner and toast when both the create and the retry fail', async () => {
mockCreateMcpSecret.mockRejectedValue(serverError())
mockUpdateMcpSecret.mockRejectedValue(serverError())
await renderPanel(ENV_SECRET, 'set')
await submitSet(ALL_KEYS)
expect(screen.getByText(/Could not set credentials:/)).toBeInTheDocument()
- expect(screen.queryByText(/Rotation failed/i)).not.toBeInTheDocument()
+ // The toast is the only failure surface that could plausibly carry rotate
+ // wording here — the banner branch above can never render it in set mode, so
+ // asserting THAT absence would pass vacuously.
+ expect(screen.getByText('Failed to set credentials.')).toBeInTheDocument()
+ expect(screen.queryByText('Failed to rotate credentials.')).not.toBeInTheDocument()
expect(screen.getByRole('button', { name: 'Try again' })).toBeInTheDocument()
})
+
+ it('offers to try setting the credentials again — never "the rotation" — when the poll times out', async () => {
+ // The timeout banner used to be the one retrospective surface with no mode
+ // branch, so a create that never converged told the operator to "try the
+ // rotation again" about a rotation that never happened.
+ mockCreateMcpSecret.mockResolvedValue({ name: ENV_SECRET.name, namespace: 'mcp-server' })
+ // Always stale: the condition predates the POST on every poll.
+ mockGetMcpServer.mockResolvedValue(
+ serverWithCondition({
+ status: 'False',
+ message: 'rolling out',
+ lastTransitionTime: '2020-01-01T00:00:00.000Z',
+ })
+ )
+ await renderPanel(ENV_SECRET, 'set')
+ await submitSet(ALL_KEYS)
+
+ await act(async () => {
+ await vi.advanceTimersByTimeAsync(POLL_TIMEOUT_MS + POLL_INTERVAL_MS)
+ })
+
+ const banner = screen.getByText(/did not finish within/i)
+ expect(banner).toHaveTextContent('You can also try setting the credentials again.')
+ expect(banner.textContent).not.toMatch(/rotation/i)
+ })
})
diff --git a/control-ui/components/__tests__/resolveCredentialSurface.test.ts b/control-ui/components/__tests__/resolveCredentialSurface.test.ts
index bc88c4e9d..f8b974354 100644
--- a/control-ui/components/__tests__/resolveCredentialSurface.test.ts
+++ b/control-ui/components/__tests__/resolveCredentialSurface.test.ts
@@ -28,6 +28,28 @@ describe('resolveCredentialSurface', () => {
).toBe('rotate')
})
+ // Pins the `type` clause on its own. Every other fixture is a SecretResolved
+ // condition, so deleting `c.type === 'SecretResolved'` from the predicate left
+ // the whole suite green: a DeploymentReady=False/SecretNotFound (or any other
+ // condition type reusing that reason) would then be read as a missing Secret
+ // and send the operator to the create form.
+ it('returns "rotate" when SecretNotFound is carried by a different condition type', () => {
+ expect(
+ resolveCredentialSurface([condition({ type: 'Ready', reason: 'SecretNotFound' })], {
+ managed: true,
+ })
+ ).toBe('rotate')
+ })
+
+ // Pins the `status` clause on its own. The clean-resolution fixture below
+ // changes `status` AND `reason` together, so the `reason` clause alone kept it
+ // green; this one varies ONLY the status.
+ it('returns "rotate" when SecretResolved holds SecretNotFound at status Unknown', () => {
+ expect(resolveCredentialSurface([condition({ status: 'Unknown' })], { managed: true })).toBe(
+ 'rotate'
+ )
+ })
+
it('returns "rotate" when the Secret resolves cleanly', () => {
expect(
resolveCredentialSurface([condition({ status: 'True', reason: 'SecretResolved' })], {})
diff --git a/control-ui/package-lock.json b/control-ui/package-lock.json
index cd5ee1f4e..5766a89e7 100644
--- a/control-ui/package-lock.json
+++ b/control-ui/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-ui",
- "version": "0.1.393",
+ "version": "0.1.395",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-ui",
- "version": "0.1.393",
+ "version": "0.1.395",
"dependencies": {
"@clerum/llm-providers": "file:../packages/llm-providers",
"@clerum/workflow-recipe-capability-policy": "file:../packages/workflow-recipe-capability-policy",
diff --git a/control-ui/package.json b/control-ui/package.json
index b74371d59..7fbd77fb8 100644
--- a/control-ui/package.json
+++ b/control-ui/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-ui",
- "version": "0.1.393",
+ "version": "0.1.395",
"private": true,
"scripts": {
"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",