fix(cost): snapshot estimatedCostUsd instead of accumulating (#69347)#69403
Conversation
cd7c183 to
11b7487
Compare
Greptile SummaryThis PR correctly fixes a cost-inflation bug where
Confidence Score: 4/5Core fix is correct and well-tested, but the test file has a syntax error that will prevent it from compiling. The production fix is solid. However, the malformed comment on line 2417 of session.test.ts (/ Before fix:) is a division expression, not a comment, and will cause a parse/compile error in the test suite. src/auto-reply/reply/session.test.ts (line 2417 — malformed comment will break compilation)
|
| expect(stored1[sessionKey].estimatedCostUsd).toBeCloseTo(0.007725, 8); | ||
|
|
||
| // Second persist with SAME cumulative usage (e.g., heartbeat or redundant persist) | ||
| // Before fix: cost would accumulate to $0.0155 (2x) |
There was a problem hiding this comment.
Malformed comment (missing leading slash)
The line starts with / Before fix: instead of // Before fix:, making it a division expression rather than a comment. This will cause a syntax/parse error.
| // Before fix: cost would accumulate to $0.0155 (2x) | |
| // Before fix: cost would accumulate to $0.0155 (2x) |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/auto-reply/reply/session.test.ts
Line: 2417
Comment:
**Malformed comment (missing leading slash)**
The line starts with `/ Before fix:` instead of `// Before fix:`, making it a division expression rather than a comment. This will cause a syntax/parse error.
```suggestion
// Before fix: cost would accumulate to $0.0155 (2x)
```
How can I resolve this? If you propose a fix, please make it concise.d32b6a4 to
199c16c
Compare
|
Maintainer pass: root cause and production fix look right. I pushed
Local verification on the PR branch: pnpm check:changed
pnpm test src/agents/command/session-store.test.ts src/auto-reply/reply/session.test.tsBoth pass locally. Waiting on GitHub CI for the updated branch. |
8df7230 to
f518100
Compare
The bug: three persist sites accumulated cost instead of snapshotting it like tokens. This caused cost to be inflated 1x-72x on multi-persist sessions because the same cumulative usage was added repeatedly. Root cause: persistSessionUsageUpdate, updateSessionStoreAfterAgentRun, and the cron isolated-agent run path all used: estimatedCostUsd = existingCost + runCost But runCost was already computed from cumulative run usage, so this added the same cost repeatedly on redundant persists. Fix: snapshot cost directly like tokens already do: estimatedCostUsd = runCost Files affected: - src/auto-reply/reply/session-usage.ts - src/agents/command/session-store.ts - src/cron/isolated-agent/run.ts Tests added: - session-store.test.ts: verify cost is snapshotted, not accumulated - session.test.ts: updated existing test to verify snapshot behavior Fixes #69347
f518100 to
c2ddf75
Compare
The bug: three persist sites accumulated cost instead of snapshotting it like tokens. This caused cost to be inflated 1x-72x on multi-persist sessions because the same cumulative usage was added repeatedly.
Root cause: persistSessionUsageUpdate, updateSessionStoreAfterAgentRun, and the cron isolated-agent run path all used:
estimatedCostUsd = existingCost + runCost
But runCost was already computed from cumulative run usage, so this added the same cost repeatedly on redundant persists.
Fix: snapshot cost directly like tokens already do:
estimatedCostUsd = runCost
Files affected:
Tests added:
Fixes #69347