Skip to content

Hotfix: CC balance stale JPA L1 cache in AgentAndCcApplicationController (#19752)#19786

Open
buddhika75 wants to merge 1 commit intoruhunu-prodfrom
19752-cc-balance-stale-l1-cache-hotfix
Open

Hotfix: CC balance stale JPA L1 cache in AgentAndCcApplicationController (#19752)#19786
buddhika75 wants to merge 1 commit intoruhunu-prodfrom
19752-cc-balance-stale-l1-cache-hotfix

Conversation

@buddhika75
Copy link
Copy Markdown
Member

Summary

Changes

  • AgentAndCcApplicationController.java: Refresh JPA entity before reading CC balance to bust L1 cache

Test plan

  • Verify CC balance reflects real-time data after transactions
  • No regression in agent/CC application workflows

Closes #19752

🤖 Generated with Claude Code

Replace collectingCentre.getBallance() with a JPQL scalar query in all
13 handlers of AgentAndCcApplicationController.

Root cause: institutionFacade.findWithoutCache() uses em.find() with
CacheRetrieveMode.BYPASS, which only bypasses the EclipseLink L2
(shared) cache. When an outer JTA transaction is active (from the
calling EJB chain), InstitutionFacade joins that transaction and shares
its persistence context. If the Institution entity is already in that
L1 cache with a stale balance, em.find() returns the stale object
without hitting the database — causing AgentHistory records to store an
incorrect balanceBeforeTransaction.

Fix: added fetchCurrentBalance(Long ccId) which uses JPQL
("SELECT i.ballance FROM Institution i WHERE i.id = :ccId"). JPQL
always bypasses both L1 and L2 caches and reads directly from the DB.
Applied to all 13 handlers. The entity is still loaded via
findWithoutCache for the editAndCommit merge.

Confirmed incident: RCC367 (Monaragala) on 22 Mar 2026 — bills 020009
and 020012 both stored balanceBefore=-8660.75 (stale pre-020006 value)
instead of the correct post-020007 value of +1306.75.

Closes #19752

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant