Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ The format follows Keep a Changelog and the package uses semantic versioning.

## Unreleased

- Fixed query comparisons, ordering and projections reading inherited
JavaScript properties as document data. Missing optional fields such as
`toString` no longer cause clone/sort errors, and absent `__proto__` fields
no longer match inherited empty objects. Own shadowing values remain
supported. Existing reserved index/projection names, formats, public APIs,
planner, collation and limits are unchanged.

- Fixed an empty raw memory-cache key blocking LRU eviction when eldest.
Entry/byte budgets now evict it normally; empty keys remain supported.
Direct raw caches and shared roots containing such a key are affected.
Expand Down
243 changes: 243 additions & 0 deletions benchmarks/own-field-query-projections/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
# Own-field query and projection qualification

P18 qualifies a bounded correctness correction: document comparisons,
ordering and projections use directly owned fields, rather than inherited
JavaScript properties. Missing optional fields such as `toString` no longer
cause clone/sort exceptions. A query for an owned `__proto__` object no longer
matches a document merely because it inherits `Object.prototype`.

The score is 92/100, above the prospective 85/100 threshold. Local gates pass.
Merge eligibility also requires normal CI and CodeQL on the PR's exact
publication head. The score is an engineering judgement, not a probability
or a measured performance result.

## Scope and compatibility

The correction reuses `ownValue` in four existing modules: query comparisons
and ordering, covering-index projection, browser projection and typed
collection-fallback projection. Genuine own shadowing values remain data.
Missing fields remain different from `null`; ascending missing values remain
last, descending missing values first, with the existing ID tie-breaker.

Index/projection rejection of `__proto__`, `prototype` and `constructor`
is unchanged. Queries retain their existing field-name validation. Operators,
collation, limits, planning, index format/version, public APIs, package exports,
cache policies and dependencies are unchanged. Existing ordinary-field and
all-present controls have identical results, reader observations and clone
work. No infrastructure or shared-host runtime was changed.

An omitted field has no own property. Returned records still have ordinary
JavaScript prototypes; use an ownership check rather than `in` to distinguish
data from inherited methods. The standalone evaluator retains its previous
input/output ownership. Projection output remains detached before application
schema parsing; custom parsers remain responsible for their own results.

This is a source-backed correction using established JavaScript ownership
semantics, not a new industry capability. It does not repair arbitrary existing
indexes, validate custom prototypes/getters, prevent every prototype-related
application error, or establish production incidence or performance gains.

## Prospective design and provenance

- Exact baseline: `7220ab5489ae757a758da83a05b1e6c31700c662`, the merged P17
tree, verified equal to its qualified publication.
- Protocol published before production edits:
`9bf7faa601b9df1b3ad3866a1c2baa539cb07a25`.
- Source, fixtures, collector, verifier and tests frozen and pushed:
`f47d0e830c41a42c3f761b4a77bc425c909cf3c1`.
- Sole comparative capture: 3 December 2026,
22:27:27.814-22:27:34.971 UTC, on that detached source commit.

[Protocol](protocol.json) fixes two families, each with six fields and six
recipes, three availability patterns, two payloads and three deterministic
input permutations. This produces 648 trials per family per arm, or 1,296
pairs/2,592 raw rows. Three replicates are deterministic checks, not independent
production samples or statistical confidence.

Four fresh JSON-parsed documents per trial exercise absent, mixed and complete
own-field presence. Fields include inherited method names and ordinary
`title`/`_custom` controls. Query fixtures also include `__proto__` and
`constructor`; projection restrictions remain in force. No global prototype
is modified. `Date.now` is fixed per trial and restored afterwards.

Both complete public source graphs are compiled from exact Git revisions
with the same locked esbuild 0.28.2. The raw capture retains both executable
bundles, their digests, all 19 loaded source-module identities per arm, and
80 frozen input digests. Execution order alternates by pair. No historical
method is rewritten into a candidate fixture.

Captured bundles include existing dependencies. Redistribute them with the
repository's [license](../../LICENSE) and [third-party notices](../../NOTICE).

Browser paths use real `ThimbleClient` snapshot/index readers against an
in-process JSON transport and no-op persistent delegate. Covered queries
must read HEAD/index only. These are synthetic transport observations, not
encrypted IndexedDB, provider, authority-network or production benchmarks.

## Complete comparative results

Each recipe has 108 trials per arm. Correctness includes result values,
metadata, own-field presence, unchanged inputs and projection ownership.

| Recipe | Historical correct | Historical incorrect return | Historical exception | Candidate correct |
| --- | ---: | ---: | ---: | ---: |
| eq-object | 96 | 12 | 0 | 108 |
| ne-object | 96 | 12 | 0 | 108 |
| in-object | 96 | 12 | 0 | 108 |
| and-not | 96 | 12 | 0 | 108 |
| order-asc | 90 | 0 | 18 | 108 |
| order-desc | 84 | 6 | 18 | 108 |
| collection-projection | 60 | 0 | 48 | 108 |
| browser-point-projection | 60 | 0 | 48 | 108 |
| browser-scan-projection | 60 | 0 | 48 | 108 |
| covering-build-roundtrip | 60 | 0 | 48 | 108 |
| covering-update | 60 | 0 | 48 | 108 |
| covered-browser-projection | 60 | 0 | 48 | 108 |
| Total | 918 | 54 | 324 | 1,296 |

![All contract outcomes by recipe](results/local-2026-12-03-contracts.svg)

![All returned-correct, incorrect and thrown outcomes](results/local-2026-12-03-outcomes.svg)

All 720 ordinary-field/all-present control pairs pass both arms with identical
complete outcomes, reader observations, clone events and ownership probes.
The other historically correct rows are retained too. For example, the
selected mixed `__proto__` ascending-order input already produces the expected
ID order historically; it is not counted as a repair.

## Work and costs

| Logged work across 1,296 trials per arm | Historical | Candidate |
| --- | ---: | ---: |
| Reader/delegate calls, including collection scans | 660 | 756 |
| Structured-clone attempts | 5,436 | 7,164 |
| Successful structured clones | 5,148 | 7,164 |
| Attempts to clone an inherited function | 288 | 0 |

The extra 96 synthetic reader calls are 48 covered-query cases reaching their
HEAD/index reads after index construction previously threw. The 2,016 extra
successful clones similarly include work that historical failures never
reached. Removing 288 invalid clone attempts leaves 1,728 net additional
attempts. These are complete fixed-matrix counts, not a performance regression
or improvement estimate. Already-correct declared controls retain exact work.

Each corrected lookup adds an `Object.hasOwn` check. Its CPU cost is unmeasured.
Completing an operation can do more useful copying and reading than throwing
early. No new input copy, retry or format migration is introduced.

## Qualification and independent checks

| Check | Result |
| --- | --- |
| Final candidate and existing related controls | 258/258 |
| Exact historical focused/index comparison | 74 pass, 38 expected failures, 112 total |
| Candidate matrix | 1,296/1,296 |
| Declared complete-work control pairs | 720/720 unchanged |
| Native Chromium | 36/36 |
| Native Firefox | 36/36 |
| Native WebKit | 36/36 |
| Built public-entrypoint probes | 36/36 |
| Repository, Studio, Worker and explicit fixture types | Pass |
| Packed consumers and browser package isolation | Pass |

New snapshot/trie integration cases publish optional covering fields through
real engine writes, then remove an own shadowing field in a replacement.
Browser projections remain on the index path, read HEAD/index only, omit the
removed own field and leave earlier results unchanged.

The [independent verifier](verify.mjs) does not import the collector or fixtures.
It reconstructs every input, query, expected result and ownership probe from
explicit own entries, checks all pairs/control work, clone payloads and reader
responses, validates frozen source identities, and executes both captured
bundles against the discovery case. It checks every CSV cell, both graphs'
data and geometry, and the published derivative hashes.

All 108 native observations match their corresponding fixed-clock candidate
rows in full. They come from one invocation with zero retries, flakes or skips;
each original attachment has a retained digest. Windows x64, OS 10.0.26200,
Node 22.22.2, TypeScript 5.9.3 and Playwright 1.63.0 were used. Actual engines:
Chromium 153.0.8010.12, Firefox 155.0, WebKit 26.6. Windows WebKit does not
qualify Apple Safari.

An initial candidate fixture attempt passed 67/85 groups and failed 18 because
it called a non-exported encoder. Initial explicit types also identified a
generic cast and test type arguments. These were corrected before freezing;
no comparative trial ran on that revision. The corrected initial controls
passed 256/256; adding real-engine integration cases gave the final 258/258.
Historical focused qualification progressed from 49/85 with 36 expected
failures to 74/112 with 38 expected failures.

The native helper started with absent data and free ports. Cleanup verified
three generated paths, matching UTC timestamps, no reparses and stopped
listeners before non-recursive removal, without reading the key. An initial
metadata check blocked deletion because PowerShell rebound typed UTC dates
as local strings; correcting that inspection required no trial rerun.

## Evidence and reproduction

Raw observations are the source of truth:

- [Full capture and both executable source graphs](results/local-2026-12-03.json)
- [Every trial as CSV](results/local-2026-12-03-trials.csv)
- [Native observations and original attachment digests](results/native-2026-12-03.json)
- [Qualification manifest and retained runner/log digests](results/qualification-2026-12-03.json)

Use the frozen source and the locked dependencies in a clean checkout.
Verify the checked-in evidence without recollecting:

```powershell
npm ci
node benchmarks\own-field-query-projections\verify.mjs benchmarks\own-field-query-projections\results\local-2026-12-03.json benchmarks\own-field-query-projections\results\native-2026-12-03.json
npm test -- tests\query-own-fields.test.ts tests\query.test.ts tests\collection.test.ts tests\secondary-index.test.ts tests\browser-read-ownership.test.ts tests\browser-client.test.ts tests\browser-connect.test.ts
npx tsc -p benchmarks\own-field-query-projections\tsconfig.json --noEmit
```

The exact historical command exits 1 intentionally, with 38 expected failures
and 74 passes:

```powershell
npx vitest run --config benchmarks\own-field-query-projections\baseline-vitest.config.ts
```

For a fresh comparative capture, use an unused output name; outputs are
exclusive and cannot overwrite evidence:

```powershell
git switch --detach f47d0e830c41a42c3f761b4a77bc425c909cf3c1
node --import tsx benchmarks\own-field-query-projections\run.mjs --output benchmarks\own-field-query-projections\results\local-rerun.json
node benchmarks\own-field-query-projections\verify.mjs benchmarks\own-field-query-projections\results\local-rerun.json
```

Native tests use the repository's existing local helper. Ensure its
`.thimble-e2e` directory is absent and ports 5173/8787/8790 are free before
running; its startup removes that directory. Do not delete pre-existing data
or stop unrelated listeners. A single invocation selects all 108 cases:

```powershell
npm run test:e2e -- 'query-own-fields\.spec\.ts'
```

Each test attaches the complete observation and actual browser version.
No new cloud campaign, provisioning, deployment or shared runtime upgrade
is required. The normal supported-Node CI site build remains a merge gate;
the local Node version is below the site's development floor.

## Decision and rejection criteria

| Criterion | Score | Basis |
| --- | ---: | --- |
| Semantic correctness and fit | 35/40 | Repairs reproducible valid-input failures; unusual field names limit the demonstrated scope |
| Compatibility and work | 24/25 | 720 exact-work controls; ownership/restrictions preserved; extra own checks and completed work disclosed |
| Reproducible evidence | 19/20 | Exact source graphs, independent replay, full raw matrix and three native engines; local/synthetic boundaries remain |
| Scope and simplicity | 14/15 | Existing helper in four modules; no public option or format change |
| Total | 92/100 | Recommend merging only after every mandatory gate passes |

Reject or defer if any candidate result, ownership/omission rule, reserved
field rejection, ordinary control, covering-read boundary, package contract,
native case, exact-head CI or CodeQL gate fails. Do not use this experiment
to justify broader prototype rewriting, query-planner changes, unrestricted
index fields, new security guarantees or production performance claims.

Sources: [own-property semantics](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn)
and [JSON's own-enumerable-field traversal](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify),
alongside the exact source revisions and checked-in tests above.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { execFileSync } from "node:child_process";
import { readFileSync } from "node:fs";
import { fileURLToPath } from "node:url";
import { resolve } from "node:path";
import { defineConfig } from "vitest/config";

const root = fileURLToPath(new URL("../../", import.meta.url));
const { baseline } = JSON.parse(readFileSync(new URL("./protocol.json", import.meta.url), "utf8"));
const paths = ["src/query.ts", "src/secondary-index.ts", "src/browser/client.ts", "src/browser/collection.ts"];
const sources = new Map(paths.map((path) => [
resolve(root, path).replaceAll("\\", "/"),
execFileSync("git", ["--no-pager", "show", `${baseline}:${path}`], { cwd: root, encoding: "utf8" }),
]));
export default defineConfig({
root,
plugins: [{
name: "exact-baseline-own-field-queries", enforce: "pre",
load(id) { return sources.get(id.replaceAll("\\", "/").split("?")[0]!) ?? null; },
}],
test: { include: ["tests/query-own-fields.test.ts", "tests/secondary-index.test.ts"] },
});
Loading