Skip to content

[fix] Read provider-key presence from value_status, not the write-only value - #6691

Merged
mmabrouk merged 1 commit into
release/v0.115.3from
fix/release-1153-provider-key-presence
Sep 8, 2026
Merged

[fix] Read provider-key presence from value_status, not the write-only value#6691
mmabrouk merged 1 commit into
release/v0.115.3from
fix/release-1153-provider-key-presence

Conversation

@mmabrouk

@mmabrouk mmabrouk commented Sep 8, 2026

Copy link
Copy Markdown
Member

Context

The playground's Model section kept asking for a provider key after one was added, while the agent ran on that same key. Reproduced on staging v0.115.3 with the steps from #6660: fresh project, Settings, AI providers, Add provider, OpenAI, paste a working key, Test reports 133 models fetched, Done. The provider row lists the key. Back in the playground the Model row still shows the amber Connect key badge and its "Connect the model's provider key to run this agent." tooltip, and it survives a reload. The turn that follows reaches OpenAI and comes back with a billing error, so the key is plainly in use.

The cause is a presence check reading the wrong field. Secrets are write-only on staging and on every dev stack, so /secrets/ returns no value at all:

{"kind":"provider_key","data":{"kind":"openai","provider":{}},
 "write_only":true,"value_status":{"configured":true,"preview":"sk-****AAA"}}

Presence rides on value_status.configured, which the transform surfaces as hasKey, and hasStoredKey is the one rule that reads it. The Model section tested !providerVaultEntry.key instead, which is true for every write-only row, so a connected project read as keyless forever.

Changes

Before:  vaultLoaded && !!providerVaultEntry && !providerVaultEntry.key
After:   vaultLoaded && !!standardProviderEntry && !hasStoredKey(standardProviderEntry)

The rule moves into shouldPromptForProviderKey (providerKeyPrompt.ts), which drives the badge, the section tooltip and the section auto-opening. Its exemptions are unchanged. A self_managed connection signs itself in through the harness, and a named agenta connection points at one vault record that this rule never looks up, so a missing standard key for the family says nothing about it. vaultLoaded still gates everything, so nothing prompts while the vault query is pending.

providerNeedsKey also drives the Provider credentials section's warning status, so that surface stops warning too.

One comment in the vault persister claimed !!secret.key was the presence rule. It is not, and it now points at hasStoredKey.

Tests

  • New packages/agenta-entity-ui/tests/unit/providerKeyPrompt.test.ts covers the row shapes the vault really serves: unconnected, write-only connected, readable connected, both of those restored from IndexedDB, and a record that says the key is gone while a stale value lingers. It fails against the old rule and passes against the new one.
  • pnpm --filter @agenta/entity-ui test: 710 passed. pnpm --filter @agenta/entities exec vitest run tests/unit: 1600 passed.
  • Types, pnpm lint-fix and pnpm run format: clean.
  • Codex reviewed the rule at extra-high effort: "the presence fix is correct, and I would ship it." Its requested changes are in, including the name, the contract comments, and the stale-value test case.

Browser verification

Before, on staging with a real OpenAI key, and after, on a PR preview with the same vault row shape, counting visible instances rather than matching text:

key present -> connectKeyBadges 0
key deleted -> connectKeyBadges 1

Screenshots are on the dev box under ~/agenta-qa-evidence/2026-09-08-issue-6660/, before and after plus the no-key regression.

Note on #6660

That issue described a second symptom, a stale banner above the composer, and it was closed as invalid: the banner text sits in the DOM in collapsed instances, so a whole-document text search reported it on every page whether or not anything was drawn. The closing comment keeps this half: "The Connect key badge bug that #6677 fixes in its first commit is real and was found independently on a fresh staging project. That fix stands on its own evidence." This PR is that fix, alone, off the current release head.

What to QA

  • Fresh project. Settings, AI providers, add an OpenAI key, Test, Done. Open an agent. The Model row shows the model with no Connect key badge, and no "Connect the model's provider key" tooltip on the section header.
  • Reload the playground. The badge stays away.
  • Regression: a project with no provider key at all. The badge is back and the Model section opens on it.
  • Regression: an agent on a self-managed connection, and one pointed at a named connection. Neither asks for a key.

…write-only value

The playground's Model section decided whether the project holds a key for
the selected model's provider by reading the key value off the vault row.
Secrets are write-only on staging and on every dev stack, so `/secrets/`
returns no value and reports presence through `value_status.configured`,
which the transform surfaces as `hasKey`. Every connected project therefore
read as keyless, and the amber "Connect key" badge and its "Connect the
model's provider key to run this agent." tooltip stayed up across reloads
while the agent ran on that same key.

The rule moves into `shouldPromptForProviderKey` and asks `hasStoredKey`,
the one vault presence rule. Its exemptions are unchanged: a self-managed
connection signs itself in, a named connection points at a vault record this
rule never looks up, and an unresolved vault prompts for nothing.
@vercel

vercel Bot commented Sep 8, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated
agenta-documentation Ready Ready Preview Sep 8, 2026 8:25pm UTC

Request Review

@mmabrouk

mmabrouk commented Sep 8, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Advanced

Run ID: d634a319-901e-4b4a-a5d6-b12e54904334

📥 Commits

Reviewing files that changed from the base of the PR and between 3ded1f9 and 159dc1f.

📒 Files selected for processing (4)
  • web/packages/agenta-entities/src/secret/state/persistence.ts
  • web/packages/agenta-entity-ui/src/DrillInView/SchemaControls/agentTemplate/providerKeyPrompt.ts
  • web/packages/agenta-entity-ui/src/DrillInView/SchemaControls/agentTemplate/useModelHarness.tsx
  • web/packages/agenta-entity-ui/tests/unit/providerKeyPrompt.test.ts

Included review availability: Your plan provides up to 8 included reviews per hour; 0 remain after this review.


📝 Summary

Summary by CodeRabbit

  • Bug Fixes
    • Improved provider-key prompts across model connections.
    • Prompts now correctly account for self-managed connections, named connections, unavailable provider data, and vault loading states.
    • Recognizes stored keys even when their values cannot be displayed, preventing unnecessary prompts.
    • Keeps configuration highlighting and chat prompting behavior consistent across supported connection scenarios.

Walkthrough

The change adds a shared provider-key prompt helper, replaces inline model-harness conditions, clarifies state usage, updates related documentation, and adds unit coverage for connection and vault-key states.

Changes

Provider key prompting

Layer / File(s) Summary
Provider key prompt helper
web/packages/agenta-entity-ui/src/DrillInView/SchemaControls/agentTemplate/providerKeyPrompt.ts, web/packages/agenta-entities/src/secret/state/persistence.ts
The new helper skips self-managed connections, named Agenta connections, unavailable vault data, and missing provider entries. It uses hasStoredKey to determine stored-key presence.
Model harness integration
web/packages/agenta-entity-ui/src/DrillInView/SchemaControls/agentTemplate/useModelHarness.tsx
The model harness uses the shared helper and distinguishes configuration-panel highlighting from chat gating.
Prompt decision tests
web/packages/agenta-entity-ui/tests/unit/providerKeyPrompt.test.ts
Unit tests cover loading, connection modes, provider availability, readable keys, write-only records, restored records, and stale key values.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 159dc

Provider-key badges and credential warnings now correctly recognize configured write-only keys while preserving existing connection and loading behavior. The covered change is ready to merge.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 60.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 4 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the main change: provider-key presence now uses value_status instead of the write-only key value.
Description check ✅ Passed The description directly explains the provider-key detection bug, the implementation changes, test coverage, and verification results.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/release-1153-provider-key-presence

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai

coderabbitai Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor
⚠️ Action not completed

Already reviewed the last commit. Use @coderabbitai full review to rerun a review of the entire changeset.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@mmabrouk

mmabrouk commented Sep 8, 2026

Copy link
Copy Markdown
Member Author

Reviews on this diff.

Codex, extra-high effort, on this branch off the current release head: "Ship it as the Model-badge fix. No actionable findings." It checked the four things worth checking after the split. The commit sits directly on 3ded1f9ddb and depends on nothing from the dropped work. The comment at the needsProviderKey return site is accurate, since both composers key off gateActive rather than this rule. The test assertions still hold, including explicit hasKey: false overriding a lingering value. And no other live presence check was left behind: the remaining raw-value reads serve credential input, migration or previews.

CodeRabbit: no actionable comments.

An earlier Codex pass reviewed the same rule inside the larger branch and asked for three changes, all of which are in this commit: the name shouldPromptForProviderKey, the normalized ConnectionMode, and the stale-value test case. It also corrected two claims I had made, which is why the test fixtures now describe what redaction really does to a write-only row.

For anyone reading the history: four further commits exist on fix/release-1153-provider-key-banner at b2c1160550. They harden candidate resolution against an empty harness catalog and against a subscription answer that could not be read. They were written for a symptom that turned out to be a measurement error, so they are held without a PR rather than shipped here.

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Railway Preview Environment

Status Destroyed (PR closed)

Updated at 2026-09-08T20:38:48.905Z

@mmabrouk
mmabrouk merged commit 1bfaa4d into release/v0.115.3 Sep 8, 2026
53 of 54 checks passed
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