Install
$ agentstack add skill-deadlymind-nanolama-db-concurrency ✓ scanned · ✓ verified, works with Claude Code, Cursor, and more.
Security review
✓ PassedNo issues found. Passed automated security review. · v0.1.0 How review works →
- ✓ Prompt-injection patterns
- ✓ Secret / credential exfiltration
- ✓ Dangerous shell & filesystem operations
- ✓ Untrusted network calls
- ✓ Known-malicious package signatures
What it can access
- ✓ Network access No
- ✓ Filesystem access No
- ✓ Shell / process execution No
- ✓ Environment & secrets No
- ✓ Dynamic code execution No
From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.
Verified badge
Passed review? Show it. Paste this badge into your README, it links to the public security report.
Reliability & compatibility
Declared compatibility
Compatibility is declared by the source manifest. End-to-end runtime verification is coming, see below.
We're building live execution health for every listing: tool-call success rate, median latency, uptime, and last-checked timestamps, measured, not self-reported. It isn't live yet, so we don't show numbers we can't stand behind.
How agent discovery & health will work →About
DB concurrency (money & counters under concurrent writes)
When to use
Any write that reads a value, computes a new one, and writes it back — balances, stock, quotas, "used" counters — where two requests or workers can run at once. Without a lock the second write silently overwrites the first (lost update); with money, a float or an un-revalidated check turns that into a wrong ledger.
Pattern
Four rules, held together:
- Lock the row. Wrap the read-modify-write in
transaction.atomic()and select
the row with select_for_update() — Postgres holds a row lock until commit, so concurrent writers queue instead of racing.
- Validate inside the lock. Re-check the invariant (sufficient balance, stock >= 0)
after acquiring the lock, on the freshly-read value — a check before the lock is already stale.
- Decimal, never float, for money. Compute in
Decimalandquantize()to a fixed
scale; float rounding corrupts ledgers.
- Keep the transaction short. No network/AI/HTTP calls, no
time.sleep, no email
inside the lock — hold it only for the read, check, and write.
For a pure integer counter with no cross-value invariant, an F() expression does the increment atomically in the database without a lock at all.
Pattern — worked example
from decimal import Decimal
from django.db import transaction
from django.db.models import F
from rest_framework.exceptions import ValidationError
def debit_account(account_id, amount: Decimal, entreprise):
if not amount.is_finite() or amount 0, finite) before opening the transaction, and the
*state* invariant (sufficient balance) after locking — a negative amount turns a
debit into a credit, and no row lock will catch it. `balance < amount` is False for
a negative amount, so the guard passes and `balance -= amount` adds money.
- `select_for_update(skip_locked=True)` / `nowait=True` are for queue-style claiming,
not for balances — a skipped row means the update never happened.
- Long transactions block other writers and exhaust connections — never call an
external API or `Anthropic`/`Tavily` inside the lock; do that work, then open a short
transaction to persist (see `celery-tasks`).
- Float creeps in via `float(...)` or JSON parsing — coerce request input to `Decimal`
(or `str` first) before arithmetic.
## See also
- `migrations`
- `celery-tasks`
- `drf-api`
## Source & license
This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.
- **Author:** [Deadlymind](https://github.com/Deadlymind)
- **Source:** [Deadlymind/nanolama](https://github.com/Deadlymind/nanolama)
- **License:** MIT
Install and usage instructions live in the source repository linked above.
Reviews
No reviews yet, be the first.
Write a review
Versions
- v0.1.0 Imported from the upstream source.