Skip to content

Commit d713179

Browse files
Merge upstream/main into feat/abort-r1-gateway-a-openrouter
Conflict resolution (src/api/providers/openrouter.ts): this unit wraps the whole createMessage body in a per-request AbortController try/finally, which re-indents every line, so git could not combine it with #2271's edits inside the same body and emitted a block that duplicated the body. Resolution keeps this unit's structure (controller + external-signal bridge + fail-fast + rejectOnAbort(fetchModel) + per-yield/finally abort guards) and re-applies upstream's prompt-cache TTL change on top of it: addAnthropicCacheBreakpoints(systemPrompt, openAiMessages, resolveCacheTtl(this.options, model.info)) plus the Gemini no-TTL rationale comment. The resolveCacheTtl import and the upstream 'prompt cache TTL' describe block in src/api/providers/__tests__/openrouter.spec.ts (3 tests) merged cleanly and are kept. Local verification on the merged tree: - parse-check OK: openrouter.ts, openrouter.spec.ts, api/index.ts, api/transform/caching/anthropic.ts, api/transform/caching/ttl.ts - tsc --noEmit (cwd src): 0 errors - vitest run: 4 files / 198 tests passed (openrouter, abort-signal, request-timeout, error-handler) - eslint --max-warnings=0 clean on openrouter.ts, openrouter.spec.ts, test-utils/promise.ts - prettier --check clean (openrouter.ts re-wrapped by prettier after the merge) - eslint suppressions: no count increased; file-wide total 3505 -> 3271 @coderabbitai resolve
2 parents 63c562d + 3ee042d commit d713179

415 files changed

Lines changed: 9261 additions & 9893 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/code-qa.yml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ jobs:
7070
install-args: "--frozen-lockfile"
7171
- name: Verify all translations are complete
7272
run: node scripts/find-missing-translations.js
73+
- name: Verify t() calls pass every interpolation variable
74+
run: node scripts/check-i18n-interpolation.js
7375

7476
knip:
7577
runs-on: ubuntu-latest

‎.github/workflows/solheim-provider-smoke.yml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ jobs:
4141
pnpm --filter @roo-code/vscode-webview build
4242
4343
- name: Install display dependencies
44+
timeout-minutes: 5
4445
run: sudo apt-get update && sudo apt-get install -y xvfb ffmpeg libasound2t64
4546

4647
- name: Run Solheim provider smoke
@@ -73,6 +74,7 @@ jobs:
7374
path: |
7475
${{ runner.temp }}/solheim-provider-smoke/verdict.json
7576
${{ runner.temp }}/solheim-provider-smoke/trace.json
77+
${{ runner.temp }}/solheim-provider-smoke/sidebar-focus.json
7678
if-no-files-found: error
7779
retention-days: 7
7880

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// i18next splits a namespace from a key on ":" only. t("chat.foo") has no namespace, so it looks in the
2+
// default namespace, misses, and shows the raw key to the user. Built-in no-restricted-syntax only.
3+
import { readdirSync } from "node:fs"
4+
import { basename } from "node:path"
5+
6+
/**
7+
* @param {URL | string} enLocalesDir The `en` locale directory. Each JSON file name is a namespace.
8+
*/
9+
export function createI18nDotKeyConfig(enLocalesDir) {
10+
const namespaces = readdirSync(enLocalesDir)
11+
.filter((file) => file.endsWith(".json"))
12+
.map((file) => basename(file, ".json"))
13+
const dotKey = `/^(${namespaces.join("|")})\\./`
14+
const message = "Write the key as 'namespace:path'. A dot after the namespace is not a namespace separator."
15+
16+
return {
17+
files: ["**/*.ts", "**/*.tsx"],
18+
ignores: ["**/__tests__/**", "**/*.test.ts", "**/*.test.tsx", "**/*.spec.ts", "**/*.spec.tsx"],
19+
rules: {
20+
"no-restricted-syntax": [
21+
"error",
22+
...i18nDotKeySelectors(dotKey).map((selector) => ({ selector, message })),
23+
],
24+
},
25+
}
26+
}
27+
28+
/** The selectors alone, for a file set that already sets no-restricted-syntax. */
29+
export function getI18nDotKeySelectors(config) {
30+
return config.rules["no-restricted-syntax"].slice(1)
31+
}
32+
33+
function i18nDotKeySelectors(dotKey) {
34+
const call = "CallExpression:matches([callee.name='t'], [callee.property.name='t'])"
35+
return [`${call}[arguments.0.value=${dotKey}]`, `${call}[arguments.0.quasis.0.value.cooked=${dotKey}]`]
36+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import assert from "node:assert/strict"
2+
import { describe, it } from "node:test"
3+
import { URL } from "node:url"
4+
5+
import { Linter } from "eslint"
6+
import typescriptEslint from "typescript-eslint"
7+
8+
import { createI18nDotKeyConfig } from "./i18n-keys.js"
9+
10+
const linter = new Linter({ configType: "flat" })
11+
const config = [
12+
{ files: ["**/*.ts", "**/*.tsx"], languageOptions: { parser: typescriptEslint.parser } },
13+
createI18nDotKeyConfig(new URL("../../webview-ui/src/i18n/locales/en", import.meta.url)),
14+
]
15+
16+
const lint = (code, filename = "components/example.tsx") =>
17+
linter.verify(code, config, { filename }).map((message) => message.message)
18+
19+
describe("i18n dot-form keys", () => {
20+
for (const code of [
21+
't("chat.commandExecution.exitStatus", { exitCode })',
22+
'i18next.t("settings.autoApprove.title")',
23+
"t(`chat.errors.${name}`)",
24+
"t(`chat\\u002ecommandExecution.exitStatus`)",
25+
]) {
26+
it(`flags: ${code}`, () => {
27+
assert.equal(lint(code).length, 1)
28+
})
29+
}
30+
31+
for (const code of [
32+
't("chat:commandExecution.exitStatus", { exitCode })',
33+
't("unknownNamespace.key")',
34+
"t(`chat:errors.${name}`)",
35+
]) {
36+
it(`allows: ${code}`, () => {
37+
assert.deepEqual(lint(code), [])
38+
})
39+
}
40+
41+
it("does not apply to spec files", () => {
42+
assert.deepEqual(lint('t("chat.key")', "components/__tests__/example.spec.tsx"), [])
43+
})
44+
})

‎packages/config-eslint/package.json‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
"./react": "./react.js",
88
"./next-js": "./next.js",
99
"./provider-identifiers": "./provider-identifiers.js",
10-
"./api-provider-hygiene": "./api-provider-hygiene.js"
10+
"./api-provider-hygiene": "./api-provider-hygiene.js",
11+
"./i18n-keys": "./i18n-keys.js"
1112
},
1213
"scripts": {
1314
"lint": "eslint . --max-warnings=0",
14-
"test": "node --test provider-identifiers.test.js api-provider-hygiene.test.js"
15+
"test": "node --test provider-identifiers.test.js api-provider-hygiene.test.js i18n-keys.test.js"
1516
},
1617
"devDependencies": {
1718
"@eslint/js": "9.39.5",
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// npx vitest run src/__tests__/cache-write-ttl-pricing.test.ts
2+
3+
import { describe, it, expect } from "vitest"
4+
5+
import { anthropicModels } from "../providers/anthropic.js"
6+
import { bedrockModels } from "../providers/bedrock.js"
7+
import { openAiNativeModels } from "../providers/openai.js"
8+
import {
9+
CACHE_WRITE_MULTIPLIER_12H,
10+
CACHE_WRITE_MULTIPLIER_1H,
11+
deriveCacheWritesPrice12h,
12+
deriveCacheWritesPrice1h,
13+
type ModelInfo,
14+
} from "../model.js"
15+
16+
/**
17+
* Catalog invariant for the TTL accounting program (ADR-0006 phase 1).
18+
*
19+
* A model that advertises prompt caching on a provider which can report a
20+
* long-lived cache write must carry the matching per-TTL write rate. Without it
21+
* the cost layer can only fall back to the aggregate write rate, which
22+
* under-reports every long-lived write (37.5% for Anthropic 1h, 50% for OpenAI 12h).
23+
*/
24+
describe("cache-write TTL pricing catalog invariant", () => {
25+
const anthropicFamilyEntries = Object.entries(anthropicModels as Record<string, ModelInfo>)
26+
27+
const bedrockAnthropicEntries = Object.entries(bedrockModels as Record<string, ModelInfo>).filter(([id]) =>
28+
id.startsWith("anthropic."),
29+
)
30+
31+
const openAiLongLivedEntries = Object.entries(openAiNativeModels as Record<string, ModelInfo>).filter(
32+
([id]) => id.startsWith("gpt-5.6") || id.startsWith("gpt-6"),
33+
)
34+
35+
it("every Anthropic catalog entry with prompt caching defines cacheWritesPrice1h", () => {
36+
const missing = anthropicFamilyEntries
37+
.filter(([, info]) => info.supportsPromptCache && info.cacheWritesPrice1h === undefined)
38+
.map(([id]) => id)
39+
40+
expect(missing).toEqual([])
41+
})
42+
43+
it("every Bedrock Anthropic-family entry with prompt caching defines cacheWritesPrice1h", () => {
44+
const missing = bedrockAnthropicEntries
45+
.filter(([, info]) => info.supportsPromptCache && info.cacheWritesPrice1h === undefined)
46+
.map(([id]) => id)
47+
48+
expect(missing).toEqual([])
49+
})
50+
51+
it("every OpenAI 5.6/6-class entry defines cacheWritesPrice12h", () => {
52+
expect(openAiLongLivedEntries.length).toBeGreaterThan(0)
53+
54+
const missing = openAiLongLivedEntries
55+
.filter(([, info]) => info.supportsPromptCache && info.cacheWritesPrice12h === undefined)
56+
.map(([id]) => id)
57+
58+
expect(missing).toEqual([])
59+
})
60+
61+
it("Anthropic 1h rates match the documented 2x input-price relationship", () => {
62+
for (const [id, info] of anthropicFamilyEntries) {
63+
if (info.cacheWritesPrice1h === undefined || info.inputPrice === undefined) continue
64+
expect(info.cacheWritesPrice1h, id).toBeCloseTo(info.inputPrice * CACHE_WRITE_MULTIPLIER_1H, 9)
65+
}
66+
})
67+
68+
it("OpenAI 12h rates match the documented 2.5x input-price relationship", () => {
69+
for (const [id, info] of openAiLongLivedEntries) {
70+
if (info.cacheWritesPrice12h === undefined || info.inputPrice === undefined) continue
71+
expect(info.cacheWritesPrice12h, id).toBeCloseTo(info.inputPrice * CACHE_WRITE_MULTIPLIER_12H, 9)
72+
}
73+
})
74+
75+
it("deriveCacheWritesPrice1h scales inputPrice by 2x and stays undefined without one", () => {
76+
expect(deriveCacheWritesPrice1h(3.0)).toBe(6.0)
77+
expect(deriveCacheWritesPrice1h(undefined)).toBeUndefined()
78+
})
79+
80+
it("deriveCacheWritesPrice12h scales inputPrice by 2.5x and stays undefined without one", () => {
81+
expect(deriveCacheWritesPrice12h(4.0)).toBe(10.0)
82+
expect(deriveCacheWritesPrice12h(undefined)).toBeUndefined()
83+
})
84+
})

‎packages/types/src/__tests__/openai-models.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ describe("OpenAI native models", () => {
122122
inputPrice: 2,
123123
outputPrice: 10,
124124
cacheWritesPrice: 2.5,
125+
cacheWritesPrice12h: 5,
125126
cacheReadsPrice: 0.2,
126127
longContextPricing: {
127128
thresholdTokens: 272_000,
@@ -166,6 +167,7 @@ describe("OpenAI native models", () => {
166167
inputPrice: 0.1,
167168
outputPrice: 0.5,
168169
cacheWritesPrice: 0.125,
170+
cacheWritesPrice12h: 0.25,
169171
cacheReadsPrice: 0.01,
170172
longContextPricing: {
171173
thresholdTokens: 272_000,
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// npx vitest run src/__tests__/prompt-cache-ttl.test.ts
2+
3+
import { describe, it, expect } from "vitest"
4+
5+
import { anthropicModels, anthropicProviderDefinition } from "../providers/anthropic.js"
6+
import { vertexModels } from "../providers/vertex.js"
7+
import { openRouterDefaultModelInfo } from "../providers/openrouter.js"
8+
import {
9+
vercelAiGatewayDefaultModelId,
10+
VERCEL_AI_GATEWAY_PROMPT_CACHING_MODELS,
11+
} from "../providers/vercel-ai-gateway.js"
12+
import {
13+
DEFAULT_PROMPT_CACHE_TTL,
14+
modelInfoSchema,
15+
promptCacheTtlSchema,
16+
promptCacheTtlValues,
17+
type ModelInfo,
18+
} from "../model.js"
19+
import { baseProviderSettingsShape } from "../providers/common.js"
20+
import { providerIdentifiers } from "../provider-identifiers.js"
21+
import { globalSettingsSchema } from "../global-settings.js"
22+
23+
/**
24+
* Catalog invariant for the request-side TTL knob (ADR-0006 phase 2, PR-C5b).
25+
*
26+
* Emission is gated by `ModelInfo.promptCacheTtlSupport`, so a model that can
27+
* report a 1h cache write but carries no capability array would silently never
28+
* emit the TTL the user asked for. These tests pin both directions: capable
29+
* catalogs advertise it, and catalogs that cannot know stay absent (fail closed).
30+
*/
31+
describe("prompt cache TTL schema", () => {
32+
it("accepts exactly the 5m and 1h classes", () => {
33+
expect(promptCacheTtlValues).toEqual(["5m", "1h"])
34+
expect(promptCacheTtlSchema.parse("5m")).toBe("5m")
35+
expect(promptCacheTtlSchema.parse("1h")).toBe("1h")
36+
expect(promptCacheTtlSchema.safeParse("30m").success).toBe(false)
37+
expect(promptCacheTtlSchema.safeParse("12h").success).toBe(false)
38+
})
39+
40+
it("defaults to undefined so an unset knob emits no ttl key", () => {
41+
expect(DEFAULT_PROMPT_CACHE_TTL).toBeUndefined()
42+
})
43+
44+
it("is optional on ModelInfo", () => {
45+
const parsed = modelInfoSchema.parse({ contextWindow: 200_000, supportsPromptCache: true })
46+
expect(parsed.promptCacheTtlSupport).toBeUndefined()
47+
48+
const withCapability = modelInfoSchema.parse({
49+
contextWindow: 200_000,
50+
supportsPromptCache: true,
51+
promptCacheTtlSupport: ["5m", "1h"],
52+
})
53+
expect(withCapability.promptCacheTtlSupport).toEqual(["5m", "1h"])
54+
})
55+
})
56+
57+
describe("prompt cache TTL knob location", () => {
58+
it("lives in provider settings so handlers can see it", () => {
59+
// ApiHandlerOptions = Omit<ProviderSettings, "apiProvider">, so only a
60+
// provider-settings key reaches a handler (ADR-0006 decision item 2).
61+
expect(baseProviderSettingsShape.promptCacheTtl).toBeDefined()
62+
63+
const parsed = anthropicProviderDefinition.schema.safeParse({
64+
apiProvider: providerIdentifiers.anthropic,
65+
promptCacheTtl: "1h",
66+
})
67+
expect(parsed.success).toBe(true)
68+
expect(parsed.success && parsed.data.promptCacheTtl).toBe("1h")
69+
})
70+
71+
it("is not a global setting", () => {
72+
const shape = globalSettingsSchema.shape as Record<string, unknown>
73+
expect(shape.promptCacheTtl).toBeUndefined()
74+
})
75+
})
76+
77+
describe("prompt cache TTL capability catalog", () => {
78+
it("every Anthropic entry with prompt caching advertises both TTL classes", () => {
79+
const missing = Object.entries(anthropicModels as Record<string, ModelInfo>)
80+
.filter(([, info]) => info.supportsPromptCache && !info.promptCacheTtlSupport?.includes("1h"))
81+
.map(([id]) => id)
82+
83+
expect(missing).toEqual([])
84+
})
85+
86+
it("leaves the Vertex catalog without capability so it fails closed", () => {
87+
// PR-C5b scopes the catalog capability to the Anthropic entries; the Vertex
88+
// catalog is populated separately, so its models stay 5m-only for now.
89+
const withCapability = Object.entries(vertexModels as Record<string, ModelInfo>)
90+
.filter(([, info]) => info.promptCacheTtlSupport !== undefined)
91+
.map(([id]) => id)
92+
93+
expect(withCapability).toEqual([])
94+
})
95+
96+
it("leaves dynamic-catalog defaults without capability so they fail closed", () => {
97+
// OpenRouter and the gateway catalogs are fetched at runtime and carry no TTL
98+
// capability data, which ADR-0006 maps to "5m only" (invariant I2).
99+
expect(openRouterDefaultModelInfo.promptCacheTtlSupport).toBeUndefined()
100+
expect(VERCEL_AI_GATEWAY_PROMPT_CACHING_MODELS.has(vercelAiGatewayDefaultModelId)).toBe(true)
101+
})
102+
})

0 commit comments

Comments
 (0)