Skip to content

feat(models): optional auto-alias creation for autosynced provider models - #865

Closed
kaspesi wants to merge 1 commit into
mcowger:mainfrom
kaspesi:feat/autosync-create-aliases
Closed

kaspesi wants to merge 1 commit into
mcowger:mainfrom
kaspesi:feat/autosync-create-aliases

Conversation

@kaspesi

@kaspesi kaspesi commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Problem

model_autosync keeps a provider's models map current, but those models are not routable: inference resolves the request model against aliases only (Router.resolveCandidates/resolve → findAlias, which reads config.models), and GET /v1/models enumerates aliases only. So a newly-discovered provider model never appears in /v1/models and can't be called by bare name until an operator hand-creates an alias for it. Autosync fills half the gap (the provider models map) but not the half clients actually use.

Change

Add an opt-in model_autosync.createAliases flag (default false). When enabled, after autosync inserts newly-discovered models into the provider's models map, the scheduler also creates a passthrough alias (slug === model id) for each new model that has no existing alias:

{
  "priority": "api_match",
  "sticky_session": true,
  "target_groups": [
    { "name": "<provider>", "selector": "random",
      "targets": [{ "provider": "<provider>", "model": "<id>", "enabled": true }] }
  ]
}
  • Never overwrites an alias that already exists (a slug already taken by this or any other provider is left untouched).
  • Fires the existing models-changed callback when aliases or provider models were added, so the change is picked up without a restart.
  • preferred_api is intentionally omitted so the model family determines the default surface.

Details

  • New model_autosync_create_aliases column (sqlite + postgres schema). Migrations not committed per repo workflow — CI regenerates on merge.
  • ModelAutosyncScheduler.createMissingAliases() + wiring in runSyncNow().
  • OpenAPI ProviderConfig.model_autosync.createAliases documented; asset regenerated.
  • Admin UI: "Auto-create model aliases" checkbox in the provider Advanced editor (disabled unless autosync is enabled).
  • Tests: scheduler create / skip-existing / off / callback-on-alias-only + DB round-trip of the flag.

Drive-by fix

Set an explicit Connection: keep-alive header on MCP SSE responses instead of relying on a runtime-implicit header. This fixes a pre-existing mcp-routes SSE test (expect(response.headers.connection).toBe('keep-alive')) that fails under Bun's inject/light-my-request harness, where the implicit header isn't synthesized. Needed to get a green bun run test locally.

Test plan

  • bun run typecheck — all workspaces pass
  • bun run test — full backend suite green (incl. new scheduler + DB tests)
  • Manually verified on a live gateway: enabling the flag surfaces a newly-catalogued Codex model in /v1/models and routes an inference call to it end-to-end.

🤖 Generated with Claude Code

…dels

Model autosync keeps a provider's `models` map fresh but never exposes
those models as routable aliases, so newly discovered models don't appear
in GET /v1/models and can't be routed by bare name — operators must
hand-create an alias per model.

Add an opt-in `model_autosync.createAliases` flag. When enabled, after
autosync inserts newly discovered models into the provider's `models`
map it also creates a passthrough alias (slug === model id) for each new
model that has no existing alias. Existing aliases are never overwritten.

- New `model_autosync_create_aliases` column (sqlite + postgres)
- Scheduler creates missing passthrough aliases and fires the
  models-changed callback when aliases or models were added
- OpenAPI ProviderConfig documents the flag; asset regenerated
- Admin UI: "Auto-create model aliases" checkbox in the Advanced editor
- Tests: scheduler create/skip-existing/off/callback + DB round-trip

Also set an explicit `Connection: keep-alive` header on MCP SSE responses
instead of relying on a runtime-implicit header, fixing a pre-existing
mcp-routes SSE test that fails under Bun's inject harness.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@mcowger

mcowger commented Sep 9, 2026

Copy link
Copy Markdown
Owner

Why not simply using the direct/ prefix?

@mcowger mcowger closed this Sep 23, 2026
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