Skip to content

Commit 335d4af

Browse files
refactor(server): trim Claude effort-cap tests and proof fixtures
Drop the scripted capture fixtures and tests that repeat the catalog unit cases, type the get_settings probe failure like the usage read, and shorten comments to the repository's limits. AI-assisted; verified with the tests and tools listed above.
1 parent ed6a833 commit 335d4af

8 files changed

Lines changed: 21 additions & 460 deletions

File tree

‎apps/server/src/provider/ClaudeModelCatalog.ts‎

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -387,19 +387,9 @@ function resolveClaudeModelMaxEffortLevels(
387387
}
388388

389389
/**
390-
* Claude Code clamps every effort above settings.json `maxEffortLevel` to the highest level the
391-
* model supports at or below it, so a model without Extra High runs Max at High under an `xhigh`
392-
* cap. Each descriptor's effective cap is therefore its highest plain-level option at or below the
393-
* configured cap. Options above it are relabelled rather than removed: a stored selection that no longer matched any option
394-
* would fall back to the descriptor default and run below the cap. An option counts as above the
395-
* cap only when both the level it reads as and the level the CLI is sent are, so an `effortMap`
396-
* that already sends Max as High keeps its label, and values that map to no level (prompt-injected
397-
* Ultrathink) are never capped.
398-
*
399-
* The cap is resolved like Claude Code does: within each settings source, the lowest
400-
* `modelSettings.<model>.maxEffortLevel` naming the model replaces that source's top-level cap and
401-
* `max` means no cap; across sources the lowest cap wins. The merged settings cannot express this,
402-
* since a per-model `max` in one file would hide another file's top-level cap.
390+
* Claude Code clamps efforts above `maxEffortLevel` to the model's highest level under it, so
391+
* such options are relabelled, not removed, keeping stored selections valid. Per-model caps
392+
* replace their own source's top-level cap and `max` means none; across sources the lowest wins.
403393
*/
404394
export function capClaudeCatalogEffort(
405395
catalog: ClaudeModelCatalog,

‎apps/server/src/provider/ClaudeProvider.ts‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -486,9 +486,7 @@ const probeClaudeCapabilities = (
486486
// Usage has its own deadline so a slow optional request cannot discard initialization.
487487
// Only the rate limits are read, so skip the local transcript scan that fills
488488
// `behaviors`: with a few GB of transcripts it outlasts the deadline.
489-
// The effort cap is read alongside it under the same deadline, so a CLI that never
490-
// answers `get_settings` delays the probe by at most that one timeout. Workspace probes
491-
// only keep slash commands, so they skip both reads.
489+
// The effort caps are read in parallel under the same deadline; workspace probes skip both.
492490
const usageCheckedAt = DateTime.formatIso(yield* DateTime.now);
493491
const { getSettings } = q as ClaudeSettingsQuery;
494492
const [usageResult, settingsResult] = yield* Effect.all(
@@ -502,14 +500,14 @@ const probeClaudeCapabilities = (
502500
catch: (cause) =>
503501
new ClaudeCapabilitiesProbeSdkError({ operation: "usage", cause }),
504502
}).pipe(Effect.timeout(DEFAULT_TIMEOUT_MS), Effect.result)
505-
: Effect.succeed(undefined),
503+
: Effect.undefined,
506504
includeStatus && getSettings
507505
? Effect.tryPromise({
508506
try: () => getSettings.call(q),
509507
catch: (cause) =>
510508
new ClaudeCapabilitiesProbeSdkError({ operation: "settings", cause }),
511509
}).pipe(Effect.timeout(DEFAULT_TIMEOUT_MS), Effect.result)
512-
: Effect.succeed(undefined),
510+
: Effect.undefined,
513511
],
514512
{ concurrency: "unbounded" },
515513
);

‎apps/server/src/provider/ProviderInstanceRegistry.test.ts‎

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -468,90 +468,6 @@ describe("ProviderInstanceRegistry — multi-instance codex slice", () => {
468468
}).pipe(Effect.provide(layerTest)),
469469
);
470470

471-
it.live("reads Claude's maxEffortLevel cap from the CLI's effective settings", () =>
472-
Effect.gen(function* () {
473-
if (yield* HostProcess.isWindows) return;
474-
475-
const fixtures = yield* makeTildeProviderFixtures();
476-
const claudeId = ProviderInstanceId.make("claude_effort_cap");
477-
const { registry } = yield* makeProviderInstanceRegistry<ClaudeDriverEnv>({
478-
drivers: [ClaudeDriver],
479-
configMap: {
480-
[claudeId]: {
481-
driver: ProviderDriverKind.make("claudeAgent"),
482-
enabled: true,
483-
environment: [{ name: "T3_CLAUDE_MAX_EFFORT_LEVEL", value: "high", sensitive: false }],
484-
config: makeClaudeConfig({
485-
enabled: true,
486-
binaryPath: fixtures.claudeBinaryPath,
487-
homePath: fixtures.claudeHomePath,
488-
}),
489-
},
490-
},
491-
});
492-
const claude = yield* registry.getInstance(claudeId);
493-
494-
const snapshot = yield* claude!.snapshot.refresh;
495-
const effortLabels = snapshot.models.flatMap((model) =>
496-
(model.capabilities?.optionDescriptors ?? []).flatMap((descriptor) =>
497-
descriptor.id === "effort" && descriptor.type === "select"
498-
? descriptor.options.map((option) => option.label)
499-
: [],
500-
),
501-
);
502-
expect(effortLabels).toContain("High");
503-
expect(effortLabels).toContain("Extra High (capped to High)");
504-
}).pipe(Effect.provide(layerTest)),
505-
);
506-
507-
it.live("lets Claude's per-model maxEffortLevel replace the top-level cap", () =>
508-
Effect.gen(function* () {
509-
if (yield* HostProcess.isWindows) return;
510-
511-
const fixtures = yield* makeTildeProviderFixtures();
512-
const claudeId = ProviderInstanceId.make("claude_model_effort_cap");
513-
const { registry } = yield* makeProviderInstanceRegistry<ClaudeDriverEnv>({
514-
drivers: [ClaudeDriver],
515-
configMap: {
516-
[claudeId]: {
517-
driver: ProviderDriverKind.make("claudeAgent"),
518-
enabled: true,
519-
environment: [
520-
{ name: "T3_CLAUDE_MAX_EFFORT_LEVEL", value: "xhigh", sensitive: false },
521-
{
522-
name: "T3_CLAUDE_MODEL_SETTINGS",
523-
value: JSON.stringify({
524-
"claude-opus-5": { maxEffortLevel: "max" },
525-
"claude-sonnet-5": { maxEffortLevel: "high" },
526-
}),
527-
sensitive: false,
528-
},
529-
],
530-
config: makeClaudeConfig({
531-
enabled: true,
532-
binaryPath: fixtures.claudeBinaryPath,
533-
homePath: fixtures.claudeHomePath,
534-
}),
535-
},
536-
},
537-
});
538-
const claude = yield* registry.getInstance(claudeId);
539-
540-
const snapshot = yield* claude!.snapshot.refresh;
541-
const maxLabel = (slug: string) =>
542-
snapshot.models
543-
.find((model) => model.slug === slug)
544-
?.capabilities?.optionDescriptors?.flatMap((descriptor) =>
545-
descriptor.id === "effort" && descriptor.type === "select"
546-
? descriptor.options.filter((option) => option.id === "max")
547-
: [],
548-
)[0]?.label;
549-
expect(maxLabel("claude-opus-5")).toBe("Max");
550-
expect(maxLabel("claude-sonnet-5")).toBe("Max (capped to High)");
551-
expect(maxLabel("claude-opus-4-8")).toBe("Max (capped to Extra High)");
552-
}).pipe(Effect.provide(layerTest)),
553-
);
554-
555471
it.live("applies the lowest maxEffortLevel across Claude's settings sources", () =>
556472
Effect.gen(function* () {
557473
if (yield* HostProcess.isWindows) return;

‎apps/server/src/provider/ProviderRegistry.test.ts‎

Lines changed: 14 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as CodexManagedTokenBroker from "./CodexManagedTokenBroker.ts";
66
import * as ServerEnvironment from "../environment/ServerEnvironment.ts";
77
import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
88
import * as NodeServices from "@effect/platform-node/NodeServices";
9+
import type { ModelInfo } from "@anthropic-ai/claude-agent-sdk";
910
import { describe, it, assert, expect } from "@effect/vitest";
1011
import * as DateTime from "effect/DateTime";
1112
import * as Deferred from "effect/Deferred";
@@ -33,6 +34,7 @@ import {
3334
ServerSettings,
3435
ServerSettingsError,
3536
ServerProvider,
37+
type ServerProviderSlashCommand,
3638
type ServerSettings as ContractServerSettings,
3739
} from "@t3tools/contracts";
3840
import { HttpClient, HttpClientResponse } from "effect/http";
@@ -44,7 +46,7 @@ import { applyServerSettingsPatch } from "@t3tools/shared/serverSettings";
4446

4547
import { checkCodexProviderStatus, type CodexAppServerProviderSnapshot } from "./CodexProvider.ts";
4648
import { BUNDLED_CLAUDE_MODEL_CATALOG } from "./ClaudeModelCatalog.ts";
47-
import { type ClaudeCapabilitiesProbe, checkClaudeProviderStatus } from "./ClaudeProvider.ts";
49+
import { checkClaudeProviderStatus } from "./ClaudeProvider.ts";
4850
import * as BackgroundPolicy from "../background/BackgroundPolicy.ts";
4951
import * as AntigravityInstallation from "./AntigravityInstallation.ts";
5052
import * as ModelManifest from "./ModelManifest.ts";
@@ -168,7 +170,17 @@ function booleanDescriptor(id: string, label: string) {
168170
};
169171
}
170172

171-
function claudeCapabilities(overrides: Partial<ClaudeCapabilitiesProbe> = {}) {
173+
type TestClaudeCapabilities = {
174+
readonly email: string | undefined;
175+
readonly subscriptionType: string | undefined;
176+
readonly tokenSource: string | undefined;
177+
readonly apiKeySource: string | undefined;
178+
readonly apiProvider: string | undefined;
179+
readonly slashCommands: ReadonlyArray<ServerProviderSlashCommand>;
180+
readonly models?: ReadonlyArray<ModelInfo>;
181+
};
182+
183+
function claudeCapabilities(overrides: Partial<TestClaudeCapabilities> = {}) {
172184
return () =>
173185
Effect.succeed({
174186
email: undefined,
@@ -3524,43 +3536,6 @@ it.layer(
35243536
),
35253537
);
35263538

3527-
it.effect("marks effort above the CLI's maxEffortLevel cap as capped", () =>
3528-
Effect.gen(function* () {
3529-
// Claude Code silently clamps `--effort max` to the settings.json
3530-
// `maxEffortLevel`, so a plain "Max" label would show an effort the turn never uses.
3531-
const status = yield* checkClaudeProviderStatus(
3532-
defaultClaudeSettings,
3533-
claudeCapabilities({ effortCapSources: [{ maxEffortLevel: "xhigh" }] }),
3534-
);
3535-
const maxOptions = status.models.flatMap((model) =>
3536-
(model.capabilities?.optionDescriptors ?? []).flatMap((descriptor) =>
3537-
descriptor.id === "effort" && descriptor.type === "select"
3538-
? descriptor.options
3539-
.filter((option) => option.id === "max")
3540-
.map((option) => ({ slug: model.slug, label: option.label }))
3541-
: [],
3542-
),
3543-
);
3544-
assert.isNotEmpty(maxOptions);
3545-
for (const { slug, label } of maxOptions) {
3546-
// Sonnet 4.6 already sends Max as `high`, under the cap.
3547-
if (slug === "claude-sonnet-4-6") assert.strictEqual(label, "Max", slug);
3548-
// Models without Extra High run Max at High, the highest level they support under the cap.
3549-
else if (slug === "claude-opus-4-6" || slug === "claude-opus-4-5")
3550-
assert.strictEqual(label, "Max (capped to High)", slug);
3551-
else assert.include(label, "capped to Extra High", slug);
3552-
}
3553-
}).pipe(
3554-
Effect.provide(
3555-
layerMockSpawner((args) => {
3556-
const joined = args.join(" ");
3557-
if (joined === "--version") return { stdout: "2.1.303\n", stderr: "", code: 0 };
3558-
throw new Error(`Unexpected args: ${joined}`);
3559-
}),
3560-
),
3561-
),
3562-
);
3563-
35643539
it.effect("keeps a CLI that says nothing about its account authenticated", () =>
35653540
Effect.gen(function* () {
35663541
const status = yield* checkClaudeProviderStatus(

‎apps/server/src/provider/testing/ProviderInstanceRegistryLive.fixture.mjs‎

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,7 @@ lines.on("line", (line) => {
8282
return;
8383
}
8484
if (message.request?.subtype === "get_settings") {
85-
const userSettings = {
86-
...(process.env.T3_CLAUDE_MAX_EFFORT_LEVEL
87-
? { maxEffortLevel: process.env.T3_CLAUDE_MAX_EFFORT_LEVEL }
88-
: {}),
89-
...(process.env.T3_CLAUDE_MODEL_SETTINGS
90-
? { modelSettings: JSON.parse(process.env.T3_CLAUDE_MODEL_SETTINGS) }
91-
: {}),
92-
};
93-
const sources = process.env.T3_CLAUDE_SETTINGS_SOURCES
94-
? JSON.parse(process.env.T3_CLAUDE_SETTINGS_SOURCES)
95-
: Object.keys(userSettings).length > 0
96-
? [{ source: "userSettings", settings: userSettings }]
97-
: [];
85+
const sources = JSON.parse(process.env.T3_CLAUDE_SETTINGS_SOURCES ?? "[]");
9886
// Like Claude Code, `effective` is the last-writer merge, which hides per-source caps.
9987
const effective = { modelSettings: {} };
10088
for (const { settings } of sources) {

‎scripts/fixtures/issue-17110/README.md‎

Lines changed: 0 additions & 101 deletions
This file was deleted.

0 commit comments

Comments
 (0)