fix(host-service): propagate Superset home directory

Closed
JA
3mo ago
+27-11

summary

  • pass the CLI's resolved SUPERSET_HOME_DIR into the host-service child environment
  • fall back to ~/.superset when host-service is launched directly without the variable
  • add a regression assertion covering a CLI launch with no inherited SUPERSET_HOME_DIR

Refs #6254 — this is Defect 1 only of the two defects diagnosed there. Defect 2 (headless
hosts never get notify.sh or the managed agent hook entries, because agent-setup lives under
apps/desktop/) is not addressed here and still blocks the reported symptom end-to-end.

why

CLI-started host services previously inherited no SUPERSET_HOME_DIR. Terminal creation then passed an empty home directory into the PTY environment, which disabled the managed agent hook command and also prevented shell bootstrap path resolution.

The CLI already resolves the canonical directory in packages/cli/src/lib/config.ts; this makes the child process receive that value. The host-service fallback also protects direct launchers such as systemd or containers.

the deployment this actually fixes

packages/cli/src/lib/host/spawn.ts is the right layer, confirmed against the machine that
reported #6254 — a self-hosted remote host running under systemd:

[Service]
Type=exec
EnvironmentFile=/etc/superset/env
ExecStart=/opt/superset/current/bin/superset start --org <redacted> --port 8420

The unit invokes the CLI, so the host-service is a child of spawnHostService() and the
spawn.ts half of this change is what reaches it. The terminal.ts fallback is defence in depth
for launchers that exec the host binary directly.

validation

Run on this branch, against a real checkout:

  • bun test packages/cli/src/lib/host/spawn.test.ts → 1 pass / 4 expect
  • bun test packages/host-service/src/terminal/env.test.ts → 46 pass / 119 expect
  • bunx biome check packages/cli/src/lib/host/spawn.ts packages/cli/src/lib/host/spawn.test.ts packages/host-service/src/terminal/terminal.ts
  • git diff --check

The new assertion is a genuine regression test, verified by reverting only the one-line
spawn.ts change and re-running:

expect(received).toBe(expected)
Expected: ".../superset-cli-spawn-6WpnQR"
Received: undefined
(fail) spawnHostService > passes SUPERSET_AUTH_CONFIG_PATH when provided

It fails without the fix and passes with it. spawn.ts spreads ...process.env and the test
deletes SUPERSET_HOME_DIR before the call, so the only path to a defined value is the explicit
key this PR adds.

Not run here: package typecheck (tsc unavailable in the environment that authored the
commit) and the *.node-test.ts files (they need Node ≥ 22 for --experimental-strip-types;
the local toolchain is Node 20, and better-sqlite3 fails to build under it). Both are worth a
CI confirmation.

known follow-up, not done here

This change makes terminal.ts:1401 the sixth copy of the same resolution:

fileform
packages/cli/src/lib/config.ts:27?? join(homedir(), ".superset")
packages/host-service/src/daemon/manifest.ts:34|| join(homedir(), ".superset")
packages/host-service/src/terminal/terminal.ts:1401|| join(homedir(), ".superset") ← added here
packages/host-service/src/providers/model-providers/utils/anthropic-runtime-env/anthropic-runtime-env.ts:94?.trim() ||
packages/chat-legacy/src/server/desktop/chat-service/anthropic-env-config.ts:88?.trim() ||
apps/desktop/src/main/lib/agent-setup/templates/pi-extension.template.ts:35|| join(homedir(), ".superset")

Exporting one resolver and calling it from all six would both remove the duplication and make the
fallback trivially unit-testable — which is the cleanest answer to the review note about
terminal.ts lacking direct coverage. Happy to do that here or in a follow-up, whichever the
maintainers prefer; I left it out to keep this diff to the fix.

Minor: config.ts uses ?? while the rest use ||, so they disagree when SUPERSET_HOME_DIR is
set but empty — ?? keeps "", || falls back. Not a live bug on this path (the
terminal.ts || catches it), but it is the exact empty-string case that produced #6254.

Summary by CodeRabbit

  • Bug Fixes
    • Host services now consistently receive the configured Superset home directory when launched.
    • Added a default home directory of ~/.superset when no custom directory is provided.
    • Improved handling of inherited environment settings during host service startup.