From 0d7d87d9863748e85df09b92258b1b602643926e Mon Sep 17 00:00:00 2001 From: 3mdistal <86723305+3mdistal@users.noreply.github.com> Date: Mon, 23 Nov 2026 07:49:53 -0500 Subject: [PATCH 01/11] Put the fixes first in the cross-organization missing-key message --- .changeset/cross-org-key-fix-first.md | 5 +++++ .../core/src/agent/production-agent.spec.ts | 16 ++++++++++++++ packages/core/src/credentials/index.ts | 22 +++++++++---------- .../core/src/credentials/scope-gap.spec.ts | 14 +++++++----- 4 files changed, 40 insertions(+), 17 deletions(-) create mode 100644 .changeset/cross-org-key-fix-first.md diff --git a/.changeset/cross-org-key-fix-first.md b/.changeset/cross-org-key-fix-first.md new file mode 100644 index 00000000000..5baeae7882f --- /dev/null +++ b/.changeset/cross-org-key-fix-first.md @@ -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 (switch the active organization to the one holding the key, or save the key in this one) and explains after, so a stop's one-line reason keeps both fixes even with long key and organization names. When that organization's name can't be read, the message no longer says "the another organization". diff --git a/packages/core/src/agent/production-agent.spec.ts b/packages/core/src/agent/production-agent.spec.ts index 6d353a2bb7b..e37cd761f50 100644 --- a/packages/core/src/agent/production-agent.spec.ts +++ b/packages/core/src/agent/production-agent.spec.ts @@ -18530,6 +18530,22 @@ describe("runAgentLoop", () => { 'save "GOOGLE_APPLICATION_CREDENTIALS_JSON" with Workspace or ' + "Organization scope. That needs to be fixed outside this chat", }, + { + label: + "keeps both cross-organization fixes when a long key and organization name push the cause past the limit", + thrown: + "bigquery credential not configured. Switch your active organization " + + 'to "Builder.io Developer Relations and Community Programs", where ' + + '"GOOGLE_APPLICATION_CREDENTIALS_JSON" is saved, or save it in this ' + + "organization. Credentials aren't shared between organizations. " + + "Tried: BIGQUERY_PROJECT_ID, GOOGLE_APPLICATION_CREDENTIALS_JSON", + headline: + "I stopped because github-repo-list-files can't run yet: bigquery " + + "credential not configured. Switch your active organization to " + + '"Builder.io Developer Relations and Community Programs", where ' + + '"GOOGLE_APPLICATION_CREDENTIALS_JSON" is saved, or save it in this ' + + "organization. That needs to be fixed outside this chat", + }, ])("$label in the stop headline", async ({ thrown, headline }) => { let streamCalls = 0; const run = vi.fn(async () => { diff --git a/packages/core/src/credentials/index.ts b/packages/core/src/credentials/index.ts index 586f55f54b8..523e58c762c 100644 --- a/packages/core/src/credentials/index.ts +++ b/packages/core/src/credentials/index.ts @@ -400,7 +400,9 @@ export async function resolveCredential( * 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, ahead of the explanation, so the same + * headline keeps both. * * 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 @@ -451,13 +453,11 @@ export async function describeCredentialScopeGap( ? 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.` + `Switch your active organization to ${target} "${key}" is saved, ` + + `or save it in this organization. Credentials aren't shared between ` + + `organizations.` ); } } @@ -489,7 +489,7 @@ async function hasForeignPersonalCredentialInOrg( async function findMemberOrgHoldingCredential( key: string, ctx: CredentialContext, -): Promise { +): Promise<{ name: string | null } | null> { try { const { rows } = await getDbExec().execute({ sql: `SELECT o.name AS org_name @@ -506,9 +506,9 @@ async function findMemberOrgHoldingCredential( }); 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; } diff --git a/packages/core/src/credentials/scope-gap.spec.ts b/packages/core/src/credentials/scope-gap.spec.ts index 3b359ab15c3..5e544b28ece 100644 --- a/packages/core/src/credentials/scope-gap.spec.ts +++ b/packages/core/src/credentials/scope-gap.spec.ts @@ -183,7 +183,7 @@ describe("describeCredentialScopeGap across organizations", () => { resolveOrgIdForEmailResult = null; }); - it("names the organization holding the key and the mismatch as the cause", async () => { + it("leads with both fixes, naming the organization holding the key, then the cause", async () => { onlyAnotherMemberOrgHasKey("Builder.io"); const message = await describeCredentialScopeGap( @@ -191,10 +191,10 @@ describe("describeCredentialScopeGap across organizations", () => { { userEmail: "tim@example.com", orgId: "coach-org" }, ); - expect(message).toContain("ACADEMY_CONVEX_SITE_URL"); - expect(message).toContain('"Builder.io" organization'); - expect(message).toContain( - "organization mismatch rather than a missing key", + expect(message).toBe( + 'Switch your active organization to "Builder.io", where ' + + '"ACADEMY_CONVEX_SITE_URL" is saved, or save it in this ' + + "organization. Credentials aren't shared between organizations.", ); }); @@ -226,7 +226,9 @@ describe("describeCredentialScopeGap across organizations", () => { orgId: "org-1", }); - expect(message).toContain("another organization"); + expect(message).toMatch( + /^Switch your active organization to one where "STRIPE_SECRET_KEY" is saved, or save it in this organization\. /, + ); expect(message).not.toContain("org-1"); }); From 589657769935ff4d88a2d16fbfc5b0a32445f9c4 Mon Sep 17 00:00:00 2001 From: 3mdistal <86723305+3mdistal@users.noreply.github.com> Date: Mon, 23 Nov 2026 07:59:02 -0500 Subject: [PATCH 02/11] Name why the scope-gap test's assertions changed --- packages/core/src/credentials/scope-gap.spec.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/core/src/credentials/scope-gap.spec.ts b/packages/core/src/credentials/scope-gap.spec.ts index 5e544b28ece..8a5052a19dc 100644 --- a/packages/core/src/credentials/scope-gap.spec.ts +++ b/packages/core/src/credentials/scope-gap.spec.ts @@ -191,6 +191,7 @@ describe("describeCredentialScopeGap across organizations", () => { { userEmail: "tim@example.com", orgId: "coach-org" }, ); + // oracle-change: the message was reworded fix-first; one exact match replaces three partial matches on the old wording expect(message).toBe( 'Switch your active organization to "Builder.io", where ' + '"ACADEMY_CONVEX_SITE_URL" is saved, or save it in this ' + From 7796fa1be758da056328e0b32093b0ba8f3d022d Mon Sep 17 00:00:00 2001 From: 3mdistal <86723305+3mdistal@users.noreply.github.com> Date: Mon, 23 Nov 2026 08:09:16 -0500 Subject: [PATCH 03/11] Name the scope-gap spec after the module so the changed-lines mutation check runs it --- .../credentials/{scope-gap.spec.ts => index.scope-gap.spec.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename packages/core/src/credentials/{scope-gap.spec.ts => index.scope-gap.spec.ts} (100%) diff --git a/packages/core/src/credentials/scope-gap.spec.ts b/packages/core/src/credentials/index.scope-gap.spec.ts similarity index 100% rename from packages/core/src/credentials/scope-gap.spec.ts rename to packages/core/src/credentials/index.scope-gap.spec.ts From 2ba0fb3152da04f6d1c722b2cd2d261b6a1accd9 Mon Sep 17 00:00:00 2001 From: 3mdistal <86723305+3mdistal@users.noreply.github.com> Date: Mon, 23 Nov 2026 08:54:07 -0500 Subject: [PATCH 04/11] Put the organization name after both fixes so a long one can't push a fix out of the headline --- .changeset/cross-org-key-fix-first.md | 2 +- .../core/src/agent/production-agent.spec.ts | 35 ++++++++++++++----- .../src/credentials/index.scope-gap.spec.ts | 19 +++++++--- packages/core/src/credentials/index.ts | 9 ++--- 4 files changed, 48 insertions(+), 17 deletions(-) diff --git a/.changeset/cross-org-key-fix-first.md b/.changeset/cross-org-key-fix-first.md index 5baeae7882f..ecd8e9e050a 100644 --- a/.changeset/cross-org-key-fix-first.md +++ b/.changeset/cross-org-key-fix-first.md @@ -2,4 +2,4 @@ "@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 (switch the active organization to the one holding the key, or save the key in this one) and explains after, so a stop's one-line reason keeps both fixes even with long key and organization names. When that organization's name can't be read, the message no longer says "the another organization". +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. The organization's name comes after both fixes, so a stop's one-line reason keeps them 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". diff --git a/packages/core/src/agent/production-agent.spec.ts b/packages/core/src/agent/production-agent.spec.ts index e37cd761f50..6d329243a16 100644 --- a/packages/core/src/agent/production-agent.spec.ts +++ b/packages/core/src/agent/production-agent.spec.ts @@ -18534,17 +18534,36 @@ describe("runAgentLoop", () => { label: "keeps both cross-organization fixes when a long key and organization name push the cause past the limit", thrown: - "bigquery credential not configured. Switch your active organization " + + 'bigquery credential not configured. Save "GOOGLE_APPLICATION_' + + 'CREDENTIALS_JSON" in this organization, or switch your active ' + + 'organization to "Builder.io Developer Relations and Community ' + + "Programs\", where it's saved. Credentials aren't shared between " + + "organizations. Tried: BIGQUERY_PROJECT_ID, " + + "GOOGLE_APPLICATION_CREDENTIALS_JSON", + headline: + "I stopped because github-repo-list-files can't run yet: bigquery " + + 'credential not configured. Save "GOOGLE_APPLICATION_CREDENTIALS_' + + 'JSON" in this organization, or switch your active organization ' + 'to "Builder.io Developer Relations and Community Programs", where ' + - '"GOOGLE_APPLICATION_CREDENTIALS_JSON" is saved, or save it in this ' + - "organization. Credentials aren't shared between organizations. " + - "Tried: BIGQUERY_PROJECT_ID, GOOGLE_APPLICATION_CREDENTIALS_JSON", + "it's saved. That needs to be fixed outside this chat", + }, + { + label: + "keeps both cross-organization fixes when an organization name of any length runs past the limit", + thrown: + 'bigquery credential not configured. Save "GOOGLE_APPLICATION_' + + 'CREDENTIALS_JSON" in this organization, or switch your active ' + + 'organization to "The Builder.io Developer Relations, Community ' + + "Programs and Open Source Partnerships Working Group for the " + + "Americas and Europe\", where it's saved. Credentials aren't shared " + + "between organizations. Tried: GOOGLE_APPLICATION_CREDENTIALS_JSON", headline: "I stopped because github-repo-list-files can't run yet: bigquery " + - "credential not configured. Switch your active organization to " + - '"Builder.io Developer Relations and Community Programs", where ' + - '"GOOGLE_APPLICATION_CREDENTIALS_JSON" is saved, or save it in this ' + - "organization. That needs to be fixed outside this chat", + 'credential not configured. Save "GOOGLE_APPLICATION_CREDENTIALS_' + + 'JSON" in this organization, or switch your active organization ' + + 'to "The Builder.io Developer Relations, Community Programs and ' + + "Open Source Partnerships Working Group… That needs to be fixed " + + "outside this chat", }, ])("$label in the stop headline", async ({ thrown, headline }) => { let streamCalls = 0; diff --git a/packages/core/src/credentials/index.scope-gap.spec.ts b/packages/core/src/credentials/index.scope-gap.spec.ts index 8a5052a19dc..bbcb15aac4a 100644 --- a/packages/core/src/credentials/index.scope-gap.spec.ts +++ b/packages/core/src/credentials/index.scope-gap.spec.ts @@ -193,12 +193,23 @@ describe("describeCredentialScopeGap across organizations", () => { // oracle-change: the message was reworded fix-first; one exact match replaces three partial matches on the old wording expect(message).toBe( - 'Switch your active organization to "Builder.io", where ' + - '"ACADEMY_CONVEX_SITE_URL" is saved, or save it in this ' + - "organization. Credentials aren't shared between organizations.", + 'Save "ACADEMY_CONVEX_SITE_URL" in this organization, or switch your ' + + 'active organization to "Builder.io", where it\'s saved. ' + + "Credentials aren't shared between organizations.", ); }); + it("trims the organization's name", async () => { + onlyAnotherMemberOrgHasKey(" Builder.io "); + + const message = await describeCredentialScopeGap(["GITHUB_TOKEN"], { + userEmail: "owner@example.com", + orgId: "org-1", + }); + + expect(message).toContain('organization to "Builder.io", where'); + }); + it("bounds the probe to the caller's own memberships and excludes the active org", async () => { onlyAnotherMemberOrgHasKey("Builder.io"); @@ -228,7 +239,7 @@ describe("describeCredentialScopeGap across organizations", () => { }); expect(message).toMatch( - /^Switch your active organization to one where "STRIPE_SECRET_KEY" is saved, or save it in this organization\. /, + /^Save "STRIPE_SECRET_KEY" in this organization, or switch your active organization to one where it's saved\. /, ); expect(message).not.toContain("org-1"); }); diff --git a/packages/core/src/credentials/index.ts b/packages/core/src/credentials/index.ts index 523e58c762c..9c571e65dca 100644 --- a/packages/core/src/credentials/index.ts +++ b/packages/core/src/credentials/index.ts @@ -402,7 +402,8 @@ export async function resolveCredential( * 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. Its * two fixes come first too, ahead of the explanation, so the same - * headline keeps both. + * 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. * * 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 @@ -455,9 +456,9 @@ export async function describeCredentialScopeGap( if (holder) { const target = holder.name ? `"${holder.name}", where` : "one where"; return ( - `Switch your active organization to ${target} "${key}" is saved, ` + - `or save it in this organization. Credentials aren't shared between ` + - `organizations.` + `Save "${key}" in this organization, or switch your active ` + + `organization to ${target} it's saved. Credentials aren't shared ` + + `between organizations.` ); } } From 8b7fe04c679381d29a705a0676ba7dccdf48f6b3 Mon Sep 17 00:00:00 2001 From: 3mdistal <86723305+3mdistal@users.noreply.github.com> Date: Mon, 23 Nov 2026 10:15:26 -0500 Subject: [PATCH 05/11] Leave the key unnamed in the cross-organization fixes so a long one can't push a fix out of the headline --- .changeset/cross-org-key-fix-first.md | 2 +- .../core/src/agent/production-agent.spec.ts | 57 ++++++++++++------- .../src/credentials/index.scope-gap.spec.ts | 10 ++-- packages/core/src/credentials/index.ts | 13 +++-- 4 files changed, 51 insertions(+), 31 deletions(-) diff --git a/.changeset/cross-org-key-fix-first.md b/.changeset/cross-org-key-fix-first.md index ecd8e9e050a..fa3306f0e9a 100644 --- a/.changeset/cross-org-key-fix-first.md +++ b/.changeset/cross-org-key-fix-first.md @@ -2,4 +2,4 @@ "@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. The organization's name comes after both fixes, so a stop's one-line reason keeps them 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". +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. The error's opening sentence already names the missing key, so the fixes don't repeat it, and the organization's name comes after both fixes, so a stop's one-line reason keeps them 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". diff --git a/packages/core/src/agent/production-agent.spec.ts b/packages/core/src/agent/production-agent.spec.ts index 6d329243a16..9c1a7ce18e7 100644 --- a/packages/core/src/agent/production-agent.spec.ts +++ b/packages/core/src/agent/production-agent.spec.ts @@ -18532,39 +18532,56 @@ describe("runAgentLoop", () => { }, { label: - "keeps both cross-organization fixes when a long key and organization name push the cause past the limit", + "keeps the whole cross-organization explanation with the longest key name and a long organization name", thrown: - 'bigquery credential not configured. Save "GOOGLE_APPLICATION_' + - 'CREDENTIALS_JSON" in this organization, or switch your active ' + - 'organization to "Builder.io Developer Relations and Community ' + - "Programs\", where it's saved. Credentials aren't shared between " + - "organizations. Tried: BIGQUERY_PROJECT_ID, " + + "bigquery credential not configured. Save it in this organization, " + + "or switch your active organization to \"Builder.io Developer " + + "Relations and Community Programs\", where it's saved. Credentials " + + "aren't shared between organizations. Tried: BIGQUERY_PROJECT_ID, " + "GOOGLE_APPLICATION_CREDENTIALS_JSON", headline: "I stopped because github-repo-list-files can't run yet: bigquery " + - 'credential not configured. Save "GOOGLE_APPLICATION_CREDENTIALS_' + - 'JSON" in this organization, or switch your active organization ' + - 'to "Builder.io Developer Relations and Community Programs", where ' + - "it's saved. That needs to be fixed outside this chat", + "credential not configured. Save it in this organization, or " + + 'switch your active organization to "Builder.io Developer ' + + "Relations and Community Programs\", where it's saved. Credentials " + + "aren't shared between organizations. That needs to be fixed " + + "outside this chat", }, { label: "keeps both cross-organization fixes when an organization name of any length runs past the limit", thrown: - 'bigquery credential not configured. Save "GOOGLE_APPLICATION_' + - 'CREDENTIALS_JSON" in this organization, or switch your active ' + - 'organization to "The Builder.io Developer Relations, Community ' + - "Programs and Open Source Partnerships Working Group for the " + - "Americas and Europe\", where it's saved. Credentials aren't shared " + - "between organizations. Tried: GOOGLE_APPLICATION_CREDENTIALS_JSON", + "bigquery credential not configured. Save it in this organization, " + + 'or switch your active organization to "The Builder.io Developer ' + + "Relations, Community Programs and Open Source Partnerships Working " + + "Group for the Americas and Europe\", where it's saved. Credentials " + + "aren't shared between organizations. Tried: " + + "GOOGLE_APPLICATION_CREDENTIALS_JSON", headline: "I stopped because github-repo-list-files can't run yet: bigquery " + - 'credential not configured. Save "GOOGLE_APPLICATION_CREDENTIALS_' + - 'JSON" in this organization, or switch your active organization ' + - 'to "The Builder.io Developer Relations, Community Programs and ' + - "Open Source Partnerships Working Group… That needs to be fixed " + + "credential not configured. Save it in this organization, or " + + 'switch your active organization to "The Builder.io Developer ' + + "Relations, Community Programs and Open Source Partnerships Working " + + 'Group for the Americas and Europe", where… That needs to be fixed ' + "outside this chat", }, + { + label: + "keeps both cross-organization fixes however long the credential key is", + thrown: + "acme-warehouse credential not configured. Save it in this " + + "organization, or switch your active organization to " + + "\"Builder.io\", where it's saved. Credentials aren't shared " + + "between organizations. Tried: ACME_" + + "WAREHOUSE_ANALYTICS_EXPORT_".repeat(5) + + "SERVICE_ACCOUNT_TOKEN", + headline: + "I stopped because github-repo-list-files can't run yet: " + + "acme-warehouse credential not configured. Save it in this " + + "organization, or switch your active organization to " + + "\"Builder.io\", where it's saved. Credentials aren't shared " + + "between organizations. That needs to be fixed outside this chat", + }, ])("$label in the stop headline", async ({ thrown, headline }) => { let streamCalls = 0; const run = vi.fn(async () => { diff --git a/packages/core/src/credentials/index.scope-gap.spec.ts b/packages/core/src/credentials/index.scope-gap.spec.ts index bbcb15aac4a..2824b41de17 100644 --- a/packages/core/src/credentials/index.scope-gap.spec.ts +++ b/packages/core/src/credentials/index.scope-gap.spec.ts @@ -183,7 +183,7 @@ describe("describeCredentialScopeGap across organizations", () => { resolveOrgIdForEmailResult = null; }); - it("leads with both fixes, naming the organization holding the key, then the cause", async () => { + it("leads with both fixes, naming the organization holding the key but not the key, then the cause", async () => { onlyAnotherMemberOrgHasKey("Builder.io"); const message = await describeCredentialScopeGap( @@ -193,9 +193,9 @@ describe("describeCredentialScopeGap across organizations", () => { // oracle-change: the message was reworded fix-first; one exact match replaces three partial matches on the old wording expect(message).toBe( - 'Save "ACADEMY_CONVEX_SITE_URL" in this organization, or switch your ' + - 'active organization to "Builder.io", where it\'s saved. ' + - "Credentials aren't shared between organizations.", + "Save it in this organization, or switch your active organization " + + 'to "Builder.io", where it\'s saved. Credentials aren\'t shared ' + + "between organizations.", ); }); @@ -239,7 +239,7 @@ describe("describeCredentialScopeGap across organizations", () => { }); expect(message).toMatch( - /^Save "STRIPE_SECRET_KEY" in this organization, or switch your active organization to one where it's saved\. /, + /^Save it in this organization, or switch your active organization to one where it's saved\. /, ); expect(message).not.toContain("org-1"); }); diff --git a/packages/core/src/credentials/index.ts b/packages/core/src/credentials/index.ts index 9c571e65dca..57e776d56cd 100644 --- a/packages/core/src/credentials/index.ts +++ b/packages/core/src/credentials/index.ts @@ -402,8 +402,11 @@ export async function resolveCredential( * 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. Its * two fixes come first too, ahead of the explanation, 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. + * headline keeps both. Key and organization names have no length limit, + * so neither comes before the second fix: the key goes unnamed, as "it", + * because both callers' sentence before this one already names what's + * missing, and the organization's name comes after both fixes, where a + * long one is all the cut can drop. * * 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 @@ -456,9 +459,9 @@ export async function describeCredentialScopeGap( if (holder) { const target = holder.name ? `"${holder.name}", where` : "one where"; return ( - `Save "${key}" in this organization, or switch your active ` + - `organization to ${target} it's saved. Credentials aren't shared ` + - `between organizations.` + `Save it in this organization, or switch your active organization ` + + `to ${target} it's saved. Credentials aren't shared between ` + + `organizations.` ); } } From 8b1f03ee03f6e4131299c166cbfb805d1c0f64c2 Mon Sep 17 00:00:00 2001 From: 3mdistal <86723305+3mdistal@users.noreply.github.com> Date: Mon, 23 Nov 2026 10:24:12 -0500 Subject: [PATCH 06/11] Format the updated message tests --- packages/core/src/agent/production-agent.spec.ts | 2 +- packages/core/src/credentials/index.scope-gap.spec.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/core/src/agent/production-agent.spec.ts b/packages/core/src/agent/production-agent.spec.ts index 9c1a7ce18e7..39e47de764e 100644 --- a/packages/core/src/agent/production-agent.spec.ts +++ b/packages/core/src/agent/production-agent.spec.ts @@ -18535,7 +18535,7 @@ describe("runAgentLoop", () => { "keeps the whole cross-organization explanation with the longest key name and a long organization name", thrown: "bigquery credential not configured. Save it in this organization, " + - "or switch your active organization to \"Builder.io Developer " + + 'or switch your active organization to "Builder.io Developer ' + "Relations and Community Programs\", where it's saved. Credentials " + "aren't shared between organizations. Tried: BIGQUERY_PROJECT_ID, " + "GOOGLE_APPLICATION_CREDENTIALS_JSON", diff --git a/packages/core/src/credentials/index.scope-gap.spec.ts b/packages/core/src/credentials/index.scope-gap.spec.ts index 2824b41de17..90e4449860d 100644 --- a/packages/core/src/credentials/index.scope-gap.spec.ts +++ b/packages/core/src/credentials/index.scope-gap.spec.ts @@ -194,7 +194,7 @@ describe("describeCredentialScopeGap across organizations", () => { // oracle-change: the message was reworded fix-first; one exact match replaces three partial matches on the old wording expect(message).toBe( "Save it in this organization, or switch your active organization " + - 'to "Builder.io", where it\'s saved. Credentials aren\'t shared ' + + "to \"Builder.io\", where it's saved. Credentials aren't shared " + "between organizations.", ); }); From 9915f871b6ff95cf90a4c8bce7904050465da25a Mon Sep 17 00:00:00 2001 From: 3mdistal <86723305+3mdistal@users.noreply.github.com> Date: Mon, 23 Nov 2026 11:01:38 -0500 Subject: [PATCH 07/11] Put a required key after the explanation so a long one can't crowd out the fixes --- .changeset/cross-org-key-fix-first.md | 2 +- packages/core/src/provider-api/index.spec.ts | 26 ++++++++++++++++++++ packages/core/src/provider-api/index.ts | 7 +++++- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/.changeset/cross-org-key-fix-first.md b/.changeset/cross-org-key-fix-first.md index fa3306f0e9a..7fc9841fccf 100644 --- a/.changeset/cross-org-key-fix-first.md +++ b/.changeset/cross-org-key-fix-first.md @@ -2,4 +2,4 @@ "@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. The error's opening sentence already names the missing key, so the fixes don't repeat it, and the organization's name comes after both fixes, so a stop's one-line reason keeps them 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". +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. The fixes don't repeat the key, and the organization's name comes after both of them. A provider that needs one specific key now words an explained miss the way the any-key error does, " credential not configured. Tried: ", so the key comes last there too. Together these keep both 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". diff --git a/packages/core/src/provider-api/index.spec.ts b/packages/core/src/provider-api/index.spec.ts index 4eb32472268..f22516f4de4 100644 --- a/packages/core/src/provider-api/index.spec.ts +++ b/packages/core/src/provider-api/index.spec.ts @@ -4670,6 +4670,32 @@ describe("provider API runtime", () => { ); }); + it("puts a single required key after the explanation, as the any-key error does", async () => { + resolveCredential.mockResolvedValue(null); + describeCredentialScopeGap.mockResolvedValue( + "Save it in this organization, or switch your active organization " + + 'to "Builder.io", where it\'s saved.', + ); + const runtime = createProviderApiRuntime({ + appId: "analytics", + providerIds: ["apollo"], + getCredentialContext: () => credentialContext, + }); + + const error = await runtime + .executeRequest({ provider: "apollo", path: "/v1/auth/health" }) + .then( + () => null, + (err: Error) => err, + ); + + expect(error?.message).toBe( + "apollo credential not configured. Save it in this organization, or " + + 'switch your active organization to "Builder.io", where it\'s saved. ' + + "Tried: APOLLO_API_KEY", + ); + }); + it("gives no shared-key advice when the selected connection lacks the key", async () => { describeCredentialScopeGap.mockResolvedValue("SAVE A SHARED KEY"); resolveWorkspaceConnectionForApp.mockResolvedValue({ diff --git a/packages/core/src/provider-api/index.ts b/packages/core/src/provider-api/index.ts index 95837a18754..bf7793a707a 100644 --- a/packages/core/src/provider-api/index.ts +++ b/packages/core/src/provider-api/index.ts @@ -5168,8 +5168,13 @@ async function resolveRequiredCredential(options: { message: `${options.provider} requires an available workspace connection.`, }); } + // Key names have no length limit, so an explanation's key goes last, as in + // resolveAnyCredential: a long one can't push the explanation's fixes out + // of a chat stop's one-line headline. throw new Error( - `${options.key} not configured${scopeGap ? `. ${scopeGap}` : ""}`, + scopeGap + ? `${options.provider} credential not configured. ${scopeGap} Tried: ${options.key}` + : `${options.key} not configured`, ); } From 463f6c618bb5c11a5ecc57c7f876114e84ef2d02 Mon Sep 17 00:00:00 2001 From: 3mdistal <86723305+3mdistal@users.noreply.github.com> Date: Mon, 23 Nov 2026 12:00:16 -0500 Subject: [PATCH 08/11] Leave the key unnamed in the Personal-key fix too, and drop a prose comment the guard rejects --- .changeset/cross-org-key-fix-first.md | 2 +- .../core/src/agent/production-agent.spec.ts | 38 ++++++++++--------- .../src/credentials/index.scope-gap.spec.ts | 6 +-- packages/core/src/credentials/index.ts | 19 +++++----- packages/core/src/provider-api/index.spec.ts | 7 ++-- packages/core/src/provider-api/index.ts | 3 -- 6 files changed, 37 insertions(+), 38 deletions(-) diff --git a/.changeset/cross-org-key-fix-first.md b/.changeset/cross-org-key-fix-first.md index 7fc9841fccf..404c71caec4 100644 --- a/.changeset/cross-org-key-fix-first.md +++ b/.changeset/cross-org-key-fix-first.md @@ -2,4 +2,4 @@ "@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. The fixes don't repeat the key, and the organization's name comes after both of them. A provider that needs one specific key now words an explained miss the way the any-key error does, " credential not configured. Tried: ", so the key comes last there too. Together these keep both 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". +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, " credential not configured. Tried: ". 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". diff --git a/packages/core/src/agent/production-agent.spec.ts b/packages/core/src/agent/production-agent.spec.ts index 39e47de764e..4b6e8a6d7be 100644 --- a/packages/core/src/agent/production-agent.spec.ts +++ b/packages/core/src/agent/production-agent.spec.ts @@ -18503,32 +18503,34 @@ describe("runAgentLoop", () => { label: "keeps the longest missing-key error's fix and drops its key list", thrown: "hubspot credential not configured. Ask an organization owner or " + - 'admin to save "HUBSPOT_PRIVATE_APP_TOKEN" with Workspace or ' + - "Organization scope. This workspace has it only as a Personal key, " + - "which works only for the member who saved it. Tried: " + - "HUBSPOT_PRIVATE_APP_TOKEN, HUBSPOT_ACCESS_TOKEN", + "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. Tried: HUBSPOT_PRIVATE_APP_TOKEN, " + + "HUBSPOT_ACCESS_TOKEN", headline: "I stopped because github-repo-list-files can't run yet: hubspot " + "credential not configured. Ask an organization owner or admin to " + - 'save "HUBSPOT_PRIVATE_APP_TOKEN" with Workspace or Organization ' + - "scope. This workspace has it only as a Personal key, which works " + - "only for the member who saved it. That needs to be fixed outside " + - "this chat", + "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. That needs to be fixed outside this chat", }, { label: - "keeps the fix and drops the cause when the longest key name pushes the cause past the limit", + "keeps the whole Personal-key explanation however long the credential key is", thrown: - "bigquery credential not configured. Ask an organization owner or " + - 'admin to save "GOOGLE_APPLICATION_CREDENTIALS_JSON" with Workspace ' + - "or Organization scope. This workspace has it only as a Personal " + - "key, which works only for the member who saved it. Tried: " + - "BIGQUERY_PROJECT_ID, GOOGLE_APPLICATION_CREDENTIALS_JSON", + "acme-warehouse credential not configured. 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. Tried: ACME_" + + "WAREHOUSE_ANALYTICS_EXPORT_".repeat(5) + + "SERVICE_ACCOUNT_TOKEN", headline: - "I stopped because github-repo-list-files can't run yet: bigquery " + - "credential not configured. Ask an organization owner or admin to " + - 'save "GOOGLE_APPLICATION_CREDENTIALS_JSON" with Workspace or ' + - "Organization scope. That needs to be fixed outside this chat", + "I stopped because github-repo-list-files can't run yet: " + + "acme-warehouse credential not configured. 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. That needs to be fixed outside this " + + "chat", }, { label: diff --git a/packages/core/src/credentials/index.scope-gap.spec.ts b/packages/core/src/credentials/index.scope-gap.spec.ts index 90e4449860d..1ffd4888c4a 100644 --- a/packages/core/src/credentials/index.scope-gap.spec.ts +++ b/packages/core/src/credentials/index.scope-gap.spec.ts @@ -80,9 +80,9 @@ describe("describeCredentialScopeGap", () => { ); expect(message).toBe( - 'Ask an organization owner or admin to save "GITHUB_TOKEN" with ' + - "Workspace or Organization scope. This workspace has it only as " + - "a Personal key, which works only for the member who saved it.", + "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.", ); expect(message).not.toContain("integration"); expect(message).not.toContain("Save your own"); diff --git a/packages/core/src/credentials/index.ts b/packages/core/src/credentials/index.ts index 57e776d56cd..0ba2211a625 100644 --- a/packages/core/src/credentials/index.ts +++ b/packages/core/src/credentials/index.ts @@ -395,18 +395,19 @@ export async function resolveCredential( * 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. Its - * two fixes come first too, ahead of the explanation, so the same - * headline keeps both. Key and organization names have no length limit, - * so neither comes before the second fix: the key goes unnamed, as "it", - * because both callers' sentence before this one already names what's - * missing, and the organization's name comes after both fixes, where a - * long one is all the cut can drop. + * 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 @@ -447,8 +448,8 @@ export async function describeCredentialScopeGap( 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.` ); } diff --git a/packages/core/src/provider-api/index.spec.ts b/packages/core/src/provider-api/index.spec.ts index f22516f4de4..fdf1cfc246b 100644 --- a/packages/core/src/provider-api/index.spec.ts +++ b/packages/core/src/provider-api/index.spec.ts @@ -4644,9 +4644,8 @@ describe("provider API runtime", () => { it("explains an out-of-scope credential instead of reporting it missing", async () => { resolveCredential.mockResolvedValue(null); describeCredentialScopeGap.mockResolvedValue( - 'Ask an organization owner or admin to save "HUBSPOT_ACCESS_TOKEN" ' + - "with Workspace or Organization scope. This workspace has it only " + - "as a Personal key.", + "Ask an organization owner or admin to save it with Workspace or " + + "Organization scope. This workspace has it only as a Personal key.", ); const runtime = createProviderApiRuntime({ appId: "analytics", @@ -4662,7 +4661,7 @@ describe("provider API runtime", () => { ); expect(error?.message).toMatch( - /^hubspot credential not configured\. Ask an organization owner or admin to save "HUBSPOT_ACCESS_TOKEN" .* Personal key\. Tried: \S/, + /^hubspot credential not configured\. Ask an organization owner or admin to save it .* Personal key\. Tried: \S/, ); expect(describeCredentialScopeGap).toHaveBeenCalledWith( expect.arrayContaining(["HUBSPOT_ACCESS_TOKEN"]), diff --git a/packages/core/src/provider-api/index.ts b/packages/core/src/provider-api/index.ts index bf7793a707a..36a0fbebc1c 100644 --- a/packages/core/src/provider-api/index.ts +++ b/packages/core/src/provider-api/index.ts @@ -5168,9 +5168,6 @@ async function resolveRequiredCredential(options: { message: `${options.provider} requires an available workspace connection.`, }); } - // Key names have no length limit, so an explanation's key goes last, as in - // resolveAnyCredential: a long one can't push the explanation's fixes out - // of a chat stop's one-line headline. throw new Error( scopeGap ? `${options.provider} credential not configured. ${scopeGap} Tried: ${options.key}` From 18ec3da7c83a05c817a1e47102155d2d8f1f629c Mon Sep 17 00:00:00 2001 From: 3mdistal <86723305+3mdistal@users.noreply.github.com> Date: Mon, 23 Nov 2026 12:12:30 -0500 Subject: [PATCH 09/11] Pin the single-key error without an explanation --- packages/core/src/provider-api/index.spec.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/packages/core/src/provider-api/index.spec.ts b/packages/core/src/provider-api/index.spec.ts index fdf1cfc246b..30ffd2d60d6 100644 --- a/packages/core/src/provider-api/index.spec.ts +++ b/packages/core/src/provider-api/index.spec.ts @@ -4695,6 +4695,25 @@ describe("provider API runtime", () => { ); }); + it("names a single required key alone when there's nothing to explain", async () => { + resolveCredential.mockResolvedValue(null); + describeCredentialScopeGap.mockResolvedValue(null); + const runtime = createProviderApiRuntime({ + appId: "analytics", + providerIds: ["apollo"], + getCredentialContext: () => credentialContext, + }); + + const error = await runtime + .executeRequest({ provider: "apollo", path: "/v1/auth/health" }) + .then( + () => null, + (err: Error) => err, + ); + + expect(error?.message).toBe("APOLLO_API_KEY not configured"); + }); + it("gives no shared-key advice when the selected connection lacks the key", async () => { describeCredentialScopeGap.mockResolvedValue("SAVE A SHARED KEY"); resolveWorkspaceConnectionForApp.mockResolvedValue({ From 077edc0c2999c173f9b05faf9d3043975cad9af8 Mon Sep 17 00:00:00 2001 From: 3mdistal <86723305+3mdistal@users.noreply.github.com> Date: Mon, 23 Nov 2026 13:18:47 -0500 Subject: [PATCH 10/11] Test an organization name too long for the headline --- packages/core/src/agent/production-agent.spec.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/core/src/agent/production-agent.spec.ts b/packages/core/src/agent/production-agent.spec.ts index 4b6e8a6d7be..e81dc5304ac 100644 --- a/packages/core/src/agent/production-agent.spec.ts +++ b/packages/core/src/agent/production-agent.spec.ts @@ -18551,20 +18551,20 @@ describe("runAgentLoop", () => { }, { label: - "keeps both cross-organization fixes when an organization name of any length runs past the limit", + "keeps both cross-organization fixes and the opening words of an organization name too long for the headline", thrown: "bigquery credential not configured. Save it in this organization, " + 'or switch your active organization to "The Builder.io Developer ' + "Relations, Community Programs and Open Source Partnerships Working " + - "Group for the Americas and Europe\", where it's saved. Credentials " + - "aren't shared between organizations. Tried: " + - "GOOGLE_APPLICATION_CREDENTIALS_JSON", + "Group for the Americas, Europe, the Middle East, Africa and the " + + "Asia-Pacific Region\", where it's saved. Credentials aren't shared " + + "between organizations. Tried: GOOGLE_APPLICATION_CREDENTIALS_JSON", headline: "I stopped because github-repo-list-files can't run yet: bigquery " + "credential not configured. Save it in this organization, or " + 'switch your active organization to "The Builder.io Developer ' + "Relations, Community Programs and Open Source Partnerships Working " + - 'Group for the Americas and Europe", where… That needs to be fixed ' + + "Group for the Americas, Europe, the Middle… That needs to be fixed " + "outside this chat", }, { From c15418709dc870dc1b4d444354f20fa5f8b97201 Mon Sep 17 00:00:00 2001 From: 3mdistal <86723305+3mdistal@users.noreply.github.com> Date: Mon, 23 Nov 2026 13:56:43 -0500 Subject: [PATCH 11/11] Name the key the scope-gap message found when several were tried --- .changeset/cross-org-key-fix-first.md | 2 +- .../src/credentials/index.scope-gap.spec.ts | 35 +++++++++++++++++++ packages/core/src/credentials/index.ts | 13 ++++--- 3 files changed, 44 insertions(+), 6 deletions(-) diff --git a/.changeset/cross-org-key-fix-first.md b/.changeset/cross-org-key-fix-first.md index 404c71caec4..24eea2c163b 100644 --- a/.changeset/cross-org-key-fix-first.md +++ b/.changeset/cross-org-key-fix-first.md @@ -2,4 +2,4 @@ "@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, " credential not configured. Tried: ". 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". +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 names the key before its fixes any more (when a provider accepts several keys, each ends by naming the one it found), and a provider that needs one specific key now words an explained miss the way the any-key error does, " credential not configured. Tried: ". 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". diff --git a/packages/core/src/credentials/index.scope-gap.spec.ts b/packages/core/src/credentials/index.scope-gap.spec.ts index 1ffd4888c4a..84745be5be6 100644 --- a/packages/core/src/credentials/index.scope-gap.spec.ts +++ b/packages/core/src/credentials/index.scope-gap.spec.ts @@ -144,6 +144,23 @@ describe("describeCredentialScopeGap", () => { expect(message).toContain("Personal key"); }); + it("ends by naming the key it found when several were tried", async () => { + execute = async ({ args }) => + args?.[0] === "GH_TOKEN" ? { rows: [{ 1: 1 }] } : { rows: [] }; + + const message = await describeCredentialScopeGap( + ["GITHUB_TOKEN", "GH_TOKEN"], + { userEmail: "owner@example.com", orgId: "org-1" }, + ); + + expect(message).toBe( + "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. The saved key " + + "is GH_TOKEN.", + ); + }); + it("stays quiet when the key is missing everywhere in the org", async () => { const message = await describeCredentialScopeGap(["SLACK_BOT_TOKEN"], { userEmail: "owner@example.com", @@ -199,6 +216,24 @@ describe("describeCredentialScopeGap across organizations", () => { ); }); + it("ends by naming the key it found when several were tried", async () => { + execute = async ({ sql, args }) => + sql.includes(CROSS_ORG_PROBE) && args?.[1] === "GH_TOKEN" + ? { rows: [{ org_name: "Builder.io" }] } + : { rows: [] }; + + const message = await describeCredentialScopeGap( + ["GITHUB_TOKEN", "GH_TOKEN"], + { userEmail: "owner@example.com", orgId: "org-1" }, + ); + + expect(message).toBe( + "Save it in this organization, or switch your active organization " + + "to \"Builder.io\", where it's saved. Credentials aren't shared " + + "between organizations. The saved key is GH_TOKEN.", + ); + }); + it("trims the organization's name", async () => { onlyAnotherMemberOrgHasKey(" Builder.io "); diff --git a/packages/core/src/credentials/index.ts b/packages/core/src/credentials/index.ts index 0ba2211a625..97750585da8 100644 --- a/packages/core/src/credentials/index.ts +++ b/packages/core/src/credentials/index.ts @@ -405,9 +405,11 @@ export async function resolveCredential( * 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. + * Neither message names the key before its fixes, since its 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. When more than + * one key was tried, the message ends by naming the one it found, which that + * list can't show. * * 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 @@ -446,11 +448,12 @@ export async function describeCredentialScopeGap( const scopedCtx: CredentialContext = { ...ctx, orgId: orgLookup.orgId }; for (const key of keys) { + const found = keys.length > 1 ? ` The saved key is ${key}.` : ""; if (await hasForeignPersonalCredentialInOrg(key, scopedCtx)) { return ( `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.` + `Personal key, which works only for the member who saved it.${found}` ); } @@ -462,7 +465,7 @@ export async function describeCredentialScopeGap( return ( `Save it in this organization, or switch your active organization ` + `to ${target} it's saved. Credentials aren't shared between ` + - `organizations.` + `organizations.${found}` ); } }