r/SpringBoot • u/LostEconomics144 • Aug 03 '26
Discussion I built a SAGA compensation library for Spring AI tool calls — looking for design feedback
I've been working with Spring AI agents that perform multi-step tasks with real side effects (API calls, database writes, payments). The problem I kept hitting: when step 3 of 5 fails, steps 1-2 have already executed and nothing undoes them.
Temporal/Restate solve durability (resume after crash), but not compensation (undo what you already did). So I built Sagacity.
What it does:

When a saga fails, it walks the journal backward and runs compensations in reverse. Every tool call is journaled to an append-only Postgres table with SHA-256 hash chaining (for audit/compliance — EU AI Act Article 12 is coming in August).
What's working (38 tests):
- u/Compensable/u/Compensation annotations
- Postgres journal with hash chain
- Approval gates (IRREVERSIBLE tools need human sign-off before executing)
- Spring Boot Starter with REST endpoints for approve/reject/audit
- JSON Lines audit export with chain verification
What's NOT done:
- Not on Maven Central (build from source)
- No streaming support
- No LangChain4j adapter
- No UI dashboard
- Probably needs more battle-testing
GitHub: https://github.com/sumitvairagar/sagacity
Genuinely looking for feedback on:
- Is the annotation API natural? Or would you prefer a different approach?
- The hash chain — is SHA-256(prev_hash || payload) sufficient, or would you want something stronger?
- Should the approval gate be an Advisor instead of a ToolCallback decorator?
Anyone else dealing with the "agent did half the work then died" problem?
2
u/schemalith Aug 03 '26
for money-moving tool calls, i'd put the approval gate as close to execution as possible, not only in planning. the scary case is stale approval: the model asks for one action, context changes, then a slightly different payload runs. i'd want the journal row to include the exact approved payload, approver id, policy version, idempotency key, and the compensation that would run. the hash chain seems fine as tamper evidence if serialization is strict and boring.
1
u/tzolov Aug 07 '26
Interesting idea. Could be a candidate for https://github.com/spring-ai-community