Merge branch 'perf/lag': dashboard lag fixes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

# Conflicts:
#	client/src/components/Sagi/PetSprite.tsx
#	client/src/components/Sagi/useSagiBrain.ts
This commit is contained in:
2026-10-14 12:26:41 +07:00
36 changed files with 676 additions and 101 deletions
+40
View File
@@ -234,6 +234,46 @@ describe("TranscriptCache tokensByHour", () => {
});
});
describe("writeHourly skips unchanged hours", () => {
const { writeHourly, forgetHourly } = require("../lib/hourly-usage");
const bucket = (input) => ({
hour: "2026-10-05T08",
model: "claude-opus-4-1",
speed: "standard",
geo: "",
tier: "standard",
input,
output: 0,
cacheRead: 0,
cacheWrite: 0,
cacheWrite1h: 0,
webSearch: 0,
webFetch: 0,
codeExec: 0,
});
const rows = () =>
db
.prepare("SELECT input_tokens FROM token_usage_hourly WHERE session_id = 'skip-hourly'")
.all()
.map((r) => r.input_tokens);
it("writes a changed hour, skips an unchanged one, and writes again once forgotten", () => {
session("skip-hourly", "2026-10-05T08:00:00.000Z");
writeHourly("skip-hourly", { a: bucket(5) });
assert.deepEqual(rows(), [5]);
writeHourly("skip-hourly", { a: bucket(9) });
assert.deepEqual(rows(), [9]);
// Deleted behind the writer's back: an unchanged bucket is not re-sent…
db.prepare("DELETE FROM token_usage_hourly WHERE session_id = 'skip-hourly'").run();
writeHourly("skip-hourly", { a: bucket(9) });
assert.deepEqual(rows(), []);
// …which is why every path that deletes hourly rows forgets them.
forgetHourly(["skip-hourly"]);
writeHourly("skip-hourly", { a: bucket(9) });
assert.deepEqual(rows(), [9]);
});
});
describe("session list cost", () => {
it("equals the session's own cost, speed and server-tool fees included", async () => {
session("list-fast", "2026-10-01T00:00:00.000Z");
+13
View File
@@ -142,6 +142,19 @@ describe("install-hooks host-only guard (#193)", () => {
});
});
describe("async hooks", () => {
it("runs only the per-tool-call hooks in the background, in settings and the plugin alike", () => {
const { makeHookEntry, ASYNC_HOOKS } = require("../../scripts/install-hooks");
const plugin = require("../../.claude-plugin/plugin.json");
assert.deepEqual([...ASYNC_HOOKS].sort(), ["PostToolUse", "PreToolUse"]);
for (const type of HOOK_TYPES) {
const want = ASYNC_HOOKS.has(type) ? true : undefined;
assert.equal(makeHookEntry(type).hooks[0].async, want, `settings ${type}`);
assert.equal(plugin.hooks[type][0].hooks[0].async, want, `plugin ${type}`);
}
});
});
describe("HOOK_TYPES", () => {
it("is the event list the plugin ships, so the hook status checks every one", () => {
const exported = require("../../scripts/install-hooks").HOOK_TYPES;
+1
View File
@@ -93,6 +93,7 @@ describe("GET /api/metrics", () => {
"agenthub_build_info",
"agenthub_process_uptime_seconds",
"agenthub_process_resident_memory_bytes",
"agenthub_event_loop_delay_seconds",
"agenthub_sessions",
"agenthub_agents",
"agenthub_events_total",
+15
View File
@@ -19,6 +19,21 @@ describe("tmux wrapper", () => {
assert.equal(tmux.hasSession("agenthub-lane-1"), true);
});
it("hasSession answers yes from a fresh list, and asks tmux for anything else", () => {
const calls = [];
tmux.__setExecImpl((args) => {
calls.push(args[0]);
if (args[0] === "list-sessions") return "agenthub-lane-1\nagenthub-lane-1-2\n";
throw Object.assign(new Error("no session"), { status: 1 });
});
tmux.listSessions("agenthub-lane-");
assert.equal(tmux.hasSession("agenthub-lane-1-2"), true);
assert.deepEqual(calls, ["list-sessions"]); // no has-session spawn
// Not listed: asked for real (a pane that just died is never trusted).
assert.equal(tmux.hasSession("agenthub-lane-1-3"), false);
assert.deepEqual(calls, ["list-sessions", "has-session"]);
});
it("hasSession returns false when execFileSync throws", () => {
tmux.__setExecImpl(() => {
const e = new Error("no such session");