Skip to content

[finding] A record payload field named id/options/ast/data reads back the WRAPPER's value through the flat-input proxy while its descriptor reports the PAYLOAD's — get and getOwnPropertyDescriptor disagree on the same key #12601

Closed

Description

@os-warren

Found while implementing #12578 (the ownKeys own-key set). Unassigned, observation class — no measured consumer, and the repair is a contract decision rather than a mechanical one, so it is recorded rather than ridden along. Filed from the #12578 lane per its out-of-scope rule; the bounded in-place exemption does not apply because the correct shape is not pinned by existing evidence (see "Why it is not mechanical").

What it does

installFlatInput (packages/objectql/src/hook-wrappers.ts) gives the four wrapper keys id / options / ast / data precedence in the get trap — they resolve against the envelope, never the payload:

get(target, prop, receiver) {
  if (prop === 'id' || prop === 'options' || prop === 'ast' || prop === 'data') {
    return Reflect.get(target, prop, receiver);   // <- the WRAPPER
  }
  …
}

The descriptor trap orders the two the other way round — it consults data first, and only falls through to the wrapper branch when data does not own the key:

getOwnPropertyDescriptor(target, prop) {
  const data = target.data;
  if (data && typeof data === 'object') {
    const own = Object.getOwnPropertyDescriptor(data, prop);
    if (own) return { ...own, configurable: true };   // <- the PAYLOAD
  }
  …
}

So for a record whose payload genuinely carries a field called id, the two traps answer about the same key from two different objects.

Measured

Driven through wrapDeclarativeHook against the real proxy, on origin/main at f93df4dbe3 (an update-shaped envelope: wrapper id bound, payload also carrying an id field):

const raw = { data: { id: 'PAYLOAD-ID', subject: 'help' }, options: {}, id: 'WRAPPER-ID' };

input.id                                        // 'WRAPPER-ID'   <- get trap, wrapper
Object.getOwnPropertyDescriptor(input, 'id').value  // 'PAYLOAD-ID'   <- descriptor trap, payload
Reflect.ownKeys(input).includes('id')           // true           <- listed, from `data`

id is listed by ownKeys (it is read off data, and the wrapper-key exclusion works by reading data rather than by subtracting those four names — correctly, since a payload field named id is a genuine record field). It is listed with the payload's descriptor and read with the wrapper's value.

The consequence worth naming is that the split reaches ordinary copying, because a spread reads keys from ownKeys, filters them through the descriptor trap, and then takes values through get:

{ ...input }.id       // 'WRAPPER-ID'  — the copy carries the envelope's id under a payload field's name
Object.entries(input) // same: ['id', 'WRAPPER-ID']

Object.entries over this proxy is exactly what unwrapProxyToPlain (packages/runtime/src/sandbox/body-runner.ts) runs to build a hook body's ctx.input, so a sandboxed body on such an object would read the envelope id as its field value.

Why it is not mechanical

Which side should win is a contract question, not a spelling choice, and the two candidate answers differ in what they assert about the payload:

  1. Wrapper wins consistently (make the descriptor trap check the wrapper keys first, matching get) — then a genuine payload field named id becomes unreadable and unlistable through the flat face, and ownKeys has to stop listing it too, or the disagreement just moves to a third instrument.
  2. Payload wins consistently (make get check data first for these four names) — then input.id stops meaning "the row this write targets" on every update hook that has a same-named field, which is a documented spelling (packages/spec/src/data/hook.zod.ts's envelope table, and D4's HookTargetRebindError reasoning).

Option 2 in particular collides with an existing ruling, so this is not a case where one answer is obviously the truthful one. It also depends on whether an object may declare a field named id at all (and options / ast / data) — a question about what a record payload may hold, which #12397 fenced off as a maintainer floor.

Scope note

Distinct from #12578, which is the same trap set but a different mechanism: that card is enumeration-vs-descriptor disagreement caused by enumerable filtering, and its fix (landing on claude/issue-12578-ownkeys-own-key-set) does not touch wrapper-key precedence in either direction. This one is get-vs-descriptor disagreement caused by the two traps ordering the wrapper and the payload differently. The measurement above was taken both before and after that fix with identical results.

Dedup

Local grep across packages/** and docs/** for the wrapper-key collision — no in-tree record. The contract's prescribed REST dedup channel returned 403 (GitHub access is not enabled for this session) for this session too, which is #12293's shape, so the issue scan went through the MCP list endpoint (60 most recently created open issues) — declared rather than reported as a clean REST search.

Activity

  1. added
    finding
    domain:engine
    on Aug 26, 2026
  2. added
    needs-user-decision
    and removed
    finding
    on Aug 26, 2026
  3. added theissue type on Aug 26, 2026
  4. claude commented on Aug 26, 2026

    @claude
    Contributor

    分诊定级:观察卡入决策箱(finding 摘除,挂 needs-user-decision,type Bug)

    分诊座位,session session_01VuzvqsYQDYg8pLnGicpciV(2026-08-26 小时增量轮)。定级依据:卡面自证修法是契约选择而非拼写修正,且选项之一与既有裁决相撞——协议行为变化 + 触既有裁决,双重人工地板,不入代裁面。

    <!-- os-decision-facets -->

    一句话问题:一条钩子输入记录里若有个字段恰好叫 id(或 options/ast/data),同一个对象用两种标准读法会得到两个不同的值——直接取值拿到"这次写操作指向哪一行"的信封值,而拷贝/枚举(spread、Object.entries,沙箱钩子体正走这条路)读到的却来自记录本身。哪一边是对的,是契约选择。

    选项 × 真实代价:

    • A(信封一致胜出):四个保留名恒指信封,payload 同名字段从扁平面隐身,要读走 input.data.id。业务上 = 平台保留字(像 Salesforce 的系统字段 Id)。代价:已声明同名业务字段的对象在钩子扁平面读不到该字段,需响亮文档化。
    • B(payload 一致胜出):被记录声明的名字指记录。业务上 = 用户字段优先。代价:input.id 不再恒等于"写目标行",与 hook.zod.ts 信封表及 D4 HookTargetRebindError 的既有裁决相撞——等于推翻一条已落地裁决。
    • C(契约层拒收这四个名字):payload 声明保留名即编写期响亮报错。业务上 = 命名规则前移到建模时刻。代价:存量已用这些名字的元数据一律要迁移;且"payload 可否声明这些名字"正是 [finding] The flat-input Proxy's getOwnPropertyDescriptor synthesises a descriptor instead of mirroring data's — now reachable, since #12277 routed defineProperty into data #12397 关单时圈给维护者地板的前置问,本卡不能替它答。

    四棱:

    • ① 项目长远合理性:A 把特例收敛成"四个保留名"一条闭合规则;B 让信封语义随记录形状漂移,契约面增生。
    • ② 实际业务拉动:尚无实测撞上的用户(观察类);但 unwrapProxyToPlain 是每个沙箱钩子体的必经路,一旦有对象声明 id 字段即静默读错——不是投机面,是已量测的分叉。
    • ③ 防 AI 犯错:今天两读法答案不一致,AI 写钩子时 spread 与直读混用即埋雷且零报错;A/C 都收敛为单一答案,C 最响亮(编写期拒收),B 静默改变既有语义、出错时没人看到任何信号,最危险。
    • ④ 创业阶段不扩散:三个选项都不新增声明面,成本在一次修法与文档;C 额外背存量迁移义务。

    推荐 A,回退 C(若维护者裁定 payload 本就不得声明这四个名字,A 的修法退化为 C 的拒收实现)。置信缺口:本分析看不见存量元数据与真实部署里是否已有对象声明这四个字段名(无全量元数据扫描);也看不见与 #12603(同族 SYMBOL 键枚举决策卡,已在箱)合裁时的交互形状。

    裁后执行(维护者不用管):A ⇒ 立执行卡归 domain:engine(descriptor/ownKeys 与 get 对齐 + 回归用例,与在飞 #12578 的落地串行);B ⇒ 先撤 D4 裁决再动(不推荐);C ⇒ 契约拒收半边转 domain:spec 席,engine 侧对齐随后。状态转换由分诊同笔落地。

    相关:#12578(同 trap 集不同机制,在飞;其修法两向实测不动保留名优先级)· #12603(同族决策卡,建议同批裁)· #12397(已关;选项 C 的前置问在该卡圈为维护者地板)。


    Generated by Claude Code

  5. os-zhuang commented on Aug 27, 2026

    @os-zhuang
    Contributor

    Maintainer ruling recorded — Option A: the envelope wins consistently; the four names are platform-reserved on the flat face

    Provenance: maintainer, 2026-08-27, PM chat decision-inbox batch 6 (adjudication session session_01DKWDdUJ2XNRESVVWUvcpnh), verbatim: 「其他同意」 — accepting the triage recommendation A (2026-08-26T17:10Z facet block), ruled together with #12603 as one family.

    Ruled: id / options / ast / data are reserved names on the hook flat-input face — the getOwnPropertyDescriptor and ownKeys traps align with get (envelope first), so all three instruments answer from the same object. A payload field carrying one of these names remains a legal record field, readable via input.data.<name> — loudly documented at the trap and in the hook envelope docs. ⛔ B (payload wins) declined: it would overturn the D4 HookTargetRebindError ruling and silently change input.id's meaning on every update hook. C (contract-level refusal of the four names) stays the recorded fallback if a later ruling decides payloads may not declare them at all.

    Dispatch notes: lands with a regression case per instrument (get / descriptor / ownKeys / spread all agreeing on the envelope value, and input.data.<name> returning the payload's); serialize behind #12578's landed fix on the same trap set; the unwrapProxyToPlain sandbox path gets the pinned consequence case (a sandboxed body reading a same-named field sees the envelope value — now by contract, not by accident).

    State: needs-user-decision → pm:queue.


    Generated by Claude Code

  6. added
    pm:queue
    and removed
    needs-user-decision
    on Aug 27, 2026
  7. os-zhuang commented on Aug 27, 2026

    @os-zhuang
    Contributor

    PM — the serial hold has expired; this card is dispatch-ready

    domain:engine PM seat (#6367). Recording a measurement rather than claiming: no dispatch slot is free (batch:3), so this is prep so the next seat to pick it up does not re-derive it.

    The maintainer's ruling (comment 5434984840, Option A) attached a sequencing condition: "serialize behind #12578's landed fix on the same trap set." That condition is now met, and I checked it by content on origin/main rather than by #12578's closed state:

    packages/objectql/src/hook-wrappers.ts:652
        ownKeys(target) {
          return target.data && typeof target.data === 'object'
            ? Object.getOwnPropertyNames(target.data)
            : [];
        },
    

    Object.keys → Object.getOwnPropertyNames. That is #12578's fix, landed via PR #12602. Control: installFlatInput greps 2× in the same file, so the instrument is live and the reading is not a false zero.

    One detail worth carrying into the dispatch, because it changes what this card has to do: #12578 landed getOwnPropertyNames — own string keys — and not Reflect.ownKeys. So symbol keys are still not exposed through the proxy, and #12603 stays genuinely open rather than having been silently answered by its sibling. Whoever implements this card must not "tidy" that call to Reflect.ownKeys on the way past: that is #12603's decision, not this one's, and taking it here would resolve an open maintainer question as a side effect.

    What the ruling asks for, restated as scope

    • Align getOwnPropertyDescriptor and ownKeys with get — envelope first for id / options / ast / data, so all three instruments answer from the same object.
    • A payload field carrying one of those names stays a legal record field, reachable at input.data.<name>. Document that loudly at the trap and in the hook envelope docs.
    • A regression case per instrument: get, getOwnPropertyDescriptor, ownKeys, and spread all agreeing on the envelope value, plus input.data. returning the payload's.
    • The unwrapProxyToPlain consequence case gets pinned: a sandboxed body reading a same-named field sees the envelope value — now by contract rather than by accident. That pin is the load-bearing one; it is the path the original finding measured, and it is the one that would silently regress.

    ⛔ Not in scope: option B (declined — it would overturn the D4 HookTargetRebindError ruling), and option C's contract-level refusal of the four names (recorded fallback only, and its prerequisite is #12397's maintainer floor).


    Generated by Claude Code

  8. added
    pm:dispatched
    and removed
    pm:queue
    on Aug 27, 2026
  9. self-assigned this
    on Aug 27, 2026
  10. os-zhuang commented on Aug 27, 2026

    @os-zhuang
    Contributor

    Claim: domain:engine PM seat (#6367), session session_01LZbWd2jNV1FErXTPSS4Dry, branch claude/issue-12601-flat-input-wrapper-key-precedence.

    Dispatching at the maintainer's ruling (comment 5434984840, Option A). The serial hold on #12578 is measured as expired — evidence in my previous comment, checked by content on origin/main rather than by #12578's closed state.

    Re-stating the two fences that matter most, because both are ways this card could quietly do someone else's work:

    ⛔ Do not touch ownKeys' getOwnPropertyNames → Reflect.ownKeys. #12578 landed own string keys deliberately; symbols are #12603's open question. Changing it here answers a live maintainer question as a side effect.

    ⛔ Option B is declined and option C is a fallback, not this card. The ruling is envelope-first alignment only.


    Generated by Claude Code

  11. os-zhuang commented on Aug 27, 2026

    @os-zhuang
    Contributor

    os-dev-report

    {
      "issue": 12601,
      "status": "done",
      "branch": "claude/issue-12601-flat-input-wrapper-key-precedence",
      "head": "6e1297bc42d05659eaf68fc65de3d38f17141b30",
      "pr": "https://github.com/objectstack-ai/objectstack/pull/12752",
      "clause2": "Rejects an inconsistency, does not widen the surface. No field, key, capability, or export is added or removed. The wrapper-first precedence rule already existed in `get` (and in the pre-existing `ownKeys` \"WRAPPER KEYS remain excluded\" design intent) -- this PR extends that SAME existing rule to `getOwnPropertyDescriptor` so it stops disagreeing with its siblings. If anything the change is a narrowing: a payload field colliding with one of the four reserved names was PARTIALLY reachable through the flat face before this fix (via a direct descriptor read only, inconsistently with every other instrument) and is now reachable through NONE of the flat face's instruments -- only through `input.data.NAME`, which was always the documented route. `ownKeys` itself is byte-for-byte unchanged (the dispatch fence held).",
      "premise_still_valid": true,
      "premise_readings": {
        "note": "Re-driven through wrapDeclarativeHook against the built @objectstack/objectql dist on origin/main (34d30118c), before any edit, per the dispatch's repro script.",
        "input.id (get)": "WRAPPER-ID",
        "Object.getOwnPropertyDescriptor(input,'id').value (descriptor)": "PAYLOAD-ID -- disagreed with get, exactly as the issue reported",
        "Reflect.ownKeys(input).includes('id') (ownKeys)": true,
        "{...input}.id (spread)": "WRAPPER-ID -- already agreed with get before this fix",
        "input.data.id": "PAYLOAD-ID"
      },
      "ablation": {
        "prediction_commit": "0554527ca (test(objectql,runtime): pin #12601 envelope-precedence regression, pre-fix) -- test files written and run against unmodified origin/main BEFORE the fix commit (a424bf4ec) existed",
        "predicted_vs_observed": {
          "packages/objectql/src/hook-input-envelope-precedence.test.ts": {
            "predicted": "5 failed / 2 passed -- named set: REPRODUCTION id, options, data(nested field), ast, and the insert-shaped EDGE CASE fail; POSITIVE CONTROL and the non-collision DECLARED case pass",
            "observed_pre_fix_baseline": "5 failed / 2 passed -- exact named-set match",
            "observed_in_formal_ablation_revert (post-fix, hook-wrappers.ts mutated back to the pre-fix blob)": "5 failed / 2 passed -- exact named-set match, byte-identical failure messages to the baseline"
          },
          "packages/runtime/src/sandbox/hook-input-envelope-precedence.integration.test.ts": {
            "predicted": "already green pre-fix ('by accident' per its own header) -- NOT a discriminator",
            "observed_pre_fix": "2 passed, 0 failed",
            "observed_post_fix": "2 passed, 0 failed -- unchanged, now 'by contract' per the fixed descriptor trap"
          }
        },
        "mutation_proof": "anchored grep for the post-fix trap comment ('RESERVED-NAME PRECEDENCE mirrors `get`: checked FIRST') = 0 hits after mutation; anchored grep for the pre-fix comment ('Wrapper keys: still descriptors so `prop in input` works') = 1 hit after mutation; `git diff HEAD --stat` on the file non-empty (77 deletions / 6 insertions) during the mutated window",
        "restore_proof": "git checkout HEAD -- FILE (never bare); git diff HEAD -- FILE empty both times; git hash-object FILE == 26a035dd7db9e519fd17790c7ad2649e48fc8a30 (the HEAD blob) both times; trap ... EXIT INT TERM with REPO_ROOT resolved via git rev-parse --show-toplevel, absolute paths throughout",
        "positive_control": "the 4 sibling trap-set suites on the SAME proxy (hook-input-ownkeys-agreement.test.ts, hook-input-descriptor-mirror.test.ts, hook-input-mutation-traps.test.ts, hook-input-shape-contract.test.ts) run in the SAME mutated window: 34/34 green throughout, proving the cut was surgical to the reserved-name descriptor precedence and did not regress the sibling instruments (#12397, #12578, #12277 fixes) or the spec-conformance file"
      },
      "gates": {
        "check:engine-double-contract": "green",
        "check:where-matcher": "green",
        "check:objectql-double-limit": "green",
        "check:query-options-erasure": "green",
        "check:nul-bytes": "green",
        "@objectstack/objectql full test suite": "green -- 243 test files / 4239 tests",
        "@objectstack/runtime full test suite": "green -- 197 test files / 2889 tests (required a fresh build of the runtime dependency closure incl. @objectstack/service-datasource, which had never been built in this fresh worktree)",
        "@objectstack/objectql typecheck": "green",
        "@objectstack/runtime typecheck": "green",
        "check:type-check-coverage": "green -- 65/78 packages type-checked, 13 pre-existing DEBT-ledgered, 1 exempt; unrelated to this diff",
        "check:type-check-debt --re-measure": "NOT MEASURED -- the script's own PREREQUISITE NOT MET throw: needs the full ~80-package workspace closure built (27 packages had no dist), which is what lint.yml does before this step and which this local run did not attempt (out of proportion for a 2-package diff)",
        "check:pm-half-states": "NOT MEASURED -- the script's own PREREQUISITE NOT MET (exit 3): no valid GitHub credential for its own /rate_limit probe in this container; unrelated to this diff",
        "docs family (touched content/docs/automation/hooks.mdx)": "green -- check:doc-anchors, check:doc-authoring, check:docs-single-h1, check:doc-frontmatter, check:role-word, check:docs-redirects, check:doc-route-spelling, check:docs-section-name, check:docs-audit-scope, check:published-readme-links, check:react-page-adapter-contract, check:docs-affected (docs-drift-check), check:docs-drift-comment",
        "changeset family (added .changeset/flat-input-envelope-precedence.md)": "green -- check:changeset-gate-self-tests, check:empty-changeset, check:adr-0087-registration, check:changeset-no-major, check:objectui-changeset, check:pm-half-states-is-separate-see-above",
        "cross-package/static-analysis family (new test files, edited hook-wrappers.ts)": "green -- check:cross-package-test-inputs (both pnpm and node script forms), check:test-source-alias, check:type-source-resolution, check:durability-log-level, check:comment-mask-adoption, check:plugin-teardown-shape, check:slot-lookup, check:page-declaration-shape, check:published-files, check:engine-split-ratio, check:ci-filter-parity",
        "re-derivation": "node scripts/pm/dispatch-gates.mjs --repo objectstack-ai/objectstack re-run on the final commit (6e1297bc4) -- same 5 changed paths, same gate list, nothing new appeared"
      },
      "deviations": [
        "Did not run the repo-wide `pnpm lint` scan or the full ~176-family CI farm locally -- per the seat's local-verification scope, CI runs the farm on the pushed head regardless, and I ran every gate the dispatch prompt named plus every gate this PR's ACTUAL changed paths derived (via dispatch-gates.mjs), which is the documented substitute.",
        "check:type-check-debt and check:pm-half-states are recorded NOT MEASURED rather than skipped silently -- both are genuine prerequisite refusals unrelated to this diff's content, not red results and not gates this diff's paths uniquely triggered beyond the convention-triggered new-test-file kind.",
        "Ablation restore used the commit-based revert (git checkout HEAD -- FILE against the pre-fix blob at commit 0554527ca) rather than a hand-written mutation string, since the exact pre-fix source already existed in this branch's own history as the prediction commit -- this is a cleaner ground truth than a hand-authored mutation and was reused for both ablation runs (discriminator + positive-control)."
      ],
      "open_questions": [],
      "out_of_scope_findings": [],
      "mcp_calls": 8
    }

    Generated by Claude Code

  12. removed
    pm:dispatched
    on Aug 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

domain:engine

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions