mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 12:27:28 +01:00
* fix(loki): own-key turns get time to think, a way out when they fail, and settings that say what they did
From George's first real session on his own key (xAI grok-4.7, 2026-10-10):
- A model call is bounded by silence, not a stopwatch (lib/agent/call-timeout.ts):
first byte within 90 s on an own key (30 s on the free chain), at most 30 s
between bytes, a 5-minute ceiling. The single 30 s AbortSignal.timeout on
the whole fetch killed a reasoning model that thought for longer than that.
The failure sentence says which limit hit. Fake-clock test.
- A turn the person's own model failed offers "Answer with the free models
instead" under it (meta.ownModelFailed + pendingText → OwnModelFallbackOffer):
the same words on the free chain, for that turn only (AskLokiOpts.pool,
body.pool), chosen by them — never a silent switch. The error sentence drops
the walker's "no chat model answered:" plumbing.
- Model picker: the card and its rows are shrink-0 — in the phone sheet they
were flex items of a height-capped scroller and shrank to 56px, so a
two-line subtitle spilled over the next row. A vendor label already cased
("xAI") is no longer re-cased to "XAI".
- Settings → AI: each key's text block has basis-56, so the buttons wrap under
it instead of squeezing "grok-4.7" into one letter per line; break-words.
Every action leaves a sentence (added / changed / order saved / removed),
and a funded add runs POST /api/settings/model/test — one short real turn on
that key, timed — so "added" reads "Answered in 1.3 s — 'Hello…'". A Test
button per row repeats it.
- The key field is type="text" + ui-input-secret (masked), so the browser's
password manager stops offering to save an API key as the site's login.
- AI capacity copy no longer claims every answer runs on the free tier.
- CHANGELOG; models-and-money.md: time to think, proof that it works.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YKx4TPejLvFR9Uj4xrTf6Y
* chore(deps): chatkit 0.7.0 — the words as they are heard while the take is live
Pins @bitbaum/chatkit to b8b613d0 (bitbaum/chatkit#15): the browser's
recogniser previews the words beside the server-leg recording, dimmed while
the server transcribes, replaced by its words when they land. Lock entries
edited the way main's last bump was (codeload tarball, no integrity).
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YKx4TPejLvFR9Uj4xrTf6Y
---------
Co-authored-by: Claude <noreply@anthropic.com>
115 lines
3.3 KiB
TypeScript
115 lines
3.3 KiB
TypeScript
/**
|
|
* A model call is bounded by silence, not by a stopwatch.
|
|
*
|
|
* Pins src/lib/agent/call-timeout.ts on a fake clock: a slow first token
|
|
* that still arrives inside the first-byte limit is NOT a failure, bytes
|
|
* that keep flowing past the old 30 s are NOT a failure, silence is, and the
|
|
* total ceiling holds whatever flows.
|
|
*
|
|
* Run: npx tsx scripts/test/call-timeout.ts
|
|
*/
|
|
import assert from "node:assert/strict";
|
|
import { createCallTimeout, type TimerHost } from "@/lib/agent/call-timeout";
|
|
|
|
type Timer = { at: number; fn: () => void; id: number };
|
|
function fakeClock() {
|
|
let now = 0;
|
|
let seq = 0;
|
|
let timers: Timer[] = [];
|
|
const host: TimerHost = {
|
|
setTimeout: (fn, ms) => {
|
|
const t = { at: now + ms, fn, id: ++seq };
|
|
timers.push(t);
|
|
return t.id;
|
|
},
|
|
clearTimeout: (id) => {
|
|
timers = timers.filter((t) => t.id !== id);
|
|
},
|
|
};
|
|
const advance = (ms: number) => {
|
|
const until = now + ms;
|
|
for (;;) {
|
|
const due = timers.filter((t) => t.at <= until).sort((a, b) => a.at - b.at)[0];
|
|
if (!due) break;
|
|
now = due.at;
|
|
timers = timers.filter((t) => t.id !== due.id);
|
|
due.fn();
|
|
}
|
|
now = until;
|
|
};
|
|
return { host, advance };
|
|
}
|
|
|
|
const LIMITS = { firstByteMs: 90_000, idleMs: 30_000, totalMs: 300_000 };
|
|
let passed = 0;
|
|
function check(name: string, fn: () => void) {
|
|
fn();
|
|
passed++;
|
|
console.log(` ✓ ${name}`);
|
|
}
|
|
|
|
console.log("call-timeout:");
|
|
|
|
check("a first token at 60 s is not a failure under a 90 s first-byte limit", () => {
|
|
const { host, advance } = fakeClock();
|
|
const t = createCallTimeout(LIMITS, host);
|
|
advance(60_000);
|
|
assert.equal(t.signal.aborted, false);
|
|
t.sawByte();
|
|
advance(25_000);
|
|
assert.equal(t.signal.aborted, false, "25 s of quiet after a byte is within idle");
|
|
t.done();
|
|
});
|
|
|
|
check("no byte at all for 90 s aborts, and says so", () => {
|
|
const { host, advance } = fakeClock();
|
|
const t = createCallTimeout(LIMITS, host);
|
|
advance(90_000);
|
|
assert.equal(t.signal.aborted, true);
|
|
assert.equal(t.reason(), "no answer within 90 s");
|
|
});
|
|
|
|
check("bytes every 5 s for two minutes keep the call alive past the old 30 s", () => {
|
|
const { host, advance } = fakeClock();
|
|
const t = createCallTimeout(LIMITS, host);
|
|
for (let i = 0; i < 24; i++) {
|
|
advance(5_000);
|
|
t.sawByte();
|
|
}
|
|
assert.equal(t.signal.aborted, false);
|
|
t.done();
|
|
});
|
|
|
|
check("silence mid-answer aborts after the idle limit with its own sentence", () => {
|
|
const { host, advance } = fakeClock();
|
|
const t = createCallTimeout(LIMITS, host);
|
|
advance(1_000);
|
|
t.sawByte();
|
|
advance(30_000);
|
|
assert.equal(t.signal.aborted, true);
|
|
assert.equal(t.reason(), "went silent for 30 s mid-answer");
|
|
});
|
|
|
|
check("the total ceiling holds even while bytes keep flowing", () => {
|
|
const { host, advance } = fakeClock();
|
|
const t = createCallTimeout(LIMITS, host);
|
|
for (let i = 0; i < 61; i++) {
|
|
advance(5_000);
|
|
t.sawByte();
|
|
}
|
|
assert.equal(t.signal.aborted, true);
|
|
assert.equal(t.reason(), "still answering after 300 s — stopped waiting");
|
|
});
|
|
|
|
check("done() stops every timer, so a finished call never aborts late", () => {
|
|
const { host, advance } = fakeClock();
|
|
const t = createCallTimeout(LIMITS, host);
|
|
t.sawByte();
|
|
t.done();
|
|
advance(10 * 60_000);
|
|
assert.equal(t.signal.aborted, false);
|
|
assert.equal(t.reason(), null);
|
|
});
|
|
|
|
console.log(`\ncall-timeout: ${passed} passed`);
|