Skip to content

feat: refresh Prime Inference models from live API - #1928

Closed
sethkarten wants to merge 21 commits into
mainfrom
eng-5435-hosted-model-catalog
Closed

feat: refresh Prime Inference models from live API#1928
sethkarten wants to merge 21 commits into
mainfrom
eng-5435-hosted-model-catalog

Conversation

@sethkarten

@sethkarten sethkarten commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Part of RES-1239. Supersedes #1633.

What changed

  • Refreshes Prime Inference models directly from the public https://api.pinference.ai/api/v1/models endpoint.
  • Uses an authenticated request to discover team-authorized internal/*, dev/*, and deployment routes.
  • Applies live additions, removals, display names, pricing, context limits, modalities, and reasoning support without a Prime Agent release.
  • Keeps models for all other providers in the release-bundled catalog.
  • Loads a validated disk cache or the bundled Prime Inference list immediately, then refreshes the public list in the background.
  • Preserves local models.json definitions, provider/model overrides, extension providers, and bundled client compatibility metadata.
  • Removes the proposed R2 publication workflow, credentials, aggregate schema, and catalog URL configuration.

Safety and fallback behavior

  • Both public and authenticated requests are pinned to the Prime Inference HTTPS origin.
  • Live data cannot inject headers or change the provider, API type, or request URL.
  • Unknown models require complete specs; entries without them are skipped rather than assigned guessed limits or capabilities.
  • Existing models with missing specs retain bundled capabilities and limits while accepting live names and prices.
  • New models use conservative client compatibility defaults and do not send unconfirmed reasoning controls.
  • A response must retain at least 50% of the bundled Prime Inference model IDs. Severe truncation, invalid responses, timeouts, and oversized responses fall back to the last valid cache or bundled models.
  • Public responses exclude internal/*, dev/*, and deployment IDs containing :. Authenticated-only routes use a separate mode-0600 cache keyed by a credential/team fingerprint; they never enter the public cache.
  • PI_OFFLINE=1 skips network refreshes.

Current backend follow-up

The endpoint currently returns 120 public routes. It provides complete specs for 113. Five new Qwen routes and the currently authorized private routes cannot be added dynamically yet because specs is null. To remove the remaining client fallbacks and route-name heuristics, the endpoint should provide:

  • complete specs for every public and private route;
  • an explicit public/private visibility field;
  • supported reasoning controls or a thinking-level map;
  • an optional featured field if realtime promotion is desired.

Validation

  • npm run check
  • AI package: 343 passed, 720 skipped
  • Focused Prime Inference and registry tests: 123 passed
  • Live generation: 1,290 models across 32 providers; 120 public Prime Inference routes
  • Runtime live smoke test: 115 usable public Prime Inference models, five additions, zero unintended removals, zero private-route leaks, and zero transport/header changes

Note

Medium Risk
Runtime model pickers and context limits now follow live API data with merge/fallback rules; mistakes could hide models, leak private routes, or mis-state limits, though guards and tests target those cases.

Overview
Prime Inference model lists now update from the live /models endpoint instead of relying only on release bundles and ad hoc generator logic.

@earendil-works/pi-ai adds a shared parsePrimeInferenceModelCatalog parser (pricing, cache costs, specs, private-route detection) and moves generated catalog output through renderModelsFile so remote strings are JSON-escaped. The generate-models script hits the public endpoint without Prime CLI credentials, applies truncation/coverage guards, and still merges OpenRouter gaps where needed.

Prime Agent loads a validated prime-inference-models-cache.json (or bundled models) immediately, background-refreshes the public catalog, and merges live entries via buildPrimeInferenceModels / mergePrimeInferenceModels while keeping bundled compat and thinking maps. Authorized internal/*, dev/*, and deployment routes are built from authenticated catalog responses and persisted as full model records, not ID sets. PI_OFFLINE=1 skips network refresh; docs describe the new behavior.

Reviewed by Cursor Bugbot for commit 24d3413. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Refresh Prime Inference models from live API with validated cache fallback

  • Adds a shared catalog parser and builder for Prime Inference models, validating metadata like pricing, cache costs, context/output limits, and image support
  • The generator now fetches from the public /models endpoint without Prime CLI credentials, with a severe-truncation guard preserving the existing snapshot if live results are too sparse
  • The registry merges authorized private model objects with full metadata, excludes public IDs from private results, and reloads models after catalog or authorization changes
  • Public refreshes are backgrounded with cache fallback, request deduplication, atomic 0600 cache writes, and PI_OFFLINE=1 support
  • Risk: loadModels in model-registry.ts replaces bundled Prime Inference entries with live entries when supplied; existing tests for fixed maxTokens and context assertions are relaxed to allow clamped live metadata

Changes since #1928 opened

  • Changed ModelRegistry private Prime authorization flow to cache and restore full model metadata instead of model IDs, enabling immediate availability of authorized private deployments at startup without network access [24d3413]
  • Tightened validation in parsePrimeInferenceModelCatalog utility to require both input and output modalities to be arrays of strings, treating modalities as undefined when validation fails and only attaching full specs when all required fields are valid [24d3413]
  • Changed minimum coverage criteria in buildPrimeInferenceModels utility to measure coverage of bundled models rather than total model count [24d3413]
  • Added test coverage for cached authorized deployment metadata restoration without network access, retention of priced entries without complete specs, and coverage measurement against bundled models [24d3413]

Macroscope summarized e7e810c.

Comment thread packages/coding-agent/src/core/remote-model-catalog.ts Outdated
Comment thread packages/ai/scripts/model-catalog-format.ts Outdated
Comment thread packages/ai/scripts/model-catalog-format.ts Outdated
Comment thread packages/ai/scripts/model-catalog-format.ts Outdated
Comment thread packages/ai/scripts/model-catalog-format.ts Outdated
Comment thread packages/coding-agent/src/core/remote-model-catalog.ts Outdated
Comment thread packages/ai/scripts/model-catalog-format.ts Outdated
Comment thread packages/coding-agent/src/core/remote-model-catalog.ts Outdated
Comment thread packages/ai/src/model-catalog.ts Outdated
Comment thread packages/ai/src/model-catalog.ts Outdated

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread packages/ai/scripts/generate-models.ts Outdated
Comment thread packages/coding-agent/src/core/remote-model-catalog.ts Outdated
Comment thread packages/ai/src/model-compat-schema.ts Outdated
Comment thread packages/coding-agent/src/core/remote-model-catalog.ts Outdated
Comment thread packages/ai/src/model-catalog.ts Outdated
Comment thread packages/coding-agent/src/core/remote-model-catalog.ts Outdated
Comment thread packages/ai/src/model-compat-schema.ts Outdated
Comment thread .github/workflows/refresh-model-catalog.yml Outdated
Comment thread packages/coding-agent/src/core/remote-model-catalog.ts Outdated
Comment thread packages/coding-agent/src/core/remote-model-catalog.ts Outdated
Comment thread packages/coding-agent/src/core/remote-model-catalog.ts Outdated
Comment thread packages/coding-agent/src/core/remote-model-catalog.ts Outdated
Comment thread packages/coding-agent/src/core/remote-model-catalog.ts Outdated
@sethkarten sethkarten changed the title feat: refresh models from a hosted catalog feat: refresh Prime Inference models from live API Sep 6, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread packages/coding-agent/src/core/prime-inference-models.ts Outdated
Comment thread packages/coding-agent/src/core/prime-inference-model-catalog.ts Outdated
Comment thread packages/ai/.changes/prime-inference-model-catalog.md Outdated
Comment thread packages/ai/src/prime-inference-model-catalog.ts Outdated
@sethkarten
sethkarten requested a review from snimu September 6, 2026 00:28
@sethkarten

Copy link
Copy Markdown
Contributor Author

@snimu The PR has been fully redesigned around the live Prime Inference /api/v1/models endpoint. The R2 catalog workflow is removed, public refreshes are anonymous and nonblocking, team-private routes stay authorization-gated, and incomplete unknown routes are skipped. All 21 checks are green and all bot threads are resolved. Could you take the final approval review?

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit e7e810c. Configure here.

Comment thread packages/coding-agent/src/core/model-registry.ts Outdated
Comment thread packages/ai/src/prime-inference-model-catalog.ts
Comment thread packages/coding-agent/src/core/prime-inference-model-catalog.ts Outdated
this.authorizedPrivatePrimeInferenceModelIds = new Set(authorizedModels.map((model) => model.id));
this.authorizedPrivatePrimeInferenceTeamId = teamId;
this.writePrivatePrimeAuthorizationCache({ fingerprint, modelIds: authorizedIds, refreshedAt: Date.now() });
this.reloadModelsAfterCatalogChange();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium core/model-registry.ts:884

Dynamically authorized private deployments are rebuilt without the models.json provider or per-model overrides, so settings such as providers["prime-inference"].modelOverrides["vendor/model:deployment"] and baseUrl are silently ignored. reloadModelsAfterCatalogChange() calls loadModels(), which applies overrides in loadBuiltInModels() before appending authorizedPrivatePrimeInferenceModels; apply the same override pipeline to authorized models before adding them to this.models.

🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file @packages/coding-agent/src/core/model-registry.ts around line 884:

Dynamically authorized private deployments are rebuilt without the `models.json` provider or per-model overrides, so settings such as `providers["prime-inference"].modelOverrides["vendor/model:deployment"]` and `baseUrl` are silently ignored. `reloadModelsAfterCatalogChange()` calls `loadModels()`, which applies overrides in `loadBuiltInModels()` before appending `authorizedPrivatePrimeInferenceModels`; apply the same override pipeline to authorized models before adding them to `this.models`.

Evidence trail:
Commit 24d3413. `packages/coding-agent/src/core/model-registry.ts:511-514,537-576,578-600,654-669,884-885,1366-1425`. Git commands: `git show REVIEWED_COMMIT -- packages/coding-agent/src/core/model-registry.ts`; `git grep -n "authorizedPrivatePrimeInferenceModels\|loadBuiltInModels\|modelOverrides" REVIEWED_COMMIT -- packages/coding-agent/src/core/model-registry.ts`

@sethkarten

Copy link
Copy Markdown
Contributor Author

Included in #2068: #2068

@sethkarten sethkarten closed this Sep 7, 2026
sethkarten added a commit that referenced this pull request Sep 7, 2026
…2068)

* feat(coding-agent): show the model label on every agents-view row

Resident summaries carry model info for all session kinds; only the
renderer restricted the label to subagent rows. Drop the special case so
any row whose summary has a model renders provider/id[:thinkingLevel] in
the suffix region, still suppressed while pending delete/kill.

* fix(coding-agent): open visible sessions without waiting for selection anchors

Consolidates #2079 at d5b4926.

* feat(tui): open local file links

Consolidates #2073 at b6e83f0.

* feat(coding-agent): highlight file references and command options

Consolidates #1145 at 285ccf4.

* feat: refresh Prime Inference models from the live catalog

Consolidates #1928 at 24d3413.

* feat(coding-agent): let root agents create sibling sessions

Consolidates #1996 at 0c9c883.

* feat(coding-agent): wake agents when asynchronous bash finishes

Consolidates #2053 at 1bb4d43.

* feat(coding-agent): simplify the agents view while retaining model details

Consolidates #2087 at dc67428.
Retains #2068 model visibility and #2079 immediate opening and query ownership.

* fix(coding-agent): preserve background work and sibling-session credentials

Keep managed shell commands active until completion delivery is accepted.
Forward only effective same-provider transient auth when creating root sessions.
Integration fixes for #2053 and #1996.

* fix(coding-agent): address session lifecycle and rendering regressions

Preserve sibling PATH and reject root creation after disposal.
Treat background completions as new runs without duplicate as_completed wakes.
Keep table delimiters visible and sanitize live catalog display metadata.
Scope the stale-auth regression fixture to its cached Prime team.

* fix(coding-agent): forward the selected provider environment credentials

Preserve alias priority and runtime credential identity when creating sibling sessions.
Pin that a create timeout never dispatches the task prompt.

* fix(runtime): recheck creating-cell waits when shell commands settle

Preserve late as_completed consumers without suppressing detached completion notices.
Document the cached-wrapper result limitation.

* fix(runtime): preserve background bash completion lifecycle

Wait for process-group cleanup before releasing residency. Defer paused admission within the original request and report terminal rejection.
Preserve notices after cancelled non-owning waits and clean up interrupted task construction.

* fix(runtime): use a portable signal for construction cleanup

Keep immediate POSIX cleanup and use the existing Windows job cleanup path without referencing SIGKILL.

* fix(coding-agent): steer shell messages and stop losing supervisor launches

Deliver labeled shell completion messages at the next safe turn boundary.
Stop only an owned replacement child that loses to a current authenticated supervisor.

---------

Co-authored-by: Seth <seth@primeintellect.ai>
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.

2 participants