diff --git a/.aristo/canon-matches.toml b/.aristo/canon-matches.toml new file mode 100644 index 000000000..a83cca820 --- /dev/null +++ b/.aristo/canon-matches.toml @@ -0,0 +1,135 @@ +[__meta__] +schema_version = 1 +canon_version = "v0.1.0" +last_fetched = "2026-05-30T06:00:12.353Z" + +[aret_4mbjdhds] +last_match_text_hash = "sha256:9d400437abc7d933b5a5f93bdc8bef54c9f0dbc03d029683fd41dbfe40b5bc16" +canon_fetched_at = "2026-05-26T06:22:36.7271Z" + +["aristos:wal_checkpoint_error_no_db_leak"] +last_match_text_hash = "sha256:99cf0a4664b81492fcaf3eaace7c7ab17a51261a6c340c7cad8faae4be7d45cc" +canon_fetched_at = "2026-05-30T06:00:12Z" + +[["aristos:wal_checkpoint_error_no_db_leak".accepted_matches]] +canon_id = "wal_checkpoint_error_no_db_leak" +version = "v0.1.0" +canonical_text = """ +A checkpoint failure must not leak frames into the main database file +""" +canon_version = "v0.1.0" +confidence = 0.982379848137498 +prefix_tier = "aristos:" +backed_by = "golden model + proofs + differential testing" +linked = "arta_5cc2507abbafa1dcca819c702e32c824" +accepted_at = "2026-05-30T06:00:12Z" +bound_at = "2026-05-30T06:00:12Z" + +["aristos:wal_commit_requires_fsync"] +last_match_text_hash = "sha256:eabb4e41b7add936f2f8679a208a15b4c545042d2644a7d920de7c6f767ff7c6" +canon_fetched_at = "2026-05-30T06:00:12Z" + +[["aristos:wal_commit_requires_fsync".accepted_matches]] +canon_id = "wal_commit_requires_fsync" +version = "v0.1.0" +canonical_text = """ +A commit frame must reach stable storage via fsync before the transaction is reported as durable +""" +canon_version = "v0.1.0" +confidence = 0.9738098997622728 +prefix_tier = "aristos:" +backed_by = "golden model + proofs + differential testing" +linked = "arta_e376126754850310276ec5c621c3c717" +accepted_at = "2026-05-30T06:00:12Z" +bound_at = "2026-05-30T06:00:12Z" + +["aristos:wal_find_frame_range_invariant"] +last_match_text_hash = "sha256:a6a6aabf707adfe418c11bc5ea417c1364c926f72ee5f05bd27b8b6aac7b34f5" +canon_fetched_at = "2026-05-30T05:43:56Z" + +[["aristos:wal_find_frame_range_invariant".accepted_matches]] +canon_id = "wal_find_frame_range_invariant" +version = "v0.1.0" +canonical_text = """ +find_frame never reads outside the live frame range [nbackfills, max_frame] +""" +canon_version = "v0.1.0" +confidence = 0.9851749204099178 +prefix_tier = "aristos:" +backed_by = "golden model + proofs + differential testing" +linked = "arta_961fe492d27d1abdb6f6af1e6a38ac79" +accepted_at = "2026-05-30T05:43:56Z" +bound_at = "2026-05-30T05:43:56Z" + +["aristos:wal_initialized_reflects_sync_outcome"] +last_match_text_hash = "sha256:9d400437abc7d933b5a5f93bdc8bef54c9f0dbc03d029683fd41dbfe40b5bc16" +canon_fetched_at = "2026-05-26T06:23:53Z" + +[["aristos:wal_initialized_reflects_sync_outcome".accepted_matches]] +canon_id = "wal_initialized_reflects_sync_outcome" +version = "v0.1.0" +canonical_text = """ +The WAL initialized flag is set true only after a successful sync of the wal-header +""" +canon_version = "v0.1.0" +confidence = 1.0000000000000002 +prefix_tier = "aristos:" +backed_by = "golden model + proofs + differential testing" +accepted_at = "2026-05-26T06:23:53Z" +bound_at = "2026-05-26T06:23:53Z" + +["aristos:wal_nbackfills_orders_with_recovery"] +last_match_text_hash = "sha256:7e7d1fd2ae298d6be58888acc49a0b7464f686bb0aa5725cf62e7459d3c59f42" +canon_fetched_at = "2026-05-30T06:00:12Z" + +[["aristos:wal_nbackfills_orders_with_recovery".accepted_matches]] +canon_id = "wal_nbackfills_orders_with_recovery" +version = "v0.1.0" +canonical_text = """ +The nbackfills counter advances after frames are durable, so recovery never replays already-checkpointed frames +""" +canon_version = "v0.1.0" +confidence = 0.9736252743750812 +prefix_tier = "aristos:" +backed_by = "golden model + proofs + differential testing" +linked = "arta_40ceca467c64335d30ced059369d412f" +accepted_at = "2026-05-30T06:00:12Z" +bound_at = "2026-05-30T06:00:12Z" + +["aristos:wal_truncate_atomic_under_concurrent_writers"] +last_match_text_hash = "sha256:3d260cf86a59e54d02ee3224cc3951b4c17aa0488e8be1109cf70e0912eef1ae" +canon_fetched_at = "2026-05-30T05:43:56Z" + +[["aristos:wal_truncate_atomic_under_concurrent_writers".accepted_matches]] +canon_id = "wal_truncate_atomic_under_concurrent_writers" +version = "v0.1.0" +canonical_text = """ +WAL truncate is atomic: no committed frame can be observed lost across the truncate operation +""" +canon_version = "v0.1.0" +confidence = 0.9876048462465404 +prefix_tier = "aristos:" +backed_by = "golden model + proofs + differential testing" +linked = "arta_013316bc46e9af51cf52612fe2533e90" +accepted_at = "2026-05-30T05:43:56Z" +bound_at = "2026-05-30T05:43:56Z" + +[wal_checkpoint_error_no_db_leak] +last_match_text_hash = "sha256:99cf0a4664b81492fcaf3eaace7c7ab17a51261a6c340c7cad8faae4be7d45cc" +canon_fetched_at = "2026-05-30T06:00:12.360964Z" + +[wal_commit_requires_fsync] +last_match_text_hash = "sha256:eabb4e41b7add936f2f8679a208a15b4c545042d2644a7d920de7c6f767ff7c6" +canon_fetched_at = "2026-05-30T06:00:12.360964Z" + +[wal_find_frame_range_invariant] +last_match_text_hash = "sha256:a6a6aabf707adfe418c11bc5ea417c1364c926f72ee5f05bd27b8b6aac7b34f5" +canon_fetched_at = "2026-05-30T05:43:33.980749Z" + +[wal_nbackfills_orders_with_recovery] +last_match_text_hash = "sha256:7e7d1fd2ae298d6be58888acc49a0b7464f686bb0aa5725cf62e7459d3c59f42" +canon_fetched_at = "2026-05-30T06:00:12.360964Z" + +[wal_truncate_atomic_under_concurrent_writers] +last_match_text_hash = "sha256:3d260cf86a59e54d02ee3224cc3951b4c17aa0488e8be1109cf70e0912eef1ae" +canon_fetched_at = "2026-05-30T05:43:33.980749Z" diff --git a/.github/workflows/aristo-verify.yml b/.github/workflows/aristo-verify.yml new file mode 100644 index 000000000..ae1664c47 --- /dev/null +++ b/.github/workflows/aristo-verify.yml @@ -0,0 +1,32 @@ +# Aristo heavy verification — runs `aristo verify` (server-side canon +# conformance) for all bound annotations in .aristo/index.toml. This clones, +# builds, and runs the conformance harness on Aretta's infrastructure and +# reports back, so it needs an Aretta token. +# +# Triggers: manual only (workflow_dispatch). A nightly `schedule` is available +# but commented out below — uncomment to enable it. Deliberately NOT on push or +# pull_request — verify requires the checked-out commit to exist on origin, and +# a PR's synthetic merge-commit HEAD is not pushed. +# +# Target: turso's per-repo conductor instance, addressed via the ARETTA_API_URL +# repo Variable and authenticated with the ARETTA_TOKEN secret. The server-side +# instance decides the books edition / flavor; this client only sends (repo, +# commit), so this file does not change as the books evolve. +name: aristo verify +on: + workflow_dispatch: + # Nightly run — uncomment to enable scheduled verification. + # schedule: + # - cron: '0 7 * * *' # nightly at 07:00 UTC +jobs: + verify: + runs-on: ubuntu-latest + env: + # The per-repo conductor instance; managed via the ARETTA_API_URL repo Variable. + ARETTA_API_URL: ${{ vars.ARETTA_API_URL }} + steps: + - uses: actions/checkout@v4 + - uses: aretta-ai/aristo-action@v1 + with: + checks: verify + aretta-token: ${{ secrets.ARETTA_TOKEN }} diff --git a/.github/workflows/aristo.yml b/.github/workflows/aristo.yml new file mode 100644 index 000000000..581f85f93 --- /dev/null +++ b/.github/workflows/aristo.yml @@ -0,0 +1,25 @@ +# Aristo lite PR gate — the cheap, local checks via the shared aristo-action +# (aretta-ai/aristo-action). No token needed; runs entirely on the runner. +# +# audit — every committed .aristo/proofs/*.proof is fresh vs source (no +# stale/refuted/orphan). The 0.4 proof-freshness gate that replaces +# the legacy `stamp --check`; .aristo/index.toml is now a gitignored, +# regenerable cache (never committed), rebuilt from source on demand. +# lint — annotation quality (strict by default: warnings fail the build). +# The `doc` check is intentionally omitted in this PR: .aristo/doc/ is +# gitignored to keep the diff small. Regenerate the docs with `aristo doc` and +# add `doc` back here to re-enable the in-sync check. +# +# `version` is left unpinned, so the action installs the latest aristo from +# crates.io. Heavy canon verification (`aristo verify`) is a separate workflow: +# .github/workflows/aristo-verify.yml (manual + nightly, needs ARETTA_TOKEN). +name: aristo +on: [push, pull_request] +jobs: + aristo: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: aretta-ai/aristo-action@v1 + with: + checks: audit, lint diff --git a/.gitignore b/.gitignore index fc2f570a1..fe7ce4a61 100644 --- a/.gitignore +++ b/.gitignore @@ -87,3 +87,19 @@ CLAUDE.md bindings/python/dev.py bindings/python/implementation-test/ dhat-heap.json + +# Aristo runtime, cache, and per-user state: never commit these. +# Durable state (.aristo/proofs/*.proof, .aristo/specs/, .aristo/feedback/, +# .aristo/expectations.toml, .aristo/canon-matches.toml, aristo.toml) is +# committed and intentionally not listed here. +.aristo/index.toml +# Per-annotation docs: normally committed, but excluded from this PR to keep the +# diff small. Regenerate with `aristo doc` (see CONTRIBUTING.md -> Aristo). +.aristo/doc/ +.aristo/sessions/ +.aristo/nudge-state.toml +.aristo/verify-queue/ +.aristo/critique-queue/ +.aristo/critiques/ +.aristo/proofs/*.proof.bak +.aristo/archive/ diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 226a07792..fd6312c4b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -421,6 +421,63 @@ And launch an Antithesis test run with: scripts/antithesis/launch.sh ``` +## Annotating intent with Aristo + +Turso uses [Aristo](https://github.com/aretta-ai/aristo) to capture design intent that the code alone doesn't spell out — invariants a refactor could silently break — as `#[aristo::intent("...")]` annotations attached to the code. They're optional; reach for one only when a property is invisible from the signature and not already guarded by a test. For example, on the WAL trait in `core/storage/wal.rs`: + +```rust +#[aristo::intent( + "An append-only log that records page-level changes before they are \ + applied to the database, so a system crash can be recovered by \ + replaying the log.", + verify = "neural", + id = "wal_records_changes_before_apply", +)] +pub trait Wal: Debug + Send + Sync { ... } +``` + +The macros are a workspace dependency, so annotated code builds normally. To author and lint annotations, install the CLI: + +```console +cargo install aristo-cli # provides the `aristo` command +aristo lint # lint annotation prose (also runs in CI on every PR) +``` + +Annotations with `verify = "neural"` are machine-checked by an agent. The skills +that drive this are not committed to this repository — they are generated by the +CLI and tied to its version — so install them into your local agent on demand: + +```console +aristo install-skills --agent claude-code --user # installs into ~/.claude/skills/, not the repo +``` + +Then, from Claude Code, run `/aristo-verify`. The skill produces a verdict for each +annotation pending verification and writes the proofs under `.aristo/proofs/`. To +validate those proofs and apply them to the annotation index, run: + +```console +aristo verify --apply-verdicts +``` + +To run deep verification, run this prompt with `claude`: + +``` +Run Aristo canon match +``` + +Some intents assert invariants over internal state the public API doesn't expose. Rather than widen the API for tests, mark that state with the `aristo::instrument` macros (`#[derive(Inspect)]`, `#[expose_pub]`, `yield_point!`) behind a Cargo feature, so the verification harness can read it while normal builds compile it out entirely. See the `/aristo-instrumenting` skill for when and how. + +### Using Aristo, day to day + +Write intents *as you write the code* — one at a time, in the same change, while the rationale is fresh; a batched "annotate it later" pass recovers the *what* but not the *why*. `aristo status` shows where a module stands and `aristo nudge` suggests the next action. Inside an AI agent (see [Developing with AI coding agents](#developing-with-ai-coding-agents)) the loop runs through the installed skills rather than the bare CLI: + +* `/aristo-status` — read the board (what's annotated, verified, awaiting review). +* `/aristo-authoring` — write good intents while you're in the code. +* `/aristo-verify` — verify the annotations your change touched. +* `/aristo-intent-suggestions` and `/aristo-authored-review` — review what was authored. + +Only the durable, trust-gating artifacts are committed: `aristo.toml`, the annotations themselves, `.aristo/proofs/*.proof`, and `.aristo/doc/`. The annotation index (`.aristo/index.toml`) is a regenerable, gitignored cache — every read command rebuilds it from source, so there's nothing to stage. + ## Adding Third Party Dependencies When you want to add third party dependencies, please follow these steps: diff --git a/Cargo.lock b/Cargo.lock index 008b2c3e6..509d4b4a0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -225,6 +225,26 @@ version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "69f7f8c3906b62b754cd5326047894316021dcfe5a194c8ea52bdd94934a3457" +[[package]] +name = "aristo" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe6ebb7c22c91a8d0b936448480e0216a9621dc09481a3c08a08f9fe4a64ad57" +dependencies = [ + "aristo-macros", +] + +[[package]] +name = "aristo-macros" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "382cece5540ed31a126d26ca551561a670d7940074787b420585bd0d39676e7f" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.100", +] + [[package]] name = "arrayref" version = "0.3.9" @@ -6643,6 +6663,7 @@ dependencies = [ "allocator-api2 0.4.0", "antithesis_sdk", "arc-swap", + "aristo", "bigdecimal", "bitflags 2.9.4", "branches", diff --git a/aristo.toml b/aristo.toml new file mode 100644 index 000000000..cc67873d4 --- /dev/null +++ b/aristo.toml @@ -0,0 +1,34 @@ +[instance] +# Aristo data-plane endpoint for this repo's verify + canon requests. +# ARETTA_API_URL overrides it; auth/login is unaffected (token stays +# minted against the central account server). +url = "https://turso.aretta.ai" + +[verify.cache] +strategy = "local" +commit_specs = true + +[stamp] +hooks = "pre-commit" +hash_crate_root = false + +[telemetry] +enabled = false + +[lint] +pre_commit = "check" +strict = false + +[corpus] +contribute = false + +[doc] +commit_artifacts = true +position = "before" + +[index] + +[canon] +enabled = true +threshold_stamp = 0.85 +threshold_critique = 0.65 diff --git a/core/Cargo.toml b/core/Cargo.toml index f4c70232e..224865c86 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -72,6 +72,12 @@ libloading = "0.8.6" tantivy = { version = "0.26.0", optional = true } [dependencies] +# aristo SDK from crates.io (0.4.x — latest; also carries the aristo::instrument +# surface behind the `aristo_instrument` feature, for future state-exposure +# accessors). Was a local sibling path (../../aristo) pre-OSS; the conformance +# harness resolves aristo + aristo-macros from crates.io, so no vendored mount +# / path-rewrite is needed. +aristo = "0.4" turso_ext = { workspace = true, features = ["core_only"] } cfg_block = "0.1.1" fallible-iterator = { workspace = true } diff --git a/core/storage/pager.rs b/core/storage/pager.rs index 071e255b9..2bb3fe41a 100644 --- a/core/storage/pager.rs +++ b/core/storage/pager.rs @@ -3962,6 +3962,7 @@ impl Pager { } #[instrument(skip_all, level = Level::DEBUG)] + #[aristo::intent("A commit frame must reach stable storage via fsync before the transaction is reported as durable\n", id = "aristos:wal_commit_requires_fsync", verify = "full", parent = "wal_protocol_correctness")] fn commit_dirty_pages_inner( &self, allowed_auto_actions: WalAutoActions, @@ -4450,6 +4451,7 @@ impl Pager { ) } + #[aristo::intent("The nbackfills counter advances after frames are durable, so recovery never replays already-checkpointed frames\n", id = "aristos:wal_nbackfills_orders_with_recovery", verify = "full", parent = "wal_protocol_correctness")] fn checkpoint_inner( &self, mode: CheckpointMode, diff --git a/core/storage/wal.rs b/core/storage/wal.rs index 540148630..a9c2a8ea4 100644 --- a/core/storage/wal.rs +++ b/core/storage/wal.rs @@ -595,6 +595,7 @@ trait WalCoordination: Debug + Send + Sync { } /// Write-ahead log (WAL). +#[aristo::intent("The WAL subsystem maintains LSN monotonicity, frame commitment ordering, recovery idempotency, checkpoint safety, and group commit atomicity.", id = "wal_protocol_correctness", verify = "neural")] pub trait Wal: Debug + Send + Sync { /// Begin a read transaction. /// Returns whether the database state has changed since the last read transaction. @@ -3262,6 +3263,12 @@ impl Wal for WalFile { /// Find the latest frame containing a page. #[instrument(skip_all, level = Level::DEBUG)] + #[aristo::intent( + "find_frame never reads outside the live frame range [nbackfills, max_frame]\n", + id = "aristos:wal_find_frame_range_invariant", + verify = "full", + parent = "wal_protocol_correctness" + )] fn find_frame(&self, page_id: u64, frame_watermark: Option) -> Result> { #[cfg(not(feature = "conn_raw_api"))] turso_assert!( @@ -4014,6 +4021,12 @@ impl Wal for WalFile { } } + #[aristo::intent( + "The WAL initialized flag is set true only after a successful sync of the wal-header\n", + id = "aristos:wal_initialized_reflects_sync_outcome", + verify = "full", + parent = "wal_protocol_correctness" + )] fn prepare_wal_finish(&self, sync_type: FileSyncType) -> Result { let file = self.coordination.wal_file()?; let coordination = self.coordination.clone(); @@ -4506,6 +4519,12 @@ impl WalFile { Ok(()) } + #[aristo::intent( + "A checkpoint failure must not leak frames into the main database file\n", + id = "aristos:wal_checkpoint_error_no_db_leak", + verify = "full", + parent = "wal_protocol_correctness" + )] fn checkpoint_inner( &self, pager: &Pager, @@ -4884,6 +4903,7 @@ impl WalFile { } /// Truncate WAL file to zero and sync it. Called by pager AFTER DB file is synced. + #[aristo::intent("WAL truncate is atomic: no committed frame can be observed lost across the truncate operation\n", id = "aristos:wal_truncate_atomic_under_concurrent_writers", verify = "full", parent = "wal_protocol_correctness")] fn truncate_log( &self, result: &mut CheckpointResult,