fix: make agent cost accounting updates transactional#405
Open
sahu-virendra-1908 wants to merge 2 commits into
Open
Conversation
Author
|
@Ronit-Raj9 @Parvm1102 @vibhor-5 If any improvements, corrections, or additional changes are needed, please let me know and I will update the PR accordingly. |
Signed-off-by: sahu-virendra-1908 <virendrashivsahu@gmail.com>
Signed-off-by: sahu-virendra-1908 <virendrashivsahu@gmail.com>
sahu-virendra-1908
force-pushed
the
fix/agent-cost-accounting-race-condition
branch
from
May 28, 2026 09:52
d64b81f to
e2398a7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes a race condition in agent cost accounting caused by non-atomic multi-table database updates in
server/src/core/heartbeat.ts.Previously, updates to:
agentRuntimeStatecostEventsagents.spentMonthlyCentswere executed as separate database operations outside a transaction. Under concurrent agent execution or process crashes, this could produce inconsistent financial state and allow budget enforcement to read stale spend values.
This change wraps all related accounting operations inside a single database transaction to ensure atomicity and consistency.
Related Issue
Fixes #404
Type of Change
How Was This Tested?
Notes:
CE & Security Check
Screenshots / Demos (if UI or UX)
N/A — backend concurrency and transactional consistency fix.
Checklist