Repository navigation
fix: genvm invalid contract error - #1363
Conversation
WalkthroughAdds a Claude plugin config, reduces ConsensusWorker transaction timeout to 20 minutes, propagates Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
backend/consensus/worker_service.py (1)
64-64: Captured return code is unused.
_pkill_rccaptures the return code but it's never used. The underscore prefix suggests intentional non-use, but per the PR summary, this was added "for observability." Consider logging the return code if observability was the intent.- _pkill_rc = os.system("pkill -9 -f 'genvm (llm|web)' 2>/dev/null || true") - logger.info("GenVM cleanup complete") + pkill_rc = os.system("pkill -9 -f 'genvm (llm|web)' 2>/dev/null || true") + logger.info(f"GenVM cleanup complete (exit code: {pkill_rc})")backend/consensus/worker.py (1)
45-45: Mismatch between parameter default and environment variable default.The
transaction_timeout_minutesparameter defaults to 20 minutes, but theTRANSACTION_TIMEOUT_MINUTESenvironment variable in docker-compose.yml defaults to 30 minutes. When running via docker-compose, the environment variable takes precedence, but these inconsistent code-level defaults can cause confusion. Align the parameter default to 20 to match the code intent, or change it to 30 for consistency with docker-compose configuration.
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
.claude/settings.json(1 hunks)backend/consensus/worker.py(7 hunks)backend/consensus/worker_service.py(4 hunks)backend/node/base.py(1 hunks)docker-compose.yml(1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.py
📄 CodeRabbit inference engine (CLAUDE.md)
Use Black formatter for Python code
Target Python 3.12, use 4-space indentation, and rely on Black via pre-commit for formatting consistency
Files:
backend/consensus/worker.pybackend/node/base.pybackend/consensus/worker_service.py
backend/**/*.py
📄 CodeRabbit inference engine (CLAUDE.md)
backend/**/*.py: Include type hints in Python code
Use SQLAlchemy ORM with Alembic migrations for database operationsAlign backend filenames with their behavior (e.g.,
validators/llm_validator.py) and mirror that pattern in tests
Files:
backend/consensus/worker.pybackend/node/base.pybackend/consensus/worker_service.py
docker-compose*.{yml,yaml}
📄 CodeRabbit inference engine (CLAUDE.md)
Use Docker Compose for orchestrating microservices (genlayer up/down commands)
Files:
docker-compose.yml
🧠 Learnings (1)
📚 Learning: 2025-12-04T13:40:37.336Z
Learnt from: CR
Repo: genlayerlabs/genlayer-studio PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-04T13:40:37.336Z
Learning: Applies to docker-compose*.{yml,yaml} : Use Docker Compose for orchestrating microservices (genlayer up/down commands)
Applied to files:
docker-compose.yml
🧬 Code graph analysis (1)
backend/consensus/worker_service.py (2)
backend/node/genvm/origin/logger.py (1)
error(23-24)backend/protocol_rpc/message_handler/fastapi_handler.py (1)
error(156-165)
🪛 Ruff (0.14.8)
backend/consensus/worker_service.py
64-64: Starting a process with a shell: seems safe, but may be changed in the future; consider rewriting without shell
(S605)
64-64: Starting a process with a partial executable path
(S607)
371-371: Do not catch blind exception: Exception
(BLE001)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: backend-unit-tests
🔇 Additional comments (8)
backend/node/base.py (1)
695-695: LGTM! Timeout increase for schema retrieval is appropriate.The 6x increase from 5s to 30s provides adequate headroom for GenVM schema retrieval during latency spikes, aligning with the PR's reliability improvements.
.claude/settings.json (1)
1-7: Configuration file for Claude plugins looks reasonable.This enables official Claude plugins for code review, feature development, and hookify. While unrelated to the GenVM debugging objective of this PR, the configuration is valid.
backend/consensus/worker.py (3)
161-161: LGTM!blocked_atfield properly added to finalization claim.The field is correctly selected in the SQL RETURNING clause and mapped to the returned dictionary.
267-268: LGTM!blocked_atfield properly added to appeal claim.Consistent with the finalization claim changes.
370-370: LGTM!blocked_atfield properly added to transaction claim.All three claim methods now consistently return the
blocked_atfield for health check monitoring.backend/consensus/worker_service.py (2)
344-356: LGTM! Robustblocked_atparsing handles both string and datetime types.The parsing logic correctly handles ISO strings (with
Zsuffix) and datetime objects, normalizing to naive UTC for consistent comparison. This aligns with the worker.py changes that now returnblocked_atfrom SQL queries.
371-374: Exception handling is appropriate for defensive parsing.Logging the error without failing the health check is reasonable here—a parsing failure shouldn't mark the pod as unhealthy. The bare
Exceptioncatch is acceptable given the context.docker-compose.yml (1)
93-93: GenVM v0.2.7 is a documented, official release and correctly configured.The version bump from v0.2.4 to v0.2.7 is properly implemented in both docker-compose.yml (line 93) and Dockerfile.backend, which download the binaries from the official genlayerlabs/genvm GitHub releases. The environment variable is correctly passed through and used for multi-platform binary extraction.
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
backend/consensus/worker_service.py (1)
377-380: Consider more specific exception handling.While catching
Exceptionis defensive here, consider narrowing to specific exceptions likeValueError(for ISO parsing) andTypeError(for type issues) to avoid masking unexpected errors.Also, the
passstatement at line 380 is redundant since there's no code after the except block.- except Exception as e: + except (ValueError, TypeError, AttributeError) as e: # Log the error but don't fail the health check logger.error(f"Error parsing blocked_at timestamp: {e}") - pass
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
backend/consensus/worker_service.py(4 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.py
📄 CodeRabbit inference engine (CLAUDE.md)
Use Black formatter for Python code
Target Python 3.12, use 4-space indentation, and rely on Black via pre-commit for formatting consistency
Files:
backend/consensus/worker_service.py
backend/**/*.py
📄 CodeRabbit inference engine (CLAUDE.md)
backend/**/*.py: Include type hints in Python code
Use SQLAlchemy ORM with Alembic migrations for database operationsAlign backend filenames with their behavior (e.g.,
validators/llm_validator.py) and mirror that pattern in tests
Files:
backend/consensus/worker_service.py
🧬 Code graph analysis (1)
backend/consensus/worker_service.py (2)
backend/node/genvm/origin/logger.py (1)
error(23-24)backend/protocol_rpc/message_handler/fastapi_handler.py (1)
error(156-165)
🪛 Ruff (0.14.8)
backend/consensus/worker_service.py
64-64: Starting a process with a shell: seems safe, but may be changed in the future; consider rewriting without shell
(S605)
64-64: Starting a process with a partial executable path
(S607)
377-377: Do not catch blind exception: Exception
(BLE001)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: backend-unit-tests
🔇 Additional comments (1)
backend/consensus/worker_service.py (1)
64-64: Good observability improvement.Capturing the return code is a helpful addition for debugging, even if not currently used. The leading underscore convention appropriately signals the variable is intentionally unused.
Note: The static analysis warning about shell commands is a false positive here since the command string is fixed with no user input.
| blocked_at = tx["blocked_at"] | ||
|
|
||
| # Handle both datetime objects and ISO strings | ||
| if isinstance(blocked_at, str): | ||
| blocked_at = datetime.fromisoformat( | ||
| blocked_at.replace("Z", "+00:00") | ||
| ) | ||
|
|
||
| # Convert to naive UTC datetime for comparison | ||
| if blocked_at.tzinfo is not None: | ||
| blocked_at = blocked_at.replace(tzinfo=None) | ||
|
|
||
| elapsed = datetime.utcnow() - blocked_at | ||
|
|
||
| # Check if blocked for more than 10 minutes - pod is unhealthy | ||
| if elapsed.total_seconds() > 600: # 10 minutes = 600 seconds | ||
| return JSONResponse( | ||
| status_code=500, | ||
| content={ | ||
| "status": "unhealthy", | ||
| "worker_id": worker.worker_id, | ||
| "error": "Transaction blocked for more than 10 minutes", | ||
| "blocked_duration_seconds": elapsed.total_seconds(), | ||
| }, | ||
| ) |
There was a problem hiding this comment.
Replace datetime.utcnow() with datetime.now(timezone.utc) for Python 3.12 compliance.
datetime.utcnow() is deprecated in Python 3.12. Replace it with datetime.now(timezone.utc) at line 356. Import timezone from the datetime module.
Additionally, the current code converts parsed blocked_at to naive datetime. To align with Python 3.12 best practices, ensure blocked_at remains timezone-aware (UTC) throughout the function, then perform the subtraction with an aware datetime.now(timezone.utc). This eliminates the manual timezone stripping.
Add return type hints to health_check() per coding guidelines for backend Python code.
🤖 Prompt for AI Agents
In backend/consensus/worker_service.py around lines 344 to 368, the code uses
datetime.utcnow() and strips tzinfo from parsed blocked_at; update to keep
blocked_at timezone-aware (parse ISO strings into UTC-aware datetimes and do not
replace tzinfo=None) and replace datetime.utcnow() with
datetime.now(timezone.utc) so the subtraction is between two aware UTC
datetimes; add "from datetime import timezone" to imports and adjust parsing to
ensure blocked_at has tzinfo=timezone.utc when it's a string; also add an
appropriate return type hint to the health_check() function signature per
backend guidelines.
|
|
🎉 This PR is included in version 0.83.6 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |




Summary
Improves GenVM/consensus-worker reliability and health reporting by increasing timeouts, surfacing
blocked_atstate, and making the worker health check fail when a transaction is stuck too long.What changed
GENVM_TAGupdated from v0.2.4 → v0.2.7 indocker-compose.yml.backend/node/base.py.transaction_timeout_minutesreduced from 30 → 20 inbackend/consensus/worker.py.blocked_atis now selected and returned in worker transaction queries inbackend/consensus/worker.py.backend/consensus/worker_service.py):blocked_atas either ISO string or datetimeelapsed > 600s)pkillreturn code (for observability/debugging)Why
Testing / verification
/healthreportsblocked_atwhen present and returns 500 once the blocked duration exceeds the threshold.Summary by CodeRabbit
Bug Fixes
Chores
✏️ Tip: You can customize this high-level summary in your review settings.