Skip to content

Commit 2fd0c2b

Browse files
saphidclaude
andcommitted
refactor(usage): stop sending unused project session counts
Each project row carried a session count that the server tracked per record and no client read. Drop it from the contract and aggregation. Co-Authored-By: Claude Fable 5.2 <[email protected]>
1 parent a571a8c commit 2fd0c2b

5 files changed

Lines changed: 7 additions & 19 deletions

File tree

‎apps/server/src/usage/UsageService.test.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2442,7 +2442,7 @@ describe("UsageService", () => {
24422442
const projectRows = (summary: UsageSummary) =>
24432443
(summary.projectTotals ?? [])
24442444
.filter((row) => row.provider !== "pi")
2445-
.map((row) => [String(row.projectId ?? null), row.totals.outputTokens, row.sessions])
2445+
.map((row) => [String(row.projectId ?? null), row.totals.outputTokens])
24462446
.toSorted(([a], [b]) => String(a).localeCompare(String(b)));
24472447

24482448
yield* Effect.gen(function* () {
@@ -2478,15 +2478,15 @@ describe("UsageService", () => {
24782478
const service = yield* UsageService.make;
24792479
const summary = yield* service.readSummary(WINDOW);
24802480
assert.deepStrictEqual(projectRows(summary), [
2481-
["null", 18, 2],
2482-
["p-app", 8, 2],
2483-
["p-gone", 13, 1],
2481+
["null", 18],
2482+
["p-app", 8],
2483+
["p-gone", 13],
24842484
]);
24852485
assert.deepStrictEqual(
24862486
summary.projectTotals
24872487
?.filter((row) => row.provider === "pi")
2488-
.map((row) => [row.projectId, row.totals.outputTokens, row.sessions]),
2489-
[[ProjectId.make("p-app"), 17, 1]],
2488+
.map((row) => [row.projectId, row.totals.outputTokens]),
2489+
[[ProjectId.make("p-app"), 17]],
24902490
);
24912491
assert.deepStrictEqual(
24922492
summary.projects?.toSorted((a, b) => a.projectId.localeCompare(b.projectId)),

‎apps/server/src/usage/usageAggregation.test.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,6 @@ describe("UsageAggregator", () => {
317317
costUsd: expect.closeTo(projectCost, 9),
318318
records: 2,
319319
unpricedRecords: 0,
320-
sessions: 1,
321320
},
322321
{
323322
provider: "claude",
@@ -326,7 +325,6 @@ describe("UsageAggregator", () => {
326325
costUsd: 0,
327326
records: 1,
328327
unpricedRecords: 1,
329-
sessions: 1,
330328
},
331329
]);
332330
const bucketCost = result.buckets.reduce((sum, bucket) => sum + bucket.costUsd, 0);

‎apps/server/src/usage/usageAggregation.ts‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ interface MutableProjectTotals {
6969
costUsd: number;
7070
records: number;
7171
unpricedRecords: number;
72-
sessions: Set<string>;
7372
}
7473

7574
export interface AggregateOptions {
@@ -240,10 +239,7 @@ export class UsageAggregator {
240239
}
241240
// Keyed usage is counted in finish(), once all its copies are merged.
242241
if (record.dedupeKey === null) this.#accumulate(bucket, project, record);
243-
if (record.sessionId.length > 0) {
244-
bucket.sessions.add(record.sessionId);
245-
project?.sessions.add(record.sessionId);
246-
}
242+
if (record.sessionId.length > 0) bucket.sessions.add(record.sessionId);
247243
return true;
248244
}
249245

@@ -287,7 +283,6 @@ export class UsageAggregator {
287283
costUsd: 0,
288284
records: 0,
289285
unpricedRecords: 0,
290-
sessions: new Set(),
291286
};
292287
this.#projects.set(key, project);
293288
}
@@ -458,7 +453,6 @@ export class UsageAggregator {
458453
costUsd: project.costUsd,
459454
records: project.records,
460455
unpricedRecords: project.unpricedRecords,
461-
sessions: project.sessions.size,
462456
};
463457
});
464458

‎packages/contracts/src/usage.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ export const UsageProjectTotals = Schema.Struct({
8585
costUsd: Schema.Number,
8686
records: NonNegativeInt,
8787
unpricedRecords: NonNegativeInt,
88-
sessions: NonNegativeInt,
8988
});
9089
export type UsageProjectTotals = typeof UsageProjectTotals.Type;
9190

‎packages/shared/src/usageMerge.test.ts‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ describe("mergeUsage", () => {
147147
costUsd,
148148
records: 1,
149149
unpricedRecords: 0,
150-
sessions: 1,
151150
});
152151
const withProjects = (
153152
usageSummary: UsageSummary,
@@ -217,7 +216,6 @@ describe("mergeUsage", () => {
217216
costUsd,
218217
records: 1,
219218
unpricedRecords: 0,
220-
sessions: 1,
221219
});
222220
const merged = mergeUsage(
223221
[
@@ -376,7 +374,6 @@ describe("mergeUsage", () => {
376374
costUsd: 7,
377375
records: 3,
378376
unpricedRecords: 0,
379-
sessions: 2,
380377
},
381378
],
382379
projects: [{ projectId: "p1" as ProjectId, title: "App" }],

0 commit comments

Comments
 (0)