docs(genlayer-py-std): clarify unpack_result vs run_nondet return values - #11
Open
ygd58 wants to merge 1 commit into
Open
docs(genlayer-py-std): clarify unpack_result vs run_nondet return values#11ygd58 wants to merge 1 commit into
ygd58 wants to merge 1 commit into
Conversation
run_nondet() and run_nondet_default() already return the plain decoded
leader value (they internally call unpack_result() on the RunNondet
sub-vm result before returning), unlike spawn_sandbox() which returns a
raw Result that still needs unpack_result().
Calling unpack_result() a second time on a run_nondet(_default) return
value crashes with:
AttributeError: 'dict' object has no attribute 'calldata'
because the value has already been unwrapped and is a plain object,
not a Return/Result wrapper.
This is easy to get wrong because validator_fn *does* receive a proper
Result (with .calldata, isinstance(x, Return) works) for both
functions - only the final return value differs. Clarified the
docstrings of run_nondet, run_nondet_default, and unpack_result to
make the asymmetry explicit and cross-reference each other.
No behavior change - docstrings only.
Addresses the confusion reported in genlayerlabs/genvm#322 (that repo
is archived/moved here, so filed against the current source location).
📝 WalkthroughWalkthroughVM documentation now clarifies that ChangesVM result-unwrapping documentation
Estimated code review effort: 1 (Trivial) | ~3 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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 |
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
Fixes the confusion reported in genlayerlabs/genvm#322 — that repo is archived and moved here, so filing the fix against the current source location.
gl.vm.unpack_result(gl.vm.run_nondet_unsafe(leader_fn, validator_fn))(or the currentrun_nondet/run_nondet_default) crashes with:Root cause
run_nondetandrun_nondet_defaultboth go through_decode_sub_vm_result, which already callsunpack_result()internally before returning — so their return value is the plain decoded leader value, not aResult/Returnwrapper. Callingunpack_result()on it again crashes, since a plaindict/int/etc. has no.calldataattribute.This is easy to get wrong because the validator_fn callback does receive a proper
Result(with.calldata,isinstance(x, Return)works as expected) for both functions — only the final return value is already unwrapped. The asymmetry isn't obvious from the API surface.This is not a behavior bug —
run_nondet/run_nondet_defaultare working as designed, and changing their return type would break every existing caller that (correctly) uses the value directly, as already shown inrun_nondet_default's own docstring example. The actionable fix is documentation clarity, per the issue's own "Ask".Change
Docstring-only, no behavior change:
run_nondet: explicitly states the return value is already unwrapped and must not be passed tounpack_result()again; notes the validator_fn/return-value asymmetry.run_nondet_default: same clarification, cross-referencingrun_nondet.unpack_result: added a note on which vm functions' outputs need it (spawn_sandbox,validator_fnresults) versus which don't (run_nondet,run_nondet_defaultreturn values).Note:
genvm#322lives in the now-archivedgenlayerlabs/genvmrepo, which is read-only, so I couldn't comment there directly — linking it here instead.Summary by CodeRabbit
unpack_result.