Skip to content

Save a model key added in the Vault where the Bots read it - #1524

Merged
davidmckayv merged 2 commits into
mainfrom
fix/vault-ai-key-name
Nov 12, 2026
Merged

davidmckayv merged 2 commits into
mainfrom
fix/vault-ai-key-name

Conversation

@davidmckayv

Copy link
Copy Markdown
Contributor

What a person saw

Settings > Setup says the AI model needs a key: "Set OPENAI_API_KEY, then restart OpenBot. Or add the key in Vault." In the Vault's Add key form, someone who follows the placeholders types Provider "OpenAI" and Key ID "production" and saves. The key is stored, the Vault lists it as active, and Setup still says "Needs setup": OpenBot can't answer.

Why

The Personal Assistant, and every built-in Bot, reads one vault entry for its model key: a model credential for the provider it runs on (openai), under the tenant package's model.credential_secret_ref (openai-api-key). resolveModelApiKey and the Setup checklist both match that exactly. The form asked for both as free text and said nothing about either, so the only way to get it right was to already know the internal name. The end-to-end core loop (#1521) worked around it by typing the exact name.

The fix

Take the names off the form for a model key, so there is nothing to get wrong:

  • Add key form: for a model key, Provider is a choice of the AI providers (OpenAI, Anthropic), starting on the one the Bots run on, with one line saying whether they'll use the key ("Your Bots run on OpenAI and will use this key." / "..., so they won't use this key."). There is no Key ID field for a model key. A connector key keeps its free-text provider and key ID (placeholder now "GitHub", since "OpenAI" pointed people at the wrong type).
  • Server: a model key posted without a key ID is filed under the name the Bots read. GET /api/admin/credentials also returns modelKey (the provider the Bots run on and that name), which the form uses for its starting provider and for the existing "saving replaces it" notice.
  • Setup: the AI model row's "add the key in Vault" link opens the Add key form directly (/settings/vault/new, or /admin/credentials/new in a team), instead of the Vault list.

Why this one instead of the alternatives:

  • Pre-filling the form from Setup only still leaves the same trap for anyone who opens Add key from the Vault.
  • A lenient lookup (case-insensitive provider, or any key ID) would rescue "OpenAI" but not "production", and would change which key a deployment answers with whenever a stray model key exists. It also keeps a free-text field that can still be mistyped.
  • A choice list plus the server choosing the name covers every way into the form, and the server stays the one place that knows the name.

Nothing is renamed or migrated. A key already saved under the exact name keeps working, and a client that still sends a key ID (the exact name, or a connector's) is saved as before.

Tests (red, then green)

  • server/tests/credentials.test.ts, "a model key added in the Vault" (real Postgres, real route): posts what the form now sends (provider and secret, no name) and resolves the Personal Assistant's key the way every built-in Bot's run does, with the name read from examples/personal. Red on main: the post is refused (400) and the list has no modelKey. Green after. A third case pins that a client sending the exact name still works.
  • app/tests/new-credential-page.test.tsx: the form starts on the Bots' provider (OpenAI, and Anthropic when that's what they run on), offers no Key ID, and posts { kind, provider, plaintext, metadata } with no name. Red with main's form: there is no Provider choice.
  • e2e/journeys/core-loop.journey.ts: the core loop now adds the key the way a person does. Setup's link opens Add key, Provider already reads OpenAI, the person pastes the key and types nothing else, Setup moves off "Needs setup", and the Personal Assistant answers. Red on main (the link opens the Vault list, not the form); green on this branch, with 0 strict-replay misses. The aimock fixtures are unchanged.
  • Updated the Setup link path in server/tests/setup-checklist.test.ts and app/tests/setup-checklist-editions.test.tsx.

Checked by looking

Screenshots before (main) and after (this branch): Setup, the Add key form, the Vault list, Setup after saving, the answer, the other-provider line, the replace notice, a connector key, and the form at phone width. On main, following the placeholders leaves Setup at "Needs setup". On this branch the form is Type, Provider, Secret, and Setup reads "The key is set". Spacing, alignment and wrapping match the rest of Settings.

The Personal Assistant and the other built-in Bots read one vault entry for their model key: the provider they run on, under the tenant package's key name (openai-api-key). The Vault's Add key form asked for a free-text provider and key ID with "OpenAI" and "production" as placeholders, so a person who followed them saved a key nothing read, and Setup still said OpenBot couldn't answer.

- Add key asks a model key only which provider it is for, starting on the one the Bots run on, and says whether they will use it. It sends no name.
- The server files a model key that arrives without a name under the name the Bots read, and tells the form which provider and name that is.
- Setup's "add the key in Vault" link opens the Add key form directly.
- A key sent with a name (the exact one, or a connector's) is saved as before.
@davidmckayv
davidmckayv merged commit 7c3fdd6 into main Nov 12, 2026
23 checks passed
@davidmckayv
davidmckayv deleted the fix/vault-ai-key-name branch November 12, 2026 21:31
davidmckayv added a commit that referenced this pull request Nov 12, 2026
These carry the server half of #1524 and #1531.

The desktop's two cross-writer lock tests take the server's own lock as their other writer, which
now runs in the server image, so they are ignored here and say why. The release rerun tests package
a chart with helm and archive a tree more than once, which takes longer than five seconds on a
shared runner.
davidmckayv added a commit that referenced this pull request Nov 13, 2026
These carry the server half of #1524 and #1531.

The desktop's two cross-writer lock tests take the server's own lock as their other writer, which
now runs in the server image, so they are ignored here and say why. The release rerun tests package
a chart with helm and archive a tree more than once, which takes longer than five seconds on a
shared runner.
davidmckayv added a commit that referenced this pull request Nov 13, 2026
These carry the server half of #1524 and #1531.

The desktop's two cross-writer lock tests take the server's own lock as their other writer, which
now runs in the server image, so they are ignored here and say why. The release rerun tests package
a chart with helm and archive a tree more than once, which takes longer than five seconds on a
shared runner.
davidmckayv added a commit that referenced this pull request Nov 13, 2026
These carry the server half of #1524 and #1531.

The desktop's two cross-writer lock tests take the server's own lock as their other writer, which
now runs in the server image, so they are ignored here and say why. The release rerun tests package
a chart with helm and archive a tree more than once, which takes longer than five seconds on a
shared runner.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant