Skip to content

Commit cf8b58c

Browse files
authored
refactor(models): simplify picker and thinking projections (#130694)
* refactor(models): simplify picker and thinking projections * fix(doctor): keep bundled checks in the host health registry * test(doctor): consolidate repeated lint invocation * docs: keep Doctor release context in the PR body
1 parent 0b0cff1 commit cf8b58c

15 files changed

Lines changed: 183 additions & 222 deletions

‎extensions/codex/api.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const CODEX_PLUGIN_ROOT = path.dirname(fileURLToPath(import.meta.url));
1111
export { CODEX_MANAGED_APP_SERVER_CHECK_ID };
1212

1313
export function registerCodexManagedAppServerDoctorChecks(host: {
14+
getHealthCheck(id: string): HealthCheck | undefined;
1415
registerHealthCheck(check: HealthCheck): void;
1516
}): void {
1617
registerChecks({ ...host, pluginRoot: CODEX_PLUGIN_ROOT });

‎extensions/codex/src/doctor.test.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ function createCheck(deps: ReturnType<typeof managedDeps>) {
7878
registerCodexManagedAppServerDoctorChecks(
7979
{
8080
pluginRoot: "/candidate/plugin",
81+
getHealthCheck: () => check,
8182
registerHealthCheck(value) {
8283
check = value;
8384
},
@@ -91,6 +92,25 @@ function createCheck(deps: ReturnType<typeof managedDeps>) {
9192
}
9293

9394
describe("managed Codex doctor check", () => {
95+
it("registers once in each host registry", () => {
96+
for (let index = 0; index < 2; index++) {
97+
let check: HealthCheck | undefined;
98+
const host = {
99+
pluginRoot: "/candidate/plugin",
100+
getHealthCheck: () => check,
101+
registerHealthCheck: vi.fn((value: HealthCheck) => {
102+
check = value;
103+
}),
104+
};
105+
106+
registerCodexManagedAppServerDoctorChecks(host);
107+
registerCodexManagedAppServerDoctorChecks(host);
108+
109+
expect(host.registerHealthCheck).toHaveBeenCalledOnce();
110+
expect(check?.id).toBe(CODEX_MANAGED_APP_SERVER_CHECK_ID);
111+
}
112+
});
113+
94114
it("accepts the exact pinned native binary without changing explicit long-context config", async () => {
95115
const cfg = config();
96116
const before = structuredClone(cfg);

‎extensions/codex/src/doctor.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { execFile } from "node:child_process";
22
import { resolveDefaultModelForAgent } from "openclaw/plugin-sdk/agent-runtime";
33
import { listAgentIds, resolveAgentDir } from "openclaw/plugin-sdk/agent-scope-runtime";
44
import { resolveEffectiveAgentRuntime } from "openclaw/plugin-sdk/command-auth-native";
5-
import { getHealthCheck, type HealthCheck, type HealthFinding } from "openclaw/plugin-sdk/health";
5+
import type { HealthCheck, HealthFinding } from "openclaw/plugin-sdk/health";
66
import {
77
resolveCodexAppServerRuntimeOptions,
88
resolveCodexAppServerStartOptionsForAgent,
@@ -32,6 +32,7 @@ type CodexManagedDoctorDependencies = {
3232
};
3333

3434
type CodexManagedDoctorRegistrationHost = {
35+
readonly getHealthCheck: (id: string) => HealthCheck | undefined;
3536
readonly registerHealthCheck: (check: HealthCheck) => void;
3637
readonly pluginRoot: string;
3738
};
@@ -207,7 +208,8 @@ export function registerCodexManagedAppServerDoctorChecks(
207208
host: CodexManagedDoctorRegistrationHost,
208209
deps?: CodexManagedDoctorDependencies,
209210
): void {
210-
if (getHealthCheck(CODEX_MANAGED_APP_SERVER_CHECK_ID)) {
211+
// Lookup and registration must use the same host registry across artifact loaders.
212+
if (host.getHealthCheck(CODEX_MANAGED_APP_SERVER_CHECK_ID)) {
211213
return;
212214
}
213215
host.registerHealthCheck(

‎extensions/crabbox/doctor-health-api.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const CRABBOX_PLUGIN_ROOT = path.dirname(fileURLToPath(import.meta.url));
1212
export { CRABBOX_CLOUD_WORKER_PROFILE_CHECK_ID };
1313

1414
export function registerWorkerProviderDoctorChecks(host: {
15+
getHealthCheck(id: string): HealthCheck | undefined;
1516
registerHealthCheck(check: HealthCheck): void;
1617
}): void {
1718
registerChecks({

‎extensions/crabbox/src/doctor.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ function captureCrabboxDoctorCheck(): HealthCheck {
1313
let check: HealthCheck | undefined;
1414
registerCrabboxWorkerProviderDoctorChecks({
1515
openclawRoot: OPENCLAW_ROOT,
16+
getHealthCheck: () => check,
1617
registerHealthCheck(value) {
1718
check = value;
1819
},

‎extensions/crabbox/src/doctor.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getHealthCheck, type HealthCheck, type HealthFinding } from "openclaw/plugin-sdk/health";
1+
import type { HealthCheck, HealthFinding } from "openclaw/plugin-sdk/health";
22
import {
33
asOptionalRecord as readRecord,
44
normalizeOptionalString as nonEmptyString,
@@ -10,6 +10,7 @@ export const CRABBOX_CLOUD_WORKER_PROFILE_CHECK_ID = "crabbox/cloud-worker-profi
1010

1111
type CrabboxDoctorRegistrationHost = {
1212
readonly openclawRoot: string;
13+
readonly getHealthCheck: (id: string) => HealthCheck | undefined;
1314
readonly registerHealthCheck: (check: HealthCheck) => void;
1415
};
1516

@@ -111,7 +112,8 @@ function createCrabboxCloudWorkerProfileCheck(openclawRoot: string): HealthCheck
111112
export function registerCrabboxWorkerProviderDoctorChecks(
112113
host: CrabboxDoctorRegistrationHost,
113114
): void {
114-
if (getHealthCheck(CRABBOX_CLOUD_WORKER_PROFILE_CHECK_ID)) {
115+
// Lookup and registration must use the same host registry across artifact loaders.
116+
if (host.getHealthCheck(CRABBOX_CLOUD_WORKER_PROFILE_CHECK_ID)) {
115117
return;
116118
}
117119
host.registerHealthCheck(createCrabboxCloudWorkerProfileCheck(host.openclawRoot));

‎src/commands/doctor-lint.test.ts‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -451,12 +451,13 @@ describe("runDoctorLintCli", () => {
451451
});
452452
const stdout = vi.spyOn(process.stdout, "write").mockImplementation(() => true);
453453
try {
454-
const exitCode = await runDoctorLintCli(runtime, {
455-
json: true,
456-
onlyIds: [CRABBOX_CLOUD_WORKER_PROFILE_CHECK_ID],
457-
});
458-
459-
expect(exitCode).toBe(1);
454+
for (let run = 0; run < 2; run++) {
455+
const exitCode = await runDoctorLintCli(runtime, {
456+
json: true,
457+
onlyIds: [CRABBOX_CLOUD_WORKER_PROFILE_CHECK_ID],
458+
});
459+
expect(exitCode).toBe(1);
460+
}
460461
const payload = JSON.parse(String(stdout.mock.calls.at(-1)?.[0]));
461462
expect(payload).toMatchObject({
462463
ok: false,

‎src/flows/bundled-health-checks.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ describe("registerBundledHealthChecks", () => {
339339
artifactCandidates: ["doctor-health-api.js"],
340340
});
341341
expect(mocks.registerWorkerProviderDoctorChecks).toHaveBeenCalledWith({
342+
getHealthCheck: expect.any(Function),
342343
registerHealthCheck: expect.any(Function),
343344
});
344345
});
@@ -373,6 +374,7 @@ describe("registerBundledHealthChecks", () => {
373374
artifactBasename: "api.js",
374375
});
375376
expect(mocks.registerCodexManagedAppServerDoctorChecks).toHaveBeenCalledWith({
377+
getHealthCheck: expect.any(Function),
376378
registerHealthCheck: expect.any(Function),
377379
});
378380
});

‎src/flows/bundled-health-checks.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type EmbeddingProviderSetupInspectionResult =
2626
// Bridges bundled plugin doctor checks into the core health registry.
2727
type BundledHealthApi = {
2828
registerCodexManagedAppServerDoctorChecks?: (host: {
29+
getHealthCheck: typeof getHealthCheck;
2930
registerHealthCheck: typeof registerHealthCheck;
3031
}) => void;
3132
pluginStateIsolatedDoctorCheckIds?: readonly string[];
@@ -45,6 +46,7 @@ type BundledHealthApi = {
4546

4647
type WorkerProviderHealthApi = {
4748
registerWorkerProviderDoctorChecks?: (host: {
49+
getHealthCheck: typeof getHealthCheck;
4850
registerHealthCheck: typeof registerHealthCheck;
4951
}) => void;
5052
};
@@ -127,7 +129,7 @@ export function registerBundledHealthChecks(params: {
127129
loadBundledPluginPublicArtifactModuleSync<BundledHealthApi>({
128130
dirName: "codex",
129131
artifactBasename: "api.js",
130-
}).registerCodexManagedAppServerDoctorChecks?.({ registerHealthCheck });
132+
}).registerCodexManagedAppServerDoctorChecks?.({ getHealthCheck, registerHealthCheck });
131133
}
132134
if (shouldRegisterPolicyHealth(params)) {
133135
loadBundledPluginPublicArtifactModuleSync<BundledHealthApi>({
@@ -160,7 +162,7 @@ function registerBundledWorkerProviderHealthChecks(
160162
loadBundledPluginPublicArtifactModuleFromCandidatesSync<WorkerProviderHealthApi>({
161163
dirName: pluginId,
162164
artifactCandidates: ["doctor-health-api.js"],
163-
})?.registerWorkerProviderDoctorChecks?.({ registerHealthCheck });
165+
})?.registerWorkerProviderDoctorChecks?.({ getHealthCheck, registerHealthCheck });
164166
}
165167
}
166168

‎src/gateway/session-utils-model.ts‎

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -179,34 +179,11 @@ export function resolveGatewayModelThinkingProfile(params: {
179179
sessionKey: params.sessionKey,
180180
});
181181
const thinkingPolicyProvider = params.thinkingPolicyProvider ?? params.provider;
182-
if (!params.rowContext) {
183-
return {
184-
thinkingLevels: listGatewayThinkingLevelOptions({
185-
provider: thinkingPolicyProvider,
186-
model: params.model,
187-
modelCatalog: params.modelCatalog,
188-
agentRuntime,
189-
configuredReasoning: params.configuredReasoning,
190-
providerPolicySource: params.providerPolicySource,
191-
}),
192-
thinkingDefault: resolveGatewaySessionThinkingDefault({
193-
cfg: params.cfg,
194-
provider: params.provider,
195-
thinkingPolicyProvider,
196-
model: params.model,
197-
agentId: params.agentId,
198-
modelCatalog: params.modelCatalog,
199-
agentRuntime,
200-
configuredReasoning: params.configuredReasoning,
201-
providerPolicySource: params.providerPolicySource,
202-
}),
203-
};
204-
}
205182
const key = `${normalizeAgentId(params.agentId)}\0${agentRuntime}\0${normalizeLowercaseStringOrEmpty(thinkingPolicyProvider)}\0${String(params.configuredReasoning)}\0${params.providerPolicySource ?? "active-or-bundled"}\0${createSessionRowModelCacheKey(
206183
params.provider,
207184
params.model,
208185
)}`;
209-
const cached = params.rowContext.thinkingMetadataByModelRef.get(key);
186+
const cached = params.rowContext?.thinkingMetadataByModelRef.get(key);
210187
if (cached) {
211188
return cached;
212189
}
@@ -231,7 +208,7 @@ export function resolveGatewayModelThinkingProfile(params: {
231208
providerPolicySource: params.providerPolicySource,
232209
}),
233210
};
234-
params.rowContext.thinkingMetadataByModelRef.set(key, metadata);
211+
params.rowContext?.thinkingMetadataByModelRef.set(key, metadata);
235212
return metadata;
236213
}
237214

0 commit comments

Comments
 (0)