Repository navigation
docs(objectql): state the measured outcome of a failed ctx.api statement in a before* hook's unit - #37990
Conversation
…ent in a before* hook's unit Measured on PostgreSQL 16.15, a MongoDB 8.0.38 replica set and a MongoDB 8.0.38 standalone server (card #34563), with a beforeInsert hook whose ctx.api insert hits a unique constraint: - PostgreSQL and a MongoDB replica set refuse the outer write when the hook body catches the error, when onError: 'log' swallows it, and when retryPolicy re-runs it (every retry is refused too). The answer is the database's own error (25P02 on PostgreSQL, code 251 on MongoDB); neither the row nor the hook's writes are stored. SQLite lets the write through. - A MongoDB standalone server refuses every write on such an object, even when nothing in the write fails, and retryWrites=false does not change it. hooks.mdx and the released 18.6 objectql CHANGELOG entry said "read in the driver's code, not measured"; both now say what was measured. Claude-Session: https://claude.ai/code/session_01L6bhgWfqiK4KtAFo9PN4Xr Co-authored-by: Claude <noreply@anthropic.com>
📓 Docs Drift Check
What this run could not see
Coarse fallback — 21 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): |
|
repo:objectstack#2 · os-sales · session_01L6bhgV6i8jfWwSXjpWJrjA 席位核对 — ACCEPT · head 5c0e0ef · card #34563 · area s2-data · 2026-11-27T14:52ZL1 checklist (no review face on this file list: this record is the review of record)
Tier: S. Landing: ready and auto-merge in this stroke. |
Requested by Sales · project thread
Fixes #34563
维护者速读
ctx.api写入一旦在数据库层失败,不管钩子自己 catch、onError: 'log'吞掉,还是retryPolicy重试,外层保存都会被拒(重试也全部被拒),用户拿到的是数据库原始报错(PG25P02、Mongo251),记录和钩子写入都不留。SQLite 上同样情况保存会成功。MongoDB 单机(非副本集)上,带这种钩子的对象每次保存都失败,哪怕什么都没出错,加retryWrites=false也没用。What changes
Docs only. Two places said the before* hook unit's failure rules were "read in the driver's code, not measured"; both now state the measurement:
content/docs/automation/hooks.mdx(After hooks run inside the unit of work): the MongoDB standalone outcome, and the failed-statement rule widened from PostgreSQL alone to PostgreSQL and a MongoDB replica set, with the exact error each answers, the retry outcome and the SQLite contrast. The "not yet measured; tracked in review follow-ups of PR #34503 #34563" pointer is removed.packages/objectql/CHANGELOG.md, the releaseda8e09bbentry (18.6): the two "Inside the new unit" bullets (MongoDB, PostgreSQL) amended in place, as AGENTS.md's Documentation Guardrails row forpackages/*/CHANGELOG.mdprescribes for a factual error in a released entry (a dedicated docs-only PR, never an erratum in a later entry).Why
The card's Done-when: both cells measured, linked on the card, and the docs say exactly what was measured. The comment's N5 cell (replica set) is measured too.
Verification
Measured with a throwaway vitest probe (not committed) in
packages/runtime: a realObjectQLover a realSqlDriver/MongoDBDriver,bindHooksToEnginewith one metadata-boundbeforeInserthook onzz_casewhosectx.apiinsert intozz_notehits a unique constraint on a pre-seeded value. Tree:objectstack-ai/objectstackorigin/main57ab087. Servers: PostgreSQL 16.15, MongoDB 8.0.38 standalone and single-node replica set (rs0), SQLite (better-sqlite3) as the contrast.25P02, nothing stored251"Transaction … has been aborted", nothing storedonError: 'log'[hook] handler failed (onError=log; suppressing))25P02, nothing stored251, nothing storedretryPolicy {maxRetries: 2}, 2nd attempt writes a valid row25P02; both retries answered25P02; nothing stored251; both retries answered251; nothing storedretryPolicy+onError: 'log'25P02, nothing stored251, nothing storedDuplicateRecordError(DUPLICATE_RECORD, 409, cause SQLSTATE23505); the outer write's error is the raw driver error (code: '25P02', nostatus), not an ADR-0112 refusal.retryWrites=falseon the connection string: the same message on all five paths. A write to an object with no such hook (the seed insert, and amongoshinsert) succeeds on the same server.check:doc-authoring,check:doc-anchors,check:docs-transcript-drift,check:pm-skill-id-lint: all green.Not in this PR, for the seat:
skills/objectstack-data/references/data-hooks.md:60and its evalhooks-security-seeds-datasources.json:317still say "MongoDB needs a replica set (read in code, not measured)" (Tier H, its own card);content/docs/releases/v18/18-6.mdx:411is release-owned and names the failed-statement rule for PostgreSQL only.Clause-②: no
Metadata-protocol: none
Human Minimum
packages/specholds no runtime logic. (not touched)pnpm lintpasses. (docs only; no lintable source changed)main, one pull request.skip-changeset).packages/spectouched: not touched.packages/*/CHANGELOG.md: deliberately edited. This is the dedicated docs-only amendment of a released entry that AGENTS.md's Documentation Guardrails row prescribes.🤖 Generated with Claude Code
https://claude.ai/code/session_01L6bhgWfqiK4KtAFo9PN4Xr
Generated by Claude Code