Skip to content

fix(den-api): scope catalog providers' env names to the provider row - #4281

Merged
reachjalil merged 1 commit into
devfrom
cloud-provider-env-namespacing
Sep 3, 2026
Merged

reachjalil merged 1 commit into
devfrom
cloud-provider-env-namespacing

Conversation

@reachjalil

@reachjalil reachjalil commented Sep 1, 2026 •

Copy link
Copy Markdown
Member

Problem

Den provider rows created from the models.dev catalog declare their credential env name straight from the catalog (OPENAI_API_KEY, ANTHROPIC_API_KEY, …). OpenWork materialized the organization credential under that exact name on members' machines and cloud workers. The desktop shell injects the user env store into the engine, and OpenCode treats a well-known env name as global provider config, so:

  • one organization OpenAI provider switched on OpenCode's whole built-in OpenAI catalog next to the scoped lpr_* provider;
  • it silently shadowed any OPENAI_API_KEY the member had set themselves;
  • two rows for the same vendor (two OpenRouter keys, say) shared one credential slot.

The change

Catalog providers now leave Den under a provider-scoped env name:

LPR_<last five characters of the row id>_<declared name>
lpr_01kx4t3amgendr682dmp6120jv + OPENAI_API_KEY  →  LPR_120JV_OPENAI_API_KEY
Provider source Runtime env names
models_dev (catalog) scoped: LPR_120JV_OPENAI_API_KEY
custom unchanged — exactly what the organization declared
openwork (hosted) unchanged — OPENWORK_API_KEY

The rename happens in one place, where a provider leaves Den: the /connect payload every desktop consumes (providerConfig.env and the apiKeys map) and the cloud-worker materializer. Desktop server, desktop app, and worker consumers need no logic changes; they use the names they are given.

Why this shape

  • No storage, no migration, reversible. The name is a pure function of the row id. Stored rows keep the catalog names, re-syncs are idempotent (a second pass is a noop), and reverting this PR returns bare names on the next sync. Existing catalog rows move to the scoped name on their next sync through the same owned-key cleanup that already handles env changes.
  • Custom providers are untouched. Organizations that route members to their own gateway and declare the env name themselves keep that contract, including leaving the credential for the member's machine.
  • Prefix, not suffix. Primary-credential selection ranks names by their _API_KEY / _ACCESS_KEY_ID suffix (three copies: den-api, desktop server, desktop app). A prefix keeps Azure's LPR_…_AZURE_API_KEY ranked above LPR_…_AZURE_RESOURCE_NAME without touching any of them.
  • Visible, not magic. Provider responses gain an additive runtimeEnvKeys list. The Den editor shows the exact names members' machines read under the credential fields; the desktop provider list prefers them when present and falls back for older Den servers.

Proof

  • pnpm evals:pr specs/cloud-provider-env-namespacing.test.ts — app-less spec: a catalog row and a custom row go through den-api's transform and the desktop CloudProviderSync; asserts the scoped name in the provider block and env store, the custom name untouched, the member's own OPENAI_API_KEY never overwritten, the engine still receiving the org credential via /auth, a repeat sync as noop, and sign-out removing only what OpenWork wrote.
  • bun test test/provider-credentials.test.ts test/cloud-provider-materialization.test.ts in ee/apps/den-api — 54 pass, including a new custom-provider case and the pure-function rule (determinism, ranking, no mutation of the stored input).
  • pnpm evals:pr specs/spec-impact.test.ts, tsc for ee/apps/den-api, ee/apps/den-web, apps/app — green.

Known edge

A catalog provider with no credential stored in Den, satisfied today by a member's locally saved bare OPENAI_API_KEY, now looks for LPR_…_OPENAI_API_KEY instead. The Den editor and desktop provider list show that exact name. This is the intended single rule (catalog → scoped, always) rather than a value-dependent exception.

@vercel

vercel Bot commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
openwork-app Ready Ready Preview Sep 3, 2026 7:59pm UTC
openwork-den Ready Ready Preview Sep 3, 2026 7:59pm UTC
openwork-diagnostics Ready Ready Preview Sep 3, 2026 7:59pm UTC
openwork-landing Ready Ready Preview, v0 Sep 3, 2026 7:59pm UTC

@reachjalil

reachjalil commented Sep 1, 2026 •

Copy link
Copy Markdown
Member Author

Test evidence — granted-cloud-providers-appear-automatically-in-settings-and-the-model-picker — 2/2 screenshots passed · 6 assertions

✅ 2/2 screenshots passed · 6 assertions · 12 expectations passed · 0 failed · 0 pending

screenshots not uploaded (no BLOB_READ_WRITE_TOKEN)

ℹ️ ASSERTION — 1. The granted provider connected without an import action

Settings state: {"connected":true,"importButton":false}

  • ✅ PASS The granted provider connected without an import action — Settings state: {"connected":true,"importButton":false}

✅ PASS — 2. The Cloud providers page shows Automatic Team Models as Connected

  • ✅ PASS The Cloud providers page shows Automatic Team Models as Connected — “Automatic Team Models” is shown with a green “Connected” badge.
  • ✅ PASS The page is status-only with Sync now and no Import provider action — A “Sync now” button is visible, and no “Import provider” action appears.
  • ✅ PASS No error or crash message is visible — The page renders normally with provider status and no visible error or crash message.

ℹ️ ASSERTION — 3. The organization credential is stored only under OpenWork's env namespace

OPENWORK_AUTO_IMPORT_PROVIDER_API_KEY holds the organization credential; bare AUTO_IMPORT_PROVIDER_API_KEY is absent.

  • ✅ PASS The organization credential is stored only under OpenWork's env namespace — OPENWORK_AUTO_IMPORT_PROVIDER_API_KEY holds the organization credential; bare AUTO_IMPORT_PROVIDER_API_KEY is absent.

ℹ️ ASSERTION — 4. The server-side sync settled with the provider materialized

lastRun: applied; reloadPending: false; skipped: []

  • ✅ PASS The server-side sync settled with the provider materialized — lastRun: applied; reloadPending: false; skipped: []

ℹ️ ASSERTION — 5. The organization model reaches the picker within 3 Sync now refreshes

The model was in the picker on the first read after import.

  • ✅ PASS The organization model reaches the picker within 3 Sync now refreshes — The model was in the picker on the first read after import.

ℹ️ ASSERTION — 6. The automatically imported provider contributes exactly its assigned model

Selectable models: [{"id":"automatic-proof-model","name":"Automatic Proof Model","providerName":"Automatic Team Models","selected":true,"selectable":true}]; models offered under Automatic Team Models: ["automatic-proof-model"]

  • ✅ PASS The automatically imported provider contributes exactly its assigned model — Selectable models: [{"id":"automatic-proof-model","name":"Automatic Proof Model","providerName":"Automatic Team Models","selected":true,"selectable":true}]; models offered under Automatic Team Models: ["automatic-proof-model"]

✅ PASS — 7. The open Models picker shows automatic-proof-model from the organization provider

  • ✅ PASS The open Models picker shows automatic-proof-model from the organization provider — The expanded “Automatic Team Models” provider shows “Automatic Proof Model” with ID “automatic-proof-model”.
  • ✅ PASS The organization model is visibly selectable without a provider connection prompt — “Automatic Proof Model” is visible, highlighted, and checked; no provider connection prompt is shown.
  • ✅ PASS No error or crash message is visible — The Models dialog is displayed normally with model lists and a Done button; no error or crash message appears.

ℹ️ ASSERTION — 8. A bare key the member set with a different value survives the next sync

After a applied sync, AUTO_IMPORT_PROVIDER_API_KEY still holds the member's value and OPENWORK_AUTO_IMPORT_PROVIDER_API_KEY still holds the organization credential.

  • ✅ PASS A bare key the member set with a different value survives the next sync — After a applied sync, AUTO_IMPORT_PROVIDER_API_KEY still holds the member's value and OPENWORK_AUTO_IMPORT_PROVIDER_API_KEY still holds the organization credential.

Test run created 2026-09-01T22:20:26.522Z · Source: evals/results/test-runs/2026-09-01T22-20-26-522Z-granted-cloud-providers-appear-automatically-in-settings-and-the-model-picker/test-run.json · Repro: pnpm --dir evals artifacts:publish -- --pr 4281 --test-run 2026-09-01T22-20-26-522Z-granted-cloud-providers-appear-automatically-in-settings-and-the-model-picker

diff-warden[bot]
diff-warden Bot previously approved these changes Sep 1, 2026

@diff-warden diff-warden Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warden security clearance: clear. No blocking findings (security or desktop↔den sync) in this diff (68d4a9a99a56c191810d5a84b238de51df2f540f). Automated clearance satisfies the required-review gate only — a human still reviews and merges. Analysis run

diff-warden[bot]
diff-warden Bot previously approved these changes Sep 1, 2026

@diff-warden diff-warden Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warden security clearance: clear. No blocking findings (security or desktop↔den sync) in this diff (5bf9cc61e31ae635b81eb649e0c9d9127ea80ae7). Automated clearance satisfies the required-review gate only — a human still reviews and merges. Analysis run

diff-warden[bot]
diff-warden Bot previously approved these changes Sep 2, 2026

@diff-warden diff-warden Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warden security clearance: clear. No blocking findings (security or desktop↔den sync) in this diff (be5e3b58e8b3035d81f038d205cbc045e8cb81c3). Automated clearance satisfies the required-review gate only — a human still reviews and merges. Analysis run

Den provider rows created from the models.dev catalog declare their
credential env name straight from the catalog (OPENAI_API_KEY,
ANTHROPIC_API_KEY, ...). OpenWork materialized the organization
credential under that exact name on members' machines and cloud
workers. The desktop shell injects the user env store into the engine,
and OpenCode treats a well-known env name as global provider config, so
one organization OpenAI provider switched on OpenCode's whole built-in
OpenAI catalog next to the scoped lpr_* provider, shadowed any
OPENAI_API_KEY the member had set themselves, and two rows for the same
vendor shared one credential slot.

Catalog providers now leave Den under a provider-scoped name:
`LPR_<last five characters of the row id>_<declared name>`, e.g.
`LPR_120JV_OPENAI_API_KEY`. The rename is applied where a provider
leaves Den (the connect payload every desktop consumes and the cloud
worker materializer), so every consumer picks it up without changes.

- The name is a pure function of the row id: nothing is stored, no
  migration runs, re-syncs are idempotent, and reverting this commit
  simply returns the bare names on the next sync.
- Only `source: "models_dev"` rows are affected. Custom providers keep
  exactly the env names their organization declared, and the hosted
  OpenWork provider keeps OPENWORK_API_KEY.
- The tag is a prefix, so credential-shaped suffixes (`_API_KEY`,
  `_ACCESS_KEY_ID`) still drive primary-credential selection for
  multi-env providers such as Azure.
- Provider responses gain an additive `runtimeEnvKeys` list; the Den
  editor shows the exact names members' machines read, and the desktop
  provider list prefers them when present.

@diff-warden diff-warden Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warden security clearance: clear. No blocking findings (security or desktop↔den sync) in this diff (f71f056008924e00847e48ab9c0781c1246c16a0). Automated clearance satisfies the required-review gate only — a human still reviews and merges. Analysis run

@reachjalil
reachjalil merged commit f0d77be into dev Sep 3, 2026
33 checks passed
OmarMcAdam added a commit that referenced this pull request Oct 6, 2026
…env names (#5730)

Catalog providers leave Den under provider-scoped env names
(LPR_<tag>_AWS_REGION) since #4281. OpenCode hands a provider's credential
to its SDK only when the provider declares a single env name, so for
multi-env providers such as Amazon Bedrock the SDK fell back to the bare
names (AWS_REGION, AWS_ACCESS_KEY_ID, ...), which no longer exist. Every
chat failed with "AWS region setting is missing".

Den now binds each delivered env name that a bundled SDK reads to that
SDK option as an {env:RUNTIME_NAME} reference, for desktop connect
payloads and cloud workers alike. The env -> option list lives in
@openwork-ee/utils/ai-sdk-env-settings and a spec checks it against the
pairs extracted from the pinned OpenCode binary.

Saving a changed Bedrock credential without a valid AWS_REGION is now
rejected instead of failing on every request.

Fixes #5705

Signed-off-by: Omar McAdam <[email protected]>
OmarMcAdam added a commit that referenced this pull request Oct 6, 2026
…env names (#5733)

Reapplies #5730 (reverted in #5732) with its tests moved out of
evals/specs, where the spec-boundary ratchet rejects unit tests.

Catalog providers leave Den under provider-scoped env names
(LPR_<tag>_AWS_REGION) since #4281. OpenCode hands a provider's credential
to its SDK only when the provider declares a single env name, so for
multi-env providers such as Amazon Bedrock the SDK fell back to the bare
names (AWS_REGION, AWS_ACCESS_KEY_ID, ...), which no longer exist. Every
chat failed with "AWS region setting is missing".

Den now binds each delivered env name that a bundled SDK reads to that
SDK option as an {env:RUNTIME_NAME} reference, for desktop connect
payloads and cloud workers alike. The env -> option list lives in
@openwork-ee/utils/ai-sdk-env-settings.

Saving a changed Bedrock credential without a valid AWS_REGION is now
rejected instead of failing on every request.

Tests are colocated and run in the Unit tests job against the pinned
OpenCode on PATH: a drift test compares the list with the pairs extracted
from that binary, and a wire test proves scoped-only Bedrock credentials
reach the provider with their own region and keys.

Fixes #5705

Signed-off-by: Omar McAdam <[email protected]>

This branch was successfully deployed

4 active deployments
Preview – openwork-landing — f71f0560 Deployed Sep 3, 2026 by vercel[bot]
Preview – openwork-den — f71f0560 Deployed Sep 3, 2026 by vercel[bot]
Preview – openwork-app — f71f0560 Deployed Sep 3, 2026 by vercel[bot]
Preview – openwork-diagnostics — f71f0560 Deployed Sep 3, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants