Skip to content

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

TypeScript

Merge remote-tracking branch 'origin/dev' into pr252-consolidated

Alfredo Lopez4a599afd9da2
diff --cc control-api/src/db.ts
index ce5db6654,08b9a5abb..bdcdb8227
--- a/control-api/src/db.ts
+++ b/control-api/src/db.ts
@@@ -6045,18 -6083,84 +6113,101 @@@ export const CONTROL_API_MIGRATIONS: Db
apply: applyLlmProviderAttemptSdkLinkOnDeleteSetNullSchema,
},
{
- version: '0109_mcp_secret_rollback_permits',
- // Renamed while syncing onto dev: 0101 -> 0109. This branch introduced the
- // migration as 0101, and the sync brought dev's 0101–0108 (codex multi-
- // connection through the SDK-link FK), so 0101 is now taken by
- // 0101_codex_multi_connection. Environments where this feature branch was
- // already deployed recorded it under the earlier name. legacyVersions lets
- // the runner mark 0109 applied from that prior row instead of re-running
- // the DDL and leaving an orphan schema_migrations entry. The prior name is
- // unique to this migration, so there is no false-skip.
- legacyVersions: ['0101_mcp_secret_rollback_permits'],
+ version: '0109_grok_subscription_connections',
+ apply: applyGrokSubscriptionConnectionSchema,
+ },
+ {
+ version: '0110_grok_subscription_oauth_states',
+ apply: applyGrokSubscriptionOAuthStateSchema,
+ },
+ {
+ version: '0111_grok_catalog_models',
+ apply: applyGrokCatalogModelsSchema,
+ },
+ {
+ version: '0112_llm_provider_attempts_grok_broker',
+ apply: applyLlmProviderAttemptsGrokBrokerSchema,
+ },
+ {
+ version: '0113_grok_subscription_terminal_connection_key',
+ apply: applyGrokSubscriptionTerminalConnectionKeySchema,
+ },
+ {
+ version: '0114_llm_provider_attempts_connection_integrity',
+ apply: applyLlmProviderAttemptConnectionIntegritySchema,
+ },
+ {
+ // Renumbered from 0109 when `dev` was merged: `dev` had already shipped
+ // `0109_grok_subscription_connections`, so this one moves to the end of the
+ // list rather than claiming a version another migration already uses.
+ version: '0115_llm_allowed_models_image_input',
+ apply: async db => {
+ // #654 — model-level image-input capability + evidence for the allowlist.
+ //
+ // ADDITIVE and NULLABLE. Every pre-existing row reads as `unknown` (no
+ // affirmative capability): the shared contract
+ // (`@clerum/llm-providers` normalizeImageInputCapability) maps absent or
+ // malformed metadata to `{ state: 'unknown' }`, so a legacy row can never
+ // become affirmative support by accident, and this migration alone changes
+ // no runtime behavior — enforcement acts only where a capability exists.
+ //
+ // The CHECK constrains the ONE field no reader may have to guess (`state`)
+ // against a non-object/scalar payload. The nested evidence is validated
+ // strictly on write by the service (shared parser) and normalized on read,
+ // so `state` here is a backstop, not the only gate.
+ //
+ // All three conjuncts are load-bearing, because a CHECK accepts NULL:
+ // `jsonb_typeof` alone would let `{}` through (`'{}'::jsonb->>'state'` is
+ // NULL, so the IN list yields NULL, not FALSE), and `? 'state'` alone
+ // would let `{"state": null}` through (`?` is true while `->>` is NULL).
+ // COALESCE is what turns that untyped NULL into a real FALSE.
+ await db.query(`
+ ALTER TABLE llm_allowed_models
+ ADD COLUMN IF NOT EXISTS image_input JSONB;
+ DO $$ BEGIN
+ ALTER TABLE llm_allowed_models
+ ADD CONSTRAINT llm_allowed_models_image_input_state_check
+ CHECK (
+ image_input IS NULL
+ OR (
+ jsonb_typeof(image_input) = 'object'
+ AND image_input ? 'state'
+ AND COALESCE(
+ image_input->>'state' IN ('supported','unsupported','unknown'),
+ false
+ )
+ )
+ );
+ EXCEPTION WHEN duplicate_object THEN NULL;
+ END $$;
+ `)
+
+ // This migration is PURELY ADDITIVE: it adds the column and the CHECK, and
+ // writes no data. It used to hand-curate two Z.AI ids from their public
+ // docs, which was a stand-in for not knowing any model's image capability.
+ // The catalog sync now derives that from models.dev `modalities.input` for
+ // every model, including those two (#654), so the seed would only have
+ // pinned `curated` provenance the sync is required never to overwrite —
+ // freezing exactly the rows a test harness needs to be able to refresh.
+ },
+ },
++ {
++ version: '0116_mcp_secret_rollback_permits',
++ // Renumbered twice while syncing onto dev: 0101 -> 0109 -> 0116. This branch
++ // introduced the migration as 0101; the first sync brought dev's 0101–0108
++ // (codex multi-connection through the SDK-link FK) and pushed it to 0109;
++ // this sync brought dev's 0109–0115 (grok subscriptions through the
++ // allowed-models image-input column), so 0109 is now taken by
++ // 0109_grok_subscription_connections and the migration moves to the end of
++ // the list rather than claiming a version another migration already uses.
++ // Environments where this feature branch was already deployed recorded it
++ // under one of the earlier names. legacyVersions lets the runner mark 0116
++ // applied from that prior row instead of re-running the DDL and leaving an
++ // orphan schema_migrations entry. Both prior names are unique to this
++ // migration, so there is no false-skip.
++ legacyVersions: ['0101_mcp_secret_rollback_permits', '0109_mcp_secret_rollback_permits'],
+ apply: applyMcpSecretRollbackPermitSchema,
+ },
]
async function consolidateWorkflowAllowedUsersToTriggers(db: DbClient): Promise<void> {
diff --cc control-api/src/routes/admin/secrets.ts
index 8c334fe07,0169b7062..3192fcbe3
--- a/control-api/src/routes/admin/secrets.ts
+++ b/control-api/src/routes/admin/secrets.ts
@@@ -42,43 -22,6 +42,55 @@@ import { isLlmHostSecret } from './llmS
const logger = rootLogger
+export type McpSecretRollbackPermitStore = {
+ issue(input: McpSecretRollbackPermit): Promise<void>
+ claim(input: McpSecretRollbackPermitLookup): Promise<McpSecretRollbackPermitClaim | null>
+ release(input: McpSecretRollbackPermitClaimBinding): Promise<void>
+ finalize(input: McpSecretRollbackPermitClaimBinding): Promise<void>
+}
+
+const defaultMcpSecretRollbackPermitStore: McpSecretRollbackPermitStore = {
+ issue: issueMcpSecretRollbackPermit,
+ claim: claimMcpSecretRollbackPermit,
+ release: releaseMcpSecretRollbackPermitClaim,
+ finalize: finalizeMcpSecretRollbackPermitClaim,
+}
+
+const mcpSecretDeleteEdgeRateLimit = rateLimit({
+ windowMs: 60_000,
+ limit: 60,
+ standardHeaders: 'draft-7',
+ legacyHeaders: false,
+ keyGenerator: req => {
+ const sessionJti = (req as UiAuthedRequest).adminAuth?.jti
+ return sessionJti
+ ? `admin-session:${createHash('sha256').update(sessionJti).digest('hex')}`
+ : ipKeyGenerator(req.ip ?? '127.0.0.1')
+ },
+})
+
+const mcpSecretDeleteRateLimit = rateLimitMiddleware({
+ bucketType: 'admin_mcp_secret_delete',
+ maxPerMinute: 30,
+ getBucketKey: req => {
+ const sessionJti = (req as UiAuthedRequest).adminAuth?.jti
+ const caller = sessionJti || req.ip || 'unknown-admin'
+ return `admin-mcp-secret-delete:${createHash('sha256').update(caller).digest('hex')}`
+ },
++ // Required by RateLimitEnforcerOptions since dev made the choice explicit; the
++ // union has no fail-open member, so both modes still enforce.
++ //
++ // 'process-memory', not 'closed': this is an admin-authenticated surface that
++ // already sits behind mcpSecretDeleteEdgeRateLimit (in-process, 60/min), which
++ // caps it whether or not Postgres can count. 'closed' answers 503, which would
++ // deny an operator the ability to delete a Secret precisely during a Postgres
++ // outage — when removing a compromised Secret matters most. The two 'closed'
++ // callers in the repo are the external GFS surfaces (#764), where an
++ // uncountable request from an untrusted caller is refused instead of admitted
++ // unmetered; that reasoning does not transfer to an authenticated admin route.
++ onBackendUnavailable: 'process-memory',
+})
+
// The bedrock credential-slot keys and the vertex service-account key, derived
// from the shared provider package (never hardcoded here) so the write-side
// gate cannot drift from the UI's client-side gate (spec R4.5.3).
diff --cc control-api/test/db.oauthGrantsOwnerGeneralization.test.ts
index 87ccc5c10,e4759a7f0..30bdc76d0
--- a/control-api/test/db.oauthGrantsOwnerGeneralization.test.ts
+++ b/control-api/test/db.oauthGrantsOwnerGeneralization.test.ts
@@@ -21,13 -21,7 +21,20 @@@ describe('0101 oauth_grants owner gener
const { CONTROL_API_MIGRATIONS } = await import('../src/db.js')
const versions = CONTROL_API_MIGRATIONS.map(m => m.version)
expect(versions).toContain('0106_oauth_grants_owner_generalization')
- expect(versions.at(-1)).toBe('0115_llm_allowed_models_image_input')
+ // Ordering, not tail position: this test guards where 0106 sits relative to
- // its neighbours. Pinning `.at(-1)` asserted that 0108 is the last
- // migration that will ever exist, which every subsequent additive
- // migration breaks — 0109_mcp_secret_rollback_permits did.
++ // its neighbours. Pinning `.at(-1)` asserted that the migration named there
++ // is the last one that will ever exist, which every subsequent additive
++ // migration breaks — 0116_mcp_secret_rollback_permits did.
++ //
++ // `indexOf` returns -1 for an absent version, and -1 is less than any real
++ // index, so the ordering assertion alone would pass vacuously if the left
++ // operand were dropped from the list. The two `toContain` assertions are the
++ // liveness witness: they fail first if either version stops being registered.
++ expect(versions).toContain('0108_llm_provider_attempts_sdk_link_on_delete_set_null')
++ expect(versions).toContain('0116_mcp_secret_rollback_permits')
+ expect(versions.indexOf('0108_llm_provider_attempts_sdk_link_on_delete_set_null')).toBeLessThan(
- versions.indexOf('0109_mcp_secret_rollback_permits')
++ versions.indexOf('0116_mcp_secret_rollback_permits')
+ )
expect(versions.indexOf('0100_seed_minimax_allowed_model')).toBeLessThan(
versions.indexOf('0106_oauth_grants_owner_generalization')
)
diff --cc control-ui/components/SecretsTable.tsx
index 2859f7d6f,4f7455a06..e71d07150
--- a/control-ui/components/SecretsTable.tsx
+++ b/control-ui/components/SecretsTable.tsx
@@@ -744,112 -721,130 +736,134 @@@ export function SecretsTable(
</tr>
</thead>
<tbody>
- {filteredRecipeRows.map(row => (
- <tr key={`${row.status}:${row.namespace}:${row.name}`}>
- <td>
- <div style={{ display: 'inline-flex', alignItems: 'center', gap: '0.5rem' }}>
- <span>{row.name}</span>
- <span className="cu-chip" title={`Secret namespace: ${row.namespace}`}>
- {row.namespace}
- </span>
- {row.status === 'missing' ? (
- <span
- className="cu-chip"
- style={{
- color: 'var(--cu-warn-text, var(--cu-text-soft))',
- borderColor: 'var(--cu-warn-border, var(--cu-border-subtle))',
- }}
- >
- Missing
- </span>
- ) : null}
- {row.ownership?.kind === 'shared' ? (
- <span className="cu-chip" title="Any recipe can reference this secret">
- Shared
- </span>
- ) : null}
- {row.ownership?.kind === 'owner-recipe' ? (
- <span
- className="cu-chip"
- title={`Only ${row.ownership.recipeName} can reference this secret`}
- >
- Owner: {row.ownership.recipeName}
- </span>
- ) : null}
- {row.ownership?.kind === 'unlabeled' ? (
- <span
- className="cu-chip"
- style={{
- color: 'var(--cu-warn-text, var(--cu-text-soft))',
- borderColor: 'var(--cu-warn-border, var(--cu-border-subtle))',
- }}
- title="Secret has neither owner-recipe nor shared label — WRC will refuse to project it"
- >
- Unlabeled
- </span>
- ) : null}
- </div>
- </td>
- <td style={{ color: 'var(--cu-text-soft)', fontSize: '0.8125rem' }}>
- {row.keys.length > 0
- ? row.keys.join(', ')
- : row.status === 'missing'
- ? 'No keys declared by recipe.'
- : 'No keys defined.'}
- </td>
- <td style={{ color: 'var(--cu-text-soft)', fontSize: '0.8125rem' }}>
- {row.recipes.length > 0
- ? `${row.recipes.length} recipe(s): ${row.recipes.join(', ')}`
- : 'Not yet referenced by a recipe.'}
- </td>
- <td style={{ textAlign: 'right' }}>
- {row.status === 'missing' ? (
- <button
- type="button"
- className="cu-btn cu-btn--primary cu-btn--sm"
- onClick={() =>
- onCreateRecipeSecretFor(
- row.name,
- row.keys,
- row.recipes.length === 1 ? row.recipes[0] : undefined,
- row.namespace
- )
- }
- aria-label={`Add recipe secret ${row.name}`}
+ {isRecipeInitialLoad ? (
+ <TableStateRow colSpan={4} kind="loading" message="Loading recipe secrets…" />
+ ) : recipeError && filteredRecipeRows.length === 0 ? (
+ <TableStateRow colSpan={4} kind="error" message={recipeError} />
+ ) : filteredRecipeRows.length === 0 ? (
+ <TableStateRow
+ colSpan={4}
+ message={
+ normalizedRecipeSearch
+ ? 'No recipe secrets match this search.'
+ : 'No recipe secrets found.'
+ }
+ />
+ ) : (
+ recipeSort.sortedRows.map(row => (
+ <tr key={`${row.status}:${row.namespace}:${row.name}`}>
+ <td>
+ <div
+ style={{ display: 'inline-flex', alignItems: 'center', gap: '0.5rem' }}
>
- Add
- </button>
- ) : (
- <div style={{ display: 'inline-flex', gap: '0.35rem' }}>
- <RowActionsMenu
- ariaLabel={`Actions for recipe secret ${row.name}`}
- horizontalTrigger
- actions={[
- {
- key: 'update',
- label: 'Update',
- onClick: () => navigateToRecipeEdit(row.name, row.namespace),
- },
- {
- key: 'delete',
- label:
- recipeDeletingName === `${row.namespace}/${row.name}`
- ? 'Deleting…'
- : 'Delete',
- danger: true,
- disabled: recipeDeletingName === `${row.namespace}/${row.name}`,
- onClick: () => void deleteRecipeSecretRow(row),
- },
- ]}
- />
+ <span>{row.name}</span>
+ <span className="cu-chip" title={`Secret namespace: ${row.namespace}`}>
+ {row.namespace}
+ </span>
+ {row.status === 'missing' ? (
+ <span
+ className="cu-chip"
+ style={{
+ color: 'var(--cu-warn-text, var(--cu-text-soft))',
+ borderColor: 'var(--cu-warn-border, var(--cu-border-subtle))',
+ }}
+ >
+ Missing
+ </span>
+ ) : null}
+ {row.ownership?.kind === 'shared' ? (
+ <span className="cu-chip" title="Any recipe can reference this secret">
+ Shared
+ </span>
+ ) : null}
+ {row.ownership?.kind === 'owner-recipe' ? (
+ <span
+ className="cu-chip"
+ title={`Only ${row.ownership.recipeName} can reference this secret`}
+ >
+ Owner: {row.ownership.recipeName}
+ </span>
+ ) : null}
+ {row.ownership?.kind === 'unlabeled' ? (
+ <span
+ className="cu-chip"
+ style={{
+ color: 'var(--cu-warn-text, var(--cu-text-soft))',
+ borderColor: 'var(--cu-warn-border, var(--cu-border-subtle))',
+ }}
+ title="Secret has neither owner-recipe nor shared label — WRC will refuse to project it"
+ >
+ Unlabeled
+ </span>
+ ) : null}
</div>
- )}
- </td>
- </tr>
- ))}
+ </td>
+ <td style={{ color: 'var(--cu-text-soft)', fontSize: '0.8125rem' }}>
+ {row.keys.length > 0
+ ? row.keys.join(', ')
+ : row.status === 'missing'
+ ? 'No keys declared by recipe.'
+ : 'No keys defined.'}
+ </td>
+ <td style={{ color: 'var(--cu-text-soft)', fontSize: '0.8125rem' }}>
+ {row.recipes.length > 0
+ ? `${row.recipes.length} recipe(s): ${row.recipes.join(', ')}`
+ : 'Not yet referenced by a recipe.'}
+ </td>
+ <td className="cu-table__cell-actions">
+ {row.status === 'missing' ? (
+ <button
+ type="button"
+ className="cu-btn cu-btn--primary cu-btn--sm"
+ onClick={() =>
+ onCreateRecipeSecretFor(
+ row.name,
+ row.keys,
+ row.recipes.length === 1 ? row.recipes[0] : undefined,
+ row.namespace
+ )
+ }
+ aria-label={`Add recipe secret ${row.name}`}
+ >
+ Add
+ </button>
+ ) : (
+ <div style={{ display: 'inline-flex', gap: '0.35rem' }}>
+ <RowActionsMenu
+ ariaLabel={`Actions for recipe secret ${row.name}`}
+ horizontalTrigger
+ actions={[
+ {
+ key: 'update',
+ label: 'Update',
+ onClick: () => navigateToRecipeEdit(row.name, row.namespace),
+ },
+ {
+ key: 'delete',
+ label:
+ recipeDeletingName === `${row.namespace}/${row.name}`
+ ? 'Deleting…'
+ : 'Delete',
+ danger: true,
+ disabled: recipeDeletingName === `${row.namespace}/${row.name}`,
- onClick: () =>
- void deleteRecipeSecretRow(row.name, row.namespace),
++ // Pass the whole row, not (name, namespace): the delete is
++ // fenced on the live object's uid + resourceVersion, which
++ // only the row carries. Reducing it to two identifier strings
++ // would drop the CAS precondition and let the request delete a
++ // Secret that was replaced since the table was loaded.
++ onClick: () => void deleteRecipeSecretRow(row),
+ },
+ ]}
+ />
+ </div>
+ )}
+ </td>
+ </tr>
+ ))
+ )}
</tbody>
- </table>
- </div>
+ </DataTable>
+ </TableViewport>
)}
{scope === 'mcp' ? (
diff --cc desktop-app/src/__tests__/uiCsp.test.ts
index 000000000,d9ae08f8a..5eebf74cb
mode 000000,100644..100644
--- a/desktop-app/src/__tests__/uiCsp.test.ts
+++ b/desktop-app/src/__tests__/uiCsp.test.ts
@@@ -1,0 -1,12 +1,12 @@@
++import { describe, expect, it } from 'vitest'
+ import { promises as fs } from 'node:fs'
+ import path from 'node:path'
-import { describe, expect, it } from 'vitest'
+
+ describe('desktop UI content security policy', () => {
+ it('allows blob-backed media used by GFS video previews', async () => {
+ const source = await fs.readFile(path.join(process.cwd(), 'ui', 'index.html'), 'utf8')
+ const content = source.match(/http-equiv="Content-Security-Policy"\s+content="([^"]+)"/)?.[1]
+
+ expect(content).toContain("media-src 'self' blob:")
+ })
+ })