Cost channel cull: the cluster-naming fold dies — two stages, two channels

Off UI's d651f93 flag (displayCostTotals already isolates the display to
extraction + audit; the naming stage row and naming runs were filtered
out client-side). This culls the server side of the same ruling.

THE STANDING RULING, REVERSED BY ITS OWN PREMISE: NamingRunUsage /
readNamingRuns / appendNamingUsage were kept at the wave-7 namer kill
ONLY because cost-summary's HISTORICAL naming stage read them. With the
fold culled, that premise dies — so the whole ledger read path goes too,
following the wave-7 embeddings precedent chain: consumer-less ledger
seams are deleted, and the on-disk naming-runs.jsonl stays INERT (real
trees keep their historical spend bytes; they are simply not displayed
anywhere — the same treatment as historical stages.embedding spend).

- core/cost-summary.ts: two channels in (chat + notes front doors), two
  stages out; RecentRun.kind collapses to "extraction" (labels field
  gone); CostSummaryInput.naming gone; totalDollars = extraction + audit.
- ports/store/contracts/config: appendNamingUsage + readNamingRuns ports,
  store impls + guards, the NamingRunUsage interface, and
  LEDGER_FILES.namingRuns die. graphRevision no longer counts the file
  (a smaller revision value is harmless — reads never compare).
- components/graph-view.tsx (mechanical, flagged): the defensive
  .filter(run.kind !== "naming") guards a kind that no longer exists.
- Tests: cost-summary's both-channels fold pins; the naming fixtures and
  the appendNamingUsage store pin die with the seams.
This commit is contained in:
amosblomqvist
2026-09-24 19:33:35 +03:00
parent 2cba283009
commit 73027f49bf
12 changed files with 33 additions and 153 deletions
+10 -24
View File
@@ -12,7 +12,7 @@ import {
type CostSummaryInput,
type GraphCostSummary,
} from "../src/core/cost-summary.ts";
import type { CallUsage, ExtractionRunUsage, NamingRunUsage } from "../src/core/contracts.ts";
import type { CallUsage, ExtractionRunUsage } from "../src/core/contracts.ts";
import { PRICES, callCost } from "../src/core/prices.ts";
/** A model with full published pricing (from the generated registry). */
@@ -43,40 +43,30 @@ const extractionRun = (
...(stats ? { stats } : {}),
});
const namingRun = (startedAt: number, model: string, appended: number): NamingRunUsage => ({
startedAt,
at: new Date(startedAt).toISOString(),
durationMs: 4_000,
model,
steps: [step(500, 50)],
stats: { detected: 8, claimed: 6, named: 2, appended },
});
describe("graphCostSummary (the cost pill's fold)", () => {
test("folds all three channels: stage totals, tokens, newest-first runs", () => {
test("folds both channels: stage totals, tokens, newest-first runs", () => {
// (The cluster-naming channel died with the extraction-UX close-out,
// 2026-09-24 — two channels: chat + notes front doors.)
const input: CostSummaryInput = {
chats: [{ title: "Testing session", extractions: [extractionRun(100, PRICED, PRICED)] }],
sources: [{ filePath: "/vault/modal.md", extractions: [extractionRun(200, PRICED, PRICED)] }],
naming: [namingRun(300, PRICED, 2)],
};
const s = graphCostSummary(input);
const extStep = callCost(step(1000, 200), PRICED)!;
const audStep = callCost(step(2000, 100), PRICED)!;
assert.equal(s.stages.extraction.dollars, extStep * 2);
assert.equal(s.stages.audit.dollars, audStep * 2);
assert.equal(s.stages.naming.dollars, callCost(step(500, 50), PRICED));
assert.equal(s.stages.extraction.runs, 2);
assert.equal(s.stages.naming.runs, 1);
assert.equal(s.stages.extraction.tokens.inputTokens, 2000);
assert.equal(s.stages.audit.tokens.outputTokens, 200);
assert.equal(s.totalDollars, extStep * 2 + audStep * 2 + callCost(step(500, 50), PRICED)!);
// All three runs, newest first, titles joined per front door.
assert.equal(s.totalDollars, extStep * 2 + audStep * 2);
// Both runs, newest first, titles joined per front door — every
// run is kind "extraction" now.
assert.deepEqual(
s.runs.map((r) => r.title),
["Cluster naming", "/vault/modal.md", "Testing session"],
["/vault/modal.md", "Testing session"],
);
assert.equal(s.runs[0]!.labels, 2);
assert.equal(s.runs[0]!.kind, "naming");
assert.deepEqual(s.runs.map((r) => r.kind), ["extraction", "extraction"]);
assert.equal(s.unpricedRuns, 0);
});
@@ -84,7 +74,6 @@ describe("graphCostSummary (the cost pill's fold)", () => {
const s: GraphCostSummary = graphCostSummary({
chats: [{ title: "partial", extractions: [extractionRun(100, PRICED, "unknown-model")] }],
sources: [{ filePath: "/vault/x.md", extractions: [extractionRun(200, "unknown-model", "unknown-model")] }],
naming: [],
});
assert.equal(s.stages.audit.unpricedRuns, 2);
assert.equal(s.stages.audit.dollars, 0); // never a silent zero: unpricedRuns says it
@@ -101,7 +90,6 @@ describe("graphCostSummary (the cost pill's fold)", () => {
const s = graphCostSummary({
chats: [{ title: "chat", extractions }],
sources: [],
naming: [],
recentCap: 2,
});
assert.equal(s.runs.length, 2);
@@ -114,13 +102,11 @@ describe("graphCostSummary (the cost pill's fold)", () => {
const s = graphCostSummary({
chats: [{ title: "failed", extractions: [extractionRun(100, PRICED, PRICED)] }],
sources: [],
naming: [],
});
assert.equal(s.runs[0]!.merged, undefined);
const empty = graphCostSummary({ chats: [], sources: [], naming: [] });
const empty = graphCostSummary({ chats: [], sources: [] });
assert.equal(empty.totalDollars, 0);
assert.equal(empty.runs.length, 0);
assert.equal(empty.stages.naming.runs, 0);
assert.equal(empty.stages.extraction.tokens.inputTokens, undefined);
});
});
-8
View File
@@ -32,7 +32,6 @@ import type {
GraphEdge,
GraphNode,
LedgerEvent,
NamingRunUsage,
NodeMapping,
NotesSource,
SessionCheckpoint,
@@ -68,7 +67,6 @@ function memoryLedgers() {
const checkpoints: SessionCheckpoint[] = [];
const coverage: CoverageEntry[] = [];
const sources = new Map<string, NotesSource>();
const namingRuns: NamingRunUsage[] = [];
const positions = new Map<string, { x: number; y: number }>();
return {
appendNode: (n: GraphNode) => void nodes.push(n),
@@ -99,11 +97,6 @@ function memoryLedgers() {
}
},
// Cluster labelings — mirrors the real store: append dedupes by id.
// Cluster-naming run usage — mirrors the real store: dedupe per startedAt.
appendNamingUsage: (entry: NamingRunUsage) => {
if (!namingRuns.some((r) => r.startedAt === entry.startedAt)) namingRuns.push(entry);
},
readNamingRuns: () => namingRuns.map((r) => ({ ...r, steps: [...r.steps], stats: { ...r.stats } })),
// The layout ledger — settleGraphLayout writes it after each merge.
readPositions: () => Object.fromEntries([...positions].map(([id, p]) => [id, { ...p }])),
writePositions: (next) => {
@@ -422,7 +415,6 @@ describe("the extraction pipeline (extractor → auditor → merger)", () => {
// Wave 7 (950ddfd): birth-session clusters carry session-name labels,
// so the post-merge naming garnish is gone — no model spend, no
// naming-run records, no label writes.
assert.equal(ledgers.readNamingRuns().length, 0, "no naming runs minted");
});
-1
View File
@@ -60,7 +60,6 @@ function fakeStores(
readClusterLabels: () => [],
appendClusterLabel: () => {},
appendNamingRun: () => {},
readNamingRuns: () => [],
} as unknown as GraphStore;
const chatStore: ChatStore = {
listChats: () =>
+1 -23
View File
@@ -18,7 +18,7 @@ import assert from "node:assert/strict";
import * as fs from "node:fs";
import { after, describe, it } from "node:test";
import type { UIMessage } from "ai";
import type { AuditResult, NamingRunUsage } from "../src/core/contracts.ts";
import type { AuditResult } from "../src/core/contracts.ts";
import type { QuestionAnswerData } from "../src/core/question-core.ts";
import { getGraph, graphSnapshot, mergeFindings, type GraphDeps } from "../src/core/graph.ts";
import { coverageSlots } from "../src/core/coverage.ts";
@@ -573,28 +573,6 @@ describe("graph ledger store", () => {
assert.deepEqual(nodes[0]!.provenance, [{ chatId: "chat_c", messageId: "m1" }]);
});
it("appendNamingUsage is idempotent per startedAt and strict-reads foreign shapes", () => {
const run: NamingRunUsage = {
startedAt: 1789800000000,
at: "2026-09-17T00:00:00.000Z",
durationMs: 1234,
model: "z-ai/glm-5.3-flash",
steps: [{ inputTokens: 10, outputTokens: 2, cacheReadTokens: 0, cacheWriteTokens: undefined, reasoningTokens: 0 }],
stats: { detected: 4, claimed: 3, named: 1, appended: 1 },
};
graphStore.appendNamingUsage(run);
graphStore.appendNamingUsage(run); // re-append: same startedAt — no-op
// A torn append + a foreign shape (missing stats) — skipped by the guard.
fs.appendFileSync(
LEDGER_FILES.namingRuns,
`{not json}\n${JSON.stringify({ startedAt: 1789800000001, at: "x", durationMs: 1, model: "m", steps: [] })}\n`,
"utf-8",
);
const runs = graphStore.readNamingRuns().filter((r) => r.startedAt >= 1789800000000);
assert.equal(runs.length, 1, "one record — idempotent append, corrupt/foreign lines skipped");
assert.deepEqual(runs[0]!.stats, { detected: 4, claimed: 3, named: 1, appended: 1 });
assert.equal(runs[0]!.steps.length, 1);
});
it("returns RAW node lines — repeated ids (link-appends) are each their own line; getGraph merges", () => {
const line = (msgId: string) =>
-1
View File
@@ -54,7 +54,6 @@ function fakeStores(
(over.sources ?? []).map((s) => ({ ...s, extractions: [] }) as unknown as NotesSource),
readPositions: () => ({}),
writePositions: () => {},
readNamingRuns: () => [],
} as unknown as GraphStore;
const chatStore: ChatStore = {
listChats: () =>