
A reviewer opens an offering approval while the terms are on version one. Before the reviewer clicks Approve, another operator publishes version two. A check that looks only for a pending request can approve an operation the reviewer never saw.
This lab implements a SQLite approval queue that binds a decision to a request version, payload fingerprint and current terms. It also requires a reviewer different from the requester and serializes two simultaneous decisions. Actors and offerings are synthetic test labels. Download the standalone queue and tests.
Aurum RWA's offering approval source checks expected version, request hash, expiry and requester identity. Its quote approval path also checks that the offering still refers to the quote's terms. The lab extracts those ideas into a smaller model. It does not implement the product's identity system or execute an offering operation.
Run one independent review
The archive was verified with Python 3.13.3. SQLite and the other imports are part of the standard library.
python3 lab.py
python3 -m unittest -v
The demo creates a request from maker, then records an approval from checker. A request begins at version one. Its successful decision increments the version and changes the status, so another decision using the original version becomes stale.
The example stores a hash of the submitted payload rather than the full payload. A real review interface would also need an immutable copy of the content the reviewer saw. The fingerprint alone cannot reconstruct that screen or explain the proposal to an auditor.
The target table stores the currently effective terms identifier. Keeping that value outside the approval row lets the test change the target independently after the request has been created.
Bind the decision to the reviewed proposal
The request hash uses canonical JSON formatting before SHA-256. The ordering removes irrelevant dictionary ordering from the fingerprint.
def payload_hash(payload):
return hashlib.sha256(json.dumps(payload,sort_keys=True,separators=(',',':')).encode()).hexdigest()
This hash is a comparison mechanism. It is not a signature and does not authenticate a reviewer. The application must obtain the reviewer identity from its authenticated server context. Passing an arbitrary name into this sample is sufficient for a fixture, but would not provide separation of duties in a deployed service.
The decision method checks both the saved request and the current target while holding a database write transaction.
def decide(self,identity,actor,expected_version,expected_hash,decision,now):
if decision not in {'approve','reject'}: raise ValueError('invalid decision')
with self.db:
self.db.execute('BEGIN IMMEDIATE')
row=self.db.execute('SELECT requester,terms,hash,expires,version,status FROM review WHERE id=?',(identity,)).fetchone()
if row is None: raise ValueError('missing request')
requester,terms,hashed,expires,version,status=row
current=self.db.execute('SELECT terms FROM target WHERE id=1').fetchone()[0]
if actor==requester: raise ValueError('self approval forbidden')
if status!='pending' or version!=expected_version or hashed!=expected_hash or expires<=now or terms!=current:
raise ValueError('stale approval')
self.db.execute('UPDATE review SET status=?,version=version+1,reviewer=? WHERE id=?',(decision,actor,identity))
return decision
A request must still be pending. Its version and hash must match the review submission, its expiry must be later than the service time, and its terms must still equal the target's terms. The requester cannot approve or reject their own request in this model.
The lab applies the same freshness conditions to both decisions. An application can choose different rejection semantics if its business process requires them, but that choice should be explicit. This sample avoids adding a second stale-request cleanup path.
Serialize competing reviewers
The method begins with BEGIN IMMEDIATE. That makes the read-check-write sequence a single protected decision for this SQLite exercise. A second reviewer waits, then sees the first reviewer's updated status and version.
def test_two_reviewers_one_decision(self):
barrier=threading.Barrier(2)
def worker(actor):
r=Reviews(self.path); barrier.wait()
try: return r.decide('r',actor,1,self.h,'approve',150)
except ValueError: return 'stale'
finally: r.close()
with ThreadPoolExecutor(2) as pool: results=list(pool.map(worker,['A','B']))
self.assertEqual(sorted(results),['approve','stale'])
The test uses two database connections and a barrier. Both reviewers reach the decision attempt before either is allowed to continue. The expected result is one approval and one stale rejection. It does not depend on a chosen sleep duration or assume which reviewer wins.
The production source uses its own database and transaction helpers. SQLite's locking behavior is not a claim about the product's deployment database. The transferable requirement is that the evidence read for the decision cannot be invalidated by another successful decision before the update commits.
The decision records the reviewer identity beside the outcome. A fuller audit system would also retain timestamps, reason text and the immutable proposal, all under the project's actual retention rules. Those fields are deliberately outside this small concurrency lab.

Reproduce stale approval directly
The failure test first changes the target terms and verifies that the old approval still has a pending status. That proves why checking only the status would accept the wrong proposal.
def test_naive_pending_only_check_misses_changed_terms(self):
self.r.change_terms('terms-2')
self.assertEqual(self.r.db.execute('SELECT status FROM review').fetchone()[0],'pending')
with self.assertRaises(ValueError): self.decide()
The protected decision refuses the request because the terms identifiers differ. It does not silently substitute the new terms into the old approval. A new review can then be prepared around the changed proposal.
Seven named tests passed after extracting the archive into a clean temporary directory. They also reject self-review, a changed hash and the wrong expected version. The expiry test checks equality at the deadline, while another test ensures a rejected request cannot later be approved by supplying its incremented version.
Try removing the target-terms comparison and rerun the stale approval test. Try removing the pending-status requirement and rerun the rejection test. These mutations reveal two distinct protections that a successful happy-path approval would never exercise.
Keep approval separate from execution
Recording approve does not deploy a token, open subscriptions or move funds. The sample deliberately stops at the review decision. Aurum's actual workflows have action-specific checks after an approval, and those execution paths need their own evidence.
Time also remains an explicit service input. The test can set it to exactly the expiry boundary. A server integration should supply trusted time and should not accept the browser's clock as the deciding value.
The integer quote lab checks the amounts and terms presented to an investor. This approval lab checks who may accept a versioned operational proposal and whether it is still current. A valid quote calculation does not replace a valid approval decision.
Use two reviewers in the product walkthrough
For an Aurum RWA evaluation, ask two operators to open the same pending request. Let one decide, then submit the other's unchanged screen. The second action should show why the proposal needs a fresh view.
Repeat with the requester as reviewer and with the underlying terms changed before approval. These are concrete delivery checks for the software workflow. They establish neither the legal authority of an offering nor the identity assurance of a production organization; those depend on the project's actual participants, documents and integrations.