8000 feat(browser): add incomingRefs to BrowserWriteTransaction (#925) by adityamukho · Pull Request #927 · project-minigraf/minigraf · GitHub
[go: up one dir, main page]

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
4 changes: 4 additions & 0 deletions .github/workflows/wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ jobs:
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
- name: wasm-bindgen tests (lib, incl. BrowserDb and IndexedDB)
run: wasm-pack test --headless --${{ matrix.browser }} --features browser
- name: Check generated incoming-reference TypeScript declarations
run: |
wasm-pack build --dev --target web --out-dir target/browser-types --features browser
npx --yes --package typescript@5.9.3 tsc --strict --noEmit --target ES2020 --lib ES2020,DOM,ESNext.Disposable --moduleResolution node tests/browser/incoming_refs.ts

browser-worker:
name: Browser worker tests (headless ${{ matrix.browser }})
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- **Browser incoming-reference lookup and binding parity** (#925, v3): synchronous `BrowserWriteTransaction.incomingRefs(target, maxLinks, maxRecords)` exposes #924's lookup on in-memory, IndexedDB and OPFS databases. It returns a plain object with a TypeScript `status` union (`complete` with links, or `exhausted` with a budget and no partial list). Budgets are exact integer JS numbers in `0..=2^32-1`; invalid inputs are `[API-017]`, finished/closed handles `[API-018]`. It reads earlier statements and remains available after an IndexedDB flush failure. Native/JVM semantics are unchanged; remaining binding and package parity work is tracked separately in #925.

- **Bounded typed incoming-reference lookup** (#924, v3): `WriteTransaction::incoming_refs` and `OwnedWriteTransaction::incoming_refs` return `IncomingRefs::Complete` or `Exhausted`, with separate links/records budgets and a records-examined count. They read scalar `Value::Ref` links across pending, staged, durable VAET and large working trees, ignore valid time, and never return a partial list. Require a complete result before cascading deletes. No format, WAL, grammar, error-code or browser API change. See [implementation and acceptance evidence](docs/testing/924-incoming-refs.md).

- **JVM/WASI nightly lanes** (#858): 14 JVM and 3 WASI routes, pinned runtimes, measured-core/artifact provenance, strict raw-sample reporting and independent histories, live on both branches with the adapter merged in `minigraf-java`. The iOS simulator and Android emulator were qualified against matched Device Farm physical runs and rejected for every case, so no mobile lane is enabled ([report](docs/benchmarks/858-mobile-qualification/REPORT.md)). No runtime, file-format or Rust test inventory change. See [the adapter contract](docs/BINDING_BENCHMARKS.md).
Expand All @@ -30,6 +32,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- **Browser transaction callback reentry** (#925): `incomingRefs`, `execute`, `commit` and `rollback` on the same transaction from its own user function now report `[INT-001]` before lifecycle or argument validation. Previously the existing methods hit wasm-bindgen's recursive-borrow error. The transaction remains usable; `rollback(): void` is unchanged in TypeScript and throws on reentry.

- **Strict UTC timestamps (v3.0.0 behaviour change, #900)**: removed the unmaintained `chrono` dependency (RUSTSEC-2026-0543) without a replacement crate. Accept only `YYYY-MM-DD`, `YYYY-MM-DDTHH:MM:SSZ`, or `YYYY-MM-DDTHH:MM:SS.fZ` with 1–9 ASCII fractional digits, truncated to milliseconds (also before 1970), and years 0000–9999. Newly rejected with INT-004: lowercase `z`, the `UTC` suffix, any whitespace, single-digit fields, one- or two-digit years, negative years, leap seconds, more than nine fractional digits, empty fractions and comma fractions. Offsets, lowercase `t`, missing seconds, five-digit years, invalid calendar/clock fields, non-ASCII digits and trailing characters remain rejected. Formatting keeps whole-second UTC output and returns INT-005 outside the same year range.

- **v3 binary-size CI budget**: raise the enforced distribution-binary limit from 1,240 to 1,250 KiB (1,280,000 bytes). Unchanged production source measured 1,242 KiB after CI moved to Rust 1.100.0 and a newer runner image; the additional headroom changes no production code or build settings.
Expand Down
4 changes: 2 additions & 2 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ cargo run < demos/demo_negation.txt

8. **`src/error.rs`** — Structured error codes: `MinigrafError`, `ErrorCategory`, `ErrorCode` registry (PRS/QRY/STG/WAL/API/INT codes); must match `docs/ERROR_REFERENCE.md`. `MinigrafError::invalid_argument` (API-017) and `MinigrafError::closed` (API-018) exist for language bindings; browser OPFS adds API-026 (unavailable context), API-027 (busy) and STG-048 (failed browser storage operation)

9. **`src/browser/`** — Browser WASM backend (`browser` feature): `backend.rs` (buffer/OPFS dispatch), `opfs.rs` (`OpfsBackend` over an exclusive dedicated-worker sync access handle, one `<name>.graph` file and a 256-page cache; no WAL; sole-valid-meta recovery; crash-atomic import stages `<name>.graph-import`), `buffer.rs` (`BrowserBufferBackend`, in-memory pages with dirty tracking; free pages a pinned generation may read are withheld from release, `pins::split_released`), `indexeddb.rs` (IndexedDB persistence on the main thread or in workers; atomic puts/deletes, abort/error settlement, STG-048 on failure, ordered flushes and persistent per-handle STG-046 refusal after failure, #894; checkpoint waits for earlier applied writes, close discards unstarted flushes, reads/export retain already-applied memory); `openOpfs(name)` selects OPFS explicitly (Tier 2 in v3.0.0); all modes have synchronous `close()`, invalidating dependents and releasing the OPFS lock, with no save; `BrowserDb.query` returns a `BrowserCursor` (JSON row batches); `BrowserDb.prepare` returns a `BrowserPreparedQuery` (`execute`/`query` with a bindings object; `withMaxDerivedFacts`/`withQueryMemoryLimit`/`withMaxIterations` return a new one, #872; read by `binds.rs`: plain JS values or `{type, value}` forms, #181; a set as `{type: 'set', value: [..]}` or a JS `Set`, #316); `BrowserDb.beginWrite` returns a `BrowserWriteTransaction` (#824: sync `execute` staging through `db::Staged`, `commit()` a `Promise` resolved after the IndexedDB flush, `rollback()`; `BrowserDbInner::tx_open` makes every other read/write call `INT-001`; finished = `API-018`; tests in `tx_tests.rs`); `udfs.rs`: `registerPredicate`/`registerAggregate` (#180; values as `{type, value}` objects, a throw is `QRY-014`; JS values held in a thread-local table, the registry keeps ids). Tests here must be `#[wasm_bindgen_test]` (the module only builds for wasm32); `.github/workflows/wasm.yml` runs them in headless browsers, runs the WASI tests under Wasmtime, and lints both wasm targets. New file-backed integration test files need `#![cfg(not(target_arch = "wasm32"))]`
9. **`src/browser/`** — Browser WASM backend (`browser` feature): `backend.rs` (buffer/OPFS dispatch), `opfs.rs` (`OpfsBackend` over an exclusive dedicated-worker sync access handle, one `<name>.graph` file and a 256-page cache; no WAL; sole-valid-meta recovery; crash-atomic import stages `<name>.graph-import`), `buffer.rs` (`BrowserBufferBackend`, in-memory pages with dirty tracking; free pages a pinned generation may read are withheld from release, `pins::split_released`), `indexeddb.rs` (IndexedDB persistence on the main thread or in workers; atomic puts/deletes, abort/error settlement, STG-048 on failure, ordered flushes and persistent per-handle STG-046 refusal after failure, #894; checkpoint waits for earlier applied writes, close discards unstarted flushes, reads/export retain already-applied memory); `openOpfs(name)` selects OPFS explicitly (Tier 2 in v3.0.0); all modes have synchronous `close()`, invalidating dependents and releasing the OPFS lock, with no save; `BrowserDb.query` returns a `BrowserCursor` (JSON row batches); `BrowserDb.prepare` returns a `BrowserPreparedQuery` (`execute`/`query` with a bindings object; `withMaxDerivedFacts`/`withQueryMemoryLimit`/`withMaxIterations` return a new one, #872; read by `binds.rs`: plain JS values or `{type, value}` forms, #181; a set as `{type: 'set', value: [..]}` or a JS `Set`, #316); `BrowserDb.beginWrite` returns a `BrowserWriteTransaction` (#824: sync `execute` staging through `db::Staged`, `commit()` a `Promise` resolved after the IndexedDB flush, `rollback()`; `BrowserDbInner::tx_open` makes every other read/write call `INT-001`; finished = `API-018`; tests in `tx_tests.rs`; #925 adds synchronous `incomingRefs(target, maxLinks, maxRecords)`, a plain-object complete/exhausted TypeScript union with exact 32-bit JS budgets, sharing `db::incoming_refs` with native transactions without `Staged::read_view`; all transaction methods use shared receivers and a per-transaction `RefCell` guard for callback INT-001 before lifecycle/validation; parity and bounded-work tests in `incoming_tests.rs`); `udfs.rs`: `registerPredicate`/`registerAggregate` (#180; values as `{type, value}` objects, a throw is `QRY-014`; JS values held in a thread-local table, the registry keeps ids). Tests here must be `#[wasm_bindgen_test]` (the module only builds for wasm32); `.github/workflows/wasm.yml` runs them in headless browsers, runs the WASI tests under Wasmtime, and lints both wasm targets. New file-backed integration test files need `#![cfg(not(target_arch = "wasm32"))]`

### Data Model

Expand Down Expand Up @@ -250,7 +250,7 @@ Auto-migrates v7 → v8 on open (spec §9, with a backup meta page). v1–v6 are

## Test Coverage

**2213 tests** (2190 active, 23 ignored; unit + integration + example + doc). Browser-only inventory is separate: #894 adds 14 wasm tests (95 main-thread / 128 dedicated-worker tests in total); see `docs/testing/894-idb-flush-recovery.md` for execution results. Engine answers once checked by the executor are frozen in `tests/answers/` (#551). The #924 Rust 1.99.1 dist binary is 1,250,568 bytes (+3,808 from the v3 base), below the 1,280,000-byte gate; [verification and acceptance mapping](docs/testing/924-incoming-refs.md).
**2213 tests** (2190 active, 23 ignored; unit + integration + example + doc). Browser-only inventory is separate: #925 adds eight wasm tests (103 main-thread / 136 dedicated-worker tests in total); see `docs/testing/925-browser-incoming-refs.md` for execution results. Engine answers once checked by the executor are frozen in `tests/answers/` (#551). The #924 Rust 1.99.1 dist binary is 1,250,568 bytes (+3,808 from the v3 base), below the 1,280,000-byte gate; [verification and acceptance mapping](docs/testing/924-incoming-refs.md).
See `docs/TEST_COVERAGE.md` for the full per-file breakdown.

The #760 deterministic storage suite adds three native unit tests in a separate `--cfg minigraf_shuttle` build, outside the default count. Run only `graph::storage::deterministic::` with that cfg; ordinary unit tests do not enter its scheduler. `deterministic-schedules.yml` runs relevant v3 PRs on Linux/macOS/Windows plus Linux MSRV, and larger nightly/manual searches with replay artifacts. The identical main workflow activates the v3 schedule after both PRs merge. See `docs/testing/deterministic-schedules.md` for scope, controls and findings.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ See the [Mobile Integration](https://project-minigraf.github.io/minigraf-docs/la

### For WASM / Browser

Published as [`@minigraf/browser`](https://www.npmjs.com/package/@minigraf/browser) on npm (`wasm-pack`). `BrowserDb.open(name)` uses IndexedDB on the main thread or in a worker. From v3.0.0, `await BrowserDb.openOpfs(name)` uses one `<name>.graph` file in OPFS, in a dedicated worker on HTTPS or localhost, with a 256-page cache instead of a whole-file memory buffer. OPFS starts at Tier 2 inside the Tier 1 browser binding; the modes have separate namespaces and never fall back to each other. `close()` is synchronous and releases the database and its lock in every mode. See the [complete module-worker example](https://github.com/project-minigraf/minigraf-wasm/tree/v3#opfs-worker) and [browser durability contract](docs/DURABILITY.md#browser-storage-modes). `BrowserDb.beginWrite()` opens a write transaction (from v3.0.0): `execute` stages and reads back, `await tx.commit()` stores it in IndexedDB or flushes it to OPFS, `rollback()` discards it, and the database's other calls throw `[INT-001]` until it ends. The WASI package is the REPL: each command commits on its own, with no explicit transactions. WASI build (`wasm32-wasip1`) available as [`@minigraf/wasi`](https://www.npmjs.com/package/@minigraf/wasi) on npm and as a GitHub Releases artifact (Wasmtime / Wasmer). See the [Use Cases](https://project-minigraf.github.io/minigraf-docs/latest/use-cases/). The [playground](https://minigraf-playground.vercel.app/) and the [time travel visualizer](https://project-minigraf.github.io/minigraf-visualizer/) are both built on `@minigraf/browser`.
Published as [`@minigraf/browser`](https://www.npmjs.com/package/@minigraf/browser) on npm (`wasm-pack`). `BrowserDb.open(name)` uses IndexedDB on the main thread or in a worker. From v3.0.0, `await BrowserDb.openOpfs(name)` uses one `<name>.graph` file in OPFS, in a dedicated worker on HTTPS or localhost, with a 256-page cache instead of a whole-file memory buffer. OPFS starts at Tier 2 inside the Tier 1 browser binding; the modes have separate namespaces and never fall back to each other. `close()` is synchronous and releases the database and its lock in every mode. See the [complete module-worker example](https://github.com/project-minigraf/minigraf-wasm/tree/v3#opfs-worker) and [browser durability contract](docs/DURABILITY.md#browser-storage-modes). `BrowserDb.beginWrite()` opens a write transaction (from v3.0.0): `execute` stages and reads back, `await tx.commit()` stores it in IndexedDB or flushes it to OPFS, `rollback()` discards it, and the database's other calls throw `[INT-001]` until it ends. `tx.incomingRefs(target, maxLinks, maxRecords)` synchronously returns `{status: 'complete', links, recordsExamined}` or `{status: 'exhausted', budget: 'links' | 'records', recordsExamined}` without partial links. Both budgets are integer JS numbers in `0..=4294967295`; invalid inputs throw `[API-017]`, finished/closed handles `[API-018]`, and callback reentry `[INT-001]`. It includes earlier staged statements and only scalar Ref values (not Keywords, strings or sets), ignoring valid time. Require complete before deleting; retry or abandon on exhausted, which leaves earlier writes staged. The WASI package is the REPL: each command commits on its own, with no explicit transactions or incoming-reference lookup. WASI build (`wasm32-wasip1`) available as [`@minigraf/wasi`](https://www.npmjs.com/package/@minigraf/wasi) on npm and as a GitHub Releases artifact (Wasmtime / Wasmer). See the [Use Cases](https://project-minigraf.github.io/minigraf-docs/latest/use-cases/). The [playground](https://minigraf-playground.vercel.app/) and the [time travel visualizer](https://project-minigraf.github.io/minigraf-visualizer/) are both built on `@minigraf/browser`.

### For Python / Node.js / Java / C

Expand Down
3 changes: 2 additions & 1 deletion ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ Shipped:

## v3.0.0 — File Format v8 and Data Integrity

- Bounded typed incoming references (#924): core Rust transaction APIs implemented, with separate link/record limits, exact scalar Ref matching and target-local access in every storage layer. JVM bindings and the docs site remain separate deliverables. The measurement report shows no median regression above 5% on any of 65 IDs in either round; see [acceptance evidence](docs/testing/924-incoming-refs.md).
- Bounded typed incoming references (#924): core Rust transaction APIs implemented, with separate link/record limits, exact scalar Ref matching and target-local access in every storage layer. The JVM bindings and docs-site deliverables are merged. The measurement report shows no median regression above 5% on any of 65 IDs in either round; see [acceptance evidence](docs/testing/924-incoming-refs.md).
- Incoming-reference binding parity (#925): core browser `BrowserWriteTransaction.incomingRefs` implemented with exact JS budgets, typed complete/exhausted outcomes and callback reentry guards; remaining binding, wasm package and docs-site PRs are separate deliverables.

**v3.0.0 supports file format v8 only.** Fixing #287/#371 (`EavtKey`/`AevtKey` carry no value bytes, so same-transaction multi-values collapse) bumps the format from v7 to v8. Support for v1–v6 is dropped at the same time. The v1–v6 → v7 auto-migration code in `persistent_facts.rs` can be removed when cutting this release; a v7→v8 migration replaces it. Any database opened at least once under a v1.x release will already be on v7; there are no known users on older formats. Every other layout change this release needs goes into v8 too, so there is no separate v9.

Expand Down
17 changes: 16 additions & 1 deletion docs/TEST_COVERAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@

## Coverage Summary

**#925 browser incoming references** adds eight `wasm_bindgen_test` cases:
six in `src/browser/incoming_tests.rs` (generated-JS budget/type boundaries,
in-memory lifecycle, IndexedDB/OPFS reopen and lifecycle, failed-flush reads,
differential parity with `OwnedWriteTransaction`, and 10,000 unrelated staged
or committed facts with independent enumeration counters), and two in
`src/browser/tx_tests.rs` (all four transaction methods reentered through JS
and callback close/free behavior). Browser inventory is **103 main-thread /
136 dedicated-worker** tests. Native inventory remains **2,213 tests**
(2,190 active, 23 ignored). `tests/browser/incoming_refs.ts` checks generated
TypeScript narrowing, required numeric budgets and `rollback(): void` in
`wasm.yml`. The browser and native paths share the same three-layer lookup.
Local Firefox runs pass all 103/136 tests; native default tests, strict native
and browser-library Clippy, formatting and generated TypeScript checks pass.
See [commands, limitations and size measurements](testing/925-browser-incoming-refs.md).

**#924 bounded incoming references**: full native runs on 2026-11-28 with
Rust 1.99.1 on Linux x86_64 pass **2,190 tests, 0 failed, 23 ignored**
(2,213 total) by default and **2,228 tests, 0 failed, 32 ignored**
Expand Down Expand Up @@ -823,7 +838,7 @@ None of these are counted in the summary. The wasm32 targets run in CI (`.github
- AC13/AC14: `opfs_open_read_bound`, `opfs_cache_residency_bound`, `indexeddb_mode_works_in_a_worker`.
- AC3 parity: the worker build runs the existing transaction, prepared-query and UDF suites against OPFS as well as IndexedDB. The main-thread build preserves the existing IndexedDB tests. Worker CI sets `RUSTFLAGS=--cfg minigraf_browser_worker` for Firefox and Chrome.

- **In a browser** (`wasm-pack test --headless`, Firefox and Chrome): 94 `wasm_bindgen_test` tests after #894 (81 inherited plus 13 flush-recovery tests); see the [#894 verification record](testing/894-idb-flush-recovery.md) for actual runs. The final #641 snapshot passed in headless Firefox on the bench; Chrome remains a CI run.
- **In a browser** (`wasm-pack test --headless`, Firefox and Chrome): 103 main-thread and 136 dedicated-worker `wasm_bindgen_test` tests after #925 (95/128 inherited plus eight incoming-reference and reentry cases); see the [#894 verification record](testing/894-idb-flush-recovery.md) for actual runs. The final #641 snapshot passed in headless Firefox on the bench; Chrome remains a CI run.
- Three committed-memory-backend input-order fixtures: scalar Sort omission, streaming counts with Boolean/float representatives and mixed numeric group order, and partition windows preserving float edges and numeric group classes (#641).
- Twenty-six for `BrowserDb`, including IndexedDB persistence, the default `allow_overrides` list (#869), the cursor, and the flush returning every dirty page and failing on one it cannot read (#470).
- Eleven for `BrowserBufferBackend` (which used `#[test]` and never ran before).
Expand Down
Loading
Loading
0