Skip to content

feat(inference): KeepAlivePolicy idle auto-unload + UnloadReason.idleTimeout#1886

Merged
roryford merged 1 commit into
mainfrom
feat/obs-keep-alive-policy
Jun 15, 2026
Merged

feat(inference): KeepAlivePolicy idle auto-unload + UnloadReason.idleTimeout#1886
roryford merged 1 commit into
mainfrom
feat/obs-keep-alive-policy

Conversation

@roryford

Copy link
Copy Markdown
Owner

Summary

  • Adds KeepAlivePolicy struct (Sources/ManifoldInference/KeepAlivePolicy.swift) with an idleTimeout: TimeInterval? and a .never static default
  • Adds UnloadReason.idleTimeout case to ManifoldHardware/MemoryPressureEvent.swift; entry added to .github/api-breakage-allowlist.txt (no # comments per convention)
  • Adds lastActivityAt: Date and idleDuration: TimeInterval to GenerationQueue; stamped each time a request begins draining
  • Adds idle watch Task { } infrastructure to ModelLifecycleCoordinator — armed on commit, cancelled on unload or policy change; reads idle duration via injected closure to avoid retain cycles
  • Exposes public var keepAlivePolicy: KeepAlivePolicy on InferenceService
  • Wires unloadRequestHandler and idleDurationProvider closures in wireGenerationContext() so the coordinator can fire unloadModel(reason: .idleTimeout) without holding a strong service reference
  • 7 XCTest cases in KeepAlivePolicyTests.swift covering: default-is-never, equatable, no-auto-unload with .never, fires after timeout, activity resets clock, policy disabled at runtime, explicit-unload no double-fire

Closes #1881

Test plan

  • swift test --filter KeepAlivePolicyTests — all 7 pass
  • swift build --build-tests --traits Server,Macros — no exhaustiveness gaps (exit 0)
  • CI green on PR push

🤖 Generated with Claude Code

…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>
@roryford roryford force-pushed the feat/obs-keep-alive-policy branch from d023947 to 45bfcf8 Compare June 15, 2026 10:43
@roryford roryford merged commit 5ca06aa into main Jun 15, 2026
11 checks passed
@roryford roryford deleted the feat/obs-keep-alive-policy branch June 15, 2026 11:23
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.

Optional idle keep-alive / auto-unload policy

1 participant