Repository navigation
feat: forward LLM error details to transaction receipts - #1441
Conversation
Add eager loading with selectinload for the triggered_transactions relationship in TransactionsProcessor methods that fetch multiple transactions and call _parse_transaction_data. This eliminates the N+1 query problem detected by Sentry (GENLAYER-STUDIO-NA). Methods updated: - get_activated_transactions_older_than - get_transactions_for_address - get_transactions_for_block (conditionally, only when include_full_tx) - get_newer_transactions - transactions_in_process_by_contract Fixes GENLAYER-STUDIO-NA Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…he transaction receipts
📝 WalkthroughWalkthroughThe PR introduces enhanced error context propagation through GenVM execution and consensus layers, adds structured error reporting with contextual metadata, optimizes database query performance via eager loading, refines error handling with improved diagnostic logging across multiple execution paths, and increases healthcheck resilience in Docker configuration. Changes
Sequence DiagramsequenceDiagram
participant GenVM as GenVM Execution
participant GenVMBase as genvm/base.py
participant ErrorCodes as error_codes.py
participant Consensus as Consensus Layer
participant Logger as Logging
GenVM->>GenVM: Execute (ModuleError occurs)
GenVM->>GenVMBase: Raise error with result_data
GenVMBase->>GenVMBase: Check if result_data is dict
alt result_data is dict
GenVMBase->>GenVMBase: Extract ctx, error_code, causes, is_fatal
else result_data is string
GenVMBase->>ErrorCodes: parse_ctx_from_module_error_string(error_str)
ErrorCodes->>ErrorCodes: Parse ModuleError format
ErrorCodes->>ErrorCodes: Extract primary_error, fallback_error
ErrorCodes->>ErrorCodes: Extract fields (status, model, provider, error_message)
ErrorCodes->>GenVMBase: Return ctx dict
GenVMBase->>GenVMBase: Derive ctx from string parsing
end
GenVMBase->>GenVMBase: Create GenVMInternalError(ctx=ctx, ...)
GenVMBase->>Consensus: Raise GenVMInternalError with ctx
Consensus->>Consensus: Build internal error receipt
Consensus->>Logger: Log GenVMInternalError
Logger->>Logger: Include ctx in log output
Consensus->>Consensus: Update transaction status (with propagated context)
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 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: 2
🤖 Fix all issues with AI agents
In `@backend/node/genvm/base.py`:
- Around line 200-201: Remove the unused alias import "from loguru import logger
as _ilog" (symbol _ilog) in base.py; either delete that import line or replace
it with the intended logger usage (e.g., use the existing logger variable
instead of introducing _ilog) so there are no unused imports left.
In `@backend/node/llm.lua`:
- Around line 218-233: The code may index a nil as_user_error.ctx when
evaluating llm.overloaded_statuses[as_user_error.ctx.status]; to fix, capture
the context safely (e.g. local ctx = as_user_error.ctx) and use a guarded status
lookup (local status = ctx and ctx.status) before referencing it, update
error_info.status with that safe status, and only index llm.overloaded_statuses
when status is non-nil; ensure the lib.log calls use the safe ctx/status
variables and keep existing branches (as_user_error present vs nil) intact.
| from loguru import logger as _ilog | ||
|
|
There was a problem hiding this comment.
Unused import: _ilog is imported but never referenced.
from loguru import logger as _ilog on Line 200 appears to be a debug leftover — it's not used anywhere in this block.
🧹 Proposed fix
- from loguru import logger as _ilog
-
error_ctx = None🤖 Prompt for AI Agents
In `@backend/node/genvm/base.py` around lines 200 - 201, Remove the unused alias
import "from loguru import logger as _ilog" (symbol _ilog) in base.py; either
delete that import line or replace it with the intended logger usage (e.g., use
the existing logger variable instead of introducing _ilog) so there are no
unused imports left.
| local as_user_error = lib.rs.as_user_error(result) | ||
| if as_user_error ~= nil then | ||
| error_info.status = as_user_error.ctx and as_user_error.ctx.status or nil | ||
| error_info.error_message = tostring(result) | ||
| if as_user_error.ctx and as_user_error.ctx.body then | ||
| error_info.body = as_user_error.ctx.body | ||
| end | ||
| if llm.overloaded_statuses[as_user_error.ctx.status] then | ||
| lib.log{level = "warning", message = "service is overloaded", error = as_user_error, request = request} | ||
| else | ||
| lib.log{level = "warning", message = "provider failed", error = as_user_error, request = request} | ||
| end | ||
| else | ||
| error_info.error_message = tostring(result) | ||
| lib.log{level = "warning", message = "provider failed with unexpected error", error = tostring(result), request = request} | ||
| end |
There was a problem hiding this comment.
Potential nil dereference on as_user_error.ctx at Line 225.
Lines 220 and 222 guard against nil ctx (as_user_error.ctx and ...), but Line 225 accesses as_user_error.ctx.status without a nil check. If as_user_error.ctx is nil, this will throw a Lua "attempt to index a nil value" error, breaking the error info construction.
🐛 Proposed fix — add nil guard
- if llm.overloaded_statuses[as_user_error.ctx.status] then
+ if as_user_error.ctx and llm.overloaded_statuses[as_user_error.ctx.status] then🤖 Prompt for AI Agents
In `@backend/node/llm.lua` around lines 218 - 233, The code may index a nil
as_user_error.ctx when evaluating
llm.overloaded_statuses[as_user_error.ctx.status]; to fix, capture the context
safely (e.g. local ctx = as_user_error.ctx) and use a guarded status lookup
(local status = ctx and ctx.status) before referencing it, update
error_info.status with that safe status, and only index llm.overloaded_statuses
when status is non-nil; ensure the lib.log calls use the safe ctx/status
variables and keep existing branches (as_user_error present vs nil) intact.
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
backend/node/genvm/base.py (1)
199-238:⚠️ Potential issue | 🔴 Critical
NameErrorwhenresult_datais adict:error_stris only assigned in theelsebranch.When
res.result_datais adict(Line 205 branch), execution skips Line 212 whereerror_stris assigned, but Line 238 unconditionally referenceserror_str[:1000]. This will crash with aNameErrorinstead of properly raisingGenVMInternalError.🐛 Proposed fix
elif res.result_kind == ResultCode.INTERNAL_ERROR: - from loguru import logger as _ilog - error_ctx = None + error_str = str(res.result_data) # Try to extract structured data if result_data is a dict if isinstance(res.result_data, dict):This ensures
error_stris always defined before it's used at Line 238. It also removes the unused_ilogimport (see below).
|
I'm not sure those errors belong in the receipt, I think logs is the right place
|
You are right, the intention here is to be able to access them fast in the studio explorer |
Removed from the first level of the receipt and also fixed a race condition in the triggered transactions integration tests due to the query optimization that you did recently |
|
🎉 This PR is included in version 0.100.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
What
llm.luato capture structured error info (HTTP status, model, provider, error message) from LLM provider failures and pass it throughlib.rs.user_error()ctxparse_ctx_from_module_error_string()parser inerror_codes.pyto extractprimary_error/fallback_errorfrom the Rust debug format string that GenVM produces forINTERNAL_ERRORctxfield toGenVMInternalErrorexception so error context flows through the Python exception chain_extract_llm_error_result()toReceiptto surface LLM errors asllm_error_resultin the transaction receipt dictraw_errorconstruction innode/base.pyto includectxand use correct"fatal"keyWhy
result_dataarrives as a Rust debug format string (not a Python dict), so the structured ctx containing error details was silently discarded.Testing done
parse_ctx_from_module_error_stringcovering: field extraction, nested Maps, escaped quotes, Nil values, integer status conversionDecisions made
Map({...})content from Rust debug strings, since nested structures break regex-based approachesstatus,model,provider,error_messagefields — these are the actionable fields users need. Thebodyfield (which may contain large nested error payloads) is deliberately excluded fromllm_error_resultllm_error_resultfield isNonewhen no LLM errors occur, keeping receipts clean for successful transactionsChecks
Reviewing tips
backend/node/llm.luato see how error info is now captured at the sourceerror_codes.py(parser) →genvm/base.py(provide_result) →node/base.py(receipt construction) →types.py(receipt serialization)error_codes.pyis the core new logic — the test cases show the format clearlyUser facing release notes
llm_error_result) when a validator's LLM provider fails, showing the HTTP status code, provider name, model, and error message🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes
New Features
Improvements