Skip to content

Commit 732d697

Browse files
authored
fix: repair model provider edge cases
Repairs a batch of narrow model/provider edge cases: - honor OpenAI and Anthropic base URL environment overrides when provider config does not set an explicit base URL - preserve OpenRouter Anthropic cache retention while stripping unsupported transport options - allow apply_patch for non-OpenAI providers when the tool config otherwise permits it - prune stale same-provider model selections from configure/model picker state - expose GitHub Copilot bundled thinking policy metadata to offline/provider-policy lookups - repair additive SQLite shared-state upgrades for existing databases - keep same-size rotated log readers from reusing stale content in CI tooling Proof: - GitHub PR checks green on exact head 4651490 - Crabbox delegated Blacksmith Testbox tbx_01kt3em5r9vd7g0bnykrff6jdk exited 0 - Focused local Vitest/oxlint/format proof recorded in PR body and land-ready comment Fixes #80347. Fixes #88357. Fixes #45269. Supersedes #74427, #74432, #79370, #79894, #80366, and #88359.
1 parent 438eb26 commit 732d697

28 files changed

Lines changed: 1088 additions & 69 deletions
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { describe, expect, it } from "vitest";
2+
import { resolveThinkingProfile } from "./provider-policy-api.js";
3+
4+
describe("github-copilot provider-policy-api", () => {
5+
it("returns the base level set for non-xhigh GitHub Copilot models", () => {
6+
expect(
7+
resolveThinkingProfile({
8+
provider: "github-copilot",
9+
modelId: "claude-opus-4.6",
10+
})?.levels.map((level) => level.id),
11+
).toEqual(["off", "minimal", "low", "medium", "high"]);
12+
});
13+
14+
it("appends xhigh for current static GPT Copilot xhigh ids", () => {
15+
for (const modelId of ["gpt-5.4", "gpt-5.3-codex"]) {
16+
expect(
17+
resolveThinkingProfile({
18+
provider: "github-copilot",
19+
modelId,
20+
})?.levels.map((level) => level.id),
21+
`model=${modelId}`,
22+
).toContain("xhigh");
23+
}
24+
});
25+
26+
it("appends xhigh when catalog compat advertises it", () => {
27+
expect(
28+
resolveThinkingProfile({
29+
provider: "github-copilot",
30+
modelId: "future-copilot-model",
31+
compat: { supportedReasoningEfforts: ["low", "medium", "high", "xhigh"] },
32+
})?.levels.map((level) => level.id),
33+
).toContain("xhigh");
34+
});
35+
36+
it("appends xhigh for static Copilot metadata overrides", () => {
37+
expect(
38+
resolveThinkingProfile({
39+
provider: "github-copilot",
40+
modelId: "claude-opus-4.7-1m-internal",
41+
})?.levels.map((level) => level.id),
42+
).toContain("xhigh");
43+
});
44+
45+
it("normalizes the model id casing before xhigh membership checks", () => {
46+
expect(
47+
resolveThinkingProfile({
48+
provider: "github-copilot",
49+
modelId: "GPT-5.4",
50+
})?.levels.map((level) => level.id),
51+
).toContain("xhigh");
52+
});
53+
54+
it("returns null for non-GitHub Copilot providers", () => {
55+
expect(
56+
resolveThinkingProfile({
57+
provider: "openai",
58+
modelId: "gpt-5.4",
59+
}),
60+
).toBeNull();
61+
});
62+
});
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import type { ProviderDefaultThinkingPolicyContext } from "openclaw/plugin-sdk/core";
2+
import { normalizeOptionalLowercaseString } from "openclaw/plugin-sdk/string-coerce-runtime";
3+
import { resolveStaticCopilotModelOverride } from "./model-metadata.js";
4+
5+
const COPILOT_XHIGH_MODEL_IDS = ["gpt-5.4", "gpt-5.3-codex"] as const;
6+
7+
function compatSupportsXHigh(
8+
compat: { supportedReasoningEfforts?: readonly string[] | null } | null | undefined,
9+
) {
10+
return (
11+
Array.isArray(compat?.supportedReasoningEfforts) &&
12+
compat.supportedReasoningEfforts.some(
13+
(effort) => normalizeOptionalLowercaseString(effort) === "xhigh",
14+
)
15+
);
16+
}
17+
18+
export function resolveThinkingProfile(context: ProviderDefaultThinkingPolicyContext) {
19+
if (context.provider.trim().toLowerCase() !== "github-copilot") {
20+
return null;
21+
}
22+
const normalizedModelId = normalizeOptionalLowercaseString(context.modelId) ?? "";
23+
const staticCompat = resolveStaticCopilotModelOverride(normalizedModelId)?.compat;
24+
const modelSupportsXHigh =
25+
COPILOT_XHIGH_MODEL_IDS.includes(normalizedModelId as never) ||
26+
compatSupportsXHigh(context.compat) ||
27+
compatSupportsXHigh(staticCompat);
28+
29+
return {
30+
levels: [
31+
{ id: "off" as const },
32+
{ id: "minimal" as const },
33+
{ id: "low" as const },
34+
{ id: "medium" as const },
35+
{ id: "high" as const },
36+
...(modelSupportsXHigh ? [{ id: "xhigh" as const }] : []),
37+
],
38+
};
39+
}

‎extensions/openai/base-url.test.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import {
33
canonicalizeCodexResponsesBaseUrl,
44
isOpenAIApiBaseUrl,
55
isOpenAICodexBaseUrl,
6+
OPENAI_API_BASE_URL,
67
OPENAI_CODEX_RESPONSES_BASE_URL,
8+
resolveOpenAIDefaultBaseUrl,
79
} from "./base-url.js";
810

911
describe("openai base URL helpers", () => {
@@ -57,4 +59,12 @@ describe("openai base URL helpers", () => {
5759
);
5860
expect(canonicalizeCodexResponsesBaseUrl(undefined)).toBeUndefined();
5961
});
62+
63+
it("resolves default API base URL from OPENAI_BASE_URL", () => {
64+
expect(resolveOpenAIDefaultBaseUrl({})).toBe(OPENAI_API_BASE_URL);
65+
expect(resolveOpenAIDefaultBaseUrl({ OPENAI_BASE_URL: " " })).toBe(OPENAI_API_BASE_URL);
66+
expect(resolveOpenAIDefaultBaseUrl({ OPENAI_BASE_URL: " https://proxy.example/v1 " })).toBe(
67+
"https://proxy.example/v1",
68+
);
69+
});
6070
});

‎extensions/openai/base-url.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import { normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
22

33
export const OPENAI_CODEX_RESPONSES_BASE_URL = "https://chatgpt.com/backend-api/codex";
4+
export const OPENAI_API_BASE_URL = "https://api.openai.com/v1";
5+
6+
export function resolveOpenAIDefaultBaseUrl(
7+
env: Record<string, string | undefined> = process.env,
8+
): string {
9+
return normalizeOptionalString(env.OPENAI_BASE_URL) ?? OPENAI_API_BASE_URL;
10+
}
411

512
export function isOpenAIApiBaseUrl(baseUrl?: string): boolean {
613
const trimmed = normalizeOptionalString(baseUrl);

‎extensions/openai/openai-provider.ts‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ import {
1111
} from "openclaw/plugin-sdk/provider-model-shared";
1212
import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/string-coerce-runtime";
1313
import { OPENAI_ACCOUNT_WIZARD_GROUP, OPENAI_API_KEY_LABEL } from "./auth-choice-copy.js";
14-
import { isOpenAIApiBaseUrl, isOpenAICodexBaseUrl } from "./base-url.js";
14+
import {
15+
isOpenAIApiBaseUrl,
16+
isOpenAICodexBaseUrl,
17+
resolveOpenAIDefaultBaseUrl,
18+
} from "./base-url.js";
1519
import { applyOpenAIConfig, OPENAI_DEFAULT_MODEL } from "./default-models.js";
1620
import {
1721
buildOpenAIChatGPTAuthMethods,
@@ -203,7 +207,7 @@ function resolveOpenAIGptForwardCompatModel(ctx: ProviderResolveDynamicModelCont
203207
patch = {
204208
api: "openai-responses",
205209
provider: PROVIDER_ID,
206-
baseUrl: "https://api.openai.com/v1",
210+
baseUrl: resolveOpenAIDefaultBaseUrl(),
207211
reasoning: false,
208212
input: ["text", "image"],
209213
cost: OPENAI_CHAT_LATEST_COST,
@@ -215,7 +219,7 @@ function resolveOpenAIGptForwardCompatModel(ctx: ProviderResolveDynamicModelCont
215219
patch = {
216220
api: "openai-responses",
217221
provider: PROVIDER_ID,
218-
baseUrl: "https://api.openai.com/v1",
222+
baseUrl: resolveOpenAIDefaultBaseUrl(),
219223
reasoning: true,
220224
input: ["text", "image"],
221225
mediaInput: OPENAI_GPT_55_MEDIA_INPUT,
@@ -229,7 +233,7 @@ function resolveOpenAIGptForwardCompatModel(ctx: ProviderResolveDynamicModelCont
229233
patch = {
230234
api: "openai-responses",
231235
provider: PROVIDER_ID,
232-
baseUrl: "https://api.openai.com/v1",
236+
baseUrl: resolveOpenAIDefaultBaseUrl(),
233237
reasoning: true,
234238
input: ["text", "image"],
235239
cost: OPENAI_GPT_55_PRO_COST,
@@ -241,7 +245,7 @@ function resolveOpenAIGptForwardCompatModel(ctx: ProviderResolveDynamicModelCont
241245
patch = {
242246
api: "openai-responses",
243247
provider: PROVIDER_ID,
244-
baseUrl: "https://api.openai.com/v1",
248+
baseUrl: resolveOpenAIDefaultBaseUrl(),
245249
reasoning: true,
246250
input: ["text", "image"],
247251
cost: OPENAI_GPT_54_COST,
@@ -253,7 +257,7 @@ function resolveOpenAIGptForwardCompatModel(ctx: ProviderResolveDynamicModelCont
253257
patch = {
254258
api: "openai-responses",
255259
provider: PROVIDER_ID,
256-
baseUrl: "https://api.openai.com/v1",
260+
baseUrl: resolveOpenAIDefaultBaseUrl(),
257261
reasoning: true,
258262
input: ["text", "image"],
259263
cost: OPENAI_GPT_54_PRO_COST,
@@ -265,7 +269,7 @@ function resolveOpenAIGptForwardCompatModel(ctx: ProviderResolveDynamicModelCont
265269
patch = {
266270
api: "openai-responses",
267271
provider: PROVIDER_ID,
268-
baseUrl: "https://api.openai.com/v1",
272+
baseUrl: resolveOpenAIDefaultBaseUrl(),
269273
reasoning: true,
270274
input: ["text", "image"],
271275
cost: OPENAI_GPT_54_MINI_COST,
@@ -277,7 +281,7 @@ function resolveOpenAIGptForwardCompatModel(ctx: ProviderResolveDynamicModelCont
277281
patch = {
278282
api: "openai-responses",
279283
provider: PROVIDER_ID,
280-
baseUrl: "https://api.openai.com/v1",
284+
baseUrl: resolveOpenAIDefaultBaseUrl(),
281285
reasoning: true,
282286
input: ["text", "image"],
283287
cost: OPENAI_GPT_54_NANO_COST,

‎scripts/e2e/lib/incremental-line-reader.mjs‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { createHash } from "node:crypto";
12
import fs from "node:fs";
23

34
function readSlice(filePath, start, length) {
@@ -14,20 +15,43 @@ function readSlice(filePath, start, length) {
1415
}
1516
}
1617

18+
function readBufferSlice(filePath, start, length) {
19+
if (length <= 0) {
20+
return Buffer.alloc(0);
21+
}
22+
const fd = fs.openSync(filePath, "r");
23+
try {
24+
const buffer = Buffer.alloc(length);
25+
const bytesRead = fs.readSync(fd, buffer, 0, length, start);
26+
return buffer.subarray(0, bytesRead);
27+
} finally {
28+
fs.closeSync(fd);
29+
}
30+
}
31+
1732
function resolveFileIdentity(stats) {
1833
if (Number.isSafeInteger(stats.dev) && Number.isSafeInteger(stats.ino) && stats.ino !== 0) {
1934
return `${stats.dev}:${stats.ino}`;
2035
}
2136
return Number.isFinite(stats.birthtimeMs) ? `birth:${stats.birthtimeMs}` : undefined;
2237
}
2338

39+
function readTailFingerprint(filePath, stats, maxReadBytes) {
40+
const length = Math.min(stats.size, maxReadBytes);
41+
const start = Math.max(0, stats.size - length);
42+
const buffer = readBufferSlice(filePath, start, length);
43+
const hash = createHash("sha256").update(buffer).digest("base64url");
44+
return `${start}:${buffer.byteLength}:${hash}`;
45+
}
46+
2447
export function resolvePositiveInteger(value, fallback) {
2548
return Number.isSafeInteger(value) && value > 0 ? value : fallback;
2649
}
2750

2851
export function createIncrementalLineReader(filePath, options = {}) {
2952
const maxReadBytes = resolvePositiveInteger(options.maxReadBytes, 256 * 1024);
3053
let fileIdentity;
54+
let contentFingerprint;
3155
let offset = 0;
3256
let pending = "";
3357

@@ -55,6 +79,18 @@ export function createIncrementalLineReader(filePath, options = {}) {
5579
}
5680
fileIdentity = nextFileIdentity;
5781

82+
if (!reset && stats.size === offset && contentFingerprint !== undefined) {
83+
const nextContentFingerprint = readTailFingerprint(filePath, stats, maxReadBytes);
84+
if (contentFingerprint !== nextContentFingerprint) {
85+
offset = 0;
86+
pending = "";
87+
reset = true;
88+
} else {
89+
contentFingerprint = nextContentFingerprint;
90+
return { lines: [], reset: false };
91+
}
92+
}
93+
5894
if (stats.size < offset) {
5995
offset = 0;
6096
pending = "";
@@ -82,6 +118,7 @@ export function createIncrementalLineReader(filePath, options = {}) {
82118

83119
const text = readSlice(filePath, start, stats.size - start);
84120
offset = stats.size;
121+
contentFingerprint = readTailFingerprint(filePath, stats, maxReadBytes);
85122
if (!text) {
86123
return { lines: [], reset };
87124
}

‎src/agents/agent-tools-agent-config.test.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ describe("Agent-specific tool filtering", () => {
143143
expect(toolNames).toContain("read");
144144
expect(toolNames).toContain("write");
145145
expect(toolNames).not.toContain("exec");
146-
expect(toolNames).not.toContain("apply_patch");
146+
expect(toolNames).toContain("apply_patch");
147147
});
148148

149149
it("should keep global tool policy when agent only sets tools.elevated", () => {
@@ -164,7 +164,7 @@ describe("Agent-specific tool filtering", () => {
164164
expect(toolNames).toContain("exec");
165165
expect(toolNames).toContain("read");
166166
expect(toolNames).not.toContain("write");
167-
expect(toolNames).not.toContain("apply_patch");
167+
expect(toolNames).toContain("apply_patch");
168168
});
169169

170170
it("uses the configured default agent for lean local-model filtering on legacy session keys", () => {
@@ -687,7 +687,7 @@ describe("Agent-specific tool filtering", () => {
687687
expect(toolNames).not.toContain("browser");
688688
expect(toolNames).not.toContain("exec");
689689
expect(toolNames).not.toContain("process");
690-
expect(toolNames).not.toContain("apply_patch");
690+
expect(toolNames).toContain("apply_patch");
691691
});
692692

693693
it("should work with sandbox tools filtering", () => {

‎src/agents/agent-tools.create-openclaw-coding-tools.test.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ describe("createOpenClawCodingTools", () => {
762762
const defaultTools = createOpenClawCodingTools({ config: testConfig });
763763
expect(toolNameList(defaultTools)).toContain("exec");
764764
expect(toolNameList(defaultTools)).toContain("process");
765-
expect(toolNameList(defaultTools)).not.toContain("apply_patch");
765+
expect(toolNameList(defaultTools)).toContain("apply_patch");
766766

767767
const openAiTools = createOpenClawCodingTools({
768768
config: testConfig,
@@ -830,7 +830,7 @@ describe("createOpenClawCodingTools", () => {
830830
expect(names.has("read")).toBe(true);
831831
expect(names.has("write")).toBe(true);
832832
expect(names.has("edit")).toBe(true);
833-
expect(names.has("apply_patch")).toBe(false);
833+
expect(names.has("apply_patch")).toBe(true);
834834
});
835835

836836
it("provides top-level object schemas for all tools", () => {
@@ -875,7 +875,7 @@ describe("createOpenClawCodingTools", () => {
875875
expect(names.has("read")).toBe(true);
876876
expect(names.has("exec")).toBe(true);
877877
expect(names.has("process")).toBe(true);
878-
expect(names.has("apply_patch")).toBe(false);
878+
expect(names.has("apply_patch")).toBe(true);
879879
});
880880

881881
it("uses stored spawnDepth to apply leaf tool policy for flat depth-2 session keys", async () => {

‎src/agents/agent-tools.ts‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,6 @@ import {
110110
} from "./tool-search.js";
111111
import { resolveWorkspaceRoot } from "./workspace-dir.js";
112112

113-
function isOpenAIProvider(provider?: string) {
114-
const normalized = normalizeOptionalLowercaseString(provider);
115-
return normalized === "openai";
116-
}
117-
118113
const MEMORY_FLUSH_ALLOWED_TOOL_NAMES = new Set(["read", "write"]);
119114

120115
type GuardContainerMount = {
@@ -708,7 +703,6 @@ export function createOpenClawCodingTools(options?: {
708703
const applyPatchWorkspaceOnly = workspaceOnly || applyPatchConfig?.workspaceOnly !== false;
709704
const applyPatchEnabled =
710705
applyPatchConfig?.enabled !== false &&
711-
isOpenAIProvider(options?.modelProvider) &&
712706
isApplyPatchAllowedForModel({
713707
modelProvider: options?.modelProvider,
714708
modelId: options?.modelId,

0 commit comments

Comments
 (0)