context: the last-cache fix fits the core script budget again
5b25d7e9e(shenggxhz on X) added 106 bytes of code to context.js while the core scripts sat exactly at their budget (1,268,645 at its parent), so TestCoreScriptBudget has been red on main since (1,268,751). The budget is not raised; the change is packed instead: - Routing passes the session key whole (sk, the conversation, or the line's first request), so ctxCard keys on opts.session alone. Routing is ctxCard's only caller. - cacheOf takes a missing route, so the seed is `lastCache ||= cacheOf(opts.prev)`, and the cache shows when lastCache is set: it is set only by a shown cache (cacheShown) or by prev, which Routing passes only for a request under way, so `live &&` added nothing. - Three nearby lines in the same card packed to one statement each (the health word, the big figure, the cache's class), same output. core scripts now 1,268,634 of 1,268,645 (117 bytes less than5b25d7e9e). Run (mica-run, at this tree on5b25d7e9e): go test ./internal/gui -run 'TestCoreScriptBudget|TestAppScriptBudget' ok; node --test routing-ctx-cache-long, -still, -sessions, -fold, i18n-keys, context-cap, ctx-session-line: 150 of 154. The 4 reds are context-cap chromium en/zh (#6514) and ctx-session-line's session-line test in both engines (#5801), red the same on main before this. Broken by hand: without `|| lastCache` in the cache's condition, and separately without the prev seed, routing-ctx-cache-long goes 12 of 22 red in both engines. Not tried: the real app; the change has no new behaviour, and the Routing ctx GUI files cover the card's cache states in both engines.
This commit is contained in:
@@ -92,7 +92,7 @@
|
||||
|
||||
// the cache a route's vendor read: its last answer's usage
|
||||
function cacheOf(r) {
|
||||
const u = r.usage?.[r.usage.length - 1];
|
||||
const u = r?.usage?.[r.usage.length - 1];
|
||||
// a vendor that counts no cache has none to show, not 0% (#3464)
|
||||
if (!u || u.cache_unknown) return null;
|
||||
const total = (u.in || 0) + (u.cache_read || 0) + (u.cache_write || 0);
|
||||
@@ -805,12 +805,10 @@
|
||||
k.append(el("span", "", t("Context used")));
|
||||
if (window) {
|
||||
const [tone, word] = health(full);
|
||||
const h = el("span", "ctx-health " + tone, t(word));
|
||||
k.append(h);
|
||||
k.append(el("span", "ctx-health " + tone, t(word)));
|
||||
}
|
||||
const big = el("div", "ctx-big");
|
||||
big.append(num("b", "", p.tokens));
|
||||
big.append(el("span", "", window ? "/ " + fmtK(window) + " " + t("tokens") : t("tokens")));
|
||||
big.append(num("b", "", p.tokens), el("span", "", window ? "/ " + fmtK(window) + " " + t("tokens") : t("tokens")));
|
||||
const sub = el("div", "ctx-sub");
|
||||
if (window) {
|
||||
const bits = [t("{pct} full", { pct: pct(full) })];
|
||||
@@ -829,14 +827,14 @@
|
||||
// first request: Routing keeps the latest 60 requests, so in a long
|
||||
// session that first one moved on with each new request, and every
|
||||
// request under way showed "—" (shenggxhz on X, Codex in T3 Code)
|
||||
const whose = r.agent + " " + (opts.session ?? opts.series?.[0]?.id ?? "");
|
||||
const whose = r.agent + " " + opts.session;
|
||||
if (whose !== cacheWhose) lastCache = null;
|
||||
cacheWhose = whose;
|
||||
// opened while a request is under way, the session's last answered
|
||||
// request is the cache to show till this one's is read
|
||||
if (!lastCache && opts.prev) lastCache = cacheOf(opts.prev);
|
||||
lastCache ||= cacheOf(opts.prev);
|
||||
const known = cache && p.counted !== false ? cache : null;
|
||||
if (known || cacheShown || (live && lastCache)) {
|
||||
if (known || cacheShown || lastCache) {
|
||||
// once shown, the cache keeps its place, so nothing under it moves
|
||||
// up and back down. A request under way has read no cache yet:
|
||||
// the last request's stays, dimmed and named as the last one's,
|
||||
@@ -844,7 +842,7 @@
|
||||
// request flashed it to "—" and an empty bar, the dash against
|
||||
// 命中). Nothing to show is said in words, with no bar
|
||||
const shown = known || (live ? lastCache : null);
|
||||
const c = el("div", "ctx-stat ctx-cache" + (!known && shown ? " was" : shown ? "" : " none"));
|
||||
const c = el("div", "ctx-stat ctx-cache" + (known ? "" : shown ? " was" : " none"));
|
||||
c.append(el("div", "ctx-k", t("Prompt cache")));
|
||||
const cb = el("div", "ctx-big");
|
||||
cb.append(el("b", "", shown ? hitPct(shown.read / shown.total) : "—"), el("span", "", t("hit")));
|
||||
|
||||
@@ -3377,7 +3377,7 @@ function routingPage(part) {
|
||||
const prev = !r.done && series ? sessionReqs.filter((x) => same(x) && x.done && x.id < r.id && x.usage?.length).sort((a, b) => b.id - a.id)[0] : null;
|
||||
draw(r, {
|
||||
still, series, tab: ctxTab, place: "routing", foldable: true,
|
||||
session: sk || r.conv || undefined, prev,
|
||||
session: sk || r.conv || series?.[0]?.id, prev,
|
||||
open: ctxFor === r.id, onFold: () => { ctxFor = 0; },
|
||||
onTab: (id) => { ctxTab = id; },
|
||||
crumbs: [agentName(r.agent), sess && (sess.length > cut ? sess.slice(0, cut - 2) + "…" : sess), "#" + r.id],
|
||||
|
||||
Reference in New Issue
Block a user