·5 min read
DailyBrief's run estimate averaged two programs, so I switched to a median by kind
The estimate DailyBrief makes before an AI run was wrong in a way I could read straight off the code: it averaged the last ten successful runs of a mode, and those ten came from two different programs. Before the lean runner shipped, a run cost 5 to 10 times the tokens and time it does now, and the journal still held them.
- Project
- DailyBrief
- Date
- Oct 2026
- Stack
- Node.js, Electron, node:test
- Commit
- 79aacff
The estimate that sat in the toolbar
DailyBrief keeps a journal of AI runs in ai-runs.jsonl: mode, status, token counts, cost, duration. Before starting a run, main.js predicts its tokens, cost and duration from that journal. The prediction used to be this:
const same = readRuns().filter((r) =>
r.mode === mode && r.status === 'ok' && ((r.inputTokens || 0) + (r.outputTokens || 0) > 0 || (r.costUsd || 0) > 0)
).slice(-10);
if (same.length) {
const avg = (k) => Math.round(same.reduce((s, r) => s + (r[k] || 0), 0) / same.length);
...
}A reasonable first version: same mode, successful runs, last ten, mean. Three things made it wrong, and the header comment of the new module names all three.
Three ways the mean misled
Old runs belonged to a different program. The lean runner arrived in 1.8.0 and cut tokens and time sharply. Runs older than that were at 5 to 10 times today's cost, yet they stayed in the last-ten window for as long as the user had not run ten new ones. The new module hard-codes the day the lean runner shipped and ignores everything before it:
// The lean runner shipped this day; anything older is a different program.
const LEAN_SINCE = Date.parse('2026-10-26T15:00:00Z');
const WINDOW = 9; // newest runs considered
const MIN_SAME_KIND = 2; // below this, fall back to every run of the modeOne slow outlier dragged a mean far up. A single slow run shifts an average of ten a lot. A median does not move. The test for this uses durations of 6, 7, 8, 9 and 120 seconds and expects 8.
Different kinds of check were averaged together. mode: 'check' covers four quite different jobs: one task, one project's shard of a parallel batch, the batch's new-task pass, and the whole board. The code comment says a 6 s per-project check was being averaged with a 30 s whole-board one. So a run now has a kind, derived from its own fields:
function runKind(r) {
const x = r || {};
if (x.variant === 'newtasks') return 'newtasks';
if (x.taskId) return 'task';
if (x.scope || x.batchId) return 'shard';
return 'board';
}startCheck passes the shape of the run it is about to launch (taskId, scope, batchId, and a variant of newtasks when applicable) into estimateRun(mode, ctx), and the estimator compares like with like.
Why a threshold of two
Filtering to the same kind is only safe if there is enough of it. With one old task-run in the journal, a "same kind" estimate would be that single run, outlier or not. MIN_SAME_KIND = 2 makes the module fall back to every lean-era run of the mode when the kind has fewer than two. The selection itself is short:
const kind = runKind(ctx);
const same = all.filter((r) => runKind(r) === kind);
const pool = (same.length >= MIN_SAME_KIND ? same : all).slice(-WINDOW);
const med = (k) => median(pool.map((r) => r[k] || 0));The result carries samples: pool.length, so the caller can tell how much history stood behind a number.
Seeds for a journal that is empty
When there is no usable history, such as a fresh install or the first day after an upgrade, the code falls back to seed constants. These were also stale. The comment records that on the lean runner one model turn measured 10 to 35 s for everything except the brief and execution, and the seeds moved to match: full 60 to 35 s, replan 50 to 15, check 30 to 15, task-command 30 to 12, and so on, with execute unchanged at 600. Checks got per-kind seeds of their own: task 12, shard 10, new-task pass 8, whole board 15. The comment says the journal's own median takes over after two lean runs.
Pinning it with tests
The estimator is pure: main.js passes the parsed runs in, so it can be tested with plain arrays. test/estimate.test.js has five cases using node:test:
runKindtells task, shard, new-task pass and whole board apart.- Pre-lean runs are ignored: a fixture run from August with 140000 input tokens and 67 s does not touch an estimate of 8 s and 4000 tokens, and a journal with only old runs returns
null, so the seeds are used. - The median ignores the 120 s outlier.
- Same kind is preferred when there are two or more, otherwise every run of the mode answers. In the fixture, a shard estimate from two runs of 6 s and 8 s gives 7, a whole-board estimate over four runs gives 31, and a single task run is not enough to answer for its kind.
- Skipped, failed and token-less runs never count.
Those fixture values are made up for the tests; they are not measurements of my real runs.
What I would repeat
Two habits from this change. First, when a metric's meaning changes at a known moment, put that moment in the code as a constant with a comment; here the old data was not wrong, it described a program that no longer exists. Second, an average over a mixed population answers nobody's question. If the journal already records enough to say what kind of run each entry was, the estimate should use that before it uses arithmetic.
#javascript#electron#testing#estimation
Keep reading
Have a project in mind?