Skip to content

Fix self-host daemon setup URLs (MUL-2804)#3474

Open
barbudour wants to merge 2 commits into
multica-ai:mainfrom
barbudour:codex/selfhost-runtime-urls
Open

Fix self-host daemon setup URLs (MUL-2804)#3474
barbudour wants to merge 2 commits into
multica-ai:mainfrom
barbudour:codex/selfhost-runtime-urls

Conversation

@barbudour
Copy link
Copy Markdown

Summary

  • expose self-host daemon setup URLs from /api/config at runtime
  • store those URLs in the frontend config store and render multica setup self-host --server-url ... --app-url ... in the Add computer dialog
  • keep Multica Cloud defaults unchanged when no self-host daemon URLs are configured
  • document the env vars used for runtime setup commands

Fixes #3013.

Testing

  • go test ./internal/handler -run 'TestGetConfig' from server/
  • git diff --check

Notes

  • I added Vitest coverage for the dialog command rendering, but could not run it locally because this machine ran out of disk space while installing workspace dependencies (ERR_PNPM_ENOSPC).

@vercel
Copy link
Copy Markdown

vercel Bot commented May 28, 2026

@barbudour is attempting to deploy a commit to the IndexLabs Team on Vercel.

A member of the Team first needs to authorize it.

@Bohan-J Bohan-J changed the title Fix self-host daemon setup URLs Fix self-host daemon setup URLs (MUL-2804) May 29, 2026
Copy link
Copy Markdown
Collaborator

@Bohan-J Bohan-J left a comment

Choose a reason for hiding this comment

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

Request changes

The core fix is well-aimed — self-host operators should see a setup command pointing at their own instance (multica setup self-host --server-url … --app-url …), and Multica Cloud defaults should stay untouched (which they do, verified byte-for-byte). A few things should be resolved before this lands.

Blocking

1. Split out the unrelated Fix hook dependency warnings commit (482e636f).
That commit touches 7 files that have nothing to do with self-host setup URLs — auth-initializer.tsx, attachment-preview-modal.tsx, search-command.tsx, step-runtime-connect.tsx, activity-heatmap.tsx, usage-section.tsx. These span auth bootstrap, search memoization, attachment preview, onboarding analytics, and usage/cost chart recomputation. Even where a change is individually correct, it shouldn't ride along in a feature PR — most notably the auth-initializer.tsx effect going from [] to a six-element dependency array, which changes when the auth bootstrap effect re-runs and deserves its own focused review. Please move the lint/hook cleanup into a dedicated PR so it can be reviewed and tested on its own.

2. FRONTEND_ORIGIN-only deployments still render the Cloud command.
In daemonSetupURLsFromEnv() (server/internal/handler/config.go), FRONTEND_ORIGIN is only consulted as an app-URL fallback inside the if appURL == "" && serverURL != "" branch. If an operator sets only FRONTEND_ORIGIN (with MULTICA_APP_URL and MULTICA_PUBLIC_URL unset), serverURL == "" so that branch is skipped, appURL stays empty, and the function returns "", "" → the dialog falls back to the Cloud command. But the docs mark FRONTEND_ORIGIN as the variable self-host must set (environment-variables.mdx), so a bare-binary / systemd deployment following the required-vars docs still reproduces #3013. Please make FRONTEND_ORIGIN an unconditional appURL fallback (not gated on MULTICA_PUBLIC_URL being set), let serverURL fall back to appURL for the same-origin case, and add a Go test for the FRONTEND_ORIGIN-only config.

3. The new /api/config fields bypass the response-schema rule.
getConfig() in packages/core/api/client.ts is a bare return this.fetch("/api/config"), and the two new fields (daemon_server_url / daemon_app_url) flow straight into a rendered shell command. If a server or proxy returns a non-string for one of them, normalizeCommandURL's .trim() in connect-remote-dialog.tsx throws and takes down the dialog render. The repo's API Response Compatibility guidance asks endpoint responses to go through parseWithFallback with a malformed-response test. Please add a lenient schema + a malformed-response test for the config endpoint, or have a maintainer explicitly mark /api/config as exempt — this PR shouldn't silently widen the unvalidated surface.

Should-fix (can be follow-ups once the above are addressed)

  • urlHostEquals() is fail-open for scheme-less hosts, host:port, and trailing-dot forms: url.Parse("api.multica.ai").Hostname() is "", and "api.multica.ai:8080" parses with an empty host, so isOfficialCloudDaemonConfig returns false and the official-cloud suppression is bypassed. Canonicalize the host (e.g. re-parse with a synthetic scheme when Hostname() is empty, and trim a trailing dot) before the allowlist comparison, and add table-driven tests for bare-host / host:port / trailing-dot.
  • Chinese docs not synced. The English environment-variables.mdx gained MULTICA_APP_URL / MULTICA_PUBLIC_URL rows; the Chinese page environment-variables.zh.mdx still lacks them.

Thanks for the work on this — the backend/frontend wiring and the dialog tests are solid; it mainly needs the scope trimmed and the two correctness gaps closed.

@barbudour barbudour force-pushed the codex/selfhost-runtime-urls branch from 482e636 to 8155da4 Compare May 29, 2026 12:48
@barbudour
Copy link
Copy Markdown
Author

barbudour commented May 29, 2026

Addressed the review feedback in 8155da4:

  • Removed the unrelated hook dependency cleanup commit from this PR.
  • Made FRONTEND_ORIGIN an unconditional app URL fallback and added same-origin Go coverage.
  • Added canonical host matching for bare host / host:port / trailing-dot forms with table tests.
  • Added a lenient /api/config response schema plus malformed daemon URL coverage.
  • Synced the Chinese environment variables docs for MULTICA_APP_URL / MULTICA_PUBLIC_URL.

Validation run locally:

  • go test ./internal/handler -run 'TestGetConfig|TestURLHostEquals'
  • pnpm --filter @multica/core typecheck
  • pnpm --filter @multica/core test -- api/schema.test.ts (46 files / 413 tests)
  • pnpm --filter @multica/views test -- runtimes/components/connect-remote-dialog.test.tsx (100 files / 892 tests)

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.

[Feature]: Add env to support self-hosted instances displaying custom server_url and app_url while adding runtime

2 participants