Skip to content

FIX: Keep cold target catalog responsive - #2360

Open
Roman Lutz (romanlutz) wants to merge 3 commits into
microsoft:mainfrom
romanlutz:romanlutz-fix-cold-target-catalog
Open

FIX: Keep cold target catalog responsive#2360
Roman Lutz (romanlutz) wants to merge 3 commits into
microsoft:mainfrom
romanlutz:romanlutz-fix-cold-target-catalog

Conversation

@romanlutz

Copy link
Copy Markdown
Contributor

Description

A fresh GET /api/targets/catalog synchronously materialized the lazy Hugging Face target export, importing heavyweight inference dependencies on the FastAPI event loop. This delayed both the catalog and unrelated requests such as /api/health.

This change:

  • defers transformers and Hugging Face download imports until target validation or model-loading execution paths
  • preserves the registry metadata cache while adding thread-safe, single-flight discovery and coherent class-registration invalidation
  • offloads remaining cold metadata discovery from the async route
  • keeps the existing eight renderable frontend target choices available while authoritative metadata loads, preserving selection during enrichment

Fresh-process route checks measured 81-103 ms for the cold catalog, 65-87 ms for concurrent health, and 3.3-4.5 ms for warm catalog requests. All 20 target types remain present, including HuggingFaceChatTarget, without catalog discovery importing transformers, torch, or huggingface_hub.

Tests and Documentation

Added deterministic coverage for import isolation, cold/warm equivalence, concurrent single-flight discovery, runtime class invalidation, instance-cache lifetime, event-loop schedulability, and frontend fallback selection/enrichment.

Validation completed:

  • backend and registry suites: 1,149 passed, 5 skipped
  • target dialog suite: 52 passed
  • Ruff, ty, TypeScript type-check, ESLint, and pre-commit hooks passed
  • JupyText: not applicable; no documentation notebooks changed

Defer Hugging Face inference imports, coordinate registry metadata discovery, offload cold catalog work, and keep fallback target choices interactive while metadata loads.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

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.

Overall looks great! I left 4 comments all related to very similar timing issues with locks that I believe are held longer than necessary. I could be wrong though and we actually need to hold.

Comment thread pyrit/registry/registry.py
Comment thread pyrit/prompt_target/hugging_face/hugging_face_chat_target.py
Comment thread pyrit/registry/registry.py
Comment thread frontend/src/components/Config/CreateTargetDialog.test.tsx
Copilot AI and others added 2 commits August 12, 2026 16:32
Narrow registry lock scope, coordinate singleton construction per registry class, keep Hugging Face model loading off the event loop, and eliminate frontend act warnings.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 130110b1-e9bb-4dc5-9f71-c2405871b1e4
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.

3 participants