You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 5cd2b54
Browse filesBrowse the repository at this point in the historyBrowse files
fix(objectql): a committed or rolled-back trio handle reads as closed (#35541)
repo:objectstack#5 · os-bill · session_01Utp6Ca1jJvsA1dHsPwMiQb
Fixes#35149
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 用户能看到什么变化:脚本里手动开启的事务提交或回滚之后,仍带着这个旧事务的迟到写入会像普通写入一样正常落库,不再被塞进一个已经结束的事务。
- 为什么做:两种事务结束后的行为原本不一致,另一种早已按“已关闭即视为没有事务”处理,这次让两者一致。
- 出错会怎样:最坏情况是某次迟到写入没有进入它本应加入的仍在进行的事务;改动只在事务已提交或已回滚之后生效,事务进行中的行为不变。
- 要你做什么:无,席位落地。
## 席位核对
### What changes
- `engine-execute-transactions.ts`: the trio's commit/rollback release
is now `closeTrioTransactionScope`, which drops the owner record (as
before) AND adds the handle to a module-level `closedTrioHandles`
WeakSet, only for a handle the trio itself opened (one with an owner
record). `isClosedTrioHandle` reads it. `recordTrioTransactionScope`
clears the mark, so a driver that hands the same object out on a later
`beginTransaction` gets it back open.
- `engine-transactions-section.ts` `isClosedUnitHandle`: when
`openedUnits` holds no entry for the handle, it answers
`isClosedTrioHandle(handle)`. An `openedUnits` entry still decides
first, so a `transaction()` unit handle reads exactly as before.
- `engine-scoped-context.ts`: `commitTransaction` /
`rollbackTransaction` call `closeTrioTransactionScope` in their existing
`finally`. A joined (ambient) handle still returns early and is never
marked.
- `engine.ts` untouched: 6852 lines at `origin/main` 9212119 and at
head (facade ceiling 6854).
- Every reader of `isClosedUnitHandle` now treats a closed trio handle
as absent, as #22855 does for a closed unit: `buildDriverOptions`,
`enforceTransactionOrigin`, `opensAfterAbortUnit`, the secret-row
release, the summary write transaction, and `openTransactionKind`
(`'separate'` becomes `'none'` for a closed trio handle).
- Clause-② measured on the diff: no caller that got an answer now gets a
refusal. A late write carrying a closed trio handle was never refused
(unattributed handle, the gate declined to judge), and is not refused
now; it runs unenrolled instead of being handed the dead handle.
### Tests
`packages/objectql/src/engine-transaction-same-origin.test.ts`:
- The PR #35102 pins "forgets the owner once the trio commits / rolls
back" are re-worded to "treats the handle as closed once the trio
commits / rolls back — a late cross-datasource write runs unenrolled".
Intent kept (the record does not outlive the handle; the late write
lands, not refused); the assertion now also requires
`ledgerDb.writes[0].transaction` to be `undefined`.
- New top-level describe `a trio handle closes as a transaction() unit
handle does (#35149)`, in the same harness file: parity with a closed
`transaction()` unit handle on a late cross-datasource write; a late
same-datasource write after rollback runs unenrolled; CONTROL (open trio
handle reads open, enrolls, and a cross-datasource business write under
it is still refused with `ERR_CROSS_DATASOURCE_TRANSACTION_WRITE`);
`openTransactionKind` separate-then-none; a reused driver handle reads
open on its next begin.
### Acceptance notes
- A0, reproduced at `origin/main` 9212119 source with the new tests
only: a late `ledger` insert carrying a committed trio handle reached
`ledger_db` with `transaction: { __trx: 'primary' }` (the dead foreign
handle); the same after rollback. 7 failed / 27 passed.
- The ADR-0119 note (2026-11-18) says the owner record is "dropped when
commitTransaction or rollbackTransaction closes it": still true, and its
"a handle the engine never opened" limit now matches the code. No ADR
edit.
### Verification
<details><summary>Red at origin/main source, green at head,
ablations</summary>
- Red (tests only, source at 9212119): `vitest run
src/engine-transaction-same-origin.test.ts` → `Tests 7 failed | 27
passed (34)`; first failure `expected { __trx: 'primary' } to be
undefined`.
- Green at b548ddf: same file plus
`engine-scoped-transaction-late-write.test.ts` and
`open-transaction.test.ts` → `Test Files 3 passed (3)`, `Tests 69 passed
(69)`.
- Ablation 1 (`scripts/ablation-replace.mjs`, anchor x1 → x0, blob
abff616 → 235b522e2582): close drops the record without marking →
`Tests 7 failed | 27 passed (34)`; restored, blob == HEAD, `git diff
HEAD` empty.
- Ablation 2 (anchor x1 → x0, blob abff616 → 99010386c306):
`recordTrioTransactionScope` no longer clears the mark → `Tests 1 failed
| 33 passed (34)` (the reused-handle pin); restored, blob == HEAD, `git
diff HEAD` empty.
- The test imports `./engine.js` from `src`, so no `dist` leg applies.
</details>
<details><summary>Package and gates at b548ddf</summary>
- `pnpm --filter @objectstack/objectql typecheck && pnpm --filter
@objectstack/objectql test` under the verify lock → `VERDICT
command-exit 0`; `Test Files 615 passed (615)`, `Tests 13900 passed
(13900)`; `check:test-typecheck: OK`.
- `dispatch-gates.mjs --commands` derived 65 families: 59 ran locally,
exit 0 each. `check:type-check-debt` exit 3 (its closure build never got
a turn on the shared verify lock): NOT MEASURED. `check:dts-closure`,
`check:dual-build-cjs-loads`, `check:lean-entry-closure`,
`check:published-files` and `check:sourcemap-no-sources-content` read
the built `dist`; the objectql build did not get a turn on the lock
after more than 45 minutes in the queue, so these are NOT MEASURED
locally, a declared narrowing, and left to CI.
- `test:repo`, `--project integration` and the dogfood battery not run
locally: not owed for this diff (no `!`, no narrowing arm), declared to
CI.
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_01Utp6Ca1jJvsA1dHsPwMiQb)_
Co-authored-by: Claude <noreply@anthropic.com>
fix(objectql): a trio transaction handle that committed or rolled back reads as closed, as a closed `transaction()` unit handle does
6
+
7
+
Clause-②: no
8
+
Metadata-protocol: none
9
+
10
+
`ScopedContext`'s discrete `beginTransaction` / `commitTransaction` / `rollbackTransaction` trio (the sandbox runner's `ctx.api.transaction`) now marks its handle closed when it commits or rolls it back, instead of only dropping the handle's owner record. The engine's closed-handle check answers `true` for it, so work that still carries the handle afterwards runs outside any transaction, on its own connection, exactly as late work carrying a closed `transaction()` unit handle already did. Before, such a handle read as an unattributed one: a late write routed to another datasource was handed the dead foreign handle, and a late write on the same datasource was handed the finished handle. `openTransactionKind` answers `'none'` for a closed trio handle, where it answered `'separate'`. A driver that hands out the same handle object on a later `beginTransaction` gets it back open.
0 commit comments