Skip to content

Extract shared timestamp-id primitives into TimestampId module#2629

Draft
maeldonn wants to merge 8 commits into
improvement/ARSN-578/micro-version-idfrom
improvement/ARSN-583/timestamp-id
Draft

Extract shared timestamp-id primitives into TimestampId module#2629
maeldonn wants to merge 8 commits into
improvement/ARSN-578/micro-version-idfrom
improvement/ARSN-583/timestamp-id

Conversation

@maeldonn
Copy link
Copy Markdown
Contributor

Move the constants, padding/hex helpers, and the stateful ts+seq+rg
generator out of VersionID into a new TimestampId module that both
VersionID and MicroVersionId consume. Add
a dedicated test suite covering constants, helpers, and generator
behaviour.

Issue: ARSN-583

maeldonn added 8 commits May 22, 2026 17:20
Replace the random 8-byte hex microVersionId with a 20-character
timestamp-ordered identifier matching the versionId scheme, and add
encode/decode/compare helpers in a new MicroVersionID module. Add an
optional isReplica flag to ReplicationInfo to distinguish replica
writes from user writes, enabling cascaded CRR.

Issue: ARSN-578
Move the constants, padding/hex helpers, and the stateful ts+seq+rg
generator out of VersionID into a new TimestampId module that both
VersionID and MicroVersionId consume. Each module instantiates its
own generator so the two id streams keep independent counters. Add
a dedicated test suite covering constants, helpers, and generator
behaviour.

Issue: ARSN-583
Replace the template+slice padding pattern with native padStart/padEnd
in TimestampId, and modernize the constants (10**N, '0'.repeat).
Remove the backward-compatibility re-exports from VersionID so callers
must import shared primitives from TimestampId directly.

Issue: ARSN-583
The 1ms wait guarding against pre-crash id collisions protects the
process, not the closure, so each generator was paying it again
unnecessarily. Move the guard to a module-level flag, drop the now
redundant inline comments at the call sites, and collapse the
MicroVersionId generate wrapper since it added no logic over the
underlying closure.

Issue: ARSN-583
Drop the fictional version parameter from hasVersionIDFormat (only ever
called with VERSION_ID_FORMAT_VERSION), rename it to
hasCurrentFormatSuffix to match what it actually verifies, and replace
the hand-rolled marker+version compare with a single endsWith call on
the precomputed suffix constant.

Issue: ARSN-583
decode now uses TimestampId.parse to validate the decoded id structure,
adding a numeric ts/seq check on top of the existing length guard.
compare becomes a pure re-export from TimestampId instead of a one-line
wrapper, since the function is identical.

Issue: ARSN-583
@maeldonn maeldonn requested review from a team, benzekrimaha and delthas May 26, 2026 09:28
hexDecode,
createTimestampSequenceGenerator,
getInfId,
} from './TimestampId';
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VersionID.ts previously exported hexEncode, hexDecode, padLeft, padRight, wait, MAX_TS, MAX_SEQ, LENGTH_TS, LENGTH_SEQ, LENGTH_RG, TEMPLATE_TS, TEMPLATE_SEQ, TEMPLATE_RG. These are now only in TimestampId.ts, which is not re-exported from lib/versioning/index.ts.

Since index.ts does export * as VersionID from './VersionID', downstream consumers (CloudServer, Backbeat) accessing e.g. versioning.VersionID.hexEncode will break at import time.

Consider re-exporting the moved symbols from VersionID.ts (e.g. export { hexEncode, hexDecode, padLeft, padRight, wait, MAX_TS, MAX_SEQ, LENGTH_TS, LENGTH_SEQ, LENGTH_RG, TEMPLATE_TS, TEMPLATE_SEQ, TEMPLATE_RG } from './TimestampId') or exporting TimestampId from lib/versioning/index.ts and coordinating the migration with downstream repos.

— Claude Code

@claude
Copy link
Copy Markdown

claude Bot commented May 26, 2026

  • Breaking API change: 13 symbols previously exported from VersionID.ts (hexEncode, hexDecode, padLeft, padRight, wait, MAX_TS, MAX_SEQ, LENGTH_TS, LENGTH_SEQ, LENGTH_RG, TEMPLATE_TS, TEMPLATE_SEQ, TEMPLATE_RG) are no longer exported. They were moved to TimestampId.ts which is not re-exported from lib/versioning/index.ts. Downstream consumers accessing these via the versioning.VersionID namespace will break.
    - Re-export them from VersionID.ts (export { ... } from './TimestampId') to preserve backwards compatibility
    - Or add export * as TimestampId from './TimestampId' to lib/versioning/index.ts and coordinate downstream migration

    The refactoring itself (shared generator, process-wide boot wait, hasCurrentFormatSuffix simplification, base62Decode cleanup) is correct and well-structured.

    Review by Claude Code

@maeldonn maeldonn force-pushed the improvement/ARSN-578/micro-version-id branch from 5f4839a to 7be6414 Compare May 27, 2026 07:47
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.

1 participant