← Back to PRs

#8195: feat(migration): env fallbacks + legacy launchd cleanup

by shuv-amp open 2026-02-03 18:07 View on GitHub →
app: web-ui gateway agents stale
## Summary This PR improves the migration experience from legacy Clawdbot/Moltbot installations to OpenClaw by: 1. **Centralizing environment variable resolution** - Adds `MigrationService.getEnv()` with consistent fallback (`OPENCLAW_*` -> `CLAWDBOT_*` -> `MOLTBOT_*`), strict-mode guard, and accurate legacy warnings. 2. **Improving macOS launchd cleanup** - Ensures legacy LaunchAgent services (`ai.clawdbot.gateway`, `ai.moltbot.gateway`) are booted out, and surfaces real failures while ignoring "not found". 3. **Preserving gateway auth precedence** - Remote mode still prefers `gateway.remote.*` tokens (local env only in local mode), while password behavior remains unchanged. ## Changes ### `src/services/MigrationService.ts` [NEW] - Implements `MigrationService.getEnv(key, env?)` with: - Primary lookup: `OPENCLAW_<KEY>` - Fallback: `CLAWDBOT_<KEY>` -> `MOLTBOT_<KEY>` - Accurate legacy warnings when legacy vars are used - **Strict mode**: If `~/.openclaw` exists, legacy vars are ignored unless `OPENCLAW_ALLOW_LEGACY_ENV=1` - Adds unit tests for strict mode, caching, and warning key accuracy ### `src/gateway/auth.ts` - Uses `MigrationService` for token/password resolution - Threads `env` param through to support testing mocks ### `src/gateway/call.ts` - Uses `MigrationService` for gateway token/password env lookups - Keeps remote-mode token precedence aligned with pre-PR behavior ### `src/daemon/constants.ts` - `resolveLegacyGatewayLaunchAgentLabels()` returns actual legacy labels ### `src/daemon/launchd.ts` - `stopLaunchAgent()` bootouts legacy services and reports non-"not found" failures ### Branding Updates - `src/routing/resolve-route.test.ts`: `MoltbotConfig` -> `OpenClawConfig` - `src/gateway/server-methods/*.ts`: Updated doc links to openclaw/openclaw - `src/agents/system-prompt.test.ts`: Updated test fixtures ## Related Issues - Partially addresses #2354 (legacy launchd not stopped on mode switch) - Improves experience for users migrating from Clawdbot/Moltbot (#6085, #6720) ## Testing - `pnpm exec vitest run src/services/MigrationService.test.ts`

Most Similar PRs