Skip to content

Persistence: stores on layerKvs and layerRedis can clear and read each other's entries #9207

Closed

Description

@nick-inkeep

What version of Effect is running?

[email protected] (the code is unchanged on main)

What steps can reproduce the bug?

Stores made with the Persistence service's make({ storeId }) are not kept apart on layerKvs and layerRedis. clear on one store deletes other stores' entries, and some store id / key pairs read each other's entries. layerMemory and layerSql keep stores apart, and the SQL suite pins it: clear on one store leaves another store's entry for the same key intact (isolation between stores, packages/sql/sqlite-node/test/Persistence.test.ts:112).

import { Effect, Exit, Layer, Schema } from "effect"
import { KeyValueStore, Persistable, Persistence } from "effect/persistence"

class GetUser extends Persistable.Class<{ payload: { id: string } }>()("GetUser", {
  primaryKey: (p) => p.id,
  success: Schema.String
}) {}

const program = Effect.gen(function*() {
  const persistence = yield* Persistence.Persistence

  const users = yield* persistence.make({ storeId: "users" })
  const sessions = yield* persistence.make({ storeId: "sessions" })
  yield* users.set(new GetUser({ id: "1" }), Exit.succeed("alice"))
  yield* sessions.clear
  console.log(yield* users.get(new GetUser({ id: "1" })))

  const a = yield* persistence.make({ storeId: "a" })
  const ab = yield* persistence.make({ storeId: "ab" })
  yield* a.set(new GetUser({ id: "bc" }), Exit.succeed("from a/bc"))
  console.log(yield* ab.get(new GetUser({ id: "c" })))
})

Effect.runPromise(program.pipe(
  Effect.scoped,
  Effect.provide(Persistence.layerKvs.pipe(Layer.provide(KeyValueStore.layerMemory)))
))

On layerRedis (NodeRedis, Redis 8.10.2), plain store ids are kept apart, but ids containing : are not:

  • clear on store cache deletes the entries of store cache:users.
  • Store a / key b:c and store a:b / key c are the same Redis key, a:b:c.

To see it, provide Persistence.layerRedis.pipe(Layer.provide(NodeRedis.layer({ url }))) to the snippet instead, and rename store users → cache:users, sessions → cache, ab → a:b, and key bc → b:c. It prints the same two lines.

What is the expected behavior?

The same as with Persistence.layerMemory or layerSql: users still holds "alice" after sessions.clear, and store ab has no entry c.

What do you see instead?

undefined
{ _id: 'Exit', _tag: 'Success', value: 'from a/bc' }

sessions.clear emptied the whole KeyValueStore, including every other store. Store ab / key c and store a / key bc are the same KeyValueStore key, abc.

Additional information

Cause, at [email protected]:

#7004 proposed a fix for the KVS half and was closed unmerged; it did not touch the Redis backing. Draft #8735 changes the Redis clear to escape glob characters, but keeps the storeId:key layout on standalone and Sentinel, so these cases remain. KeyValueStore has no way to list keys, so layerBackingKvs cannot scope clear by prefix alone.

Activity

  1. self-assigned this
    on Oct 15, 2026
  2. added a commit that references this issue on Oct 15, 2026
    b961475
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions