Repository navigation
docs(skills): teach the hook body first in data-hooks.md, drop hook ctx.api methods that do not exist, guard nullable hook and formula predicates - #31201
Conversation
…ble hook and formula predicates
- references/data-hooks.md: the schema example, the implementation section
and Pattern 3 are sandboxed `body`s; `handler` remains only as the
deprecated form (Pattern 4 read masking, which a body cannot do, and the
string-named registration). The Cross-Object API handler snippet is cut
(homes: § ctx.api.object(name), Pattern 2).
- The repository table and the api.write row drop upsert / updateMany /
deleteMany, which the hook's ctx.api (ObjectRepository) does not have, and
teach update / delete with { where, multi: true } as the bulk form.
- Two hook `condition` examples and one objectstack-formula predicate gain
the `!= null` guard the publish gate requires.
- § Capabilities links Connector recipes; the async list drops the two
external-call bullets a body cannot do.
- Evals: two new data cases (body bulk cascade, guarded hook condition);
formula case 2 now asserts the guard.
Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J8VVAnzH4vvvJVUf6zdYe9
|
domain:skills#3 · huangyiirene · session_01J8VVAj7CvjkGXvgXzd6RZ7 Contract-review-claim: session_01J8VVAj7CvjkGXvgXzd6RZ7 · head 9931ab6 · 2026-11-07T17:16Z Full contract review of PR #31201 (#31131, claim 6710181100, widened 6710259290). The seat review runs at CONTRACT_REVIEW_TIER in an isolated subagent. |
|
domain:skills#3 · huangyiirene · session_01J8VVAj7CvjkGXvgXzd6RZ7 Contract reviewServed-tier: ① Derived judgmentsInputs: card #31131 (body; triage 6707819308; claim 6710181100; widening 6710259290 with the seat's two rulings), the PR body (identical to /mnt/project-files/card-31131/body-v1.md apart from the attribution lines and a trailing newline), the order at /mnt/project-files/skills-seat3/order-31131.md, the gate record gates-9931ab6f.txt (46 commands, all exit 0), PR #31127's merged diff, the commit, the net diff, and the seat's mid-flight ruling on the two
② Semver level
③ Boundary flags
④ Design judgment
Verdict: FAIL |
…input.id to the handler
A body's ctx.input carries `id` only when the write payload does, so on a
bulk, by-where or delete dispatch `ctx.input.id` is undefined and a
`where: { account_id: ctx.input.id }` matches every row. Patterns 1-3 now
key the row on ctx.previous.id (Pattern 2 falls back to ctx.result for
inserts), and the "input.id names the row" prose and the sandbox ctx.input
row say which door that holds for.
The Connector recipes note no longer names one flow phase. Eval case 12
keys on ctx.previous.id and forbids the input.id key; case 13 no longer
overstates the runtime refusal; must_contain strings drop their quotes.
Paid by same-file deletion: Gotcha 1's restated has() guard sentence,
Pattern 1's capability comment, Pattern 2's default `async: false` line.
Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J8VVAnzH4vvvJVUf6zdYe9
|
domain:skills#3 · huangyiirene · session_01J8VVAj7CvjkGXvgXzd6RZ7 Contract-review-claim: session_01J8VVAj7CvjkGXvgXzd6RZ7 · head a15a1f3 · 2026-11-07T17:35Z Delta review against the FAIL at head 9931ab6 (comment 6710673767: must-fix M1, should-fixes S1–S4, nits N1–N5). The delta is one fix commit answering M1, S1, S3 (claim widened in #31131 comment 6710683947), S4 and N1, plus a merge of |
|
domain:skills#3 · huangyiirene · session_01J8VVAj7CvjkGXvgXzd6RZ7 Contract reviewServed-tier: ① Derived judgments
② Semver level
③ Boundary flags
④ Design judgment
Verdict: FAIL |
A body's ctx.input carries `id` only when the payload does, as the sandbox ctx table now says; Gotcha 1 no longer claims both carry it. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01J8VVAnzH4vvvJVUf6zdYe9
|
domain:skills#3 · huangyiirene · session_01J8VVAj7CvjkGXvgXzd6RZ7 Contract-review-claim: session_01J8VVAj7CvjkGXvgXzd6RZ7 · head 9b1e926 · 2026-11-07T17:42Z Delta review against the FAIL at head a15a1f3 (comment 6710804344, must-fix M1). The delta is one commit, a one-line change in data-hooks.md, plus the PR body's token reading (patched by the seat). The seat reviews it at CONTRACT_REVIEW_TIER. |
|
domain:skills#3 · huangyiirene · session_01J8VVAj7CvjkGXvgXzd6RZ7 Contract reviewServed-tier: ① Derived judgments
② Semver levelUnchanged: ③ Boundary flags
④ Design judgmentThe page now gives one consistent account of what a body's Verdict: PASS |
|
domain:skills#3 · huangyiirene · session_01J8VVAj7CvjkGXvgXzd6RZ7 维护者速读
席位核对 — ACCEPT · domain:skills#3 · head
|
Requested by Irene · project thread
Fixes #31131
Clause-②: no
Metadata-protocol: none
dispatch-gates --tierreads a MANDATORY model tier forskills/**(clause ① of the model-tiering ruling); it is waived by the standing order of the maintainer in this project (2026-11-03), and this card ran on the project's default model. The dispatching seat runs the contract review.维护者速读
objectstack-data的references/data-hooks.md改为先教沙箱body:Schema 示例、实现小节、Pattern 3 都写成body;handler只作为已弃用形式保留(读脱敏 Pattern 4,因为body只回写ctx.input;以及按名字注册的字符串handler)。仓库方法表与api.write行去掉钩子ctx.api并不存在的upsert/updateMany/deleteMany,批量写法改教update/delete加{ where, multi: true }。Pattern 1–3 的body改用ctx.previous.id定位行(body的ctx.input只在载荷带id时才有id,批量/按 where/删除时为空,where会匹配全部行)。两处钩子condition与objectstack-formula一处谓词加!= null守卫;§ Capabilities 链到 Connector recipes。os generate agentstill listed, deprecatedhandlertaught first #31113 / PR docs(skills): guard nullable validation operands, teach hookbody, listmailbox/package-registry, dropos generate agent#31127)。@objectstack/skillspatch;回滚即 revert。skills/objectstack-data/references/data-hooks.md的 §ctx.api.object(name)方法表与 Pattern 3 / Pattern 4(席位裁定:Pattern 4 保留为标注弃用的handler;批量写法以引擎为准)。node scripts/check-skills-token-ratchet.mjs,预期退出 0,57 authored bundle file(s) within their ceilings。skills/**属 Tier H(人合),需要os-zhuang或hotlong的一次 approval,之后席位落地。What changes
1.
data-hooks.mdteachesbodyfirstCode sites:
HookSchema.handler(packages/spec/src/data/hook.zod.tsL485: "DEPRECATED, preferbody") andHookSchema.body(L487–L498: preferred; with both present the runtime usesbody). The capability set isHookBodyCapability(packages/spec/src/data/hook-body.zod.tsL48–L54; nohttp.fetch, L38). Per example, against the body runner (packages/runtime/src/sandbox/body-runner.ts):bodyreceives:buildSandboxContext(L1232 onward) hands a JSON snapshot:input,previous(undefinedon insert),result,user,session,event,object,api,log,title,notice.ctx.input, viaapplyMutationsToInput(L496; header L24–L36). A write toctx.resultstays in the VM.ctx.inputis a snapshot of the flat-input Proxy (unwrapProxyToPlain, L1481), whoseownKeyslists only the payload's keys (installFlatInput,packages/objectql/src/hook-wrappers.tsL689). Soctx.input.idexists only when the payload carries one: it is undefined on a bulk (multi: true) update, awhere-addressed update and every delete.ctx.previous.idis bound on all of them;packages/runtime/src/sandbox/perrow-dispatch-signal.integration.test.tsL49 and L187–L188 pininputIdType === 'undefined'and "the row id a per-row body needs isctx.previous.id".ctx.api.object(n).<method>is gated byapi.read/api.writeinquickjs-runner.tsL705–L708. The method then runs on the engine's repository (ObjectRepository,packages/objectql/src/engine.tsL10079), and a method that repository lacks throwsnot implemented(quickjs-runner.tsL1368).body-runner.tsL497–L505).http.fetchtoken, andfetchis absent from the VM (same file, § Sandbox restrictions).Every
handlersite the card listed, re-read onmain620b6e6d:mainlinehandler: async (ctx: HookContext) => {…}body: { language: 'js', source, capabilities: [] }, commented "the inlinehandleris deprecated"; the unusedHookContextimport goes.#### handler — Implementation: inline function "(recommended for simple hooks)" and the string ref'my_plugin.validateAccount'#### body — Implementation: abodythat normalisesctx.input.email, with "a throw aborts the write". One sentence names the deprecatedhandler's two shapes (inline function, registered function's name) and links § Registration Methods, which holds the string-ref example.bodyvshandlercomparison tablehandlercolumn header now says "(deprecated)"; the Status row already did.handler:snippetctx.api.object(name)(the repo, thewherekey, thefilteralias) and Pattern 2 (the related-recordinsert). The prose above it stays.handlerbodywithcapabilities: ['api.write']; bulk writeupdate(fields, { where: { account_id: ctx.previous.id }, multi: true })(review M1:ctx.input.idmade thewhereempty, matching every contact). The comment "Only the sandboxctx.apiaddsupdateMany/deleteMany" goes (false, see § 2).afterFind)handler(seat ruling A). Retitled "(deprecated inlinehandler)" with the reason: abodywrites back onlyctx.input, and itsctx.resultis a snapshot. The field-level-metadata callout is unchanged.handler: 'normalize'+functionsSame defect in the pre-existing bodies (review S3, claim widened 6710683947): Pattern 1 (
beforeDelete) counted open opportunities onaccount_id: ctx.input.id, which is{}on a delete, so it counted across every account; it now keys onctx.previous.id, and its comment says a delete'sctx.inputis empty. Pattern 2 recordedString(ctx.input.id || ''); it now records(ctx.previous || ctx.result || {}).id(previouson update/delete,resulton insert). The three "input.idnames the row" sentences (the "Why so few?" callout, §condition'sbefore*andafter*bullets) now read "input.id(handler; abody:ctx.previous.id)", and the sandboxctx.inputrow saysidis there only if the payload has it.Also, so the page does not contradict itself: the intro and § Sandboxed Hook Bodies no longer say "everything above this point showed the inline
handler"; "Skip handler execution" and "inside the handler" in §conditionbecome hook / body; § Sandbox restrictions labels "a bundledhandler" as deprecated; § Hook Context API says the documentedctxis the deprecated in-processhandlercontext.2. The repository method table teaches only methods the hook's
ctx.apihas (seat ruling, same file)A hook body's
ctx.apiis the engine'sScopedContext(buildSandboxApiSource,body-runner.tsL1208–L1210), whoseobject(name)returnsObjectRepository:find,findOne,insert,create,update,updateById,delete,deleteById,count,aggregateandexecute(which the sandbox does not install,quickjs-runner.tsL705–L708).upsert,updateManyanddeleteManytherefore throwctx.api.object('…').updateMany not implemented. The bulk form is the option:ObjectRepository.update(data, options)passesoptionstoengine.update(engine-object-repository.tsL83–L88), which routes a predicate withmulti: trueto the driver'supdateMany(engine.tsL6147–L6153, L7616);deletethe same way (packages/metadata-core/src/engine-delete-dispatch.tsL72, L133 "Delete requires an ID or options.multi=true").3. Nullable comparisons are guarded
Code site:
packages/lint/src/validate-null-guards.ts; its wiring table (L89) lists the lifecycle hookconditionas covered (hook-wrappers.tsmaterializeDeclaredFields), and L747 makes a hook condition's fault refuse the write.skills/objectstack-formula/SKILL.mdL112–L122 teaches the same rule.record.status == 'active' && record.amount > 1000record.status == 'active' && record.amount != null && record.amount > 1000record.annual_revenue > 1000000record.annual_revenue != null && record.annual_revenue > 1000000os:checkblock)record.amount > 10000 && record.region in ['us', 'eu']record.amount != null && record.amount > 10000 && record.region in ['us', 'eu']Measured, not assumed:
findUnguardedNullableOperands(the gate's decision procedure, run throughtsxwith every named field nullable) returns 1 finding for each "before" predicate and 0 for each "after" predicate.4. § Capabilities links Connector recipes
"outbound calls go through Connector recipes" now links
objectstack-automation/references/integration-recipes.md(relative fromskills/objectstack-data/references/, resolves toskills/objectstack-automation/references/integration-recipes.md), with "(connector_actionin a flow)". The target's recipes are connector declarations dispatched by a flow (recipe 1 is a scheduled flow); arecord-before-*flow gates a write, arecord-after-*or scheduled flow carries a side effect, so the note names no phase (review S1).rules/validation.mdalready sends external-API checks to this section.Token readings (
node scripts/check-skills-token-ratchet.mjs, exit 0)main620b6e6dskills/objectstack-data/references/data-hooks.mdskills/objectstack-formula/SKILL.mdNo ceiling is raised, so the ruling path was not used. No line was re-wrapped. Every deletion, with the facts it held and where each survives:
handlersnippet (main L738–L755). Facts:ctx.api.object(name)returns a repository → §ctx.api.object(name)first paragraph;findOne({ where: { id } })withwherecanonical andfiltera tolerated alias → same section, "Query shape" and thefilter:note; inserting a related record with the session user → Pattern 2 (audit_loginsert,ctx.session && ctx.session.userId); "within the same transaction" and "bodyneedsapi.read/api.write" → the prose kept above it.#### handler — Implementation(main L155–L171). Facts: the inline-function shape → the comparison table's Shape row; the string reference → § Registration Methods (handler: 'normalize'+functions), linked from the new sentence; "throw to abort" → the new section's first line and § Error Handling. "(recommended for simple hooks)" is dropped: it recommended the deprecated door.handler" is no longer true; "the form a metadata-only runtime executes" stays in the new lead.update(data, { where, multi: true })stays in the code and in the method table; "the handler-side repo has noupdateMany" is moot for abody; "only the sandboxctx.apiaddsupdateMany/deleteMany" was false (§ 2).upsertandaggregate · updateMany · deleteMany, and threeapi.writetokens. False (§ 2);aggregatekeeps its own row.asyncbullets "Calling slow external APIs" and "Logging to external systems" (seat ruling). Abodyhas no outbound HTTP; home: § Capabilities → Connector recipes.HookContextimport. Unused once the example is abody.record.x != null, not withhas(record.x)" (home: §condition, "Guard optional values with!= null, never withhas(...)", same file); Pattern 1's trailing comment "count() is a read; an undeclared token throws in the VM" (homes: the method table'scount→api.readrow and § Capabilities "Calling an undeclared one throws inside the VM"); Pattern 2'sasync: false, // must run inside the transactionline (home: §async, "Blocking (default) — runs within transaction" and "When to use async: false: Creating related records"); Pattern 1's old comment "(it is undefined on insert)" (home: the sandboxctx.previousrow).Eval cases
objectstack-data/evals/hooks-security-seeds-datasources.jsoncase 12 (new, body-first, bulk form, row key): copy a changedaccount.industryonto its contacts. The expected answer keys the bulkwhereonctx.previous.idand says why. Must containafterUpdate,language,js,api.write,multi: true,ctx.previous.id; must not containhandler:,HookContext,account_id: ctx.input.id. (updateMany(left the list per N1: an answer explaining the trap may name it.)objectstack-data/evals/hooks-security-seeds-datasources.jsoncase 13 (new, the guard): run a hook only when an optionalannual_revenueis above 1,000,000. Must containcondition:,record.annual_revenue != null,record.annual_revenue > 1000000;must_not_containis empty (per N1,has(record.annual_revenue) &&would fail an answer that explains whyhas()is no guard). The runtime sentence now says it refuses each write on an account with noannual_revenue(review S4).objectstack-formula/evals/cel-predicates-formulas.jsoncase 2 (corrected): itsexpected_outputpredicate was unguarded while its prose asked for the guard; the predicate now carriesrecord.amount != null &&, andmust_containassertsrecord.amount != null(in place of the barerecord.).handler,updateMany/deleteMany/ hookupsert, or an unguarded nullable comparison (cases 7 and 10 already forbidhandler:). Everymust_containstring appears in itsexpected_output, and nomust_not_containstring does.Other sites found (not changed: outside this card's file surface)
skills/objectstack-automation/references/state-machines-and-approvals.mdL90, L128, L133, L135:condition: cel`record.amount > 100000`(and> 500000,<= 500000) on arecord-after-updateflow's start and edges, unguarded and refused (confirmed by the review). Going to a follow-up card.packages/spec/src/data/hook.zod.tsL524–L526: theconditionjsdoc@exampleand.describe()showrecord.amount > 1000unguarded, published tocontent/docs/references/data/hook.mdx. Going to a follow-up card.skills/objectstack-formula/SKILL.mdL57: thecelrow's examplecel`record.amount * 1.1`multiplies a possibly-null field. It is a computed value in a reference table, not a predicate the gate judges.Deviations (all accepted by the seat before writing)
handler, labelled deprecated (seat ruling 1, option A): abodycannot rewritectx.result.upsert/updateMany/deleteManycorrection (§ 2), the L105 guard, the twoasyncbullets.ctx.previous.id, and the "input.idnames the row" prose scoped to thehandler. The sandboxctx.inputrow ("plusid") states the same claim for a body, so it was scoped in the same commit.Review round 1 (contract review 6710673767, FAIL at 9931ab6)
ctx.previous.id; case 12 forbidsaccount_id: ctx.input.id). S1 fixed (no flow phase in the Connector recipes note). S2 accepted by the seat as a headroom draw. S3 fixed under the widening. S4 fixed. N1 applied (quote-freemust_contain, trap-explaining strings offmust_not_contain). N4 and N5 corrected in this body. N2 and N3 skipped by the seat's word.ctx.resultandctx.inputcarryid; it now reads "(ctx.resultaddsid)" (9b1e926, +4 tokens from headroom: 9901 → 9905). N2 left as is.origin/mainhad moved 5 commits past the base620b6e6dat review time (3c1eb635,8acbfab9,bd5a443c,150f7401,658d84f5), none touching these files; merged into the branch with the fix (merge commit, no rebase).Verification
Local gates on 9931ab6: 46 derived, 46 exit 0, 0 NOT MEASURED
node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstackderived 46 commands for the 5 changed paths; each ran after a fullpnpm build(exit 0) underNODE_OPTIONS=--max-old-space-size=8192, with its exit code captured before any pipe.dispatch-gates --ranreconciles: 46 derived, 46 run, 0 NOT-MEASURED, 0 UNRUN. All 46 exited 0, includingcheck:skill-identifier-liveness,check:skill-compatibility,check:skill-frame-sync,check:skill-docs,check:skill-refs,check:doc-authoring,check:corpus-claim-drift,check:role-wordand the token ratchet.pnpm check:skill-top-level-keys(an artifact-roster family, not derived): exit 0.pnpm --filter @objectstack/spec run check:skill-examples(theos:checkgate; not derived): exit 0,285 prose examples type-check across 3 surface(s).node scripts/check-skills-token-ratchet.mjs: exit 0,57 authored bundle file(s) within their ceilings.node scripts/check-commit-card-trailers.mjs --range origin/main..HEAD: exit 0 before the push.origin/mainmerge): the token ratchet,check:skill-refs, both eval JSON files parse,check-commit-card-trailers,check:skill-identifier-liveness,check:skill-top-level-keys,check:doc-authoring,check:corpus-claim-drift,check:role-word, and@objectstack/specbuild +check:skill-examples(285 prose examples type-check): all exit 0.Human Minimum
packages/specholds no runtime logic. (No schema touched.)main, one pull request.'@objectstack/skills': patch), and both declaration lines are filled in here and in the changeset.packages/specnot touched; nothing to regenerate.content/docs/references/,packages/*/CHANGELOG.mdorcontent/docs/releases/.🤖 Generated with Claude Code
https://claude.ai/code/session_01J8VVAnzH4vvvJVUf6zdYe9