Repository navigation
feat(concurrency): row versions on the bucket forms (REQ-RUNTIME-003 rule 4) - #43
Merged
Merged
Conversation
…rule 4) The Storage page and the Move page new-bucket form were last-write-wins. storage_kit_profile gets an additive row_version column (never written by the ORM). Each form carries the version read from the database in a hidden rowVersion field; the save advances it with one atomic compare-and-set inside its existing write unit. A stale page writes nothing and answers a domain 409 (X-Error-Code: STORAGE_KIT_STALE_EDIT) with a translated message in the 7 locales. StorageMove::saveTarget() takes an optional expected version and advances it unchecked without one. Tests: two-connection races and a real MySQL/MariaDB deadlock inside the flush (audit ZH-M1: 409 CONFLICT_001, nesting level 0, next save works).
|
@coderabbitai review |
… ZK-M1) The hidden rowVersion field now carries <row id>:<row version>, and submittedRowVersion($form, $profile) returns MISSING when the token names another row, so a page opened before its bucket was replaced (target discarded and saved again, or a Move switch) can never overwrite the new row at an equal version. The version comes from the same load as the values (ZK-L1). Docs say host ORM writes do not advance it (ZK-I3).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes the REQ-RUNTIME-003 rule-4 gap (lost update) of the sweep-2026-11-22 audit: the bucket edit forms (Storage page and the Move page's new-bucket form) were last-write-wins. Owner decision 2026-11-22: fix it, one minor PR.
Design
storage_kit_profile.row_version INT NOT NULL DEFAULT 1, mappedinsertable: false, updatable: falseonStorageProfile, so the ORM never writes it and it can never go backwards.rowVersionfield (StorageProfileTypeoptionrow_version, default null = no field). Its value is read from the database (RowVersion::read()), never from the identity map, so a manager that kept a row across requests (worker mode, kernel reset false) cannot make a stale page look current. A missing or malformed token counts as 0, which never matches (versions start at 1).StorageEntityManager::transactional(): transaction-doctrine'sDoctrineTransactionRunneron the bundle's private / dedicated manager, owner lock), after the existingisCurrent()re-check, one atomicUPDATE storage_kit_profile SET row_version = row_version + 1 WHERE id = ? AND row_version = ?. It also holds the row lock until the commit, so a racing save waits and then matches no row. Only then is the entity changed and flushed.StaleEditException(nothing written) → the form is rendered again with 409, a translated flash (settings.flash.stale/move.flash.stale, 7 locales) andX-Error-Code: STORAGE_KIT_STALE_EDIT. Deliberate deviation from ApiStudio #114: a stale page is a domain conflict, so it carries noX-Conflict-Codeand noRetry-After. REQ-RUNTIME-003 rule 6 reserves that header for lock conflicts, andCONFLICT_001would tell clients "retry is safe" for a request that can never succeed. This matches CookieConsent'sRowVersionGuard. Lock conflicts keepCONFLICT_001/CONFLICT_002throughStorageKitConflictListener.StorageMove::saveTarget().saveTarget()gets an optional?int $expectedVersion: null (host code) advances the version unchecked, so pages opened before are refused. State changes (switch / forget) are already covered byisCurrent(). The test-result DBAL writes (ProfileTester, Instance Settings listener) do not touch form fields and do not advance the version.ConnectionRepairer::afterFailure()rolls back to the entry level and closes the connection if that fails). A real deadlock test proves it.RowVersionis static,StaleEditExceptionis a value; the controllers keep the token in locals. Only the bundle's own manager is used (private or dedicated); the host's manager is never touched.ConcurrencyRaceTestupdated).Tests
tests/Unit/Concurrency/RowVersionTest.php: compare-and-set, unchecked advance, missing row.tests/Integration/Functional/StaleEditTest.php(SQLite + DB jobs): stale / missing / forged tokens ('',abc,-1,1e3, a 20-digit value, absent) on the Storage page, the Move page, a first save, a bucket created meanwhile, and an unchecked save from code.tests/Integration/Concurrency/RowVersionRaceTest.php(DB jobs, two connections):CONFLICT_001, and its retry is stale;CONFLICT_001, nesting level 0, the next save works.Local results:
Front-end (Chrome Modern Web Guidance)
npx -y modern-web-guidance@latest search "forms" --skill-version 2026_11_10-47b4c80e, thenretrieve forms. The checks:name(storage_profile[rowVersion]).role="alert", so it is announced.Other guides listed by the search (
agentic-forms,autofill-*,form-fields-automatically-fit-contents,brand-consistent-forms,sms-otp-form,form-associated-custom-elements) do not apply: there are no new visible controls.Upgrade
ALTER TABLE storage_kit_profile ADD row_version INT DEFAULT 1 NOT NULL;(same on MySQL / MariaDB / PostgreSQL), deployed with the code. Custom templates that list fields one by one must renderrowVersion(form_rest()does). See UPGRADING "Unreleased".🤖 Generated with Claude Code