Skip to content

Keep edge-table sort keys aligned after a missing key - #595

Draft
anle2024 wants to merge 1 commit into
mainfrom
anle/edge-table-row-counter
Draft

anle2024 wants to merge 1 commit into
mainfrom
anle/edge-table-row-counter

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

Sometimes an edge-table row has a source or destination key that the node table does not have. After such a row, this PR keeps the time and weight of each later edge in that shard aligned with its own row.

Why

An edge-table relation can take its sort key (time and weight) from the edge table itself. Ingest then reads the value of each edge at row_idx, the position of the edge row in its shard. The edge build drops a row whose source or destination key is missing from the primary-key map. In that case it returned without advancing row_idx. Every later edge in that shard then read the time and weight of an earlier row. In the check runs, 3 of 10 edges had the right time after 2 such rows. With 4 such keys over 4 shards, 22 of 40 edges had the right time. Other shards are not affected.

Before and now

Case Before (main) Now (this PR)
Row with a null time Dropped, and row_idx advances Same
Row with a missing source key Dropped, but row_idx does not advance Dropped, and row_idx advances
Row with a missing destination key Dropped, but row_idx does not advance Dropped, and row_idx advances
Later edges in that shard Read the time and weight of an earlier row Read the time and weight of their own row

Why the new way is better

  • Encode writes one sort-key value for every edge row that the edge build reads, including the rows that are dropped later. Now every read path advances the counter once per row, so the position and the value always match.
  • The new tests fail on main: every surviving edge carries the time and weight of the row 2 positions back, or 4 positions back in the multi-shard case. They pass with the fix.

Trade-off

  • The fix changes no behavior for edge tables without missing keys, and no behavior for foreign-key relations.
  • Indexes that were built with missing keys keep their wrong edge times until they are ingested again.

Change map

See the change-map comment on this PR.

Testing Done

  • New tests in ingest_sort_key_alignment.rs: sort_key_alignment_edge_table_dangling_keys (1 shard) and sort_key_alignment_edge_table_dangling_keys_across_shards (4 shards). They check the time and weight of every edge in both directions, and the lookup-failure counts. Both fail on main and pass with the fix.
  • cargo test --locked --workspace in packages/diskgraph: 2,204 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 and fails the same way on main on the test machine.
  • 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 (none)
  • 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

An edge-table relation can take its time and weight from the edge
table itself. The edge build reads that value at row_idx, the position
of the edge row in its shard. When a row's source or destination key
was missing from the primary-key map, the edge build dropped the row
without advancing row_idx. Every later edge in that shard then read
the time and weight of an earlier row.

Advance row_idx in the two lookup-miss branches, as the null-time
branch already does. The new tests put missing keys before valid rows
on 1 shard and on 4 shards, and check the time and weight of every
edge in both directions.

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

anle2024 commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator Author

Change map

Observed failure: an edge-table row can have a missing source or destination key. After it, each later edge in that shard reads an earlier row's time and weight. Existing behavior: the two lookup-miss branches return without advancing row_idx, while the null-time branch advances it. Smallest change: advance row_idx in the two lookup-miss branches. Focused check: two new alignment tests that fail on main and pass with the fix. Stopping condition: every surviving edge carries its own row's time and weight in both directions.

File Function / scope What changed Why
packages/diskgraph/diskgraph-ingest/src/lib.rs Edge-table edge build in IngestContext, the read_temp_rows closure The source and destination lookup-miss branches advance row_idx before they return row_idx must match the row's position in the edge-table sort-key component
packages/diskgraph/diskgraph-ingest/tests/ingest_sort_key_alignment.rs sort_key_alignment_edge_table_dangling_keys, sort_key_alignment_edge_table_dangling_keys_across_shards New tests with missing keys before valid rows, on 1 shard and on 4 shards Pin the time and weight of every edge in both directions

@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 previously deployed

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