Skip to content

Commit 99c200d

Browse files
committed
chore(changeset): name both arms of the update's own unit in the claim-race note
The unit opens for a metadata beforeUpdate hook (since 18.6.0) or a blocking / conditioned metadata afterUpdate hook (since before 18.5.0); the note now gives the loser's answer history for each and the post-next() timing for both. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JQwxbXGvw43spR79ztEvWt
1 parent 415eefd commit 99c200d

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

‎.changeset/35142-claim-race-loser-409.md‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,20 @@
22
'@objectstack/objectql': patch
33
---
44

5-
fix(objectql): the loser of a concurrent update answers 409 CONCURRENT_UPDATE again on an object with a metadata `beforeUpdate` hook
5+
fix(objectql): the loser of a concurrent update answers 409 CONCURRENT_UPDATE on any update that opens its own unit of work
66

77
Clause-②: no
88
Metadata-protocol: none
99

10-
Two members of a queue claiming the same parked record at the same moment again get one success and one `409 CONCURRENT_UPDATE`, as ADR-0142 D4 says. Since 18.6.0, on a single-connection store such as SQLite, the loser got `404 RECORD_NOT_FOUND` (private sharing) or `403 PERMISSION_DENIED` (public read) whenever the object carried a metadata `beforeUpdate` hook. The stored owner was always right; only the loser's answer was wrong.
10+
Two members of a queue claiming the same parked record at the same moment get one success and one `409 CONCURRENT_UPDATE`, as ADR-0142 D4 says, on every object. On a single-connection store such as SQLite, the loser got `404 RECORD_NOT_FOUND` (private sharing) or `403 PERMISSION_DENIED` (public read) instead whenever the update opened its own unit of work. An update does that in two cases, and the wrong answer has a different history in each:
1111

12-
The cause: a write on such an object opens its own unit of work, so that a refusal later in the write rolls back what a `beforeUpdate` hook wrote through `ctx.api`. That unit opened around the whole update, the authorization middleware included. On SQLite the second writer then waited for the first one's commit before its authorization gate read the record, and by then the record belonged to someone else. The unit now opens around the engine body only: the middleware runs before it, as it does for an update that opens no unit, and the hooks, the row write and the `after*` chain still run inside it and still roll back together.
12+
- The object carries a metadata `beforeUpdate` hook. This case opens the unit since 18.6.0, so the loser answered 409 in 18.5.0 and 404 / 403 in 18.6.0. It answers 409 again.
13+
- The object carries a blocking (`onError: abort`, the default) or conditioned metadata `afterUpdate` hook. This case already opened the unit in 18.5.0, so the loser answered 404 / 403 in 18.5.0 and 18.6.0. It now answers 409.
1314

14-
What a middleware does after `next()` on such an update now runs after the commit, as it does on an object with no metadata hook.
15+
The stored owner was always right; only the loser's answer was wrong.
16+
17+
The cause: the unit exists so that a refusal later in the write rolls back what the write's hooks wrote through `ctx.api`, the row included. That unit opened around the whole update, the authorization middleware included. On SQLite the second writer then waited for the first one's commit before its authorization gate read the record, and by then the record belonged to someone else. The unit now opens around the engine body only: the middleware runs before it, as it does for an update that opens no unit, and the hooks, the row write and the `after*` chain still run inside it and still roll back together.
18+
19+
What a middleware does after `next()` on such an update now runs after the commit, as it does on an object with no metadata update hook. For the `beforeUpdate` case that is how 18.5.0 behaved. For the `afterUpdate` case it is a change from every earlier release, where that code ran inside the unit.
1520

1621
Nothing to change in an app.

0 commit comments

Comments
 (0)