docs backend evidence community safety SEC01C_ATOMIC_ADMISSION - AlexandreZanata/Abastevo GitHub Wiki
SEC01-C — Atomic admission + budgets
Date: 2026-10-11. Status: LOCAL_DONE. Scope: per-address + aggregate
mail, aggregate key-usernames, per-account sessions, per-account
comments, invalid-first validation, retention purges — no SMTP,
no SEC01-D matrix.
Head: maintained dev + this task.
Plan: remediation plan
(SEC01, AUD-01). Contract: B-BR-A01/A02/A04/A05 (free registration,
code policy, sessions, free social) + B-BR-F03/F04 (280-scalar
comments/replies); BUC-A01/A04 + BUC-F social writes. Constraint:
free registration/social stay free inside ceilings; no oracle leaks
status; hashed accounting only.
Validation: PASS
Changes
account/domain/policy.go: frozenMaxAggregateCodesPerHour=20,MaxKeyAccountsPerHour=100,MaxLiveSessionsPerAccount=10,CodePurgeGraceSeconds=24h,SessionPurgeGraceSeconds=7d.account/domain/account.go:ValidEmail(cheap shape: <=254, one @, no spaces);account/domain/ports.go:ErrAggregateExhausted,ErrSessionBudgetExhausted+ verdict codes (admission-exhausted,session-budget-exhausted).account/application:StoregainsCountAllCodesSince,CountKeyAccountsSince,CountLiveFamiliesByAccount,PurgeExpiredCodes/Families,TryIssueCode,TryCreateKeyAccount,TryCreateFamily(single lock/tx).RequestCodevalidates email before any IO then admits viaTryIssueCode(suspended/per-addr/aggregate/cooldown atomically, refusals nil with no rows/mail);CreateKeyAccountadmits viaTryCreateKeyAccount(aggregate → ErrAggregateExhausted); sessions admit viaTryCreateFamily(live cap → ErrSessionBudgetExhausted).account/adapters/pgstore.go+db/queries/account/accounts.sql(sqlc regenerated, vet clean): counts, purges,Try*withpg_advisory_xact_lock(global 810001/810002, per-accountfamilies:hash) + single-tx check+insert.account/adapters/http/http.go:validEmaildelegates to domain (single predicate); new 429 mappings for both budget errors.feedback/domain/feedback.go: frozenMaxLiveCommentsPerAccount=100(edits converge, deletes free).feedback/application:CommentStoregainsCountLiveCommentsByAccount+TryInsertComment(single lock/tx, over-budget → ErrQuotaExceeded);submitvalidates target/text before authorize/station/parent IO.feedback/adapters/pgstore.go+db/queries/feedback/comments.sql(sqlc regenerated): live count +TryInsertCommentunder per-account advisory lock;feedback/adapters/http/http.gomaps plainquota-exceededto 429.- Tests: 6 SEC01-A skips inverted to enforced GREEN (session test
rewritten to cap+second-account); new unit accounting/purge +
parallel-ceiling tests (account + feedback); new real-PostGIS
TestSEC01C*(aggregate parallel exact, session cap + second-account, comment budget + parallel exact, purge exact).
Validation (actual)
go test ./internal/modules/account/... ./internal/modules/feedback/...green (incl. 6/6 regressions + 5 new unit).-race -tags=integrationgreen:account/adapters(incl. 2 new SEC01-C),feedback/adapters(incl. 2 new SEC01-C) on disposable local PostGIS (shared dev DB host, per-test DBs).go build ./...,go vet(account/feedback),gofmt -lclean,sqlc vetclean,git diff --checkclean,scan-secrets.shpassed (synthetic addresses only).- RED pre-GREEN: SEC01-A evidence proved all 6 FAIL unskipped; session placeholder could never pass as written (always Fatal); this task rewrote it to cap+legit-second and turned all 6 GREEN with parallel/purge proofs.
Limits / owed
- Full SEC01-D matrix still owed: quota rollback, duplicate intent/retry, exhausted-global retry metadata, rotating subjects, multi-window expiry, HTTP 429 Retry-After wiring for account budgets (feedback 429 mapped; account 429 coded, header owed), real-SQL concurrency beyond the bounded parallel proofs here.
- Multi-replica strict serializability beyond advisory xact locks (e.g. partitioned PG, failover) not proven here.
- SMTP needs explicit need/license/security record — not added.
- No VPS/phone/shared-edge change; no production readiness claim.
Next microtask: SEC01-D real-SQL flood/rollback/retry proofs.