Skip to content

fix(oracles): own object-literal functions reached via dynamic lookup or whole-value reference - #197

Open
schiller-manuel wants to merge 5 commits into
mainfrom
fix/oracle-gaps-object-literal-owners
Open

schiller-manuel wants to merge 5 commits into
mainfrom
fix/oracle-gaps-object-literal-owners

Conversation

@schiller-manuel

@schiller-manuel schiller-manuel commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Problem

When an owned function dispatches dynamically through a module-level object literal (e.g. const handlers = { initialize: ..., openProject() {}, transform() {}, closeProject() {} }; handlers[message.method](params)) or passes it as a whole value (dispatch(handlers), Object.values(handlers)), oracle-gaps reported the object literal's methods as unowned warnings.

Findings

Checking owners.mjs and gap-report-static-oracle.property.test.mjs:

  • The existing static oracle laws intentionally keep object-literal methods separate in two cases:
    1. Static property reads (D_FNS.used() leaves spare unowned: a method of read module data that nothing calls unowned).
    2. Direct owns entries naming the variable (owns: ['src/sut.ts#D_FNS'] leaves methods unowned: a method of module data that an entry names unowned).
  • Dynamic lookup (handlers[key]) and whole-value references (dispatch(handlers), Object.values(handlers)) were not excluded by any law — this was an oversight compared to classes, where the existing law already states: "A class passed as a value brings all its methods, because which one is called is unknown statically".
  • Probing also uncovered two related bugs in owners.mjs:
    • referencesOf only skipped ts.isFunctionLike(child), so PropertyAssignment declaration names (initialize: (p) => ...) were accidentally visited as references, pulling arrow/function properties in even on static dot-reads and direct owns entries while missing MethodDeclarations.
    • ShorthandPropertyAssignment (const handlers = { fnA, fnB }) resolved to the shorthand property declaration rather than its value symbol (getShorthandAssignmentValueSymbol).

Changes

  • packages/oracles/oracle-gaps/owners.mjs:
    • When a data declaration (variable, property, export default, or module.exports =) is referenced dynamically (handlers[key]) or as a whole value (dispatch(handlers), Object.values(handlers), etc.), bring every function defined inside its value's span into the caller's ownership tree.
    • Preserve static property access (handlers.openProject(), resolved literal handlers['openProject']()), type-only/typeof positions (keyof typeof handlers), and direct owns: ['src/x.ts#handlers'] entries leaving sibling functions unowned.
    • Skip PropertyAssignment declaration names in referencesOf so arrow/function properties and method declarations behave consistently.
    • Resolve ShorthandPropertyAssignment value symbols via checker.getShorthandAssignmentValueSymbol.
  • packages/oracles/tests/oracle-gaps-owns-through-calls.test.ts:
    • Add regression tests for dynamic dispatch tables, static dot & string-literal reads, keyof typeof type queries, direct data owns entries, whole-value passing, Object.freeze/nested tables, shorthand properties, and cross-file/default/namespace imports.
  • packages/oracles/skills/oracles-design/SKILL.md (Step 6, Ownership):
    • Document static property reads vs dynamic lookup/whole-value references vs direct variable owns entries for object-literal dispatch maps.

Validation

  • pnpm test — passed
  • pnpm --filter @tanstack/oracles test:oracle-gaps:fast — passed (5 test files, 33,899 tests, including all gap-report-static-oracle module-data laws)
  • pnpm --filter @tanstack/oracles test:oracle-gaps:shards — passed (5 shards)
  • pnpm --filter @tanstack/oracles test:pr-shards — passed (7 partitions)
  • pnpm lint:check — passed
  • pnpm format:check — passed
  • pnpm typecheck — passed
  • pnpm build — passed

Follow-up: law, evidence, and limits (commits 86ff3e6, 834795e, c920740, 7b23fc3)

Follows the maintainer's ruling of 2026-11-23 (decisions register, "Object-literal functions used dynamically are owned"). The rule now has an oracle law, not only the skill text and pinned tests.

Law. A function defined in a module-level object literal is owned when the literal is used dynamically (table[key]()) or as a whole value (passed to a function, spread, or read with Object.values). A static property read owns only its member. A shorthand name in the literal is owned through the literal's initializer (F10). An owns entry on the literal owns no member. A property name in the literal refers to no binding. Authority: the ruling above, and the ownership law of owners.mjs (P6, R6, I10: the static call tree of owns, unioned over oracle files). The model is an independent graph over the generated history, and it does not read owners.mjs.

Oracle. packages/oracles/oracle-gaps/gap-report-static-oracle-dispatch.property.test.mjs, a sibling of the static oracle. It is a new file rather than an append to gap-report-static-oracle.property.test.mjs, so it adds no lines to that file.

Reach. Each fixed-seed and random-seed campaign runs 120 generated histories. Generated counts (fixed seed 20261123): dynamic lookup 15, passed 25, Object.values 17, spread 19, static read 26, no use 18, owns entry on the literal 36, shorthand member 114, member named like a called function 64. Random seed: 18, 23, 21, 19, 21, 18, 37, 116, 71. Each state also has a constructed history, so every state is required.

RED. On main's owners.mjs (7b6bae16), with the new oracle and the head's test files: 20 of 32 units fail, under both the fixed and random seeds (vitest --run --config oracle-gaps/vitest.config.mjs gap-report-static-oracle-dispatch). The first counterexample is the shorthand bug: fb is named by the literal's initializer, the rule owns it, and main leaves it unowned.

GREEN. On head (7b23fc3f): the new oracle passes 32 of 32. pnpm --filter @tanstack/oracles test:oracle-gaps:fast passes 6 files and 33,931 tests, including the new 32. The pinned tests (tests/oracle-gaps-owns-through-calls.test.ts, 4 of 4) pass, and tests/gap-report-history-fingerprint.test.ts passes.

Mutants. Each is applied to head's owners.mjs and run against the new oracle, then restored:

  • whole-value use not counted (wholeValue = false): 14 of 32 fail.
  • shorthand resolved to the property symbol (the pre-fix behavior): 20 of 32 fail.
  • every literal read treated as a whole-value use: 5 of 32 fail.
  • the PropertyAssignment-name skip removed (isPropertyName disabled): 15 of 32 fail.

CI wiring. The static shards select tests with a name pattern that the new suite name does not match, so both shards would skip its 32 tests (checked: "32 skipped"). The new file runs whole in the third gap-oracle job instead, in .github/workflows/pr.yml. It is also run by test:oracle-gaps:fast.

Conflicts. I expect no textual conflicts with #99 or #133 in owners.mjs, the design skill, the new oracle file, or the changeset, because neither PR touches them. Two possible conflicts: .github/workflows/pr.yml (#133 changes that file; a conflict is possible in the third-job block, which this PR edits), and packages/oracles/oracle-gaps/gap-report-static-oracle.property.test.mjs (not touched here; listed in case the rebase needs it).

Limits.

  • Not generated: literals inside functions, computed or numeric property names, wrappers such as Object.freeze, keyof typeof, imported literals, nested literals, and more than one level of member calls. One use per run.
  • The observation is each unit's ownership, not the gap report's mutant outcomes; those belong to the end-to-end oracle.
  • The new tests run on Linux and macOS CI only. They are not in the Windows static job, which uses the same name patterns. Not run locally on Windows.
  • The gap CLI (index.mjs) was not run over owners.mjs: no production source changed in this follow-up. The oracle ran through Vitest, as the package scripts do.
  • A constructed history's counterexample can shrink to a generated value outside its constructed state (framework behavior). The "no use" RED printed a dynamic counterexample; the run that failed first had use: "none" on an entry-on-literal history.
  • The changeset states the ownership change and the two bug fixes.

This pull request and its description were written by Isaac.

… or whole-value reference

When an owned function accesses a module-level object literal dynamically
(e.g. handlers[message.method]) or passes it as a whole value (e.g.
Object.values(handlers), dispatch(handlers)), which member is called is
unknown statically, so ownership now brings every function defined inside
the declaration's value into the caller's tree — matching the existing
rule for classes passed as values.

Static property reads (handlers.openProject(), handlers['openProject']())
and direct owns entries naming the data variable (src/x.ts#handlers) still
leave unreferenced sibling methods and function properties unowned. This
also fixes two related reference-resolution issues in owners.mjs:
- skip PropertyAssignment declaration names when walking module-level data
  so arrow/function property assignments behave consistently with methods
- resolve ShorthandPropertyAssignment value symbols ({ fnA, fnB })

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 33 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d1e3a459-48f0-4d80-8b75-6a0bc8c964fb
Commits

Reviewing files that changed from the base of the PR and between 7b6bae1 and 7b23fc3.

Files selected for processing: 6

  • .changeset/quiet-monkeys-brake.md
  • .github/workflows/pr.yml
  • packages/oracles/oracle-gaps/gap-report-static-oracle-dispatch.property.test.mjs
  • packages/oracles/oracle-gaps/owners.mjs
  • packages/oracles/skills/oracles-design/SKILL.md
  • packages/oracles/tests/oracle-gaps-owns-through-calls.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@changeset-bot

changeset-bot Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7b23fc3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@tanstack/oracles Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

KyleAMathews and others added 4 commits November 23, 2026 13:42
The maintainer ruled on 2026-11-23 that a function defined in a module
object literal is owned when the literal is used dynamically or as a whole
value, and that a static property read owns only its member. The rule had
only pinned tests. This adds a generated law to the static gap oracle family.

The new oracle generates modules with a literal of arrow, method, and
shorthand members (names may shadow module functions), one use in run
(dynamic lookup, passed, Object.values, spread, static read, or none), and
an entry that is run or the literal. Its model is an independent graph over
the history, not owners.mjs. The driver reads each unit's ownership through
the production analyze and owned.at. Each reach state has a constructed
history.

Law: a module object literal's functions are owned by how the literal is
used (decisions register, M 2026-11-23; ownership law P6, R6, I10; F10).
Reach: 120 random histories per seed, plus nine constructed states; generated
reach counts 15 to 116 per state (fixed seed 20261123).
RED: on main's owners.mjs, 20 of 32 units fail (vitest, this file).
GREEN: on head, 32 of 32 pass; the package fast suite passes 33,931 tests.
Mutants on head owners.mjs, each killed: whole-value not counted (14 of 32
fail), shorthand value symbol reverted (20), static reads treated as whole
values (5), property-name visit restored (15).

Co-authored-by: Isaac <no-reply@databricks.com>
The design skill's ownership paragraph now says the dispatch rule is the
maintainers' ruling of 2026-11-23 (decisions register, "Object-literal
functions used dynamically are owned"), judged by the static gap oracle's
dispatch law. A spread of the literal is named as a whole-value use.

Co-authored-by: Isaac <no-reply@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
The static shards select tests with a name pattern that matches a suite
named oracle-gaps.report-static followed by " > " or a space. The dispatch
oracle's suite, oracle-gaps.report-static-dispatch, matches neither, so
both shards skipped all of its tests (32 skipped on the shard pattern check).
The third job runs its file whole.

Co-authored-by: Isaac <no-reply@databricks.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants