Repository navigation
Put the fixes first in the cross-organization missing-key error #9684
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
0d7d87d
5896577
7796fa1
2ba0fb3
8b7fe04
8b1f03e
9915f87
463f6c6
18ec3da
077edc0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@agent-native/core": patch | ||
| --- | ||
|
|
||
| When a provider key is saved in another organization the person also belongs to, the missing-key error now opens with its two fixes (save the key in this organization, or switch to the one holding it) and explains after, with the organization's name after both fixes. Neither that explanation nor the one for a key saved only as someone's Personal key repeats the key any more, and a provider that needs one specific key now words an explained miss the way the any-key error does, "<provider> credential not configured. <explanation> Tried: <key>". Together these keep the fixes in a stop's one-line reason however long the key and organization names are. When that organization's name can't be read, the message no longer says "the another organization". |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -87,12 +87,12 @@ | |
| credential?.connectionId !== endpoint.connectionId) | ||
| ) { | ||
| throw new CredentialEndpointMismatchError( | ||
| `Refusing to send ${key ? `\"${key}\"` : "a credential"} to a workspace connection unless it is bound to that exact connection.`, | ||
|
Check warning on line 90 in packages/core/src/credentials/index.ts
|
||
| ); | ||
| } | ||
| if (endpoint.scope === "unknown") { | ||
| throw new CredentialEndpointMismatchError( | ||
| `Refusing to send ${key ? `\"${key}\"` : "a credential"} to an endpoint with unknown ownership.`, | ||
|
Check warning on line 95 in packages/core/src/credentials/index.ts
|
||
| ); | ||
| } | ||
| const soloWorkspaceEndpoint = | ||
|
|
@@ -110,7 +110,7 @@ | |
| if (credentialBelongsToEndpointUser) return; | ||
|
|
||
| throw new CredentialEndpointMismatchError( | ||
| `Refusing to send ${key ? `\"${key}\"` : "a credential"} to a user-controlled endpoint unless it is saved by the same user.`, | ||
|
Check warning on line 113 in packages/core/src/credentials/index.ts
|
||
| ); | ||
| } | ||
|
|
||
|
|
@@ -122,7 +122,7 @@ | |
| if (credentialBelongsToEndpointWorkspace) return; | ||
|
|
||
| throw new CredentialEndpointMismatchError( | ||
| `Refusing to send ${key ? `\"${key}\"` : "a credential"} to a shared endpoint unless it is saved by the same organization or workspace.`, | ||
|
Check warning on line 125 in packages/core/src/credentials/index.ts
|
||
| ); | ||
| } | ||
| } | ||
|
|
@@ -395,12 +395,19 @@ | |
| * channel) and whether Settings lets a member save that key as Personal | ||
| * are both unknown here, so "the integration did it" and "save your own" | ||
| * are each wrong for some runs. The fix comes first, so a chat stop's | ||
| * 240-character headline keeps it for every key name. | ||
| * 240-character headline keeps it. | ||
| * - The key is saved in a DIFFERENT organization the caller also belongs to. | ||
| * Credentials are per-organization, so gaining a second organization (or | ||
| * having `active-org-id` repointed at one) orphans every key synced under | ||
| * the first. Without this, the only symptom is a missing-env-var error that | ||
| * names the key rather than the org mismatch that actually caused it. | ||
| * names the key rather than the org mismatch that actually caused it. Its | ||
| * two fixes come first too, so the same headline keeps both. The | ||
| * organization's name has no length limit, so it comes after both fixes, | ||
| * where a long one is all the cut can drop. | ||
| * | ||
| * Neither message names the key, whose name has no length limit either: | ||
| * both callers' sentence before it already names what's missing, and their | ||
| * "Tried:" list after it names the keys. | ||
| * | ||
| * SECURITY: both probes are bounded to organizations the caller is a member | ||
| * of, report only the scope kind (and, for the cross-org case, the name of an | ||
|
|
@@ -441,8 +448,8 @@ | |
| for (const key of keys) { | ||
| if (await hasForeignPersonalCredentialInOrg(key, scopedCtx)) { | ||
| return ( | ||
| `Ask an organization owner or admin to save "${key}" with ` + | ||
| `Workspace or Organization scope. This workspace has it only as a ` + | ||
| `Ask an organization owner or admin to save it with Workspace or ` + | ||
| `Organization scope. This workspace has it only as a ` + | ||
| `Personal key, which works only for the member who saved it.` | ||
| ); | ||
| } | ||
|
|
@@ -451,13 +458,11 @@ | |
| ? null | ||
| : await findMemberOrgHoldingCredential(key, scopedCtx); | ||
| if (holder) { | ||
| const target = holder.name ? `"${holder.name}", where` : "one where"; | ||
| return ( | ||
| `A "${key}" key is saved in the ${holder} organization, but this ` + | ||
| `request resolved to a different organization you also belong to. ` + | ||
| `Credentials are scoped per organization and are not shared between ` + | ||
| `them, so this is an organization mismatch rather than a missing key. ` + | ||
| `Either switch your active organization back to ${holder}, or save ` + | ||
| `"${key}" in the organization this request runs in.` | ||
| `Save it in this organization, or switch your active organization ` + | ||
|
builder-io-integration[bot] marked this conversation as resolved.
Resolved
Comment on lines
+461
to
+463
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Long organization names can hide the switch destinationThe organization name is still part of this recovery sentence and the stop headline is capped at 240 characters. For sufficiently long names the headline can retain “switch your active organization” but truncate the destination, so the user cannot tell which organization to select; please define bounded headline behavior and add a test with a name longer than the available budget.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Covered in 077edc0. The headline's behavior for a long name is already bounded by its cut: both fixes always come first, then as much of the name as fits, cut at a word with "…". The new stop-headline case uses a 175-character organization name, past the budget, and the headline ends Shortening the name in the message itself would cost the full name in the error, which is where a person reads it in full, so the name stays whole there. |
||
| `to ${target} it's saved. Credentials aren't shared between ` + | ||
| `organizations.` | ||
| ); | ||
| } | ||
| } | ||
|
|
@@ -489,7 +494,7 @@ | |
| async function findMemberOrgHoldingCredential( | ||
| key: string, | ||
| ctx: CredentialContext, | ||
| ): Promise<string | null> { | ||
| ): Promise<{ name: string | null } | null> { | ||
| try { | ||
| const { rows } = await getDbExec().execute({ | ||
| sql: `SELECT o.name AS org_name | ||
|
|
@@ -506,9 +511,9 @@ | |
| }); | ||
| if (rows.length === 0) return null; | ||
| const name = (rows[0] as { org_name?: unknown }).org_name; | ||
| return typeof name === "string" && name.trim() | ||
| ? `"${name.trim()}"` | ||
| : "another"; | ||
| return { | ||
| name: typeof name === "string" && name.trim() ? name.trim() : null, | ||
| }; | ||
| } catch { | ||
| return null; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Personal-key advice does not identify the matched key
The scope-gap probe returns on the first matching key, but this message no longer names it. For providers with multiple fallback keys,
Tried:lists all candidates without showing which one is Personal-only, so the user cannot tell which key an organization owner should save with shared scope; please preserve the matched-key identity and cover a multi-key case.