Skip to content

fix: deduplicate OmniParser init and reuse HeuristicEngine as singleton - #33

Open
Pranjal0410 wants to merge 1 commit into
ruxailab:mainfrom
Pranjal0410:fix/singleton-initialization
Open

fix: deduplicate OmniParser init and reuse HeuristicEngine as singleton#33
Pranjal0410 wants to merge 1 commit into
ruxailab:mainfrom
Pranjal0410:fix/singleton-initialization

Conversation

@Pranjal0410

Copy link
Copy Markdown

fix: remove duplicate OmniParser initialization and store HeuristicEvaluationEngine as singleton

Problem

Two issues in the current startup and request handling:

  1. Duplicate OmniParser initialization in main.pyOmniParserClient() is created and initialized twice during startup (lines 36–37 and lines 44–45), meaning the model is loaded into memory twice unnecessarily.

  2. HeuristicEvaluationEngine re-created on every request — In evaluation.py, the /evaluate endpoint creates a new HeuristicEvaluationEngine() and calls await evaluation_engine.initialize() on every single request. This re-initializes the OpenAI client and the RAG knowledge base each time, adding unnecessary latency and memory overhead.

Fix

  • main.py: Removed the duplicate OmniParserClient initialization. Stored HeuristicEvaluationEngine on app.state.heuristic_engine as a singleton, matching the existing pattern used for app.state.omniparser_client.

  • app/api/routes/evaluation.py: Updated the /evaluate endpoint to use request.app.state.heuristic_engine instead of creating a new engine instance per request.

Files Changed

File Change
main.py Removed duplicate OmniParser init; added app.state.heuristic_engine singleton
app/api/routes/evaluation.py Use singleton engine from app.state instead of re-creating per request

Testing

  • Existing integration test (tests/test_integration_real.py) is unaffected — it creates its own engine instance directly.
  • The /evaluate endpoint behavior is unchanged; only the initialization strategy differs.

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.

1 participant