chore(util): adopt Bun.randomUUIDv7 — Bun-API audit - #93
Merged
Conversation
`src/util/ulid.ts` shrinks from 50 LOC (Crockford-base32 encoder + custom random sampler) to a 1-line wrapper over `Bun.randomUUIDv7()`. UUIDv7 (RFC 9562) provides the same guarantees we relied on: - 48-bit ms-epoch timestamp prefix → lex-sortable, so `runs` table range scans on `run_id` are time-ordered without an index. - Per-call randomness → unique under heavy parallelism. - Standard string format → tools that handle UUIDs (DB clients, log indexers) understand it for free. User-visible: `run_id` column values switch from 26-char Crockford base32 (`01JC0K…`) to 36-char hex with hyphens (`019e3255-9a99-…`). Pre-alpha; no migration concerns. Tests rewritten — old tests injected a custom timestamp arg, which Bun.randomUUIDv7 doesn't expose. The new tests check the contract we actually care about (format, uniqueness across N rapid calls, lex ordering across a 5ms sleep). Decision log entry in CLAUDE.md records this plus the wider Bun-API audit results (notably: `Bun.Archive` benchmarked 15-400× slower than our `extractOutputs` for typical KB-MB cache artifacts; not adopting).
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.
Summary
Bun-API audit. One concrete replacement plus a record of the wider findings (so the next agent doesn't re-litigate).
Replaced
src/util/ulid.ts→ thinBun.randomUUIDv7()wrapper. Drops 50 LOC of hand-rolled Crockford-base32 encoding + custom random sampling. UUIDv7 (RFC 9562) gives us the same guarantees we need:run_idscansUser-visible change:
run_idstrings switch from 26-char Crockford (01JC0K…) to 36-char hex (019e3255-9a99-7000-…). Pre-alpha, no migration concern.Tests rewritten — old tests injected a custom timestamp arg the built-in doesn't expose. New tests cover the actual contract (format, uniqueness over 1000 rapid calls, lex ordering across a 5ms sleep).
NOT shipped (with reasons recorded in CLAUDE.md)
Bun.Archivefor extractextractOutputsfor typical artifacts (10-500 files, 1KB-64KB each). Fixed JS-bridge overhead dominates for small archives. Detailed numbers intests/ulid.test.tscommit msg.Bun.envprocess.env; not worth the diff churn (13 sites)Bun.semver,Bun.deepEquals,Bun.stripANSI,Bun.stringWidth,Bun.which,Bun.JSONC,Bun.TOML,Bun.password,Bun.markdown,Bun.serveBun.stdout/Bun.stdinBun.File-shaped, no advantage overprocess.stdoutBun.writeintar.ts:200Bun.writeeverywhere it pays off (cache.ts/save, layered-cache, run-artifacts); the onewriteFilein extractOutputs is fine and the bench shows the bottleneck is elsewhereAlready using
Bun.YAML.parse,Bun.Glob,bun:sqlite,Bun.hash.xxHash3,Bun.zstdCompress/zstdDecompress,Bun.spawn/spawnSync,Bun.color,Bun.file,Bun.write,Bun.nanoseconds,Bun.sleep.Test plan
run_idformat change doesn't affect cache key derivationhttps://claude.ai/code/session_016HXj6HW6bxSn8EYuKcxTD9
Generated by Claude Code