spring-retry-conventions

spring-retry-conventions is a cursor rule for coding agents from e-gov/cursor-prompts. It costs 0 tokens per session (1,729 once invoked), scanned A, original, MIT.

A set of rules for retrying database operations in Spring Boot services. Spring Boot is a Java framework for building applications, while retries repeat an operation after temporary failures.

In plain words
What is it for?
Implementing jOOQ database operations with shared retry handling, transactions, and the application's database service base class.
Why use it?
It gives database code a consistent way to handle short-lived connection problems, deadlocks, and service unavailability.

Cursor rule

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/e-gov/cursor-prompts/spring-retry-conventions
Clone the repo
git clone --depth 1 https://github.com/e-gov/cursor-prompts

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for spring-retry-conventions

README.md
[![agentmods](https://agentmods.dev/badge/rules/e-gov/cursor-prompts/spring-retry-conventions.svg)](https://agentmods.dev/rules/e-gov/cursor-prompts/spring-retry-conventions)
Your own site
<a href="https://agentmods.dev/rules/e-gov/cursor-prompts/spring-retry-conventions"><img src="https://agentmods.dev/badge/rules/e-gov/cursor-prompts/spring-retry-conventions.svg" alt="Measured on agentmods" height="20"></a>
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 1,729 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.01729
Opus 5 $0.00000 $0.00864
Sonnet 5 $0.00000 $0.00346
Haiku 4.5 $0.00000 $0.00173

Measured 5d ago against content hash a03cab446935, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

spring-retry-conventions scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 5d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

rules/java-spring-boot/spring-retry-conventions.mdc · 129 lines

How it starts

The opening of the file, as written. The whole thing — 129 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Database Retry Conventions

Context

  • Apply when implementing database operations in service classes (src/main/java/**/service/**/*.java) that need resilience against transient database failures (e.g., connection issues, temporary unavailability, deadlocks).
  • Applies specifically to services interacting with the database via jOOQ within this application.
  • This pattern relies on the RetryConfig, AbstractDatabaseService, and DatabaseRetryProperties components configured in the project.
  • Note: {base.package} represents your project's base package (e.g., com.example.myapp). Projects must implement the referenced classes (AbstractDatabaseService, DatabaseRetryException, etc.).

Requirements

  1. Extend Base Class: Service classes performing database operations that should be retried MUST extend {base.package}.service.common.AbstractDatabaseService.
  2. Constructor Injection: Services extending AbstractDatabaseService MUST receive DSLContext, RetryTemplate, and PlatformTransactionManager via constructor injection and pass them to the super(dsl, retryTemplate, txManager) constructor.
  3. Use Retry Methods: ALL individual database operations within these services MUST be wrapped in one of the retry methods provided by the base class:
    • executeWithRetry(String operationName, DatabaseOperation<T> operation) — for write operations
    • executeReadOnlyWithRetry(String operationName, DatabaseOperation<T> operation) — for read-only operations (uses a read-only TransactionTemplate)
  4. No @Transactional on Methods: Do NOT annotate service methods with @Transactional. Transactions are managed programmatically inside each retry attempt using TransactionTemplate with PROPAGATION_REQUIRES_NEW. Each attempt gets a fresh transaction and connection, preventing poisoned-connection reuse after failures.
  5. Provide Operation Name: A meaningful, unique operationName string (typically matching the service method name or the specific action) MUST be provided as the first argument for clear logging and error reporting.
  6. Use Logging Helpers (Optional): The base class provides logOperationStart(String operation, String details) and logOperationSuccess(String operation, String details) helpers. These can be used for additional debug-level logging outside the retry lambda if needed, but executeWithRetry/executeReadOnlyWithRetry already handles INFO-level start/success logging and ERROR-level failure logging.
  7. Exception Handling:
    • Only transient database errors are retried. The recoverable SQLState classification is centralised in PostgreSQLExceptionOverride.isRecoverableState(String):
      • 08xxx — Connection exceptions (connection lost, timeout)
      • 57Pxx — Operator intervention (admin shutdown, failover)
      • 40xxx — Transaction rollback (serialization failure, deadlock)
      • 53xxx — Insufficient resources (out of memory, too many connections)
      • 25006 — Read-only transaction (PostgreSQL failover)
    • Non-recoverable errors (constraint violations 23xxx, syntax errors 42xxx, data errors 22xxx) are not retried.
    • If all retries are exhausted, the retry method wraps the last thrown exception in a {base.package}.exception.DatabaseRetryException.
    • Service methods should generally allow DatabaseRetryException to propagate upwards to be handled by the GlobalExceptionHandler.
  8. HikariCP Connection Eviction: PostgreSQLExceptionOverride implements SQLExceptionOverride and returns MUST_EVICT for recoverable SQLStates, ensuring stale connections are removed from the pool before the next retry acquires a fresh one. When adding new recoverable SQLStates, update only isRecoverableState().
  9. Configuration: Do not hardcode retry attempts or backoff periods. Rely on the centrally configured RetryTemplate which uses settings from DatabaseRetryProperties (defined in application.yml):
    database:
      retry:
        max-attempts: ${DB_RETRY_MAX_ATTEMPTS:3}
        initial-interval: ${DB_RETRY_INITIAL_INTERVAL:500}
        multiplier: ${DB_RETRY_MULTIPLIER:2.0}
        max-interval: ${DB_RETRY_MAX_INTERVAL:10000}
        timeout: ${DB_RETRY_TIMEOUT:30000}
    

Read the full file on GitHub · 129 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 5d ago First seen · 129 lines · 1,729 tokens per session scan A a03cab446935

Subscribe to this mod's changes

spring-retry-conventions is a cursor rule published in the GitHub repository e-gov/cursor-prompts (34 stars, last pushed 4mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 1,729 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.