Skip to content

Commit 22fa9f5

Browse files
authored
fix(linux): first-run desktop onboarding automatically connects working AI (#129211)
* fix(linux): make desktop AI onboarding work automatically * fix(linux): harden provider ownership and onboarding lifecycle * test(ui): document partial onboarding context fixture * fix(linux): preserve operator-owned onboarding API keys * fix(linux): retire previously managed provider credentials * fix(linux): retain rotated onboarding provider credentials
1 parent 1fdd10b commit 22fa9f5

12 files changed

Lines changed: 1335 additions & 111 deletions

‎apps/linux/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ The app uses `OPENCLAW_DESKTOP_CLI` when set. Otherwise it checks `~/.openclaw/b
4747

4848
Desktop notifications use each platform's system notification service. macOS 13+ uses Apple's User Notifications framework; Windows uses native system toasts and Linux uses the desktop notification service through `notify-rust`. On macOS, test notifications from a signed `.app` bundle: a direct `cargo run` stays unbundled, so the app disables notifications instead of initializing Apple's framework with no bundle identity.
4949

50-
On first run, release builds automatically install the stable CLI channel, while development builds ask for a release channel and preselect Development. After the CLI install, the app opens the local dashboard once with onboarding mode enabled. Reconnects and later app launches use the normal dashboard URL.
50+
On first run, release builds automatically install the stable CLI channel, while development builds ask for a release channel and preselect Development. After the CLI install, the app opens Model Setup, automatically checks existing credentials, and verifies a real model response before continuing. A working existing model opens the normal dashboard; newly configured AI access continues into guided onboarding. If no existing credentials work, choose a provider, sign in, or enter an API key in Model Setup. Reconnects and later app launches use the normal dashboard URL.
5151

5252
## Updates
5353

‎apps/linux/src-tauri/src/main.rs‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,12 @@ impl NavigationState {
144144
let mut url =
145145
Url::parse(target).map_err(|_| "Dashboard returned an invalid URL.".to_string())?;
146146
if self.onboarding_pending {
147-
// Dashboard auth lives in the fragment, so the marker must be added through URL pairs.
148-
url.query_pairs_mut().append_pair("onboarding", "1");
147+
// Setup owns inference before chat; preserve Gateway base paths and fragment auth.
148+
url.path_segments_mut()
149+
.map_err(|_| "Dashboard returned an invalid URL.".to_string())?
150+
.pop_if_empty()
151+
.extend(["settings", "model-setup"]);
152+
url.query_pairs_mut().append_pair("firstRun", "1");
149153
self.onboarding_pending = false;
150154
}
151155
Ok(url)
@@ -648,20 +652,21 @@ mod navigation_tests {
648652
}
649653

650654
#[test]
651-
fn onboarding_url_preserves_existing_query_and_fragment() {
655+
fn first_run_url_preserves_gateway_base_path_query_and_auth_fragment() {
652656
let mut navigation = NavigationState::default();
653657
navigation.mark_onboarding_pending();
654658

655659
let url = navigation
656-
.prepare_dashboard_url("http://127.0.0.1:18789/?foo=bar#token=secret")
660+
.prepare_dashboard_url("http://127.0.0.1:18789/openclaw/?foo=bar#token=secret")
657661
.expect("dashboard URL");
658662

659-
assert_eq!(url.query(), Some("foo=bar&onboarding=1"));
663+
assert_eq!(url.path(), "/openclaw/settings/model-setup");
664+
assert_eq!(url.query(), Some("foo=bar&firstRun=1"));
660665
assert_eq!(url.fragment(), Some("token=secret"));
661666
}
662667

663668
#[test]
664-
fn onboarding_flag_is_consumed_once() {
669+
fn first_run_model_setup_is_opened_only_once() {
665670
let mut navigation = NavigationState::default();
666671
navigation.mark_onboarding_pending();
667672

@@ -672,7 +677,9 @@ mod navigation_tests {
672677
.prepare_dashboard_url("http://127.0.0.1:18789/#token=secret")
673678
.expect("second dashboard URL");
674679

675-
assert_eq!(first.query(), Some("onboarding=1"));
680+
assert_eq!(first.path(), "/settings/model-setup");
681+
assert_eq!(first.query(), Some("firstRun=1"));
682+
assert_eq!(second.path(), "/");
676683
assert_eq!(second.query(), None);
677684
}
678685

‎docs/platforms/linux.md‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,18 @@ The OpenClaw Linux companion is a Tauri desktop app for a local Gateway. It:
2222
- discovers nearby Bonjour Gateways and opens each Control UI in a route-scoped window, so several
2323
Gateway dashboards can stay connected and be used simultaneously
2424
- opens the Gateway-served Control UI with its resolved authentication URL
25-
- opens the Control UI in onboarding mode after its first-run install, which
26-
offers to import detected Claude Code, Codex, or Hermes memories into the
27-
agent workspace (the same import stays available later under
28-
Settings → Import Memory)
25+
- opens Model Setup after its first-run install, automatically tests available
26+
AI credentials, and verifies an existing model before opening the dashboard
27+
- continues into guided onboarding after connecting a new model; onboarding can
28+
import detected Claude Code, Codex, or Hermes memories into the agent workspace
29+
(the same import stays available later under Settings → Import Memory)
2930
- remains available from the system tray when its window is closed
3031

32+
When the desktop app starts with a supported provider API key in its environment,
33+
the Gateway service keeps that dedicated inference credential in an owner-only
34+
environment file. Provider admin keys, GitHub tokens, and unrelated environment
35+
variables are not copied into the service.
36+
3137
### Host sleep
3238

3339
On systems with systemd-logind, the companion prepares a suspension lease for

‎src/cli/gateway-cli/run.option-collisions.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1757,6 +1757,7 @@ describe("gateway run option collisions", () => {
17571757
OPENCLAW_SERVICE_MANAGED_ENV_KEYS: "REMOVED_KEY,SECRET_REF_KEY",
17581758
REMOVED_KEY: "stale-service-value",
17591759
SECRET_REF_KEY: "file-backed-value",
1760+
OPENAI_API_KEY: "operator-owned-provider-key",
17601761
OPERATOR_KEY: "operator-value",
17611762
},
17621763
async () => {
@@ -1765,6 +1766,7 @@ describe("gateway run option collisions", () => {
17651766
await selectGatewayRunEnvironment({ opts: {}, runtime: defaultRuntime });
17661767
expect(process.env.REMOVED_KEY).toBeUndefined();
17671768
expect(process.env.SECRET_REF_KEY).toBe("file-backed-value");
1769+
expect(process.env.OPENAI_API_KEY).toBe("operator-owned-provider-key");
17681770
expect(process.env.OPERATOR_KEY).toBe("operator-value");
17691771
await prepareGatewayRunBootstrap({ opts: {}, runtime: defaultRuntime });
17701772
},

‎src/commands/daemon-install-helpers.test.ts‎

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,203 @@ describe("buildGatewayInstallPlan", () => {
592592
expect(mocks.loadPluginManifestRegistryForPluginRegistry).not.toHaveBeenCalled();
593593
});
594594

595+
it("keeps first-install provider API keys file-backed without capturing unrelated credentials", async () => {
596+
mockNodeGatewayPlanFixture({ serviceEnvironment: { OPENCLAW_PORT: "3000" } });
597+
mocks.hasAnyAuthProfileStoreSource.mockReturnValue(false);
598+
599+
const plan = await buildGatewayInstallPlan({
600+
env: isolatedPlanEnv({
601+
OPENAI_API_KEY: "ambient-openai",
602+
ANTHROPIC_API_KEY: "ambient-anthropic",
603+
ANTHROPIC_OAUTH_TOKEN: "ambient-oauth",
604+
ANTHROPIC_ADMIN_API_KEY: "ambient-anthropic-admin",
605+
OPENAI_ADMIN_KEY: "ambient-openai-admin",
606+
GITHUB_TOKEN: "ambient-github",
607+
GH_TOKEN: "ambient-gh",
608+
UNRECOGNIZED_API_KEY: "ambient-unrecognized",
609+
NODE_OPTIONS: "--require /tmp/untrusted.js",
610+
}),
611+
port: 3000,
612+
runtime: "node",
613+
platform: "linux",
614+
config: {},
615+
});
616+
617+
expect(plan.environment.OPENAI_API_KEY).toBe("ambient-openai");
618+
expect(plan.environment.ANTHROPIC_API_KEY).toBe("ambient-anthropic");
619+
expect(plan.environmentValueSources?.OPENAI_API_KEY).toBe("file");
620+
expect(plan.environmentValueSources?.ANTHROPIC_API_KEY).toBe("file");
621+
expect(plan.environment.OPENCLAW_SERVICE_MANAGED_ENV_KEYS).toBeUndefined();
622+
expect(plan.environment.ANTHROPIC_OAUTH_TOKEN).toBeUndefined();
623+
expect(plan.environment.ANTHROPIC_ADMIN_API_KEY).toBeUndefined();
624+
expect(plan.environment.OPENAI_ADMIN_KEY).toBeUndefined();
625+
expect(plan.environment.GITHUB_TOKEN).toBeUndefined();
626+
expect(plan.environment.GH_TOKEN).toBeUndefined();
627+
expect(plan.environment.UNRECOGNIZED_API_KEY).toBeUndefined();
628+
expect(plan.environment.NODE_OPTIONS).toBeUndefined();
629+
});
630+
631+
it("does not let enabled third-party plugins capture ambient provider API keys", async () => {
632+
const pluginId = "third-party-provider";
633+
const pluginRoot = path.join(isolatedHome, pluginId);
634+
createSecurePluginRoot(pluginRoot);
635+
writeSecurePluginEntrypoint(path.join(pluginRoot, "index.js"));
636+
fs.writeFileSync(
637+
path.join(pluginRoot, "openclaw.plugin.json"),
638+
JSON.stringify({
639+
id: pluginId,
640+
configSchema: { type: "object", additionalProperties: false },
641+
setup: { providers: [{ id: pluginId, envVars: ["THIRD_PARTY_API_KEY"] }] },
642+
providerAuthChoices: [
643+
{
644+
provider: pluginId,
645+
method: "api-key",
646+
choiceId: "third-party-api-key",
647+
appGuidedSecret: true,
648+
},
649+
],
650+
}),
651+
);
652+
mockNodeGatewayPlanFixture();
653+
mocks.hasAnyAuthProfileStoreSource.mockReturnValue(false);
654+
const env = isolatedPlanEnv({
655+
OPENAI_API_KEY: "bundled-openai",
656+
THIRD_PARTY_API_KEY: "ambient-third-party",
657+
});
658+
const config: OpenClawConfig = {
659+
plugins: {
660+
enabled: true,
661+
load: { paths: [pluginRoot] },
662+
entries: { [pluginId]: { enabled: true } },
663+
},
664+
};
665+
const { loadManifestMetadataSnapshot } =
666+
await import("../plugins/manifest-contract-eligibility.js");
667+
const snapshot = loadManifestMetadataSnapshot({ config, env });
668+
const externalPlugin = snapshot.plugins.find(({ id }) => id === pluginId);
669+
expect(externalPlugin).toEqual(expect.objectContaining({ origin: "config" }));
670+
expect(externalPlugin?.trustedOfficialInstall).not.toBe(true);
671+
expect(snapshot.index.plugins.find(({ pluginId: id }) => id === pluginId)?.enabled).toBe(true);
672+
673+
const plan = await buildGatewayInstallPlan({
674+
env,
675+
config,
676+
port: 3000,
677+
runtime: "node",
678+
platform: "linux",
679+
});
680+
681+
expect(plan.environment.OPENAI_API_KEY).toBe("bundled-openai");
682+
expect(plan.environment.THIRD_PARTY_API_KEY).toBeUndefined();
683+
expect(plan.environment.OPENCLAW_SERVICE_MANAGED_ENV_KEYS).toBeUndefined();
684+
});
685+
686+
it("keeps durable provider API keys authoritative over first-install shell credentials", async () => {
687+
await writeStateDirDotEnv("OPENAI_API_KEY=durable-openai\n", {
688+
stateDir: path.join(isolatedHome, ".openclaw"),
689+
});
690+
mockNodeGatewayPlanFixture({ serviceEnvironment: { OPENCLAW_PORT: "3000" } });
691+
mocks.hasAnyAuthProfileStoreSource.mockReturnValue(false);
692+
693+
const plan = await buildGatewayInstallPlan({
694+
env: isolatedPlanEnv({
695+
OPENAI_API_KEY: "ambient-openai",
696+
ANTHROPIC_API_KEY: "ambient-anthropic",
697+
}),
698+
port: 3000,
699+
runtime: "node",
700+
platform: "linux",
701+
config: {},
702+
});
703+
704+
expect(plan.environment.OPENAI_API_KEY).toBeUndefined();
705+
expect(plan.environment.ANTHROPIC_API_KEY).toBe("ambient-anthropic");
706+
expect(plan.environmentValueSources?.ANTHROPIC_API_KEY).toBe("file");
707+
expect(plan.environment.OPENCLAW_SERVICE_MANAGED_ENV_KEYS).toBe("OPENAI_API_KEY");
708+
});
709+
710+
it("does not claim provider API keys already owned by Linux auth profiles", async () => {
711+
mockNodeGatewayPlanFixture({ serviceEnvironment: { OPENCLAW_PORT: "3000" } });
712+
713+
const plan = await buildGatewayInstallPlan({
714+
env: isolatedPlanEnv({ OPENAI_API_KEY: "profile-owned-openai" }),
715+
authStore: {
716+
version: 1,
717+
profiles: {
718+
"openai:default": {
719+
type: "api_key",
720+
provider: "openai",
721+
keyRef: { source: "env", provider: "default", id: "OPENAI_API_KEY" },
722+
},
723+
},
724+
},
725+
port: 3000,
726+
runtime: "node",
727+
platform: "linux",
728+
config: {},
729+
});
730+
731+
expect(plan.environment.OPENAI_API_KEY).toBe("profile-owned-openai");
732+
expect(plan.environment.OPENCLAW_SERVICE_MANAGED_ENV_KEYS).toBeUndefined();
733+
});
734+
735+
it.each(["inline", "file"] as const)(
736+
"preserves an existing %s provider API key over unrelated shell credentials",
737+
async (source) => {
738+
mockNodeGatewayPlanFixture({ serviceEnvironment: { OPENCLAW_PORT: "3000" } });
739+
mocks.hasAnyAuthProfileStoreSource.mockReturnValue(false);
740+
741+
const plan = await buildGatewayInstallPlan({
742+
env: isolatedPlanEnv({ OPENAI_API_KEY: "ambient-openai" }),
743+
existingEnvironment: { OPENAI_API_KEY: "operator-openai" },
744+
existingEnvironmentValueSources: { OPENAI_API_KEY: source },
745+
port: 3000,
746+
runtime: "node",
747+
platform: "linux",
748+
config: {},
749+
});
750+
751+
expect(plan.environment.OPENAI_API_KEY).toBe("operator-openai");
752+
expect(plan.environmentValueSources?.OPENAI_API_KEY).toBe(source);
753+
expect(plan.environment.OPENCLAW_SERVICE_MANAGED_ENV_KEYS).toBeUndefined();
754+
},
755+
);
756+
757+
it.each([
758+
{ currentOpenAiKey: "existing-managed-openai", expectedOpenAiKey: undefined },
759+
{ currentOpenAiKey: "rotated-operator-openai", expectedOpenAiKey: "rotated-operator-openai" },
760+
])(
761+
"retires managed provider keys while preserving genuinely rotated replacements",
762+
async ({ currentOpenAiKey, expectedOpenAiKey }) => {
763+
mockNodeGatewayPlanFixture({ serviceEnvironment: { OPENCLAW_PORT: "3000" } });
764+
mocks.hasAnyAuthProfileStoreSource.mockReturnValue(false);
765+
766+
const plan = await buildGatewayInstallPlan({
767+
env: isolatedPlanEnv({
768+
OPENAI_API_KEY: currentOpenAiKey,
769+
ANTHROPIC_API_KEY: "fresh-operator-anthropic",
770+
}),
771+
existingEnvironment: {
772+
OPENAI_API_KEY: "existing-managed-openai",
773+
OPENCLAW_SERVICE_MANAGED_ENV_KEYS: "OPENAI_API_KEY",
774+
},
775+
existingEnvironmentValueSources: { OPENAI_API_KEY: "file" },
776+
port: 3000,
777+
runtime: "node",
778+
platform: "linux",
779+
config: {},
780+
});
781+
782+
expect(plan.environment.OPENAI_API_KEY).toBe(expectedOpenAiKey);
783+
expect(plan.environmentValueSources?.OPENAI_API_KEY).toBe(
784+
expectedOpenAiKey ? "file" : undefined,
785+
);
786+
expect(plan.environment.ANTHROPIC_API_KEY).toBe("fresh-operator-anthropic");
787+
expect(plan.environmentValueSources?.ANTHROPIC_API_KEY).toBe("file");
788+
expect(plan.environment.OPENCLAW_SERVICE_MANAGED_ENV_KEYS).toBeUndefined();
789+
},
790+
);
791+
595792
it("renders config env SecretRefs as file-backed managed values on Linux", async () => {
596793
mockNodeGatewayPlanFixture({
597794
serviceEnvironment: {

0 commit comments

Comments
 (0)