Skip to content

fix(schema): widen the identifier time field so sortable ids stop wrapping - #46978

Open
stooit wants to merge 1 commit into
anomalyco:devfrom
stooit:fix/identifier-time-field-overflow
Open

fix(schema): widen the identifier time field so sortable ids stop wrapping#46978
stooit wants to merge 1 commit into
anomalyco:devfrom
stooit:fix/identifier-time-field-overflow

Conversation

@stooit

@stooit stooit commented Sep 3, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #46980

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

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 5 bits are dropped. Two consequences:

  • The sortable prefix wraps every 2^36 ms, about 795 days. Last time 2026-08-14, next time 2028-10-17.
  • 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.ts and packages/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 on dev, all pass with this change.

Full suites, run locally:

  • packages/opencode 3545 pass, 0 fail
  • packages/core 1098 pass, 0 fail
  • packages/schema 18 pass, 2 fail. Those 2 are in event-manifest.test.ts and also fail on an unmodified checkout.
  • typecheck clean in schema, core and opencode.

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

…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.
@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. needs:issue labels Sep 3, 2026
@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

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.

Identifier.timestamp() returns a 1970 date, and the time field wraps again in 2028

1 participant