Skip to content

Commit 04459a6

Browse files
committed
fix(claude): honor authoritative context windows in generated profiles
1 parent e1fc0f2 commit 04459a6

2 files changed

Lines changed: 17 additions & 10 deletions

File tree

‎src/claude/agents-inject.ts‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { lstatSync, mkdirSync, readdirSync, readFileSync, renameSync, unlinkSync
1515
import { join } from "node:path";
1616
import type { OcxConfig } from "../types";
1717
import { claudeCodeAlias, claudeCodeNativeAlias } from "./alias";
18-
import { resolveAutoContext, stripOneMillionMarker, withOneMillionMarker } from "./context-windows";
18+
import { stripOneMillionMarker, withOneMillionMarker } from "./context-windows";
1919
import { claudeConfigDir } from "./gateway-cache";
2020
import { DEFAULT_SUBAGENT_MODELS, hasOwnProvider } from "../config";
2121
import { effectiveBlockedSkillNames, resolveInboundModel } from "./inbound";
@@ -55,6 +55,15 @@ function pickerDefaultModel(configDir: string): string | null {
5555
}
5656
}
5757

58+
/**
59+
* Generated subagents cannot rely on parent auto-context compaction before
60+
* routed requests reach the real model limit.
61+
*/
62+
function withSubagentContextMarker(selector: string, windows: Record<string, number>): string {
63+
const bare = stripOneMillionMarker(selector);
64+
return withOneMillionMarker(bare, windows) ?? bare;
65+
}
66+
5867
/** Roster entry -> alias + display parts. Entries are bare native slugs or "provider/id".
5968
* Codex-facing encoded ids (`provider/vendor-model`) decode to the native slash id first
6069
* so the alias joins the raw-native context-window map (context-windows.ts). */
@@ -72,7 +81,6 @@ function entryParts(entry: string, config: OcxConfig): { alias: string; id: stri
7281
}
7382

7483
export function buildClaudeAgentDefs(config: OcxConfig, windows: Record<string, number>, configDir = claudeConfigDir()): ClaudeAgentDef[] {
75-
const auto = resolveAutoContext(config.claudeCode);
7684
const blockedSkills = effectiveBlockedSkillNames(config.claudeCode);
7785
const blockedSkillsFor = (model: string): readonly string[] => {
7886
const unmarked = stripOneMillionMarker(model);
@@ -87,8 +95,7 @@ export function buildClaudeAgentDefs(config: OcxConfig, windows: Record<string,
8795
const coveredModels = new Set<string>();
8896

8997
const push = (name: string, alias: string, description: string) => {
90-
// Effective model value: [1m] marking follows the same predicate as env slots.
91-
const model = withOneMillionMarker(alias, windows, auto) ?? alias;
98+
const model = withSubagentContextMarker(alias, windows);
9299
const bare = alias.toLowerCase();
93100
if (coveredModels.has(bare)) return;
94101
coveredModels.add(bare);
@@ -120,7 +127,7 @@ export function buildClaudeAgentDefs(config: OcxConfig, windows: Record<string,
120127
// the next launch sync — documented limit. No resolvable default -> no self def.
121128
const selfModel = pickerDefaultModel(configDir) ?? (config.claudeCode?.model?.trim() || null);
122129
if (selfModel) {
123-
const marked = withOneMillionMarker(selfModel, windows, auto) ?? selfModel;
130+
const marked = withSubagentContextMarker(selfModel, windows);
124131
defs.push({
125132
file: `${OWNED_PREFIX}self.md`,
126133
name: `${OWNED_PREFIX}self`,

‎tests/claude-agents-inject.test.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,19 @@ function generatedBodies(config: OcxConfig, dir: string): string[] {
2424
}
2525

2626
describe("buildClaudeAgentDefs (devlog 070 + audit 071)", () => {
27-
test("roster + pinned self from settings.json; [1m] marking; name collision suffix", () => {
27+
test("roster + pinned self mark only authoritative 1M windows; name collision suffix", () => {
2828
const windows = { "claude-ocx-native--gpt-5.6-sol": 372_000, "claude-ocx-cursor--gpt-5.6-sol": 1_000_000 };
2929
const dir = tempDir();
3030
writeFileSync(join(dir, "settings.json"), JSON.stringify({ model: "claude-ocx-native--gpt-5.6-sol[1m]" }));
3131
const defs = buildClaudeAgentDefs(cfg({
3232
subagentModels: ["gpt-5.6-sol", "cursor/gpt-5.6-sol"],
33-
claudeCode: {},
33+
claudeCode: { autoContext: true },
3434
}), windows, dir);
3535
const byName = Object.fromEntries(defs.map(d => [d.name, d]));
36-
expect(byName["ocx-gpt-5-6-sol"]!.model).toBe("claude-ocx-native--gpt-5.6-sol[1m]"); // 372k >= 350k default
36+
expect(byName["ocx-gpt-5-6-sol"]!.model).toBe("claude-ocx-native--gpt-5.6-sol");
3737
expect(byName["ocx-gpt-5-6-sol-2"]!.model).toBe("claude-ocx-cursor--gpt-5.6-sol[1m]"); // collision suffix
38-
// Self pins the picker-saved default (inherit disproven live — devlog 072).
39-
expect(byName["ocx-self"]!.model).toBe("claude-ocx-native--gpt-5.6-sol[1m]");
38+
// Self pins the picker-saved default but cannot inherit an unsafe auto-context marker.
39+
expect(byName["ocx-self"]!.model).toBe("claude-ocx-native--gpt-5.6-sol");
4040
expect(defs).toHaveLength(3);
4141
// Dispatcher directive (live repro: model:"fable" override broke inherit).
4242
for (const d of defs) expect(d.description).toContain("`model` argument is ignored");

0 commit comments

Comments
 (0)