Skip to content

[Duplicate Code] Repeated filtered model-alias assembly in proxy server #8816

Closed

Description

@github-actions

Duplicate Code Opportunity

Summary

  • Pattern: containers/api-proxy/server.js builds the same configuredProviders + filteredAliases structure twice: once for buildModelsJson() and again for writeModelsJson().
  • Locations: containers/api-proxy/server.js lines 167-194.
  • Impact: Removes one duplicated alias-filtering block from the security-sensitive proxy startup/management path and keeps model metadata generation consistent.

Evidence

Block A — buildModelsJson()

function buildModelsJson() {
  const configuredProviders = getConfiguredModelCacheKeys();
  const filteredAliases = MODEL_ALIASES ? {
    models: filterResolvableAliases(
      MODEL_ALIASES.models,
      filterAvailableModelsToConfiguredProviders(cachedModels, configuredProviders),
      configuredProviders,
    ),
  } : null;
  return _buildModelsJson(registeredAdapters, cachedModels, filteredAliases, getRuntimeCatalogSnapshot());
}

Block B — writeModelsJson()

function writeModelsJson(logDir) {
  const configuredProviders = getConfiguredModelCacheKeys();
  const filteredAliases = MODEL_ALIASES ? {
    models: filterResolvableAliases(
      MODEL_ALIASES.models,
      filterAvailableModelsToConfiguredProviders(cachedModels, configuredProviders),
      configuredProviders,
    ),
  } : null;
  const modelsJson = _buildModelsJson(
    registeredAdapters,
    cachedModels,
    filteredAliases,
    getRuntimeCatalogSnapshot(),
  );
  return _writeModelsJson(registeredAdapters, cachedModels, filteredAliases, logDir, modelsJson);
}

Suggested Refactoring

Extract a shared helper that returns the filtered alias snapshot once, then have both callers reuse it. For example:

  • getFilteredModelAliases() for the configuredProviders / filteredAliases assembly
  • buildModelsSnapshot() to produce the shared JSON payload used by both buildModelsJson() and writeModelsJson()

This keeps alias filtering and model snapshot generation aligned and reduces the chance of drift if the filtering rules change.

Affected Files

  • containers/api-proxy/server.js — lines 167-194

Effort Estimate

Low


Detected by Duplicate Code Detector workflow. Run date: 2026-09-20

Generated by Duplicate Code Detector · copilot · gpt50mini · 5.79 AIC · ⊞ 21K · ◷

  • expires on Oct 20, 2026, 9:42 PM UTC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions