8000 Clarify historical MiniGraf design notes (main) by adityamukho · Pull Request #999 · 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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.

**Goal:** Fix the retraction semantics bug in `filter_facts_for_query`, extract shared net-view logic as a single source of truth, add early fact-size validation for file-backed inserts, and cover both with integration tests.
**Goal:** Fix the retraction semantics bug in `filter_facts_for_query`, use the same net-view function in `get_current_value` and `filter_facts_for_query`, add early fact-size validation for file-backed inserts, and cover both with integration tests.

**Architecture:** `net_asserted_facts` is added to `src/graph/storage.rs` and used by both `get_current_value` (fixing its ordering key from `tx_id` to `tx_count`) and `filter_facts_for_query` (fixing Step 2 to compute net view instead of naively filtering `asserted=true`). A `check_fact_sizes` guard is added to both write paths in `src/db.rs` before the WAL write. A `MAX_FACT_BYTES` constant is exported from `src/storage/packed_pages.rs`.

Expand Down Expand Up @@ -284,8 +284,8 @@ Insert this function immediately after the closing `}` of `get_current_value` (l
/// (NaN canonicalisation, ±0.0 disambiguation) consistently with the rest of
/// the storage layer.
///
/// This is the single source of truth for retraction semantics, shared by
/// `get_current_value` and `filter_facts_for_query`.
/// `get_current_value` and `filter_facts_for_query` both use this function
/// to decide which facts survive retraction.
pub(crate) fn net_asserted_facts(facts: Vec<Fact>) -> Vec<Fact> {
use std::collections::HashMap;
// key: (entity, attribute, canonical value bytes) → fact with highest tx_count
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.

**Goal:** Expose `:db/valid-from`, `:db/valid-to`, `:db/tx-count`, `:db/tx-id`, and `:db/valid-at` as first-class bindable values in Datalog `:where` patterns, unlocking the full four-class taxonomy of temporal queries.
**Goal:** Expose `:db/valid-from`, `:db/valid-to`, `:db/tx-count`, `:db/tx-id`, and `:db/valid-at` so Datalog `:where` patterns can bind these values. These bindings support four classes of temporal query.

**Architecture:** A new `PseudoAttr` enum and `AttributeSpec` wrapper type replace `EdnValue` in `Pattern.attribute`. The parser detects `:db/*` keywords and constructs `AttributeSpec::Pseudo`; the matcher binds the corresponding fact-metadata field instead of matching a stored attribute name. `:db/valid-at` is query-level: the executor computes it once and passes it into the matcher via a new `from_slice_with_valid_at` constructor.

Expand Down
4 changes: 2 additions & 2 deletions docs/superpowers/plans/2026-05-01-phase8-completion.md
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ Replace the entire "Current Focus" block (from `## Current Focus` down to and in

**Key Decisions Made**:
- ✅ Datalog query language (simpler, better for temporal)
- ✅ Bi-temporal as first-class feature (not afterthought)
- ✅ Bi-temporal support for transaction time and valid time built in from the start
- ✅ Keep single-file philosophy
- ✅ Recursive rules with semi-naive evaluation
- ✅ UTC-only timestamps (avoids chrono GHSA-wcg3-cvx6-7396)
Expand Down Expand Up @@ -726,7 +726,7 @@ Query either axis independently or together:
The unit of storage is `(entity, attribute, value, valid_from, valid_to, tx_id, tx_count, asserted)`. Entities are UUIDs. Attributes are keywords (`:person/name`). Values are strings, integers, floats, booleans, entity refs, keywords, or null.

**Datalog queries**
Pattern matching with variable unification. Recursive rules use semi-naive fixed-point evaluation. Transitive closure and cycle-safe graph traversal are first-class. Stratified negation (`not` / `not-join`), scalar aggregation (`count`, `sum`, `min`, `max`, `count-distinct`, `sum-distinct`), arithmetic/predicate expression clauses (`[(< ?age 30)]`, `[(+ ?a ?b) ?c]`), disjunction (`or` / `or-join`), window functions (`sum/count/min/max/avg/rank/row-number :over (:partition-by … :order-by …)`), and user-defined functions (custom aggregates + predicates via `FunctionRegistry`) are all supported.
Pattern matching with variable unification. Recursive rules use semi-naive fixed-point evaluation and support transitive closure and cycle-safe graph traversal. Stratified negation (`not` / `not-join`), scalar aggregation (`count`, `sum`, `min`, `max`, `count-distinct`, `sum-distinct`), arithmetic/predicate expression clauses (`[(< ?age 30)]`, `[(+ ?a ?b) ?c]`), disjunction (`or` / `or-join`), window functions (`sum/count/min/max/avg/rank/row-number :over (:partition-by … :order-by …)`), and user-defined functions (custom aggregates + predicates via `FunctionRegistry`) are all supported.

**Prepared statements**
Parse and plan a query once; execute thousands of times with different bind values. `$slot` tokens accepted in entity, value, `:as-of`, and `:valid-at` positions. `BindValue` variants: `Entity(Uuid)`, `Val(Value)`, `TxCount(u64)`, `Timestamp(i64)`, `AnyValidTime`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.

**Goal:** Add production-grade clippy lints to the entire workspace and fix all 336 existing violations so `cargo clippy --workspace` is error-free.
**Goal:** Enable the selected Clippy lints across the workspace and fix all 336 existing violations so `cargo clippy --workspace` is error-free.

**Architecture:** Lint rules live in `[workspace.lints.clippy]` in the root `Cargo.toml`; every workspace member opts in via `[lints] workspace = true`. Test code is exempted via `#![cfg_attr(test, allow(...))]` at each crate root. Violations are fixed file-by-file using `?`/`try_from`/`.get()` patterns — no `unwrap`, no direct indexing, no lossy casts in production paths.

Expand Down
6 changes: 3 additions & 3 deletions docs/superpowers/plans/2026-05-13-datalog-tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -1297,9 +1297,9 @@ fn main() -> anyhow::Result<()> {
}
```

Note: the `or-join` + arithmetic approach above is a pedagogically honest demonstration of
how to work around Minigraf's lack of `if/else` in expressions. Simplify the aggregate UDF
example if the `or-join` makes it too complex for the tutorial page — an alternative is to
Note: this example uses `or-join` and arithmetic because Minigraf does not support
`if/else` in expressions. Simplify the aggregate UDF example if the `or-join`
makes it too complex for the tutorial page. An alternative is to
pre-aggregate in Rust before transacting a `:order/signed-weight` fact.

**Page structure:**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.

**Goal:** Fix a known correctness bug where retracted facts remain visible in Datalog query results, extract shared retraction logic as a single source of truth, and add tests for retraction semantics plus two additional edge cases (oversized facts, checkpoint-during-crash).
**Goal:** Fix a known correctness bug where retracted facts remain visible in Datalog query results, share one net-view function between `get_current_value` and `filter_facts_for_query`, and add tests for retraction semantics plus two additional edge cases (oversized facts, checkpoint-during-crash).

**Architecture:** Three coherent pieces: (1) extract `net_asserted_facts` helper in the storage layer, (2) apply it in the query executor to fix Step 2 of `filter_facts_for_query`, (3) add integration tests covering retraction scenarios and edge cases.

Expand Down Expand Up @@ -70,8 +70,8 @@ Extract a module-level `pub(crate)` function. Use `encode_value` from `crate::st
/// Uses `encode_value` for the value key to ensure correct handling of
/// floating-point edge cases (NaN canonicalisation, ±0.0 disambiguation).
///
/// This is the single source of truth for retraction semantics, used by both
/// `get_current_value` and `filter_facts_for_query`.
/// `get_current_value` and `filter_facts_for_query` both use this function
/// to decide which facts survive retraction.
pub(crate) fn net_asserted_facts(facts: Vec<Fact>) -> Vec<Fact> {
use std::collections::HashMap;
use crate::storage::index::encode_value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

## Overview

Add arithmetic and predicate expression clauses to the Datalog `:where` clause, expressed as a unified `Expr` AST. This unlocks filter predicates (`[(< ?v 100)]`) and arithmetic bindings (`[(+ ?a ?b) ?result]`) without requiring application-side post-processing.
Add arithmetic and predicate expression clauses to the Datalog `:where` clause, expressed as a unified `Expr` AST. This lets queries filter rows with predicates (`[(< ?v 100)]`) and bind arithmetic results (`[(+ ?a ?b) ?result]`) without requiring application-side post-processing.

This is a load-bearing dependency for Phase 7.7 (temporal range queries via `:db/valid-from` / `:db/valid-to` pseudo-attributes) and Phase 7.9b (UDF predicates via `FunctionRegistry`).
These clauses are required for Phase 7.7 (temporal range queries via `:db/valid-from` / `:db/valid-to` pseudo-attributes) and Phase 7.9b (UDF predicates via `FunctionRegistry`).

---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

## Goal

Expose `valid_from`, `valid_to`, `tx_count`, `tx_id`, and the query-level `valid_at` point as first-class bindable values in Datalog `:where` clauses, unlocking the full four-class taxonomy of temporal queries.
Allow Datalog `:where` patterns to bind `valid_from`, `valid_to`, `tx_count`, `tx_id`, and the query's `valid_at` time. These bindings support four classes of temporal query.

---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

Compile Minigraf to `wasm32-wasip1` (WASI) so it runs inside server-side WASM runtimes — Wasmtime, Wasmer, Cloudflare Workers (WASI), and Fastly Compute — with a working in-memory REPL and no JavaScript bridge required.

This is orthogonal to Phase 8.1a (browser WASM with IndexedDB). Both share the `wasm32` architecture but use different targets and storage models:
Phase 8.1b is independent of Phase 8.1a (browser WASM with IndexedDB). Both use `wasm32`, but with different build targets and storage models:
- **8.1a**: `wasm32-unknown-unknown` + `wasm-bindgen` → browser (IndexedDB)
- **8.1b**: `wasm32-wasip1` → server-side WASM runtimes (in-memory; file-backed is out of scope)

Expand Down
2 changes: 1 addition & 1 deletion docs/superpowers/specs/2026-05-03-clippy-lints-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

**Date:** 2026-05-03
**Status:** Approved
**Scope:** Add production-grade clippy lints across the entire workspace and fix all existing violations
**Scope:** Enable the selected Clippy lints across the workspace and fix all existing violations

---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@

## Overview

The Minigraf Datalog tutorial will be delivered as a series of wiki pages (GitHub Wiki),
driven by a single coherent real-world storyline. The storyline provides narrative scaffolding
so readers encounter each language feature in a context they already understand emotionally —
rather than in a contrived, isolated example.
The Minigraf Datalog tutorial will be delivered as a series of GitHub Wiki pages.
The pages follow one real-world storyline so readers meet each language feature
in a familiar context rather than in an isolated example.

The domain is **e-commerce order management**, chosen because:
- Nearly every reader has placed an online order
Expand Down
4 changes: 2 additions & 2 deletions docs/superpowers/specs/2026-05-19-perf-tuning-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ sense in context. It is the reference complement to the tutorials — scannable,

### Section 1 — Cost Model

A table of every operation with its cost class and a short note. Purpose: give users a mental model
before they reach for any knob.
List each operation, its cost class, and a short note. The table helps readers
understand the cost of each operation before changing any tuning settings.

| Operation | Cost | Notes |
|---|---|---|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ For high-write-volume callers (bulk ingestion, migration, seeding) issuing many
Discovered while diagnosing event-loop blocking in `temporal-reasoning`'s git-history ingestion,
which issues ~20-25 separate `execute()`/`checkpoint()` calls per commit.

Three independent improvements, increasing risk/leverage:
Three independent improvements, ordered from lower to higher risk and potential benefit:

1. `sync_all()` → `sync_data()` (fdatasync): skips the inode-metadata flush `sync_all()` also
does. The WAL is pure-append, so no metadata beyond file length (which `sync_data()` still
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,8 @@ uncoded.
code+category, not text): the initial draft of this spec. Rejected on
review — it left `ERROR_REFERENCE.md` sync as a code-list check only, with
no mechanism catching drift between a call site's actual wording and its
documented "Error text." Moving the template into `REGISTRY` costs a small
hand-rolled runtime formatter (Rust's `format!` needs a compile-time
literal, which a data-driven template can't supply) but makes the registry
the true single source of truth the acceptance criteria call for.
documented "Error text." Moving the template into `REGISTRY` requires a small
custom formatter because Rust's `format!` needs a compile-time literal, which a
data-driven template cannot supply. In return, the registry defines each
error's code, category, and message template in one place, as the acceptance
criteria call for.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Full investigation: `Planner-Discussion/Claude-01.md` and `Codex-01.md`. Key ref
- WASI: core v3 `benchmarks/bindings839/wasi.py` (+ `validate.py`, `test_wasi.py`, `test_guardrails.py`, `README.md:8-35`). 3 REPL cases, Wasmtime with `-C cache=n -C parallel-compilation=n`, no preopened dir (in-memory), 3 warmups, 10 samples, 20 ops per query sample. It refuses Python `-O`, and `--core-revision` is only a label. `.github/workflows/wasm.yml:105-128` already pins Wasmtime `v49.0.2` (its test flags preopen a dir and must not be copied into timing).
- `benchmarks/bindings839/validate.py:11-49` is a strict validator for the 14-case and 3-case sets: full sets only, rejects smoke. Partial mobile activation needs an equally strict selection contract, not a loosened allowlist.
- Swift/iOS: `minigraf-swift` v3 `bench/device-farm/`. `Tests/BenchmarkTests.swift:152-181` rejects simulator timing. `build.sh:27-61` builds device + arm64-simulator libraries but records only the device library hash/ABI. `:70-81` auto-picks a simulator (not pinned). `.github/workflows/bench-839-build.yml` builds the IPA/XCTest.
- Android: `minigraf-android` v3 `bench/device-farm/`. It is ARM64-only (`build.sh:32-65`, `build.gradle.kts:16-32` `arm64-v8a`), non-debuggable Release. `BenchmarkTest.kt:88-134` defaults to smoke, and `-e mode benchmark` times. It records model/fingerprint/ABIs but has no first-class physical-versus-emulated identity.
- Android: `minigraf-android` v3 `bench/device-farm/`. It is ARM64-only (`build.sh:32-65`, `build.gradle.kts:16-32` `arm64-v8a`), non-debuggable Release. `BenchmarkTest.kt:88-134` defaults to smoke, and `-e mode benchmark` times. The v3 harness records the model, fingerprint and ABIs, but does not report explicitly whether the run used a physical device or an emulator.
- Physical baselines: `docs/benchmarks/839-bindings/results.md` (v3). Pixel 7 / Android 14 and iPhone 15 (`iPhone15,4`) / iOS 18.5, core `33e5dffa…`, AWS Device Farm public devices (a model/OS pin, not a reserved unit), with visible spread. These are historical and **not** the qualification reference (see §6).
- Status drift: `docs/benchmarks/839-bindings/README.md:3-4`, `dispositions.md:34-48` and `docs/BINDING_BENCHMARKS.md:79-102` still say "pending sign-off". #839 accepted both maintainer roles for evidence revision `10ff8003…` (merged in #852 as `cdad3e72…`).
- #840 completion record and tooling: `docs/benchmarks/840-regression/completion.md:14-129` (fresh independent runs, inherited main observations excluded, isolated notification scenarios, checksummed archives that reproduce byte-for-byte). This is the pattern for the evidence work here.
Expand Down
Loading
0