Imported from jpaljasma/ecoflow-pulse (
internal/AGENTS.md). Install upstream withnpx skills add jpaljasma/ecoflow-pulse --skill internal. Copyright stays with the author.
AGENTS
Scope
This file adds backend/runtime guidance for internal/ work on top of the repository root AGENTS.md.
Backend Design
- Optimize for long-lived service correctness first:
- clean startup,
- bounded retries,
- graceful shutdown,
- no leaked transactions, goroutines, or connections.
- Default non-cryptographic internal hashing to
XXH3_128:- use it for internal cache keys, internal dedup/checksum tags, and other high-volume pipeline hashing where collision resistance only needs to be pragmatic,
- keep SHA-2/HMAC style hashing for security boundaries, auth/signing, or places where an external protocol/storage contract explicitly requires it.
- Shared behavior belongs in shared packages:
- connection-pool tuning,
- compatibility shims,
- metrics-server helpers,
- retry helpers.
- Prefer fixes that keep worker behavior safe under multi-replica rolling updates, not just single-process local runs.
Cache Substrate Work
- Backend caches that cross process boundaries should use the shared cache substrate from ADR-0028.
- Keep domain-owned key hooks limited to canonical inputs:
- final key shape, hash-tag partitioning, digesting, envelope handling, compression, encryption, and metrics belong in shared cache code.
- Use versioned tag invalidation for cache fanout invalidations:
- do not add wildcard deletes,
KEYS/SCANinvalidation, or reverse-index cleanup loops.
- do not add wildcard deletes,
- Read-through loaders that may receive concurrent identical misses must use
singleflight. - Sensitive provider-session cache paths must bypass storage when encryption is not configured.
- When adding goroutines to cache miss paths, keep concurrency bounded and avoid holding mutexes around I/O or loaders.
Valkey Client Work
- Use shared Valkey client setup for Sentinel, auth, retry, backoff, jitter, reconnect, and client-side-cache options.
- Keep Valkey clients process-persistent and close them during service shutdown, not per request.
- Lease/script clients must keep client-side caching disabled; only shared cache read paths may opt in with explicit local TTLs.
- Retry only safe transient operations:
- writes require idempotency or explicit side-effect handling before adding automatic retries.
- Tests for Valkey client changes should cover retry/backoff behavior, disconnect/reconnect behavior, and client-side-cache opt-in/opt-out defaults.
Database and Messaging
- Idle connections and idle transactions must be bounded and cleaned up on normal shutdown.
- Retry only safe transient operations, with short backoff and jitter.
- Preserve write safety: do not add automatic retries to writes unless idempotency and side effects are explicitly handled.
- Background workers must release leases, subscriptions, and DB resources cleanly during drain.
- Transient dependency drops such as EOF, connection reset/refused, broken pipe, or timeout should be retried for safe request paths and reported as temporary unavailability after retries are exhausted.
Go Quality Gates
- Keep
golangci-lint run ./...clean. - Run targeted
go testfor touched packages andmake test-racefor concurrency-sensitive shutdown/lease/worker changes. - When touching a hot path, add or update regression tests for:
- cancellation,
- drain/shutdown,
- retries/backoff,
- resource cleanup.
Observability
- Hot-path logs should stay structured and sampled appropriately.
- Rollout and shutdown behavior should be diagnosable from logs and metrics:
- startup dependency retries,
- readiness/drain transitions,
- dropped work / queue depth,
- lease and connection pressure symptoms.