Skip to content

Constrain immutable edge tables to one index and one direction - #440

Merged
em3s merged 2 commits into
mainfrom
fix/immutable-edge-single-index
Jul 21, 2026
Merged

em3s merged 2 commits into
mainfrom
fix/immutable-edge-single-index

Conversation

@em3s

@em3s em3s commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Establish the constraints for an immutable edge table: exactly one index in one direction (OUT or IN, not BOTH).

Surfaced while implementing scan-and-delete. An immutable edge persists only index rows (no State row, no count), so the index rows are the record — and an append writes one row per (index x direction). Eviction scans a single index in a single direction and deletes only those rows. Any row keyed by another index, or by the opposite direction, would be orphaned: unreachable to trim via the scanned path, yet still returned by scans that reach it.

Constraining an immutable edge to one index and one direction keeps "the index rows are the record" true by construction, so eviction stays a complete delete. This is a prerequisite for the immutable-edge scan-delete work.

Changes

  • ModelSchema.ImmutableEdge — init block enforces two invariants:

    • indexes.size <= 1 (message names the offending indexes)
    • direction != BOTH

    Enforced at the model boundary, so it holds for every entry point (table create/update, deserialization, direct construction) and yields a 400 on the create/update path.

Compatibility

The check runs on every construction, including reads (toV3ModelSchemaImmutableEdge reconstructs the schema from stored metadata). Immutable edge is a new table type and queue/v1 (single seq_asc index, OUT) is compliant, so no existing table is affected; a pre-existing table that violated the rule would now fail to read back.

How to Test

  • ./gradlew :core:test --tests "*EdgeSchemaSerializationTest" — includes cases asserting a two-index and a BOTH-direction ImmutableEdge construction each throw.
  • ./gradlew :server:test --tests "*ImmutableEdgeE2ETest" — includes E2Es: creating an immutable table with two indexes, or with BOTH direction, returns 400.
  • ./gradlew :core:spotlessCheck :server:spotlessCheck.

AI Assistance

  • This PR was written largely with AI assistance.
    • Tool / model: claude code (opus 4.8)

An immutable edge append writes one index row per index, and those index rows
are the whole persisted record (no State row, no count). Eviction (scan-and-delete)
scans a single index and deletes only its rows, so a second index's rows would be
orphaned: unreachable to trim via the scanned index, yet still returned by scans on
the other index.

Enforce `indexes.size <= 1` in `ModelSchema.ImmutableEdge.init`, so "the index rows
are the record" holds by construction. This keeps immutable-edge eviction a complete
delete and is a prerequisite for scan-and-delete. Surfaced while implementing delete.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. enhancement New feature or request labels Jul 21, 2026
@em3s em3s changed the title Restrict immutable edge tables to a single index Constrain immutable edge tables to a single index and single direction Jul 21, 2026
@em3s
em3s force-pushed the fix/immutable-edge-single-index branch 2 times, most recently from bcd8fb5 to 27add0a Compare July 21, 2026 12:50
A BOTH-direction immutable edge writes both an OUT and an IN index row per append.
Eviction (scan-and-delete) scans one direction and deletes only those rows, so the
opposite-direction rows would be orphaned — the same complete-delete violation as
multiple indexes.

Extend the ImmutableEdge invariant to also require `direction != BOTH`, so an
immutable edge is one index in one direction: its persisted rows are exactly the
set a single scan can reach and delete.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@em3s
em3s force-pushed the fix/immutable-edge-single-index branch from 27add0a to a0d4e3f Compare July 21, 2026 12:50
@em3s em3s changed the title Constrain immutable edge tables to a single index and single direction Constrain immutable edge tables to one index and one direction Jul 21, 2026
@em3s

em3s commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

Merge

@em3s em3s mentioned this pull request Jul 21, 2026
1 task done
@em3s
em3s merged commit 9a78bf0 into main Jul 21, 2026
2 checks passed
@em3s
em3s deleted the fix/immutable-edge-single-index branch July 21, 2026 13:03
@em3s em3s self-assigned this Jul 21, 2026
@em3s em3s mentioned this pull request Jul 21, 2026
1 task done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant