Skip to content

fix(objectql): insert and delete open their after-abort unit inside the middleware chain, as update does - #35386

Merged
objectstack-fleet[bot] merged 7 commits into
mainfrom
claude/issue-35167-unit-inside-middleware
Nov 19, 2026
Merged

objectstack-fleet[bot] merged 7 commits into
mainfrom
claude/issue-35167-unit-inside-middleware

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Fixes #35167

Clause-②: no
Metadata-protocol: none

维护者速读

  1. 用户能看到什么变化:给对象绑了会写数据的前置钩子或会拦截的后置钩子之后,新增和删除在单连接数据库(SQLite)上不再让别人的写入排在权限检查后面等待,三个动词(新增、修改、删除)的事务边界从此是同一条规则。
  2. 为什么做:上一轮「抢领记录输家答错」的修复只改了修改,你选了「三个动词一条规则」,这一单把新增和删除补齐。
  3. 出错会怎样:受影响的只有绑了这类钩子的对象;最坏情况是某个插件在写入之后做的收尾工作不再和这一行同进同退(与没绑钩子的对象一致),回滚这一个 PR 即可恢复。
  4. 要你做什么:无,席位落地。

席位核对

What changes

  • insert (packages/objectql/src/engine-insert.ts) and delete (packages/objectql/src/engine-delete-and-aggregate.ts) no longer re-enter their own door inside inAfterAbortUnit. Each computes opensAfterAbortUnit once at the door and wraps only the executor it hands executeWithMiddleware (inOwnUnit), the shape engine-update.ts has used since fix(objectql): the loser of a concurrent update answers 409 again on an object with a metadata beforeUpdate hook #35165. The middleware chain (the authorization gate's reads, and any post-next() work) runs outside the unit; the before* hooks' ctx.api writes, the row and the after* chain run inside it. Nothing between the door and the executor writes (insert: normalisation and opCtx; delete: option folding, withResolvedWhere, and the in-memory cascade claim).
  • The now-unread 'insert' / 'delete' members leave the two facets' this Picks.
  • The three prose places now state one rule: engine-hook-dispatch.ts (inAfterAbortUnit docblock), engine-top-level.ts (the four paths that open a unit around the after* dispatch), engine-middleware-and-context.ts (claimReferentialCascadeDelete: no delete() re-enters itself).
  • scripts/measure-durability-swallow-family.mjs: the resolution control pinned on the delete door's this.delete(...) re-entry matched no call site once that re-entry was gone (check:swallow-census-controls red, "A control that matches nothing passes VACUOUSLY"). It is re-pointed at the same facet-stub shape on insertMany's this.insert(...) in InsertFacet. This file is outside the claim's file surface; see Acceptance notes.
  • Changeset: @objectstack/objectql patch.

Not changed: the delete loser's false vs RECORD_NOT_FOUND answer and what fires on a driver false (the follow-up card that lands after this PR); after* stays inside the write's unit (#7477).

Tests

Two new files in packages/plugins/plugin-security/src/ (shape of ownership-claim-race-sqlite.test.ts: ObjectQL + SqlDriver on better-sqlite3 :memory: + SecurityPlugin; that package's vitest config aliases @objectstack/objectql and @objectstack/driver-sql to source):

  • insert-unit-inside-middleware-sqlite.test.ts, delete-unit-inside-middleware-sqlite.test.ts. Cells per verb: no metadata hook, a metadata before* hook, only a blocking after* hook. A test middleware parks user A's write after the security gate and before next(); user B's write on another row must settle within 2 s while A is parked. Control per verb: a throwing after* hook (asserted by identity) leaves no inserted row / leaves the deleted row stored.
Ablation, per verb (fix committed first; mutation = the file restored from base 24cc61f, then `git checkout HEAD --` and hash match)
  • insert, engine-insert.ts at base (door re-entry count 1, inOwnUnit 0): Tests 2 failed | 2 passed (4); both hooked cells Expected: "fulfilled" Received: "still waiting"; no-hook cell and control green. Restored: hash match, git diff HEAD empty.
  • delete, engine-delete-and-aggregate.ts at base: Tests 2 failed | 2 passed (4), same two cells red with the same reading; restored, hash match.
  • Control re-point in the census script, mutated with scripts/ablation-replace.mjs (resolvesIn: 'InsertFacet' to 'UpdateFacet', anchor x1 to x0): self-test red, resolution control moved: … expected UpdateFacet, got InsertFacet@307, InsertFacet@1760; restored, hash match.
Suites (final head 155c9e5, after merging origin/main)
  • pnpm --filter @objectstack/objectql typecheck then test: Test Files 614 passed (614), Tests 13878 passed (13878).
  • the two new files plus ownership-claim-race-sqlite.test.ts: Test Files 3 passed (3), Tests 15 passed (15).
  • Before the merge (d5bfdb0 line): @objectstack/plugin-security typecheck exit 0 and test: Test Files 281 passed (281), Tests 6993 passed | 45 skipped.

Acceptance notes

  • File-surface breach, one file: scripts/measure-durability-swallow-family.mjs. Necessary because the change made its control vacuous; the re-point keeps the same resolution shape live rather than deleting the control.
  • Wording only, left as is: engine-transactions-section.ts:161, hook-wrappers.ts:533 and unit-detach.ts:21 call it "the door's own unit". They name the write's own unit and say nothing about where it opens, so they stay true.
  • A middleware that throws after next() on a hooked object no longer rolls the insert or delete back. That already held for update and for every unhooked object; the changeset says so.

Verification

Local gates

node scripts/pm/dispatch-gates.mjs --commands (94 families after the script edit), all run with exit codes captured before any pipe; --ran: 94 derived famil(ies) accounted for — 93 run, 1 NOT-MEASURED (1 DERIVED from a recorded exit 3).

  • NOT MEASURED: node scripts/check-plugin-teardown-shape.mjs --self-test exit 3 (fixture pinned to a commit this clone cannot reach even after --deepen=3000; checker-health only, untouched script).
  • First pass exit 3, then exit 0 after the builds they needed: check:dual-build-cjs-loads, check:i18n, check:type-check-debt (run under the verify lock).
  • check:swallow-census-controls exit 1 at first (the vacuous control above), exit 0 after the re-point.
  • Re-run on the final head 155c9e5: check:swallow-census-controls, check:nul-bytes, check:type-check-coverage, check:test-source-alias, check:cross-package-test-inputs, check-empty-changeset, check-adr-0087-registration, check:issue-citations: all exit 0.
  • overlap-check --branch=HEAD: VERDICT clean exit 0 (origin/main and fix(audit): a search the server widens never names a column the caller may not query #34817 merge cleanly).
  • test:repo and the rest of the farm are left to CI.

Generated by Claude Code

…he middleware chain

Claude-Session: https://claude.ai/code/session_01Utp6Ca1jJvsA1dHsPwMiQb
Co-authored-by: Claude <noreply@anthropic.com>
…rialise writers behind the gate on SQLite

Claude-Session: https://claude.ai/code/session_01Utp6Ca1jJvsA1dHsPwMiQb
Co-authored-by: Claude <noreply@anthropic.com>
…any's this.insert

The delete control matched no call site once delete stopped re-entering itself.

Claude-Session: https://claude.ai/code/session_01Utp6Ca1jJvsA1dHsPwMiQb
Co-authored-by: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added size/m 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 19, 2026
@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 1 package(s): @objectstack/objectql, touching 69 documentable anchor(s). ⚠️ 2 changed file(s) yielded no anchor (packages/objectql/src/engine-hook-dispatch.ts, packages/objectql/src/engine-top-level.ts), so the pages documenting them are NOT COVERED by this run — this is not a clean bill of health for those files.

17 hand-written doc(s) name something this change touched — list omitted above 15 rows. Re-derive on the tree named below: node scripts/docs-audit/affected-docs.mjs --json 6d833b50fbb64ae3f0c83607cfdcaaefd260db77.

⛔ 3 release-owned page(s) also affected — read-only, see AGENTS.md Documentation Guardrails.

What this run could not see
  • 2 changed file(s) yielded no anchor (packages/objectql/src/engine-hook-dispatch.ts, packages/objectql/src/engine-top-level.ts) — pages documenting those are invisible to this run
  • 1 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 6d833b50fbb64ae3f0c83607cfdcaaefd260db77 → packageMentionDocs.

Which tree this was computed on

This run read content/docs from 7dc027acd3cdf310c971678266c8f4e34da97ec7 — the merge of head 30f5259bc6e7fa7657838f5d7cff85e7b5996f19 into base 6d833b50fbb64ae3f0c83607cfdcaaefd260db77, 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 7dc027acd3cdf310c971678266c8f4e34da97ec7 && git checkout 7dc027acd3cdf310c971678266c8f4e34da97ec7
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 6d833b50fbb64ae3f0c83607cfdcaaefd260db77 30f5259bc6e7fa7657838f5d7cff85e7b5996f19 && git checkout -B drift-repro 6d833b50fbb64ae3f0c83607cfdcaaefd260db77 && git merge --no-ff 30f5259bc6e7fa7657838f5d7cff85e7b5996f19

node scripts/docs-audit/affected-docs.mjs --json 6d833b50fbb64ae3f0c83607cfdcaaefd260db77

⚠️ 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 6d833b50fbb64ae3f0c83607cfdcaaefd260db77 → 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#5 · os-bill · session_01Utp6Ca1jJvsA1dHsPwMiQb

Seat judgment: Test Core (7/10) on 155c9e5 is a slow-runner timeout, not this PR. Re-running the failed jobs once (2026-11-19T08:16Z)

  • The only FAIL in the saved log (job 135415542075) is Error: Test timed out in 5000ms. It comes from plugin-security src/org-admin-assignment-boundary.posture.test.ts:1153, posture 'isolated' > auditorDelegate, which took 5534 ms. The other 6992 tests in the package passed.
  • The runner was slow across the board. On this run plugin-security took 926.29s (import 1680.87s) and this file took 178960 ms. On main's last scheduled run (44455704227, job 135330913312) the same package took 430.85s (import 800.60s), the file 81075 ms, and this case 2124 ms. That is about 2.2x slower everywhere, imports included. The suite-ceiling summary on this run also shows 18 packages over their wall ceiling.
  • The code is not slower. In a local A/B on the same tree, swapping only this PR's two engine files against origin/main's, the per-variant cases ran 280–595 ms (PR) against 320–642 ms (main). The file passed 104/104 on this branch.
  • Per the platform-readings rule: one re-run of the failed jobs of run 44481541851. A second failure is treated as real.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#5 · os-bill · session_01Utp6Ca1jJvsA1dHsPwMiQb

Test Core (7/10): the re-run failed again. Measured: not this PR (2026-11-19T09:04Z)

The re-run (attempt 2) timed out on the same file, plugin-security org-admin-assignment-boundary.posture.test.ts:1153 (posture 'isolated': auditorDelegate and orgAdminAuditor, 5000 ms). A second failure is treated as real, so it was measured (dev addendum 7004581195 on #35167):

The case reaches 4.5–4.7 s without this change whenever the shard is loaded. The fix belongs to the test's time budget, not to this diff. Follow-up card: see the next comment on #35167. No timeout is raised in this PR and no test is skipped.

Brings in the posture-test split (#35452) so this PR's Test Core shard can go green.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Utp6Ca1jJvsA1dHsPwMiQb
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#5 · os-bill · session_01Utp6CXsZsKmgG1EcKp5bY4

维护者速读

  • 用户能看到什么变化:给对象绑了写数据的前置钩子或会拦截的后置钩子后,新增和删除在单连接数据库(SQLite)上不再让别人的写入排队等权限检查;新增、修改、删除三个动作的事务边界成为同一条规则。
  • 为什么做:这是你选的"三个动作一条规则",修改已经先做完,这一单补齐新增和删除。
  • 出错会怎样:只影响绑了这类钩子的对象;钩子报错时整笔写入照样回滚。中间件在写入完成之后才做的收尾工作,不再和这一行一起回滚,和没绑钩子的对象一样。
  • 要你做什么:无。区域自行落地。

席位核对

L1-a: ACCEPT · head 30f5259bc6e7fa7657838f5d7cff85e7b5996f19 · Fixes #35167 · 2026-11-19T11:19Z

Scope of this record. The relay asked for a merge-only delta over an earlier verdict on 155c9e54ec. No L1 record exists on this PR or on #35167; the comments are the docs-drift bot and two seat CI judgments, 7003622533 and 7004622123. So this record is a full L1 of the PR's own diff at 155c9e54ec, plus the merge delta.

Merge delta. 30f5259bc6 = merge of main 6d833b50fb into 155c9e54ec. The PR's own diff is byte-identical before and after the merge, checked by diff of git diff merge-base..155c9e54ec against git diff M^2..M. It is main-only, and it brings in #35452, the posture-test split that cleared the Test Core timeout. K=3; merge-tree against main clean; CI 37 success / 16 skipped / 0 failed. Trailers are model-free.

Code (9 files, +408/−36).

  • insert and delete drop their door re-entry, return this.inAfterAbortUnit(() => this.insert|delete(…)). Each now computes ownUnit once and wraps only the executor handed to executeWithMiddleware. This is the same inOwnUnit shape update already ships (engine-update.ts:172-175, :475, 18.6.0 regression: the loser of two concurrent updates on SQLite gets 404 RECORD_NOT_FOUND instead of 409 CONCURRENT_UPDATE #35142), so the three verbs read one rule.
  • inAfterAbortUnit is unchanged. It runs write under this.transaction(…), and the body reaches the unit's transaction through the same ambient path the old re-entry relied on, since that re-entry also passed the caller's options through unchanged.
  • Between the door and the executor nothing writes. The calls there are assertWriteAllowed, the organization-probe drop, enforceTransactionOrigin on the caller's own transaction, withResolvedWhere (a read), and claimReferentialCascadeDelete, an in-memory token. The claim's docblock is corrected to match: no delete() re-enters itself now, so the claiming call is the dispatching call.
  • The Pick<> lists lose 'insert' and 'delete', confirming no self-call is left. The durability-census resolution control moves from the gone this.delete(…) to insertMany's this.insert(…), with the same shape and a reason that says why.

Pins. plugin-security/src/{insert,delete}-unit-inside-middleware-sqlite.test.ts:

  • per hook kind, a second writer lands while the first is parked in the middleware chain;
  • CONTROL: an after* that throws still leaves no row (insert) or keeps the row (delete) on SQLite.

Ablation per verb, with the engine file restored from base: 2 failed / 2 passed, the hooked cells "still waiting", and the controls green throughout. objectql 13878 tests pass.

Declaration: agreed. Clause-②: no / Metadata-protocol: none / @objectstack/objectql patch. Nothing is refused and no authorable key moves. The one observable shift is a middleware's post-next() work running after the commit on a hooked object. The changeset states it, and it matches what every unhooked object and update already do, the same declaration #35142 shipped under.

Routing. Not governed (check-governed-merges --pr 35386), no contract face: data-1 lands it. A new push needs a fresh L1 only if it changes more than a main merge.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#5 · os-bill · session_01Utp6Ca1jJvsA1dHsPwMiQb

Landing · area data-1 · 2026-11-19T11:19Z

reading value
L1-a ACCEPT 7007598740 at 30f5259bc6 (a full L1 of the PR's own diff plus the merge delta)
Head 30f5259bc6: a merge of origin/main 6d833b50fb into 155c9e54ec. It is clean, and the PR's own diff is byte-identical. CI is green on this head.
Earlier red The posture-test timeout (7003622533, 7004622123) was measured not this PR's. Its fix, #35452 (card #35436), is merged and is part of this head.
check-governed-merges --pr 35386 NOT governed; no contract face
Declaration Clause-②: no / Metadata-protocol: none / @objectstack/objectql patch (agreed by L1-a)

State: draft → ready + auto-merge (merge queue). #35167 closes on merge via Fixes. #35329 and #35149 are next in this area once it merges.

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 19, 2026 11:20
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 19, 2026
Merged via the queue into main with commit 43639a6 Nov 19, 2026
54 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/issue-35167-unit-inside-middleware branch November 19, 2026 11:47
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 size/m tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

objectql: insert and delete keep the after-abort unit at the door while update moves it inside the middleware

2 participants