Skip to content

an open-source alternative to the dots, bots and muses of the world, run an office of claude code/codex like agents on your laptop, sandboxes or anywhere, uses your existing subscriptions

fix(cost-ledger): only write a row for a live session sample (#56)

Chaitanya Giri650c568437e8
diff --git a/src/main/index.ts b/src/main/index.ts
index 0e3deb0e..c0a4914d 100644
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@ -428,7 +428,14 @@ function runBreakerBeat(progressWindowMs: number): void {
for (const [id, a] of Object.entries(reg.agents)) {
if (a.archived) continue;
const sample = usageProvider.getAgentUsage(id);
- if (sample) hive.appendCostLedger(sample); // ledger covers everyone incl. god
+ // #56: only append a ledger row for a LIVE session sample. A dead/orphaned
+ // agent with a frozen transcript still yields a sample via the transcript
+ // fallback, but with an EMPTY sessionId (aggregateLive returns null → no live
+ // OTel session). Appending it every ~30s rewrote the identical row forever
+ // (2,417 dupes observed). A truthy sessionId is set only by a live session
+ // (aggregateLive picks the most-recent live session id), so this gates on
+ // "is there a live session" without changing any live-agent behavior.
+ if (sample?.sessionId) hive.appendCostLedger(sample); // ledger covers everyone incl. god
if (id === reg.godId) continue; // breaker skips god
inputs.push({ agentId: id, sample, progressing: now - lastCoordinationAt(id) < progressWindowMs });
}