Skip to content

Commit 7e2ebef

Browse files
committed
fix: close ambient owner fallback gaps
1 parent d267417 commit 7e2ebef

4 files changed

Lines changed: 79 additions & 6 deletions

File tree

‎src/infra/outbound/targets.test.ts‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,6 +1101,44 @@ describe("resolveSessionDeliveryTarget", () => {
11011101
).toHaveLength(1);
11021102
});
11031103

1104+
it("upgrades an owner-route setup shell with the selected agent runtime", () => {
1105+
const runtime = createOwnerAllowlistTargetTestPlugin({
1106+
id: "forum",
1107+
label: "Forum",
1108+
ownerId: "user:ops",
1109+
inferTargetChatType: () => "direct",
1110+
});
1111+
const setup = { ...runtime, outbound: undefined };
1112+
setActivePluginRegistry(createTargetsTestRegistry([setup]));
1113+
mocks.resolveOutboundChannelPlugin.mockImplementation(
1114+
({
1115+
channel,
1116+
agentId,
1117+
allowBootstrap,
1118+
}: {
1119+
channel: string;
1120+
agentId?: string;
1121+
allowBootstrap?: boolean;
1122+
}) => (channel === "forum" && agentId === "ops" && allowBootstrap === true ? runtime : setup),
1123+
);
1124+
const cfg = { channels: { forum: {} } } as OpenClawConfig;
1125+
1126+
const resolved = resolveHeartbeatDeliveryTarget({
1127+
cfg,
1128+
agentId: "ops",
1129+
heartbeat: { target: "owner" },
1130+
});
1131+
1132+
expect(resolved.channel).toBe("forum");
1133+
expect(resolved.to).toBe("user:ops");
1134+
expect(mocks.resolveOutboundChannelPlugin).toHaveBeenCalledWith({
1135+
channel: "forum",
1136+
cfg,
1137+
agentId: "ops",
1138+
allowBootstrap: true,
1139+
});
1140+
});
1141+
11041142
it("does not bypass target policy when bootstrapping plugin-channel heartbeat routes", () => {
11051143
const forum = createForumTargetTestPlugin();
11061144
setActivePluginRegistry(createTargetsTestRegistry([]));

‎src/infra/outbound/targets.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,8 @@ export function resolveHeartbeatDeliveryTarget(params: {
207207
const rawTarget = heartbeat?.target;
208208
const implicitDefaultRoute = rawTarget === undefined;
209209
let target = implicitDefaultRoute ? "owner" : "none";
210-
let preparedExplicitPlugin: ChannelPlugin | undefined, preparedExplicitTo: string | undefined;
210+
let preparedExplicitPlugin: ChannelPlugin | undefined;
211+
let preparedExplicitTo: string | undefined;
211212
if (rawTarget === "none" || rawTarget === "last" || rawTarget === "owner") {
212213
target = rawTarget;
213214
} else if (typeof rawTarget === "string") {
@@ -309,15 +310,14 @@ export function resolveHeartbeatDeliveryTarget(params: {
309310

310311
// Bootstrap once after a concrete route exists, then carry the prepared plugin
311312
// through account validation, target policy, and allow-from comparison.
313+
const preparedPlugin = preparedExplicitPlugin ?? ownerRoute?.plugin;
312314
const plugin =
313-
preparedExplicitPlugin ??
314-
ownerRoute?.plugin ??
315315
resolveOutboundChannelPlugin({
316316
channel: resolvedTarget.channel,
317317
cfg,
318318
agentId: params.agentId,
319319
allowBootstrap: true,
320-
});
320+
}) ?? preparedPlugin;
321321

322322
if (heartbeatAccountId) {
323323
const listAccountIds = plugin?.config.listAccountIds;

‎src/model-catalog/pricing.test.ts‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,40 @@ describe("hosted model pricing", () => {
232232
expect(() => resolveModelCostConfigFingerprint(config)).not.toThrow();
233233
});
234234

235+
it("keeps optional pricing non-throwing without an ambient agent owner", () => {
236+
const config = {
237+
agents: {
238+
ownership: "explicit",
239+
entries: { main: {}, other: {} },
240+
},
241+
models: {
242+
providers: {
243+
fixture: {
244+
baseUrl: "https://fixture.invalid",
245+
models: [
246+
{
247+
id: "priced",
248+
name: "Priced",
249+
cost: { input: 1, output: 2, cacheRead: 0, cacheWrite: 0 },
250+
},
251+
],
252+
},
253+
},
254+
},
255+
} as unknown as OpenClawConfig;
256+
257+
expect(resolveModelCostConfig({ config, provider: "fixture", model: "priced" })).toEqual({
258+
input: 1,
259+
output: 2,
260+
cacheRead: 0,
261+
cacheWrite: 0,
262+
});
263+
expect(
264+
resolveModelCostConfig({ config, provider: "fixture", model: "missing" }),
265+
).toBeUndefined();
266+
expect(() => resolveModelCostConfigFingerprint(config)).not.toThrow();
267+
});
268+
235269
it("bounds fingerprints for multi-megabyte hosted pricing catalogs", () => {
236270
const pricing = Object.fromEntries(
237271
Array.from({ length: 40_000 }, (_, index) => [

‎src/utils/usage-format.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { normalizeOptionalString } from "@openclaw/normalization-core/string-coe
99
import {
1010
listAgentEntries,
1111
resolveAgentDir,
12-
resolveDefaultAgentId,
12+
tryResolveDefaultAgentId,
1313
} from "../agents/agent-scope-config.js";
1414
import { modelKey, normalizeModelRef, normalizeProviderId } from "../agents/model-selection.js";
1515
import type { NormalizedUsage } from "../agents/usage.js";
@@ -317,7 +317,8 @@ function resolveCostAgentDir(config?: OpenClawConfig, agentDir?: string): string
317317
return agentDir;
318318
}
319319
if (config && listAgentEntries(config).length > 0) {
320-
return resolveAgentDir(config, resolveDefaultAgentId(config));
320+
const defaultAgentId = tryResolveDefaultAgentId(config);
321+
return defaultAgentId ? resolveAgentDir(config, defaultAgentId) : undefined;
321322
}
322323
// Config-less and pricing-only lookups are shipped APIs for the historical
323324
// main models.json. Full runtime configs resolve their roster default above.

0 commit comments

Comments
 (0)