8000 fix: one current valid-time window per (e, a, v) (#435) by adityamukho · Pull Request #460 · project-minigraf/minigraf · GitHub
[go: up one dir, main page]

Skip to content

fix: one current valid-time window per (e, a, v) (#435) - #460

Merged
adityamukho merged 1 commit into
v3from
fix/435-one-window-per-triple
Oct 6, 2026
Merged

adityamukho merged 1 commit into
v3from
fix/435-one-window-per-triple

Conversation

@adityamukho
Copy link
Copy Markdown
Collaborator

Refs #435 (tracker #383). Targets v3; no file format change, but query results change for existing data (v3.0.0 behaviour change).

Model

At transaction time N each (e, a, v) has exactly one current valid-time window: the one from its latest assertion with tx_count ≤ N, if that is newer than its last retraction. A later assertion replaces the earlier window; the earlier one stays visible through :as-of. Closing, extending or reopening a window is a plain transact with the new bounds (no close command). retract still withdraws the triple.

query (tx 1 [2020, 2022), tx 2 [2024, ∞)) before after
:as-of 1 :valid-at "2021-01-01" found found
:as-of 2 :valid-at "2021-01-01" found not found
:as-of 2 :valid-at "2025-01-01" found found

Changes

  • net_asserted_facts: winner per (e, a, v) by tx_count, with a tied flag; only tied triples (pre-check data) take a second pass. Still idempotent under duplicates, still uses the keyed hasher.
  • OnDiskReader::live_scan: the first transaction group of a triple at or before as_of decides it; everything older is skipped (existing seek after 8). Per-triple window set removed.
  • API-011 (new, documented in ERROR_REFERENCE.md): two different windows for one triple in one transaction are rejected before a tx_count is allocated or the WAL is written. This covers Minigraf::execute, WriteTransaction::commit, the browser write path and FactStorage::transact*. Identical repeats, other values and retractions are allowed.
  • Pre-existing data with two windows in one transaction keeps both (once each), in memory and on disk. Open, WAL replay and migration never reject.

Tests

  • Unit: replace, close, retraction, same-tx retraction, legacy tied windows; randomized histories against a new per-triple model (replaces the pre-perf: point query on a bound entity scans the entity's whole version history — O(retract/reassert count), not O(live facts) #323 per-window oracle); API-011 accept/reject; a rejected batch takes no tx_count.
  • On disk: a hand-written history at every as_of, before and after reopen. I checked that it fails on the old per-window walk.
  • tests/valid_time_window_test.rs (8 tests): the issue's table, close, extend/reopen, retract-then-reassert, API-011 from transact and WriteTransaction. Each runs in memory, checkpointed and reopened, via EAVT and AEVT.
  • Revised bitemporal_test::test_same_eav_later_valid_time_interval_replaces_earlier and multi_value_test::multi_value_time_stints_…. Both encoded the old two-live-windows behaviour.
  • same_transaction_multi_window_matches_full_scan and the golden corpus pass unchanged.

Local: cargo fmt --check, cargo clippy --all-features -D warnings, cargo check --target wasm32-unknown-unknown --features browser, cargo test → 1258 passed, 0 failed, 9 ignored (1267 total).

Follow-ups (not in this PR)

🤖 Generated with Claude Code

https://claude.ai/code/session_015GgLEs8YozJjYhwPEYgTUn

At transaction time N a triple now has exactly one current valid-time
window: the one from its latest assertion at or before N, if newer than
its last retraction. A later assertion replaces the earlier window, which
stays visible through :as-of. Closing, extending or reopening a window is
a plain transact with the new bounds; retract still withdraws the triple.

net_asserted_facts now picks a winner per (e, a, v) instead of per
(e, a, v, vf, vt), and the on-disk key walk stops at each triple's first
transaction group. Two windows of one triple in one transaction are
rejected with the new API-011 before a tx_count is taken (execute,
WriteTransaction::commit, the browser write path, FactStorage::transact*).
Records written before the check with two windows in one transaction keep
both; open, WAL replay and migration never fail on them.

This changes query results for existing data, so it ships in v3.0.0.
Design: docs/superpowers/specs/2026-10-06-one-window-per-triple-design.md

Refs #435, #383

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015GgLEs8YozJjYhwPEYgTUn
@codecov
codecov Bot commented Oct 6, 2026
Copy link
Copy Markdown
8000

Codecov Report

❌ Patch coverage is 98.76543% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/storage/reader.rs 92.30% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@adityamukho
adityamukho merged commit 22f18d8 into v3 Oct 6, 2026
19 checks passed
@adityamukho
adityamukho deleted the fix/435-one-window-per-triple branch October 6, 2026 18:39
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.

1 participant

0