Skip to content

feat: idle eviction for pooled resident adapters - #130

Merged
AhmadRAbuhussein merged 1 commit into
mainfrom
feat/resident-idle-eviction
Sep 8, 2026
Merged

feat: idle eviction for pooled resident adapters#130
AhmadRAbuhussein merged 1 commit into
mainfrom
feat/resident-idle-eviction

Conversation

@mmalkhatib

Copy link
Copy Markdown
Contributor

Summary

  • Pooled resident instances now support idle eviction: an instance nobody rents for ResidentOptions.IdleTimeout (default off), or a per-adapter IdleTimeoutSeconds metadata override, is retired by the host's existing supervisor sweep — so a warm pool shrinks back down instead of holding its peak size forever.
  • Exclusive instances (broker connections, etc.) are never affected — only pooled adapters are swept.
  • Exposes IdleSince on ResidentAdapterInstance/InstanceHealth so the state is observable.
  • Wires a live demo into SW.Serverless.SampleWeb: the Carrier page overrides the idle timeout per-adapter, and the Adapters dashboard shows "Idle for" and lets you watch an instance disappear once evicted.

Test plan

  • dotnet build SW.Serverless.sln
  • dotnet test SW.Serverless.UnitTests — 80/80 passing, including new IdleEvictionTests covering: host-default-with-no-override, explicit-zero-override-falls-back-to-default (not disabled), renting-again-cancels-eviction, exclusive-instances-never-evicted, partial-eviction-with-multiple-idle-instances, and IdleTimeout = TimeSpan.Zero disabling eviction entirely.
  • SW.Serverless.SampleWeb builds; Carrier + Adapters pages updated to demo the feature manually.

🤖 Generated with Claude Code

A pooled instance nobody rents for ResidentOptions.IdleTimeout (or a
per-adapter "IdleTimeoutSeconds" override) is now retired by the
supervisor's existing sweep, so a warm pool shrinks back down instead
of holding its peak size forever. Off by default. Exclusive instances
are never affected.

Adds IdleSince to ResidentAdapterInstance/InstanceHealth so the state
is observable, and wires a demo into SW.Serverless.SampleWeb (Carrier
page + Adapters dashboard) to show it live.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Sep 8, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: simplify9/coderabbit/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 991b7262-8de0-459f-a187-e73a8123e094

📥 Commits

Reviewing files that changed from the base of the PR and between 909c600 and 15492db.

📒 Files selected for processing (10)
  • SW.Serverless.SampleWeb/Components/Pages/AdapterDashboard.razor
  • SW.Serverless.SampleWeb/Components/Pages/CarrierWork.razor
  • SW.Serverless.SampleWeb/Program.cs
  • SW.Serverless.UnitTests/CarrierAdapterTests.cs
  • SW.Serverless.UnitTests/IdleEvictionTests.cs
  • SW.Serverless/Resident/AdapterPool.cs
  • SW.Serverless/Resident/InstanceHealth.cs
  • SW.Serverless/Resident/ResidentAdapterHost.cs
  • SW.Serverless/Resident/ResidentAdapterInstance.cs
  • SW.Serverless/Resident/ResidentOptions.cs

📝 Summary

Summary

Adds idle eviction for pooled resident adapters.

  • Tracks IdleSince on ResidentAdapterInstance and InstanceHealth.
  • Evicts pooled instances during supervisor sweeps after ResidentOptions.IdleTimeout.
  • Supports per-adapter IdleTimeoutSeconds overrides.
  • Keeps eviction disabled by default.
  • Excludes exclusive instances.
  • Updates SampleWeb to demonstrate timeout overrides and idle status.

Risk

risk:medium. The change affects concurrent pool checkout, return, reset, and eviction behavior.

Security-sensitive areas

No authentication, authorization, or secret-handling code changed. The lifecycle changes affect resource retention and process retirement.

Test coverage

Adds coverage for default and per-adapter timeouts, re-renting, exclusive instances, partial eviction, and disabled eviction. The reported test run passed 80 unit tests. Solution and SampleWeb builds passed.

Operational concerns

Eviction remains disabled when IdleTimeout is TimeSpan.Zero. Deployments that enable it should validate timeout values against workload startup cost and pool capacity. No migration is required. Rollback removes eviction behavior; existing pooled adapter operation remains available.

Walkthrough

The change adds idle tracking and timeout-based eviction for pooled resident adapter instances. Supervisor cycles remove stale pooled instances, while exclusive instances remain active. Health output and sample pages expose idle state. Tests cover timeout inheritance, overrides, re-renting, staggered pools, and disabled eviction.

Changes

Pooled adapter idle eviction

Layer / File(s) Summary
Idle state and timeout contracts
SW.Serverless/Resident/ResidentOptions.cs, SW.Serverless/Resident/ResidentAdapterInstance.cs, SW.Serverless/Resident/InstanceHealth.cs, SW.Serverless/Resident/AdapterPool.cs
Adds ResidentOptions.IdleTimeout, IdleSince state, health reporting, timeout resolution, and timestamp updates during rent and return operations.
Eviction and supervisor execution
SW.Serverless/Resident/AdapterPool.cs, SW.Serverless/Resident/ResidentAdapterHost.cs
Adds EvictIdleAsync() and runs it for all pools during supervisor cycles.
Idle eviction validation
SW.Serverless.UnitTests/IdleEvictionTests.cs, SW.Serverless.UnitTests/CarrierAdapterTests.cs
Tests default and per-adapter timeouts, re-renting, exclusive instances, staggered idle instances, disabled eviction, and process removal.
Sample configuration and dashboard display
SW.Serverless.SampleWeb/Program.cs, SW.Serverless.SampleWeb/Components/Pages/CarrierWork.razor, SW.Serverless.SampleWeb/Components/Pages/AdapterDashboard.razor
Configures host and adapter timeout values, documents idle eviction, and displays elapsed idle time.

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Feature

Suggested labels: risk:medium

Suggested reviewers: samerzughul

Warning

Tools execution failed with the following error:

Failed to run tools: 13 INTERNAL: Received RST_STREAM with code 2 (Internal server error)


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@AhmadRAbuhussein
AhmadRAbuhussein merged commit cfc8da3 into main Sep 8, 2026
4 of 5 checks passed
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.

2 participants