Skip to content

fix(automation): a record-change flow's run history and notification deliveries land when the triggering write runs in a unit of work - #37742

Merged
objectstack-fleet[bot] merged 8 commits into
mainfrom
claude/project-thread-a7kaf6
Nov 27, 2026
Merged

objectstack-fleet[bot] merged 8 commits into
mainfrom
claude/project-thread-a7kaf6

Conversation

@objectstack-fleet

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

Copy link
Copy Markdown
Contributor

Requested by Sales · project thread
Fixes #37705

Clause-②: yes (widening) — ObjectQL is exported from the @objectstack/objectql entry, and it gains two public methods, runOutsideOpenUnits(body) and runAfterOpenUnitsCommit(body); @objectstack/core gains the root export wakeAfterOpenUnitsCommit(engine, wake); the @objectstack/service-automation interface SuspendedRunStoreEngine gains the matching optional member runOutsideOpenUnits, so an engine that does not supply it still satisfies the interface. No existing signature or accepted input narrows. DispatchLoop's change is to the async context its ticks run in, and the dispatchers' change is to when a wake is sent, not to any API. The level stays patch because nothing a metadata author can write changes (Metadata-protocol: none).
Metadata-protocol: none

维护者速读

  • 用户能看到什么变化:记录变更触发的流程(例如 hotcrm 的线索分配)跑完后,运行历史和通知投递、活动记录不再丢失;运行历史会在保存返回后片刻落库,而不是和那次保存同时落库。
  • 为什么做:hotcrm 移植到框架 19 被这个问题挡住,6 个线索分配测试失败;任何在保存时带钩子的对象上跑流程的应用都会丢运行历史。
  • 出错会怎样:最坏是运行历史晚一点出现或重新丢失,业务数据本身不受影响;改动可直接回滚。
  • 要你做什么:无。

What changes

On 19.0.0-next.0 (and on main at 0f8e13b0), a record-change flow fired by a write whose object carries a metadata before* hook, or a blocking after* hook that can abort, runs inside the unit of work the write door opens for that write (inAfterAbortUnit). Two pieces of work the run starts and does not await then took that unit's transaction handle while it was still open, and ran their statements after it had committed, so knex answered "Transaction query already complete":

  1. The terminal run-history write (ObjectStoreSuspendedRunStore.recordTerminal, fired and forgotten from run-history.ts). Its first find on sys_automation_run failed, so the run's history row never landed.
  2. The notification dispatcher's tick, started by the notify node's outbox wake (DispatchLoop.wake()) in the same async context. Its delivery updates failed, and so did the sys_activity audit rows they fire; the timer each tick sets inherited the same context, so later ticks did too.

The fix, one mechanism per producer:

  • packages/objectql/src/engine.ts: new public ObjectQL.runOutsideOpenUnits(body). It runs work its caller starts and does not await outside every unit open at the call, through the same runOutsideOpenUnits exit an async: true hook's run already takes (unit-detach.ts): out of the ambient entry, with that entry's handle recorded as detached.
  • packages/services/service-automation/src/suspended-run-store.ts: recordTerminal runs its whole write (the read, the insert or update, the retention prune) through the engine's runOutsideOpenUnits. SuspendedRunStoreEngine gains it as an optional member, so a double without units keeps running the write where it is.
  • packages/core/src/dispatch-loop.ts: DispatchLoop (the notification, HTTP-delivery, database-queue and audit-seal loops) runs every tick, its due-time read and the timer for the next tick in the async context it was constructed in, never the context of the caller of start(), wake() or wakeAt(). Its docblock now states that a loop is constructed at boot, and names DbQueueAdapter.start() reached from subscribe() under autoStart (review F-5).
  • The wake waits for the commit (review F-2, option a). A tick woken inside a unit now runs outside it, and on a pooled driver (Postgres, MySQL) it cannot see the outbox or queue row the unit has not committed yet, so that row would wait for a backed-off tick (up to maxIdleIntervalMs, 30 s, under soleWriter). New public ObjectQL.runAfterOpenUnitsCommit(body) (unit-detach.ts) runs body outside the units once the ambient unit commits, never when it rolls back, at once when no unit is open, on the same UnitCommitQueue the write events' async runs wait on (objectql: run async after-hooks on commit of the triggering unit (drop on rollback) #33760). wakeAfterOpenUnitsCommit(engine, wake) (new, @objectstack/core) sends a wake through it, or at once on an engine without it. Wired at the notification and HTTP outboxes' onEnqueued (messaging-service-plugin.ts) and at the DB queue's due publish and replay (db-queue-adapter.ts). A deferred publish keeps wakeAt (a timer hint, no read now). A ScopedContext beginTransaction trio unit holds the wake back while an engine call carrying its handle runs (publishTrioHandleFor publishes the handle with the trio's queue); a wake made outside such a call, by code that holds the trio handle only explicitly, goes at once and on a pooled driver waits one backed-off tick (review F-6, accepted). engine.ts stays within its line ceiling (6856 of 6857): the [DETACHED_HOOK_RUN] docblock lost one line, wording only.

Behaviour a reader can see: a run's history row is written beside the run, not inside the triggering write's unit. It is not rolled back with that write, and it can land a moment after the write has returned, as it already could for any run outside a unit (the run-history write was never awaited). A test that reads a run's history once, straight after the write that fired it, has to wait for it to land instead.

Branch: claude/project-thread-a7kaf6, the name the harness assigned this card thread, not claude/issue-37705-*.

Tests

  • packages/objectql/src/engine-scoped-transaction-late-write.test.ts, new top-level describe #37705: a driver that refuses a finished handle as knex does, and holds a read until after the commit. CONTROL: a read started bare inside engine.transaction() took the unit's handle and fails with "Transaction query already complete". The same read through runOutsideOpenUnits reaches the driver with no handle and answers. A unit the detached body opens is its own.
  • packages/services/service-automation/src/suspended-run-store.test.ts, new describe #37705: every statement of the terminal write (find, insert, update, the prune's delete) runs inside runOutsideOpenUnits; an engine without it still gets the row.
  • packages/core/src/dispatch-loop.test.ts, new describe #37705: a tick, its due-time read and the next timer tick see none of an AsyncLocalStorage store the caller of wake(), start() or wakeAt() was in. A second describe: wakeAfterOpenUnitsCommit hands the wake to the engine's runAfterOpenUnitsCommit, and wakes at once without it.
  • packages/objectql/src/engine-scoped-transaction-late-write.test.ts, second #37705 describe: inside a unit the signal runs after the commit (body done, commit, signal); a read it starts reaches the driver with no handle; a rolled-back unit sends none; with no unit it runs before the call returns.
  • packages/services/service-queue/src/db-queue-idle-backoff.test.ts, new describe #37705: under an engine that holds the signal as an open unit does, a due publish runs no tick until the commit and then delivers within the base interval; a replay hands its wake over too.
  • packages/services/service-messaging/src/plugin-enqueue-wakes-dispatcher.test.ts, new describe #37705 on the composed plugin and a real engine: an emit() inside objectql.transaction() hands its wake to runAfterOpenUnitsCommit once, nothing is sent while the unit is open, and the delivery goes out after the commit.

Reverse verification (fix committed first, then each source file put back to its main body, engine.ts by making the method return body()): the two #37705 cases in each of the three files go red (6 of 6), the control stays green, and restoring HEAD gives git diff HEAD empty. Round 2 at 92c84c3, the same way: runAfterOpenUnitsCommit running at once (2 red: commit order, rollback), wakeAfterOpenUnitsCommit never deferring (1 red), the queue's two wakes back to this.wake() (2 red), the notification outbox's onEnqueued back to a bare wake (1 red); 6 of 6, git diff HEAD empty after each.

Local runs (tree: objectstack-ai/objectstack, head f94bcab; 62064b5 below)
  • pnpm --filter @objectstack/core test: Tests 3797 passed (3797); typecheck exit 0.
  • pnpm --filter @objectstack/objectql test: Tests 14435 passed (14435); typecheck exit 0.
  • pnpm --filter @objectstack/service-messaging test: Tests 1108 passed (1108); typecheck exit 0.
  • pnpm --filter @objectstack/service-queue test: Tests 93 passed (93); typecheck exit 0.
  • pnpm --filter @objectstack/service-automation test: Tests 4322 passed (4322); typecheck exit 0.
  • All under os-verify-lock.sh (VERDICT command-exit 0), after a turbo run build of the five packages with declarations.
  • dispatch-gates.mjs --commands at f94bcab derived 79 families; --ran reconciles 79: 78 run, all exit 0 (check:facade-delegation-only, check:query-options-erasure, check:dts-closure and check:dual-build-cjs-loads included), 1 NOT MEASURED (exit 3, prerequisite not met in this shallow tree: check-plugin-teardown-shape --self-test).
  • check-adr-0087-registration, check-changeset-no-major, check-empty-changeset green.
  • At 62064b5 (docs and comment wording only: webhooks.mdx, the unit-detach.ts docblock, the changeset): dispatch-gates --commands derives 110 families, the 31 the docs page adds all run and exit 0, check:facade-delegation-only and check:query-options-erasure re-ran green, and engine-scoped-transaction-late-write.test.ts re-ran green.
  • Full dogfood battery: not owed (no ! in the title, no (narrowing) arm). Round 1's sweep files were run at aed7894 (table above); round 2 changes when a wake is sent, not what the swept tests read.

Read-after-write sweep (seat ask)

What moved: only a run's terminal history row in sys_automation_run, and only for a run fired inside a unit. listRuns, listRunsPage and getRun answer from the in-memory run log first (run-history.ts), so an in-process read through them sees the run as soon as it finishes, as before. Delivery rows (and the sys_activity rows their updates fire) for a wake made inside a unit go out once the unit commits, through the commit-time wake above, on every driver, except a wake made outside an engine call that carries a trio handle (review F-6); before review F-2 this sentence held only on a single-connection pool. What can now miss is a test that reads the durable row itself (ql.find('sys_automation_run'), /data/sys_automation_run, loadTerminal) once, straight after the write.

Checked against this branch's build (every file green, no edit needed):

File Reads Verdict
packages/qa/dogfood/test/install-local-uninstall-flows-withdrawn.dogfood.test.ts durable rows already a bounded wait (settledRunCounts, 10 s)
packages/plugins/plugin-approvals/src/save-notice-approval-round-trip.integration.test.ts durable terminal row already a bounded wait (100 × 20 ms)
packages/qa/dogfood/test/flow-shipped-name-stored-row-boot.dogfood.test.ts listRuns already a bounded wait (50 × 100 ms)
packages/qa/dogfood/test/flow-trigger-record-credential-mask.dogfood.test.ts, flow-durable-suspend.dogfood.test.ts durable paused rows the pause write is awaited, unchanged
packages/qa/dogfood/test/flow-name-per-namespace.dogfood.test.ts, automation-stored-reference-package-column.dogfood.test.ts rows the test seeds itself; getRun not a run's terminal write
packages/qa/dogfood/test/flow-condition-scope-keys, flow-door-elevated-start, seed-ownership-claim-dispatch (.dogfood.test.ts) listRuns / resume door in-memory log
packages/verify/src/action-flow-elevated-door, automation-trigger-elevated-door, handle.flows-system-start, handle.public-form-door, handle.system-insert-delete, handle.update-doors (.test.ts) listRuns in-memory log
packages/plugins/plugin-approvals/src/batch-item-recall-resumes-batch.test.ts getRun in-memory log
packages/runtime/src/domains/automation-run-detail-passthrough, automation-screen-read-gate, automation-resume-caller-gate, automation-run-read-permission-gate, automation-write-capability-gate (.test.ts) stubbed engine no store
packages/plugins/organizations/src/elevated-organization-wall.postures.wall.test.ts flow side effects green
examples/app-todo/test/task-completion-trigger.test.ts, task-recurrence.test.ts; examples/app-showcase/test/approver-bindings-specimen-unarmed.test.ts listRuns in-memory log
packages/services/service-automation/** all full package suite green (4322)

Runs: dogfood 51 + 26, verify 70, runtime 25, organizations 10, plugin-approvals 3 + 10, example-todo 27, example-showcase 4, all passed. Found by grepping packages/ and examples/ test files for sys_automation_run, listRuns, getRun, loadTerminal, /runs and sys_activity next to a record-change trigger.

hotcrm (not in this PR): in PR #2820's test/flow-record-change.test.ts, the three case_escalation cases at lines 205, 263 and 787 read the durable row once and must switch to the file's own landedRuns wait (details under Acceptance notes).

Acceptance notes

  • hotcrm. hotcrm PR feat(auth): 身份导入默认不设密码(passwordPolicy: 'none') #2820's head 03a2647, with every @objectstack/* package except console swapped for this branch's build: test/flow-record-change.test.ts answers 6 failed / 50 passed on main (0f8e13b0, the same 6 as on 19.0.0-next.0) and 0 "Transaction query already complete" lines with the fix. Three case_escalation cases (lines 205, 263 and 787 there) then read the run's history once, straight after the write, and find nothing yet: on main the row was written inside the triggering write's unit and was visible when the write returned. With those three reads switched to the file's own landedRuns (wait for the row), the file is 56 / 56. That three-line change belongs to the hotcrm port, not to this PR.
  • A framework end-to-end twin of the hotcrm run was not kept: a booted fixture (record-after-create flow, update_record, a metadata before* and blocking after* hook, AuditPlugin) did not reproduce the race on SQLite, because nothing there held the history read between its handle and its statement. The engine-level pin holds that step by construction instead.
  • Accepted deviations from review: F-1, the terminal history row outlives a rolled-back triggering write. F-7, an outbox or queue table on a datasource the open unit does not cover commits its row on its own connection while the wake rides the unit's queue, so a rollback drops that wake and the row goes out on the next backed-off tick (at most maxIdleIntervalMs); no in-tree composition was measured that way.
  • Docs: content/docs/automation/webhooks.mdx now says a delivery enqueueHttp() or redeliverHttp() writes inside a transaction goes out at its commit, and not at all on a rollback (review F-9).
  • Same class elsewhere: any other work a run or a hook starts inside a unit and does not await can take the unit's handle the same way. This PR fixes the two producers the hotcrm run measured; ObjectQL.runOutsideOpenUnits is the exit for the next one.

Verification

Two-minute check: pnpm --filter @objectstack/objectql exec vitest run src/engine-scoped-transaction-late-write.test.ts -t 37705, which shows the control failing with "Transaction query already complete" and the detached read answering.

Read first:

  1. packages/services/service-automation/src/suspended-run-store.ts recordTerminal: the write leaves the caller's units; it no longer commits or rolls back with the triggering write.
  2. packages/core/src/dispatch-loop.ts loopTickAtHome / wakeAt: every loop's ticks now run in the context the loop was constructed in; wakeAfterOpenUnitsCommit and the unit-detach.ts runAfterOpenUnitsCommit it reaches: a wake made in a unit goes at its commit.
  3. packages/objectql/src/engine.ts runOutsideOpenUnits: the new public engine member.

Generated by Claude Code

🤖 Generated with Claude Code

https://claude.ai/code/session_01L6bhgX3p4cHBBQ11Sjokrq

…ck run outside the unit that started them

A record-change flow finishes inside the unit of work the write door opens
for the triggering write's after-hooks. Its terminal run-history write is not
awaited, so its first read took that unit's handle and ran after the unit had
committed: knex answered "Transaction query already complete" and the row
never landed. A notify node's outbox wake started the dispatcher's tick in the
same unit, and its delivery and audit writes failed the same way.

- ObjectQL.runOutsideOpenUnits(body): run work the caller does not await
  outside every open unit (the exit an async: true hook's run takes).
- ObjectStoreSuspendedRunStore.recordTerminal runs its write through it.
- DispatchLoop runs every tick in its own async context, never the waker's.

Claude-Session: https://claude.ai/code/session_01L6bhgX3p4cHBBQ11Sjokrq
Co-authored-by: Claude <noreply@anthropic.com>
…pin's options

The contract for ObjectQL.runOutsideOpenUnits now lives on the function it
delegates to in unit-detach.ts, and the #37705 pins pass typed options.

Claude-Session: https://claude.ai/code/session_01L6bhgX3p4cHBBQ11Sjokrq
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 27, 2026
@github-actions

github-actions Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 5 package(s): @objectstack/core, @objectstack/objectql, @objectstack/service-automation, @objectstack/service-messaging, @objectstack/service-queue, touching 13 documentable anchor(s).

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

  • content/docs/api/error-handling-server.mdx (via ScopedContext (symbol, a top-level class))
  • content/docs/automation/hook-bodies.mdx (via ScopedContext (symbol, a top-level class))
  • content/docs/automation/webhooks.mdx (via MessagingServicePlugin (symbol, a top-level class))
  • content/docs/permissions/system-context.mdx (via ScopedContext (symbol, a top-level class))
  • content/docs/plugins/packages.mdx (via MessagingServicePlugin (symbol, a top-level class))

⛔ 2 release-owned page(s) also name something this change touched. These are read-only:

  • content/docs/releases/v14.mdx (via MessagingServicePlugin (symbol, a top-level class))
  • content/docs/releases/v17/17-5.mdx (via MessagingServicePlugin (symbol, a top-level class))

content/docs/releases/ is RELEASE-OWNED (AGENTS.md "Documentation Guardrails"): release
notes are written centrally at release time, and a code PR that edits them is the exact PR
that guardrail exists to stop. They are still audited — read-only. If one of them is actually
wrong, file an issue or open a dedicated docs-only PR; do not edit it here.

What this run could not see
  • 1 anchor(s) matched too much of the corpus to be a work list: ObjectQL (symbol, 82 pages)
  • 5 name(s) were too generic to anchor anything (single lowercase words)
  • the SDK route bridge reached 69 of 252 client-bound route-ledger rows — the other 183 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 183: 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; 124 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 — 54 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 247382446d968e3b39635ed416275581f09117f2 → packageMentionDocs.

Which tree this was computed on

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

node scripts/docs-audit/affected-docs.mjs --json 247382446d968e3b39635ed416275581f09117f2

⚠️ 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 247382446d968e3b39635ed416275581f09117f2 → pass the list as
args.docs, on the commit named under Which tree this was computed on.

…lause-② widening (#37705)

ObjectQL is exported from the @objectstack/objectql entry, so the new
public method widens it, and SuspendedRunStoreEngine gains the matching
optional member. The level stays patch (Metadata-protocol: none).

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

Copy link
Copy Markdown
Contributor Author

repo:objectstack#2 · os-sales · session_01L6bhgV6i8jfWwSXjpWJrjA

Contract review

Served-tier: TIER_DEFAULT
Head-sha: dbe4ac7ac20b52bb48b36b1b5a96769a58cac8b5
Local-runs: none

Face: declaration (Clause-②: yes (widening) on the PR body and the changeset); no published schema and no governed path in the file list, so no ④. Inputs: card #37705 with every comment, this PR's body and 8-file net diff against main (merge-base 0f8e13b0), and the head's check-runs (57 success, 13 skipped, 0 failed, none pending; all eleven required contexts green). The PR is still a draft.

① Derived judgments

  • ObjectQL.runOutsideOpenUnits(body) (new public member on an exported class): right. It is a one-line delegate to the existing runOutsideOpenUnits(txStore, undefined, body) in unit-detach.ts: it leaves the engine's ambient unit entry and records that entry's handle as detached. No handle is threaded, which is correct here because the store's statements carry SYSTEM_CTX and no transaction. Nothing that is already accepted changes.
  • The detach matches the async-hook exit only for afterFind, not for the write events. engine-scoped-context.ts sends a write event's async run through runOutsideOpenUnitsOnCommit: it waits for the unit's commit and is dropped on rollback (objectql: run async after-hooks on commit of the triggering unit (drop on rollback) #33760). The new member starts at once and is never dropped. That is a deliberate choice, and the changeset and the docblock state it. F-1 grades the result.
  • SuspendedRunStoreEngine.runOutsideOpenUnits? (optional member on an exported type): right. The registered objectql and data services are both the ObjectQL instance, so the shipped composition takes the detached arm. A double without units keeps the old in-place write. recordTerminal drops async but still returns writeTerminal's promise, and its only caller (run-history.ts, void write.catch) never awaits it. So no single-connection pool can deadlock on a detached write that a caller is awaiting.
  • No write that must be atomic with the triggering write escapes. Only the terminal history row (find, upsert, retention prune) is detached. The run's own node writes, the pause write and the suspension claim stay in the unit, awaited. Paused rows (raw runId) and terminal rows (run_ + runId) are disjoint, so a detached upsert cannot race the unit's claim delete on the same row.
  • DispatchLoop ticks in its constructor's async context: right, and safe for context. All four in-tree loops (notification, HTTP delivery, DB queue, audit sealer) are constructed at boot (constructor, start() from kernel:ready, or plugin start). None of their ticks reads an ambient store, because delivery rows carry their own tenant and recipient. Timer-driven ticks never had the waker's context anyway, so no delivery depended on it. start(), wake(), wakeAt() with a past due time, and a future wakeAt() timer are all re-homed. The node:async_hooks import matches the node:crypto and node:net imports already on core's main entry.
  • Root cause and coverage of the reproduction: right for the two producers measured. The card's audit failures are the sys_activity rows that the notification tick's delivery updates fire. The PR measured 0 "Transaction query already complete" lines in hotcrm with the fix. F-4 names other candidates of the same class.
  • Tests: they fail without the fix, by reading. objectql: with return body(), the detached read takes the unit's handle (seen equals [begun[0]]), and the inner transaction() joins the outer unit (begun length 1). Both cases go red and the CONTROL stays green. service-automation: without the routing, every statement records outside: false, so 2 cases go red. core: without loopTickAtHome, the tick sees the waker's store, so 2 cases go red. That matches the reported 6/6.
  • Read-after-write sweep: it holds for sys_automation_run. Every listed reader of the durable row already waits with a bound (10 s, 100 × 20 ms, 50 × 100 ms) or reads the in-memory log. The unlisted readers I checked read rows that are not the terminal write of a run fired inside a unit: schedule-fired runs, restored-approval hasSuspendedRun, stubbed runtime doors. Test Core and Dogfood Regression are green on this head. The sweep's DispatchLoop sentence does not hold on every driver: see F-2.

② Semver level

  • Changeset: @objectstack/objectql, @objectstack/service-automation and @objectstack/core at patch. The diff publishes one new public method, one new optional interface member and a tick-context change. It adds no authorable key, no accepted value and no metadata type, so Metadata-protocol: none is right, and under the level rule a non-protocol widening ships patch. The level is right.
  • Clause-②: the PR body and the changeset each carry Clause-②: yes (widening) at the start of a line. That is right for a public member added to an exported class with no signature or input narrowed. The card's Clause-②: no was filed before the fix existed, and the PR correctly supersedes it.

③ Boundary flags

  • F-1 · nit: the terminal row now outlives a rolled-back triggering write. On a pooled driver it can also commit before that write is visible. A completed history row can therefore name a run whose in-unit effects were rolled back, and a trigger_record_id can name a row that is not yet visible. The changeset and the unit-detach.ts docblock declare this. It is defensible: a run whose failure caused the rollback must keep its row, which the commit-and-drop posture of objectql: run async after-hooks on commit of the triggering unit (drop on rollback) #33760 would erase. Accepted as a deviation; nothing is owed in this PR.
  • F-2 · should-fix: a wake made inside a unit can no longer see the row it was woken for, on a pooled driver. The woken tick now runs outside the unit, so on Postgres or MySQL it cannot see the outbox or queue row the uncommitted unit just enqueued, and nextDueAt cannot see it either. The tick finds nothing, and the row waits for the next backoff tick: twice intervalMs by default, and maxIdleIntervalMs (30 s by default) when soleWriter is set, whose premise is that wakes carry the work. On a single-connection pool, which is the hotcrm case, the tick waits for the connection and sees the committed row. So the sweep's sentence that sys_activity and delivery rows "land when they did" holds only there. Close this either way: (a) the wake fires on the unit's commit, which the producer that enqueues through the engine can arrange; or (b) correct the PR body and changeset to state the pooled-driver latency, and file it as a follow-up card under the filing gate.
  • F-3 · should-fix: the card is not delivered whole by Fixes #37705. The card's acceptance also requires hotcrm's six lead_assignment tests to pass on the release that carries the fix, and that cannot be observed at merge. The PR body also says three hotcrm case_escalation reads, which passed on main, need the file's own bounded wait (landedRuns) because of this change. No card tracks either item. Before ACCEPT: file the hotcrm-side card for the three reads, and either switch to Refs #37705 so the card stays open until the release check, or record on the card that the hotcrm card owns that check.
  • F-4 · nit: candidates of the same class, outside the diff. plugin-audit's read-audit and dataset-query-audit batchers are enqueued from a synchronous afterFind (recordView). The batcher calls void runFlush() at maxBatchSize and arms its flush timer in the reader's async context. A user-principal read inside an open unit can therefore start a sys_audit_log persist enrolled in that unit, which can then outlive it. This is unmeasured and needs a reproduction before a card (Prime Directive 10). The PR body already names runOutsideOpenUnits as the exit for the next such producer.
  • F-5 · nit: the loop's home is wherever it was constructed. Every in-tree construction runs at boot. But DbQueueAdapter.start() is also reachable from subscribe() under autoStart, and a lazy first subscribe inside a request would make that request's context the loop's home for good. A sentence in the DispatchLoop docblock naming the boot-construction invariant would close this.
  • SQL push-down: no finding. The diff adds no id materialisation and no in-app join. The in-app sort and per-row delete in pruneFlowOverflow predate the diff; it is only re-routed here.
  • Dev flags and open questions: the PR body's two flags are answered above. The missing framework end-to-end twin is acceptable, because the engine pin holds the race by construction (the driver holds the read until after the commit). The hotcrm three-line change is F-3. The report carries no open_questions entry. The PR author is objectstack-fleet[bot], so no author note is owed.
  • Remaining before ACCEPT: close F-2 and F-3 (each a delta read by this reviewer), then take the PR out of draft.

Implemented-by: claude/project-thread-a7kaf6
Reviewed-by: session_01L6bhgV6i8jfWwSXjpWJrjA

VERDICT: PASS

…t that wrote its row (#37705)

A wake made inside a unit of work now runs its tick outside the unit, and
on a pooled driver that tick cannot see the row the unit has not yet
committed, so the row waited for a backed-off tick. The wake now goes at
the unit's commit through the new ObjectQL.runAfterOpenUnitsCommit, and
not at all when the unit rolls back: the notification and HTTP outboxes'
onEnqueued and the DB queue's publish and replay route through core's
wakeAfterOpenUnitsCommit. The DispatchLoop docblock also states that a
loop is constructed at boot.

Claude-Session: https://claude.ai/code/session_01L6bhgX3p4cHBBQ11Sjokrq
Co-authored-by: Claude <noreply@anthropic.com>
…the boot-construction rule (#37705)

Claude-Session: https://claude.ai/code/session_01L6bhgX3p4cHBBQ11Sjokrq
Co-authored-by: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added size/l and removed size/m labels Nov 27, 2026
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#2 · os-sales · session_01L6bhgV6i8jfWwSXjpWJrjA

Contract review

Served-tier: TIER_DEFAULT
Head-sha: f94bcab7d35570caf826930c52a256f40efadaae
Local-runs: none

This is the delta round on my round-1 record (7207454847, head dbe4ac7ac2). Face: declaration, as before. I read the delta dbe4ac7ac2..f94bcab7d3 (2 commits, 10 files), the PR body as it now stands, card #37705, and the head's check-runs. Each round-1 finding is closed or kept below by id.

Gate line: CI on this head is still running at review time. 13 checks succeeded, 12 were skipped and 23 are in progress, including Test Core 1-10, Build Core, the Type Check and Lint lanes, and Live E2E UI. The one cancelled run is a superseded PR-body-guards run: a later run of the same name succeeded. None has failed yet. This record does not certify the gate. It has to be read green before ACCEPT.

① Derived judgments

  • ObjectQL.runAfterOpenUnitsCommit(body) (new public member): right.
    • It queues body on the ambient unit's objectql: run async after-hooks on commit of the triggering unit (drop on rollback) #33760 UnitCommitQueue, bound to the caller's async context. It runs outside every unit once transaction() settles the queue, which happens after commit returns.
    • It is dropped in the catch arm on any failure, whether a callback throw or a commit failure.
    • When no unsettled unit exists, it runs at once outside the units.
    • A nested transaction() joins the outer entry (ADR-0067 D2), so a wake made there waits for the outermost commit.
    • The write door's own unit (inAfterAbortUnit) is a transaction(), so it carries a queue. That is the reproduction's case.
  • Is a wake lost or stuck? No in-unit row loses its wake.
    • On rollback, the enqueued row rolls back with the unit, so dropping its wake is correct.
    • A unit that never settles also never commits its row.
    • A run detached by txStore.exit finds no ambient unit and wakes at once.
    • The DispatchLoop's own timer stays the floor for every row: a missed wake costs one backoff interval, never the row. F-6 and F-7 cover the two residual edges.
    • A deferred publish keeps wakeAt, which now only arms a timer. If that timer fires while the publishing unit is still open, a pooled driver misses the row once and backs off. This is narrow and bounded, so it is not a finding.
  • Atomicity and errors. The body runs after the commit and outside every unit, so nothing it does can be atomic with the write. The four wired bodies are bare wake() calls, which write nothing and throw nothing. See F-8 for the public contract's wording.
  • wakeAfterOpenUnitsCommit(engine, wake) (new root export of @objectstack/core): right. It wakes through the engine when the engine has the member, and otherwise at once. In production the engine it receives is the ObjectQL instance in all four wirings: the notification outbox, the HTTP outbox (including redeliverHttp, which shares onHttpDeliveryEnqueued), the queue's due publish, and replay.
  • The engine.ts docblock compression is pure wording. The [DETACHED_HOOK_RUN] comment merges two sentences into one, with the same claim. No code changed.
  • Pins: by reading, they fail without the wiring.
    • objectql: 3 of 4 go red with an at-once implementation (the event order, the handle seen, a signal on rollback). The no-unit case is the control.
    • core: 1 goes red if the helper calls wake() directly. The member-absent case is the control.
    • service-queue: 2 go red without the wiring (held is empty for publish and for replay).
    • service-messaging: 1 goes red on the spy count. It runs on a real engine over SQLite, in a real transaction().

② Semver level

  • The changeset now names @objectstack/service-messaging and @objectstack/service-queue at patch beside objectql, service-automation and core. Those two change only when a wake is sent, so patch is right.
  • The Clause-②: yes (widening) lines in the PR body and the changeset list the whole new public surface: two ObjectQL methods, the core root export, and the optional SuspendedRunStoreEngine member. The new unit-detach.ts function is not reachable from the objectql entry. Metadata-protocol: none still holds. The level is still right.

③ Boundary flags

  • F-1 · nit: kept as an accepted deviation, unchanged by the delta.
  • F-2 · should-fix: CLOSED. Route (a) holds against the tree. The wake goes at the commit of the unit that wrote the row, on the same queue and at the same settle point objectql: run async after-hooks on commit of the triggering unit (drop on rollback) #33760's async runs use, and not at all on rollback. The PR body's sweep sentence is corrected.
  • F-3 · should-fix: STILL OPEN. The PR body still reads Fixes #37705. No hotcrm card is filed for the three case_escalation reads, and card 19.0.0-next.0: a record-change flow's run-history and audit writes throw knex "Transaction query already complete" after the flow finishes (hotcrm lead_assignment) #37705 carries no note on who owns its release-side acceptance check. The delta does not touch this.
  • F-4 · nit: kept, unchanged. It is outside the diff and needs a reproduction before a card.
  • F-5 · nit: CLOSED. The DispatchLoop docblock now states that a loop is built at boot, and names DbQueueAdapter.start() reached from subscribe() under autoStart. The changeset says the same.
  • AuditSealer item: CLOSED. The audit-seal loop is now in the loop list in the PR body and the changeset.
  • F-6 · nit (new): the ScopedContext beginTransaction-trio gap is acceptable, and narrower than the PR declares.
    • The PR body and the changeset say a trio unit "does not hold the wake back". The tree is better than that. While an engine call that carries the trio handle runs, publishTrioHandleFor publishes the handle into the ambient entry together with the trio's own queue (trioCommitQueueOf). commitTransaction and rollbackTransaction settle that queue (settleTrioCommitQueue).
    • So a wake made inside such a call, which is where an enqueue's onEnqueued runs, already waits for the trio's commit.
    • The gap left is a wake made outside any such call, by code that holds the trio handle only explicitly. It goes at once, as in round 1. On a pooled driver that costs one backoff interval, never the row.
    • Accepted. Optionally, narrow the declaration in the PR body and changeset to that case. The sweep's "on every driver" sentence should carry the same exception.
  • F-7 · nit (new): a dropped wake for a row that did commit.
    • Case: the outbox or queue table sits on a datasource the open unit does not cover. Its insert then commits on its own connection, which the same-origin gate allows for system ledgers, while the wake still rides the unit's queue.
    • Consequence: on rollback the wake is dropped. The row goes out on the next backoff tick, at most maxIdleIntervalMs. No in-tree composition was measured that way.
  • F-8 · nit (new): the wording of runAfterOpenUnitsCommit's public contract.
    • The docblock says a throw from body after the commit "is the body's own". In fact settleUnitCommitQueue swallows a synchronous throw with no log, a rejected promise from an async body is unhandled, and on the no-unit path the throw reaches the caller.
    • Unlike its sibling runOutsideOpenUnits, it carries no ⛔ line against routing work that must be atomic with the write.
    • Fix: state both in the docblock. A wording change.
  • F-9 · should-fix (new): content/docs/automation/webhooks.mdx:495-497 is now false inside a unit.
    • The page says messaging.enqueueHttp() and messaging.redeliverHttp() wake the dispatcher "so a delivery written there goes out at once".
    • Against the tree: both call onHttpDeliveryEnqueued (messaging-service.ts), which the plugin now routes through wakeAfterOpenUnitsCommit. Inside a unit the delivery goes out at that unit's commit, and not at all on rollback. Outside a unit it goes at once.
    • The sentence needs that qualifier.
    • The other four hand-written pages docs-drift lists (api/error-handling-server.mdx, automation/hook-bodies.mdx, permissions/system-context.mdx, plugins/packages.mdx) name only ScopedContext or MessagingServicePlugin and state no wake timing. I spot-checked them: no edit is owed. The two release-owned pages are read-only.
  • Regression of round-1 closures: none. The delta adds no write path. The terminal history row and its detach are unchanged, so the round-1 atomicity, deadlock and context judgments stand.
  • SQL push-down: no finding. The delta adds no id materialisation and no in-app join.
  • The PR is still a draft. Its author is objectstack-fleet[bot], so no author note is owed.
  • Remaining before ACCEPT:
    1. Close F-3.
    2. Close F-9.
    3. Read every check on this head green.
    4. Take the PR out of draft.
      The F-3 and F-9 fixes are a body, card and docs change, which this reviewer reads as a delta. F-6, F-7 and F-8 are nits that may ride along or be accepted.

Implemented-by: claude/project-thread-a7kaf6
Reviewed-by: session_01L6bhgV6i8jfWwSXjpWJrjA

VERDICT: PASS

…ommit; tighten the commit-time wake's contract (#37705)

webhooks.mdx said an enqueued or redelivered HTTP delivery goes out at
once; inside a transaction it now goes at the commit and not at all on a
rollback. runAfterOpenUnitsCommit's docblock now states how a body's
throw surfaces, that a trio unit holds the wake while an engine call
carrying its handle runs, and that nothing in the body is atomic with
the write.

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

Copy link
Copy Markdown
Contributor Author

repo:objectstack#2 · os-sales · session_01L6bhgV6i8jfWwSXjpWJrjA

Contract review

Served-tier: TIER_DEFAULT
Head-sha: 62064b52334ae7f6452474523247b1469c32c392
Local-runs: none

This is delta round 3 on my round-2 record (7208126545, head f94bcab7). Face: declaration, as before.

I read four things:

Gate line: CI on this head is still running at review time. 9 checks have succeeded, 11 were skipped and 21 are in progress, including Build Core, every Type Check and Lint lane, Check Changeset and Live E2E UI. Test Core and Test UI have not started.

The run on f94bcab7 was cancelled when this head was pushed. Its two failure rows (TypeScript Type Check, Test UI) are the roll-up jobs over shards that were cancelled at 02:34Z, not measured failures. So no completed gate yet covers the code, which is unchanged since f94bcab7. This record does not certify the gate. Every check has to be read green before ACCEPT.

① Derived judgments

  • The delta is comment and docs only. That holds.
    • It changes one sentence of the changeset prose and appends one sentence to content/docs/automation/webhooks.mdx.
    • In unit-detach.ts it rewrites only the docblock above runAfterOpenUnitsCommit.
    • It touches no code line, no export, no test and no changeset frontmatter.
  • Each new sentence is true against the tree.
    • The webhooks.mdx sentence. enqueueHttp() and redeliverHttp() both call onHttpDeliveryEnqueued, which the plugin routes through wakeAfterOpenUnitsCommit.
      • Inside a transaction the delivery goes out at that transaction's commit.
      • On rollback the row rolls back with the transaction and its wake is dropped.
      • Before the commit, a pooled driver's tick cannot see the row.
      • The one place the sentence over-reaches is the accepted F-7 composition: there the row commits on its own and goes out on a later tick. That is covered by F-7's acceptance and is not a new finding.
    • The runAfterOpenUnitsCommit errors paragraph.
      • With no unit open, the body runs synchronously inside txStore.exit and its throw reaches the caller.
      • At the commit, the try/catch in settleUnitCommitQueue discards a synchronous throw without logging it. That covers the trio's commit too, because settleTrioCommitQueue delegates to it.
      • A body typed () => void that returns a rejected promise is never observed, so the rejection is unhandled.
      • The new ⛔ line, never route atomic work through it, matches the fact that the body runs after the commit and outside every unit.
    • The trio sentence (docblock, changeset, PR body, sweep).
      • publishTrioHandleFor publishes the trio handle together with trioCommitQueueOf(explicit) while an engine call carrying it runs. So a wake made there waits for the trio's commit.
      • A wake made outside such a call goes at once.
      • This is now stated the same way in all four places.
  • No round-1 or round-2 judgment regresses. No code moved, so ①'s judgments from round 2 stand: the commit-time wake, the detach of the run-history write, and the DispatchLoop's home context.

② Semver level

  • The changeset frontmatter is unchanged: five packages at patch.
  • The Clause-②: yes (widening) lines in the PR body and the changeset are unchanged, and so is Metadata-protocol: none.
  • The level is still right.

③ Boundary flags

Implemented-by: claude/project-thread-a7kaf6
Reviewed-by: session_01L6bhgV6i8jfWwSXjpWJrjA

VERDICT: PASS

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#2 · os-sales · session_01L6bhgV6i8jfWwSXjpWJrjA

席位核对 — ACCEPT · head 62064b5 · card #37705 · area s2-data · 2026-11-27T03:04Z

L1 checklist

  • Shape and checks. l1-face.mjs --pr 37742 is CLEAN: 13 items read, none flagged. All 62 checks on this head succeeded and 12 were expected skips. mergeable_state is clean. Changesets: patch on core, objectql, service-automation, service-messaging and service-queue. Clause-②: yes (widening), Metadata-protocol: none.

  • Contract review at TIER_DEFAULT (declaration face). There were three rounds:

    • 7207454847 at dbe4ac7: PASS, with F-2, F-3 and F-5 open.
    • 7208126545 at f94bcab: F-2 and F-5 closed, F-9 new.
    • 7208289249 at this head: PASS, no must-fix or should-fix open.

    The seat adopts the final record.

    • F-2 is closed. A wake now waits for the commit of the unit that wrote the row (ObjectQL.runAfterOpenUnitsCommit, core wakeAfterOpenUnitsCommit), and a rollback drops it.
    • F-1 and F-7 are accepted deviations, listed in the PR body's Acceptance notes:
      • F-1: the run-history row outlives a rollback.
      • F-7: on a datasource the unit does not cover, a dropped wake is caught by the next backed-off tick.
    • The Clause-② list is complete: two ObjectQL methods, the core root export, and the optional SuspendedRunStoreEngine member.
  • Fixes #37705 is right. The card's acceptance also names hotcrm's six lead_assignment tests on the release that carries the fix. That release check, and the three case_escalation history reads in hotcrm PR feat(auth): 身份导入默认不设密码(passwordPolicy: 'none') #2820 that must switch to landedRuns, are owned by Port to 19: switch three case_escalation history reads to landedRuns and re-check lead_assignment on the release that carries objectstack#37742 hotcrm#2822 (Blocked-by: #37742). The note on this card is 7208160602 (F-3, closed in round 3).

  • Docs read sentence by sentence. One sentence was added to content/docs/automation/webhooks.mdx: inside a transaction a delivery goes out at commit and not on rollback, for both enqueueHttp and redeliverHttp. The record verified it against the tree. The other four pages docs-drift named state no wake timing.

  • Governance. check-governed-merges.mjs on the final 13-file list: not governed, 561 changed lines. Tier S.

  • Follow-ups. F-4 is not filed. It names the plugin-audit read-audit and dataset-query-audit batchers as possible producers of the same class, but nothing has measured them, so it does not pass filing gate ①. The PR body names runOutsideOpenUnits as the exit for the next producer a reproduction finds.

Tier: S. Landing: ready + auto-merge by this stroke.

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/l tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

2 participants