Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

address review (codex): preserve unknown usage and breakdown date

[._.]/ Adam Eivy28511853f443
diff --git a/server/services/bootstrap.js b/server/services/bootstrap.js
index f275623d8b..b7ed4615af 100644
--- a/server/services/bootstrap.js
+++ b/server/services/bootstrap.js
@@ -157,7 +157,6 @@ export const bootstrapServices = async ({ io, dataDir, dataReferenceDir, serverD
});
},
onRunCompleted: (metadata, output) => {
- if (!metadata.providerId) return;
const estimatedTokens = estimateTokens(output);
const inputTokens = estimateTokensFromChars(metadata.promptLength);
recordMessages(metadata.providerId, metadata.model, 1, estimatedTokens, inputTokens).catch(err => {
diff --git a/server/services/usage.js b/server/services/usage.js
index 6de640b624..e3c28884f5 100644
--- a/server/services/usage.js
+++ b/server/services/usage.js
@@ -428,11 +428,13 @@ export function buildUsageReport(dailyActivity, { from = null, to = null, provid
const fromMonth = from ? from.slice(0, 7) : null;
const toMonth = to ? to.slice(0, 7) : null;
for (const [month, bucket] of Object.entries(monthlyActivity || {})) {
- if (fromMonth && month < fromMonth) continue;
- if (toMonth && month > toMonth) continue;
if (bucket?.byProvider) {
const monthStart = `${month}-01`;
if (!breakdownSince || monthStart < breakdownSince) breakdownSince = monthStart;
+ }
+ if (fromMonth && month < fromMonth) continue;
+ if (toMonth && month > toMonth) continue;
+ if (bucket?.byProvider) {
foldBucket(bucket);
} else if (bucket) {
foldLegacyBucket(bucket);
@@ -440,10 +442,10 @@ export function buildUsageReport(dailyActivity, { from = null, to = null, provid
}
for (const [date, day] of Object.entries(dailyActivity || {})) {
+ if (day?.byProvider && (!breakdownSince || date < breakdownSince)) breakdownSince = date;
if (from && date < from) continue;
if (to && date > to) continue;
if (day?.byProvider) {
- if (!breakdownSince || date < breakdownSince) breakdownSince = date;
foldBucket(day);
} else if (day) {
foldLegacyBucket(day);
diff --git a/server/services/usage.test.js b/server/services/usage.test.js
index fa7bb94e4e..93902797fa 100644
--- a/server/services/usage.test.js
+++ b/server/services/usage.test.js
@@ -236,13 +236,34 @@ describe('usage.js — streak calculations', () => {
it('keeps estimatedCost all-time when the visible report is range-filtered', async () => {
readJSONFile.mockResolvedValueOnce(makeUsage({
'2025-05-01': { sessions: 1, messages: 1, tokens: 1_000_000 },
- '2025-06-01': { sessions: 1, messages: 1, tokens: 500_000 }
+ '2025-06-01': {
+ sessions: 1,
+ messages: 1,
+ tokens: 500_000,
+ byProvider: {
+ codex: {
+ name: 'Codex',
+ sessions: 1,
+ messages: 1,
+ tokensIn: 0,
+ tokensOut: 500_000,
+ byModel: {
+ 'gpt-5.3-codex': {
+ sessions: 1,
+ messages: 1,
+ tokensIn: 0,
+ tokensOut: 500_000
+ }
+ }
+ }
+ }
+ }
}));
await loadUsage();
const summary = getUsageSummary({ from: '2025-06-01', to: '2025-06-01' });
- expect(summary.report.totals.estimatedCost).toBe(7.5);
- expect(summary.estimatedCost).toBe(22.5);
+ expect(summary.report.totals.estimatedCost).toBe(7);
+ expect(summary.estimatedCost).toBe(22);
});
});
@@ -428,6 +449,19 @@ describe('usage.js — streak calculations', () => {
});
});
+ it('reports the actual breakdown start even when the visible range begins later', () => {
+ const report = buildUsageReport({
+ '2025-06-01': nestedDay('codex', 'Codex', 'gpt-5.3-codex'),
+ '2025-07-01': nestedDay('codex', 'Codex', 'gpt-5.3-codex')
+ }, {
+ from: '2025-07-01',
+ to: '2025-07-31'
+ });
+
+ expect(report.breakdownSince).toBe('2025-06-01');
+ expect(report.totals.sessions).toBe(1);
+ });
+
it('folds legacy monthly buckets into the requested range', () => {
const report = buildUsageReport({}, {
from: '2024-05-01',