Skip to content

Analysis: Factory object collection timing - bootstrap vs per-request#1108

Closed
Copilot wants to merge 1 commit intov2from
copilot/review-factory-py-contents
Closed

Analysis: Factory object collection timing - bootstrap vs per-request#1108
Copilot wants to merge 1 commit intov2from
copilot/review-factory-py-contents

Conversation

Copy link

Copilot AI commented Nov 21, 2025

Analyzed factory.py to determine optimal timing for plugin object collection (LLMs, agents, auth handlers, MCP servers).

Current Implementation (Correct ✅)

Objects are collected at app bootstrap via on_mad_hatter_refresh() callback:

# cheshire_cat.py
async def on_mad_hatter_refresh(self):
    await self.factory.load_objects(self)  # Bootstrap + plugin refresh only
    self.llms = self.factory.get_objects("llm")
    self.agents = self.factory.get_objects("agent")
    # ...

Per-request access is lightweight:

# stray_cat.py (per-request instance)
@property
def _llm(self):
    return self._ccat.llms[slug]  # Direct dict lookup, no hook execution

Recommendation: Keep at Bootstrap

Performance: Avoids executing mad_hatter.execute_hook() (iterates all plugins) on every request

Architecture:

  • CheshireCat = app singleton, Factory objects = stateless/shared
  • StrayCat = per-request, references shared objects via _ccat

Refresh triggers: App start, plugin toggle, hot reload (infrequent vs requests)

No Changes Required

Current implementation follows FastAPI best practices for plugin-based apps.

Original prompt

check the contents of factory.py and tell me:

  • should I run the collection of objects per request or at app bootstrap?

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Review object collection strategy in factory.py Analysis: Factory object collection timing - bootstrap vs per-request Nov 21, 2025
Copilot AI requested a review from pieroit November 21, 2025 09:07
@pieroit pieroit closed this Nov 21, 2025
@pieroit pieroit deleted the copilot/review-factory-py-contents branch November 21, 2025 09:09
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