Skip to content

Commit 27dc960

Browse files
committed
fix(macos): restore custodian handoff for fresh activations
Landing every finish on the plain dashboard stranded the custodian first-run flow (memory import, channels, permissions, hatch). Fresh activations now hand off to custodian onboarding; live-verified pre-existing setups reopen the normal dashboard, matching the removed already-configured shortcut. Tests pin the destination per path. Also isolate the post-startup Codex login test from developer machines: ambient OPENAI_API_KEY and a real Codex login made it assert-fail.
1 parent 3998ffe commit 27dc960

8 files changed

Lines changed: 71 additions & 30 deletions

‎apps/macos/Sources/OpenClaw/AppNavigationActions.swift‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@ enum AppNavigationActions {
77
DashboardManager.shared.presentDashboard()
88
}
99

10+
/// Post-AI-setup handoff: land in the dashboard's custodian onboarding,
11+
/// which owns everything after working inference (memory import, channels,
12+
/// app recommendations, hatch).
13+
static func openDashboardOnboarding() {
14+
Task { @MainActor in
15+
await DashboardManager.shared.show(
16+
atPath: DashboardRouteMap.custodianPagePath,
17+
search: DashboardRouteMap.custodianOnboardingSearch)
18+
}
19+
}
20+
1021
static func openChat(sessionKey: String? = nil, agentID: String? = nil, draft: String? = nil) {
1122
NSApp.activate(ignoringOtherApps: true)
1223
Task { @MainActor in

‎apps/macos/Sources/OpenClaw/Onboarding.swift‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ final class OnboardingFinishState {
3232
var didFinish = false
3333
}
3434

35+
/// Dashboard surface opened when onboarding finishes with working inference.
36+
enum OnboardingDashboardHandoff: Equatable {
37+
/// Fresh activation: the custodian flow owns the remaining first-run steps.
38+
case custodianOnboarding
39+
/// Live-verified pre-existing setup: reopen the normal dashboard.
40+
case dashboard
41+
}
42+
3543
enum OnboardingSystemAgentResumeStore {
3644
struct ActivationOwner: Equatable {
3745
let id: String
@@ -662,7 +670,7 @@ struct OnboardingView: View {
662670
let systemAgentDefaults: UserDefaults
663671
let aiSetupRouteIdentityProvider: @MainActor () -> String?
664672
let gatewaySelectionPersister: @MainActor () -> Bool
665-
let dashboardOnboardingOpener: @MainActor () -> Void
673+
let dashboardHandoffOpener: @MainActor (OnboardingDashboardHandoff) -> Void
666674

667675
static let windowWidth: CGFloat = 630
668676
static let windowHeight: CGFloat = 752 // ~+10% to fit full onboarding content
@@ -840,8 +848,11 @@ struct OnboardingView: View {
840848
aiSetupRouteIdentityProvider: (@MainActor () -> String?)? = nil,
841849
configuredGatewayProbeTimeoutMs: Double = 15000,
842850
gatewaySelectionPersister: (@MainActor () -> Bool)? = nil,
843-
dashboardOnboardingOpener: @escaping @MainActor () -> Void = {
844-
AppNavigationActions.openDashboard()
851+
dashboardHandoffOpener: @escaping @MainActor (OnboardingDashboardHandoff) -> Void = {
852+
switch $0 {
853+
case .custodianOnboarding: AppNavigationActions.openDashboardOnboarding()
854+
case .dashboard: AppNavigationActions.openDashboard()
855+
}
845856
})
846857
{
847858
self.state = state
@@ -853,7 +864,7 @@ struct OnboardingView: View {
853864
self.gatewaySelectionPersister = gatewaySelectionPersister ?? {
854865
state.syncGatewayConfigNow()
855866
}
856-
self.dashboardOnboardingOpener = dashboardOnboardingOpener
867+
self.dashboardHandoffOpener = dashboardHandoffOpener
857868
_defaultsToLocalGateway = State(
858869
initialValue: !state.onboardingSeen && state.connectionMode == .unconfigured)
859870
_gatewayDiscovery = State(initialValue: discoveryModel)

‎apps/macos/Sources/OpenClaw/OnboardingAISetupSupport.swift‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,13 @@ extension OnboardingAISetupModel {
219219
return !self.isBusy || (self.phase == .testing && self.selectedKind != kind)
220220
}
221221

222+
/// True when setup live-verified an already-configured route instead of
223+
/// activating a new one. The custodian first-run handoff belongs only to
224+
/// fresh activations; verified reopens land on the normal dashboard.
225+
var verifiedExistingInference: Bool {
226+
self.connected && self.selectedKind == "existing-model"
227+
}
228+
222229
/// Once setup starts changing inference, its successful result belongs to
223230
/// OpenClaw rather than the existing-Gateway onboarding bypass.
224231
var ownsInferenceTransition: Bool {

‎apps/macos/Sources/OpenClaw/OnboardingView+Actions.swift‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,10 @@ extension OnboardingView {
123123
OnboardingController.markComplete()
124124
OnboardingController.shared.close()
125125
guard state.connectionMode != .unconfigured else { return true }
126-
// Inference works; use the same dashboard surface as normal launch and reopen.
127-
dashboardOnboardingOpener()
126+
// Fresh activation hands off to the dashboard's custodian onboarding, which
127+
// owns the remaining first-run steps (memory import, channels, permissions,
128+
// hatch). A live-verified pre-existing setup reopens the normal dashboard.
129+
dashboardHandoffOpener(aiSetup.verifiedExistingInference ? .dashboard : .custodianOnboarding)
128130
return true
129131
}
130132
}

‎apps/macos/Sources/OpenClaw/OnboardingView+Layout.swift‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,7 @@ extension OnboardingView {
198198
self.waitForPendingInferenceSetup()
199199
return
200200
case .none:
201-
// A concurrent probe can clear an expired marker while
202-
// the dispatched activation is still returning. Keep the
203-
// setup-owned handoff, and prove inference on this route.
204-
if self.aiSetup.pendingActivationVerification {
205-
self.resumePendingSystemAgent(modelRef: modelRef)
206-
return
207-
}
201+
break
208202
}
209203
// agents.list projects an effective model even when it only
210204
// comes from an implicit runtime default. A label is not proof

‎apps/macos/Tests/OpenClawIPCTests/OnboardingAISetupTests.swift‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,13 +1505,13 @@ struct OnboardingAISetupTests {
15051505
let gateway = makeAISetupGateway(url: url, session: session)
15061506
let appState = AppState(preview: true)
15071507
appState.connectionMode = .local
1508-
var handoffCount = 0
1508+
var handoffs: [OnboardingDashboardHandoff] = []
15091509
let view = OnboardingView(
15101510
state: appState,
15111511
aiSetupGateway: gateway,
15121512
systemAgentDefaults: defaults,
15131513
aiSetupRouteIdentityProvider: { "local" },
1514-
dashboardOnboardingOpener: { handoffCount += 1 })
1514+
dashboardHandoffOpener: { handoffs.append($0) })
15151515
view.onboardingVisible = true
15161516
view.currentPage = try #require(view.pageOrder.firstIndex(of: view.aiPageIndex))
15171517

@@ -1530,7 +1530,8 @@ struct OnboardingAISetupTests {
15301530
#expect(view.aiSetup.connected)
15311531
#expect(view.aiSetup.selectedKind == "claude-cli")
15321532
#expect(view.finishState.didFinish)
1533-
#expect(handoffCount == 1)
1533+
// Fresh activation hands off to the custodian first-run flow.
1534+
#expect(handoffs == [.custodianOnboarding])
15341535
#expect(await (recorder.snapshot()).methods == [
15351536
"agents.list",
15361537
"openclaw.setup.verify",

‎apps/macos/Tests/OpenClawIPCTests/OnboardingSystemAgentChatTests.swift‎

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -202,18 +202,19 @@ struct OnboardingSystemAgentChatTests {
202202
@Test func `fresh inference connection finishes onboarding once`() {
203203
let state = AppState(preview: true)
204204
state.connectionMode = .local
205-
var dashboardOpenCount = 0
205+
var handoffs: [OnboardingDashboardHandoff] = []
206206
let view = OnboardingView(
207207
state: state,
208-
dashboardOnboardingOpener: { dashboardOpenCount += 1 })
208+
dashboardHandoffOpener: { handoffs.append($0) })
209209

210210
view.prepareSystemAgentHandoff()
211211
view.aiSetup.onConnected?()
212212

213213
#expect(view.finishState.didFinish)
214-
#expect(dashboardOpenCount == 1)
214+
// Fresh connections own the remaining first-run steps via the custodian.
215+
#expect(handoffs == [.custodianOnboarding])
215216
#expect(!view.finish())
216-
#expect(dashboardOpenCount == 1)
217+
#expect(handoffs == [.custodianOnboarding])
217218
}
218219

219220
@Test func `first run effective model is live verified before handoff`() async throws {
@@ -245,13 +246,13 @@ struct OnboardingSystemAgentChatTests {
245246
sessionBox: WebSocketSessionBox(session: session))
246247
let appState = AppState(preview: true)
247248
appState.connectionMode = .local
248-
var handoffCount = 0
249+
var handoffs: [OnboardingDashboardHandoff] = []
249250
let view = OnboardingView(
250251
state: appState,
251252
aiSetupGateway: gateway,
252253
systemAgentDefaults: defaults,
253254
aiSetupRouteIdentityProvider: { "local" },
254-
dashboardOnboardingOpener: { handoffCount += 1 })
255+
dashboardHandoffOpener: { handoffs.append($0) })
255256

256257
let initialProbe = try #require(view.onboardingDidAppear())
257258
await initialProbe.value
@@ -264,7 +265,8 @@ struct OnboardingSystemAgentChatTests {
264265

265266
#expect(view.aiSetup.connected)
266267
#expect(view.finishState.didFinish)
267-
#expect(handoffCount == 1)
268+
// A live-verified pre-existing setup reopens the normal dashboard.
269+
#expect(handoffs == [.dashboard])
268270
#expect(await methods.snapshot() == [
269271
"agents.list",
270272
"health",
@@ -305,29 +307,29 @@ struct OnboardingSystemAgentChatTests {
305307
appState.connectionMode = .remote
306308
appState.remoteTransport = .direct
307309
appState.remoteUrl = "ws://example.invalid"
308-
var dashboardOpenCount = 0
310+
var handoffs: [OnboardingDashboardHandoff] = []
309311
let view = OnboardingView(
310312
state: appState,
311313
aiSetupGateway: gateway,
312314
systemAgentDefaults: defaults,
313315
aiSetupRouteIdentityProvider: { "remote:direct:example.invalid" },
314-
dashboardOnboardingOpener: { dashboardOpenCount += 1 })
316+
dashboardHandoffOpener: { handoffs.append($0) })
315317

316318
let task = view.resumePendingSystemAgent(modelRef: "openai/gpt-5.5")
317319
await task.value
318320

319321
#expect(view.aiSetup.connected)
320322
#expect(view.aiSetup.selectedKind == "existing-model")
321323
#expect(view.finishState.didFinish)
322-
#expect(dashboardOpenCount == 1)
324+
#expect(handoffs == [.dashboard])
323325
#expect(!view.finish())
324326

325327
let repeatedResume = view.resumePendingSystemAgent(modelRef: "openai/gpt-5.5")
326328
await repeatedResume.value
327329

328330
#expect(view.aiSetup.connected)
329331
#expect(view.aiSetup.selectedKind == "existing-model")
330-
#expect(dashboardOpenCount == 1)
332+
#expect(handoffs == [.dashboard])
331333
#expect(await methods.snapshot() == [
332334
"health",
333335
"openclaw.setup.verify",
@@ -450,7 +452,7 @@ struct OnboardingSystemAgentChatTests {
450452
aiSetupGateway: gateway,
451453
systemAgentDefaults: defaults,
452454
aiSetupRouteIdentityProvider: { "remote:direct:example.invalid" },
453-
dashboardOnboardingOpener: { dashboardOpenCount += 1 })
455+
dashboardHandoffOpener: { _ in dashboardOpenCount += 1 })
454456

455457
let staleResume = view.resumePendingSystemAgent(modelRef: "openai/gpt-5.5")
456458
for _ in 0..<200 {
@@ -524,7 +526,7 @@ struct OnboardingSystemAgentChatTests {
524526
aiSetupGateway: gateway,
525527
systemAgentDefaults: defaults,
526528
aiSetupRouteIdentityProvider: { routeIdentity },
527-
dashboardOnboardingOpener: { dashboardOpenCount += 1 })
529+
dashboardHandoffOpener: { _ in dashboardOpenCount += 1 })
528530
let aiSetup = view.aiSetup
529531

530532
let initialProbe = try #require(view.onboardingDidAppear())

‎src/agents/prepared-model-catalog-worker.integration.test.ts‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import fs from "node:fs";
22
import path from "node:path";
3-
import { afterEach, describe, expect, it } from "vitest";
3+
import { afterEach, describe, expect, it, vi } from "vitest";
44
import { useAutoCleanupTempDirTracker } from "../../test/helpers/temp-dir.js";
55
import type { OpenClawConfig } from "../config/types.openclaw.js";
66
import { buildModelsListResult } from "../gateway/server-methods/models-list-result.js";
@@ -573,6 +573,9 @@ describe("prepared model catalog worker boundary", () => {
573573
});
574574

575575
it("makes a post-startup Codex login available to direct models.list", async () => {
576+
// A developer's ambient OpenAI key would count as usable openai auth and
577+
// mark the route available before the staged Codex login exists.
578+
vi.stubEnv("OPENAI_API_KEY", undefined);
576579
const codexHome = tempDirs.make("openclaw-models-list-codex-");
577580
const fixture = await createStaticSnapshot(0, { CODEX_HOME: codexHome });
578581
const route = {
@@ -595,6 +598,16 @@ describe("prepared model catalog worker boundary", () => {
595598
},
596599
],
597600
},
601+
plugins: {
602+
...fixture.config.plugins,
603+
entries: {
604+
...fixture.config.plugins?.entries,
605+
// This test proves auth-store refresh, not harness discovery. A live
606+
// model/list against a developer's real Codex login would mark the
607+
// route available before the staged auth.json exists.
608+
codex: { config: { discovery: { enabled: false } } },
609+
},
610+
},
598611
} satisfies OpenClawConfig;
599612
const owner = Object.freeze({
600613
...fixture.snapshot,

0 commit comments

Comments
 (0)