Skip to content

[vercel-flags-core] track fetchedAt in embedded and runtime datafiles - #505

Closed
luismeyer wants to merge 1 commit into
flags-version-headerfrom
fix/datafile-fetched-at
Closed

luismeyer wants to merge 1 commit into
flags-version-headerfrom
fix/datafile-fetched-at

Conversation

@luismeyer

Copy link
Copy Markdown
Member

Context

Follow-up to #498 (comment).

This PR is stacked on #498 (flags-version-header), which is still open, so the diff contains only the timestamp/freshness follow-up. Retarget to main after #498 merges.

Changes

  • Add optional epoch-millisecond fetchedAt metadata, stamped locally after build-time preparation, runtime HTTP fetches, and stream data receipt.
  • Preserve the timestamp through embedded modules and in-memory/public datafiles. Loading legacy bundled or provided definitions does not manufacture freshness.
  • Track the last exact matching version-header observation separately from fetchedAt, scoped to the current data object. Older headers do not extend freshness.
  • Base the existing 10-second background-refresh window on acquisition/confirmation age instead of the gap between configuration timestamps. Stale data with old, missing, invalid, or future acquisition timestamps requires a blocking refresh unless recently confirmed.
  • Refresh acquisition metadata when the same version is fetched again, without replacing definitions rejected by the existing version guard.
  • Add deterministic coverage for legacy embeds, metadata roundtrips, stream/poll acquisitions, timestamp boundaries, per-client confirmation, version replacement, and existing cancellation/error behavior. Update the existing changeset description without changing its release level.

New configurable stale-while-revalidate/stale-if-error APIs are intentionally left for later; fallback-on-error behavior is unchanged.

Verification

All final checks exited 0:

  • pnpm -C packages/vercel-flags-core exec vitest run --exclude src/integration.test.ts — 589 tests passed across 15 files.
  • pnpm -C packages/prepare-flags-definitions test — 23 tests passed.
  • pnpm -C packages/prepare-flags-definitions type-check
  • pnpm -C packages/vercel-flags-core type-check
  • pnpm exec biome check packages/vercel-flags-core/src/controller/{index.ts,header-source.ts,header-source.test.ts,fetch-datafile.ts,stream-source.ts} packages/vercel-flags-core/src/{types.ts,vercel-mode.black-box.test.ts,black-box.test.ts} packages/prepare-flags-definitions/src/{index.ts,index.test.ts} — 10 files checked, no fixes needed.
  • git diff --check and git diff --cached --check

Live integration tests were not run. Existing usage-tracker retry tests emitted their simulated network-error logs while passing. Biome's --changed --since=HEAD shortcut found no files in this worktree; the explicit-file check above passed instead.

@vercel

vercel Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

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

Project Deployment Actions Updated
flags-playground Ready Ready Preview, v0 Sep 21, 2026 8:43am UTC
flags-sdk-dev Ready Ready Preview, v0 Sep 21, 2026 8:43am UTC
flags-sdk-snippets Ready Ready Preview, v0 Sep 21, 2026 8:43am UTC
flags-sdk-sveltekit-snippets Ready Ready Preview, v0 Sep 21, 2026 8:43am UTC
shirt-shop Ready Ready Preview, v0 Sep 21, 2026 8:43am UTC
shirt-shop-api Ready Ready Preview, v0 Sep 21, 2026 8:43am UTC

if (res.ok) {
return res.json() as Promise<BundledDefinitions>;
const data = (await res.json()) as BundledDefinitions;
return { ...data, fetchedAt: Date.now() };

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Per-fetch fetchedAt: Date.now() embedded into each datafile defeats content-based deduplication of identical definitions across SDK keys/OIDC tokens.

Fix on Vercel

@luismeyer luismeyer closed this Sep 22, 2026

This branch was successfully deployed

6 active deployments
Preview – flags-sdk-dev — 2b5ceb0d Deployed Sep 21, 2026 by vercel[bot]
Preview – flags-sdk-snippets — 2b5ceb0d Deployed Sep 21, 2026 by vercel[bot]
Preview – flags-playground — 2b5ceb0d Deployed Sep 21, 2026 by vercel[bot]
Preview – flags-sdk-sveltekit-snippets — 2b5ceb0d Deployed Sep 21, 2026 by vercel[bot]
Preview – shirt-shop — 2b5ceb0d Deployed Sep 21, 2026 by vercel[bot]
Preview – shirt-shop-api — 2b5ceb0d Deployed Sep 21, 2026 by vercel[bot]
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