Skip to content

Add Redis coordination and idempotency - #197

Merged
chullybun merged 3 commits into
mainfrom
redis-coordination-idempotency
Nov 19, 2026
Merged

chullybun merged 3 commits into
mainfrom
redis-coordination-idempotency

Conversation

@chullybun

Copy link
Copy Markdown
Collaborator

Summary

  • Replace hybrid-cache synchronization with renewable owner-checked leases and Redis or in-memory coordination.
  • Add retained idempotency outcomes and integrate them with ASP.NET Core, Azure Functions, samples, and templates.
  • Document migration, Redis failure boundaries, and coordinated rollout requirements.

Breaking changes

Replace the HybridCache synchronization and idempotency registrations with a coordination provider and AddIdempotencyProvider(). Existing HybridCache receipts are not migrated; old and new replicas must not process the same protected operations concurrently.

Validation

  • Redis coordination: 32 tests passed against Redis, including cross-process coverage.
  • Core coordination: 9 focused tests passed.
  • ASP.NET Core idempotency: 30 focused tests passed.
  • Eight relevant template scenarios passed; the broader template validation run was interrupted due to disk space.

Closes #196

Replace hybrid-cache synchronization with renewable owner-checked leases and retained idempotency outcomes.

Co-authored-by: Copilot App <[email protected]>
Signed-off-by: Eric Sibly <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 19, 2026 00:33

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.

🟡 Changes recommended

When idempotency is optional and no key is supplied, the invocation cancellation token is dropped, preventing later cancellation from reaching the application callback and surrounding checks.

1 open issue
What changed in this PR

This PR addresses #196 by separating coordination from ordinary caching. It replaces HybridCache-based synchronization with renewable leases and adds retained idempotency outcomes for CoreEx hosts.

Changes:

  • Introduces coordination and idempotency contracts, Redis operations, and explicit in-memory registration.
  • Updates HTTP integration, Functions cancellation handling, client key formatting, samples, and templates.
  • Adds regression coverage and documents migration, coordinated rollout, and failure boundaries.
File Description
tests/​CoreEx.Test.Unit/​Http/​HttpRequestMessageExtensionsTests.cs Tests quoted and escaped idempotency keys.
tests/​CoreEx.Test.Unit/​Http/​HttpRequestBuilderTests.cs Tests generated keys and explicit-header preservation.
tests/​CoreEx.Test.Unit/​Hosting/​Synchronization/​CoordinationLeaseTests.cs Covers ownership loss and cleanup behavior.
tests/​CoreEx.Test.Unit/​GlobalUsing.cs Adds coordination test imports.
tests/​CoreEx.Redis.Test.Worker/​Program.cs Provides a cross-process coordination worker.
tests/​CoreEx.Redis.Test.Worker/​GlobalUsing.cs Adds worker imports.
tests/​CoreEx.Redis.Test.Worker/​CoreEx.Redis.Test.Worker.csproj Defines the non-packable test worker.
tests/​CoreEx.Caching.Redis.Test.Unit/​HybridCacheSynchronizerTests.cs Removes obsolete synchronization tests.
tests/​CoreEx.Caching.Redis.Test.Unit/​GlobalUsing.cs Adds shared test imports.
tests/​CoreEx.Caching.Redis.Test.Unit/​EntryPoint.cs Registers Redis coordination for tests.
tests/​CoreEx.Caching.Redis.Test.Unit/​CoreEx.Caching.Redis.Test.Unit.csproj References Redis coordination and its worker.
tests/​CoreEx.Azure.Functions.TestApp/​Program.cs Uses in-memory idempotency storage.
tests/​CoreEx.Azure.Functions.Test.Unit/​FunctionsHttpIdempotencyTests.cs Asserts uncertain outcomes block automatic retries.
tests/​CoreEx.AspNetCore.Test.Unit/​GlobalUsing.cs Adds HTTP idempotency test imports.
tests/​CoreEx.AspNetCore.Test.Api/​Program.cs Migrates test-host idempotency registration.
src/​CoreEx/​Idempotency/​IIdempotencyStore.cs Defines atomic attempts and reconciliation.
src/​CoreEx/​Idempotency/​IIdempotencyAttempt.cs Defines owned terminal-response completion.
src/​CoreEx/​Idempotency/​IdempotencyOutcome.cs Defines processing and replay decisions.
src/​CoreEx/​Idempotency/​IdempotencyBeginResult.cs Represents a coherent attempt result.
src/​CoreEx/​Idempotency/​IdempotencyAttempt.cs Implements lease-backed attempt lifetime.
src/​CoreEx/​Http/​README.md Documents quoted key serialization.
src/​CoreEx/​Http/​IdempotencyKeyHeader.cs Validates and formats logical keys.
src/​CoreEx/​Http/​IdempotencyKeyHandler.cs Quotes generated outgoing keys.
src/​CoreEx/​Hosting/​SynchronizedTimerHostedServiceBase.cs Links execution to lease ownership.
src/​CoreEx/​Hosting/​Synchronization/​ISynchronizer.cs Removes the old enter/exit contract.
src/​CoreEx/​Hosting/​Synchronization/​HybridCacheSynchronizer.cs Removes cache-based synchronization.
src/​CoreEx/​GlobalUsing.cs Switches to coordination imports.
src/​CoreEx/​Extensions.HttpRequestMessage.cs Formats explicitly supplied idempotency keys.
src/​CoreEx/​CoreExExtensions.DependencyInjection.cs Adds in-memory coordination registration.
src/​CoreEx/​Coordination/​SynchronizerExtensions.cs Adds type-qualified lease acquisition.
src/​CoreEx/​Coordination/​ISynchronizer.cs Defines bounded lease acquisition.
src/​CoreEx/​Coordination/​ISynchronizationLease.cs Defines ownership loss and disposal.
src/​CoreEx/​Coordination/​InMemoryCoordinationState.cs Holds shared in-memory ownership records.
src/​CoreEx/​Coordination/​CoordinationOptions.cs Defines and validates ownership durations.
src/​CoreEx/​Caching/​README.md Separates caching from synchronization.
src/​CoreEx.Template/​README.md Updates packaged guide counts.
src/​CoreEx.Template/​CoreEx.Template.csproj Includes the Redis AI guide.
src/​CoreEx.Template/​content/​CoreEx.Subscribe/​src/​app-name.Subscribe/​Program.cs Registers Redis-backed idempotency.
src/​CoreEx.Template/​content/​CoreEx.Subscribe/​src/​app-name.Subscribe/​app-name.Subscribe.csproj Adds the Redis package reference.
src/​CoreEx.Template/​content/​CoreEx.Subscribe/​src/​app-name.Subscribe/​AGENTS.md Documents separate coordination storage.
src/​CoreEx.Template/​content/​CoreEx.Core/​_Directory.Packages.props Pins the generated Redis package version.
src/​CoreEx.Template/​content/​CoreEx.Api/​src/​app-name.Api/​Program.cs Registers Redis-backed idempotency.
src/​CoreEx.Template/​content/​CoreEx.Api/​src/​app-name.Api/​app-name.Api.csproj Adds the Redis package reference.
src/​CoreEx.Template/​content/​CoreEx.Api/​src/​app-name.Api/​AGENTS.md Documents registration and key scoping.
src/​CoreEx.Redis/​Scripts/​LeaseRenew.lua Renews only the current owner's lease.
src/​CoreEx.Redis/​Scripts/​LeaseRelease.lua Releases only the current owner's lease.
src/​CoreEx.Redis/​Scripts/​IdempotencyTransition.lua Applies owner-checked state transitions.
src/​CoreEx.Redis/​Scripts/​IdempotencyResolve.lua Reconciles uncertain attempts by revision.
src/​CoreEx.Redis/​Scripts/​IdempotencyBegin.lua Atomically claims or reads an outcome.
src/​CoreEx.Redis/​GlobalUsing.cs Defines Redis package imports.
src/​CoreEx.Redis/​CoreExRedisExtensions.cs Registers scoped Redis providers.
src/​CoreEx.Redis/​CoreEx.Redis.csproj Defines the Redis package and embedded scripts.
src/​CoreEx.Redis/​AGENTS.md Documents usage and guarantee limits.
src/​CoreEx.Caching.FusionCache/​AGENTS.md Removes cache-backed idempotency guidance.
src/​CoreEx.Azure.Functions/​FunctionsHttpExtensions.cs Passes operation cancellation through idempotency.
src/​CoreEx.Azure.Functions/​AGENTS.md Documents storage and uncertain outcomes.
src/​CoreEx.AspNetCore/​OpenApiOptions.cs Describes structured-field key syntax.
src/​CoreEx.AspNetCore/​Idempotency/​IIdempotencyProvider.cs Adds invocation cancellation to the contract.
src/​CoreEx.AspNetCore/​Idempotency/​IdempotencyKeyMiddleware.cs Forwards request cancellation.
src/​CoreEx.AspNetCore/​GlobalUsing.cs Updates HTTP integration imports.
src/​CoreEx.AspNetCore/​CoreExAspNetCoreExtensions.DependencyInjection.cs Registers store-backed HTTP idempotency.
src/​CoreEx.AspNetCore/​AGENTS.md Documents explicit provider registration.
src/​CoreEx.AspNetCore.NSwag/​README.md Explains quoted keys and validation modes.
src/​CoreEx.AspNetCore.NSwag/​NSwagOpenApiOperationProcessor.cs Removes wire-length constraints from key schemas.
samples/​src/​Contoso.Shopping.Subscribe/​Program.cs Migrates to Redis coordination.
samples/​src/​Contoso.Shopping.Subscribe/​Contoso.Shopping.Subscribe.csproj References CoreEx.Redis.
samples/​src/​Contoso.Shopping.Api/​Program.cs Migrates to Redis coordination.
samples/​src/​Contoso.Shopping.Api/​Contoso.Shopping.Api.csproj References CoreEx.Redis.
samples/​src/​Contoso.Products.Subscribe/​Program.cs Migrates to Redis coordination.
samples/​src/​Contoso.Products.Subscribe/​Contoso.Products.Subscribe.csproj References CoreEx.Redis.
samples/​src/​Contoso.Products.Api/​Program.cs Migrates to Redis coordination.
samples/​src/​Contoso.Products.Api/​Contoso.Products.Api.csproj References CoreEx.Redis.
samples/​src/​Contoso.Orders.Api/​Program.cs Migrates to Redis coordination.
samples/​src/​Contoso.Orders.Api/​Contoso.Orders.Api.csproj References CoreEx.Redis.
samples/​src/​Contoso.Customers.Api/​Program.cs Migrates to Redis coordination.
samples/​src/​Contoso.Customers.Api/​Contoso.Customers.Api.csproj References CoreEx.Redis.
samples/​docs/​hosts-layer.md Explains host storage and replay behavior.
README.md Introduces coordination and the Redis package.
nuget-publish.ps1 Includes Redis in package publishing.
docs/​capabilities.md Clarifies bounded idempotency guarantees.
Directory.Packages.props Pins StackExchange.Redis.
CoreEx.slnx Includes Redis and its test worker.
CoreEx.Core.slnf Includes Redis projects in the solution filter.
CHANGELOG.md Records features and breaking migration steps.
AGENTS.md Adds Redis to the package catalog.
.github/​skills/​coreex-functions/​SKILL.md Updates Functions idempotency guidance.
.github/​skills/​coreex-functions/​references/​workflow.md Documents explicit storage and rollout limits.
.github/​skills/​coreex-functions/​references/​patterns.md Updates replay and registration patterns.
.github/​skills/​coreex-docs-sync/​README.md Updates the bundled guide count.
.github/​instructions/​coreex-functions.instructions.md Defines Functions coordination guidance.
.github/​instructions/​coreex-event-subscribers.instructions.md Updates subscriber registration examples.
.github/​coreex-ai-workflows.md Updates package-guide coverage.
.github/​copilot-instructions.md Separates ordinary caching from idempotency.
.github/​agents/​README.md Updates documentation-cache inventory.
.github/​agents/​coreex-expert.agent.md Adds Redis guidance and clarifies FusionCache scope.

Review effort: Balanced

Co-authored-by: Copilot App <[email protected]>
Signed-off-by: Eric Sibly <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 19, 2026 01:07

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.

🟡 Changes recommended

Recreated records reset their ETags to 1, allowing stale snapshots to overwrite or delete replacement records in both Redis and in-memory providers.

1 open issue
1 resolved since last review

Review effort: Balanced

Comment thread src/CoreEx.Redis/Scripts/WorkCreate.lua Resolved
Co-authored-by: Copilot App <[email protected]>
Signed-off-by: Eric Sibly <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 19, 2026 16:28

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.

🔵 Needs a closer look

Human judgment is needed to weigh an unpublished, low-severity logging-convention concern in the new cleanup path.

1 open issue

Review effort: Balanced

@chullybun
chullybun merged commit ea86e91 into main Nov 19, 2026
19 checks passed
@chullybun
chullybun deleted the redis-coordination-idempotency branch November 19, 2026 17:03
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.

HybridCacheSynchronizer cannot guarantee distributed exclusion; define atomic lease capabilities and ISynchronizer semantics

2 participants