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

`WORKSPACE_DEFAULT_APP` is ignored when set in the workspace `.env`, and workspace deploys always send `/` to Dispatch

Open renansantos opened this issue 1 month ago • 2 comments

Environment: multi-app workspace with dispatch and one app from the chat template, @agent-native/core 0.222.1, Windows 11, Node 24. The code is unchanged on main at 6f85adff10; nothing here is platform-specific.

What happens: I want the workspace root to open my own app instead of Dispatch. The multi-app-workspace skill of the builder-code-starter template (packages/core/src/templates/builder-code-starter/.agents/skills/multi-app-workspace/SKILL.md, "Default app resolution") says WORKSPACE_DEFAULT_APP wins if it names a real app.

  1. With WORKSPACE_DEFAULT_APP=programs in the workspace root .env, agent-native dev still prints [workspace] Default: http://127.0.0.1:8080/dispatch, and / redirects to /dispatch. Other WORKSPACE_* values in the same file (WORKSPACE_ORG_NAME, WORKSPACE_ORG_DOMAIN, WORKSPACE_OWNER_EMAIL) work.
  2. Setting it in the shell (WORKSPACE_DEFAULT_APP=programs pnpm dev) works: / redirects to /programs.
  3. In a workspace deploy, the variable is never consulted: when a dispatch app exists, / always goes to /dispatch/overview.

Why:

  • The gateway in packages/core/src/cli/workspace-dev.ts reads only process.env (:677, :755) and never loads the .env. The root .env is loaded by each app's Vite config (packages/core/src/vite/client.ts:4639, loadEnv(mode, workspaceRoot, "")), so variables the apps read work from .env and the one only the gateway reads doesn't.
  • packages/core/src/deploy/workspace-deploy.ts hardcodes / → /dispatch/overview for Netlify (:758) and Vercel (:845). The only knob is deployment.workspace.rootPage, which is "redirect" | "directory" (packages/core/src/config.ts:59) and can't name an app. create writes the same redirect (packages/core/src/cli/create.ts:4078).
  • Neither WORKSPACE_DEFAULT_APP nor rootPage is mentioned in packages/core/docs/; the template skill doesn't say the variable is dev-only or must be in the process environment.

The app id is not a way around it: it is the folder name and the mount path, and only an app with id dispatch gets the root without the variable.

Workaround: set WORKSPACE_DEFAULT_APP in the shell or in a small script that wraps pnpm dev. No workaround for deploys short of editing the generated redirects.

Possible fix:

  • Have the gateway load the workspace root .env before reading its own settings (without overriding variables already in the environment), the same way the apps' Vite config does.
  • Let deploys honor the default app: either accept an app id in deployment.workspace.rootPage, or read WORKSPACE_DEFAULT_APP at build time, keeping /dispatch and /dispatch/ → /dispatch/overview.
  • If the variable is meant for local dev only, say so in the main docs, with the resolution order and the fact that it must be in the process environment.

Tests: a gateway started with WORKSPACE_DEFAULT_APP only in the root .env redirects / to that app; the generated _redirects / Vercel routes send / to the chosen app.

Is the variable meant to apply to deploys too, or only to agent-native dev?

renansantos avatar Nov 03 '26 19:11 renansantos

Thanks for the detailed report, Renan, and for pointing at the exact lines. You were right on both counts. We've opened https://github.com/BuilderIO/agent-native/pull/8661, which is in review now. It makes agent-native dev read WORKSPACE_DEFAULT_APP from the workspace root .env (a value already in your shell still wins). Netlify and Vercel deploys also use it for /, and /dispatch still goes to /dispatch/overview. The docs now describe the variable and its resolution order. So the answer to your question is that it applies to both dev and deploys.

builderio-bot avatar Nov 03 '26 19:11 builderio-bot

Thanks for the report - this is fixed by https://github.com/BuilderIO/agent-native/pull/8661, which is merged and will be on beta shortly.

builder-factory avatar Nov 04 '26 19:11 builder-factory