Skip to content

Commit 4bf5728

Browse files
fix(dsh): export a known output limit as maxTokens (#7763)
DSH treats an exported `maxTokens` as the model's real output ceiling and sends it as `max_tokens`; when the field is absent it falls back to its own `DEFAULT_MAX_TOKENS = 32768`. The DSH exporter emitted only `contextWindow`, so every model outside DSH's bundled catalog silently ran on 32768 even when the real limit was far larger — long answers were cut off mid-sentence. The catalog row already carries the authoritative limit (`toExportModel` maps `maxOutputTokens` to `maxTokens`, and #5828 established that this value must win over the 32000 schema stand-in). The OMP exporter has consumed it since that fix; DSH simply never did. Add `knownOutputBudget()` next to `outputBudgetFor()`. The two differ only in the unknown case: `outputBudgetFor` must return a number because its callers cannot express "unknown", while `knownOutputBudget` returns undefined so a client that has a meaningful default is not handed the 32000 stand-in and does not claim a limit no model declared. Emitting `outputBudgetFor` here would have reintroduced exactly the over-reporting #5828 fixed. DSH now declares `maxTokens` only when the row (or the bundled per-model metadata) knows one, clamped to the exported context window, and stays silent otherwise — including when no context window is exported at all. Verified on a real install (opencodex 2.92.0): - exported entries carrying `maxTokens`: 0 -> 30 of 40 - entries that lost a `maxTokens` they previously declared: 0 - `contextWindow` values changed: 0 - `bun test tests/config/`: 733 pass, 0 fail - `tsc --noEmit`: clean The existing DSH test asserted `not.toHaveProperty("maxTokens")` on every row. That assertion predates #5828 and was never revisited when the other exporters started carrying the field, so it pinned the omission rather than a decision. It stays for rows with no known limit and gains a positive case.
1 parent 96f2f47 commit 4bf5728

3 files changed

Lines changed: 34 additions & 1 deletion

File tree

‎src/clients/config-export/dsh.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import type { ExportModel, ExportContext, ManagedContribution } from "./contracts";
33
import type { OcxConfig } from "../../types";
44
import { providerCodexAccountMode } from "../../providers/registry";
5-
import { normalizeExportModels, authoritativeContextWindow, exportModelLabel, singleFragment } from "./model-metadata";
5+
import { normalizeExportModels, authoritativeContextWindow, exportModelLabel, knownOutputBudget, singleFragment } from "./model-metadata";
66
import { OPENCODE_PROVIDER_ID } from "./constants";
77

88

@@ -26,6 +26,11 @@ export interface DshModelEntry {
2626
name: string;
2727
input: string[];
2828
contextWindow?: number;
29+
/**
30+
* Output ceiling DSH should treat as the model's real `max_tokens`. DSH falls back to its
31+
* own 32768 default when this is absent, so a limit it does not know stays undeclared.
32+
*/
33+
maxTokens?: number;
2934
reasoningEfforts?: Partial<Record<DshReasoningEffort, DshWireReasoningEffort>>;
3035
}
3136

@@ -97,12 +102,14 @@ export function buildDshClientConfig(ctx: ExportContext): DshGeneratedConfig {
97102
const input = dshInputModalities(model.inputModalities);
98103
if (input === null) continue;
99104
const contextWindow = authoritativeContextWindow(model.contextWindow);
105+
const maxTokens = contextWindow === undefined ? undefined : knownOutputBudget(contextWindow, model);
100106
const reasoningEfforts = dshReasoningEfforts(model);
101107
models.push({
102108
id: model.namespaced,
103109
name: exportModelLabel(model),
104110
input,
105111
...(contextWindow !== undefined ? { contextWindow } : {}),
112+
...(maxTokens !== undefined ? { maxTokens } : {}),
106113
...(reasoningEfforts ? { reasoningEfforts } : {}),
107114
});
108115
}

‎src/clients/config-export/model-metadata.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,25 @@ export function outputBudgetFor(context: number, model: OpencodeCatalogModel): n
3131
return Math.min(limit, context);
3232
}
3333

34+
/**
35+
* Known model output limit without the schema stand-in, clamped to context.
36+
*
37+
* `outputBudgetFor` always returns a number because the clients that require the field
38+
* cannot express "unknown". A client that instead treats an absent `maxTokens` as a real
39+
* default must not be handed the 32000 stand-in: that would claim a limit no model declared
40+
* (#5828). Use this variant where "no claim" is representable.
41+
* @param context - the context window this model already exports.
42+
* @param model - the catalog row, which may carry an authoritative output limit.
43+
* @returns the known limit clamped to `context`, or undefined when nothing is known.
44+
*/
45+
export function knownOutputBudget(context: number, model: OpencodeCatalogModel): number | undefined {
46+
const provider = model.provider ?? "";
47+
const metadata = getModelMetadata(resolveMetadataProvider(provider) ?? provider, model.id ?? model.namespaced);
48+
const limit = authoritativeContextWindow(model.maxTokens)
49+
?? authoritativeContextWindow(metadata?.maxTokens);
50+
return limit === undefined ? undefined : Math.min(limit, context);
51+
}
52+
3453
/** Input limits are optional: unlike output, a missing limit needs no schema fallback. */
3554
export function inputBudgetFor(context: number, model: OpencodeCatalogModel): number | undefined {
3655
const limit = authoritativeContextWindow(model.maxInputTokens);

‎tests/config/client-config-export.test.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,14 @@ describe("DSH rc.6 serializer", () => {
544544
expect(models.find(model => model.id === "a/context")?.contextWindow).toBe(128_000);
545545
expect(models.find(model => model.id === "a/fraction")).not.toHaveProperty("contextWindow");
546546
expect(models.find(model => model.id === "a/zero")).not.toHaveProperty("contextWindow");
547+
// DSH reads maxTokens as the real output ceiling and falls back to 32768 without it,
548+
// so a known limit must ride along with the context window (see #5828 for the same
549+
// failure in the other exporters). No context window means no limit claim either.
547550
for (const model of models) expect(model).not.toHaveProperty("maxTokens");
551+
const withLimit = dshConfig(ctx({
552+
models: [{ namespaced: "a/limit", provider: "a", id: "limit", contextWindow: 200_000, maxTokens: 128_000 }],
553+
}))["llm-pi-ai"].providers.opencodex!.models;
554+
expect(withLimit[0]!.maxTokens).toBe(128_000);
548555
});
549556

550557
test("maps only authoritative effort levels to DSH level-to-wire entries", () => {

0 commit comments

Comments
 (0)