Repository navigation
feat(backend): implement engine connection routing (issue #127) - #160
Merged
Merged
Conversation
- Accept optional base_url parameter in ComfyUIClient constructor - Use provided base_url if given, otherwise construct from host:port - Update _create_client to pass base_url from connection.url This allows ComfyUIClient to use the configured connection URL directly instead of always reconstructing http://host:port.
Core implementation: - Add connection_id to CreativeActionRequest and GenerationProvenance schemas - Add base_url parameter to ComfyUIClient for configured endpoints - Implement _resolve_connection() with fallback chain (connection_id > engine_id) - Implement _create_client() for type-specific client creation - Update compute_creative_cache_hash() to include connection_id (v0.3.0) - Update cancel_task() to use resolved connection - Update execute() to resolve connection before dispatch - Pass resolved comfy_client to _run_comfy() - Add comprehensive test suite for connection routing Cache isolation: Results from different connections are properly isolated. Backward compatibility: Legacy engine_id still supported with deprecation warning.
BerryUIKI
enabled auto-merge (squash)
October 6, 2026 17:22
- Replace comfy_client global with ComfyUIClient class mocks - Add engine_manager mocks for connection resolution - Update test_img2img and test_inpaint to work with new architecture All upload tests now properly mock the connection routing flow.
- Fix test_comfy_asset_transfer_contract to use ComfyUIClient mock - Fix test_cancellation_and_actions to mock engine_manager - All tests now work with connection resolution architecture Tests properly mock the connection routing flow introduced in #127.
EngineConnection schema requires endpoint_url field. Updated all mock connections in test_engine_connection_routing.py.
EngineConnection schema uses endpoint_url not url. Updated all references in creative_runner and test files.
compute_creative_cache_hash now requires connection_id as second positional parameter. Updated all test calls.
The actual EngineManager API uses get_engine() not get_connection(). Updated all references in creative_runner and test mocks.
…routing - Replace global comfy_client patches with ComfyUIClient class mocks - Add mock_engine_manager fixture to all tests - Use shared connection fixtures from conftest.py
…_hash calls Updated cache hash function signature requires connection_id as second positional parameter for connection-aware cache isolation (v0.3.0).
All integration tests now use the shared mock_engine_manager fixture to properly resolve engine connections during execution.
Removed orphaned duplicate test code that was causing IndentationError during test collection.
- test_comfy_asset_transfer_contract: use proper EngineConnection objects instead of Mock - test_cancellation_and_actions: add connection_id to active task and mock ComfyUIClient - All tests now properly handle connection routing
The test was failing with 'No connection_id or engine_id provided' error despite having engine_id in the request because engine_manager was not mocked.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements backend infrastructure for issue #127: resolving execution and lifecycle operations through the selected engine connection.
Problem
comfy_clientsingleton instead of resolving from selected connectionconnection_idpropagated from frontend to backendcancel_task()checked engine type strings instead of actual connectionBackend Changes Implemented
Schema Updates
connection_id: Optional[str]toCreativeActionRequestconnection_id: strtoGenerationProvenanceengine_idComfyUIClient Enhancement
base_urlparameter to constructorCreativeRunner Core Methods
_resolve_connection(): Resolves connection_id with engine_id fallback chain_create_client(): Creates type-specific clients (ComfyUI/WebUI) from connectionscompute_creative_cache_hash(): Includes connection_id for cache isolation (v0.3.0)cancel_task(): Uses resolved connection for interrupt routingexecute(): Resolves connection before all operationsTest Coverage
What Works Now
✅ Backend resolves stable connection_id to engine endpoint
✅ Cache isolates results by connection (different connections = different cache entries)
✅ Cancellation targets the correct connection
✅ All operations (upload, queue, poll, download) use same resolved client
✅ Backward compatible with legacy engine_id
✅ External connections properly differentiated from managed
Frontend Changes Still Needed
The backend is complete and ready, but frontend integration is required for the full feature to work end-to-end.
Architecture Preservation
Cache Invalidation
Runner version bumped from
0.2.0→0.3.0to invalidate old cache entries that don't include connection_id.Related Issues
Verification Evidence
Backend Contract Tests: ✅ 8 connection routing tests added
Connection Resolution: ✅ Implemented with fallback chain
Cache Isolation: ✅ Verified with different connection_ids
Cancellation Routing: ✅ Targets correct connection
Live Engine Testing: ⏳ Requires GPU + frontend integration
Frontend Integration: ⏳ Awaiting separate PR for frontend changes
🤖 Generated with Claude Code