-
Notifications
You must be signed in to change notification settings - Fork 3.1k
fix(onboard): refresh provider state on agent changes #3857
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cb653bb
fix(onboard): refresh provider state on agent changes
ericksoa d215931
fix(onboard): extract agent resume cleanup
ericksoa 4cd87a2
fix(onboard): avoid unused resume assignment
ericksoa 27ca3ad
fix(onboard): share stale brave preset helper
ericksoa 8639504
Merge remote-tracking branch 'origin/main' into fix/onboard-agent-sco…
ericksoa f1e26db
Merge remote-tracking branch 'origin/main' into fix/onboard-agent-sco…
ericksoa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import type { Session } from "../state/onboard-session"; | ||
|
|
||
| export function normalizeAgentNameForResumeState(agentName: string | null | undefined): string { | ||
| const trimmed = typeof agentName === "string" ? agentName.trim() : ""; | ||
| return trimmed && trimmed !== "openclaw" ? trimmed : "openclaw"; | ||
| } | ||
|
|
||
| export function resetStepForAgentChange(session: Session, stepName: string): void { | ||
| const stepState = session.steps[stepName]; | ||
| if (!stepState) return; | ||
| stepState.status = "pending"; | ||
| stepState.startedAt = null; | ||
| stepState.completedAt = null; | ||
| stepState.error = null; | ||
| } | ||
|
|
||
| export function clearAgentScopedResumeState( | ||
| session: Session, | ||
| selectedAgentName: string, | ||
| ): Session { | ||
| const normalizedAgentName = normalizeAgentNameForResumeState(selectedAgentName); | ||
| session.agent = normalizedAgentName === "openclaw" ? null : normalizedAgentName; | ||
| session.provider = null; | ||
| session.model = null; | ||
| session.endpointUrl = null; | ||
| session.credentialEnv = null; | ||
| session.hermesAuthMethod = null; | ||
| session.hermesToolGateways = null; | ||
| session.preferredInferenceApi = null; | ||
| session.nimContainer = null; | ||
| session.routerPid = null; | ||
| session.routerCredentialHash = null; | ||
| session.policyPresets = null; | ||
|
|
||
| const resetSteps = [ | ||
| "provider_selection", | ||
| "inference", | ||
| "sandbox", | ||
| "openclaw", | ||
| "agent_setup", | ||
| "policies", | ||
| ]; | ||
| for (const stepName of resetSteps) resetStepForAgentChange(session, stepName); | ||
| if (session.lastCompletedStep && resetSteps.includes(session.lastCompletedStep)) { | ||
| session.lastCompletedStep = | ||
| session.steps.gateway?.status === "complete" | ||
| ? "gateway" | ||
| : session.steps.preflight?.status === "complete" | ||
| ? "preflight" | ||
| : null; | ||
| } | ||
| if (session.lastStepStarted && resetSteps.includes(session.lastStepStarted)) { | ||
| session.lastStepStarted = null; | ||
| } | ||
| return session; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import * as http from "node:http"; | ||
| import type { Session } from "../state/onboard-session"; | ||
|
|
||
| export const ROUTER_HEALTH_TIMEOUT_MS = 3000; | ||
|
|
||
| export async function isRouterHealthy( | ||
| port: number, | ||
| timeoutMs = ROUTER_HEALTH_TIMEOUT_MS, | ||
| ): Promise<boolean> { | ||
| return new Promise<boolean>((resolve) => { | ||
| let settled = false; | ||
| const settle = (healthy: boolean) => { | ||
| if (settled) return; | ||
| settled = true; | ||
| resolve(healthy); | ||
| }; | ||
| const request = http | ||
| .get(`http://127.0.0.1:${port}/health`, (res: http.IncomingMessage) => { | ||
| res.resume(); | ||
| settle((res.statusCode || 0) >= 200 && (res.statusCode || 0) < 300); | ||
| }) | ||
| .on("error", () => settle(false)); | ||
| request.setTimeout(timeoutMs, () => { | ||
| request.destroy(); | ||
| settle(false); | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| export function isProcessRunning(pid: number | null | undefined): boolean { | ||
| if (!Number.isInteger(pid) || Number(pid) <= 0) return false; | ||
| try { | ||
| process.kill(Number(pid), 0); | ||
| return true; | ||
| } catch { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| export async function stopModelRouterProcess(pid: number, port: number): Promise<void> { | ||
| try { | ||
| process.kill(pid, "SIGTERM"); | ||
| } catch { | ||
| return; | ||
| } | ||
| for (let _attempt = 0; _attempt < 10; _attempt++) { | ||
| await new Promise((resolve) => setTimeout(resolve, 500)); | ||
| if (!isProcessRunning(pid) && !(await isRouterHealthy(port, 1000))) return; | ||
| } | ||
| try { | ||
| process.kill(pid, "SIGKILL"); | ||
| } catch { | ||
| // already stopped | ||
| } | ||
| for (let _attempt = 0; _attempt < 5; _attempt++) { | ||
| await new Promise((resolve) => setTimeout(resolve, 500)); | ||
| if (!isProcessRunning(pid) && !(await isRouterHealthy(port, 1000))) return; | ||
| } | ||
| } | ||
|
|
||
| export async function stopTrackedModelRouterForAgentChange( | ||
| session: Pick<Session, "routerPid"> | null, | ||
| port: number, | ||
| ): Promise<void> { | ||
| const recordedPid = session?.routerPid ?? null; | ||
| if (!recordedPid) return; | ||
| await stopModelRouterProcess(recordedPid, port); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.