fix(blogs): enforce atomic optimistic update concurrency
Deploy Canina / deploy (push) Successful in 52s

This commit is contained in:
Canina Automation committed 2026-10-27 08:20:33 +00:00
1 parent 0e952ef701
commit 0ad39bb92c
6 files changed
+202 -35

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
# Plan and clarified contract
Base develop 0e952ef70184040a27a6b53d7b59073502d25743 fetched via verified nested SSH proxy (origin is local bundle).
Graphify query before editing identified BlogsController -> BlogsService -> PrismaService and RevalidationService; graph source locations service update L144 and controller L29 are old, so inspect current source. Actual source has PUT admin/blogs/:id @Body any, not public UpdateBlogDto. Global whitelist is skipped for Object/any metatype, so service explicit scalar allowlist is authoritative; expectedUpdatedAt is consumed separately, never persisted. UI omission remains accepted.
Blog.updatedAt is @db.Timestamptz() (PostgreSQL default precision 6), @updatedAt. JS/JSON tokens have millisecond precision. CAS predicate uses [token,token+1ms), not exact equality to truncated DB value. Atomic claim via blog.updateMany inside interactive transaction, advancing updatedAt strictly beyond token millisecond; if count !=1 throw 409. Then nested blog.update (author/category/tags) in same transaction, retaining claimed timestamp. Relation failures roll back claim. No relation writes outside transaction. Revalidation occurs after transaction resolves only. Invalid tokens restricted to timezone-qualified ISO string with <=3 fractional digits and valid calendar round-trip; no coercive Date/null/number acceptance.
Deployed runtime version/column precision still need read-only release evidence; source evidence is not deployed proof. No writes to shared services during validation.
+3
View File
@@ -0,0 +1,3 @@
# Atomic blog update prerequisite
Guarded publishers submit the updatedAt string returned by GET to PUT /admin/blogs/:id as expectedUpdatedAt. A stale or invalid supplied token must return 409 before any scalar, relation, tag creation, or cache side effect. Exactly one competing guarded writer sharing a token can commit. Missing records retain 404. Existing UI callers omitting the token retain legacy last-write-wins behavior deliberately; they are not concurrency-protected. No production content writes or migrations are permitted.
Acceptance: current token succeeds; stale/invalid/null/number/object/array tokens fail; offset-equivalent timestamps work; microsecond DB timestamps round-trip through millisecond JSON; same-millisecond successors invalidate old tokens; relation failure rolls back scalar claim; postcommit revalidation remains fail-safe.
+11
View File
@@ -0,0 +1,11 @@
# Verified release tasks
- [x] Specify guarded update/legacy omission and timestamp precision.
- [x] RED then GREEN atomic predicate, race, rollback and token tests.
- [x] Backend: 92 suites/798 tests; targeted 5 suites/105 tests. Existing 2 suites/3 tests remain skipped. All three builds passed.
- [x] Repair obsolete removed-ApprovalsPage admin test after RED, no runtime edits: 51 files/310 tests.
- [x] Storefront candidate and identical base full runs: 98 files/501 tests each; 180s external deadline was insufficient, 420s bounded runs passed without test-timeout/config changes.
- [x] Disposable actual PostgreSQL16.14, Prisma5.22: two distinct backend PIDs, one commit/one409, precision6, four microsecond boundaries, loser tags absent, full nested rollback with existing nonnull author and attempted supported author connect. Additional evidence-only disconnect adapter separately disclosed.
- [ ] Independent exact source/diff review.
- [ ] Commit/push develop, CI and Stage acceptance. No main/production authorization here.
Local evidence is preserved under evidence/concurrency and evidence/concurrency/release-prep, excluded from staging with dependency trees, baseline archive and graph stamp. Prior atomic patch SHA256 5cfce33a47d5c00ed179029dd2314d93423e73ad1162511908a8f000472d0ced exactly reconstructed from current service plus new unit spec. Remote gitea/develop fetched and equals base0e952ef70184040a27a6b53d7b59073502d25743.