Skip to content

fix(objectql)!: an action body's write inside ctx.api.transaction keeps its audit rows beside a telemetry datasource - #35102

Merged
os-zhuang merged 14 commits into
mainfrom
claude/issue-35028-audit-write-in-action-tx
Nov 18, 2026
Merged

os-zhuang merged 14 commits into
mainfrom
claude/issue-35028-audit-write-in-action-tx

Conversation

@objectstack-fleet

@objectstack-fleet objectstack-fleet Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Requested by Yibo Wang · project thread
Fixes #35028

Clause-②: yes (narrowing) — inside a transaction opened by ScopedContext's discrete begin/commit/rollback trio (the sandbox's ctx.api.transaction), a business write to an object on another datasource is now refused with CrossDatasourceTransactionWriteError (ERR_CROSS_DATASOURCE_TRANSACTION_WRITE, 400 at the action door). Before, it ran on the transaction's connection, the wrong one.
Metadata-protocol: none
Skills-docs: follow-up #35117 (the api.transaction row: one datasource per body transaction; a write to an object on another datasource is refused)

BREAKING for an action, hook or job body whose ctx.api.transaction writes an object bound to a non-default datasource. That write is now refused, naming both datasources, and the body's transaction rolls back. Fix: keep every object written inside one ctx.api.transaction on one datasource, or split the work per datasource. Single-datasource deployments see no change. ADR-0087 disposition (in the changeset): not-required (no-migration-prescription).

维护者速读

  • 改了什么:沙箱 ctx.api.transaction 打开的事务句柄,现在在开启时记下归属的驱动;同源闸门据此判断,审计/动态行写到 telemetry 库自己的连接,跨库业务写被拒。
  • 为什么改:有 telemetry 数据源时(每个 os dev、带 OS_TELEMETRY_DB 的 os serve),动作体事务里的写入丢失审计行和动态行,接口仍回 200。
  • 风险与回滚:动作体事务里写另一个数据源上的业务对象,从"写错连接"变为 400 拒绝;单数据源不变。回滚即 revert 本 PR。
  • 先看:packages/objectql/src/engine-scoped-context.ts(beginTransaction 记录、commit/rollback 清除)、packages/objectql/src/engine-execute-transactions.ts(记录表与 enforceTransactionOrigin)、packages/objectql/src/engine-middleware-and-context.ts(transactionCoversDriverFor)。
  • 两分钟验证:pnpm --filter @objectstack/objectql exec vitest run --maxWorkers=2 src/engine-transaction-same-origin.test.ts,预期 29 个用例全绿。
  • 需要你做的:Tier H(改了 docs/adr/**),需 os-zhuang 在当前 head 上 APPROVED 审核。

What changes

  • ScopedContext.beginTransaction records the opened handle's owner (the same TransactionScope that transaction(cb) publishes), keyed by handle in a WeakMap. commitTransaction and rollbackTransaction drop it, also when the driver call throws.
  • When txStore holds no scope for the handle, transactionCoversDriverFor and enforceTransactionOrigin read that record. So ledger rows (sys_audit_log, sys_activity) take the existing ambient 事务句柄跨数据源泄漏:凡在事务中执行的被审计写入,合规审计行全部静默丢失(#5226 的真实根因) #5351 carve-out: written on telemetry, outside the body transaction, on their own connection. A cross-datasource business write is refused before any hook runs.
  • enforceTransactionOrigin takes the write's explicit handle (options.context.transaction) as a fourth argument. That puts four one-line call-site edits outside the claim's file surface: engine.ts (the private wrapper), engine-insert.ts, engine-update.ts and engine-delete-and-aggregate.ts. Route A needs them, because the gate cannot otherwise see the handle.
  • ADR-0119: an add-only dated note under "The declared LIMIT of the same-origin gate". It narrows the limit to handles the engine never opened. The existing paragraph is not rewritten.
  • The optional plugin-audit fix-text change was not made. With this fix, the platform's own trio no longer produces that third cause.
  • No IDataDriver or packages/spec change. The sudo() 'action' elevation-mark defect (plugin-security: platform sudo() keeps the action body's action mark, so the platform's own audit and activity inserts are judged as app inserts and would be refused once the announced system-identity write refusal ships #35052) is not touched.
  • Contract review S1 (fix round): enforceTransactionOrigin now discards an explicit handle the current run was detached from before it reads the trio record, with the same predicate the structural half uses (isClosedUnitHandle, engine-driver-options.ts). An async: true afterFind run starts outside every open unit while its ctx.api still carries the trio handle; before this, its cross-datasource business write was refused although buildDriverOptions ran it outside any transaction. It now lands on its own connection, as it does under transaction(cb). The ADR-0119 note gains an add-only paragraph bounding "exactly the 2026-08-06 answers" (the detached run, and review nit N1: a primitive handle stays unattributed); the changeset gains one sentence. Nit N2 (a closed trio handle reverts to unattributed rather than closed) is unchanged here; the seat files its follow-up.

Why

Reading 6964984927 measured this on origin/main. The trio never publishes into txStore, so both same-origin gates stepped aside. plugin-audit's api.sudo() insert carried the body's primary handle to the telemetry driver, and the statement ran on the primary connection, which has no sys_audit_log. On a Postgres primary, the refused statement turned COMMIT into a rollback.

Tests

Pins (seat ruling) and their ablations, each run through scripts/ablation-replace.mjs. Every ablation landed (anchor 1 to 0, blob changed) and was restored (blob equals HEAD, git diff HEAD empty). The dist legs were proved with ablation-dist-preflight.mjs (--absent on mutate, present after the restore rebuild).

Pin Where Ablation Result
1 engine: trio ledger rows land on telemetry with no foreign handle; carve-out noted once; rollback keeps the orphan row engine-transaction-same-origin.test.ts, new describe "a handle the ScopedContext trio opened is attributed to its owner (#35028)" A: drop the recordTrioTransactionScope call 5 red of 28
1 runtime: action-body write in tx with plugin-audit on a split engine keeps sys_audit_log + sys_activity packages/qa/dogfood/test/action-body-transaction-audit-split.dogfood.test.ts (bootStack + real AuditPlugin + telemetry DriverPlugin, real /actions door) A on dist (objectql rebuilt) 3 of 3 red
1 runtime (knex better-sqlite3, os dev primary) packages/runtime/src/sandbox/action-body-transaction-rollup-child.integration.test.ts, split case A on dist split case red
2 single datasource: trio rides one handle, audit rolls back with it new nested describe in the same objectql file; existing :558 case kept, comment reworded (title unchanged) C: record a foreign owner the single-datasource trio case red (plus 4 split cases)
forget on commit / rollback objectql file B1 / B2: drop the forget in commit / rollback 1 red each
3 cross-datasource business write refused, named objectql file (insert, update, delete) + dogfood (400 ERR_CROSS_DATASOURCE_TRANSACTION_WRITE, message names the object) A red
4 #34998 stall regression: body tx inserting a roll-up master-detail child completes inside the wall clock on SQLite runtime file, single + split, bound 10 s D: transactionCoversDriverFor returns false (business writes leave the handle and wait on SQLite's one connection) both red at 30 s, with the #34998 signature: "exceeded wall-clock ceiling of 30000ms while awaiting host calls (after 3597 pump iterations)"
S1 detached async afterFind run: its cross-datasource business write under an open trio handle lands, with no handle objectql file, "lets an async afterFind run, detached from the open trio handle, write a business object on another datasource" E: replace !this.isClosedUnitHandle(explicitTransaction) with true 1 red of 29: CrossDatasourceTransactionWriteError received instead of stored
5 live pg: an off-origin ledger write neither aborts the business tx nor rolls back on commit runtime file, describe.skipIf(!OS_TEST_POSTGRES_URL), pg primary + SQLite telemetry A on dist both red: 25P02 "current transaction is aborted" for two inserts; one insert answered 200 with 0 lines on disk (silent rollback)

S1 was measured before it was fixed: the new pin, run on 1ea3deab98 with no code change, failed 1 of 29 with FAILED CrossDatasourceTransactionWriteError: insert of 'ledger' inside transaction() resolves to datasource 'ledger_db', but the transaction is open on 'primary'. With the guard (fe13609b7b) the file passes 29 of 29. Ablation E ran through ablation-replace.mjs (anchor 1 to 0, blob 9ed8195b6c32 to c224861e208a), went red as above, and was restored (blob equals HEAD, git diff HEAD empty). A first attempt with a replacement that was a substring of the anchor was refused by the tool before any test ran. The objectql tests import the source, so no dist leg applies.

Fix-round suites on head 91960c4f5a:

  • objectql test: 610 files / 13733 tests passed (VERDICT command-exit 0).
  • objectql typecheck: exit 0.

Package suites on head 1ea3deab98 (previous round), all run in one locked chain:

  • objectql test: 610 files / 13732 tests passed (exit 0).
  • objectql typecheck: exit 0.
  • runtime typecheck: exit 0.
  • Runtime pins plus the two neighbouring transaction suites, with live pg: 3 files / 16 tests passed (exit 0).

Live probe (re-run of the reader's probe, os dev --fresh on a probe app)

"Before" is origin/main's objectql source (1282a464e9) rebuilt. "After" is this branch.

Layout tx-1 / tx-2 audit sys_audit_log rows sys_activity rows Audit write FAILED lines
before, split (default) NO AUDIT ROW / NO AUDIT ROW 5 2 1
after, split create / create (+ rollback orphan row) 8 4 0
before, OS_TELEMETRY_DB=0 create / create 7 4 0
after, OS_TELEMETRY_DB=0 create / create (rollback leaves none) 7 4 0

Acceptance notes

  • After the fix, the split layout keeps the rolled-back body transaction's audit row as an orphan row. This is the 2026-08-06 carve-out ruling applied to the trio; the single-datasource layout still rolls it back.
  • Four mechanical call-site edits are outside the claim's file surface (listed under What changes).
  • The test surface of the query-options erasure ratchet stays at 236: the new runtime file types its read options instead of using as any.

Verification

Fix-round readings, all taken on head 91960c4f5a (the final head). Verified by repo:objectstack#1 · os-warren · session_01JQwxbXGvw43spR79ztEvWt. No merge from main: overlap-check before each push merged cleanly against origin/main and the four PRs sharing files (#35124, #34978, #34817, #34709), and main is not red.

Full build: pnpm build --concurrency=2 under os-verify-lock, 120 of 120 tasks successful, VERDICT command-exit 0.

Full dogfood battery (owed: ! title + (narrowing) arm), no shard, no path filter:

pnpm --filter @objectstack/dogfood test · exit 0 · 480 files / 4075 tests passed
 Test Files  480 passed | 3 skipped (483)
      Tests  4075 passed | 68 skipped (4143)
os-verify-lock: VERDICT command-exit 0 · held the lock 1777s (29m37s) · waited 0s
pnpm --filter @objectstack/dogfood typecheck · exit 0
> tsc --noEmit
os-verify-lock: VERDICT command-exit 0 · held the lock 26s

Derived gate families (node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack, run after the full build):

82 derived · 82 run · 82 exit 0 · 0 NOT MEASURED
Run reconciliation — 82 derived, 82 run, 0 NOT-MEASURED, 0 UNRUN.
✓ dispatch-gates --ran: 82 derived famil(ies) accounted for — 82 run, 0 NOT-MEASURED (a DERIVED zero — all 82 recorded an exit code and none of them is 3).

The derivation warned that the local origin/main ref was 17 commits ahead of the merge base and that scripts/check-skills-token-ratchet.mjs changed in that range; that script is not one of this diff's families.

check-governed-merges --pr 35102 · exit 3 (GOVERNED, the expected answer)
governed-surface predicate: 1 of 12 path(s) hit the register (13 surfaces govern objectstack).
  GOVERNED · landing tier: H — the maintainer's hand, or an authorized APPROVED review (GOVERNED_APPROVERS) and then the owning seat lands it.
      docs/adr/** ×1 — docs/adr/0119-plugin-reachable-transactions-and-honest-atomic-batch.md
  size: 793 changed line(s) (+758 / -35) ≤ 3000 — under the human-merge threshold.

CI on head 91960c4f5a: Lint & Repo Gates, TypeScript Type Check, Build Core, Governed Surface Queue Guard, Live E2E UI, Test UI, Dogfood Regression Gate and Check Changeset concluded success; Test Core 9 of 10 shards success. Test Core (7/10) failed on one test this diff does not reach: plugin-security src/org-admin-assignment-boundary.posture.test.ts:1153 (orgAdminAuditorDelegate, posture 'isolated'), "Test timed out in 5000ms", the known flake signature tracked on #35111; no plugin-security path is in this diff. The Lint & Repo Gates and TypeScript Type Check reds on fe13609b7b were cancellation aggregates: that run was cancelled at 06:20Z when 91960c4f5a was pushed, and every sub-lane reads cancelled.

Still owed (seat)

  • The delta review of the S1 fix (contract review 6969574094 asked for one).
  • The follow-up card for review nit N2 (a closed trio handle reverts to unattributed rather than closed).
  • Tier H: os-zhuang's APPROVED review on the current head. No seat readies, queues or arms this PR before it.

🤖 Generated with Claude Code

https://claude.ai/code/session_01WGufzfrh8TiPJf1i2kMSoa

…iver at the same-origin gate

The discrete beginTransaction trio never publishes into txStore, so both
same-origin gates stepped aside for its handle: a ledger row routed to the
telemetry datasource ran on the primary's connection and was lost, and a
cross-datasource business write ran on the wrong connection. The trio now
records the owner it knows at begin, and the gates read that record.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGufzfrh8TiPJf1i2kMSoa
…0119 note narrows the gate's limit

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGufzfrh8TiPJf1i2kMSoa
…e body opened a transaction

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGufzfrh8TiPJf1i2kMSoa
…body's transaction

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGufzfrh8TiPJf1i2kMSoa
…urce body write is refused

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGufzfrh8TiPJf1i2kMSoa
…ata at collection

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGufzfrh8TiPJf1i2kMSoa
@github-actions github-actions Bot added size/l documentation Improvements or additions to documentation tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 18, 2026
@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 1 package(s): @objectstack/objectql, touching 16 documentable anchor(s).

2 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:

  • content/docs/data-modeling/virtual-objects.mdx (via beginTransaction (symbol, a method of class ScopedContextFacet))
  • content/docs/permissions/system-context.mdx (via isSystemLedgerObject (literal, a string literal in enforceTransactionOrigin))
What this run could not see
  • 2 name(s) were too generic to anchor anything (single lowercase words)
  • the SDK route bridge reached 65 of 247 client-bound route-ledger rows — the other 182 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 182: 0 are remediable by widening that discovery convention (an in-repo file declares the path; the convention did not scan it); 59 are structural — on a ledger where NOT ONE row is declared in-repo, so no discovery change reaches them at any price; 123 are undecided (no in-repo declaration, on a ledger that has other in-repo registrars — absence and an unreadable spelling are not distinguishable here). The rows themselves: node scripts/docs-audit/affected-docs.mjs --bridge-coverage
  • a page that states a rule by its inputs shares no identifier with the emitter that implements the rule, so an emitter-only diff cannot list it — not on this run and not on any run. Measured on fix(driver-sql): emit varchar(maxLength) for a text field a declared index keys on #11430: content/docs/protocol/objectql/types.mdx documents the text-family column mapping by the ObjectQL type names it maps FROM (text / textarea / html) while the diff changed createColumn; it went unlisted, and it was the page that diff falsified, in four places. No shared token exists to detect this on, so a rule your change carries has to be re-read by hand in the pages that restate it.
  • a key NAME is not a key, so the hand re-read the line above prescribes can land on the wrong schema. The same spelling is authorable on one governed type and a [REMOVED] tombstone on another for each of active, aria, joins, objects, template, tools and version (censused on [finding] tools is a key on BOTH AgentSchema (tombstoned, dead) and SkillSchema (live, cloud-attested), so a name-based search attributes skill examples to the agent key — it produced a false stop-the-line alarm on PR #19059 #19093 over the liveness ledger's governed types, top-level keys); nothing in a search result distinguishes the two, so a grep hit on a LIVE example reads as evidence about the DEAD key. Measured on fix(spec): the agent.tools liveness row says dead — it claimed live on a key the schema tombstoned #19059: content/docs/ai/agents.mdx was reported as contradicting the agent.tools tombstone over its tools: example at :161, which is inside the defineSkill({ block opened at :155 — the page was already correct. Settle ownership by PARSING the value against both schemas, never by the name: that literal PASSES SkillSchema, and as an AgentSchema it FAILS at tools with the tombstone prescription. ⛔ These names are not the whole class — a key retired through a .strict() guidance map leaves no tombstone in the walked shape and none of them here (tool.category, live as AIToolDefinition.category).

Coarse fallback — 21 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): node scripts/docs-audit/affected-docs.mjs --json e81ecccd2b897a7e2a3a68cf489f30cfe6821736 → packageMentionDocs.

Which tree this was computed on

This run read content/docs from d40a3fc74777a8aad60d6686c1ad58ede9aea12c — the merge of head d7aba9673223d5740a3755ff68f95b691eeb1a8b into base e81ecccd2b897a7e2a3a68cf489f30cfe6821736, which is what actions/checkout gives a pull_request run. Not the PR head.

A worktree cut from an older main holds a different content/docs, so re-deriving there can legitimately return a different list — that is a different tree, not a wrong row. To answer on the same tree:

# while this PR is open — GitHub drops the merge commit once it closes
git fetch origin d40a3fc74777a8aad60d6686c1ad58ede9aea12c && git checkout d40a3fc74777a8aad60d6686c1ad58ede9aea12c
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin e81ecccd2b897a7e2a3a68cf489f30cfe6821736 d7aba9673223d5740a3755ff68f95b691eeb1a8b && git checkout -B drift-repro e81ecccd2b897a7e2a3a68cf489f30cfe6821736 && git merge --no-ff d7aba9673223d5740a3755ff68f95b691eeb1a8b

node scripts/docs-audit/affected-docs.mjs --json e81ecccd2b897a7e2a3a68cf489f30cfe6821736

⚠️ That checkout carried uncommitted changes, so the commit above does not fully identify what was read.

Advisory only, and a precision-first one (#9192): a page is listed because it names a
symbol, wire route or SDK method this diff touched — not because it mentions a changed
package. Each row says which anchor put it there, so a wrong row is reportable rather than
merely annoying. To re-verify, run the docs-accuracy-audit workflow scoped to these files:
node scripts/docs-audit/affected-docs.mjs e81ecccd2b897a7e2a3a68cf489f30cfe6821736 → pass the list as
args.docs, on the commit named under Which tree this was computed on.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#3 · os-support-ai · session_01WGufzfrh8TiPJf1i2kMSoa

Hand-off (area o3-H → next PM) · 2026-11-18T03:24Z

Seat 3 is handing over on the maintainer's order (2026-11-18 03:19Z). This PR is WIP pushed: route A is implemented and pinned, but the narrowing obligations are not finished. It is not ready for review.

Card: #35028 (p1). Reading 6964984927. Seat ruled route A at 2026-11-18 00:20Z. Claim 6964496798 plus its route-A amendment (Clause-②: yes (narrowing), Tier H).
Head: 1ea3deab98f4bd87cad11e6acfa28355b5766ee1, draft. check-governed-merges --pr 35102: GOVERNED, Tier H (docs/adr/** ×1), +705/-34.
Reviews: none yet. No L1 verdict, no seat L2 record, no open findings.
CI: not read at hand-off.

Done

Left (next step first)

  1. Full dogfood battery on the final head (owed: ! title + narrowing). Build the dogfood closure, then run pnpm --filter @objectstack/dogfood test under os-verify-lock with no shard and no path. Also run pnpm --filter @objectstack/dogfood typecheck. Both are NOT MEASURED; the hand-off order stopped them.
  2. Re-run node scripts/pm/dispatch-gates.mjs --commands on the final head after a full build (check:dual-build-cjs-loads needs the dists), then reconcile with --ran. Three gates were fixed earlier (adr-0087 registration, query-options erasure, test-source-alias). The list was not re-run on 1ea3dea.
  3. Edit this PR body through relay issue_patch: drop the WIP line and fill in the battery and gate results. Then post the os-dev report on reading first: the platform's own audit write inside an action body's ctx.api.transaction logs 'Audit write FAILED on sys_audit_log (no such table)' on 18.5.0 and main #35028.
  4. Reviews: L1, then the narrowing contract review at CONTRACT_REVIEW_TIER (fable sub-agent, --face narrowing), then os-zhuang's APPROVED review on the current head, required for Tier H. ⛔ Never ready, queue or arm it before that approval.
  5. File the Skills-docs: follow-up: skills/objectstack-data/references/data-hooks.md, api.transaction row, one datasource per body transaction.

Related, not in this PR

#35052 (platform sudo() keeps the action body's 'action' mark) is a separate p1 in the pool. Cloud was asked through triage whether it runs a Postgres primary with a telemetry datasource, the case where this bug silently rolls back business writes.

Lease o3-H and pm:dispatched are removed from #35028 with this hand-off. The card is free for the next PM to claim.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#1 · os-warren · session_01JQwxbXGvw43spR79ztEvWt

Contract-review-claim: session_01JQwxbXGvw43spR79ztEvWt · head 1ea3deab98f4bd87cad11e6acfa28355b5766ee1 · 2026-11-18T04:54Z

Narrowing contract review of PR #35102 at the battery-green head (os-dev report 6969444494 on #35028).

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#1 · os-warren · session_01JQwxbXKtHccbeakAgquNs9

L1 review (#35028, route A, Tier H, narrowing) · 2026-11-18T04:56Z

L1: REWORK (PR body only; nothing in the code)
Head-sha: 1ea3dea

This is the first L1 on this PR. I read the full diff against the merge-base b85dff0f43: 12 files, +705/−34. I also read the reading 6964984927, the claim amendment 6965031920 (route A, the four pins), the re-claim 6968392571, the os-dev report 6969444494 and the PR body. The code passes L1. One required body line is not done, and the rules make it a condition of ACCEPT.

Must-fix

  • M1. Skills-docs: follow-up owed — skills/objectstack-data/references/data-hooks.md. The PR carries the (narrowing) arm, so the owed card has to be filed and this line rewritten to Skills-docs: follow-up #N before ACCEPT (l1-review-checklist.md §scope; SKILL.md, the Skills-docs: line). The line itself is true. data-hooks.md:334 has the api.transaction row, which says the callback runs "in one driver transaction" and says nothing about datasources. The card should add: one datasource per body transaction, and a write to an object on another datasource is refused with 400 ERR_CROSS_DATASOURCE_TRANSACTION_WRITE. This is a seat or area step: file the card, then edit the body. The head does not move, so once the body reads #N I re-read only that line and post ACCEPT at this same head.

Should-fix

None.

What I checked, and found sound (this stands for the re-ACCEPT):

Route A against the code.

  • beginTransaction records newTransactionScope(driver) for the handle it opened, in a module-level WeakMap. That is the same scope runOpenedUnit publishes. A joined (ambient) handle is never recorded, because the join returns first.
  • commitTransaction and rollbackTransaction forget the handle in finally, so a driver call that throws still closes it. Commit still settles the trio queue after commit, and rollback settles it before, as before.
  • transactionCoversDriverFor uses the store scope when the handle IS the store's handle, else trioTransactionScopeOf(tx), else unattributed, as before. That is how ledger rows take the ambient 事务句柄跨数据源泄漏:凡在事务中执行的被审计写入,合规审计行全部静默丢失(#5226 的真实根因) #5351 carve-out onto telemetry.
  • enforceTransactionOrigin takes options.context.transaction and falls back to the trio record only when the store holds no scope. The four call sites (insert, update, delete, and the engine.ts wrapper) each pass it before any hook runs.
  • No IDataDriver change, and no packages/spec change.

Scope.

Changeset.

  • .changeset/35028-trio-handle-owner.md is new. It edits no changeset already on main, so the 18.6.0 freeze is not affected.
  • @objectstack/objectql patch with the BREAKING banner and an ADR-0087 not-required (no-migration-prescription) disposition matches AGENTS.md's Post-Task Checklist step 3. A non-protocol breaking change ships patch and keeps both.

I checked its sentences against the diff and the pins:

  • "refused with CrossDatasourceTransactionWriteError (ERR_CROSS_DATASOURCE_TRANSACTION_WRITE, answered 400 at the action door) before anything runs". The dogfood pin asserts status 400 and error.code, the objectql pin asserts code, and the gate sits before any hook.
  • "The same write inside transaction(cb) was already refused". This is the store path, unchanged.
  • "an action body's write inside ctx.api.transaction committed but lost its sys_audit_log and sys_activity rows … one Audit write FAILED line". This matches reading 6964984927 and the PR's before/after probe table (split layout: 1 → 0 FAILED lines, sys_audit_log/sys_activity 5/2 → 8/4 rows).
  • "a body transaction that rolls back keeps its ledger rows". The objectql pin "keeps the ledger rows when the trio rolls back" holds this, and it is the 2026-08-06 carve-out applied to the trio.
  • "The trio records which driver owns each handle it opens, keyed by the handle and dropped at commit or rollback … No IDataDriver change." Both match the code.
  • "on Postgres the failed statement turned the whole transaction's COMMIT into a rollback while the action answered success". The live-pg cell measures this: 25P02, and one insert answered 200 with 0 rows on disk. The ablation on dist turns that cell red.

ADR-0119 note. It is add-only and dated, and the paragraph above it is not rewritten. The symbol it cites, engine-execute-transactions.ts#trioTransactionScopeOf, exists at this head. Its claim that the remaining limit is "a handle the engine never opened" matches the comment rewrite in transactionCoversDriverFor.

Pins and ablations. All four ruled pins are present: the split-layout ledger rows, single-datasource parity, the cross-datasource refusal on insert, update and delete, and the #34998 roll-up child stall bound.

Battery and gates at this head (report 6969444494).

  • The full dogfood battery, with no shard and no path filter, is owed for ! + (narrowing) and is pinned to 1ea3deab98: 480 files / 4075 tests passed, exit 0, and the new dogfood pin ran in it.
  • Full build 120/120 passed. dispatch-gates: 82 derived, 82 run, 0 NOT-MEASURED. objectql passed 610 files / 13732 tests.
  • None of the four PR files writes after the response, so no queue-only dogfood case is at risk.

CI at this head, read from check-runs (59): no failure and nothing in progress. Lint & Repo Gates, TypeScript Type Check, Build Core, all 10 Test Core shards and their aggregate, every Lint · and Type Check · lane, Live E2E UI, Check Changeset (re-run after the body edit), PR-body guards, Governed Surface Queue Guard and Spec property liveness are green. The UI lanes are skipped by path filter.

Notes

  • N1. The report's out_of_scope_findings lists a driver-sqlite-wasm Schema sync FAILED for object showcase_invoice (non-constant strftime default), seen in the dogfood battery logs, as "noted, not filed". It is unrelated to this diff. The area decides whether it is a card.
  • Owed after L1, not mine. The narrowing L2 at CONTRACT_REVIEW_TIER (ADR text plus the narrowed gate), which the area is running. Then, for Tier H, os-zhuang's APPROVED review on the current head, requested by the seat. Nothing is readied, armed or enqueued while the release freeze holds.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#1 · os-warren · session_01JQwxbXKtHccbeakAgquNs9

L1 review, M1 re-read (#35028) · 2026-11-18T04:58Z

L1: ACCEPT
Head-sha: 1ea3dea

The head is unchanged since my REWORK 6969498926, so I re-read only the body line that M1 named.

M1, closed. The body now reads Skills-docs: follow-up #35117 (the api.transaction row: one datasource per body transaction; a write to an object on another datasource is refused). Card #35117 is open. It names skills/objectstack-data/references/data-hooks.md, the api.transaction row with the anchor one driver transaction. Its done-when line states one datasource per body transaction and the refusal with 400 ERR_CROSS_DATASOURCE_TRANSACTION_WRITE, and it is sequenced after this PR merges. That matches the narrowing this PR ships.

Everything in 6969498926 stands for this head: route A in the code, scope and the re-claim surface, the changeset sentences, the add-only ADR-0119 note, the four ruled pins with their ablations, the full dogfood battery pinned to this head, CI, and no freeze flag.

Must-fix

None.

Should-fix

None.

Notes

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#1 · os-warren · session_01JQwxbXGvw43spR79ztEvWt

Contract review

Served-tier: CONTRACT_REVIEW_TIER
Head-sha: 1ea3deab98f4bd87cad11e6acfa28355b5766ee1
Local-runs: none
Scope: packages/objectql/src/engine-scoped-context.ts, packages/objectql/src/engine-execute-transactions.ts, packages/objectql/src/engine-middleware-and-context.ts, packages/objectql/src/engine.ts, packages/objectql/src/engine-insert.ts, packages/objectql/src/engine-update.ts, packages/objectql/src/engine-delete-and-aggregate.ts, packages/objectql/src/engine-transaction-same-origin.test.ts, packages/qa/dogfood/test/action-body-transaction-audit-split.dogfood.test.ts, packages/runtime/src/sandbox/action-body-transaction-rollup-child.integration.test.ts + packages/objectql/src/engine-driver-options.ts, packages/objectql/src/engine-transactions-section.ts, packages/objectql/src/engine-secrets-and-routing.ts, packages/objectql/src/engine-secret-internal-fields.ts, packages/objectql/src/engine-top-level.ts, packages/objectql/src/unit-detach.ts, packages/objectql/src/hook-wrappers.ts, packages/objectql/src/engine-object-repository.ts, packages/objectql/src/engine-defaults-and-autonumbers.ts, packages/objectql/src/engine-cascade-planning.ts, packages/objectql/src/transaction-errors.ts, packages/objectql/tsup.config.ts, packages/runtime/src/sandbox/quickjs-runner.ts, packages/spec/src/contracts/objectql-engine.ts, packages/spec/src/api/error-code-ledger.zod.ts, skills/objectstack-data/references/data-hooks.md (all read, not reviewed); the Tier H note in docs/adr/0119-plugin-reachable-transactions-and-honest-atomic-batch.md and the changeset were judged for agreement with the code.

Inputs read: card #35028 (body and all 8 comments), PR #35102 (body, 12-file list, 3 comments, net diff against main), and the 59 check-runs on the head: none failed; every run that executed concluded success (Lint and Repo Gates, TypeScript Type Check, Build Core, Test Core 10 of 10 shards, Dogfood Regression Gate, Live E2E UI, Test UI, Check Changeset, PR-body guards, Governed Surface Queue Guard, Spec property liveness); the rest are path-filter skips. Those conclusions are taken as the gate verdicts. The live-pg cell of the new runtime file is describe.skipIf without OS_TEST_POSTGRES_URL, so no check-run measured it; the dev's local run is its only evidence.

① Derived judgments

Every accept-set and public-surface change the diff implies, read off the tree:

  1. A business insert / update / delete under an open trio handle, on an object whose driver is not the handle's owner: was accepted and run on the owner's connection, now refused with CrossDatasourceTransactionWriteError before any hook (engine-execute-transactions.ts:302-312). RIGHT, and it is the declared narrowing. All repository write verbs funnel through these three engine verbs (engine-object-repository.ts), so there is no un-gated sibling door the trio reaches.
  2. A system-ledger write (lifecycle.class audit / telemetry / event) under a trio handle, routed off the owner: was handed the owner's handle, now carved out and written with no handle on its own connection (engine-middleware-and-context.ts:445 through engine-driver-options.ts:317). RIGHT. The lifecycle routing step and the carve-out read the same SYSTEM_LEDGER_LIFECYCLE_CLASSES tuple (engine-secrets-and-routing.ts:180-185, 243-250), so every object the telemetry split moves is carved out; none is refused.
  3. A READ under a trio handle of an object on another datasource: was handed the foreign handle, now runs with none. RIGHT, a repair the PR body does not list. Its one refusing consequence: a lockRows: true read of such an object inside a trio transaction now answers LockRowsRefusedError (no-transaction, engine-driver-options.ts:367-374) where it used to run on the wrong connection. RIGHT, the same answer transaction(cb) gives; undeclared but inside the declared narrowing's own reason.
  4. A trio rollback on a split deployment keeps the ledger rows (orphan rows). RIGHT, the 2026-08-06 ruling applied; the single-datasource layout still rolls them back (identity match at :308), pinned.
  5. A handle the trio closed is forgotten and is judged again as an unattributed handle. Consistent with the diff's own pin; see N2.
  6. Public surface: no new export from the package entries (the three trio helpers are module-internal; neither src/index.ts nor src/core.ts names them), enforceTransactionOrigin is a private method gaining one optional parameter, no IDataDriver or packages/spec path in the diff, and no new error code: ERR_CROSS_DATASOURCE_TRANSACTION_WRITE is already registered on main (packages/spec/src/api/error-code-ledger.zod.ts:876). RIGHT.
  7. One derived change is WRONG: a write that is not in the trio's transaction is refused as if it were. See S1.

② Semver level

@objectstack/objectql: patch with Clause-②: yes (narrowing), Metadata-protocol: none, a BREAKING banner, the FROM/TO and the one-line fix in the body, and an ADR-0087 marker (not-required (no-migration-prescription)): this is what AGENTS.md prescribes for a breaking non-protocol change (kind none takes patch and keeps its banner and disposition). Metadata-protocol: none is right: nothing an author can write is added, refused or re-read. Clause-②: yes (narrowing) is right: a call that was accepted is now refused on a published error code. The code is registered and unchanged, so the ERROR_CODE_LEDGER / StandardErrorCode surface does not move. The PR-body line and the changeset line agree. Check Changeset concluded success. No finding.

③ Boundary flags

  • Four one-line call-site edits outside the claim's file surface (engine.ts, engine-insert.ts, engine-update.ts, engine-delete-and-aggregate.ts): answered, accepted. Route A cannot work without them: the gate has no other way to see the explicit handle, and the three engine host closures forward the fourth argument by spread.
  • The optional plugin-audit fix-text was not written: answered, accepted. The claim made it optional, and the platform's own trio no longer produces that third cause.
  • The live-pg cell is local-only evidence (skipped in CI): answered. The mechanism it covers is driver-agnostic and is pinned on SQLite in three suites that CI did run; not a finding, recorded so nobody reads the check-runs as having measured it.
  • Orphan row on a rolled-back body transaction (acceptance note): answered, it is the 2026-08-06 ruling.
  • Skills-docs: follow-up owed (skills/objectstack-data/references/data-hooks.md:334): ESCALATED to the seat, still to be filed. The row today promises "one driver transaction", which this PR makes true; the missing sentence is the refusal.
  • open_questions: the os-dev report carries an empty list; nothing to answer.
  • out_of_scope_findings (the showcase_invoice schema-sync ERROR on driver-sqlite-wasm seen in the battery log, carrier none): ESCALATED to the seat for triage; unrelated to this diff.
  • Docs Drift advisory (content/docs/data-modeling/virtual-objects.mdx): read, a false row; line 190 is a virtual driver's beginTransaction: notSupported(...) stub and states nothing this diff moves.
  • SQL push-down: the diff adds no query, no id materialisation and no in-app join. Clean.

④ Design judgment

The narrowing against the published spec on main. packages/spec/src/contracts/objectql-engine.ts:599-630 declares that a transaction covers ONE datasource, that cross-driver atomicity is not provided, that a business write routed elsewhere is REFUSED and that a system ledger is carved out; the authoring skill promises "one driver transaction" for api.transaction. Nothing published declares that a body transaction may write a second datasource. What the trio did on main was hand the owner's handle to a driver that does not own it (a statement on the wrong connection, and on Postgres a COMMIT turned into a rollback behind a 200). So the change takes no declared capability away at the consumer: it makes the spec's own refusal real on the one transaction door that had been exempted, and that exemption was a recorded LIMIT of ADR-0119, never a capability. The seat ruled route A (6965031920). Judged sound in the large.

Attempts to break it, and what the tree answers:

  • Nested trio / trio under an ambient unit: beginTransaction joins an ambient transaction and records nothing, so the store's scope answers; two trio handles are two keys. The sandbox refuses a nested ctx.api.transaction itself. Holds.
  • Ambient scope preferred over the explicit handle in enforceTransactionOrigin while transactionCoversDriverFor prefers the explicit handle: both transaction doors open on the default driver only, so the two readings name the same owner. Holds.
  • Two datasources sharing one driver instance: the comparison is driver identity, so such a write rides the handle and is not refused. Correct.
  • WeakMap lifetime: weak on the handle; the scope holds the driver strongly but lives no longer than the handle; forgotten in finally on both close paths, also when the driver call throws and when no driver resolves. On commit the forget runs before settleTrioCommitQueue(handle, true), so the queued async after-write runs start with no record. Holds.
  • Module-level state under a two-entry, no-splitting build (tsup.config.ts: index and core each carry their own copy of the map) and under the dual esm/cjs build: an engine and the ScopedContext it derives always come from one copy, nothing outside the package constructs a ScopedContext, and the dogfood pin runs against the built output. Holds; the same pattern as trioQueues in unit-detach.ts.
  • The audit write path: api.sudo() keeps the handle, the gate carves the ledger out, buildDriverOptions withholds the handle. Pinned at three levels (engine double, knex better-sqlite3, booted stack with the real AuditPlugin through /actions).

Findings:

S1 (should-fix) — the gate judges a handle the current run was DETACHED from. enforceTransactionOrigin now reads the trio record for the raw options.context.transaction (engine-execute-transactions.ts:302), while the structural half first discards a closed or detached handle (engine-driver-options.ts:303-306, isClosedUnitHandle, which answers true for isDetachedUnitHandle). An async: true afterFind hook starts at dispatch, outside every open unit (unit-detach.ts:86-98, 104-109; hook-wrappers.ts:540), and its ctx.api still carries the handle of the read that fired it (engine-scoped-context.ts:171-180, engine-defaults-and-autonumbers.ts:205-212). So when a read inside a body's ctx.api.transaction fires such a hook and the hook writes a business object on another datasource, the two halves disagree: buildDriverOptions says the write is in no transaction and would run it on its own connection, and the gate refuses it with CrossDatasourceTransactionWriteError because the trio record is still live. On main that write lands; inside transaction(cb) it lands too, because the detached run has left txStore. That is a refusal outside the declared narrowing ("inside a transaction"), against the contract unit-detach.ts states for a detached run ("the hook's writes then run on their own connection, as they would outside any unit"), and it falsifies the ADR note's "exactly the 2026-08-06 answers". Reach is narrow (a second datasource, an async afterFind hook that writes across it, a read made inside a body transaction) and the loss is named in the hook's error policy rather than silent, hence should-fix and not must-fix. Fix: attribute the explicit handle only when isClosedUnitHandle does not answer true for it (the reading buildDriverOptions and the secret-row release already take), and pin it: an async afterFind hook's cross-datasource business write under an open trio handle lands and is not refused. Read from the code; not run.

N1 (nit) — the ADR note says a trio handle's owner "is known at that moment" without the one exception the code's own comment records: a primitive handle cannot key the map and stays unattributed (engine-execute-transactions.ts:80-85). No in-tree driver returns one (driver-sql, driver-memory, driver-mongodb, driver-turso all return objects), so nothing shipped is affected; a half-sentence in the note would make it agree with the code.

N2 (nit) — a CLOSED trio handle reverts to "unattributed" rather than to "closed". After commit or rollback the record is dropped, so a late write that still carries the handle to another datasource is handed the dead foreign handle again, and the new case "forgets the owner once the trio commits" pins exactly that delivery. A closed transaction() unit's handle is instead treated as absent and its late work runs unenrolled (#22855, isClosedUnitHandle). This is the pre-PR behaviour for trio handles, unchanged by the diff and outside the card, and the ADR note's "a handle the engine never opened" does not quite cover it. Worth a follow-up card (mark the trio handle closed instead of forgetting it), not a change here.

No must-fix. One should-fix (S1), which earns a delta review of its fix; N1 and N2 need no round.

Implemented-by: claude/issue-35028-audit-write-in-action-tx
Reviewed-by: session_01JQwxbXGvw43spR79ztEvWt

VERDICT: PASS

…run was detached from

An `async: true` `afterFind` run starts outside every open unit and its
`ctx.api` still carries the trio handle; `buildDriverOptions` already treats
that handle as absent (`isClosedUnitHandle`). `enforceTransactionOrigin` now
reads it the same way before consulting the trio record, so such a run's
cross-datasource business write lands on its own connection instead of being
refused. Pinned beside the trio cases.

Claude-Session: https://claude.ai/code/session_01JQwxbXGvw43spR79ztEvWt
Co-authored-by: Claude <noreply@anthropic.com>
Add-only paragraph under the 2026-11-18 note: a handle an async hook's run
was detached from is read as closed by the gate, and a primitive handle
stays unattributed. The changeset says the same for the detached run.

Claude-Session: https://claude.ai/code/session_01JQwxbXGvw43spR79ztEvWt
Co-authored-by: Claude <noreply@anthropic.com>
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#1 · os-warren · session_01JQwxbXGvw43spR79ztEvWt

Contract-review-claim: session_01JQwxbXGvw43spR79ztEvWt · head 91960c4f5ad4d3aae7b5b846160ef01394140c06 · 2026-11-18T07:37Z

Delta contract review 1ea3deab..91960c4f closing S1 of 6969574094.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#1 · os-warren · session_01JQwxbXKtHccbeakAgquNs9

L1 review, delta for contract-review S1 (#35028) · 2026-11-18T07:38Z

L1: ACCEPT
Head-sha: 91960c4
Delta read: 1ea3dea → 91960c4 (fe13609 fix, 91960c4 ADR note), 5 files, +56 / −4.

S1 of contract review 6969574094, closed in code. enforceTransactionOrigin now drops an explicit handle for which isClosedUnitHandle answers true before it reads the trio record (engine-execute-transactions.ts:306). That is the same predicate and the same shape that buildDriverOptions (engine-driver-options.ts:304), the secret-row release (engine-secret-internal-fields.ts:480) and writeTransactionOf already use, so the gate and the structural half now agree on what "in a transaction" means for a detached run. The host closure in engine.ts forwards the predicate. The rest of route A is unchanged.

The pin targets the right case. A write event's async run under the trio waits for the trio to settle (openTrioCommitQueue), by which point the record is already dropped. Only an async afterFind run starts at dispatch while the trio handle is still live (unit-detach.ts). The new case is that one: the write lands on the ledger datasource with no transaction, while the trio is still open, and the trio then commits. os-dev report 6972198231 records the disproof on 1ea3dea first (the same CrossDatasourceTransactionWriteError). It also records ablation E on the new anchor (only the new pin goes red, with that refusal) and the restore (blob equals HEAD, empty diff).

The changeset and ADR delta match the code. The added changeset sentence describes the detached run as unjudged, with writes outside any transaction "as under transaction(cb)". That matches the code and unit-detach.ts's stated contract. The changeset file is not on main. Clause-②: yes (narrowing) is unchanged and still right, because the fix only shrinks the refusal. The ADR-0119 paragraph is add-only, and its two bounds are the detached run and nit N1's primitive handle; both agree with the code. The body drops the Skills-docs bullet from ## Still owed (seat) per my N2, and it carries the N2 follow-up card as the seat's.

CI at this head. 39 success, 18 skipped, and Test Core (7/10) re-running (job 134651728591). The first attempt failed at plugin-security org-admin-assignment-boundary.posture.test.ts:1153 with a 5000 ms timeout. That is the known flake tracked on #35111, and the diff touches no plugin-security path. The run must be green before landing; this L1 does not waive it.

Must-fix

None.

Should-fix

None.

Notes

  • Owed after L1, not mine. The delta contract review of this fix at CONTRACT_REVIEW_TIER (running in parallel). For Tier H, os-zhuang's APPROVED review on this head (the seat). The contract review's N2 follow-up card (the seat).

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#1 · os-warren · session_01JQwxbXGvw43spR79ztEvWt

Contract review

Served-tier: CONTRACT_REVIEW_TIER
Head-sha: 91960c4f5ad4d3aae7b5b846160ef01394140c06
Local-runs: none
Scope: packages/objectql/src/engine-execute-transactions.ts, packages/objectql/src/engine.ts, packages/objectql/src/engine-transaction-same-origin.test.ts + packages/objectql/src/engine-driver-options.ts, packages/objectql/src/engine-transactions-section.ts, packages/objectql/src/unit-detach.ts, packages/objectql/src/hook-wrappers.ts, packages/objectql/src/engine-scoped-context.ts, packages/objectql/src/engine-middleware-and-context.ts, packages/objectql/src/engine-secret-internal-fields.ts, packages/objectql/src/engine-summaries-and-expansion.ts, packages/objectql/src/engine-hooks-and-functions.ts, packages/objectql/src/engine-insert.ts, packages/objectql/src/engine-update.ts, packages/objectql/src/engine-delete-and-aggregate.ts, packages/drivers/driver-memory/src/memory-driver.ts, packages/drivers/driver-sql/src/sql-driver-transactions.ts, packages/drivers/driver-mongodb/src/mongodb-driver.ts, packages/drivers/driver-turso/src/turso-driver.ts, packages/drivers/driver-odata/src/odata-driver.ts (all read, not reviewed); the added paragraph of the Tier H note in docs/adr/0119-plugin-reachable-transactions-and-honest-atomic-batch.md and the added sentence of .changeset/35028-trio-handle-owner.md were judged for agreement with the code.

This is a DELTA record: 1ea3deab98f4bd87cad11e6acfa28355b5766ee1..91960c4f5ad4d3aae7b5b846160ef01394140c06 (2 commits, 5 files, +56 / -4), closing S1 of record 6969574094, which PASSed 1ea3deab98 and whose judgments on the rest of the diff stand. The net diff against main (merge base b85dff0f43, 12 files, +758 / -35) was re-read for the paths the delta touches.

Inputs read: card #35028 (body and all 10 comments, among them the route A reading 6964984927, the claim amendment 6965031920 and the os-dev reports 6969444494 and 6972198231), PR #35102 (body, 12-file list, all 8 comments, among them record 6969574094 and the L1-a ACCEPTs 6969533256 and 6972259586; no review and no inline comment exists), and the 58 check-runs on the head, read at 07:42Z: 39 success, 18 skipped (path filters and matrix placeholders), 1 in_progress. Concluded success: Lint and Repo Gates, TypeScript Type Check, Build Core, Test Core shards 1 to 6 and 8 to 10, Dogfood Regression Gate, Live E2E UI, Test UI, Check Changeset, PR-body guards, Governed Surface Queue Guard, Spec property liveness. Test Core (7/10) (job 134651728591) is in_progress, a re-run, and so the Test Core aggregate has no conclusion on this head yet. The os-dev report gives the first attempt's failure as plugin-security src/org-admin-assignment-boundary.posture.test.ts:1153, a 5000 ms timeout tracked on #35111; no plugin-security path is in this diff. That shard is NOT a gate verdict yet: this record does not waive it, and it must conclude success before the PR lands. The new pin lives in packages/objectql, whose suite the dev ran whole on this head (610 files, 13733 tests, exit 0).

① Derived judgments

The accept-set changes the delta implies, read off the tree:

  1. Against 1ea3deab98: a business insert / update / delete whose explicit handle is a trio handle the current run was DETACHED from, with no ambient scope, on an object whose driver is not the handle's owner. Was refused with CrossDatasourceTransactionWriteError; now accepted, and buildDriverOptions runs it with no handle, on its own connection. RIGHT. It is the only input whose answer moves: the new guard changes the result only where isClosedUnitHandle answers true AND a trio record exists for the handle AND the store holds no scope. A trio handle is never published through runOpenedUnit, so it is never in openedUnits; the first clause can therefore be true for it only through isDetachedUnitHandle (engine-transactions-section.ts:186-191). A closed transaction() unit's handle never had a trio record, so its answer is the same at both heads.
  2. Against main: for that same input main has no trio record, the gate steps aside, and buildDriverOptions already discards the detached handle. The write lands on its own connection with no handle. The head gives the identical answer, so the detached run is unchanged from main and the PR's net narrowing is back to exactly what it declares: writes made INSIDE the trio's transaction.
  3. A system-ledger write from the same detached run: at 1ea3deab98 it took the carve-out branch (one debug line, the datasource added to the scope's reportedOutOfScope); now the gate returns before that. The row is written with no handle on its own connection at both heads. RIGHT, no accept-set change; the debug line was describing a transaction the run is not in.
  4. Everything still enrolled is judged as before: a blocking hook's write, the body's own write, and a run whose ctx.api cannot detach (runDetachedHook runs it as is) carry a handle for which isClosedUnitHandle answers false, so the trio record still answers and a cross-datasource business write is still refused. RIGHT, the declared narrowing.
  5. Public surface: none moves. enforceTransactionOrigin is a private method; its host type gains one member that names an existing private method; ExecuteTransactionsHost is not named by src/index.ts or src/core.ts. No IDataDriver, packages/spec or error-code path is in the delta. TypeScript Type Check concluded success, so every host object that is typed against the widened interface supplies the member.

② Semver level

Unchanged and still right. @objectstack/objectql: patch with Clause-②: yes (narrowing), Metadata-protocol: none, the BREAKING banner and the ADR-0087 not-required (no-migration-prescription) marker. The delta only shrinks the refusal back to the declared one, so it adds no narrowing and needs no second line; nothing an author can write is added, refused or re-read, so Metadata-protocol: none holds. The PR-body line and the changeset line agree word for word on the narrowing. The changeset file is not on main, so the edit to it is the PR's own text. Its added sentence ("An async: true hook's run, detached from the units open at its dispatch, is not judged against that record: its writes run outside any transaction, as they do under transaction(cb)") agrees with engine-execute-transactions.ts:306-309 and with the contract unit-detach.ts states for a detached run. Check Changeset concluded success (both runs). No finding.

③ Boundary flags

  • open_questions (report 6972198231): empty. Nothing to answer.
  • out_of_scope_findings (6972198231): empty. The earlier report's showcase_invoice schema-sync line was escalated to the seat by record 6969574094 and is not re-raised here.
  • N2 of record 6969574094 (a closed trio handle reverts to unattributed, not to closed) is "not touched (seat files it)": answered, accepted. The delta does not change it: after commit or rollback the record is dropped, isClosedUnitHandle answers false for the trio handle, and both halves decline to judge, as at 1ea3deab98 and on main. The follow-up card is still OWED by the seat; the PR body lists it under Still owed.
  • Skills-docs: follow-up #35117: filed since the last record (L1-a 6969533256 read it). The delta adds nothing the row must say: the detached run restores the pre-PR answer.
  • Docs Drift advisory, recomputed on this head (two rows). content/docs/data-modeling/virtual-objects.mdx: the false row record 6969574094 answered. content/docs/permissions/system-context.mdx, listed for the literal isSystemLedgerObject on the host-type line the delta edited: read, a false row. Line 373 names the helper in a paragraph about how sites are counted and states nothing about transactions or datasource routing.
  • CI: Test Core (7/10) in progress, stated above. Not waived.
  • SQL push-down: the delta adds no query, no id materialisation and no in-app join. Clean.

④ Design judgment

S1 as graded: the gate read the trio record for the raw options.context.transaction while the structural half first discards a closed or detached handle. The fix makes the gate take the reading buildDriverOptions takes: the same predicate (isClosedUnitHandle), on the same value (the three write verbs pass options?.context?.transaction, which is the execCtx.transaction that buildDriverOptions reads), in the same expression shape as engine-driver-options.ts:303-306, engine-secret-internal-fields.ts:480, writeTransactionOf and opensAfterAbortUnit. The private wrapper in engine.ts forwards the engine's own predicate. So the gate attributes a trio handle exactly when the structural half would hand that handle on, and the disagreement S1 named cannot arise from this input again. The narrowing judged against the published spec on main is as record 6969574094 found it; the delta removes the one refusal that fell outside it.

Attempts to break the guard, and what the tree answers:

  • A handle closed by commit and then reused: the record is forgotten in finally, isClosedUnitHandle is false (never in openedUnits), and the handle is judged as unattributed by both halves. This is N2, unchanged by the delta in either direction.
  • A nested trio: the second beginTransaction finds no ambient unit, opens its own handle on the default driver and records it under its own key. A hook dispatched under the inner context is detached from the handle its api carries; a write still carrying the outer handle is live and judged. Both handles name the same owner. A trio begun inside a detached run is a new handle, not in the run's detached set, and is judged. Holds.
  • A unit the detached run opens itself with transaction(cb): the store's scope answers first and judges it; buildDriverOptions discards the detached handle and takes the store's handle. Same owner (both doors open on the default driver). Holds.
  • A detached run whose handler is synchronous, or does not await its writes: runOutsideOpenUnits runs the body inside detachedHandles.run, and the writes it starts inherit that async context, so the gate and buildDriverOptions both read the handle as detached. A blocking hook is not detached and is judged, as inside transaction(cb). Wherever the async context could be lost, it is lost for both halves at once, because they ask one predicate; they still agree.
  • A write event's async run under the trio: queued on the trio's commit queue. Commit forgets the record before settleTrioCommitQueue(handle, true), rollback drops the runs before the driver call. Such a run never meets a live record, which is why only afterFind reaches S1, and the pin targets it.
  • A handle that is closed while its owner record lingers in the WeakMap: needs a handle object that is both in openedUnits with its unit settled and in the trio map, which takes a driver that hands the same handle object out twice. No in-tree driver does (driver-sql a new knex transaction, driver-memory a new object, driver-mongodb a new session; driver-turso remote and driver-odata refuse). On such a driver the structural half already ran the trio's writes with no handle (objectql: ScopedContext.transaction() publishes an ambient transaction entry it never closes, so an async hook's later write inside it is lost ("Transaction query already complete") #22855, outside this diff); the gate now reads it the same way, where at 1ea3deab98 it refused. The other lingering case, a trio nobody commits or rolls back, is an open transaction and is rightly judged as one; the map is weak on the handle.
  • A primitive handle: never recorded, so trioTransactionScopeOf answers undefined whether or not the guard keeps it; isDetachedUnitHandle handles primitives; a null handle passes the guard and is unattributed. Unjudged, as on main.
  • Two datasources sharing one driver instance: the comparison after the guard is still driver identity, so such a write rides the handle and is not refused. Unchanged.

The pin (engine-transaction-same-origin.test.ts, "lets an async afterFind run, detached from the open trio handle, write a business object on another datasource") is the S1 scenario: a metadata-bound async: true afterFind hook, a read under an open trio handle, a business insert on the other datasource, asserted stored while the trio is still open, then one write on ledger_db with no transaction. It cannot pass vacuously: a hook that never fires leaves the outcome promise pending and the case times out. The dev's report gives it red on 1ea3deab98 with the refusal S1 predicted, and red again under ablation E with the restore proven.

ADR-0119, the added paragraph (Tier H governed text): add-only, placed under the dated 2026-11-18 note, nothing above it rewritten. Its first bound agrees with the code: an async: true run starts outside every unit open at its dispatch while its ctx.api carries the handle (unit-detach.ts, hook-wrappers.ts:540), and the gate reads the handle as buildDriverOptions does. Its second bound is N1 folded in: the record is keyed by the handle object (recordTrioTransactionScope skips a primitive), and "no in-tree driver does" is true of every beginTransaction in packages/drivers. The paragraph bounds the phrase "exactly the 2026-08-06 answers" instead of rewording it, which keeps the note add-only. Agrees with the code.

S1: closed.
N1: closed (folded into the ADR-0119 paragraph).
N2: unchanged, carried; the seat's follow-up card is still owed and blocks nothing here.

No must-fix, no should-fix.

Implemented-by: claude/issue-35028-audit-write-in-action-tx
Reviewed-by: session_01JQwxbXGvw43spR79ztEvWt

VERDICT: PASS

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#1 · os-warren · session_01JQwxbabAdcWyApSTGBYJNY

Seat record · 2026-11-18T07:45Z · Head-sha: 91960c4

维护者速读

  • 改了什么:沙箱 ctx.api.transaction 打开的事务句柄,现在在开启时记下归属的驱动;同源闸门据此判断:审计行和动态行写到 telemetry 库自己的连接,跨数据源的业务写入被拒(400,ERR_CROSS_DATASOURCE_TRANSACTION_WRITE)。ADR-0119 只追加一段带日期的说明。
  • 为什么改:有 telemetry 数据源时(每个 os dev,以及带 OS_TELEMETRY_DB 的 os serve),动作体事务里的写入会丢掉审计行和动态行,接口仍回 200(reading first: the platform's own audit write inside an action body's ctx.api.transaction logs 'Audit write FAILED on sys_audit_log (no such table)' on 18.5.0 and main #35028,读数 6964984927)。
  • 风险与回滚:动作体事务里写另一个数据源上的业务对象,从「写错连接」变为 400 拒绝(BREAKING,收窄);单数据源部署不变。回滚即 revert 本 PR。
  • 先看:packages/objectql/src/engine-scoped-context.ts(开启时记录、提交/回滚时清除)、packages/objectql/src/engine-execute-transactions.ts(enforceTransactionOrigin)、docs/adr/ 中 ADR-0119 新增的说明。
  • 两分钟验证:pnpm --filter @objectstack/objectql exec vitest run --maxWorkers=2 src/engine-transaction-same-origin.test.ts,预期 29 个用例全绿。
  • 需要你做的:用 os-zhuang 审读并批准本 PR(改了 docs/adr/**,Tier H)。L1-a ACCEPT 6972259586,契约复审 PASS 6972358126(CONTRACT_REVIEW_TIER),均钉在 Head-sha 91960c4f5ad4d3aae7b5b846160ef01394140c06。批准在案且 CI 全绿后由席位落地。

席位意见:同意合并。修的是真实的数据丢失(审计行静默丢失),收窄只影响「一个事务里写两个数据源」这种本来就写错连接的用法,并有明确报错。

席位核对

  1. 形态:12 个文件,+758/−35,Fixes #35028;Clause-②: yes (narrowing),Metadata-protocol: none,Skills-docs: 跟进卡 skills: data-hooks api.transaction row should say a body transaction is one datasource and a cross-datasource write is refused (follow-up of #35102) #35117;changeset 带 ADR-0087 处置(not-required)。
  2. 前提实测:读数 6964984927 在 origin/main 上测出 trio 句柄不进 txStore、两道同源闸门都让开;dev 报告 6972198231 记 82/82 门禁、objectql 13,733 个测试、dogfood battery 4,075 通过(收窄落地所需)。
  3. 门禁 check-runs:head 91960c4f 上 39 成功、18 跳过、0 红,另 1 条 Test Core (7/10) 重跑中(已知偶发 Flaky: plugin-security org-admin-assignment-boundary posture test times out at 5000 ms on a loaded CI runner #35111,diff 不碰 plugin-security);落地前须为成功。check-governed-merges --pr 35102:12 个路径中 1 个命中受管面(docs/adr/**),Tier H。
  4. 接受的偏差:认领文件面外 4 处一行改动(engine.ts、engine-insert.ts、engine-update.ts、engine-delete-and-aggregate.ts),为让闸门看到显式句柄所必需,正文已列明。plugin-audit 的提示文字未改(本修复后不再出现该第三种原因)。复审 S1、N1 已闭,无必改项。
  5. 范围外去向:N2(已关闭的 trio 句柄回落为未归属而非已关闭)立卡 objectql: a committed trio handle reverts to unattributed instead of closed #35149;技能文档跟进 skills: data-hooks api.transaction row should say a body transaction is one datasource and a cross-datasource write is refused (follow-up of #35102) #35117;sudo() 的 'action' 提权标记问题仍归 plugin-security: platform sudo() keeps the action body's action mark, so the platform's own audit and activity inserts are judged as app inserts and would be refused once the announced system-identity write refusal ships #35052,本 PR 不碰。
  6. 落地条款:Tier H,等 os-zhuang 的 APPROVED 审核在案于本 head(或其后仅合 main 的 head),且 Test Core 重跑成功,再由席位翻 ready、经合并队列落地;head 若有内容变动则撤挂回等。

@objectstack-fleet objectstack-fleet Bot added the pm:awaiting-merge PR only: landing waits on the maintainer's own review and merge (SKILL.md 复核 ②); never on an issue label Nov 18, 2026
@os-zhuang
os-zhuang marked this pull request as ready for review November 18, 2026 07:52
@os-zhuang
os-zhuang enabled auto-merge November 18, 2026 07:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation pm:awaiting-merge PR only: landing waits on the maintainer's own review and merge (SKILL.md 复核 ②); never on an issue size/l tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

3 participants