proxy,proxy/config: add global TTL feature - #554
Conversation
Add a new configuration parameter globalTTL that all models will inherit. The default value is 0 which matches the currently functionality to never automatically unload a model. The model.ttl's default has changed to -1, which means use the global TTL value. Any model.ttl >=0 is now value with 0 meaning never unload. This allows a model to override a globalTTL > 0 and be configured to never unload. Fixes #459 Closes #512
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review infoConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughAdds a top-level Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@config.example.yaml`:
- Around line 188-193: Update the TTL documentation comments for the "ttl" field
so they are consistent: state that -1 => inherit globalTTL (use the global TTL
value), 0 => never unload, and >0 => unload after N seconds; remove the
contradictory "default: -1 (never unload)" and the incorrect "ttl must be >= 0"
line and ensure the remaining bullets reference the "ttl" key and "globalTTL"
clearly (e.g., "ttl: -1 inherits globalTTL; ttl: 0 never unloads; ttl: N (>0)
unloads after N seconds").
In `@proxy/config/config.go`:
- Around line 264-267: LoadConfigFromReader currently normalizes
MODEL_CONFIG_DEFAULT_TTL but allows invalid negative TTLs like -2; add
validation in LoadConfigFromReader after unmarshalling to reject any
modelConfig.UnloadAfter < -1 (return an error) and keep the existing
normalization that maps MODEL_CONFIG_DEFAULT_TTL to config.GlobalTTL; update the
code paths that construct/validate model configs (look for LoadConfigFromReader,
MODEL_CONFIG_DEFAULT_TTL, modelConfig.UnloadAfter, and config.GlobalTTL) so
invalid TTLs produce a clear error instead of being accepted.
ℹ️ Review info
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (7)
config-schema.jsonconfig.example.yamlproxy/config/config.goproxy/config/config_test.goproxy/config/model_config.goproxy/process_test.goproxy/proxymanager_test.go
| // set model TTL to globalTTL it is the default value | ||
| if modelConfig.UnloadAfter == MODEL_CONFIG_DEFAULT_TTL { | ||
| modelConfig.UnloadAfter = config.GlobalTTL | ||
| } |
There was a problem hiding this comment.
Reject invalid model ttl values below -1.
LoadConfigFromReader currently normalizes only -1, but accepts values like ttl: -2 without error. That violates the intended contract and can leak invalid runtime behavior.
💡 Suggested fix
// set model TTL to globalTTL it is the default value
+ if modelConfig.UnloadAfter < MODEL_CONFIG_DEFAULT_TTL {
+ return Config{}, fmt.Errorf("model %s: ttl must be >= -1", modelId)
+ }
if modelConfig.UnloadAfter == MODEL_CONFIG_DEFAULT_TTL {
modelConfig.UnloadAfter = config.GlobalTTL
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // set model TTL to globalTTL it is the default value | |
| if modelConfig.UnloadAfter == MODEL_CONFIG_DEFAULT_TTL { | |
| modelConfig.UnloadAfter = config.GlobalTTL | |
| } | |
| // set model TTL to globalTTL it is the default value | |
| if modelConfig.UnloadAfter < MODEL_CONFIG_DEFAULT_TTL { | |
| return Config{}, fmt.Errorf("model %s: ttl must be >= -1", modelId) | |
| } | |
| if modelConfig.UnloadAfter == MODEL_CONFIG_DEFAULT_TTL { | |
| modelConfig.UnloadAfter = config.GlobalTTL | |
| } |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@proxy/config/config.go` around lines 264 - 267, LoadConfigFromReader
currently normalizes MODEL_CONFIG_DEFAULT_TTL but allows invalid negative TTLs
like -2; add validation in LoadConfigFromReader after unmarshalling to reject
any modelConfig.UnloadAfter < -1 (return an error) and keep the existing
normalization that maps MODEL_CONFIG_DEFAULT_TTL to config.GlobalTTL; update the
code paths that construct/validate model configs (look for LoadConfigFromReader,
MODEL_CONFIG_DEFAULT_TTL, modelConfig.UnloadAfter, and config.GlobalTTL) so
invalid TTLs produce a clear error instead of being accepted.
Add a new configuration parameter globalTTL that all models will inherit. The default value is 0 which matches the currently functionality to never automatically unload a model. The model.ttl's default has changed to -1, which means use the global TTL value. Any model.ttl >=0 is now value with 0 meaning never unload. This allows a model to override a globalTTL > 0 and be configured to never unload. Fixes mostlygeek#459 Closes mostlygeek#512
Add a new configuration parameter globalTTL that all models will inherit. The default value is 0 which matches the currently functionality to never automatically unload a model. The model.ttl's default has changed to -1, which means use the global TTL value. Any model.ttl >=0 is now value with 0 meaning never unload. This allows a model to override a globalTTL > 0 and be configured to never unload. Fixes #459 Closes #512
Add a new configuration parameter globalTTL that all models will
inherit. The default value is 0 which matches the currently
functionality to never automatically unload a model.
The model.ttl's default has changed to -1, which means use the global
TTL value. Any model.ttl >=0 is now value with 0 meaning never unload.
This allows a model to override a globalTTL > 0 and be configured to
never unload.
Fixes #459
Closes #512