Skip to content

feat: Fleet Intelligence & Model Lifecycle Management (F19/F20) - #201

Merged
leocamello merged 6 commits into
mainfrom
022-fleet-intelligence-model-lifecycle
Feb 19, 2026
Merged

leocamello merged 6 commits into
mainfrom
022-fleet-intelligence-model-lifecycle

Conversation

@leocamello

@leocamello leocamello commented Feb 19, 2026 •

Copy link
Copy Markdown
Owner

Summary

Ship Model Lifecycle Management (F20) and Pre-warming & Fleet Intelligence (F19) — RFC-001 Phase 3.

Enables Nexus to control model loading/unloading across the fleet and predict demand for proactive model placement.

What Changed

New API Endpoints

  • POST /v1/models/load — Load model on specific backend
  • DELETE /v1/models/{id} — Unload model from specific backend
  • POST /v1/models/migrate — Coordinated migration (load on target, operator unloads source)
  • GET /v1/fleet/recommendations — Pre-warming recommendations based on request patterns

New Modules

  • src/api/lifecycle.rs — HTTP handlers with X-Nexus-Lifecycle-Status headers
  • src/routing/reconciler/fleet.rs — Background pattern analysis, 15 unit tests
  • src/routing/reconciler/lifecycle.rs — Routing filter for loading backends, 11 unit tests
  • src/config/lifecycle.rs / src/config/fleet.rs — Configuration types

Ollama NII Implementation

  • load_model() → POST /api/pull
  • unload_model() → POST /api/generate (keep_alive=0)
  • resource_usage() → GET /api/ps (VRAM tracking)

Key Design Decisions

  • FleetReconciler: Background analysis task (not per-request pipeline) — avoids latency impact
  • LifecycleReconciler: Early pipeline filter before PrivacyReconciler
  • Migration: Source preserved in routing until operator manually unloads
  • Fleet intelligence: Suggestion-first — recommends, never auto-loads

Verification

  • Tests: 1287 passed, 0 failed (1272 existing + 15 new)
  • Clippy: 0 warnings
  • Fmt: Clean
  • Benchmarks: Routing latency 6-160µs (well under 1ms constitution target)
  • Verification checklist: 143 pass, 67 N/A, 0 unchecked

Red Team Review

Verdict: [PASS] (after fixes)

Initial review found 4 issues, all fixed in commit 6cda049:

# Severity Issue Fix
1 Critical Memory leak — record_request() grew unbounded when fleet disabled Added if !self.config.enabled { return; } guard
2 High TOCTOU race — update_operation() set after load_model() Moved operation tracking before agent call; clear on failure
3 Medium VRAM heuristic dead code — Ollama returns None for total VRAM Made threshold configurable via vram_heuristic_max_gb
4 Medium Migration rollback left orphaned load on target Set both operations before load_model(); rollback both on failure

Re-review confirmed all fixes correct, no new issues introduced.

Configuration

[lifecycle]
timeout_ms = 300000
vram_headroom_percent = 20
vram_heuristic_max_gb = 16

[fleet]
enabled = false
min_sample_days = 3
min_request_count = 10
analysis_interval_seconds = 3600
max_recommendations = 10

Spec & Docs

  • Spec: specs/022-fleet-intelligence-model-lifecycle/
  • API docs: docs/api/lifecycle.md
  • Walkthrough: specs/022-fleet-intelligence-model-lifecycle/walkthrough.md

Closes #194
Closes #195
Closes #196
Closes #197
Closes #198
Closes #199
Closes #200

leocamello and others added 3 commits February 19, 2026 00:48
Implement RFC-001 Phase 3: Fleet Intelligence and Model Lifecycle Management.

Model Lifecycle (F20):
- POST /v1/models/load — trigger model load with VRAM validation
- DELETE /v1/models/{id} — graceful unload with active request protection
- POST /v1/models/migrate — coordinated migration (zero request drops)
- LifecycleReconciler filters loading backends from routing pipeline
- OllamaAgent: load_model (POST /api/pull), unload_model (keep_alive=0),
  resource_usage (GET /api/ps)
- Operation tracking, timeout detection, health checker integration

Fleet Intelligence (F19):
- FleetReconciler: background pattern analysis (not in hot path)
- Request history tracking per model (DashMap, 30-day retention)
- Time-of-day pattern detection with peak-to-average ratio analysis
- Model popularity trend analysis (7-day window comparison)
- Confidence scoring (0.0-1.0) based on pattern strength and sample size
- VRAM headroom checking, hot model protection
- GET /v1/fleet/recommendations — advisory-only recommendations
- Background analysis loop with configurable interval
- Suggestion-first: never auto-executes, operator approval required

Configuration:
- [lifecycle] section: timeout_ms, vram_headroom_percent, vram_buffer_percent
- [fleet] section: enabled, min_sample_days, min_request_count,
  analysis_interval_seconds, max_recommendations

Tests: 15 new fleet intelligence unit tests, 22+ lifecycle tests
All 1287 tests pass, clippy clean.

Closes #194
Closes #195
Closes #196
Closes #197
Closes #198
Closes #199

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- T089a: Add X-Nexus-Lifecycle-Status and X-Nexus-Lifecycle-Operation
  response headers to all lifecycle API endpoints
- T089b: Add Retry-After header to 503 responses when all backends are
  in Loading state (LifecycleReconciler rejections)
- T082/T083: Add lifecycle API documentation (docs/api/lifecycle.md)
- T091: Update README.md with Fleet Intelligence feature highlights
- T084: Validated routing latency <1ms via benchmarks (6-160µs)
- T087: All 1287 tests pass, clippy clean

Closes #200

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…19/F20)

- Fill out verification.md: 143 pass, 67 N/A, 0 unchecked
- Create walkthrough.md with architecture, decisions, test summary
- Fix 2 unwrap() calls in fleet.rs → let-else pattern (safer)
- Update spec.md status to Implemented
- Check off verified performance criteria in tasks.md

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@leocamello leocamello added enhancement New feature or request v0.5 v0.5 Fleet Intelligence & Orchestration milestone F19 F19: Pre-warming & Fleet Intelligence F20 F20: Model Lifecycle Management labels Feb 19, 2026
leocamello and others added 3 commits February 19, 2026 01:52
- Fix memory leak: record_request() skips when fleet disabled (Issue 1)
- Fix TOCTOU race: set operation BEFORE load_model/migrate (Issue 2, 4)
- Fix VRAM heuristic: make threshold configurable via vram_heuristic_max_gb (Issue 3)
- Migration rollback: clear both operations on load_model failure (Issue 4)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…9/F20

- roadmap.md: Mark F19/F20/Phase 3 as Complete with spec links
- docs/api/rest.md: Add lifecycle endpoints to quick reference
- copilot-instructions.md: Add lifecycle routes, reconciler modules, update v0.5 status

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@leocamello
leocamello merged commit c0470e6 into main Feb 19, 2026
9 checks passed
@leocamello
leocamello deleted the 022-fleet-intelligence-model-lifecycle branch February 19, 2026 02:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request F19 F19: Pre-warming & Fleet Intelligence F20 F20: Model Lifecycle Management v0.5 v0.5 Fleet Intelligence & Orchestration milestone

Projects

None yet

1 participant