Skip to content

fix(drive-integration): resolve environment alias for agents API calls [INTEG-4151]#11020

Merged
JuliRossi merged 6 commits into
masterfrom
fix/drive-integration-environment-alias
Jun 12, 2026
Merged

fix(drive-integration): resolve environment alias for agents API calls [INTEG-4151]#11020
JuliRossi merged 6 commits into
masterfrom
fix/drive-integration-environment-alias

Conversation

@JuliRossi

@JuliRossi JuliRossi commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

Purpose

sdk.ids.environment always 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_INSTALLED error handling from #11012.

Summary

  • Added a resolveEnvironmentId helper in useWorkflowAgent.ts that returns sdk.ids.environmentAlias when available (the fast path for alias-based access)
  • Falls back to fetching the environment via CMA and reading `sys.aliases[0]` to find the alias name when the app is accessed via the raw env ID
  • Applied to both startWorkflow and resumeWorkflow call sites
  • Added APP_NOT_INSTALLED to WorkflowFailureReason, error messages, failure reason resolution, and ModalOrchestrator error handling

Test plan

  • Open the drive-integration app on an aliased environment (e.g. master) — workflow starts normally
  • Open the app on the underlying raw environment (e.g. master-2026-06-09) — workflow no longer returns 403
  • Verify the agents API request URL uses the alias name in the path
  • When the agent returns app-not-installed, the UI shows the "App not installed in this environment" error message
  • When the agent returns ai-service-unavailable, the UI shows the "AI service temporarily unavailable" error message

Generated with Claude Code

@JuliRossi JuliRossi requested review from a team as code owners June 10, 2026 20:01
@JuliRossi JuliRossi changed the title fix(drive-integration): resolve environment alias for agents API calls fix(drive-integration): resolve environment alias for agents API calls [INTEG-4151] Jun 11, 2026
JuliRossi and others added 4 commits June 11, 2026 10:32
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>
@JuliRossi JuliRossi force-pushed the fix/drive-integration-environment-alias branch from eb93168 to ee3476f Compare June 11, 2026 13:34

@FBanfi Franco Banfi (FBanfi) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Just left a small question regarding the purpose of the error!

const rawEnvId = sdk.ids.environment;
try {
const env = await sdk.cma.environment.get({ spaceId, environmentId: rawEnvId });
const alias = env.sys.aliases?.[0]?.sys.id;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 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?

@JuliRossi JuliRossi Jun 12, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment on lines +190 to +200
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;
}

@FBanfi Franco Banfi (FBanfi) Jun 11, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense! 💯

JuliRossi and others added 2 commits June 12, 2026 12:03
….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>

@FBanfi Franco Banfi (FBanfi) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

@JuliRossi JuliRossi merged commit ed45269 into master Jun 12, 2026
14 checks passed
@JuliRossi JuliRossi deleted the fix/drive-integration-environment-alias branch June 12, 2026 17:56
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.

2 participants