Skip to content

Backport #1978: [world-vercel] Add /run-id sub-export with tagged ULID encode/decode#2114

Open
github-actions[bot] wants to merge 1 commit into
stablefrom
backport/pr-1978-to-stable
Open

Backport #1978: [world-vercel] Add /run-id sub-export with tagged ULID encode/decode#2114
github-actions[bot] wants to merge 1 commit into
stablefrom
backport/pr-1978-to-stable

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

Automated backport of #1978 to stable (backport job run).

AI recommendation: This is a self-contained additive feature that adds a new /run-id sub-export to @workflow/world-vercel (a package that exists and is maintained on stable). All changes are new files under packages/world-vercel/src/run-id/ plus a new exports entry in package.json and a changeset — none of it depends on main-only APIs, so it can ship as a minor bump on stable as well.

…1978)

* [world-vercel] Add /run-id sub-export with tagged ULID encode/decode

Encodes a tag bit, 5-bit version, and 6-bit Vercel region ID into a
ULID-shaped string used for workflow run IDs. Tagged values remain
valid 26-char Crockford-Base32 ULIDs so they still sort and round-trip
through any system that accepts ULIDs.

* [world-vercel] Add string-value assertions to run-id tests

Add exact-string expectations for encoded outputs at known inputs,
covering the default region/version pair, numeric region IDs, version
overrides, boundary values (all-zero, all-max), the dirty-input
overwrite case, and the lexicographic-order checks. Also adds an
explicit byte-array expectation for the canonical ULID-spec example
string and an additional first-char-range coverage test for isTagged.

* [world-vercel] Remove internal-repo reference from regions doc comment

* [world-vercel] Address PR review feedback on run-id sub-export

- isTaggedString now fully validates the input as a 26-char Crockford
  Base32 ULID (delegating to ulidToBytes) instead of only inspecting
  the first character. This fixes false positives on inputs like
  '4UUUU...' that have a valid tag-bit position but invalid chars
  later in the string.
- isTagged() now accepts `unknown` to match its documented behavior
  of safely rejecting non-string inputs without requiring callers to
  cast.
- Introduce `RegionKey` for the full set of keys including 'unknown',
  and narrow `RegionCode` to `Exclude<RegionKey, 'unknown'>` so the
  return type of `lookupRegion` and the `DecodedRunId.region` field
  accurately reflect that 'unknown' is never produced. Updates
  `encode` to reject 'unknown' as a region code string at runtime
  (callers wanting the unknown sentinel should pass numeric 0).

* [world-vercel] Move tagged-ULID metadata to the top of randomness

Address review feedback on #1978:

1. **Metadata at top of randomness, not bottom.** Place `regionId` (6
   bits) in the high bits of byte[6] and `version` (5 bits) straddling
   bytes 6 and 7, leaving the bottom 69 bits of randomness untouched by
   `encode`. This means a `monotonicFactory()`-style ULID generator's
   intra-millisecond bottom-bit increments survive encoding intact, so
   consecutive `encode(ulid(), region, { version })` calls with the
   same metadata produce strictly increasing strings. Previously the
   metadata sat in the bottom 11 bits — exactly the bits the monotonic
   factory uses — causing same-ms collisions/inversions.

2. **DecodedRunId is now a discriminated union.** When `tagged: false`,
   the `regionId`, `version`, and `region` fields are typed as
   `null` instead of being populated with garbage bits from arbitrary
   ULIDs. This forces callers to discriminate on `tagged` before
   reading metadata.

3. **regionIdFor: keep runtime backstop, mark as ignored for coverage.**
   The unreachable-in-TS branch stays as a defensive runtime check for
   callers crossing a JS/TS boundary; an istanbul/c8 ignore comment
   keeps coverage tools quiet.

Doc strings and tests updated accordingly. The new layout adds a test
verifying that a sequence of incrementing-bottom-bit ULIDs (simulating
`monotonicFactory()`) round-trips through `encode` as a strictly
increasing sequence.

108/108 world-vercel tests pass; typecheck clean.

Signed-off-by: Nathan Rajlich <n@n8.io>
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 26, 2026

🦋 Changeset detected

Latest commit: 4a77bac

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 17 packages
Name Type
@workflow/world-vercel Minor
@workflow/cli Patch
@workflow/core Patch
@workflow/web Patch
workflow Patch
@workflow/world-testing Patch
@workflow/builders Patch
@workflow/next Patch
@workflow/nitro Patch
@workflow/vitest Patch
@workflow/web-shared Patch
@workflow/astro Patch
@workflow/nest Patch
@workflow/rollup Patch
@workflow/sveltekit Patch
@workflow/vite Patch
@workflow/nuxt Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented May 26, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
example-nextjs-workflow-turbopack Ready Ready Preview, Comment May 26, 2026 6:14pm
example-nextjs-workflow-webpack Ready Ready Preview, Comment May 26, 2026 6:14pm
example-workflow Ready Ready Preview, Comment May 26, 2026 6:14pm
workbench-astro-workflow Ready Ready Preview, Comment May 26, 2026 6:14pm
workbench-express-workflow Ready Ready Preview, Comment May 26, 2026 6:14pm
workbench-fastify-workflow Ready Ready Preview, Comment May 26, 2026 6:14pm
workbench-hono-workflow Ready Ready Preview, Comment May 26, 2026 6:14pm
workbench-nitro-workflow Ready Ready Preview, Comment May 26, 2026 6:14pm
workbench-nuxt-workflow Ready Ready Preview, Comment May 26, 2026 6:14pm
workbench-sveltekit-workflow Ready Ready Preview, Comment May 26, 2026 6:14pm
workbench-tanstack-start-workflow Ready Ready Preview, Comment May 26, 2026 6:14pm
workbench-vite-workflow Ready Ready Preview, Comment May 26, 2026 6:14pm
workflow-docs Ready Ready Preview, Comment, Open in v0 May 26, 2026 6:14pm
workflow-swc-playground Ready Ready Preview, Comment May 26, 2026 6:14pm
workflow-tarballs Ready Ready Preview, Comment May 26, 2026 6:14pm
workflow-web Ready Ready Preview, Comment May 26, 2026 6:14pm

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.

0 participants