fix(schema): widen the identifier time field so sortable ids stop wrapping - #46978
Open
stooit wants to merge 1 commit into
Open
fix(schema): widen the identifier time field so sortable ids stop wrapping#46978stooit wants to merge 1 commit into
stooit wants to merge 1 commit into
Conversation
…pping Both id generators pack Date.now() * 0x1000 + counter into a 6-byte time field. That value needs 53 bits and the field holds 48, so the top bits are dropped and the sortable prefix wraps every 2^36 ms, about 795 days. The last wrap was 2026-08-14T11:19:55Z; the next is 2028-10-17T20:04:31Z. Identifier.timestamp() decodes the truncated field, so it reports 1970-01-20 for an id minted today. Widening the field to 7 bytes holds the encoding until 2527. Ids stay 26 characters: the random suffix goes from 14 to 12 base62 characters, which is still 62^12 of entropy on top of a per-millisecond counter. Ids minted before this change still do not sort against ids minted after it. That is unchanged by this commit — the 2026-08-14 wrap already broke it — and is why the comparison sites use time ordering.
Contributor
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
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.
Issue for this PR
Closes #46980
Type of change
What does this PR do?
Both id generators pack
Date.now() * 0x1000 + counterinto a 6-byte time field. That value needs 53 bits and the field holds 48, so the top 5 bits are dropped. Two consequences:Identifier.timestamp()decodes the truncated field, so it reports 1970-01-20 for an id minted a second ago.The August issues were closed after the comparison sites moved to time ordering, which fixed the ordering symptoms, but the encoding still truncates.
This widens the field to 7 bytes, which holds the value until 2527. Ids stay 26 characters because the random suffix goes from 14 to 12 base62 characters, still 62^12 on top of a per-millisecond counter. Both decoders read the wider field.
It does not make ids minted before 2026-08-14 sort against new ones. Nothing done to the encoder can, since those strings are already written, which is why the time-ordered comparison sites still matter. New ids do sort above ids minted since the wrap.
How did you verify your code works?
Added
packages/schema/test/identifier.test.tsandpackages/core/test/id.test.ts. The ordering tests never reference the field width, so the same files run against both versions: 3 fail and 2 fail respectively ondev, all pass with this change.Full suites, run locally:
packages/opencode3545 pass, 0 failpackages/core1098 pass, 0 failpackages/schema18 pass, 2 fail. Those 2 are inevent-manifest.test.tsand also fail on an unmodified checkout.typecheckclean in schema, core and opencode.Screenshots / recordings
Not a UI change.
Checklist