Context-meter amendment: CONTEXT_LIMITS dies — pi's live catalog is the only limit source

Owner ruling (2026-09-23, amendment to 04e336d): no hardcoded fallback
exists anywhere. contextWindow(record, limits) resolves the denominator
ONLY from the live index (provider:id -> contextWindow straight from
pi's catalog); a model missing from it (historical session, package
update, failed fetch) reads limit null and the meter renders
usage-only — the honest-render precedent, never a fake window.

- src/core/prices.ts: the 1354-entry CONTEXT_LIMITS table (65KB) and its
  generation apparatus deleted; the fold returns limit: number | null.
  PRICES untouched (regen verified byte-identical via the reworked
  sync-pricing script).
- scripts/sync-pricing.ts: generates PRICES only; contextWindow leaves
  the priced map, the guard, and the template.
- The dock meter's owner-selected treatment: the activity feed carries
  the limit server-side. catalogContextLimits() (server/model-catalog.ts)
  builds the index over the same keyed providers the picker federates;
  activityFeed() joins it onto every running job (ActivityJob.contextLimit,
  null when the model is missing — the dock reads it off the feed, no
  client-side table, no regression while the UI's catalog-join chunk lands).
- components/activity-dock.tsx: toBlobs reads job.contextLimit (import
  of CONTEXT_LIMITS gone); stats-bar renders usage-only on null limit
  (mechanical interim — UI stream's join chunk follows).
- tests: usage.test.ts pins the no-fallback contract (index hit / absent
  / empty / missing-model -> null); activity-feed.test.ts pins the
  server join (catalog model -> 1048576, unknown -> null, no-usage ->
  null); render pins updated to the interim usage-only render.
This commit is contained in:
amosblomqvist
2026-09-24 02:10:06 +03:00
parent b68a16fdb4
commit 4ded547cb5
11 changed files with 200 additions and 1450 deletions
+39
View File
@@ -59,3 +59,42 @@ test("activityFeed: running jobs across ALL chats, running-only, title-joined, o
}
}
});
test("activityFeed: contextLimit is the server's live-catalog join (owner amendment, 2026-09-23)", () => {
// keyed-provider federation — the same env-key pattern as the
// model-catalog tests; file-local (each test file is its own process)
process.env.OPENROUTER_API_KEY ??= "test-key-openrouter-catalog";
const chat = chatStore.createChat("limit join chat");
const createdJobs: string[] = [];
const usageFor = (model: string) => ({
model,
inputTokens: 1_000,
outputTokens: 100,
cacheReadTokens: 0,
cacheWriteTokens: 0,
reasoningTokens: 0,
steps: 1,
});
try {
const known = jobStore.createJob({ kind: "research", chatId: chat.id, toolCallId: "tc_known" });
const unknown = jobStore.createJob({ kind: "research", chatId: chat.id, toolCallId: "tc_unknown" });
const bare = jobStore.createJob({ kind: "research", chatId: chat.id, toolCallId: "tc_bare" });
createdJobs.push(known.id, unknown.id, bare.id);
jobStore.updateJob(known.id, { usage: usageFor("openrouter:z-ai/glm-5.3-flash") });
jobStore.updateJob(unknown.id, { usage: usageFor("nope/unknown") });
const feed = activityFeed();
const knownJob = feed.jobs.find((j) => j.id === known.id)!;
assert.equal(knownJob.contextLimit, 1_048_576, "pi's catalog, joined server-side onto the feed");
const unknownJob = feed.jobs.find((j) => j.id === unknown.id)!;
assert.equal(unknownJob.contextLimit, null, "missing from the live catalog → null, never a guessed window");
const bareJob = feed.jobs.find((j) => j.id === bare.id)!;
assert.equal(bareJob.contextLimit, null, "no usage yet → no context line");
} finally {
fs.unlinkSync(`${PATHS.chats}/${chat.id}.json`);
const jobsDir = path.join(PATHS.data, "jobs");
for (const id of createdJobs) {
fs.unlinkSync(path.join(jobsDir, `${id}.json`));
}
}
});