the progress round: the provider streams, and the two long waits get honest meters -- the refine battery and her turn. The provider (provider.mjs): every completion now streams (vLLM SSE, probed live first: reasoning_content deltas arrive before content deltas, stream_options include_usage puts the full usage on the tail chunk) and assembles back into the one ChatResponse shape every caller already consumed -- content and reasoning in order, tool_calls stitched by index (id and name on the first fragment, arguments concatenated from shards, the assembled arguments parse), usage from the tail; a malformed data line fails loud where a skipped one would silently truncate, the log still records the assembled message whole, and an optional fifth param onProgress({phase, chars}) fires per delta as the meters' feed (ChatResponse names finish_reason, the wire shape the old typedef omitted). One cosmetic wire delta, named: streamed messages carry no provider_specific_fields (vLLM's duplicate reasoning channel plus refusal:null) -- nothing reads it. The refine meter (discovery.mjs + the home admin block): the job carries steps {total, done, label, chars} where the total is the scrape's model count plus the curator's two (thinking, writing), known the moment the scrape lands; the bar moves ONLY on real completions (GM, 2026-11-17: no step has a knowable duration, the point is meaningful feedback, not smooth fill), the label names the running call down to the effort-ladder sample, every completion lands a receipt line (elapsed seconds + the battery verdict), and the lines SURVIVE the job -- the receipt renders until the next refine (GM ruling: no reason to delete the log) and a rejected pass keeps its post-mortem; the curator's thinking step closes at the first prose delta (the streaming boundary -- why the provider went first), writing at the call's resolve, and a dead call closes both honestly; the 2s poll stays the transport (GM-ruled; SSE was rejected -- EventSource cannot send the Bearer header, and tokens in query strings are worse). The turn meter (loop.mjs + the progress route + the play view): the session carries a live progress record, one per provider call (a heal or tool round restarts it), fed by the streaming callback and cleared at every exit (the ask pause, the 422, the completing return, the failed request); GET /runs/:id/progress (owner-only, never queued) returns it plus the scale the bar guesstimates against -- the only true budget is max_tokens when the knobs set one (reasoning counts inside it, the usage arithmetic proves it; the route mirrors the loop's own param resolution at ~4 chars a token), else her own history: the longest past assistant turn in chars, thinking and prose both, the authored opening included (GM: a guesstimate, but an informed one). The 100% crossing pushes back geometrically: the scale grows by a quarter until the count fits, so the bar re-lands in the 80-100% band and climbs again, the same arithmetic every poll, never pinning (a count just under a grown bracket can still round to 100% for a moment -- named and accepted). No scale at all falls to the chunk-driven fallback: a twelve-segment strip, one lit, stepping ONLY when characters actually arrived -- never a free-running spinner, which would claim liveness the stream may not have; a stall shows as a stall. NO live partial prose in the transcript (the log is the one truth; streaming raw text would leak unpicked variants and half-formed heals onto the surface that shows them composed) -- the placeholder is a live div at the transcript foot, rebuilt when a render wipes it, sticking to bottom only when the scroller was already there, and the poll runs at 1s for turns (2s for refine). Verified: the provider live-probed against the real endpoint (prose+usage, thinking+progress transitions, a forced tool call with parseable arguments, the 403 path), a REAL refine run end to end on the GM's authorization (13 models, 541s, the meter exactly to spec with the curator's thinking ticking 4k-17k chars across polls) which also landed the effort measurements the registry was waiting for -- the deterministic re-pick is glm-5.3-max, and server.json's own pin still beats it until the op edits it -- smoke ALL PASS with the new assertions (the refine steps closed, the receipt's lines, the meter idle on a dormant run, idle-between-turns scaled by history, owner-gating; the first cut of the receipt assertion named the wrong mock tie-winner and the first cut of the dormant check clobbered a shared response variable -- both assertion bugs, the code was right), restart + reminder + repo checks green, typecheck green on both programs, and a disposable live run (created, three real turns, housekept, deleted) proving the meter in the browser with zero console errors: chars ticking, the phase flip at the streaming boundary, the scale re-anchoring to her new longest after each turn. Live findings on record: the measured effort default now rides every unset turn, and the test run's turns thought 12.1k/3.9k/6.5k chars against ~1.4k prose -- the max-observable default working as ruled, and the fresh-run decision the GM will make with the knob one click away; and the browser lesson pinned in AGENTS: the meter's DOM is invisible to a11y wait-text matching, so a whole frozen-meter scare during testing was a sampling artifact (the waits matched instantly against unrelated text) -- probe such widgets by DOM, never by wait

This commit is contained in:
2026-11-17 02:21:38 +00:00
parent eebc1993dd
commit bbaf33635c
13 changed files with 481 additions and 26 deletions
+60 -10
View File
@@ -133,12 +133,14 @@ async function thinkingTokens(ctx, id, params) {
* 2026-11-16: maximum observable thinking by default, overridable
* by the user). A model that shows no thinking, or that no level
* moves, gets null -- nothing rides.
* @param {Ctx} ctx @param {string} id @returns {Promise<{ efforts: Record<string, number>, effortDefault: ?string }>} */
async function probeEfforts(ctx, id) {
* @param {Ctx} ctx @param {string} id @param {(s: string) => void} [say]
* @returns {Promise<{ efforts: Record<string, number>, effortDefault: ?string }>} */
async function probeEfforts(ctx, id, say = () => {}) {
/** @type {Record<string, number>} */ const efforts = {};
for (const level of EFFORT_LEVELS) {
const xs = [];
for (let i = 0; i < 2; i++) {
say(`${level}, sample ${i + 1}/2`);
try { xs.push(await thinkingTokens(ctx, id, { reasoning_effort: level })); } catch { xs.push(0); }
}
efforts[level] = Math.round(xs.reduce((a, b) => a + b, 0) / xs.length);
@@ -152,11 +154,13 @@ async function probeEfforts(ctx, id) {
* exact request shape a player turn takes), the reasoning samples,
* the off-switch probe, the effort ladder. Every failure is a
* verdict, never an abort.
* @param {Ctx} ctx @param {RegistryModel} m @returns {Promise<RegistryModel>} */
async function probeOne(ctx, m) {
* @param {Ctx} ctx @param {RegistryModel} m @param {(s: string) => void} [say]
* @returns {Promise<RegistryModel>} */
async function probeOne(ctx, m, say = () => {}) {
const base = { ...m };
delete base.status; // the scrape's mark -- a probed record is no longer unrefined
if (ctx.mock) {
say('the canned battery');
// the canned battery: all three stand-ins are inference models;
// mock and mock-tie are a deliberate tie pair (same deep bucket,
// same windows -- only the lex rule can part them), the cheap
@@ -170,6 +174,7 @@ async function probeOne(ctx, m) {
efforts: { none: 0, minimal: 40, low: 100, medium: 200, high: 300, xhigh: 400, max: 500 }, effortDefault: 'max' };
}
const t0 = Date.now();
say('the tool probe');
try {
await ctx.provider.chat(m.id, [{ role: 'user', content: 'Say OK.' }], [ASK_GM_TOOL], { max_tokens: 400 });
} catch (e) {
@@ -179,12 +184,14 @@ async function probeOne(ctx, m) {
const latency = Date.now() - t0;
const samples = [];
for (let i = 0; i < 2; i++) {
say(`the thinking samples, ${i + 1}/2`);
try { samples.push(await thinkingTokens(ctx, m.id, {})); } catch { samples.push(0); }
}
const think = Math.max(...samples);
/** @type {Record<string, unknown>|null} */ let offSwitch = null;
if (think > 0) {
try {
say('the off-switch probe');
if (await thinkingTokens(ctx, m.id, { chat_template_kwargs: { enable_thinking: false } }) === 0) {
offSwitch = { chat_template_kwargs: { enable_thinking: false } };
}
@@ -194,7 +201,7 @@ async function probeOne(ctx, m) {
/** @type {?string} */ let effortDefault = null;
if (think > 0) {
try {
({ efforts, effortDefault } = await probeEfforts(ctx, m.id));
({ efforts, effortDefault } = await probeEfforts(ctx, m.id, (s) => say(`the effort ladder: ${s}`)));
} catch { /* the ladder is optional knowledge -- absent on a flaky endpoint */ }
}
return { ...base, inference: true, think, reasoning: bucket(think), offSwitch, efforts, effortDefault, latency };
@@ -224,8 +231,9 @@ function rankSort(models) {
* probed inference ids, no inventions; any violation discards the
* whole output and the machine list stands.
* @param {Ctx} ctx @param {RegistryModel[]} probed @param {RegistryModel} best @param {?Actor} user
* @param {?import('./provider.mjs').ProgressFn} [onProgress] @param {?(() => void)} [onRetry]
* @returns {Promise<{ list: { id: string, family: ?string, label: ?string, description: ?string, player: boolean, housekeeper: boolean }[], note: string }>} */
async function curate(ctx, probed, best, user) {
async function curate(ctx, probed, best, user, onProgress = null, onRetry = null) {
if (ctx.mock) {
return {
list: [
@@ -252,11 +260,12 @@ async function curate(ctx, probed, best, user) {
let data = null;
for (let attempt = 0; attempt < 2; attempt++) {
try {
data = await ctx.provider.chat(best.id, messages, undefined, {});
data = await ctx.provider.chat(best.id, messages, undefined, {}, onProgress);
break;
} catch (e) {
if (attempt === 1) throw e;
console.log(`${new Date().toISOString().slice(11, 19)} curator call failed (${String(e.message ?? e).split('\n')[0]}) -- retrying once`);
onRetry?.();
}
}
if (!data) throw new Error('the curator call failed twice');
@@ -299,23 +308,63 @@ export function refine(ctx, user) {
if (ctx.jobs.get(JOB_KEY)?.state === 'running') {
throw new HttpError(409, 'a refine is already running');
}
const job = /** @type {JobState} */ ({ state: 'running', phase: 'refine', started: new Date().toISOString() });
// the meter: one step per model's battery plus the curator's two
// (thinking, writing) -- the count is known the moment the scrape
// lands. No step has a duration to guess at (GM, 2026-11-17): the
// bar moves only on real completions, the label names the call
// running now, and every completion lands a receipt line -- the
// lines survive the job, so a rejected pass keeps its post-mortem
const t0 = Date.now();
// the local view narrows steps/lines to present -- the job is born
// with them, and the reporter writes through this reference
const job = /** @type {JobState & { steps: { total: number, done: number, label: string, chars?: number }, lines: string[] }} */ ({
state: 'running', phase: 'refine', started: new Date().toISOString(),
steps: { total: 0, done: 0, label: 'scraping the provider surface' }, lines: [],
});
ctx.jobs.set(JOB_KEY, job);
/** @param {string} s */ const say = (s) => { job.steps.label = s; };
/** @param {string} s */ const line = (s) => { job.lines.push(`${Math.round((Date.now() - t0) / 1000)}s ${s}`); };
void (async () => {
try {
const scraped = await scrape(ctx); // fresh metadata -- ids can drift between discoveries
job.steps.total = scraped.length + 2;
/** @param {RegistryModel} m @returns {string} */
const verdict = (m) => m.inference === false
? `failed the tool probe -- ${m.fail}`
: `reasoning ${m.reasoning} \u00b7 ${m.think} think tokens \u00b7 ${m.offSwitch ? 'off switch' : 'no off switch'} \u00b7 ${m.latency}ms${m.effortDefault ? ` \u00b7 effort default ${m.effortDefault}` : ''}`;
const probed = [];
for (const m of scraped) probed.push(await probeOne(ctx, m));
for (const [i, m] of scraped.entries()) {
probed.push(await probeOne(ctx, m, (s) => say(`battery ${i + 1}/${scraped.length}: ${m.id} -- ${s}`)));
job.steps.done++;
line(`${m.id}: ${verdict(probed[i])}`);
}
const passing = probed.filter((m) => m.inference);
if (!passing.length) throw new Error('no model passed the inference battery -- the provider surface has nothing playable');
const best = rankSort(passing)[0];
/** @type {{ list: { id: string, family: ?string, label: ?string, description: ?string, player: boolean, housekeeper: boolean }[], note: string }} */
let curated = { list: [], note: 'fallback: not attempted' };
// the curator's two steps, marked from real events: thinking
// completes at the first prose delta (the streaming boundary),
// writing at the call's resolve; a dead call closes both -- the
// attempt is over, and the fallback carries the job
let proseStarted = false;
say(`curator (${best.id}): thinking`);
try {
curated = await curate(ctx, probed, best, user);
curated = await curate(ctx, probed, best, user, (p) => {
job.steps.chars = p.chars;
if (p.phase === 'prose' && !proseStarted) {
proseStarted = true;
job.steps.done++;
say('curator: writing');
}
}, () => say(`curator (${best.id}): retrying -- thinking`));
} catch (e) {
curated = { list: [], note: `fallback: the curator call failed (${String(e.message ?? e).split('\n')[0]})` };
}
job.steps.done = job.steps.total; // the attempt is over -- whatever remains closes with it
delete job.steps.chars;
say('writing the registry');
line(curated.note === 'curated' ? `curator (${best.id}): curated \u00b7 ${curated.list.length} labeled` : `curator: ${curated.note}`);
const byId = new Map(curated.list.map((c) => [c.id, c]));
const models = probed.map((m) => {
const c = m.inference ? byId.get(m.id) : undefined;
@@ -338,6 +387,7 @@ export function refine(ctx, user) {
models,
curator: curated.note,
}));
say('done');
job.state = 'applied';
} catch (e) {
job.state = 'rejected';