fix(drive-integration): resolve environment alias for agents API calls [INTEG-4151]#11020
Conversation
sdk.ids.environment returns the real environment ID (e.g. master-2026-06-09) instead of the alias (master), causing the agents API path to not match aliased environments. Fall back to raw ID when no alias is set. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…alls When the app is opened on a raw environment ID (e.g. master-2026-06-09), sdk.ids.environmentAlias is undefined. Fall back to fetching the environment and reading sys.aliases to find the alias name, so the agents API path matches the app installation which is scoped to the alias. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Covers: alias fast-path, CMA alias lookup, no-alias fallback, and CMA error fallback. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ABLE error handling Ports error cases from #11012 — surfaces actionable messages when the app is not installed in the target environment or the AI service is down. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
eb93168 to
ee3476f
Compare
| const rawEnvId = sdk.ids.environment; | ||
| try { | ||
| const env = await sdk.cma.environment.get({ spaceId, environmentId: rawEnvId }); | ||
| const alias = env.sys.aliases?.[0]?.sys.id; |
There was a problem hiding this comment.
🤔 Is it possible to have more than one alias per environment? Just curios due to this env.sys.aliases?.[0]?.sys.id;, or is it just because of the returned sdk shape?
There was a problem hiding this comment.
Mmm you are correct. it might be risky. The idea was to also solve the issue that affected environments accessed directly by their raw ID when an alias exists (this resulted in error in dev). But there seems to be something funky with the dev installation in particular. Went with a simpler fix that fixes the original issue (we are doing what we do in other app) and will test the second issue in prod to see how it works for that cases
| if ( | ||
| error instanceof WorkflowRunError && | ||
| error.reason === WorkflowFailureReason.APP_NOT_INSTALLED | ||
| ) { | ||
| setPreviewErrorState({ | ||
| reason: WorkflowFailureReason.APP_NOT_INSTALLED, | ||
| title: 'App not installed in this environment', | ||
| message: ERROR_MESSAGES.APP_NOT_INSTALLED, | ||
| }); | ||
| return; | ||
| } |
There was a problem hiding this comment.
I find this a bit confusing, how would the user run the workflow if the app was not installed in that environment?
Or this error refers to cases where: in the middle of a workflow run, the app was uninstalled from a different browser tab?
There was a problem hiding this comment.
The idea is to have better error handling. If by any chance the request fail in the BE, we want to be as clear as possible. Better a clear error message than a generic "Unable to generate preview" for the user. Also we want to know if the app is failing because of this
There was a problem hiding this comment.
Makes sense! 💯
….environmentAlias ?? sdk.ids.environment Replaces the resolveEnvironmentId helper (which made a CMA call to look up aliases) with the one-liner pattern used across closest-preview, slack, braze, and other apps. The CMA fallback was fragile (aliases[0] guess) and unnecessary — sdk.ids.environmentAlias is already populated when the user accesses via alias, which is the case that was causing the 403. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…nt.ts Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Purpose
sdk.ids.environmentalways returns the raw environment ID (e.g.master-2026-06-09), even when the app is opened via an alias like `master`. This caused the agents API path to use the raw env ID, which doesn't match the app installation scoped to the alias — resulting in a 403. The issue also affected environments accessed directly by their raw ID when an alias exists.Also ports
APP_NOT_INSTALLEDerror handling from #11012.Summary
resolveEnvironmentIdhelper inuseWorkflowAgent.tsthat returnssdk.ids.environmentAliaswhen available (the fast path for alias-based access)startWorkflowandresumeWorkflowcall sitesAPP_NOT_INSTALLEDtoWorkflowFailureReason, error messages, failure reason resolution, andModalOrchestratorerror handlingTest plan
master) — workflow starts normallymaster-2026-06-09) — workflow no longer returns 403app-not-installed, the UI shows the "App not installed in this environment" error messageai-service-unavailable, the UI shows the "AI service temporarily unavailable" error messageGenerated with Claude Code