-
Notifications
You must be signed in to change notification settings - Fork 199
Task #1: Run registry UI stub #81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Task #1: Run registry UI stub #81
Conversation
- Implement backend RunRegistry class with thread-safe JSON storage - Add REST API endpoints for CRUD operations on runs - Create React frontend component with grid view and detailed modal - Integrate automatic run saving in txt2img and img2img workflows - Add comprehensive unit tests for backend and frontend - Support deep linking to specific runs via React Router - Handle empty/null values gracefully throughout the system This feature allows users to: - View complete history of their image generations - Inspect detailed configuration for each run - Delete individual runs or clear all history - Access runs directly via URL for sharing
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. WalkthroughAdds a local Run Registry across backend and frontend: persistence of txt2img/img2img runs, new backend verification/tests/demo for the registry, new frontend Run Registry page with routes, service, types, and tests. dream_layer.py was rewritten with no functional changes. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Frontend as Frontend (RunRegistry)
participant Service as RunService (HTTP)
participant API as Backend API (Flask)
participant Store as RunRegistry Storage
User->>Frontend: Navigate to /runs or /runs/:id
Frontend->>Service: getRuns() / getRun(id)
Service->>API: GET /api/runs / GET /api/runs/{id}
API->>Store: List/Get runs
Store-->>API: Run summaries / Run detail
API-->>Service: JSON response
Service-->>Frontend: Runs / Run detail
Frontend-->>User: Render list / Open detail modal
User->>Frontend: Delete run
Frontend->>Service: deleteRun(id)
Service->>API: DELETE /api/runs/{id}
API->>Store: Delete run
Store-->>API: OK
API-->>Service: 200 OK
Service-->>Frontend: success
Frontend-->>User: Update list, close modal
sequenceDiagram
participant Client as Client (txt2img/img2img)
participant Server as Backend Gen Server
participant Comfy as ComfyUI
participant Store as RunRegistry Storage
Client->>Server: Generation request
Server->>Comfy: Submit workflow
Comfy-->>Server: Generation result (images)
Server->>Store: save_run(run_config + outputs)
Store-->>Server: run_id
Server-->>Client: Response (results, run_id)
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
Poem
✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
Reviewer's GuideThis PR introduces a thread-safe JSON-based RunRegistry backend with full CRUD REST endpoints, integrates automatic run saving into txt2img and img2img workflows, adds a new React RunRegistry UI (including deep linking and graceful handling of missing values), implements an API service layer with TypeScript types, and ships comprehensive unit tests for both backend and frontend. Sequence diagram for saving a run from txt2img workflowsequenceDiagram
participant User as actor User
participant Frontend as Frontend (React)
participant Backend as txt2img_server.py
participant Registry as RunRegistry
participant Storage as JSON Storage
User->>Frontend: Submit txt2img generation request
Frontend->>Backend: POST /txt2img
Backend->>Backend: Process workflow, generate image
Backend->>Registry: save_run(config)
Registry->>Storage: Write run JSON file
Registry->>Registry: Update index.json
Registry-->>Backend: run_id
Backend-->>Frontend: Generation result (success, run_id)
Frontend-->>User: Show result, run in history
Sequence diagram for viewing run details with deep linkingsequenceDiagram
participant User as actor User
participant Frontend as RunRegistry React Page
participant Service as runService.ts
participant API as REST API /api/runs/:id
participant Backend as RunRegistry
participant Storage as JSON Storage
User->>Frontend: Navigate to /runs/:id
Frontend->>Service: getRun(runId)
Service->>API: GET /api/runs/:id
API->>Backend: get_run(run_id)
Backend->>Storage: Read run JSON file
Backend-->>API: Run details
API-->>Service: Run details
Service-->>Frontend: Run details
Frontend-->>User: Show run details modal
Entity relationship diagram for RunRegistry data modelerDiagram
RUN {
string id
string timestamp
string model
string vae
string prompt
string negative_prompt
int seed
string sampler
string scheduler
int steps
float cfg_scale
int width
int height
int batch_size
json loras
json controlnet
string generation_type
json workflow
string workflow_version
json full_config
}
INDEX {
string id
string timestamp
string prompt
string model
string generation_type
}
RUN ||--o{ INDEX : indexed_by
Class diagram for RunRegistry and related TypeScript typesclassDiagram
class RunRegistry {
- Path storage_path
- threading.Lock lock
- Path index_file
+ save_run(config: dict) str
+ get_run(run_id: str) dict
+ get_runs(limit: int, offset: int) list
+ delete_run(run_id: str) bool
+ clear_all_runs() None
}
class RunConfig {
+ string model
+ string vae
+ string prompt
+ string negative_prompt
+ int seed
+ string sampler
+ string scheduler
+ int steps
+ float cfg_scale
+ int width
+ int height
+ int batch_size
+ object loras
+ object controlnets
+ object face_restoration
+ bool tiling
+ object hires_fix
+ object refiner
+ object workflow
+ string workflow_version
+ string generation_type
+ string[] output_images
+ object custom_workflow
+ object extras
}
class Run {
+ string id
+ string timestamp
+ RunConfig config
}
class RunSummary {
+ string id
+ string timestamp
+ string prompt
+ string model
+ string generation_type
}
RunRegistry o-- "*" Run
Run o-- RunConfig
RunSummary <|-- Run
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @abhaypatnala - I've reviewed your changes - here's some feedback:
Blocking issues:
- time.sleep() call; did you mean to leave this in? (link)
General comments:
- There’s a mismatch between RunRegistry.list_runs (used in tests) and the API calling registry.get_runs—consider unifying these method names or aliasing one to avoid test–API inconsistencies.
- The backend uses
controlnet
while the frontend and types expectcontrolnets
—align this naming across storage, API, and UI so control nets render correctly.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- There’s a mismatch between RunRegistry.list_runs (used in tests) and the API calling registry.get_runs—consider unifying these method names or aliasing one to avoid test–API inconsistencies.
- The backend uses `controlnet` while the frontend and types expect `controlnets`—align this naming across storage, API, and UI so control nets render correctly.
## Individual Comments
### Comment 1
<location> `dream_layer_frontend/src/types/run.ts:21` </location>
<code_context>
+ batch_size: number;
+
+ // Advanced features
+ loras: Record<string, any>;
+ controlnets: Record<string, any>;
+ face_restoration: Record<string, any>;
+ tiling: boolean;
</code_context>
<issue_to_address>
Type definitions for loras and controlnets may not match backend structure.
Update the types for loras and controlnets to match the backend—use an array for loras and an object for controlnets—to avoid mismatches and potential runtime issues.
</issue_to_address>
### Comment 2
<location> `dream_layer_backend/run_registry.py:136` </location>
<code_context>
+ return None
+ return None
+
+ def get_runs(self, limit: int = 50, offset: int = 0) -> List[Dict[str, Any]]:
+ """
+ Get a list of recent runs
+
+ Args:
+ limit: Maximum number of runs to return
+ offset: Number of runs to skip
+
+ Returns:
+ List of run summaries
+ """
+ index = self._load_index()
+ return index[offset:offset + limit]
+
+ def delete_run(self, run_id: str) -> bool:
</code_context>
<issue_to_address>
No error handling for negative or invalid limit/offset values.
Validate that limit and offset are non-negative integers to prevent unexpected behavior.
</issue_to_address>
### Comment 3
<location> `dream_layer_backend/test_run_registry.py:237` </location>
<code_context>
+ def test_large_config_handling(self, temp_registry):
</code_context>
<issue_to_address>
Missing test for extremely large or malformed JSON in config
Please add tests for extremely large or malformed JSON (such as deeply nested structures or invalid formats) to verify the registry's robustness.
</issue_to_address>
## Security Issues
### Issue 1
<location> `dream_layer_backend/test_run_registry_demo.py:100` </location>
<issue_to_address>
**security (python.lang.best-practice.arbitrary-sleep):** time.sleep() call; did you mean to leave this in?
*Source: opengrep*
</issue_to_address>
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 16
🔭 Outside diff range comments (1)
dream_layer_backend/txt2img_server.py (1)
23-23
: Add missing import for get_directories in txt2img_server.pyTo prevent a NameError at runtime, import the
get_directories
function defined indream_layer.py
at the top ofdream_layer_backend/txt2img_server.py
.• In dream_layer_backend/txt2img_server.py (after your other imports), add:
from dream_layer import get_directories• This aligns with how
get_directories
is defined in dream_layer_backend/dream_layer.py and used elsewhere.
🧹 Nitpick comments (8)
dream_layer_frontend/src/services/runService.ts (2)
15-20
: Remove unnecessary Content-Type header from GET and DELETE requests.The
Content-Type: application/json
header is only needed when sending a request body (POST/PUT/PATCH). It's unnecessary for GET and DELETE requests without bodies.static async getRuns(limit: number = 50, offset: number = 0): Promise<RunSummary[]> { try { const response = await fetch(`${API_BASE_URL}/runs?limit=${limit}&offset=${offset}`, { method: 'GET', - headers: { - 'Content-Type': 'application/json', - }, }); static async getRun(runId: string): Promise<Run | null> { try { const response = await fetch(`${API_BASE_URL}/runs/${runId}`, { method: 'GET', - headers: { - 'Content-Type': 'application/json', - }, }); static async deleteRun(runId: string): Promise<boolean> { try { const response = await fetch(`${API_BASE_URL}/runs/${runId}`, { method: 'DELETE', - headers: { - 'Content-Type': 'application/json', - }, });Also applies to: 39-43, 92-96
65-65
: Consider using a more specific type instead of Record<string, any>.The
config
parameter uses a generic type which reduces type safety.Since you have a
RunConfig
interface defined in@/types/run
, consider using it:-static async saveRun(config: Record<string, any>): Promise<string> { +static async saveRun(config: RunConfig): Promise<string> {dream_layer_backend/test_run_registry.py (1)
294-294
: Remove unused variable assignmentThe
run_id
variable is assigned but never used. Consider either using it in assertions or removing the assignment.- run_id = temp_registry.save_run(config) + temp_registry.save_run(config)dream_layer_frontend/src/pages/RunRegistry.tsx (1)
77-82
: Replace native confirm dialog with custom UI componentUsing the native browser
confirm()
dialog breaks UI consistency. Consider using a custom confirmation dialog that matches your design system.Consider implementing a custom confirmation dialog using your UI components library for better UX consistency. You could use a Dialog component with proper styling and animations instead of the browser's native confirm dialog.
dream_layer_backend/run_registry.py (2)
17-27
: Use Path consistently throughout the constructorThe constructor mixes
os.path
operations withPath
objects. Since you're already usingpathlib.Path
, consider using it consistently.def __init__(self, storage_path: str = None): """Initialize the run registry with a storage path""" if storage_path is None: # Default to a runs directory in the parent folder - current_dir = os.path.dirname(os.path.abspath(__file__)) - parent_dir = os.path.dirname(current_dir) - storage_path = os.path.join(parent_dir, 'Dream_Layer_Resources', 'runs') + current_dir = Path(__file__).resolve().parent + parent_dir = current_dir.parent + storage_path = parent_dir / 'Dream_Layer_Resources' / 'runs' self.storage_path = Path(storage_path) self.storage_path.mkdir(parents=True, exist_ok=True)
103-103
: Fix prompt truncation logicThe current logic appends '...' even when the prompt is exactly 100 characters, making it 103 characters total.
- 'prompt': run_data['prompt'][:100] + '...' if len(run_data['prompt']) > 100 else run_data['prompt'], + 'prompt': run_data['prompt'][:97] + '...' if len(run_data['prompt']) > 100 else run_data['prompt'],dream_layer_backend/dream_layer.py (2)
14-14
: Use explicit import syntax for better reliability.The relative import may cause issues depending on how the module is executed. Consider using explicit relative import syntax.
Apply this diff for more explicit import:
-from run_registry import get_registry +from .run_registry import get_registryOr if
run_registry
is in the same directory and should be treated as a module in the same package:-from run_registry import get_registry +from dream_layer_backend.run_registry import get_registry
612-629
: LGTM! Consider adding maximum limit validation.The endpoint implementation is correct with proper pagination and error handling. Consider adding a maximum limit validation to prevent performance issues.
Optional improvement to add maximum limit:
@app.route('/api/runs', methods=['GET']) def get_runs(): """Get list of generation runs""" try: registry = get_registry() limit = request.args.get('limit', 50, type=int) + limit = min(limit, 100) # Cap at 100 runs per request offset = request.args.get('offset', 0, type=int)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (11)
dream_layer_backend/dream_layer.py
(2 hunks)dream_layer_backend/img2img_server.py
(2 hunks)dream_layer_backend/run_registry.py
(1 hunks)dream_layer_backend/test_run_registry.py
(1 hunks)dream_layer_backend/test_run_registry_demo.py
(1 hunks)dream_layer_backend/txt2img_server.py
(2 hunks)dream_layer_frontend/src/App.tsx
(2 hunks)dream_layer_frontend/src/pages/RunRegistry.test.tsx
(1 hunks)dream_layer_frontend/src/pages/RunRegistry.tsx
(1 hunks)dream_layer_frontend/src/services/runService.ts
(1 hunks)dream_layer_frontend/src/types/run.ts
(1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: in the dreamlayer frontend codebase, the team prefers to rely on typescript's type system for data v...
Learnt from: rockerBOO
PR: DreamLayer-AI/DreamLayer#28
File: dream_layer_frontend/src/components/WorkflowCustomNode.tsx:88-106
Timestamp: 2025-07-14T22:55:51.063Z
Learning: In the DreamLayer frontend codebase, the team prefers to rely on TypeScript's type system for data validation rather than adding defensive programming checks, when the types are well-defined and data flow is controlled.
Applied to files:
dream_layer_frontend/src/types/run.ts
🧬 Code Graph Analysis (3)
dream_layer_frontend/src/services/runService.ts (1)
dream_layer_frontend/src/types/run.ts (5)
RunSummary
(47-53)RunsResponse
(55-58)Run
(41-45)RunResponse
(60-63)SaveRunResponse
(65-68)
dream_layer_backend/test_run_registry_demo.py (2)
dream_layer_backend/run_registry.py (6)
get_registry
(189-194)save_run
(47-115)clear_all_runs
(174-183)get_runs
(136-148)get_run
(117-134)delete_run
(150-172)dream_layer_backend/dream_layer.py (4)
save_run
(657-679)get_runs
(613-629)get_run
(633-653)delete_run
(683-703)
dream_layer_backend/run_registry.py (3)
dream_layer_frontend/src/pages/RunRegistry.tsx (1)
RunRegistry
(19-387)dream_layer_backend/dream_layer.py (4)
save_run
(657-679)get_run
(633-653)get_runs
(613-629)delete_run
(683-703)dream_layer_backend/test_run_registry.py (1)
save_run
(205-215)
🪛 Ruff (0.12.2)
dream_layer_backend/test_run_registry.py
200-200: time
imported but unused
Remove unused import: time
(F401)
294-294: Local variable run_id
is assigned to but never used
Remove assignment to unused variable run_id
(F841)
dream_layer_backend/test_run_registry_demo.py
7-7: json
imported but unused
Remove unused import: json
(F401)
🔇 Additional comments (5)
dream_layer_frontend/src/App.tsx (1)
9-9
: LGTM! Routes properly configured for the run registry feature.The routing implementation correctly:
- Places the specific routes before the catch-all route
- Uses a single component to handle both list and detail views via route parameters
- Follows React Router best practices
Also applies to: 21-22
dream_layer_backend/img2img_server.py (1)
184-199
: Well-implemented run registry integration with proper error handling.The implementation correctly:
- Captures all necessary run configuration data
- Handles save failures gracefully without interrupting the main workflow
- Uses appropriate logging levels (info for success, warning for failure)
- Maintains backward compatibility by not failing requests when registry save fails
dream_layer_backend/dream_layer.py (3)
632-653
: LGTM!The endpoint correctly handles resource retrieval with appropriate 404 handling for missing runs and consistent error responses.
656-679
: LGTM!The endpoint correctly validates input data and returns the run ID on successful creation with proper error handling.
682-703
: LGTM!The endpoint correctly handles run deletion with appropriate 404 handling for non-existent runs and provides clear success confirmation.
…x controlnet naming - Removed unnecessary time.sleep(1) from ComfyUI connection retry loop - Added list_runs() method as alias to get_runs() for test compatibility - Fixed controlnet/controlnets naming inconsistency (backend now outputs 'controlnets' to match frontend) - Updated tests to use correct field names - Added verification script to validate all fixes
- Removed unnecessary time.sleep(1) from connection retry loop - Added list_runs() alias for backward compatibility with tests - Fixed controlnet/controlnets naming to match frontend expectations - Updated tests to use correct field names - Added verification script to validate fixes Fixes issues raised in previous PR review
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (2)
dream_layer_backend/verify_pr_fixes.py (2)
10-10
: Remove unused import.The
json
import is not used anywhere in the script.-import json
35-35
: Simplify boolean comparison.Avoid explicit comparison to
True
for better Python style.- assert saved_run['controlnets']['enabled'] == True, "❌ controlnets data not properly saved" + assert saved_run['controlnets']['enabled'], "❌ controlnets data not properly saved"
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
dream_layer_backend/dream_layer.py
(0 hunks)dream_layer_backend/verify_pr_fixes.py
(1 hunks)
💤 Files with no reviewable changes (1)
- dream_layer_backend/dream_layer.py
🧰 Additional context used
🧬 Code Graph Analysis (1)
dream_layer_backend/verify_pr_fixes.py (1)
dream_layer_frontend/src/pages/RunRegistry.tsx (1)
RunRegistry
(19-387)
🪛 Ruff (0.12.2)
dream_layer_backend/verify_pr_fixes.py
10-10: json
imported but unused
Remove unused import: json
(F401)
35-35: Avoid equality comparisons to True
; use saved_run['controlnets']['enabled']:
for truth checks
Replace with saved_run['controlnets']['enabled']
(E712)
88-88: f-string without any placeholders
Remove extraneous f
prefix
(F541)
🔇 Additional comments (2)
dream_layer_backend/verify_pr_fixes.py (2)
43-72
: LGTM!The test methodology is thorough - it creates test data, verifies both methods return identical results, and properly cleans up. The assertions appropriately validate both count and data consistency.
94-139
: Good structure but will fail due to missing file.The main function has excellent structure with proper error handling, clear output formatting, and appropriate exit codes. However, it will fail when
check_time_sleep_removed()
attempts to read the non-existentdream_layer.py
file.Once the file reference issue is resolved, this orchestration function will work correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🔭 Outside diff range comments (4)
dream_layer_backend/img2img_server.py (2)
210-230
: Remove duplicate run registration logicThere are two different run registration approaches in the same function - one using the local registry (lines 187-202) and another using HTTP requests to a remote registry service (lines 210-230). This creates redundancy and potential confusion.
Based on the PR summary indicating this is implementing a "RunRegistry feature", you should choose one approach. If using the local registry approach (which aligns with the PR objectives), remove the HTTP-based registration:
- # Register the completed run - try: - run_config = create_run_config_from_generation_data( - data, generated_images, "img2img" - ) - - # Send to run registry - registry_response = requests.post( - "http://localhost:5005/api/runs", - json=asdict(run_config), - timeout=5 - ) - - if registry_response.status_code == 200: - logger.info(f"✅ Run registered successfully: {run_config.run_id}") - else: - logger.warning(f"⚠️ Failed to register run: {registry_response.text}") - - except Exception as e: - logger.warning(f"⚠️ Error registering run: {str(e)}")
276-276
: Disable debug mode for production deploymentFlask is configured with
debug=True
, which should be controlled by environment variables for production safety.- app.run(host='0.0.0.0', port=5004, debug=True) + debug_mode = os.environ.get('FLASK_DEBUG', 'false').lower() == 'true' + app.run(host='0.0.0.0', port=5004, debug=debug_mode)dream_layer_backend/txt2img_server.py (2)
110-130
: Remove duplicate run registration logicSimilar to
img2img_server.py
, there are two different run registration approaches - local registry (lines 88-102) and HTTP-based (lines 110-130). This creates redundancy.Choose one approach and remove the other. Based on the PR implementing a local RunRegistry, remove the HTTP-based registration:
- print("Start register process") - # Register the completed run - try: - run_config = create_run_config_from_generation_data( - data, generated_images, "txt2img" - ) - - # Send to run registry - registry_response = requests.post( - "http://localhost:5005/api/runs", - json=asdict(run_config), - timeout=5 - ) - - if registry_response.status_code == 200: - print(f"✅ Run registered successfully: {run_config.run_id}") - else: - print(f"⚠️ Failed to register run: {registry_response.text}") - - except Exception as e: - print(f"⚠️ Error registering run: {str(e)}")
248-248
: Disable debug mode for production deploymentFlask is configured with
debug=True
, which should be controlled by environment variables for production safety.- app.run(host='127.0.0.1', port=5001, debug=True) + debug_mode = os.environ.get('FLASK_DEBUG', 'false').lower() == 'true' + app.run(host='127.0.0.1', port=5001, debug=debug_mode)
♻️ Duplicate comments (4)
dream_layer_backend/dream_layer.py (1)
132-138
: ** Add DELETE to CORS-allowed methods**The CORS configuration only allows GET, POST, and OPTIONS methods, which will prevent the new DELETE endpoints in the Run Registry from being accessible by the frontend. This is consistent with the previous review comment.
dream_layer_backend/img2img_server.py (1)
15-17
: ** Avoid modifying sys.path - use proper imports instead**Modifying
sys.path
at runtime can lead to import conflicts and unpredictable behavior. This is consistent with the previous review comment.dream_layer_backend/txt2img_server.py (2)
12-15
: ** Avoid modifying sys.path - use proper imports instead**Same issue as in
img2img_server.py
. Modifyingsys.path
at runtime should be avoided.
88-102
: ** Use logger instead of print for consistency**The run registry saving logic uses
img2img_server.py
uses a logger. For consistency and better production practices, logging should be used.
🧹 Nitpick comments (3)
dream_layer_backend/dream_layer.py (1)
175-175
: Remove unused loop variableThe loop variable
api_key_value
is defined but never used within the loop body. This creates unnecessary code.- for api_key_name, api_key_value in api_keys.items(): + for api_key_name, _ in api_keys.items():dream_layer_backend/txt2img_server.py (2)
5-5
: Remove duplicate importsThere are duplicate imports for
interrupt_workflow
andsend_to_comfyui
that should be cleaned up.-from shared_utils import send_to_comfyui, interrupt_workflow import os import requests from dream_layer import get_directories -from dream_layer_backend_utils import interrupt_workflow -from shared_utils import send_to_comfyui +from shared_utils import send_to_comfyui, interrupt_workflowAlso applies to: 9-10
13-13
: Remove duplicate os importThe
os
module is imported twice (lines 6 and 13).from shared_utils import send_to_comfyui, interrupt_workflow import os import requests from dream_layer import get_directories from dream_layer_backend_utils import interrupt_workflow from shared_utils import send_to_comfyui from dream_layer_backend_utils.fetch_advanced_models import get_controlnet_models import sys -import os sys.path.append(os.path.dirname(os.path.abspath(__file__)))
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
dream_layer_backend/dream_layer.py
(1 hunks)dream_layer_backend/img2img_server.py
(2 hunks)dream_layer_backend/txt2img_server.py
(2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
dream_layer_backend/txt2img_server.py (2)
dream_layer_backend/txt2img_workflow.py (1)
transform_to_txt2img_workflow
(20-235)dream_layer_backend/shared_utils.py (1)
send_to_comfyui
(161-223)
🪛 Ruff (0.12.2)
dream_layer_backend/dream_layer.py
175-175: Loop control variable api_key_value
not used within loop body
Rename unused api_key_value
to _api_key_value
(B007)
dream_layer_backend/txt2img_server.py
9-9: Redefinition of unused interrupt_workflow
from line 5
(F811)
10-10: Redefinition of unused send_to_comfyui
from line 5
Remove definition: send_to_comfyui
(F811)
13-13: Redefinition of unused os
from line 6
Remove definition: os
(F811)
dream_layer_backend/img2img_server.py
202-202: SyntaxError: Expected except
or finally
after try
block
202-202: SyntaxError: Expected a statement
202-202: SyntaxError: Expected a statement
202-202: SyntaxError: Expected a statement
🪛 ast-grep (0.38.6)
dream_layer_backend/dream_layer.py
[warning] 303-303: Detected Flask app with debug=True. Do not deploy to production with this flag enabled as it will leak sensitive information. Instead, consider using Flask configuration variables or setting 'debug' using system environment variables.
Context: app.run(host='0.0.0.0', port=5002, debug=True, use_reloader=False)
Note: [CWE-489] Active Debug Code. [REFERENCES]
- https://labs.detectify.com/2015/10/02/how-patreon-got-hacked-publicly-exposed-werkzeug-debugger/
(debug-enabled-python)
print("\nStarting Flask API server on http://localhost:5002") | ||
app.run(host='0.0.0.0', port=5002, debug=True, use_reloader=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Disable debug mode for production deployment
Flask is configured with debug=True
, which exposes sensitive debugging information that should never be enabled in production environments.
- app.run(host='0.0.0.0', port=5002, debug=True, use_reloader=False)
+ debug_mode = os.environ.get('FLASK_DEBUG', 'false').lower() == 'true'
+ app.run(host='0.0.0.0', port=5002, debug=debug_mode, use_reloader=False)
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
print("\nStarting Flask API server on http://localhost:5002") | |
app.run(host='0.0.0.0', port=5002, debug=True, use_reloader=False) | |
print("\nStarting Flask API server on http://localhost:5002") | |
debug_mode = os.environ.get('FLASK_DEBUG', 'false').lower() == 'true' | |
app.run(host='0.0.0.0', port=5002, debug=debug_mode, use_reloader=False) |
🧰 Tools
🪛 ast-grep (0.38.6)
[warning] 303-303: Detected Flask app with debug=True. Do not deploy to production with this flag enabled as it will leak sensitive information. Instead, consider using Flask configuration variables or setting 'debug' using system environment variables.
Context: app.run(host='0.0.0.0', port=5002, debug=True, use_reloader=False)
Note: [CWE-489] Active Debug Code. [REFERENCES]
- https://labs.detectify.com/2015/10/02/how-patreon-got-hacked-publicly-exposed-werkzeug-debugger/
(debug-enabled-python)
🤖 Prompt for AI Agents
In dream_layer_backend/dream_layer.py around lines 303-304, the Flask app is
started with debug=True which must be disabled for production; change the run
invocation to not enable debug (set debug=False or remove the parameter), ensure
use_reloader remains False for production, and prefer controlling debug via
environment/config (e.g., read an environment variable like FLASK_ENV or a
config flag) so production runs never start with debug enabled.
# Save run to registry | ||
try: | ||
registry = get_registry() | ||
run_config = { | ||
**data, | ||
'generation_type': 'img2img', | ||
'workflow': workflow, | ||
'workflow_version': '1.0.0', | ||
'output_images': comfy_response.get("all_images", []) | ||
} | ||
run_id = registry.save_run(run_config) | ||
logger.info(f"✅ Run saved with ID: {run_id}") | ||
except Exception as save_error: | ||
logger.warning(f"⚠️ Failed to save run: {str(save_error)}") | ||
# Don't fail the request if saving fails | ||
======= |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix syntax error in try-except block
There's a syntax error at line 202 where the try block is not properly closed. The =======
appears to be a merge conflict marker that wasn't resolved.
# Save run to registry
try:
registry = get_registry()
run_config = {
**data,
'generation_type': 'img2img',
'workflow': workflow,
'workflow_version': '1.0.0',
'output_images': comfy_response.get("all_images", [])
}
run_id = registry.save_run(run_config)
logger.info(f"✅ Run saved with ID: {run_id}")
except Exception as save_error:
logger.warning(f"⚠️ Failed to save run: {str(save_error)}")
# Don't fail the request if saving fails
-=======
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
# Save run to registry | |
try: | |
registry = get_registry() | |
run_config = { | |
**data, | |
'generation_type': 'img2img', | |
'workflow': workflow, | |
'workflow_version': '1.0.0', | |
'output_images': comfy_response.get("all_images", []) | |
} | |
run_id = registry.save_run(run_config) | |
logger.info(f"✅ Run saved with ID: {run_id}") | |
except Exception as save_error: | |
logger.warning(f"⚠️ Failed to save run: {str(save_error)}") | |
# Don't fail the request if saving fails | |
======= | |
# Save run to registry | |
try: | |
registry = get_registry() | |
run_config = { | |
**data, | |
'generation_type': 'img2img', | |
'workflow': workflow, | |
'workflow_version': '1.0.0', | |
'output_images': comfy_response.get("all_images", []) | |
} | |
run_id = registry.save_run(run_config) | |
logger.info(f"✅ Run saved with ID: {run_id}") | |
except Exception as save_error: | |
logger.warning(f"⚠️ Failed to save run: {str(save_error)}") | |
# Don't fail the request if saving fails |
🧰 Tools
🪛 Ruff (0.12.2)
202-202: SyntaxError: Expected except
or finally
after try
block
202-202: SyntaxError: Expected a statement
202-202: SyntaxError: Expected a statement
202-202: SyntaxError: Expected a statement
🤖 Prompt for AI Agents
In dream_layer_backend/img2img_server.py around lines 187 to 202 there is an
unresolved merge conflict marker ("=======") inside the try/except that breaks
syntax; remove the conflict marker and any surrounding conflict markers (e.g.
<<<<<<<, >>>>>>>) so the try block and except block are properly closed and
indented, ensuring the except body (logging the save_error) remains and
execution continues as intended; then run a quick lint or run the module to
confirm no syntax errors remain.
This feature allows users to:
Description
Brief description of what this PR does.
Changes Made
Evidence Required ✅
UI Screenshot
Generated Image
Logs
Tests (Optional)
Checklist
Summary by Sourcery
Introduce a Run Registry to persist and manage image generation runs across the system
New Features:
Enhancements:
Tests:
Summary by CodeRabbit