anomalyco / anomalyco/opencode

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

Open
#46,980 0 comments 0 reactions 1 assignee View on GitHub

@nexxeln is already working on this.

Since Sep 3, 2026.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
PR merge metrics
PR metrics pending

Description

Description

The ID rollover issues from August (#42583, #42589, #42639, #42955) were closed after the comparison sites moved to time ordering. The encoding itself was never changed, so two things are still broken on dev (b578b726).

1. Identifier.timestamp() returns a 1970 date for an id minted now.

Both 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. The decoder reads the truncated field back and divides by 0x1000, which gives the time since the last rollover instead of the time the id was minted.

2. The field wraps again on 2028-10-17T20:04:31Z.

Every 2^36 ms, about 795 days. The last one was 2026-08-14T11:19:55Z.

I hit this in a fork and widened the field to 7 bytes, which holds the encoding until 2527 and keeps ids at 26 characters. Happy to send that if it is wanted.

Steps to reproduce
bun -e 'import { Identifier } from "./packages/core/src/id/id"
const id = Identifier.ascending("session")
console.log(id, new Date(Identifier.timestamp(id)).toISOString())'

Today that prints a ses_065b... id and 1970-01-20T17:58:29.071Z.

The same arithmetic in isolation, if you would rather not run the package:

const v = BigInt(Date.now()) * 0x1000n + 1n            // needs 53 bits
const field = v & 0xffffffffffffn                       // 6 bytes holds 48
Number(field / 0x1000n)                                 // 1706309071 -> 1970-01-20
OpenCode version

dev @ b578b726

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.