mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 05:57:09 +01:00
Prod, 2026-09-20. The KPI row read: 9 Needs you · 1 Shipped · 0 Running · 49 Queued Four of those are links that filter the list below. "Queued" was a <span>. So the largest figure on the page — and the one that most obviously wants investigating, 49 waiting while nothing at all was running — was the one thing you could not click. Its only explanation was a `title` tooltip, which a touch device never shows at all. CLAUDE.md states the rule this breaks: "A gate records; it never blocks. Anything that pauses a person shows the way forward on the same screen." Queued is now a filter like the rest: a tab, a tally, and a list. The part worth care is that the rule lives in ONE place. `eventIsQueued` is exported and used by the hero's count, the tab's tally and the filtered list alike. Two copies would be worse than none — a count and a list that disagree teach people to trust neither, which is the failure this repo keeps finding in other forms. The predicate also carries the precedence the summary already used: attention outranks queued, so a dispatch that never reached an agent is reported as needing you rather than as patiently waiting. Proved by mutation: letting the filter drift from the count by one clause (including local chats) fails 2 of the 6 cases, one of them the explicit count == tally == list invariant. Typed into place, not guessed: `FILTER_LABEL` is a `Record<ActivityFilter, string>`, so adding the filter made the compiler demand the label. verify: format:check, tsc, lint (0 errors, 2 pre-existing warnings), check:design (11), check:desktop, test:home 130/130. test:unit 222/224 — activity-time-zone-stable and telegram-allowlist need a live local server; both fail identically on a detached worktree of pristine origin/main, checked again here because this diff touches activity files. Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
114 lines
3.8 KiB
TypeScript
114 lines
3.8 KiB
TypeScript
/**
|
|
* The biggest number on the Activity page was the one you could not open.
|
|
*
|
|
* Prod, 2026-09-20: the KPI row read "9 Needs you · 1 Shipped · 0 Running ·
|
|
* 49 Queued". Four of those were links that filter the list below. "Queued"
|
|
* was a <span> — its only explanation a `title` tooltip, which a touch device
|
|
* never shows. So the largest figure on the page, and the one that most needs
|
|
* investigating (49 waiting while nothing runs), was a wall.
|
|
*
|
|
* The rule that decides it now lives in ONE place, `eventIsQueued`, used by
|
|
* the hero's count, the tab's tally and the filtered list alike. Two copies
|
|
* would be worse than none: a count and a list that disagree teach people to
|
|
* trust neither.
|
|
*
|
|
* Run: npx tsx scripts/test/activity-queued-filter.ts
|
|
*/
|
|
import {
|
|
eventIsQueued,
|
|
filterActivityEvents,
|
|
tallyActivityEvents,
|
|
ACTIVITY_FILTERS,
|
|
type ActivityEvent,
|
|
} from "@/lib/activity-events";
|
|
import { summarizeActivity } from "@/lib/activity-summary";
|
|
|
|
let failures = 0;
|
|
function check(name: string, fn: () => void) {
|
|
try {
|
|
fn();
|
|
console.log(` ✓ ${name}`);
|
|
} catch (err) {
|
|
failures++;
|
|
console.log(` ✗ ${name}`);
|
|
console.log(` ${err instanceof Error ? err.message : String(err)}`);
|
|
}
|
|
}
|
|
function assert(cond: boolean, msg: string) {
|
|
if (!cond) throw new Error(msg);
|
|
}
|
|
|
|
const E = (over: Partial<ActivityEvent>): ActivityEvent =>
|
|
({
|
|
id: Math.random().toString(36).slice(2),
|
|
occurredAt: "2026-09-20T12:00:00.000Z",
|
|
projectKey: "loki",
|
|
agentLabel: "Claude Code",
|
|
intentLabel: "custom",
|
|
intentId: "custom",
|
|
status: "neutral",
|
|
outcome: "dispatched",
|
|
outcomeLabel: "Dispatched",
|
|
durationLabel: null,
|
|
durationMs: null,
|
|
ask: null,
|
|
done: null,
|
|
next: null,
|
|
error: null,
|
|
verification: null,
|
|
isLocalChat: false,
|
|
runId: null,
|
|
promptId: "p1",
|
|
...over,
|
|
}) as ActivityEvent;
|
|
|
|
console.log("activity-queued-filter:");
|
|
|
|
check("queued is a real filter, not just a number", () => {
|
|
assert(ACTIVITY_FILTERS.includes("queued"), "filter must exist");
|
|
});
|
|
|
|
check("a dispatch with no run counts as queued", () => {
|
|
assert(eventIsQueued(E({})), "plain dispatch");
|
|
});
|
|
|
|
check("a local chat is never queued work", () => {
|
|
// It is a conversation, not a dispatch waiting on a builder.
|
|
assert(!eventIsQueued(E({ isLocalChat: true })), "local chat excluded");
|
|
});
|
|
|
|
check("anything needing attention outranks queued", () => {
|
|
// Matches the order the summary already used: a dispatch that never reached
|
|
// an agent is reported as needing you, not as patiently waiting.
|
|
assert(!eventIsQueued(E({ outcome: "unconfirmed" })), "unconfirmed is attention");
|
|
assert(!eventIsQueued(E({ outcome: "error" })), "error is attention");
|
|
});
|
|
|
|
check("finished work is not queued", () => {
|
|
assert(!eventIsQueued(E({ outcome: "success" })), "success");
|
|
assert(!eventIsQueued(E({ outcome: "running" })), "running");
|
|
});
|
|
|
|
check("THE INVARIANT: the count, the tally and the list agree", () => {
|
|
// This is the whole point. If these three ever diverge, the page is lying
|
|
// to someone — and that is exactly the shape of bug this fix removes.
|
|
const events = [
|
|
E({}),
|
|
E({}),
|
|
E({ isLocalChat: true }),
|
|
E({ outcome: "success" }),
|
|
E({ outcome: "running" }),
|
|
E({ outcome: "error" }),
|
|
];
|
|
const summary = summarizeActivity(events);
|
|
const tallies = tallyActivityEvents(events);
|
|
const listed = filterActivityEvents(events, "queued");
|
|
assert(summary.queued === 2, `hero count: ${summary.queued}`);
|
|
assert(tallies.queued === 2, `tab tally: ${tallies.queued}`);
|
|
assert(listed.length === 2, `list length: ${listed.length}`);
|
|
assert(listed.every(eventIsQueued), "every listed row is queued");
|
|
});
|
|
|
|
console.log(failures === 0 ? "\nall passed" : `\n${failures} failed`);
|
|
process.exit(failures === 0 ? 0 : 1);
|