agent-native icon indicating copy to clipboard operation
agent-native copied to clipboard

Personal automations created with `manage-automations` fail with `missing_credentials` when the AI provider key belongs to the organization

Open nabilkhan199999 opened this issue 1 month ago • 1 comments

Summary

We use Agent Native. Our AI provider key is saved for the organization, and users don't have personal keys. Chat works for every user. A personal automation created by the agent with manage-automations fails every background run (scheduled or Run now) with missing_credentials:

No LLM provider is connected. Open Settings > Agent > AI providers, then use Builder.io (free tier available) or add a provider key. No delivery was confirmed.

The run fails about 50 ms after it starts, before any model call.

A personal scheduled job created by the legacy manage-jobs tool, by the same user in the same app, runs with the organization's key.

Environment

  • Versions: @agent-native/core, @agent-native/toolkit and @agent-native/agentkit 0.209.2
  • App: reproduced in a freshly scaffolded app (create --standalone --template chat), run with agent-native dev and AGENT_NATIVE_ENABLE_LOCAL_RECURRING_JOBS=1, and in our internal app (where manage-jobs is turned off, so the agent always uses manage-automations).
  • Credentials: an OpenAI key saved for the organization under Settings › Agent › AI providers. No personal key.
  • createAgentChatPlugin with resolveOrgId returning the signed-in user's active organization.
  • Not run on the latest stable release (0.221.0). The code described under "Relevant code observations" is unchanged there.

Steps and observed behavior

  1. As a member of an organization with an org-level AI provider key and no personal key, confirm chat works.
  2. Ask the agent to create a personal scheduled automation, for example: "Create a personal automation called time-check that runs every 5 minutes and replies with the current UTC time. Don't use the web." The agent calls manage-automations with action: "define" and scope: "personal".
  3. Run it (Run now, or wait for the schedule).
  4. The run fails. Settings › Automations shows the "No LLM provider is connected" message, and the run history has:
{
  "automation": "time-check",
  "scope": "personal",
  "orgId": null,
  "status": "error",
  "errorCode": "missing_credentials",
  "error": "No LLM provider is connected. Open Settings > Agent > AI providers, …"
}

The automation's saved metadata has triggerType: schedule and no orgId.

For comparison, a personal scheduled job created earlier in the same app with manage-jobs has no triggerType and orgId set to the user's organization. Its runs reach the model with the organization's key.

Because the scheduler pauses an automation after repeated missing_credentials failures, the new automation stops running on its own.

Expected behavior

A user's personal automation can run with the same AI provider credentials the user's chat uses, or, if personal automations are meant to need a personal key, that's made clear when the automation is created, and the error doesn't say no provider is connected while one is connected for the organization.

Impact

  • In organizations where the provider key is held at the organization level, personal automations created through the current tool can't run at all, while chat and older manage-jobs jobs work. Users only find out after the first run fails.
  • The error message points users to AI providers, where a provider already shows as connected.

Relevant code observations

These are static source observations from 0.209.2:

  • In @agent-native/core dist/automations/service.js, defining an automation saves orgId: input.scope === "organization" ? actor.orgId : undefined, so a personal automation is saved without the creator's organization. It saves triggerType.
  • In dist/jobs/background-automation-runner.js, resolveBackgroundAutomationIdentity sends any automation with triggerType to resolveAutomationExecutionIdentity. For a resource owned by a user, that returns { userEmail, orgScope: "personal" }, with no orgId, whether or not the metadata has one.
  • For metadata without triggerType (jobs saved by manage-jobs), the same function uses meta.orgId as the run's organization. dist/jobs/tools.js saves orgId: getRequestOrgId() || undefined for those jobs.
  • With orgScope: "personal" and no orgId, credential and default-engine lookups (for example readDefaultAgentEngineSettingDetailed in dist/agent/default-agent-engine.js) read the user's own settings, not the organization's.

Taken together, these suggest background runs of personal automations defined through manage-automations resolve credentials for the user alone, whereas chat and legacy jobs resolve them for the user's organization.

In 0.221.0, service.js still saves orgId only for organization scope, resolveBackgroundAutomationIdentity still branches on triggerType, and resolveAutomationExecutionIdentity still returns orgScope: "personal" for user-owned automations.

nabilkhan199999 avatar Oct 28 '26 10:10 nabilkhan199999

Before I open a PR: should personal automations use the org's AI key?

I reproduced this on main (70b1b9f64) with the chat template. The org has an OpenAI key saved, and my test user has no personal key.

Automations settings: the personal automation fails with "No LLM provider is connected" while the organization automation reaches OpenAI

The personal automation fails with missing_credentials, and "time check" paused itself after 3 of those failures. The org automation reaches OpenAI and gets a 401 because my key is fake. So org runs find the org key.

Cause:

A user-owned automation runs with orgScope: "personal" (resolveAutomationExecutionIdentity, packages/core/src/automations/service.ts:1513). In that scope resolveOrgScopeForEmail returns no org (packages/core/src/org/context.ts:698), so resolveSecretDetailed never reads the org's keys. The credential trace (DEBUG_CREDENTIAL_RESOLVE=1) shows the difference:

personal run:      [resolve-secret] key=OPENAI_API_KEY [email protected] orgId=(none) scope=none hit=false
organization run:  [resolve-secret] key=OPENAI_API_KEY [email protected] orgId=8fb1ecd6b3b8404f885a9a6d5fda104e scope=org hit=true

Saving orgId at define time (service.ts:792) doesn't fix it on its own. I tried that: the runner read meta.orgId and still built a personal identity with no org.

Question:

#7602 made personal scope fail closed on purpose, and a test in service.spec.ts pins it ("marks a verified personal owner so background execution can preserve personal scope"). I don't want to loosen that without asking. I see two ways to go:

  1. Save the creator's org on personal automations and use it for the provider key lookup only, the way chat finds the org key. The rest of the run stays personal.
  2. Keep personal automations on personal keys. define warns when the creator has none, and the run error says personal automations don't use org keys instead of saying no provider is connected.

I'd like to build option 1, starting with a test that fails on main. Does that match what you want, or should I build option 2?

SmitMachhi avatar Oct 30 '26 14:10 SmitMachhi