Skip to content

Add versioned feature values to DiskGraph (Stage 1 proof of concept) - #594

Draft
anle2024 wants to merge 7 commits into
mainfrom
anle/versioned-features-poc
Draft

anle2024 wants to merge 7 commits into
mainfrom
anle/versioned-features-poc

Conversation

@anle2024

@anle2024 anle2024 commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator

Design discussion or issue: none. This PR is the Stage 1 proof of concept of mutable data in DiskGraph: P1 feature values on layout v4, Mode A.

Summary

This PR lets a DiskGraph index serve the feature values that a node had at the anchor time of each sample. On main, each row has only one fixed state. A new call, build_versions, reads a column-level audit log and writes a version sidecar next to an existing index. The sampler and training-table generation then read the row that was live at each anchor time.

This is one large draft PR, so that the whole proof of concept can be reviewed in one place. Its six commits follow its parts: the sidecar and the gate, the fold, the sampler, training-table generation, the Python bindings, and an end-to-end check.

It also fixes a bug that main has too, in TypeState::adaptive_reset. A fused sampler request that fails partway leaves decoded rows in the pooled state. The next request on that state then returns them.

Why

A DiskGraph index stores one row per node. When a feature value changes over time, for example a user's status, the index can hold only one state. Training then sees either the first state at every anchor, or a later state that leaks future information. This proof of concept stores the first state as the base row and the later states in a sidecar. Each anchor then reads the state that was true at that time.

Before and now

Part Before (main) Now (this PR)
Index One row per node The same base rows, plus an optional versions/ sidecar with one full row for each later version of a changed node
Build ingest only ingest, unchanged, then build_versions(index_dir, history_json). ingest_with_history runs both. A longer history reruns only build_versions.
History input None A column-level audit log: key, column, old value, new value and changed_at. Periodic snapshots are in the spec, but the build refuses them for now.
Unsupported changes Not applicable The gate refuses them with a report of counts and sample rows. Examples are new rows, deletes, key changes, create-time and edge sort-key changes, new columns, bad values, and an old value that does not match. A refusal writes nothing.
Sampler reads The base row The row live at the anchor of the node instance's root seed, in the fused, chunked and non-fused paths. A read of a versioned table without an anchor is an error.
Uniform sampling, fetch_features, legacy load Work on every index Refused on an index with versions, because they read no anchor time
Training tables Entity values from the base row Seed checks (entity filter, split value, include bit) read at each anchor. Label reads of entity columns read at the end of the label window. Other reads of a changed column stop the plan with an error that names the column and the read site.

A version is live from the first index tick at or after its changed_at until the next version starts.

Why the new way is better

  • Each anchor sees the value that was true at that time. On the end-to-end fixture, a label read at the anchor instead of at the end of the window gives different values. The count is 326 to 6,223 values, by label kind. Seed values read at the end of the window instead of at the anchor differ in 13,183 values.
  • An index without history keeps the old code paths. The Rust and Python suites pass unchanged.
  • Every unsupported case stops with a named reason instead of a silent wrong row.

Trade-off and known limits

  • A version row is a full row, so a change of one column stores the whole row again.
  • build_versions holds all version rows in memory until it writes the sidecar.
  • Column statistics stay on the base rows.
  • Uniform sampling is refused on an index with versions.
  • A training-table entity filter that combines an entity condition with an aggregate, for example WHERE status = 'active' AND COUNT(...) > 0, is refused today.
  • Split values are read at each anchor, so one entity can be in train at one anchor and in validation at another.
  • Static link-prediction plans read the latest version.
  • The sidecar is published by renaming folders. A crash between the renames can leave the index without versions/, and it then reads as an index without history until build_versions runs again.
  • New rows, deletes, foreign-key changes and snapshot input are planned for later stages.

Change map

See the change-map comment on this PR.

Testing Done

  • cargo test --locked --workspace in packages/diskgraph: 2,283 passed, 18 ignored and 1 failed. The failure is disk_manager::tests::test_eviction_under_real_disk_pressure, which measures free space on a shared disk. It missed by 1,000,000 bytes on the test machine.
  • The new version tests: sidecar 9, fold 12, gate 27, pre-check 3, reader 3, sampler 13, spec 3 and training table 9.
  • cargo clippy --locked --workspace --all-targets -- -D warnings: clean, except the unchanged diskgraph-ptrhash/src/test.rs, which fails the same way on main on aarch64.
  • Python suite against a wheel of this branch: 954 passed, including the 15 new tests in test_versions.py. 1 test and 4 test modules fail only because the test machine has no kumoapi module. They fail the same way on main.
  • scripts/versions_e2e/e2e_engine.py: 26 of 26 checks passed with 0 mismatches over 22,063,665 compared values. It compares every sampled row and every training-table row with an independent oracle. It also runs every refusal case on the index without history first, where the case must succeed.
  • Not tested yet: product-level runs at 100M rows through kumo-core, training, and the leak test.

Hotfix Context

Not a hotfix.

Checklist

  • I listed all the breaking changes introduced by the PR (none for indexes without history)
  • I made sure to update examples and documentation with my changes (if necessary)
  • I have added and modified unit tests required to cover changes made by this PR.

🤖 Generated with Claude Code

anle2024 and others added 6 commits December 3, 2026 09:10
This is part 1 of the versioned-features proof of concept: Stage 1,
P1 feature values on layout v4, Mode A.

diskgraph-index gets a version sidecar in <index>/versions/: a
manifest and, for each shard, a bitmap of the nodes with versions,
offsets, and one full row for each later version. The base row stays
the first state of the node. TableReader can now return the row of a
node at a time tau, and it refuses a sidecar that belongs to another
index build.

diskgraph-ingest gets the history spec (a column-level audit log, or
periodic snapshots, which the build refuses for now), an audit-log
reader, and a gate that refuses every kind of change that Stage 1
does not support. A refusal returns a report with a count and up to
five sample rows for each reason.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This is part 2 of the versioned-features proof of concept.

diskgraph_ingest::versions::build_versions(index_dir, history_json)
runs the gate, then folds the changes of each node forward from its
base row in time order, and writes the version sidecar. A change is
live from the first index tick at or after its changed_at. Changes of
one node inside one tick merge in (changed_at, file row order).

The fold refuses an old_value that differs from the value before the
change, a value that does not fit the column type, and a row over the
node-data limit. Any refusal writes nothing. A rerun replaces the
sidecar, also when the reader rejects the old one, because the build
opens the index without loading versions/.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This is part 3 of the versioned-features proof of concept.

DiskGraphEngine loads the version sidecar when it opens an index. Every
sampler read of a node row of a versioned table now returns the row
that is live at the anchor time of the node instance's root seed: the
fused frontier, the fused leaf, the chunked fetch (which now dedups by
node and version), and the non-fused fetch after sampling. A read of a
versioned table without an anchor time fails with InvalidRequest, never
with a silent base-row read.

The engine refuses Uniform and DeterministicUniform fanouts on a graph
with versioned tables, because they read no anchor time.
fetch_features_for_type and the legacy load refuse versioned data.
Anchors in a finer unit round down on a versioned graph. An index
without versions/ takes the old code paths.

It also fixes a bug that main has too: a fused request that failed
partway left decoded rows in the pooled TypeState, and the next
request on that state emitted them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This is part 4 of the versioned-features proof of concept.

When the entity table has versions, training-table generation reads
the entity row that is live at each anchor time tau for the seed
checks: the entity filter and its entity-column operands, the split
value and the include bit. A label op (an Aggregate or HasEdges op, or
an entity Column op, that feeds the target) reads entity columns from
the row live at the end of the label window, the latest end among the
label windows. Non-temporal plans read at the emitted timestamp.

Every other read of a changed column stops the plan with an
InvalidPlan error that names the table, the column and the read site.
Reads of unchanged columns, and COUNT of a changed column, stay
allowed. A node without versions keeps the once-per-entity seed path,
and a node with versions rebuilds its seed only when the live version
changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This is part 5 of the versioned-features proof of concept.

diskgraph.build_versions(index_dir, history_json) builds the version
sidecar of an existing index and returns the report as JSON.
diskgraph.ingest_with_history(config_json, history_json, output_dir)
checks the history spec against the config first, so a bad spec fails
before any ingest work, then runs ingest and build_versions, and
returns {"ingest": ..., "versions": ...}. If the gate refuses after
ingest, the base index stays without versions/.

A refusal raises DiskgraphDataError. Its first line names the reasons,
and the rest is the report as JSON. A history that does not parse
raises DiskgraphConfigError. The config-only table checks of the gate
move into check_config, which the pre-check shares.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This is part 6 of the versioned-features proof of concept.

scripts/versions_e2e/gen_data.py writes a small fixture (20,000 users,
180,000 orders, and an audit log of about 41,000 changes to tier,
score and status) and an independent oracle of each user's row at any
time. e2e_engine.py ingests the fixture, runs build_versions, and
compares every sampled row and every training-table row with the
oracle: seed and one-hop reads, fused and non-fused, the runtime batch
path, five label kinds, and the refusals, each of which must succeed
on the index without history first.

Run it with the diskgraph wheel installed:
python e2e_engine.py --data <fixture folder> --work <work folder>

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@copy-pr-bot

copy-pr-bot Bot commented Dec 3, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@anle2024

anle2024 commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator Author

Change map

Observed need: a DiskGraph index holds one state per row, so features that change over time either stay at the first state or leak later states. Existing behavior: every read returns the base row. Smallest change for Stage 1: keep the base index, add a version sidecar for changed feature values, and read it at each anchor. Focused check: the version tests, and an end-to-end oracle check of every sampled and training-table row. Stopping condition: engine-level reads match the oracle. Product-level runs at 100M rows are a later step.

File Function / scope What changed Why
packages/diskgraph/diskgraph-index/src/versions.rs VersionsManifest, write_versions, IndexVersions, ShardVersions New sidecar format with a manifest and, per shard, a bitmap, offsets and version rows, plus its writer and reader Store the later states of changed nodes next to an unchanged base index
packages/diskgraph/diskgraph-index/src/graph.rs TableReader::has_versions, changed_columns, shard_versions, version_at, node_data_at, GraphIndexReader::open_subset_without_versions The reader loads the sidecar at open and returns a node's row at a time. The build opens the index without the sidecar. Readers need the row at an anchor, and a rebuild must replace a sidecar that the reader rejects
packages/diskgraph/diskgraph-index/src/lib.rs Module list Exports versions New module
packages/diskgraph/diskgraph-index/tests/versions_sidecar.rs Tests Round trip, bad offsets and a stale build id Pin the format and the closed failure on bad data
packages/diskgraph/diskgraph-ingest/src/errors.rs VersionsGateError New error that carries the refusal report A refusal returns its report to the caller
packages/diskgraph/diskgraph-ingest/src/lib.rs Module list Exports versions New module
packages/diskgraph/diskgraph-ingest/src/mapping.rs to_index_key Visible inside the crate The gate maps audit keys to node ids
packages/diskgraph/diskgraph-ingest/src/versions/spec.rs HistorySpec, TableHistory, AuditLogSpec, SnapshotSpec History spec in JSON, one kind of history per build The build-time user API
packages/diskgraph/diskgraph-ingest/src/versions/audit.rs Audit-log reader Reads audit rows and parses keys, times and values Input of the gate and the fold
packages/diskgraph/diskgraph-ingest/src/versions/roles.rs Column roles Finds key, foreign-key, time and edge sort-key columns The gate refuses changes to these columns
packages/diskgraph/diskgraph-ingest/src/versions/gate.rs read_and_gate, check_config, check_table Table and row checks with a report of counts and samples Refuse every change that Stage 1 does not support
packages/diskgraph/diskgraph-ingest/src/versions/fold.rs build_versions Folds the changes of each node in time order, checks old values and types, and writes the sidecar Build the version rows
packages/diskgraph/diskgraph-ingest/src/versions/precheck.rs precheck_history Checks a history spec against a config before ingest ingest_with_history fails fast on a bad spec
packages/diskgraph/diskgraph-ingest/src/versions/mod.rs VersionsReport, reasons, re-exports Report types and refusal reasons Shared by the gate, the fold and the bindings
packages/diskgraph/diskgraph-ingest/tests/versions_gate.rs, packages/diskgraph/diskgraph-ingest/tests/versions_fold.rs, packages/diskgraph/diskgraph-ingest/tests/versions_precheck.rs, packages/diskgraph/diskgraph-ingest/tests/versions_reader.rs, packages/diskgraph/diskgraph-ingest/tests/versions_spec.rs Tests Gate refusals, fold results, the pre-check, reads at a time, and spec parsing Pin each build rule
packages/diskgraph/diskgraph-engine/src/engine.rs from_reader, compile_plan, process_layer, accumulate_features_from_ids_builder, accumulate_features_from_ids_chunked, fetch_features_for_type, fetch_features_for_type_at, load, sample_with_cutoff Reads versioned rows at the root anchor, and refuses uniform modes, reads without a time and the legacy load on versioned data Sampler reads must match the anchor
packages/diskgraph/diskgraph-engine/src/state.rs TypeState::adaptive_reset Drops the Arrow builders on reset A failed fused request left rows for the next request
packages/diskgraph/diskgraph-engine/src/tests_unit.rs Tests New caller of the leaf helper, and a pooled-state test Cover the changed helper and the reset fix
packages/diskgraph/diskgraph-ingest/tests/versions_sampler.rs Tests Reads at anchors in every sampler path, refusals, dedup by version, stage mode and two hops Pin the read rule in each path
packages/diskgraph/diskgraph-train-table/src/ttgen_resolve.rs label_end, label_aliases, refuse_changed_columns, refuse_changed_op, refuse_changed_filter, refuse_versioned_reads Finds the label windows and refuses reads of changed columns that have no correct time Training tables must read each value at a defined time
packages/diskgraph/diskgraph-train-table/src/ttgen_executor.rs EntitySeed, entity_seed, entity_columns, execute_stages Seed checks read at each anchor, and label entity columns read at the end of the label window Training rows match the anchor and the label time
packages/diskgraph/diskgraph-train-table/src/ttgen_traversal.rs VersionedRow Reads one entity's version at a time Shared by the seed and label reads
packages/diskgraph/diskgraph-train-table/src/batch_aggregate.rs, packages/diskgraph/diskgraph-train-table/src/rhs_catalog.rs, packages/diskgraph/diskgraph-train-table/src/pseudo_time.rs projection, PreparedAggregatePlan::prepare, rhs_catalog, FactPseudoTime::new Refuse reads of changed columns These paths have no anchor time
packages/diskgraph/diskgraph-train-table/tests/ttgen_versions.rs Tests Seed and label reads, two shards, two versions, and 22 refusal sites Pin the training-table rules
packages/diskgraph/diskgraph-pybind/src/lib.rs build_versions, ingest_with_history, parse_history, map_anyhow_err New Python bindings, and the refusal maps to DiskgraphDataError with the report The Python user API
packages/diskgraph/diskgraph-pybind/python/diskgraph/__init__.py Exports Exports the two new functions Public API
packages/diskgraph/diskgraph-pybind/python/tests/test_versions.py Tests Build, rerun, refusals, error classes and ingest_with_history Pin the binding behavior
packages/diskgraph/scripts/versions_e2e/e2e_engine.py, packages/diskgraph/scripts/versions_e2e/gen_data.py End-to-end check Fixture, oracle, and checks of every sampled and training-table row Engine-level proof against an independent oracle

@anle2024
anle2024 temporarily deployed to gha-kumo-workflow-tests December 3, 2026 09:17 — with GitHub Actions Inactive
@coderabbitai

coderabbitai Bot commented Dec 3, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true

Note

.coderabbit.yaml has unrecognized properties

CodeRabbit is using all valid settings from your configuration. Unrecognized properties (listed below) have been ignored and may indicate typos or deprecated fields that can be removed.

Parsing warnings: 1

Validation error: Unrecognized key: "tone_instructions" at "reviews"
Configuration instructions

  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

CodeQL reports the panic message as cleartext logging, because the
value can be a UUID. The test needs only the fact that the users id
column is not Int64.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@anle2024
anle2024 temporarily deployed to gha-kumo-workflow-tests December 3, 2026 10:15 — with GitHub Actions Inactive

This branch was previously deployed

1 inactive deployment
gha-kumo-workflow-tests — f829cb49 Deployed Dec 3, 2026 by anle2024 via import #3602
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.

2 participants