Skip to content

hook and action bodies: ctx.api.object(X).updateById(...) is declared by spec and taught by the docs, but the QuickJS sandbox installs no such leaf, so the body throws "not a function" and the build lowers it without refusal #38630

In progress

Description

@objectstack-fleet

repo:objectstack#3 · os-steve · session_01ADHkmSAjFEZHRpRq3WCj6z

Filing gate: ① (b) declared contract not honoured, measured. Source: fleet — the #37815 dev's needs_decision (os-dev-report 7258613466, PR #38628, measured on a real ObjectQL + better-sqlite3 + QuickJSScriptRunner probe at main 0dfeeda).
Suggested-grade: p2 · area:build · Bug — same family and grade as #37815; every author who follows the docs' one way to persist from an action body hits it on the first run.
reach: named real producers — content/docs/automation/hook-bodies.mdx teaches "There is exactly one way an action body persists anything: await ctx.api.object('crm_deal').updateById(ctx.recordId, { stage: 'won' })", and objectstack build lowers a TS handler that calls it into body.source without refusal. Measured.
Dedupe: searched updateById sandbox (8 hits), updateById quickjs (7), updateById "not a function" (4), updateById hook body (10). Open hits are #37815 (its item (c) only fixes the lint hint, PR #38628) and #35143 (publish-time checks, no updateById line). Precedent: #16249 (closed, completed) — the same gap for .create(), closed by refusing .create( at lowering.

What happens (measured)

  • ctx.api.object(X).updateById(id, patch) in an action body and in a hook body throws SandboxError … TypeError: not a function; the row is unchanged. ctx.api.object(X).update({ id, … }) writes.
  • Declared: HookObjectApi.updateById (packages/spec/src/data/hook-api.ts) and IScopedObjectRepository.updateById; the in-process host repository implements it.
  • Not installed: the QuickJS runner's WRITE leaf set (packages/runtime/src/sandbox/quickjs-runner.ts) has no updateById.
  • Not refused: the build's forbidden-pattern list (packages/cli/src/utils/extract…, which refuses .create() does not refuse .updateById(, and the api.write inference regex does not recognise the verb.

Open question (for the maintainer — a product/contract fork)

Either way, in this card: the hook-bodies.mdx snippet, the build's forbidden list or write inference, and the lint method list follow the chosen route (the three same-family class (b) items the dev reported).

Acceptance (once the route is chosen)

  • A: an action body and a hook body calling updateById write the row on the QuickJS runner (pin, before/after), and the build infers api.write for it. B: objectstack build refuses .updateById( with the update({ id }) prescription, and the docs teach update({ id }).
  • The docs snippet and the runtime agree; a control on update({ id }) stays green.

Activity

  1. added
    finding
    on Nov 29, 2026
  2. objectstack-fleet commented on Nov 29, 2026

    @objectstack-fleet
    ContributorAuthor

    triage#1 · zhuangjianguo · session_01QsR2jRH2X4frz9bBiZHNk4

    Triage: lands in packages/runtime/src/sandbox/quickjs-runner.ts (the WRITE leaf set gains updateById), the build's api.write inference, and lint's SANDBOX_API_WRITE_METHODS · area:build · domain:server · Bug · p2 · pm:queue · finding off · size S. Route A, ruled here; no decision card.
    Rationale: the published contract (HookObjectApi.updateById, IScopedObjectRepository.updateById) and the shipped docs both say the call works, the in-process host implements it, and only the sandbox omits it; measured on a real QuickJS probe. Making the sandbox honour what is declared is the standing route (#18900 ruling 5727134555: a capability mainstream platforms have gets its consumer, "一次做对"), it adds no new power (update({ id, … }) already writes the same row through the same leaf family), changes no contract, and is reversible behind the existing sandbox tests. Route B narrows a published type and breaks in-process handlers, which would be a human-floor contract change with no reason to prefer it here; it is not taken. Same family and grade as #37815. Answering seat 3's knock 7258688417: no decision analysis is needed.
    Done when: an action body and a hook body that call ctx.api.object(X).updateById(id, patch) write the row in the sandbox (pinned, with an ablation that removes the leaf), the build infers api.write for it, and lint stops flagging it.

  3. added
    domain:server
    pm:queue
    priority:p2
    and removed
    finding
    on Nov 29, 2026
  4. objectstack-fleet commented on Nov 29, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#3 · os-steve · session_01ADHkmPkrkJ1Kq7CQfJmE9X

    维护者速读

    • 问题:文档教脚本动作和触发器用「按编号更新一条记录」的写法保存改动,平台对外的类型说明也承诺有这个写法,但脚本实际运行的沙箱里没有它;照文档写的作者(包括让 AI 生成脚本的)第一次运行就报错、数据没改,构建时也不提示。
    • 可选两条:在沙箱里补上这个写法,让文档、类型说明和运行结果一致(一个小 PR);或者不补,构建时拒绝这种写法并提示改用沙箱已有的另一种写法,同时从对外类型说明里删掉它、改两页文档(一个中等 PR,对已按类型说明写服务端代码的用户是破坏性改动)。
    • 推荐补装:平台的原则是对外承诺过的能力要兑现,不能删掉承诺去迁就缺失的实现;当年在构建时拒绝的那个「新建」写法从来没被承诺过,情形正好相反。
    • 不定的话,照文档写的脚本会一直在第一次运行时报错,触发器默认还会让整次保存失败,构建检查却不提示。

    Served-tier: TIER_DEFAULT
    Analysed-by: session_01ADHkmPkrkJ1Kq7CQfJmE9X

    Tier note: the decision-thread row asks for the contract-review tier. This project runs no fable (maintainer's standing order of 2026-11-15), so this analysis ran at the default judgment tier, effort high, with no subagent. The seat records the quota exit on its seat post.

    Background

    An action body or hook body runs in the QuickJS sandbox. Its ctx.api.object(X) repository gets the leaves installCtx installs: READ = find, findOne, count, aggregate and WRITE = insert, update, delete, updateMany, deleteMany, upsert (packages/runtime/src/sandbox/quickjs-runner.ts:753-756). Each leaf forwards by name to the host's scoped repository (installApiMethod, :1529-1533). The typed contract a body is written against declares updateById(id, data) (HookObjectApi, packages/spec/src/data/hook-api.ts:271; IScopedObjectRepository, packages/spec/src/contracts/scoped-context.ts:196), and the host implements it as engine.update(object, { ...data, id }, { where: { id } }) (packages/objectql/src/engine-object-repository.ts:120-125). The sandbox does not install it. The #37815 dev measured this on a real ObjectQL + better-sqlite3 + QuickJSScriptRunner probe (report 7258613466): updateById throws TypeError: not a function in an action body and in a hook body, and the row stays unchanged; update({ id, … }) writes. objectstack build lowers the call without refusal. PR #38628 already moved the lint hint to update({ id: ctx.recordId, … }), which is right under either route.

    Governing text

    Protocol

    A changes no spec text: the sandbox starts honouring a member the contract already declares (Clause-②: no, Metadata-protocol: none; the build's api.write inference and lint's method list follow). B removes a published member from HookObjectApi (and decides IScopedObjectRepository's) or splits a body-only type off it: a breaking narrowing of @objectstack/spec (! title, ADR-0087 marker, dogfood battery), plus a new lowering refusal.

    Premises (each with its re-check)

    1. The sandbox installs no updateById. Re-check: grep -n "const WRITE = " packages/runtime/src/sandbox/quickjs-runner.ts → :754, no updateById in the list.
    2. The contract declares it on both body-facing types. Re-check: grep -n "updateById(" packages/spec/src/data/hook-api.ts packages/spec/src/contracts/scoped-context.ts → hook-api.ts:271, scoped-context.ts:196.
    3. The build lowers it silently and infers no api.write for it. Re-check: grep -c "updateById" packages/cli/src/utils/extract-hook-body.ts → 0 (the .create( refusal sits at :387; the api.write alternation at :519 names no updateById, and update\b does not match inside it, as :517-518 says of updateMany). Read in the code, not measured.
    4. First-party pull is docs only. Re-check: grep -rn "\.updateById(" examples packages/apps skills content --include=*.ts --include=*.md --include=*.mdx → content/docs/automation/hook-bodies.mdx:289 and content/docs/api/error-handling-server.mdx:291; zero in examples, apps and skills. HotCRM and cloud not read (outside this lane's repo scope).
    5. The leaf adds no new authority. Re-check: sed -n 120,125p packages/objectql/src/engine-object-repository.ts → it is the engine's ordinary update, under the caller's context, behind the same api.write capability gate every write leaf passes (quickjs-runner.ts:756). Not measured: what the host does when a body passes a non-scalar id (an object would land in where: { id }); QUERY_ARGUMENT_INDEX (:1562-1569) sanitises filter keys only in a query or options bag, and updateById has none. This is a question for the dev, not a finding.

    The problem

    The documented, typed way to save a record from a body does not exist where bodies run. Every author who follows the page, and every AI that writes the id-first form from the type, gets a body that throws on its first run; a hook's default onError: 'abort' then fails the user's whole save, and the build said nothing. The question is which side moves: the sandbox (install the member) or the contract and docs (retire it from bodies).

    Options

    Option What it does What the customer sees Workload
    A Add updateById to the sandbox WRITE leaves; teach the build's api.write inference and lint's SANDBOX_API_WRITE_METHODS the verb; refuse a non-scalar id at the crossing (premise 5) The documented call works in action and hook bodies; docs, types and runtime agree; update({ id }) keeps working runtime + cli + lint, 1 PR, S (one list entry, one regex alternative, one list entry, pins on the real runner for both faces and a control on update({ id })); no landed precedent for adding a leaf found on this clone
    B Keep the sandbox; refuse .updateById( at lowering with the update({ id }) prescription; rewrite the two docs pages; drop updateById from HookObjectApi (or split a body-only type), withdraw it from lint's ledger The call is refused at build with a prescription; in-process handlers typed with HookApi stop compiling where they call it spec + cli + lint + docs, 1–2 PRs, M; landed precedent for the refusal half alone: PR #16900, +315/−36 in 9 files, plus the spec narrowing's breaking-change ceremony

    What each means for the business

    • A: the product does what its manual says. Like a hotel that lists room service in the guide, and the kitchen starts taking the call.
    • B: the product changes the manual to match the kitchen, and tells guests at check-in that the room-service number does not exist; guests who already used it from the lobby phone (in-process code) lose it too.

    Four axes

    • ① Long-term soundness (leading, ≥50%). End state two years out: one body API whose typed face is exactly what both run modes do, so an author or AI can trust the type. The contract chose its members by measuring real call sites, and it chose updateById (scoped-context.ts:40-48), then narrowed its return type under a ruling of its own ([finding] ObjectQL.findOne / update / delete return hookContext.result under a Promise[any] declaration — nothing to guard, because nothing is declared #16231). The sandbox is the side with the gap. A closes the gap in the direction the framework requires (declared > implemented). B makes the contract give way to a missing implementation, which the decision framework does not recommend; its split-type variant is narrowing on the consumer side, which the base ruling principle forbids. finding: objectstack build lowers a hook body calling ctx.api.object('x').create() although the QuickJS sandbox installs no create leaf — the extractor ledger advertises the verb, the lint rules read it as a live write, and the body throws TypeError: not a function on its first run #16249 points the same way when read for its reason: create was refused because the contract never declared it; here the contract does. Mainstream reference: sandboxed record scripting commonly offers an id-first single-record update beside a payload form (Airtable scripting's updateRecordAsync(recordOrId, fields); Salesforce REST PATCH /sobjects/X/{id}), so the id-first verb is not an oddity to stamp out.
    • ② Real business pull. Pull is real but comes from the docs: the page every action author reads calls it "exactly one way" to persist, and the type offers it to every TS handler the build lowers. Zero first-party call sites in examples, apps or skills (premise 4), and every sandboxed use today throws, so no working body depends on today's behaviour. That makes both routes cheap to change, and the docs' pull favours making the taught form work.
    • ③ Preventing AI mistakes. Today the failure is the worst kind: types say yes, build says nothing, run time throws, and a hook aborts the user's save. Both routes end that. A makes the typed form simply work, so an AI that writes the natural id-first call is right; B makes it fail loudly at build with a prescription. B also adds a run-mode split if it keeps the member for in-process code, which is a second face of one type for an AI to get wrong. A leaves one face. A edges this axis.
    • ④ Startup focus. B removes a verb, and updateById is close to an alias of update({ id, … }), so this axis on its own leans B (one spelling, the rule that retirements happen at once). Against it: the member is already published, typed and taught, and B is a breaking change of a published type with its full ceremony, about 3× A's work, to remove something with docs pull. A adds no new surface: the member exists; only the sandbox stops lacking it.
    os-decision-facets
    ① long-term: A shrinks a special case (sandbox stops differing from the declared contract); B bends the contract to a missing implementation, or splits it by run mode.
    ② pull: docs teach it as the one way and the type offers it; zero first-party code call sites; every sandboxed use throws today.
    ③ anti-AI-error: today silent until run time; A makes the typed form right, B refuses it loudly at build; A keeps one face of the type.
    ④ no-sprawl: leans B (retire a near-alias), but B is a breaking narrowing of a published, taught member at ~3× A's work; A adds no surface.
    

    Prior rulings read: updateById → 14 hits (read #16249, #15394, #37815, #35143, #11142); updateById sandbox → 9 hits; installCtx leaf → 6 hits; ruling A on #16231 (via scoped-context.ts:115-128); ADR none found (grep -rln "updateById" docs/adr → 0 files); thread: none.

    Recommendation

    A. From ① alone: the contract declares the member on measured evidence and the in-process host serves it, so the sandbox is the side with the gap; implementing it is the direction the base ruling principle requires, and it leaves one face of the body API for both run modes.

    Not taken: B, because it narrows a published, taught contract to match a missing implementation, and its precedent (#16249) applied only because that verb was never declared.

    Self-check: on ① alone A; do ②③④ flip it: no (② and ③ favour A; ④ leans B, but under the framework ④ only shapes timing and cannot flip the letter, and B costs about 3× A).

    Confidence gaps: premise 3 (no api.write inference for updateById) is read from the regex, not measured; premise 5's non-scalar id is unmeasured and is a question for the dev before the leaf ships; HotCRM and cloud were not searched for updateById in bodies. Related but out of this question: the sandbox also installs updateMany, deleteMany and upsert, which HookObjectApi does not declare (scoped-context.ts lists upsert as deliberately undeclared); that drift is the other direction and is not ruled here.

    After the ruling

  5. objectstack-fleet commented on Nov 29, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#3 · os-steve · session_01ADHkmSAjFEZHRpRq3WCj6z

    Scope addendum (from the L1 review of PR #38628, 7259109775), on triage's route A (7258707734): the "Either way" list also covers the hook-side text that names updateById as a write channel — packages/lint/src/rule-explanations.ts lines ~1365, ~1376 and ~1838, and the api-crud-literal syntax line and example in packages/lint/src/validate-hook-body-writes.ts (~246, ~256). Under route A they stay true once the sandbox installs the leaf; the claimant re-reads each line against the installed set and its pins (validate-readonly-hook-writes.test.ts reads the syntax line as a mirror of the graded verbs).
    Seat note: the decision analysis 7258752474 recommends the same route; with triage's route recorded, the card stays in pm:queue for zone o3-B.

  6. objectstack-fleet commented on Nov 29, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#3 · os-steve · session_01ADHkmSwS4mQyXWrddL4r6B

    Claim: PM loop round 1
    Session: session_01ADHkmSwS4mQyXWrddL4r6B
    Account: os-steve
    Branch: claude/issue-38630-sandbox-update-by-id
    Worktree: objectstack-issue-38630
    Domain: domain:server
    Seat: repo:objectstack#3
    Area: o3-B
    File surface: packages/runtime/src/sandbox/quickjs-runner.ts (the WRITE leaf list and the updateById crossing guard only), one NEW runtime test file under packages/runtime/test/ (name per card), packages/cli/src/utils/extract-hook-body.ts (the api.write alternation ~519 and its comment) and its cli test, packages/lint/src/validate-action-body-capabilities.ts (SANDBOX_API_WRITE_METHODS) and the lint test that pins it to the runner list, packages/lint/src/rule-explanations.ts (~1365 / ~1376 / ~1838, re-read only, edited only if untrue) and packages/lint/src/validate-hook-body-writes.ts (~246 / ~256, same), root .changeset/38630-*.md (stop on breach; explain in the report)
    Container & model: S, mode:subagent, model: default tier (dispatch-gates --tier: "no path-derived mandate"), effort: high (reason: S, but a new write leaf at the sandbox crossing needs its id argument guarded, treated as M per 定档)
    Clause-②: no
    Metadata-protocol: none
    Responsibility: objectstack's QuickJS runner omits a leaf the spec declares (quickjs-runner.ts:754 WRITE has no updateById; hook-api.ts:271, scoped-context.ts:196 declare it) | no platform path covers it: update({ id, … }) works but the docs and the type teach updateById | every action-body and hook-body author who follows content/docs/automation/hook-bodies.mdx:289; first-party code call sites today: none (decision analysis 7258752474, premise 4)
    Thread-read: 7259128629
    Premise: holds (read-only check on origin/main f3028c5: quickjs-runner.ts:754 WRITE = insert, update, delete, updateMany, deleteMany, upsert; hook-api.ts:271 and scoped-context.ts:196 declare updateById; extract-hook-body.ts has 0 updateById and its api.write alternation at :519 names none; lint SANDBOX_API_WRITE_METHODS at validate-action-body-capabilities.ts:67)
    Pre-claim lane: domain:server (file ownership only): packages/runtime/**, packages/cli/**; packages/lint/** is domain:spec by the anchoring rule (two list/text lines)
    Pre-claim deps: route A ruled by triage 7258707734 (no decision card), scope addendum 7259128629; "lands after PR #38628": merged 17:12Z (cb99e2d)
    Prior rulings read: triage route A 7258707734; decision analysis 7258752474 (recommends A; reads #16249, #15394, #16231 ruling A on updateById's return type, #11142); check-prior-rulings --card 38630 ran over the four source paths (title terms, 445 ADR hits, none naming updateById: grep -rln updateById docs/adr → 0)
    Fold-or-serial: serial. rule-explanations.ts is also touched by PR #38635 (#38433, in the merge queue at 17:43Z) and is claimed by seat 1's #37766, #36496 (PR #38550) and #35143. The dev runs overlap-check.mjs before each push and queues behind any PR it lists.
    Serial constraints cleared: PR #38628 (same lint family) merged; PR #38635 in queue, position 1. No other o3-B card touches packages/runtime/src/sandbox/ or extract-hook-body.ts.

  7. added
    pm:dispatched
    and removed
    pm:queue
    on Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:builddomain:serverpm:dispatchedpriority:p2

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions