Skip to content

Commit 986a775

Browse files
committed
fix(server): bound complete proxy recovery lookup
1 parent 60803a0 commit 986a775

2 files changed

Lines changed: 61 additions & 38 deletions

File tree

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

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5759,6 +5759,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
57595759
"process cwd",
57605760
"launch inline",
57615761
"launch file",
5762+
"stalled settings",
57625763
])("uses the matching proxy reset from %s when Claude omits a reset time", (source) =>
57635764
Effect.gen(function* () {
57645765
const fs = yield* FileSystem.FileSystem;
@@ -5796,6 +5797,15 @@ describe("ClaudeAdapterV2 background wake turns", () => {
57965797
const launchSettings = JSON.stringify({ env: { ANTHROPIC_BASE_URL: "https://hub.test/v1" } });
57975798
if (source === "launch file")
57985799
yield* fs.writeFileString(path.join(cwd, "launch.json"), launchSettings);
5800+
const readStarted = yield* Deferred.make<void>();
5801+
let stallSettingsRead = false;
5802+
const stalledFileSystem = {
5803+
...fs,
5804+
readFileString: (filePath: string) =>
5805+
stallSettingsRead && filePath === path.join(configDir, "settings.json")
5806+
? Deferred.succeed(readStarted, undefined).pipe(Effect.andThen(Effect.never))
5807+
: fs.readFileString(filePath),
5808+
};
57995809
const harness = yield* makeWakeHarnessWithOptions({
58005810
settings: {
58015811
...DEFAULT_CLAUDE_SETTINGS,
@@ -5811,7 +5821,10 @@ describe("ClaudeAdapterV2 background wake turns", () => {
58115821
ANTHROPIC_BASE_URL:
58125822
source === "environment" ? "https://hub.test/v1" : "https://wrong.test",
58135823
},
5814-
}).pipe(Effect.provideService(HostProcess.WorkingDirectory, cwd));
5824+
}).pipe(
5825+
Effect.provideService(HostProcess.WorkingDirectory, cwd),
5826+
Effect.provideService(FileSystem.FileSystem, stalledFileSystem),
5827+
);
58155828
const now = yield* DateTime.now;
58165829
yield* harness.runtime.startTurn(
58175830
makeClaudeTestTurnInput({
@@ -5823,10 +5836,11 @@ describe("ClaudeAdapterV2 background wake turns", () => {
58235836
attachments: [],
58245837
runtimePolicy: {
58255838
...CLAUDE_TEST_RUNTIME_POLICY,
5826-
cwd: source === "process cwd" ? null : cwd,
5839+
cwd: source === "process cwd" || source === "stalled settings" ? null : cwd,
58275840
},
58285841
}),
58295842
);
5843+
stallSettingsRead = source === "stalled settings";
58305844
yield* Queue.offerAll(harness.sdkMessages, [
58315845
makeAssistantErrorFrame({
58325846
uuid: "00000000-0000-4000-8000-000000000652",
@@ -5840,11 +5854,18 @@ describe("ClaudeAdapterV2 background wake turns", () => {
58405854
apiErrorStatus: 429,
58415855
}),
58425856
]);
5857+
if (source === "stalled settings") {
5858+
yield* Deferred.await(readStarted);
5859+
yield* TestClock.adjust("15 seconds");
5860+
}
58435861
const terminal = yield* Queue.take(harness.terminalReceipts);
58445862
assert.equal(terminal.status, "failed");
58455863
if (terminal.status !== "failed") return;
58465864
assert.equal(terminal.failure.class, "usage_limit");
5847-
assert.equal(terminal.failure.resetAt, "2099-01-01T02:00:00.000Z");
5865+
assert.equal(
5866+
terminal.failure.resetAt,
5867+
source === "stalled settings" ? null : "2099-01-01T02:00:00.000Z",
5868+
);
58485869
}).pipe(
58495870
Effect.provide([
58505871
IdAllocator.layer,

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

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4379,41 +4379,43 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
43794379
const usageLimitSources = yield* Effect.serviceOption(UsageLimitSources.UsageLimitSources);
43804380
const workingDirectory = yield* HostProcess.WorkingDirectory;
43814381
const { attachmentsDir, fileSystem, path, crypto, idAllocator, queryRunner } = adapterOptions;
4382-
const proxyResetAt = Effect.fn("ClaudeAdapterV2.proxyResetAt")(function* (
4383-
context: ActiveClaudeTurnContext,
4384-
) {
4385-
if (Option.isNone(usageLimitSources)) return null;
4386-
const cwd = context.input.runtimePolicy.cwd ?? workingDirectory;
4387-
const localDirectory = yield* localSettingsDirectory(cwd);
4388-
let endpoint = adapterOptions.environment.ANTHROPIC_BASE_URL;
4389-
const settingsPaths = [
4390-
path.join(homePath, "settings.json"),
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")]),
4396-
];
4397-
for (const settingsPath of settingsPaths) {
4398-
const settings = yield* fileSystem.readFileString(settingsPath).pipe(
4399-
Effect.flatMap(decodeClaudeEndpointSettings),
4400-
Effect.orElseSucceed(() => undefined),
4401-
);
4402-
endpoint = settings?.env?.ANTHROPIC_BASE_URL ?? endpoint;
4403-
}
4404-
const launchSettings = yield* readClaudeLaunchArgSettings({
4405-
settings: adapterOptions.settings,
4406-
cwd,
4407-
fileSystem,
4408-
path,
4409-
}).pipe(Effect.orElseSucceed(() => undefined));
4410-
endpoint = launchSettings?.env?.ANTHROPIC_BASE_URL ?? endpoint;
4411-
if (!endpoint) return null;
4412-
return yield* usageLimitSources.value.resolveResetAt({
4413-
endpoint,
4414-
model: compileClaudeModelSelection(context.input.modelSelection).apiModelId,
4415-
});
4416-
});
4382+
const proxyResetAt = Effect.fn("ClaudeAdapterV2.proxyResetAt")(
4383+
function* (context: ActiveClaudeTurnContext) {
4384+
if (Option.isNone(usageLimitSources)) return null;
4385+
const cwd = context.input.runtimePolicy.cwd ?? workingDirectory;
4386+
const localDirectory = yield* localSettingsDirectory(cwd);
4387+
let endpoint = adapterOptions.environment.ANTHROPIC_BASE_URL;
4388+
const settingsPaths = [
4389+
path.join(homePath, "settings.json"),
4390+
path.join(cwd, ".claude", "settings.json"),
4391+
path.join(cwd, ".claude", "settings.local.json"),
4392+
...(localDirectory === cwd
4393+
? []
4394+
: [path.join(localDirectory, ".claude", "settings.local.json")]),
4395+
];
4396+
for (const settingsPath of settingsPaths) {
4397+
const settings = yield* fileSystem.readFileString(settingsPath).pipe(
4398+
Effect.flatMap(decodeClaudeEndpointSettings),
4399+
Effect.orElseSucceed(() => undefined),
4400+
);
4401+
endpoint = settings?.env?.ANTHROPIC_BASE_URL ?? endpoint;
4402+
}
4403+
const launchSettings = yield* readClaudeLaunchArgSettings({
4404+
settings: adapterOptions.settings,
4405+
cwd,
4406+
fileSystem,
4407+
path,
4408+
}).pipe(Effect.orElseSucceed(() => undefined));
4409+
endpoint = launchSettings?.env?.ANTHROPIC_BASE_URL ?? endpoint;
4410+
if (!endpoint) return null;
4411+
return yield* usageLimitSources.value.resolveResetAt({
4412+
endpoint,
4413+
model: compileClaudeModelSelection(context.input.modelSelection).apiModelId,
4414+
});
4415+
},
4416+
Effect.timeout("15 seconds"),
4417+
Effect.orElseSucceed(() => null),
4418+
);
44174419

44184420
const subagentModelCatalog = scopeClaudeModelCatalog(
44194421
BUNDLED_CLAUDE_MODEL_CATALOG,

0 commit comments

Comments
 (0)