In arcp-runtime/src/main/java/dev/arcp/runtime/idempotency/IdempotencyStore.java the claim method around line 43 calls prune() on line 45 as its first action. prune() in turn iterates entries.values() and calls removeIf with a clock-based check on every entry. With the default TTL of 24 hours the entry set can hold tens of thousands of records under sustained load, and every new submit pays the O(n) walk. The pruning logic itself is correct; the call frequency is wrong. Most production deployments prune expired entries on a scheduled cadence (every minute, every 5 minutes) rather than synchronously per write.\n\nFix prompt: In arcp-runtime/src/main/java/dev/arcp/runtime/idempotency/IdempotencyStore.java replace the in-line prune call with a scheduled task. Add a constructor parameter ScheduledExecutorService scheduler (or accept a Clock-driven "prune now" hook), and schedule prune() to run every minute (or at a frequency configurable via Builder; one minute is a reasonable default for a 24-hour TTL). The store should expose a public prune() method for tests to call deterministically. Wire the scheduling from arcp-runtime/src/main/java/dev/arcp/runtime/ArcpRuntime.java where IdempotencyStore is constructed around line 85 — pass the runtime's existing scheduler. Add a unit test that pre-populates 10 000 entries, advances a test Clock past the TTL, calls prune explicitly, and asserts the entry set is empty without ever paying the cost in claim(). Confirm existing IdempotencyStore tests still pass with no scheduling involved (call prune directly in test setup if needed).
In arcp-runtime/src/main/java/dev/arcp/runtime/idempotency/IdempotencyStore.java the claim method around line 43 calls prune() on line 45 as its first action. prune() in turn iterates entries.values() and calls removeIf with a clock-based check on every entry. With the default TTL of 24 hours the entry set can hold tens of thousands of records under sustained load, and every new submit pays the O(n) walk. The pruning logic itself is correct; the call frequency is wrong. Most production deployments prune expired entries on a scheduled cadence (every minute, every 5 minutes) rather than synchronously per write.\n\nFix prompt: In arcp-runtime/src/main/java/dev/arcp/runtime/idempotency/IdempotencyStore.java replace the in-line prune call with a scheduled task. Add a constructor parameter
ScheduledExecutorService scheduler(or accept a Clock-driven "prune now" hook), and scheduleprune()to run every minute (or at a frequency configurable via Builder; one minute is a reasonable default for a 24-hour TTL). The store should expose a publicprune()method for tests to call deterministically. Wire the scheduling from arcp-runtime/src/main/java/dev/arcp/runtime/ArcpRuntime.java where IdempotencyStore is constructed around line 85 — pass the runtime's existing scheduler. Add a unit test that pre-populates 10 000 entries, advances a test Clock past the TTL, calls prune explicitly, and asserts the entry set is empty without ever paying the cost in claim(). Confirm existing IdempotencyStore tests still pass with no scheduling involved (call prune directly in test setup if needed).