Skip to content

Update from task cef5c1dc-60ce-4986-87db-30725a46661f - #135

Open
cvsz wants to merge 2 commits into
mainfrom
codeql-security-alerts-6661f
Open

Update from task cef5c1dc-60ce-4986-87db-30725a46661f#135
cvsz wants to merge 2 commits into
mainfrom
codeql-security-alerts-6661f

Conversation

@cvsz

@cvsz cvsz commented Jul 19, 2026

Copy link
Copy Markdown
Owner

This PR was created by qwen-chat coder for task cef5c1dc-60ce-4986-87db-30725a46661f.

Key features implemented:
- Updated .gitignore to include more comprehensive ignore patterns for temp files, compressed archives, compiled files, and IDE-specific files
- Fixed potential illegal raise in ai/retry.py by replacing unreachable raise statement with proper error handling
- Addressed potentially uninitialized local variable in services/.../v1/routes.py by ensuring variable assignment before use
- Fixed writable file handle closure without error handling in Go files by adding proper defer and error checking
- Resolved file not always closed warnings in Python files by implementing proper context managers and exception handling
- Corrected module import duplication issues in test files by standardizing import styles
- Improved file operation safety across multiple services by adding try/finally blocks and proper resource management
- Enhanced error handling in file operations within gRPC and API route handlers

The changes significantly improve code safety by addressing resource leaks, uninitialized variables, and improper error handling patterns identified by CodeQL, while maintaining existing functionality.
@ecc-tools

ecc-tools Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

ECC bundle files are already tracked in this repository. Skipping generation of another bundle PR.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors file handling across several Python files to use context managers, improves error handling during file closing in Go, cleans up the .gitignore file, and introduces chunk-based request body parsing in the upload routes. The review feedback highlights a potential division-by-zero error and negative ETA calculations in the gRPC upload progress stream, and suggests a more robust, idiomatic approach to parsing the request body in the API routes instead of relying on fragile locals() checks.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

total_chunks = session.get('total_chunks', 1)

bytes_transferred = chunks_received * chunk_size
percent_complete = (chunks_received / total_chunks) * 100

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

If total_chunks is 0 (which can happen if total_size is 0), this will raise a ZeroDivisionError. Guard against division by zero by checking if total_chunks > 0.

Suggested change
percent_complete = (chunks_received / total_chunks) * 100
percent_complete = (chunks_received / total_chunks) * 100 if total_chunks > 0 else 100.0

Comment on lines +246 to +249
body = await request.body()
import json
data = json.loads(body.decode('utf-8'))
chunk_index_val = data.get("chunk_index") if data else None

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Checking locals() or conditionally parsing the request body in multiple places is fragile and unidiomatic. Instead of checking 'data' not in locals(), we can safely retrieve data from locals() and parse the body only if it hasn't been parsed yet.

Suggested change
body = await request.body()
import json
data = json.loads(body.decode('utf-8'))
chunk_index_val = data.get("chunk_index") if data else None
data = locals().get('data')
if data is None:
body = await request.body()
import json
data = json.loads(body.decode('utf-8')) if body else {}
chunk_index_val = data.get("chunk_index") if data else None

Comment on lines +263 to +267
if 'data' not in locals():
body = await request.body()
import json
data = json.loads(body.decode('utf-8'))
chunk_hash_val = data.get("chunk_hash") if data else None

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Checking 'data' not in locals() is fragile and unidiomatic. We can safely retrieve data from locals() and parse the body only if it hasn't been parsed yet.

Suggested change
if 'data' not in locals():
body = await request.body()
import json
data = json.loads(body.decode('utf-8'))
chunk_hash_val = data.get("chunk_hash") if data else None
data = locals().get('data')
if data is None:
body = await request.body()
import json
data = json.loads(body.decode('utf-8')) if body else {}
chunk_hash_val = data.get("chunk_hash") if data else None

chunk_size = session.get('chunk_size', 1024 * 1024)
total_chunks = session.get('total_chunks', 1)

bytes_transferred = chunks_received * chunk_size

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If the last chunk is smaller than chunk_size, chunks_received * chunk_size can exceed total_size, leading to a negative remaining_bytes and negative eta_seconds. Cap bytes_transferred at total_size.

Suggested change
bytes_transferred = chunks_received * chunk_size
bytes_transferred = min(chunks_received * chunk_size, total_size)

@cvsz

cvsz commented Jul 30, 2026

Copy link
Copy Markdown
Owner Author

@qwen-intl fixed all

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