fix: close Human Gates review races
This commit is contained in:
1 parent
dbb8ff4d4e
commit
9d84d5c5c4
5 files changed
+89
-18
No files matched your search
@@ -218,15 +218,20 @@ class HumanGateStore:
|
||||
if immutable_old != immutable_new:
|
||||
raise GateConflict("Candidate hash is already bound to different facts")
|
||||
if old_payload != payload:
|
||||
if existing["state"] == "superseded":
|
||||
raise GateConflict("Candidate hash was superseded by a newer candidate")
|
||||
now = float(self.clock())
|
||||
revision = existing["revision"] + 1
|
||||
reopened = existing["state"] in {"released", "held"}
|
||||
state = "pending" if reopened else existing["state"]
|
||||
action = "reopened" if reopened else "updated"
|
||||
connection.execute(
|
||||
"UPDATE human_gates SET payload_json=?, revision=?, updated_at=? WHERE id=?",
|
||||
(_canonical(payload), revision, now, existing["id"]),
|
||||
"UPDATE human_gates SET payload_json=?, state=?, revision=?, updated_at=?, decision_reason='', override_reason='', checklist_json='{}' WHERE id=?",
|
||||
(_canonical(payload), state, revision, now, existing["id"]),
|
||||
)
|
||||
connection.execute(
|
||||
"INSERT INTO human_gate_history(gate_id,action,at,details_json) VALUES (?,?,?,?)",
|
||||
(existing["id"], "updated", now, _canonical({"candidate_hash": payload["candidate_hash"]})),
|
||||
(existing["id"], action, now, _canonical({"candidate_hash": payload["candidate_hash"]})),
|
||||
)
|
||||
existing = connection.execute(
|
||||
"SELECT * FROM human_gates WHERE id=? AND login=?",
|
||||
|
||||
Reference in new issue
Block a user