Skip to content

feat(backend): add LLM registry read cache with pub/sub refresh - #13606

Closed
ntindle wants to merge 1 commit into
feat/llm-registry-v2-schemafrom
feat/llm-registry-v2-core
Closed

feat(backend): add LLM registry read cache with pub/sub refresh#13606
ntindle wants to merge 1 commit into
feat/llm-registry-v2-schemafrom
feat/llm-registry-v2-core

Conversation

@ntindle

@ntindle ntindle commented Jul 18, 2026

Copy link
Copy Markdown
Member

Why

Part 2 of 9 of the LLM registry restack (see #13605 for the schema and full context). This layer gives every backend pod a fast, always-warm view of the registry so later parts (public catalog endpoint, copilot routing, admin API) never touch the DB on hot paths.

What

backend/data/llm_registry/ — re-cut of @Bentlybro's #12359 core layer:

  • Two-level cache: L1 module-global dict under an asyncio.Lock; L2 Redis via @cached(ttl=300, shared_cache=True) on the DB fetch. All read functions are sync L1 lookups.
  • Read API: get_model, get_all_models, get_enabled_models, get_schema_options, get_default_model_slug, get_all_model_slugs_for_validation, and new get_route(surface, mode, tier) for the routing cells.
  • Cross-pod refresh: llm_registry:refresh channel; refresh_llm_registry + long-lived subscribe task wired into the rest_api lifespan (fail-soft startup, clean cancellation on shutdown).

Still dormant: nothing consumes these reads yet.

How (deltas vs the original branch)

  • Pub/sub rewritten to sharded SPUBLISH/SSUBSCRIBE via connect_sharded_pubsub_async — prod Redis is cluster mode; classic pub/sub broadcasts to every node. Mirrors event_bus.AsyncRedisEventBus.
  • ModelMetadata NamedTuple import from blocks/llm.py replaced with a standalone frozen RegistryModelMetadata — decouples the registry from the module it will eventually replace, and NamedTuples serialize as JSON arrays (wrong for API payloads).
  • RegistryModel carries the new schema columns (kind, visibility, minSubscriptionTier, source, catalogRemovedAt, fallbackModelSlug).

Verification

  • 30/30 tests pass locally (backend/data/llm_registry/) — record mapping edge cases, refresh/L1 population incl. routes, cache clearing both fetches, sharded pub/sub happy path + handshake filtering + reconnect + close-on-exit
  • poetry run format + poetry run lint clean

Checklist

  • Data-layer additions have no user-facing routes yet (no user ID checks needed — no user-scoped data involved; registry rows are global config)
  • Out-of-scope changes: none

Re-cut of #12359's reviewed core layer onto current dev (part 2 of 9).
backend/data/llm_registry/: frozen pydantic models, L1 in-process cache
under an asyncio.Lock with Redis-backed L2 (@cached shared_cache), sync
read functions (get_model/get_enabled_models/get_schema_options/
get_default_model_slug/get_route/...), and cross-pod refresh fan-out.

Changes vs the original branch:
- pub/sub rewritten to sharded SPUBLISH/SSUBSCRIBE via the
  connect_sharded_pubsub_async helper (prod Redis is cluster mode;
  mirrors event_bus.AsyncRedisEventBus)
- ModelMetadata NamedTuple import from backend.blocks.llm replaced with
  a standalone frozen RegistryModelMetadata (decouples the registry from
  the enum module it will replace; NamedTuples serialize as JSON arrays)
- RegistryModel carries the new schema columns (kind, visibility,
  minSubscriptionTier, source, catalogRemovedAt, fallbackModelSlug)
- get_route(surface, mode, tier) reads LlmModelRoute cells from the same
  L1 cache for the upcoming copilot routing integration
- rest_api lifespan: initial refresh (fail-soft — empty registry degrades
  to existing hardcoded behavior) + background subscribe task with clean
  cancellation on shutdown

Co-authored-by: Bentlybro <Github@bentlybro.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@github-project-automation github-project-automation Bot moved this to 🆕 Needs initial review in AutoGPT development kanban Jul 18, 2026
@github-actions github-actions Bot added the platform/backend AutoGPT Platform - Back end label Jul 18, 2026
@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: bf56286d-46b8-49e8-9b28-0dcb20a45a4c

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/llm-registry-v2-core

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.01%. Comparing base (30ee04c) to head (2a3a7f0).

Additional details and impacted files
@@                       Coverage Diff                       @@
##           feat/llm-registry-v2-schema   #13606      +/-   ##
===============================================================
- Coverage                        76.02%   76.01%   -0.02%     
===============================================================
  Files                             2688     2688              
  Lines                           204282   204280       -2     
  Branches                         19654    19654              
===============================================================
- Hits                            155305   155278      -27     
- Misses                           44639    44662      +23     
- Partials                          4338     4340       +2     
Flag Coverage Δ
platform-frontend-e2e 30.98% <ø> (-0.19%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
Platform Backend 82.83% <ø> (ø)
Platform Frontend 49.97% <ø> (-0.08%) ⬇️
AutoGPT Libs ∅ <ø> (∅)
Classic AutoGPT 28.43% <ø> (ø)
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ntindle

ntindle commented Jul 20, 2026

Copy link
Copy Markdown
Member Author

After a post-build design review we pivoted from the DB-registry to catalog-as-code: one canonical, schema-validated catalog file is the source of truth (models + costs + copilot routing), updated by PR (catalog-only diffs may ride hotfix→master; the /review bot covers the lane), propagated by CD, with LaunchDarkly demoted to optional cohort experiments and git history as the audit log. Rationale: the admin machinery mostly bought instant-mutation and non-engineer authoring we don't need, and LD is too unreliable to be the load-bearing control layer.

Replaced by #13622 — the same read interface and L1 cache, loaded from the catalog file; Redis L2 and pub/sub are unnecessary when the data only changes at deploy.

@ntindle ntindle closed this Jul 20, 2026
@github-project-automation github-project-automation Bot moved this from 🆕 Needs initial review to ✅ Done in AutoGPT development kanban Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

platform/backend AutoGPT Platform - Back end size/xl

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

1 participant