Skip to content

Commit b6eee72

Browse files
authored
fix: models status skips refresh with matching agent directory override (#134862)
* fix: models status skips refresh with matching agent directory override * test: preserve status override checks with owner resolution * test(models): assert owner registration for status overrides
1 parent e2eb6a6 commit b6eee72

4 files changed

Lines changed: 75 additions & 6 deletions

File tree

‎docs/cli/models.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ openclaw models set-image <model-or-alias>
2828
openclaw models scan
2929
```
3030

31-
`status`, `list`, and `auth` subcommands accept `--agent <id>` to target a configured agent; `fallbacks`/`image-fallbacks` always use the configured default agent, and `set`, `set-image`, `scan`, `refresh`, and `aliases` reject `--agent` outright because they are global and never agent-scoped. When omitted, `--agent`-aware commands use `OPENCLAW_AGENT_DIR` if set, otherwise the configured default agent.
31+
`status`, `list`, and `auth` subcommands accept `--agent <id>` to target a configured agent. Without it, model inspection uses `agents.defaults.systemAgent.agentId` when configured, otherwise the sole configured agent. Auth mutations require `--agent <id>` when multiple agents are configured.
32+
33+
For `models status`, `OPENCLAW_AGENT_DIR` overrides the inspected auth directory when `--agent` is omitted. A matching configured `agentDir` retains that agent's ownership during credential refresh. An explicit `--agent <id>` takes precedence over the environment override.
34+
35+
`fallbacks`/`image-fallbacks` manage global defaults. `set`, `set-image`, `scan`, `refresh`, and `aliases` also operate globally and reject `--agent`.
3236

3337
`models set` and `models set-image` require the provider to be declared by an installed plugin or configured under `models.providers`. An unknown provider exits nonzero without changing config. If the provider is known but the model is absent from the local catalog, the command saves the selection and prints a warning because newly released and self-hosted models may not be cataloged yet. `openclaw doctor --json` reports configured unknown providers; add `--severity-min info` to also see active models that the local catalog cannot confirm.
3438

‎src/commands/models/list.status.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,7 @@ describe("modelsStatusCommand auth overview", () => {
928928
await modelsStatusCommand({ json: true }, localRuntime as never);
929929
});
930930

931-
expect(mocks.resolveAgentDir).not.toHaveBeenCalled();
931+
expectResolveAgentDirCalledFor("main");
932932
expect(mocks.ensureAuthProfileStore).toHaveBeenCalledWith("/tmp/openclaw-isolated-agent");
933933
const payload = parseFirstJsonLog(localRuntime);
934934
expect(payload.agentDir).toBe("/tmp/openclaw-isolated-agent");
@@ -948,7 +948,7 @@ describe("modelsStatusCommand auth overview", () => {
948948
},
949949
);
950950

951-
expect(mocks.resolveAgentDir).not.toHaveBeenCalled();
951+
expectResolveAgentDirCalledFor("main");
952952
expect(mocks.ensureAuthProfileStore).toHaveBeenCalledWith("/tmp/openclaw-legacy-agent");
953953
const payload = parseFirstJsonLog(localRuntime);
954954
expect(payload.agentDir).toBe("/tmp/openclaw-legacy-agent");
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { describe, expect, it } from "vitest";
2+
import { unregisterResolvedAgentDir } from "../../agents/agent-dir-registry.js";
3+
import {
4+
readPersistedAuthProfileStateRaw,
5+
resolveAuthProfileDatabasePath,
6+
writePersistedAuthProfileStateRaw,
7+
} from "../../agents/auth-profiles/sqlite.js";
8+
import { openOpenClawAgentDatabase } from "../../state/openclaw-agent-db.js";
9+
import { withOpenClawTestState } from "../../test-utils/openclaw-test-state.js";
10+
import { resolveModelsTargetAgent } from "./shared.js";
11+
12+
describe("model inspection auth store ownership", () => {
13+
it("retains the configured owner when a read override selects the same custom directory", async () => {
14+
await withOpenClawTestState({ label: "models-custom-owner" }, async (state) => {
15+
const agentId = "helper";
16+
const agentDir = state.statePath("agents", agentId);
17+
const cfg = {
18+
agents: { ownership: "explicit" as const, entries: { [agentId]: { agentDir } } },
19+
};
20+
openOpenClawAgentDatabase({ agentId, path: resolveAuthProfileDatabasePath(agentDir) });
21+
try {
22+
const target = resolveModelsTargetAgent(cfg, undefined, {
23+
kind: "read",
24+
agentDirOverride: agentDir,
25+
});
26+
const authState = { version: 1, lastGood: { anthropic: "anthropic:local" } };
27+
28+
writePersistedAuthProfileStateRaw(authState, target.agentDir);
29+
30+
expect(target).toEqual({ agentId, agentDir });
31+
expect(readPersistedAuthProfileStateRaw(agentDir)).toEqual(authState);
32+
} finally {
33+
unregisterResolvedAgentDir({ agentId, agentDir });
34+
}
35+
});
36+
});
37+
38+
it("preserves an unrelated override without assigning it the configured agent's ownership", async () => {
39+
await withOpenClawTestState({ label: "models-override-owner" }, async (state) => {
40+
const agentId = "helper";
41+
const agentDir = state.statePath("agents", agentId);
42+
const overrideDir = state.statePath("separate-auth");
43+
const cfg = {
44+
agents: { ownership: "explicit" as const, entries: { [agentId]: { agentDir } } },
45+
};
46+
openOpenClawAgentDatabase({
47+
agentId: "separate-owner",
48+
path: resolveAuthProfileDatabasePath(overrideDir),
49+
});
50+
try {
51+
const target = resolveModelsTargetAgent(cfg, undefined, {
52+
kind: "read",
53+
agentDirOverride: overrideDir,
54+
});
55+
56+
expect(target).toEqual({ agentId, agentDir: overrideDir });
57+
expect(() => writePersistedAuthProfileStateRaw({ version: 1 }, target.agentDir)).toThrow(
58+
/requested agent custom-/,
59+
);
60+
} finally {
61+
unregisterResolvedAgentDir({ agentId, agentDir });
62+
}
63+
});
64+
});
65+
});

‎src/commands/models/shared.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ function resolveKnownAgentId(cfg: OpenClawConfig, rawAgentId: string): string {
148148

149149
type ModelsTargetMode = { kind: "read"; agentDirOverride?: string } | { kind: "mutation" };
150150

151-
/** Resolves the selected model-command agent and its profile directory. */
151+
/** Resolves model-command scope and retains configured auth ownership through read overrides. */
152152
export function resolveModelsTargetAgent(
153153
cfg: OpenClawConfig,
154154
rawAgentId: string | undefined,
@@ -172,8 +172,8 @@ export function resolveModelsTargetAgent(
172172
resolveSoleAgentId(cfg, { surface: "the model command", hint: "Pass --agent <id>." }));
173173
const agentId = resolveKnownAgentId(cfg, resolvedAgentId);
174174
const agentDirOverride = mode.kind === "read" ? mode.agentDirOverride : undefined;
175-
const agentDir = agentDirOverride ?? resolveAgentDir(cfg, agentId);
176-
return { agentId, agentDir };
175+
const agentDir = resolveAgentDir(cfg, agentId);
176+
return { agentId, agentDir: agentDirOverride ?? agentDir };
177177
}
178178

179179
/** Normalized primary/fallback config shape used by text and image defaults. */

0 commit comments

Comments
 (0)