Prototype: dense order key codec for manual ordering - #12284
Closed
rymsha wants to merge 1 commit into
Closed
Conversation
Codacy's Analysis Summary0 new issue (≤ 0 issue)
|
A manual order value today is a long resolved against the sibling set: assigning one queries the neighbors, inserting between two of them halves a fixed gap that runs out after thirty targeted inserts and then silently duplicates the lower neighbor, and two branches performing the same insertion mint the identical value by construction, colliding when their sibling sets merge. An order key is a base-62 fraction followed by the id of the node that holds it. Between two distinct keys there is always a third, so nothing is ever renumbered; the id suffix makes concurrently minted keys unequal by construction, whatever branch, layer or server minted them; and a birth key encodes the inverted creation instant, so creating a node and moving one first are the same read-free operation, and the relative operations need only the anchor keys the caller already holds. A run of inserts in one direction consumes space linearly rather than by halving, and a position never grows past a cap that turns hostile input into a clean refusal instead of index growth. Keys are stored plain and leave the server as tokens: a version character, the key, and a truncated HMAC-SHA512 tag - the construction the redirect checksums already use - under a subkey derived once from a master key and bound to the scope the token was issued for. A client can replay positions it was handed but cannot mint one, which keeps exact placement out of reach of standard means, and verification tolerates fumbles loudly: wrong scope, wrong version, truncation and tampering are each rejected. A golden token pins the exact wire format against an independently computed reference value. Nothing is wired to storage yet: this is the primitive and its properties, testable in isolation. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ANkY5TN9xn2cFKHk1sfX4B
rymsha
force-pushed
the
claude/order-key-codec
branch
from
August 23, 2026 14:11
89c394b to
b1a82b7
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #12284 +/- ##
============================================
- Coverage 87.01% 87.01% -0.01%
- Complexity 20754 20801 +47
============================================
Files 2593 2595 +2
Lines 69055 69216 +161
Branches 5723 5749 +26
============================================
+ Hits 60091 60226 +135
- Misses 6290 6307 +17
- Partials 2674 2683 +9 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
Author
|
Folded into #12285, which now carries both the codec and its node-layer integration as one PR. Closing. Generated by Claude Code |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Prototype of the core primitive for a new manual-ordering scheme, developed in design discussion with @sry-enonic. Self-contained in
core-internal, nothing wired to storage or API — the point of this PR is the algorithm and its properties, reviewable in isolation.What it replaces, eventually
_manualordervalueresolves each value against the sibling set and splits fixed gaps:between()halves a2^31gap — 30 targeted inserts into one slot, then it silently mints an exact duplicate of the lower neighbor;The primitive
An order key is
position '.' discriminator, stored plain, sorted lexicographically (ESnot_analyzedstring semantics):The token layer
Keys leave the server wrapped:
'1' + key + '~' + 16 hex chars of truncated HMAC-SHA512under a subkey derived once from a master key, bound to the scope (parent) the token was issued under — the same constructionRedirectChecksumServicealready uses, with a derivation step separating the two uses of the master key. Clients can replay positions they were handed — anchors for a reorder — but cannot mint one, so exact placement stays out of reach of standard means. Wrong scope, wrong version, truncation, tampering and oversize are each rejected; the stored key never carries the tag.The golden-token test pins the exact wire format against an independently computed reference value, so the tag implementation can change without ambiguity about compatibility. (Earlier revisions of this branch used a hand-written SipHash-2-4 for per-item speed; with token minting scoped to reorder-capable listings only, the standard platform MAC costs the same in practice and the hand-written primitive was dropped.)
Not in this PR
Storage wiring,
_orderkeymapping/field,ChildOrderintegration (the stored childOrder expression is the intended per-parent migration flag), API surface, key-node lookup for the master key (/keys/generic-hmac-sha512), migration of existing manually-ordered parents.🤖 Generated with Claude Code
https://claude.ai/code/session_01ANkY5TN9xn2cFKHk1sfX4B