feat(inference): KeepAlivePolicy idle auto-unload + UnloadReason.idleTimeout#1886
Merged
Conversation
…Timeout Adds an opt-in keep-alive TTL policy that automatically unloads a resident model after a configurable idle period, mirroring Ollama's keep_alive UX. Any generation activity resets the idle clock; the watch task is cancelled on explicit unload and when the policy reverts to .never at runtime. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
d023947 to
45bfcf8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
KeepAlivePolicystruct (Sources/ManifoldInference/KeepAlivePolicy.swift) with anidleTimeout: TimeInterval?and a.neverstatic defaultUnloadReason.idleTimeoutcase toManifoldHardware/MemoryPressureEvent.swift; entry added to.github/api-breakage-allowlist.txt(no#comments per convention)lastActivityAt: DateandidleDuration: TimeIntervaltoGenerationQueue; stamped each time a request begins drainingTask { }infrastructure toModelLifecycleCoordinator— armed on commit, cancelled on unload or policy change; reads idle duration via injected closure to avoid retain cyclespublic var keepAlivePolicy: KeepAlivePolicyonInferenceServiceunloadRequestHandlerandidleDurationProviderclosures inwireGenerationContext()so the coordinator can fireunloadModel(reason: .idleTimeout)without holding a strong service referenceKeepAlivePolicyTests.swiftcovering: default-is-never, equatable, no-auto-unload with .never, fires after timeout, activity resets clock, policy disabled at runtime, explicit-unload no double-fireCloses #1881
Test plan
swift test --filter KeepAlivePolicyTests— all 7 passswift build --build-tests --traits Server,Macros— no exhaustiveness gaps (exit 0)🤖 Generated with Claude Code