Skip to content

Conversation

@johanneskares
Copy link

Type

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update

Description

Bug Description

When using @effect/sql-kysely with Effect.fn, a TypeError is thrown due to JavaScript Proxy invariant violations. The error occurs because the effectifyWith proxy handler doesn't properly pass through non-configurable properties.

Error Messages

TypeError: 'get' on proxy: property 'Symbol(effect/Hash)' is a read-only and non-configurable data property on the proxy target but the proxy did not return its actual value
TypeError: 'get' on proxy: property 'node' is a read-only and non-configurable data property on the proxy target but the proxy did not return its actual value

Root Cause

The effectifyWith function in @effect/sql-kysely creates a Proxy that wraps Kysely query builders to make them Effect-compatible. However, the proxy's get handler violates a fundamental JavaScript Proxy invariant:

If the target object property is a non-configurable, non-writable data property, the proxy's get trap must return the same value as the target property.

The current implementation recursively wraps all property accesses, including:

  1. Symbol properties (like Symbol(effect/Hash))
  2. Non-configurable properties (like node on Kysely's internal AST)

When Effect.fn internally compares or hashes the returned value, it accesses these Symbol properties. The proxy returns a wrapped version instead of the actual value, triggering the invariant violation.

Reproduction

import { Effect } from "effect";
import { SqlKysely } from "@effect/sql-kysely";

// This works fine
const workingQuery = Effect.gen(function* () {
  const db = yield* SqlKysely;
  return yield* db.selectFrom("users").selectAll();
});

// This fails with proxy invariant violation
const brokenQuery = Effect.fn("brokenQuery")(function* () {
  const db = yield* SqlKysely;
  return yield* db.selectFrom("users").selectAll();
});

The bug only manifests when using Effect.fn because it performs internal operations (like hashing for tracing) that access Symbol properties on the returned Effect.

  • Related Issue 3299

@changeset-bot
Copy link

changeset-bot bot commented Jan 14, 2026

⚠️ No Changeset found

Latest commit: a62fbda

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@johanneskares johanneskares changed the title Proxy invariant violation: effectifyWith fails for non-configurable properties Kysely: Proxy invariant violation: effectifyWith fails for non-configurable properties Jan 19, 2026
@tim-smart
Copy link
Contributor

If you run pnpm changeset you can add a changelog entry

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Discussion Ongoing

Development

Successfully merging this pull request may close these issues.

2 participants