Skip to content

Reject sort-key specs that name a table ingest does not read - #596

Draft
anle2024 wants to merge 1 commit into
mainfrom
anle/sort-key-spec-table-check
Draft

anle2024 wants to merge 1 commit into
mainfrom
anle/sort-key-spec-table-check

Conversation

@anle2024

@anle2024 anle2024 commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator

Design discussion or issue: none. A read-only check of DiskGraph edge sort keys found this bug on 3 December 2026.

Summary

This PR makes config validation reject an edge sort-key time or weight spec that names a table that ingest does not read for that relation. The error names the fkey, the direction, the spec kind, the named table and the table to name instead.

Why

Ingest reads a node-table sort-key value at the position of the relation's destination node, whatever table the spec names. A spec that names another table therefore gives each edge the value of some other row, with no error. A check used 2,000 random orders with a forward spec that named the orders table. Every edge to a user got the time of the order whose key equals that user's key: 2,000 of 2,000. When the input was spread over 8 files, the edge times even changed between two ingests of the same data. Sometimes the read position does not exist in the named table. Ingest then fails late with "sort key offset out of range", which does not name the config.

Before and now

Spec Before (main) Now (this PR)
Fkey forward that names the destination table Right value Same
Fkey reverse that names the table that holds the fkey Right value Same
Edge-table direction that names the edge table or that direction's destination Right value Same
Fkey forward that names the table that holds the fkey Silent wrong value Config error at load
Fkey reverse that names the destination table Silent wrong value Config error at load
Any other table, a misspelled name, or another edge table Silent wrong value, or a late "sort key offset out of range" Config error at load

The name compare is exact and case-sensitive, as in the ingest code that reads the values. A reverse spec of a one-way fkey (bidirectional: false) is not checked, because ingest does not build that relation.

Why the new way is better

  • A wrong spec fails before ingest writes any file, with a message that says which table to name.
  • No producer in the repository writes such a spec. The config converter (config_converter/convert.rs) names the destination table in forward specs and the fkey's own table in reverse specs. The experimental kumo-pytorch materialization does the same.

Trade-off

  • A hand-written config that names the wrong table stops ingesting, and the resume of an old ingest with such a config fails at load. Today such a config gets wrong edge times.
  • Indexes that were built with such a spec keep their wrong edge times until they are ingested again.
  • Four test fixtures named the fkey's own table in a forward spec: three in ingest_timestamp_range.rs and one in ingest_null_ts.rs. They now put the same spec in reverse, which reads the same column for the same rows. Their asserts and their printed drop and edge counts did not change.

Change map

See the change-map comment on this PR.

Testing Done

  • New tests: validate_fkey_sort_key_tables, validate_edge_table_sort_key_tables and validate_one_way_fkey_skips_reverse_sort_key in tests/graph_config.rs, and sort_key_on_owner_table_fails_before_output in ingest_sort_key_alignment.rs. All four fail on main and pass with the change. Each weakened version of the check fails at least one of them: a case-insensitive compare, swapped edge fkeys, no weight check, or a reverse check on a one-way fkey.
  • cargo test --locked -p diskgraph-ingest after the last change: 791 passed, 7 ignored and 1 failed. The full workspace run before the last error-text change: 2,206 passed, 18 ignored and 1 failed. The failure in both runs is disk_manager::tests::test_eviction_under_real_disk_pressure, which measures free space on a shared disk and does not use the config code.
  • cargo clippy --locked --workspace --all-targets --exclude diskgraph-ptrhash -- -D warnings: clean. diskgraph-ptrhash fails the same way on main on aarch64, in an unchanged test file.
  • Python suite against a wheel of this branch: 939 passed. 1 test and 4 test modules fail only because the test machine has no kumoapi module, the same as on main.

Hotfix Context

Not a hotfix.

Checklist

  • I listed all the breaking changes introduced by the PR (see Trade-off)
  • 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

Ingest reads a node-table sort-key time or weight at the position of
the relation's destination node, whatever table the spec names. A spec
that names another table gives each edge the value of some other row,
with no error, or fails late with "sort key offset out of range".

Config validation now rejects a time or weight spec whose table is not
the relation's destination table, or, for an edge table, the edge
table itself. The compare is exact, as in the ingest code that reads
the values. The reverse spec of a one-way fkey is not checked, because
ingest does not build that relation.

Four test fixtures named the fkey's own table in a forward spec. They
now put the same spec in reverse, which reads the same column for the
same rows.

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 failure: a sort-key spec that names a table other than the one ingest reads gives each edge another row's value, with no error. Existing behavior: validation never reads the table of a time or weight spec. Smallest change: one check in each of the two validation loops. Focused check: validation tests for every allowed and refused case, and an ingest test that fails before any output. Stopping condition: every wrong spec fails at load, and every config in the repository still passes.

File Function / scope What changed Why
packages/diskgraph/diskgraph-ingest/src/graph_config.rs sort_key_tables, GraphConfig validation of fkeys and edge tables Rejects a time or weight spec whose table is not the destination table, or for an edge table, the edge table itself Ingest reads the value at the destination node or edge row, so any other table gives a wrong value
packages/diskgraph/diskgraph-ingest/tests/graph_config.rs validate_fkey_sort_key_tables, validate_edge_table_sort_key_tables, validate_one_way_fkey_skips_reverse_sort_key New table-driven tests of every allowed and refused case Pin the rule and the error text
packages/diskgraph/diskgraph-ingest/tests/ingest_sort_key_alignment.rs sort_key_on_owner_table_fails_before_output New ingest test with a wrong spec Shows that ingest fails before it writes any output
packages/diskgraph/diskgraph-ingest/tests/ingest_timestamp_range.rs test_string_timestamp_parse_failure_drops_rows, test_date32_out_of_range_drops_rows, test_time64_microsecond_create_time_does_not_drop_rows The time spec moves from forward to reverse The forward spec named the fkey's own table, which the check now refuses
packages/diskgraph/diskgraph-ingest/tests/ingest_null_ts.rs test_null_timestamp_metrics_and_filtering The time spec moves from forward to reverse Same reason

@anle2024
anle2024 deployed to gha-kumo-workflow-tests December 3, 2026 10:34 — with GitHub Actions Active
@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

This branch was successfully deployed

1 active deployment
gha-kumo-workflow-tests — 63bba4be Deployed Dec 3, 2026 by anle2024 via import #3603
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