Skip to content

refactor(redis): move distributed runtime behind explicit extension - #3216

Merged
kwakayama merged 15 commits into
mainfrom
codex/redis-extension-train-20260801
Aug 2, 2026
Merged

refactor(redis): move distributed runtime behind explicit extension#3216
kwakayama merged 15 commits into
mainfrom
codex/redis-extension-train-20260801

Conversation

@kojiwakayama

@kojiwakayama kojiwakayama commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Summary

  • moves redis and @redis/client runtime implementations into the explicit @veryfront/ext-redis boundary
  • adds provider-neutral RedisRuntimeProvider contracts and lifecycle-owned clients for cache, rate limiting, platform adapters, shared clients, proxy-routing Pub/Sub, and Claude Code Pub/Sub
  • enforces explicit activation, capability/dependency ownership, npm/binary packaging boundaries, and AST-based core dependency audits

Compatibility

  • existing core Redis facades remain, but Redis functionality now requires installing and explicitly enabling @veryfront/ext-redis
  • there is no automatic activation or in-memory compatibility fallback when Redis is selected
  • workspace and compiled-binary availability do not bypass activation
  • public dependency-free leaf exports support the extension package without pulling broad core/React surfaces

Safety

  • single-flight acquisition, abort-aware cleanup, late-settlement close, retryable teardown, listener isolation, and fail-closed provider capture
  • Redis module lookups re-resolve the active provider, reject stale in-flight loads after replacement/invalidation, and invalidate already-returned module adapters when their owning provider closes
  • provider-neutral module capture retains the Pub/Sub and error-listener methods required by proxy routing without an unsafe type cast
  • root core/CLI stay third-party-free; Redis packages are extension-owned and sensitive SBOM/capability boundaries are ratcheted
  • duplicate package metadata removed; manifest/factory contract constants are machine-checked

Validation

  • deno task verify:quick
  • deno task build:npm
  • extensions/ext-redis: 5 test files / 28 steps
  • affected core Redis suites: 7 test files / 71 steps
  • provider lifecycle regressions: 2 type-checked test files / 22 steps
  • Pub/Sub and routing regression portfolio: 4 type-checked test files / 46 steps
  • complete Redis, routing, and provider-contract portfolio: 10 test files / 103 passing steps
  • ext-redis complete source and test type-check
  • relevant build/lint policy suites: 25 tests / 62 steps
  • dependency/capability/contract audits
  • git diff --check
  • independent blocker review clean

Stack

@kojiwakayama
kojiwakayama requested a review from kwakayama as a code owner August 1, 2026 23:25

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5a9cb820c8

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/platform/adapters/redis/modules.ts Outdated
@kojiwakayama

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 281f7bd617

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread extensions/ext-redis/src/redis-runtime-provider.ts
Comment thread extensions/ext-redis/src/index.ts Outdated
@kojiwakayama

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 81f12cf11d

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread extensions/ext-redis/src/redis-runtime-provider.ts
@kojiwakayama

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f6da9dbefc

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread extensions/ext-redis/src/redis-runtime-provider.ts Outdated
@kojiwakayama

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 09d3fa0a15

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/extensions/index.ts
Comment thread src/extensions/recommendations.ts Outdated
@kojiwakayama

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 51b4ced1f9

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread extensions/ext-redis/README.md Outdated
Base automatically changed from codex/core-runtime-extension-train-20260801 to main August 2, 2026 04:41
Copilot AI review requested due to automatic review settings August 2, 2026 05:50
@kojiwakayama
kojiwakayama force-pushed the codex/redis-extension-train-20260801 branch from 48b803d to b38ed5b Compare August 2, 2026 05:50

Copilot AI 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.

Pull request overview

This PR refactors Redis support so core remains provider-neutral while Redis runtime implementations, third-party packages (redis, @redis/client), connection lifecycle, and Pub/Sub live behind an explicitly activated @veryfront/ext-redis extension. It introduces new Redis runtime contracts (RedisRuntimeProvider), adds lifecycle-owned connection helpers (shared + owned clients), and updates core features (render cache store, rate limiting, Claude Code event publishing, proxy routing invalidation, and platform Redis adapter module loading) to resolve Redis functionality through the active provider.

Changes:

  • Introduces provider-neutral Redis runtime contracts (RedisRuntimeProvider, client/handle types, module adapter capture) and core helpers (ensureRedisRuntimeProvider, OwnedRedisClientConnection, shared client facade updates).
  • Adds a new explicit extension package extensions/ext-redis that owns Redis dependencies, runtime clients, Pub/Sub publisher implementation, and lifecycle-safe teardown behavior.
  • Strengthens build/lint/audit tooling to enforce dependency and capability boundaries (SBOM ratchets, extension capability audits, AST-based core dependency audit improvements), and updates public exports/import-map entries accordingly.

Verification (recommended):

  • Not run in this review environment.
  • Suggested commands:
    • deno task verify:quick
    • deno test --no-check --allow-all --parallel
    • deno task test -- tests/docs/ (docs were updated)

Reviewed changes

Copilot reviewed 53 out of 54 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/workflow/claude-code/event-publisher.ts Routes Redis event publishing through the active Redis runtime provider contract.
src/workflow/claude-code/event-publisher.test.ts Updates Claude Code event publisher tests to use contract registration and provider stubs.
src/utils/redis-client.ts Refactors shared Redis client facade to resolve/track provider owners and disconnect across provider generations.
src/utils/redis-client.test.ts Adds tests for shared client facade owner tracking, in-flight acquisition handling, and retryable disconnect.
src/rendering/cache/stores/redis-store.ts Switches render cache Redis store to an extension-owned connection handle and object-shaped SCAN results.
src/rendering/cache/stores/redis-store.test.ts Adds tests validating owned connection close behavior and SCAN shape handling.
src/proxy/routing-invalidation-redis.ts Aligns routing invalidation Redis client typing with provider-neutral Pub/Sub surfaces.
src/platform/adapters/redis/types.ts Re-exports Redis module/client structural types from the provider-neutral contract.
src/platform/adapters/redis/node.ts Adjusts Node Redis adapter disconnect semantics to match destroy(): void contract.
src/platform/adapters/redis/modules.ts Replaces direct Redis imports with provider-owned module loading + generation-safe caching and invalidation.
src/platform/adapters/redis/modules.test.ts Expands module-loading tests for provider replacement, in-flight invalidation, and post-close behavior.
src/middleware/builtin/security/redis-rate-limit.ts Refactors Redis rate limit store to use an owned Redis connection handle.
src/middleware/builtin/security/redis-rate-limit.test.ts Updates tests to validate owned-connection cleanup and client reuse behavior.
src/extensions/recommendations.ts Adds an extension recommendation mapping for RedisRuntimeProvider.
src/extensions/index.ts Exposes provider-neutral Redis distributed runtime contracts via the public extensions surface.
src/extensions/distributed/index.ts Adds the distributed runtime barrel export for Redis runtime contracts.
src/extensions/distributed/defaults.ts Adds provider resolution helpers for explicit orchestration and active-provider lookup.
src/extensions/distributed/redis-runtime-provider.ts Introduces the provider-neutral Redis runtime contract and safe capture/snapshot wrappers.
src/extensions/distributed/redis-runtime-provider.test.ts Adds tests for provider capture correctness, accessor rejection, and fail-closed behavior.
src/extensions/distributed/owned-redis-client.ts Adds lifecycle-owned Redis connection helper with single-flight open/close and abort-aware cleanup.
src/extensions/distributed/owned-redis-client.test.ts Adds tests for connection cancellation, idempotent close, and listener isolation across replacements.
scripts/lint/extension-source-metadata.ts Extends known contract constant auditing to include RedisRuntimeProviderName.
scripts/lint/audit-extension-contracts.test.ts Updates contract audit tests to include Redis runtime provider contracts.
scripts/lint/audit-extension-capabilities.ts Adds sensitive capability policy for the Redis runtime extension.
scripts/lint/audit-extension-capabilities.test.ts Adds tests ensuring ext-redis capability requirements are enforced.
scripts/lint/audit-dependency-boundaries.test.ts Adds ext-redis dependency boundary expectations for redis and @redis/client.
scripts/lint/audit-core-deps.ts Replaces regex-based import detection with AST-based analysis for static/dynamic third-party imports.
scripts/lint/audit-core-deps.test.ts Expands tests for new AST-based third-party import detection behaviors.
scripts/build/npm-package-metadata.ts Moves Redis packages into extension-owned dependencies and removes root optional peer for redis.
scripts/build/npm-package-metadata.test.ts Updates root package metadata expectations after removing the redis peer.
scripts/build/npm-extension-package-metadata.test.ts Adds test ensuring ext-redis is externalized through dependency-free leaf exports.
scripts/build/generate-sbom.ts Adds SBOM sensitive dependency boundary for ext-redis packages.
scripts/build/generate-sbom.test.ts Adds SBOM ratchet test coverage for the ext-redis boundary.
scripts/build/compile-binary.ts Ensures compiled binary includes ext-redis source for opt-in activation.
scripts/build/compile-binary.test.ts Adds test validating compiled CLI embeds ext-redis.
extensions/README.md Documents ext-redis in the extensions catalog and capability policy tables.
extensions/ext-redis/deno.json Defines the ext-redis explicit-activation manifest, contracts, capabilities, and import mappings.
extensions/ext-redis/README.md Adds user-facing documentation for installing and explicitly enabling ext-redis.
extensions/ext-redis/src/index.ts Adds ext-redis factory that registers the RedisRuntimeProvider and declares required capabilities.
extensions/ext-redis/src/index.test.ts Tests extension factory contract/capability declaration and teardown/setup behavior.
extensions/ext-redis/src/connection-config.ts Adds Redis URL validation helper for safe, canonical connection config.
extensions/ext-redis/src/connection-config.test.ts Tests Redis URL validation behavior and rejection cases.
extensions/ext-redis/src/redis-client-manager.ts Adds extension-owned Redis shared-client manager with option capture, retries, and safe cleanup.
extensions/ext-redis/src/redis-client-manager.test.ts Tests option capture, single-flight acquisition, cancellation, retries, and cleanup behavior.
extensions/ext-redis/src/event-publisher.ts Adds extension-owned Redis Pub/Sub event publisher with safe init/close and listener lifecycle.
extensions/ext-redis/src/event-publisher.test.ts Tests Pub/Sub publisher initialization single-flight, listener isolation, and teardown failure modes.
extensions/ext-redis/src/redis-runtime-provider.ts Implements RedisRuntimeProvider using redis + @redis/client, including module adapter and owned clients.
extensions/ext-redis/src/redis-runtime-provider.test.ts Tests provider lifecycle behaviors: module invalidation, owned clients, connect/close edge cases, retries.
docs/api-reference/veryfront/workflow.md Updates generated API reference links/locations affected by refactors and type moves.
docs/api-reference/veryfront/middleware.md Updates generated API reference links/locations for Redis rate limit changes.
docs/api-reference/veryfront/extensions.md Updates generated API reference exports for new distributed runtime contracts.
docs/api-reference/veryfront/errors.md Updates generated API reference deep-import sections for error registry barrels.
deno.lock Records ext-redis npm dependency entries for redis and @redis/client.
deno.json Adds ext-redis workspace member and new public import-map entries for distributed contracts and deep imports.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/platform/adapters/redis/node.ts
Copilot AI review requested due to automatic review settings August 2, 2026 06:01

Copilot AI 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.

Pull request overview

Copilot reviewed 54 out of 55 changed files in this pull request and generated no new comments.

Suppressed comments (1)

src/workflow/claude-code/event-publisher.ts:136

  • RedisEventPublisher.close() only clears this.implementation after a successful implementation.close(). If close() rejects (for example, one underlying client fails to close), the publisher keeps the previous implementation and later publish()/subscribe() calls can reuse a partially closed or failed implementation instead of creating a fresh one.

Copilot AI review requested due to automatic review settings August 2, 2026 06:12
@kojiwakayama
kojiwakayama force-pushed the codex/redis-extension-train-20260801 branch from 7384369 to f0dde4d Compare August 2, 2026 06:12

Copilot AI 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.

Copilot wasn't able to review this pull request because it exceeds the maximum number of lines (20,000). Try reducing the number of changed lines and requesting a review from Copilot again.

Copilot AI review requested due to automatic review settings August 2, 2026 06:26
@kojiwakayama
kojiwakayama force-pushed the codex/redis-extension-train-20260801 branch from f0dde4d to d64a557 Compare August 2, 2026 06:26

Copilot AI 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.

Copilot wasn't able to review this pull request because it exceeds the maximum number of lines (20,000). Try reducing the number of changed lines and requesting a review from Copilot again.

Copilot AI review requested due to automatic review settings August 2, 2026 06:31
@kojiwakayama
kojiwakayama force-pushed the codex/redis-extension-train-20260801 branch from d64a557 to 5e9ca2f Compare August 2, 2026 06:31

Copilot AI 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.

Copilot wasn't able to review this pull request because it exceeds the maximum number of lines (20,000). Try reducing the number of changed lines and requesting a review from Copilot again.

Copilot AI review requested due to automatic review settings August 2, 2026 07:03
@kwakayama
kwakayama enabled auto-merge August 2, 2026 07:15
kwakayama
kwakayama previously approved these changes Aug 2, 2026
@kwakayama
kwakayama added this pull request to the merge queue Aug 2, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Aug 2, 2026
Copilot AI review requested due to automatic review settings August 2, 2026 07:30
@kojiwakayama
kojiwakayama force-pushed the codex/redis-extension-train-20260801 branch from a5fd100 to 78b42b6 Compare August 2, 2026 07:30
@kwakayama
kwakayama enabled auto-merge August 2, 2026 07:31

Copilot AI 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.

Pull request overview

Copilot reviewed 55 out of 56 changed files in this pull request and generated no new comments.

Suppressed comments (3)

src/extensions/distributed/redis-runtime-provider.ts:414

  • The captured ttl wrapper uses Promise.resolve(Reflect.apply(...)), which still throws synchronously if the underlying ttl throws. Since callers treat ttl as returning a Promise, wrap the call in Promise.resolve().then(...) so sync throws become rejections, matching the other async method wrappers.
    extensions/ext-redis/src/redis-runtime-provider.ts:217
  • closeClient(force) resets closed = false, which makes the forced cleanup path non-idempotent. If a provisional handle was already closed successfully, a later forced cleanup (for example from an observed cleanup callback) will attempt client.disconnect() again and can throw or cause extra network work. force should only ensure the handle remains tracked for teardown and retry after failures, not reopen a closed handle.
      if (force) {
        closed = false;
        clientHandles.add(handle);
      }
      if (closed) {

src/extensions/distributed/redis-runtime-provider.ts:288

  • captureAsyncMethods builds wrappers with Promise.resolve(Reflect.apply(...)). If the underlying method throws synchronously, the wrapper throws before returning a Promise, breaking the declared Promise<unknown> contract. Wrap the call in Promise.resolve().then(...) so sync throws become promise rejections consistently.

This issue also appears on line 411 of the same file.

@kwakayama
kwakayama added this pull request to the merge queue Aug 2, 2026
Merged via the queue into main with commit 3f02b72 Aug 2, 2026
32 checks passed
@kwakayama
kwakayama deleted the codex/redis-extension-train-20260801 branch August 2, 2026 07:44
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.

3 participants