Skip to content

@ark/schema & JIT: symbol-keyed meta cache leak, MorphNode middle-pipe refs, prototype-key TypeError, unknown alias error, and +:"reject" JIT parity #1778

Done

Description

@ssalbdivad

Five remaining runtime/JIT edge bugs in @ark/schema and arksets:

Repros

// 1. Symbol-keyed meta leaks between Types via schema node cache
const sym = Symbol("tag")
type("string").configure({ description: "d", [sym]: "v" })
;(type("string").configure({ description: "d" }).meta as any)[sym] // "v" (leaked)

// 2. MorphNode middle piped node missing from hasAlias / otherRefs
const Cyclic = scope({ N: { a: "string", "b?": "N" } }).export().N
const m = type("string.json.parse").pipe(Cyclic, x => x)
m.internal.hasAlias // false (expected true); m.internal.otherRefs.length === 0

// 3. type.schema prototype key crashes with TypeError instead of ParseError
type.schema({ domain: "string", toString: 1 })
// TypeError: Cannot read properties of undefined (reading '0')

// 4. Unknown alias reference throws InternalArktypeError instead of ParseError
rootSchema({ reference: "constructor" }) // InternalArktypeError: Unexpected resolution for reference constructor
rootSchema({ reference: "__proto__" })   // InternalArktypeError: Unexpected resolution for reference __proto__

// 5. JIT vs jitless mismatch on "+": "reject" for inherited/non-enumerable/getter keys
const U = type({ size: "0", x: "string" }).or({ size: "1" }).or({ "+": "reject" })
U.allows(new Map()) // cold (uncompiled): true; warm (JIT): false

Causes & Fixes

  • 1 (schema node cache): Node serialization/hashing ignores symbol keys in meta, returning the cached node with the earlier Type's symbol metadata. Include symbol keys in meta identity or bypass caching when symbol meta is present.
  • 2 (ark/schema/roots/morph.ts:97-99, 121-135): includePiped and otherRefs only inspect morphs[morphs.length - 1]. Walk all intermediate hasArkKind(m, "root") entries in this.piped.
  • 3 (ark/schema/parse.ts:148): impl.keys[k] lacks hasOwn, so Object.prototype keys pass truthiness and crash on keyImpl.child / indexing.
  • 4 (ark/schema/roots/alias.ts:146, 163, ark/schema/shared/registry.ts:25): nodesById is {} rather than Object.create(null), so "constructor" / "__proto__" resolve to Object / Object.prototype and hit throwInternalError.
  • 5 (ark/sets/roots/union.ts:1442-1490): disjointEntryLeavesKeyOverlap special-cases isBuiltinNonEnumerableKey rather than treating any disjoint from own-enumerable-only checks ("+": "reject", index signatures, getters, Object.create prototypes) uniformly against data?.[key] discriminant switches.
  • Minor: type.unit(new Date(NaN)).expression (ark/schema/roots/unit.ts:111-112) prints "Invalid Date", which cannot be parsed back.

Activity

  1. ssalbdivad commented on Dec 3, 2026

    @ssalbdivad
    MemberAuthor

    all five @ark/schema & JIT edge bugs were fixed in 3.0.0 (b9cd9e6f2, 6596894ce) — closing.

  2. moved this from To do to Done (merged or closed) in arktypeioon Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    • Status
      Done (merged or closed)

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions