Skip to content

Commit 60803a0

Browse files
committed
fix(server): match Claude context suffixes in proxy recovery
1 parent cb6bcb2 commit 60803a0

4 files changed

Lines changed: 36 additions & 17 deletions

File tree

‎apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5756,6 +5756,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
57565756
"settings",
57575757
"lenient settings",
57585758
"root local",
5759+
"process cwd",
57595760
"launch inline",
57605761
"launch file",
57615762
])("uses the matching proxy reset from %s when Claude omits a reset time", (source) =>
@@ -5776,6 +5777,11 @@ describe("ClaudeAdapterV2 background wake turns", () => {
57765777
path.join(configDir, "settings.json"),
57775778
'{ // Claude settings allow comments and trailing commas\n "env": { "ANTHROPIC_BASE_URL": "https://hub.test/v1", }, }',
57785779
);
5780+
if (source === "process cwd")
5781+
yield* fs.writeFileString(
5782+
path.join(cwd, ".claude", "settings.json"),
5783+
JSON.stringify({ env: { ANTHROPIC_BASE_URL: "https://hub.test/v1" } }),
5784+
);
57795785
if (source === "root local") {
57805786
yield* fs.writeFileString(
57815787
path.join(cwd, ".claude", "settings.local.json"),
@@ -5805,7 +5811,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
58055811
ANTHROPIC_BASE_URL:
58065812
source === "environment" ? "https://hub.test/v1" : "https://wrong.test",
58075813
},
5808-
});
5814+
}).pipe(Effect.provideService(HostProcess.WorkingDirectory, cwd));
58095815
const now = yield* DateTime.now;
58105816
yield* harness.runtime.startTurn(
58115817
makeClaudeTestTurnInput({
@@ -5815,7 +5821,10 @@ describe("ClaudeAdapterV2 background wake turns", () => {
58155821
attemptId: RunAttemptId.make("attempt-proxy-reset"),
58165822
text: "Continue.",
58175823
attachments: [],
5818-
runtimePolicy: { ...CLAUDE_TEST_RUNTIME_POLICY, cwd },
5824+
runtimePolicy: {
5825+
...CLAUDE_TEST_RUNTIME_POLICY,
5826+
cwd: source === "process cwd" ? null : cwd,
5827+
},
58195828
}),
58205829
);
58215830
yield* Queue.offerAll(harness.sdkMessages, [

‎apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts‎

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4377,25 +4377,22 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
43774377
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
43784378
const serverSettings = yield* Effect.serviceOption(ServerSettings.ServerSettingsService);
43794379
const usageLimitSources = yield* Effect.serviceOption(UsageLimitSources.UsageLimitSources);
4380+
const workingDirectory = yield* HostProcess.WorkingDirectory;
43804381
const { attachmentsDir, fileSystem, path, crypto, idAllocator, queryRunner } = adapterOptions;
43814382
const proxyResetAt = Effect.fn("ClaudeAdapterV2.proxyResetAt")(function* (
43824383
context: ActiveClaudeTurnContext,
43834384
) {
43844385
if (Option.isNone(usageLimitSources)) return null;
4385-
const cwd = context.input.runtimePolicy.cwd;
4386-
const localDirectory = cwd === null ? null : yield* localSettingsDirectory(cwd);
4386+
const cwd = context.input.runtimePolicy.cwd ?? workingDirectory;
4387+
const localDirectory = yield* localSettingsDirectory(cwd);
43874388
let endpoint = adapterOptions.environment.ANTHROPIC_BASE_URL;
43884389
const settingsPaths = [
43894390
path.join(homePath, "settings.json"),
4390-
...(cwd
4391-
? [
4392-
path.join(cwd, ".claude", "settings.json"),
4393-
path.join(cwd, ".claude", "settings.local.json"),
4394-
...(localDirectory === null || localDirectory === cwd
4395-
? []
4396-
: [path.join(localDirectory, ".claude", "settings.local.json")]),
4397-
]
4398-
: []),
4391+
path.join(cwd, ".claude", "settings.json"),
4392+
path.join(cwd, ".claude", "settings.local.json"),
4393+
...(localDirectory === cwd
4394+
? []
4395+
: [path.join(localDirectory, ".claude", "settings.local.json")]),
43994396
];
44004397
for (const settingsPath of settingsPaths) {
44014398
const settings = yield* fileSystem.readFileString(settingsPath).pipe(

‎apps/server/src/usage/UsageLimitSources.test.ts‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ it.effect("keeps malformed source URLs encodable for config subscribers", () =>
8686

8787
it.effect.each([
8888
{ scenario: "multiple windows", expected: "2099-01-01T02:00:00.000Z" },
89+
{ scenario: "base model for 1m", expected: "2099-01-01T02:00:00.000Z" },
90+
{ scenario: "suffixed model", expected: "2099-01-01T02:00:00.000Z" },
91+
{ scenario: "unknown suffix", expected: null },
8992
{ scenario: "model scopes", expected: "2099-01-01T04:00:00.000Z" },
9093
{ scenario: "disabled account", expected: "2099-01-01T03:00:00.000Z" },
9194
{ scenario: "model list unavailable", expected: "2099-01-01T03:00:00.000Z" },
@@ -102,7 +105,12 @@ it.effect.each([
102105
expect(unrelated).toBeNull();
103106
const reset = yield* sources.resolveResetAt({
104107
endpoint: "https://hub.test/v1",
105-
model: "claude-opus-4-6",
108+
model:
109+
scenario === "base model for 1m" || scenario === "suffixed model"
110+
? "claude-opus-4-6[1m]"
111+
: scenario === "unknown suffix"
112+
? "claude-opus-4-6[2m]"
113+
: "claude-opus-4-6",
106114
});
107115
expect(reset).toBe(expected);
108116
const unlisted = yield* sources.resolveResetAt({
@@ -153,7 +161,9 @@ it.effect.each([
153161
id:
154162
url.searchParams.get("name") === "wrong-model"
155163
? "claude-sonnet-4-6"
156-
: "claude-opus-4-6",
164+
: scenario === "suffixed model"
165+
? "claude-opus-4-6[1m]"
166+
: "claude-opus-4-6",
157167
},
158168
],
159169
}

‎apps/server/src/usage/UsageLimitSources.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,11 @@ export const make = Effect.gen(function* () {
174174
(account) =>
175175
Effect.gen(function* () {
176176
const models = yield* api.accountModels(config, account.id);
177-
if (!models.includes(input.model) || account.usageLimits.unavailable) return null;
178-
const model = input.model.replace(/^claude-/, "").replace(/[^a-z0-9]+/g, "_");
177+
const modelId = models.includes(input.model)
178+
? input.model
179+
: input.model.replace(/\[1m\]$/, "");
180+
if (!models.includes(modelId) || account.usageLimits.unavailable) return null;
181+
const model = modelId.replace(/^claude-/, "").replace(/[^a-z0-9]+/g, "_");
179182
const blocked = account.usageLimits.windows.filter((window) => {
180183
if (window.usedPercent < 100) return false;
181184
if (window.id === "five_hour" || window.id === "seven_day") return true;

0 commit comments

Comments
 (0)