agentleFS
VercelKnown publishervercel/chat/packages/state-ioredis/AGENTS.md

chat / state-ioredis

AGENTS.md2.4k starsChanged 59 days agoMITView on GitHub

Guidance for coding agents working inside the ioredis state adapter package. The top-level repository AGENTS.md covers monorepo-wide build, lint, and release rules — read it first. This file documents the adapter-specific surface, conventions, and pitfalls. @chat-adapter/state-ioredis is the same Chat SDK state contract as @chat-adapter/state-redis but built on ioredis. Pick this variant when you need: - Cluster mode — ioredis ships first-class Redis Cluster support, including topology refresh, MOVED redirection, and CROSSSLOT-safe hash tags. - Sentinel — automatic failover via…

  • Reads credentials

Trending

Quiet since March.thin dataabout the whole repository

Dec 2025: 0 mentionsJan 2026: 0 mentionsFeb 2026: 1 mentionMar 2026: 4 mentionsApr 2026: 0 mentionsMay 2026: 0 mentionsJun 2026: 0 mentionsJul 2026: 0 mentionsAug 2026: 0 mentionsSep 2026: 0 mentionsOct 2026: 0 mentionsNov 2026: 0 mentions
Dec 2025Jun 2026Nov 2026
Mentions a month of the vercel/chat repository that our weekly crawl found: only 5 in all, so this is a hint, not a trend. There is no adoption data for this file yet.

The file

We split this AGENTS.md into the rules it gives an agent

4 rules. About 0 are common, 1 is distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    If none of these apply, prefer @chat-adapter/state-redis for its smaller dependency footprint.

    line 23
  2. Very specific:

    If the caller passes a client, the adapter assumes it is already connected and does not call quit() on disconnect().

    line 176
  3. Distinctive:

    Use named exports throughout.

    line 209
  4. Very specific:

    All key construction goes through a single prefixedKey helper.

    line 210

≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
AGENTS.md

AGENTS.md — @chat-adapter/state-ioredis

Guidance for coding agents working inside the ioredis state adapter package. The top-level repository AGENTS.md covers monorepo-wide build, lint, and release rules — read it first. This file documents the adapter-specific surface, conventions, and pitfalls.

Overview

@chat-adapter/state-ioredis is the same Chat SDK state contract as @chat-adapter/state-redis but built on ioredis. Pick this variant when you need:

  • Cluster mode — ioredis ships first-class Redis Cluster support, including topology refresh, MOVED redirection, and CROSSSLOT-safe hash tags.
  • Sentinel — automatic failover via Redis Sentinel.
  • Pub/Sub + commands on the same client — ioredis allows it (node-redis doesn't without separate clients).
  • An existing codebase already standardised on ioredis.

If none of these apply, prefer @chat-adapter/state-redis for its smaller dependency footprint.

Directory layout

packages/state-ioredis/
├── src/
│   ├── index.ts             # IoRedisStateAdapter + createIoRedisState
│   └── index.test.ts        # full StateAdapter contract suite
├── package.json
├── tsconfig.json
├── tsup.config.ts
├── vitest.config.ts
└── README.md

The package mirrors state-redis line-for-line where possible so fixes apply to both. Behavioural deviations are limited to what ioredis and node-redis express differently (transaction syntax, script caching, cluster routing).

Build, test, typecheck

pnpm build
pnpm dev
pnpm test
pnpm test:watch
pnpm typecheck
pnpm clean

# from repo root
pnpm --filter @chat-adapter/state-ioredis build
pnpm --filter @chat-adapter/state-ioredis test

The unit tests use a vi.fn()-backed ioredis stub. Real Redis integration tests live in packages/integration-tests/src/state-ioredis.test.ts and run only when REDIS_URL is exported.

Public surface

Main exports from src/index.ts:

  • createIoRedisState(options) — primary factory. Requires either a url or an existing client; there is no REDIS_URL auto-detection (unlike createRedisState).
  • IoRedisStateAdapter class — implements the Chat SDK StateAdapter interface. Public methods: subscriptions, locks, cache, lists, queues, plus disconnect().
  • IoRedisStateAdapterOptions — options type, a union of the url-based and client-based variants.

Configuration

import { createIoRedisState } from "@chat-adapter/state-ioredis";

// With a connection URL
createIoRedisState({
  url: process.env.REDIS_URL!,
  keyPrefix: "chat-sdk",
  logger: customLogger, // optional, defaults to a console logger
});

// Or with an existing ioredis client
createIoRedisState({ client: existingIoredisInstance });

For cluster:

import { Cluster } from "ioredis";

const cluster = new Cluster([
  { host: "node-a", port: 6379 },
  { host: "node-b", port: 6379 },
]);

createIoRedisState({ client: cluster });

For sentinel:

import Redis from "ioredis";

const client = new Redis({
  sentinels: [{ host: "sentinel-a", port: 26379 }],
  name: "mymaster",
});

createIoRedisState({ client });

Internal key layout

Identical to state-redis:

{prefix}:subs:{threadId}
{prefix}:lock:{lockId}
{prefix}:cache:{cacheKey}
{prefix}:list:{listKey}
{prefix}:queue:{queueKey}
{prefix}:queue:{queueKey}:dedupe

Cluster mode uses hash-tag braces around the multi-key segment so locks and cache keys with the same logical ID land on the same slot:

{prefix}:{lockId}:lock              # tagged variant for cluster

The adapter selects the tagged or untagged form based on whether the client reports a cluster topology — see the isClusterClient(client) helper.

Locking semantics

acquireLock(lockId, ttlMs) uses SET key value NX PX ttl exactly as state-redis does. releaseLock(lockId, token) runs the same Lua script via EVALSHA (with EVAL fallback on NOSCRIPT). Cluster support is handled by ioredis's built-in script management.

forceReleaseLock(lockId) is unconditional DEL.

Capabilities

  • Persistence — yes.
  • Multi-instance — yes.
  • Subscriptions — yes.
  • Distributed locking — yes, atomic via Lua release script.
  • Key-value cache — yes, with TTL.
  • Lists — yes, with per-entry TTL.
  • Queues — yes, with per-entry TTL + dedupe set.
  • Automatic reconnect — yes (built into ioredis).
  • Cluster — yes, with hash-tag slot routing.
  • Sentinel — yes, via ioredis Sentinel transport.
  • Key prefix namespacing — yes.

Pipelines & transactions

ioredis exposes pipeline() separately from multi(). The adapter uses multi().exec() for atomic composite operations (queue dedupe check + enqueue, list trim + add) — pipelines are reserved for performance optimisations that don't need atomicity.

Connection management

If the caller passes a client, the adapter assumes it is already connected and does not call quit() on disconnect(). If the adapter creates its own client, it owns the lifecycle.

The adapter listens for error, reconnecting, and end events on the client and forwards them to logger. There is no automatic re-creation of clients — ioredis handles reconnection internally.

Error handling

Mirrors state-redis:

  • WRONGPASS/NOAUTH → AuthenticationError.
  • LOADING / BUSY → AdapterRateLimitError with a short retry-after.
  • Connection errors → NetworkError.

Cluster CLUSTERDOWN errors are surfaced as NetworkError so handlers can apply uniform retry logic.

Testing approach

  • The contract tests in index.test.ts mirror the state-redis suite. Whenever you fix something in one, port the test (and fix) to the other.
  • Real-cluster / real-Sentinel tests live in packages/integration-tests/src/state-ioredis.test.ts and run only with the env vars present.
  • Cluster routing tests stub ioredis.Cluster with a vi.fn() shim that records the resolved nodes per command.

Coding conventions

  • Use named exports throughout. No default exports.
  • All key construction goes through a single prefixedKey helper.
  • Cluster-aware key construction lives in keyTagged — never inline {} brace concatenation.
  • TTLs are stored as absolute epoch milliseconds for ZSET-backed structures and converted to relative ms (PX) for STRING-backed ones.
  • Top-level regex literals only.
  • Errors map to @chat-adapter/shared (AuthenticationError, AdapterRateLimitError, NetworkError).

Releases

Behavioural changes need a changeset (pnpm changeset, choose @chat-adapter/state-ioredis plus chat if a public StateAdapter type changed). When fixing parity bugs, include both state-redis and state-ioredis in the changeset.

Where to look next

  • User-facing docs: apps/docs/content/adapters/official/ioredis.mdx
  • README: packages/state-ioredis/README.md
  • Core StateAdapter contract: packages/chat/src/state.ts
  • Sibling state adapters:
    • packages/state-memory
    • packages/state-redis
    • packages/state-pg

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.