Skip to content

feat: make plugin-cache Redis writes atomic and reads fail loudly - #94

Merged
RedStar071 merged 2 commits into
feat/plugin-gatewayfrom
feat/cache-hardening
Sep 25, 2026
Merged

RedStar071 merged 2 commits into
feat/plugin-gatewayfrom
feat/cache-hardening

Conversation

@RedStar071

Copy link
Copy Markdown
Member

Stacked on #93.

🔗 Linked issue

Related to #55 (phase 4, store hardening). Also covers the first acceptance check: managers behave the same with the memory and the Redis store.

🧭 Context

The status update on #55 listed a few Redis gaps. A value and its index entry were written with two separate commands, so a crash in between left one without the other. The TTL index was only pruned when something enumerated it, so a cache nobody lists grew forever. And a corrupt value surfaced as a bare SyntaxError or zlib error with no hint of which key was broken.

📚 Description

Writes and deletes now go through one MULTI, and with a ttl every write also drops expired index entries. Unreadable values reject with a CacheValueError that carries the Redis key, with the original error as cause. Connection errors are deliberately left unwrapped, so an outage and a corrupt value stay distinguishable.

RedisClientLike gains multi(). ioredis Redis and Cluster still satisfy it as they are, which the existing type test checks. A custom client without transactions would now need one: that is the only compatibility cost, and the package is unreleased.

The test FakeRedis moved to a shared fixture, so the gateway tests can run the same manager scenarios against both stores, a Redis outage included.

Left for later in phase 4: a serialization version tag, and deciding whether clear, getSize and iteration stay mandatory on EntityCache.

Key changes

Area Change
RedisEntityCache.set / delete One MULTI for value + index; prune on write with a ttl
Errors CacheValueError for invalid JSON and corrupt gzip/brotli bytes; aborted transactions reject
Tests Outage, aborted transaction, corrupt values, prune-on-write; manager parity memory vs Redis

Type of Change

  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation change
  • Workflow / CI change

Pre-flight Checklist

  • I have read the Contributing Guidelines (if applicable)
  • My code follows the code style of this project
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have updated the documentation accordingly
  • I added a changeset with pnpm changeset (or pnpm changeset add --empty if no release is needed). See .changeset/README.md.

🤖 AI disclosure: Wolfstar Agent Kit modified this description. My AI open-source policy.

@coldtea-pr-lens

coldtea-pr-lens Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

◈ PR Lens

PR Lens paused analysis for this repository — the fair-use limit was reached. It resumes automatically at 2026-09-25T18:00:00.000Z.

@pullfrog pullfrog Bot left a comment

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.

ℹ️ No critical issues — one nitpick inline, everything else checks out.

Reviewed changes

Reviewed the atomic-write/fail-loud rework of RedisEntityCache end to end: the new RedisTransactionLike/multi() contract, the CacheValueError wrapping, the prune-on-write logic, the moved FakeRedis fixture, and the new cross-store manager parity tests.

  • Atomic set/delete: value key and @index sorted-set entry now go through one MULTI (packages/plugin-cache/src/lib/redis.ts:130-158), closing the crash-between-two-commands gap the PR describes.
  • Prune on write: when a ttl is configured, every set() also runs zremrangebyscore in the same transaction (redis.ts:139-143), bounding the index even if nothing ever enumerates it.
  • CacheValueError: deserialize() wraps JSON/gunzip/brotli failures with the Redis key and original error as cause, while connection errors are deliberately left unwrapped (redis.ts:228-242).
  • Shared FakeRedis fixture: moved to tests/fixtures/FakeRedis.ts with failure/abortTransactions toggles that simulate an outage and a WATCH-aborted transaction; its multi() only runs queued commands when not aborted, matching real Redis semantics.
  • Manager parity tests: new packages/plugin-gateway/tests/stores.test.ts runs the same GatewayClient dispatch scenarios against the in-memory and Redis (FakeRedis) stores, including an outage scenario asserting the client's error event fires and later dispatches still land.

I also verified two of the PR's load-bearing claims rather than trusting the description: installed real ioredis and ran tsc --noEmit -p packages/plugin-cache/tsconfig.consumption.json — it passes, confirming Redis/Cluster.multi() really does satisfy the new RedisTransactionLike without a cast. And ran packages/plugin-cache's vitest suite locally (30/30 passing), including the new outage, aborted-transaction, corrupt-value, and prune-on-write tests — each one would actually fail without the corresponding production code, not just theatre.

ℹ️ Nitpicks

  • packages/plugin-gateway/tests/stores.test.ts imports FakeRedis from ../../plugin-cache/tests/fixtures/FakeRedis.js — a sibling package's tests/ directory rather than a published entry point. It works today (neither package's tsconfig.json includes tests/, so it doesn't affect the build), but it's the first cross-package test import of this shape in the repo and will silently break if plugin-cache ever reorganizes its test layout. Worth considering a shared tests/fixtures location (or exporting a test-only entry from plugin-cache) if more packages end up needing it.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using Claude Sonnet | 𝕏

@RedStar071 RedStar071 changed the title feat(plugin-cache): make Redis writes atomic and reads fail loudly feat: make plugin-cache Redis writes atomic and reads fail loudly Sep 24, 2026
@RedStar071
RedStar071 added this pull request to stack #96 September 24, 2026 14:56
@codecov

codecov Bot commented Sep 24, 2026

Copy link
Copy Markdown

❌ 5 Tests Failed:

Tests completed Failed Passed Skipped
159 5 154 0
View the top 3 failed test(s) by shortest run time
packages/plugin-gateway/tests/EventGatewayListener.test.ts > packages/plugin-gateway/tests/EventGatewayListener.test.ts
Stack Traces | 0s run time
Error: Failed to resolve entry for package "@wolfstar/plugin-cache". The package may have incorrect main/module/exports specified in its package.json.
  Plugin: vite:import-analysis
  File: .../plugin-gateway/src/GatewayClient.ts:8:49
  5  |  } from "@discordjs/ws";
  6  |  import { Client, container } from "@wolfstar/http-framework";
  7  |  import { applyGatewayDispatch } from "@wolfstar/plugin-cache";
     |                                        ^
  8  |  import {
  9  |    GatewayDispatchEvents
 ❯ packageEntryFailure node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]..../node/chunks/dep-Dm0c1Wj2.js:16198:15
 ❯ resolvePackageEntry node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]..../node/chunks/dep-Dm0c1Wj2.js:16195:3
 ❯ tryNodeResolve node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]..../node/chunks/dep-Dm0c1Wj2.js:16060:18
 ❯ ResolveIdContext.resolveId node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]..../node/chunks/dep-Dm0c1Wj2.js:15831:19
 ❯ EnvironmentPluginContainer.resolveId node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]..../node/chunks/dep-Dm0c1Wj2.js:42372:17
 ❯ TransformPluginContext.resolve node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]..../node/chunks/dep-Dm0c1Wj2.js:42579:15
 ❯ normalizeUrl node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]..../node/chunks/dep-Dm0c1Wj2.js:40622:26
 ❯ node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]..../node/chunks/dep-Dm0c1Wj2.js:40753:37
packages/plugin-gateway/tests/GatewayClient.test.ts > packages/plugin-gateway/tests/GatewayClient.test.ts
Stack Traces | 0s run time
Error: Failed to resolve entry for package "@wolfstar/plugin-cache". The package may have incorrect main/module/exports specified in its package.json.
  Plugin: vite:import-analysis
  File: .../plugin-gateway/tests/GatewayClient.test.ts:3:48
  2  |  import { WebSocketShardEvents } from "@discordjs/ws";
  3  |  import { container } from "@wolfstar/http-framework";
  4  |  import { createInMemoryCache } from "@wolfstar/plugin-cache";
     |                                       ^
  5  |  import {
  6  |    ChannelType,
 ❯ packageEntryFailure node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]..../node/chunks/dep-Dm0c1Wj2.js:16198:15
 ❯ resolvePackageEntry node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]..../node/chunks/dep-Dm0c1Wj2.js:16195:3
 ❯ tryNodeResolve node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]..../node/chunks/dep-Dm0c1Wj2.js:16060:18
 ❯ ResolveIdContext.resolveId node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]..../node/chunks/dep-Dm0c1Wj2.js:15831:19
 ❯ EnvironmentPluginContainer.resolveId node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]..../node/chunks/dep-Dm0c1Wj2.js:42372:17
 ❯ TransformPluginContext.resolve node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]..../node/chunks/dep-Dm0c1Wj2.js:42579:15
 ❯ normalizeUrl node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]..../node/chunks/dep-Dm0c1Wj2.js:40622:26
 ❯ node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]..../node/chunks/dep-Dm0c1Wj2.js:40753:37
packages/plugin-gateway/tests/events.test.ts > packages/plugin-gateway/tests/events.test.ts
Stack Traces | 0s run time
Error: Failed to resolve entry for package "@wolfstar/plugin-cache". The package may have incorrect main/module/exports specified in its package.json.
  Plugin: vite:import-analysis
  File: .../plugin-gateway/tests/events.test.ts:2:36
  1  |  "use strict";
  2  |  import { WebSocketShardEvents } from "@discordjs/ws";
  3  |  import { createInMemoryCache } from "@wolfstar/plugin-cache";
     |                                       ^
  4  |  import {
  5  |    GatewayDispatchEvents,
 ❯ packageEntryFailure node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]..../node/chunks/dep-Dm0c1Wj2.js:16198:15
 ❯ resolvePackageEntry node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]..../node/chunks/dep-Dm0c1Wj2.js:16195:3
 ❯ tryNodeResolve node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]..../node/chunks/dep-Dm0c1Wj2.js:16060:18
 ❯ ResolveIdContext.resolveId node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]..../node/chunks/dep-Dm0c1Wj2.js:15831:19
 ❯ EnvironmentPluginContainer.resolveId node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]..../node/chunks/dep-Dm0c1Wj2.js:42372:17
 ❯ TransformPluginContext.resolve node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]..../node/chunks/dep-Dm0c1Wj2.js:42579:15
 ❯ normalizeUrl node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]..../node/chunks/dep-Dm0c1Wj2.js:40622:26
 ❯ node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]..../node/chunks/dep-Dm0c1Wj2.js:40753:37
packages/plugin-gateway/tests/stores.test.ts > packages/plugin-gateway/tests/stores.test.ts
Stack Traces | 0s run time
Error: Failed to resolve entry for package "@wolfstar/plugin-cache". The package may have incorrect main/module/exports specified in its package.json.
  Plugin: vite:import-analysis
  File: .../plugin-gateway/tests/stores.test.ts:3:66
  2  |  import { WebSocketShardEvents } from "@discordjs/ws";
  3  |  import { container } from "@wolfstar/http-framework";
  4  |  import { createInMemoryCache, createRedisCache } from "@wolfstar/plugin-cache";
     |                                                         ^
  5  |  import {
  6  |    ChannelType,
 ❯ packageEntryFailure node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]..../node/chunks/dep-Dm0c1Wj2.js:16198:15
 ❯ resolvePackageEntry node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]..../node/chunks/dep-Dm0c1Wj2.js:16195:3
 ❯ tryNodeResolve node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]..../node/chunks/dep-Dm0c1Wj2.js:16060:18
 ❯ ResolveIdContext.resolveId node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]..../node/chunks/dep-Dm0c1Wj2.js:15831:19
 ❯ EnvironmentPluginContainer.resolveId node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]..../node/chunks/dep-Dm0c1Wj2.js:42372:17
 ❯ TransformPluginContext.resolve node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]..../node/chunks/dep-Dm0c1Wj2.js:42579:15
 ❯ normalizeUrl node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]..../node/chunks/dep-Dm0c1Wj2.js:40622:26
 ❯ node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]..../node/chunks/dep-Dm0c1Wj2.js:40753:37
packages/plugin-gateway/tests/structures.test.ts > packages/plugin-gateway/tests/structures.test.ts
Stack Traces | 0s run time
Error: Failed to resolve entry for package "@wolfstar/plugin-cache". The package may have incorrect main/module/exports specified in its package.json.
  Plugin: vite:import-analysis
  File: .../plugin-gateway/src/GatewayClient.ts:8:49
  5  |  } from "@discordjs/ws";
  6  |  import { Client, container } from "@wolfstar/http-framework";
  7  |  import { applyGatewayDispatch } from "@wolfstar/plugin-cache";
     |                                        ^
  8  |  import {
  9  |    GatewayDispatchEvents
 ❯ packageEntryFailure node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]..../node/chunks/dep-Dm0c1Wj2.js:16198:15
 ❯ resolvePackageEntry node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]..../node/chunks/dep-Dm0c1Wj2.js:16195:3
 ❯ tryNodeResolve node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]..../node/chunks/dep-Dm0c1Wj2.js:16060:18
 ❯ ResolveIdContext.resolveId node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]..../node/chunks/dep-Dm0c1Wj2.js:15831:19
 ❯ EnvironmentPluginContainer.resolveId node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]..../node/chunks/dep-Dm0c1Wj2.js:42372:17
 ❯ TransformPluginContext.resolve node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]..../node/chunks/dep-Dm0c1Wj2.js:42579:15
 ❯ normalizeUrl node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]..../node/chunks/dep-Dm0c1Wj2.js:40622:26
 ❯ node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]..../node/chunks/dep-Dm0c1Wj2.js:40753:37

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

@pkg-pr-new

pkg-pr-new Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@wolfstar/plugin-api

pnpm add https://pkg.pr.new/wolfstar-project/plugins/@wolfstar/plugin-api@94

@wolfstar/plugin-cache

pnpm add https://pkg.pr.new/wolfstar-project/plugins/@wolfstar/plugin-cache@94

@wolfstar/plugin-gateway

pnpm add https://pkg.pr.new/wolfstar-project/plugins/@wolfstar/plugin-gateway@94

@wolfstar/plugin-i18next

pnpm add https://pkg.pr.new/wolfstar-project/plugins/@wolfstar/plugin-i18next@94

@wolfstar/plugin-logger

pnpm add https://pkg.pr.new/wolfstar-project/plugins/@wolfstar/plugin-logger@94

@wolfstar/plugin-subcommands-advanced

pnpm add https://pkg.pr.new/wolfstar-project/plugins/@wolfstar/plugin-subcommands-advanced@94

commit: 64bcf00

@pullfrog

pullfrog Bot commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

Your Claude subscription has hit its usage limit. It resets at 7:20pm (UTC). Re-trigger Pullfrog after the reset, or add an ANTHROPIC_API_KEY repo secret — Pullfrog routes around an exhausted subscription automatically when one is present.

Add repo secret → · Model settings → · Setup docs → · Ask in Discord →

Pullfrog  | Rerun failed job ➔ | View workflow run | via Pullfrog | Using Claude Sonnet | 𝕏

Value and index writes/deletes go through one MULTI transaction, a ttl
prunes expired index entries on every write, and unreadable values reject
with a CacheValueError naming the key. Managers are now tested against
both the memory and the Redis store, outage included.

Refs #55
@pullfrog

pullfrog Bot commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

Your Claude subscription has hit its usage limit. It resets at 7:20pm (UTC). Re-trigger Pullfrog after the reset, or add an ANTHROPIC_API_KEY repo secret — Pullfrog routes around an exhausted subscription automatically when one is present.

Add repo secret → · Model settings → · Setup docs → · Ask in Discord →

Pullfrog  | Rerun failed job ➔ | View workflow run | via Pullfrog | Using Claude Sonnet | 𝕏

@RedStar071
RedStar071 merged commit 7db3af5 into main Sep 25, 2026
20 of 25 checks passed
@RedStar071
RedStar071 deleted the feat/cache-hardening branch September 25, 2026 18:02
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