Skip to content

fix(core): reject non-JSON-safe layer keys with LayerKeyError#29

Merged
SutuSebastian merged 2 commits into
mainfrom
fix/json-safe-layer-keys
Jul 19, 2026
Merged

fix(core): reject non-JSON-safe layer keys with LayerKeyError#29
SutuSebastian merged 2 commits into
mainfrom
fix/json-safe-layer-keys

Conversation

@SutuSebastian

Copy link
Copy Markdown
Contributor

Summary

  • Runtime-assert JSON-safe LayerKey segments in hashKey (assertLayerKey); throw LayerKeyError / narrow with isLayerKeyError
  • Allowed: string | boolean | null | finite number | plain objects/arrays of those; reject undefined (incl. object props), NaN/±Infinity, bigint, symbol, functions, non-plain objects, cycles
  • Docs: JSON-safe domain + prior [undefined]/[null]/[NaN]"[null]" collision note; sync throw vs Promise reject in error-handling

Breaking note

Apps using undefined / NaN / non-finite numbers / BigInt / cycles / class instances in keys will start throwing. Fix: use null or explicit sentinels (filterId ?? "none"); omit optional object fields instead of setting undefined.

Test plan

  • bun test packages/core/src/layerStack.test.ts (reject matrix + sync open throw)
  • bun run --filter ./packages/core typecheck
  • bun run docs:check --isolated + docs:build
  • CI green

Fail closed before hashKey so undefined/NaN/null no longer collide via JSON.stringify, and document the JSON-safe key domain.
@SutuSebastian SutuSebastian added the docs Merged PRs with this label deploy the /layers docs site label Jul 19, 2026
@changeset-bot

changeset-bot Bot commented Jul 19, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4e45ecd

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

This PR includes changesets to release 11 packages
Name Type
@stainless-code/layers Patch
@stainless-code/alpine-layers Patch
@stainless-code/angular-layers Patch
@stainless-code/layers-devtools Patch
@stainless-code/lit-layers Patch
@stainless-code/preact-layers Patch
@stainless-code/react-layers-devtools Patch
@stainless-code/react-layers Patch
@stainless-code/solid-layers Patch
@stainless-code/svelte-layers Patch
@stainless-code/vue-layers 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

@coderabbitai

coderabbitai Bot commented Jul 19, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@SutuSebastian, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 17 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a79d0079-aa17-4cda-8b55-ce880ab5ad5e

📥 Commits

Reviewing files that changed from the base of the PR and between 323be82 and 4e45ecd.

📒 Files selected for processing (14)
  • .changeset/json-safe-layer-keys.md
  • apps/docs/content/adapters/core.mdx
  • apps/docs/content/concepts/glossary.mdx
  • apps/docs/content/concepts/identity-and-types.mdx
  • apps/docs/content/guides/error-handling.mdx
  • apps/docs/content/reference/core-api.mdx
  • docs/architecture.md
  • docs/glossary.md
  • packages/core/skills/layers/SKILL.md
  • packages/core/src/errors.ts
  • packages/core/src/index.ts
  • packages/core/src/layerStack.test.ts
  • packages/core/src/types.ts
  • packages/core/src/utils.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/json-safe-layer-keys

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Backtrack WeakSet after walking children; sort into Object.create(null); tighten tests/docs/JSDoc for the JSON-safe key contract.
@SutuSebastian
SutuSebastian merged commit de3bd7b into main Jul 19, 2026
17 checks passed
@SutuSebastian
SutuSebastian deleted the fix/json-safe-layer-keys branch July 19, 2026 09:59
@github-actions github-actions Bot mentioned this pull request Jul 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Merged PRs with this label deploy the /layers docs site

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant