Documentation

Docs / Reference

ADR 0011 — TypeScript/JavaScript object-literal owners and repeated declarations

Status: Accepted (developer review, 2026-10-08) Date: 2026-10-08

Context

T010a revision 2 decides the producer identity policy after the completed the investigation diagnosis found 26 colliding TypeScript/JavaScript identities in pinned Langflow. Separate anonymous callbacks lose their scopes, and object-literal members lose their declared object owners. The 65 warm node writes are intermediate writes: last-valid-record-wins already holds and the warm store equals a fresh snapshot. Store behavior is unchanged by this task.

Options considered

Decision

For TypeScript, TSX and JavaScript, a direct object-literal initializer of a declared variable (const, let, var, exported or not) adds the variable name as a lexical owner. Nested literals under identifier/string-keyed properties add their keys. Computed keys and unbound literals (arguments, returns, array elements and spreads) add no segment. Existing member node kinds are preserved. The nearest emitted lexical owner contains a member: the variable if emitted, otherwise the enclosing emitted named declaration, and the file only when no such declaration exists. Currently exported object variables are emitted; local object variables are not.

Anonymous functions/callbacks still add no owner. After all semantic naming, including overloads and object owners, count each unsuffixed identity per file in source declaration order. Keep the first plain name and append @2, @3, and so on for later declarations. Containment, calls and evidence reference the resulting identities. Calls to repeated callable groups remain unresolved rather than selecting a different body. Cache these ambiguity groups as internal extraction metadata, so warm replay and imported bindings use the same policy.

Bump the aggregate extractor version to extractors-6. Go, Python and Rust extraction semantics are unchanged. Contract v1, store interface, storage/schema, dependencies and grammar assets are unchanged. This documents the explicit TypeScript/JavaScript declaration-order exception alongside ADRs 0006 and 0008.

Consequences

Every bound object-literal method's identity changes once when its owner is added (unbound members retain their existing owners). Content-bound rationale, dispositions and caches for changed identities will require reassociation. Every language's extraction cache is invalidated by the aggregate version bump. Distinct declarations are preserved, eliminating these producer collisions without changing duplicate-key ingestion semantics.

Known gaps

Inserting/reordering repeated declarations can change which body receives each suffix. Anonymous lexical bindings are not modeled, so repeated helper calls are conservatively unresolved. Resolution remains syntactic and best effort. External producers can still emit duplicate keys and cause intermediate graph writes on unchanged replay; last-valid-record-wins remains in force. Postgres and cross-platform execution need CI evidence; this sandbox cannot reach Postgres or the network and cannot write the user compilation cache.

Review notes (developer, 2026-10-08)

Revision: call binding model (T046)

Status: Accepted (delegated review, 2026-11-25)

Context: the T044 review found that the "Anonymous lexical bindings are not modeled" gap above produced wrong calls edges, stored as facts: a parameter, destructured name, catch parameter or block binding of an anonymous function, arrow or block did not shadow an outer function of the same name, and a function declared inside an anonymous function was reachable from outside it by qualified name.

Options considered:

Decision: the extractor builds the file's lexical scopes by ECMAScript rules (module, function, parameter, block, for, catch, class and static block scopes; var hoisting to the function scope) and, for every call it records, compares the name's nearest lexical binding at the site with the declaration link time picks by qualified name. A mismatch, or a binding the syntax does not fix (with, direct eval, this outside a class method, two declarations of one name in one scope), marks the call shadowed: it stays unresolved. The rows are TSX-1 to TSX-17 of docs/lang/typescript-resolution.md ("Call binding model"). Link time, contract v1, the store and the cached fact shape are unchanged; the Shadowed flag of cached calls changes value, so the aggregate extractor version must be bumped when this lands.

Consequences: no calls edge whose callee's lexical binding is another declaration; edges whose binding is undecidable are dropped too (a missing edge, never a wrong one). Block bindings no longer shadow their whole named function, so some correct edges return.

Known gaps: link time still resolves by qualified name, so a call whose lexical binding is a module function but whose qualified-name lookup would pick a nearer method or nested declaration stays unresolved instead of resolving to the module function. Sloppy-mode block function declarations (Annex B) are treated as block scoped; calls outside the block stay unresolved. Static class member calls (ADR 0026) and the bridge rows keep their own shadow models.

Revision: written bindings, member ownership and lexical retargeting (T046 review fixes)

Status: Accepted (delegated review, 2026-11-25)

Context: the review of the call binding model found three forms that still stored wrong calls edges, all pre-existing: a let/var function binding reassigned after its declaration resolved to its initial value; this.m() and C.m() ignored whether m is static; and two object-literal owners of one qualified name in sibling scopes shared their members. It also counted 508 corpus call sites whose lexical binding is a single, never-written function declaration or import, left unresolved only because the qualified-name lookup of link time picks a nearer class or object method of the same name.

Options considered:

Decision: this revises the T046 revision's "never retargets" decision.

Consequences: the cached fact shape of TypeScript/JavaScript calls gains two optional fields; contract v1 and the store are unchanged. Cached Shadowed values change and the new fields appear, so the aggregate extractor version must be bumped when this lands. Edges are retargeted only to the declaration the scope model proves the call evaluates; every other disagreement stays unresolved.

Known gaps: writes through arguments, another script sharing a sloppy global or prototype patching are not seen; member writes (o.m = f, delete o.m) do not block o.m() (ADR 0026 blocks them for static class calls only); virtual dispatch through this still resolves to the class's own method even when a subclass overrides it.

Revision: member writes and the repeated rule (T046 review fixes, round 3)

Status: Accepted (delegated review, 2026-11-25)

Context: the previous revision's known gaps named member writes: a call this.m(), C.m() or o.m() resolved to the own method m even when code of the file assigned, deleted or redefined that member, so the call could reach another value (one corpus site: a plugin class whose constructor deletes the method's own-property copy after a mixin set it). The same revision kept the repeated rule for lexically bound calls whose link-time pick is another function of a repeated name (TSX-24) and left lifting it open.

Options considered:

Decision:

Consequences: fewer this.m()/C.m()/o.m() edges where a member is written (each removed edge's target may not be what the call reaches). Cached call facts change (Shadowed values and the optional MemberWritten field), so the aggregate extractor version must be bumped when this lands; contract v1 and the store are unchanged.

Known gaps: member writes through receivers the model does not follow are not seen (a mixin that receives the object as an argument, this in a plain function or object-literal method, another file, a subclass's instances, Object.setPrototypeOf). TSX-24 keeps about 2,440 corpus call sites unresolved (measured in the previous round, mostly owncast minified bundles whose module functions repeat one qualified name across webpack wrappers): a missing edge, not a wrong one, until declarations get distinct identities.

Revision: Object.assign with literal keys (T046 review fixes, round 4)

Status: Accepted (delegated review, 2026-11-25)

Context: the previous revision counts every Object.assign(x, ...) on a TSX-25 receiver as a write of every member of that side. A constructor that copies its arguments, Object.assign(this, { root, base, head }), then leaves every this.m() of the class unresolved although only three known keys are written (26 sites in one corpus).

Options considered:

Decision: Object.assign(x, s1, s2, ...) on a TSX-25 receiver writes exactly the keys of its sources when there is at least one source and every source (after parentheses and type assertions) is an object literal whose every entry is a shorthand property a, a pair keyed by an identifier or a string literal (b: v, "b": v), or a pair under a computed string literal (["b"]: v), and no key is __proto__ (copying an own __proto__ property may replace the target's prototype, so every member may change). Any other form writes every member of that side, as before: no source, a source that is no object literal (a name, a call), a spread argument, a spread entry, a method or accessor entry, a numeric key, a computed key that is not a string literal. The keys extend the receiver's key path (Object.assign(this.opts, { a }) writes opts.a; Object.assign(C.prototype, { a }) writes the instances' a).

Consequences: a this.m()/C.m()/o.m() call keeps its edge when an Object.assign of literal keys does not name m. Methods, accessors and numeric keys in a source still count as unknown keys although their keys are static: a deliberately narrow first step, so the model stays a subset of the oracle's ECMAScript semantics. Cached call facts change for such files, so the aggregate extractor version bump noted in the previous revision covers this too.

Known gaps: sources held in a name (const patch = { a }; Object.assign( this, patch)) still write every member. The static member resolver of ADR 0026 keeps its own mutation scan, which still counts every Object.assign as a write of every member (more conservative; it is only a fallback when this model leaves a call to link time unresolved).

Revision: receivers of unknown owner (T046 review fixes, round 5)

Status: Accepted (delegated review, 2026-11-25)

Context: the round-3 revision counts member writes only through receivers it follows (this of a class, a class or object binding, a declarator holding this, a name or new C()). A re-check found wrong edges through receivers it does not follow, all already on main: a declarator holding a class expression (const CE = class Inner {...}; CE.m = f), this in an object-literal method, an alias of a member path (const proto = P.prototype; proto.m = f), a destructured name, and a let assigned this after its declaration. The earlier known gaps listed some of these (a mixin parameter, this in a plain function or object method).

Options considered:

Decision: a declarator whose value is a class expression is an alias of that class (the class; through prototype, its instances), so writes through it count under TSX-25. New row TSX-26: a member write (the TSX-25 write forms) whose written object is not a determined receiver (a parameter, a destructured name, an import, a global, a written name, a member-path or call alias, this outside a class, a call result, super, or any value reached through a key, this.cfg.m = f) leaves every TSX-7, TSX-9 or TSX-13 call of the file unresolved whose key path has the written property's name; a non-static key there leaves every such call of the file unresolved. A receiver known to hold no owner (a fresh literal, Object.assign({}, ...), a never-written function binding) blocks nothing. A name written after its declaration is no longer an alias (its writes are of unknown owner). TSX-26 calls are marked like TSX-25 ones, so the ADR 0026 resolver does not resolve them either; the file's written names are cached with its facts (MemberWrittenNames), so every static call that resolver adds in the file follows the same rule: module-level calls, calls the binding model leaves to it (a class name repeated in sibling scopes, TSX-21), and calls of an imported class (the receiver may hold it).

Consequences: precision over recall: files that write a computed key on a parameter (target[key] = value) or on a value a field holds (this.cache[key] = value) lose every member-call edge. The corpus counts are in the T046 task record (internal). Cached call facts change, covered by the pending aggregate extractor version bump.

Known gaps: dispatch is static (TSX-13): this.render() in Base.run resolves to Base.render even when a subclass of the file overrides render; the edge holds for Base instances and no edge to the override is emitted (a missing edge for subclass instances). Writes in another file, Object.setPrototypeOf, and calls through an import's members (api.m() after api.m = f) are not covered. A class/namespace merge inside the class bypasses TSX-16 (tsc rejects such programs).

Revision: member calls through imports (T046 gate preparation)

Status: Accepted (delegated review, 2026-11-25)

Context: the previous revision left member calls through an import open: import * as api from "./api"; api.m = f; api.m() resolved to the export m through the module resolver (TSX-11), although the file replaces it (in CommonJS output and with bundlers a namespace object is writable; a default or named import may hold any object).

Options considered:

Decision: row TSX-26 also decides member calls through an import binding (api.m(), api.a.m(), TSX-11 and TSX-23). Receivers of unknown owner include imports (namespace, default, named), require bindings (const api = require(...), a declarator holding a call) and destructured requires (const { a } = require(...)); the write forms are those of TSX-25 (assignment, compound or logical assignment, delete, Object.defineProperty with a literal key, ...). Such calls are marked like the other TSX-26 calls, so the ADR 0026 resolver does not resolve them either.

Consequences: more missing edges in files that patch a module's exports or write a computed key on a parameter; never a wrong edge for the forms listed. Cached call facts change, covered by the aggregate extractor version bump at merge.

Known gaps: writes in another file are not seen: a module that patches another module's export (import * as api from "./api"; api.m = f in patch.js) leaves api.m() in every other file resolved to the export. A plain call through a named import (import { m } from "./api"; m()) is not blocked by a write of m through the namespace in the same file; it reads the module's binding, which such a write only replaces where the module is compiled to CommonJS with live member access.

Review notes (delegated review, 2026-11-25, T046)

Accepted with the six T046 revisions above after gate 1 (CI run 45612588023: changes and postgres green; postgres log 0 FAIL, 254 /postgres PASS, only opt-in oracle, census, corpus and generator skips; Windows runs on the final CI gate). Aggregate extractor version extractors-61.

Report a problem with this pageSource: docs/adr/0011-typescript-javascript-object-owners-and-repeated-declarations.md