Skip to content

fix(deploy): fail gracefully on execution error and validate contract address - #431

Open
Lesnak1 wants to merge 1 commit into
genlayerlabs:v0.40-devfrom
Lesnak1:fix/deploy-execution-error-and-missing-address
Open

Lesnak1 wants to merge 1 commit into
genlayerlabs:v0.40-devfrom
Lesnak1:fix/deploy-execution-error-and-missing-address

Conversation

@Lesnak1

@Lesnak1 Lesnak1 commented Oct 23, 2026 •

Copy link
Copy Markdown

Summary

Fixes #430.

When deploying a contract that fails to load (e.g. invalid_contract), consensus succeeds (consensus_data.status = 1 / FINALIZED), but execution fails (receipt.status = 5 / FINISHED_WITH_ERROR). Previously, genlayer deploy only checked consensus status before printing "Contract deployed successfully." and attempting to access receipt.contract_address, leading to misleading success output followed by TypeError: Cannot read properties of undefined (reading 'toLowerCase').

In addition, base64-encoded execution error payloads from the VM leader (e.g. AmludmFsaWRfY29udHJhY3Q= -> invalid_contract) were not decoded, obscuring the root cause from the developer.

Changes

  • Execution Error Payload Extraction & Decoding: Added extractExecutionErrorPayload(receipt) in src/commands/contracts/execution.ts to decode base64 leader execution payloads and GenVM stderr into readable strings.
  • Improved Failure Assertion: Updated assertSuccessfulExecution(receipt) to surface the decoded payload in the error message (e.g., Execution did not finish successfully: FINISHED_WITH_ERROR (payload: invalid_contract)).
  • Execution Result Normalization: Enhanced normalizeExecutionResult to handle TIMEOUT (numeric 3) and NONDET_DISAGREE (numeric 4), avoiding undefined returns.
  • Contract Address Assertion in Deploy Flow: Added explicit validation in src/commands/contracts/deploy.ts asserting that receipt.contract_address is defined before stopping spinner with success message. If absent or execution failed, it throws a clear error.
  • Regression Tests: Added unit tests in tests/actions/deploy.test.ts covering:
    1. Deployment consensus succeeded but execution returned error with invalid_contract payload.
    2. Deployment completing without a contract address.

Test plan

  • npx prettier --check "src/commands/contracts/execution.ts" "src/commands/contracts/deploy.ts" "tests/actions/deploy.test.ts": Passed (0 styling issues)
  • npx vitest run tests/actions/deploy.test.ts: 32/32 tests passed (including both new regression tests)
  • npx vitest run: 564/564 tests passed across the entire suite
  • npm run build: Production bundle (node scripts/run-esbuild.mjs production) compiled with 0 errors

Summary by CodeRabbit

  • Bug Fixes
    • Deployments that reach consensus without returning a contract address now report an error instead of appearing successful.
    • Execution errors provide more useful details when available, including reported timeout and disagreement errors.
    • Invalid contract responses are surfaced as deployment errors.

@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 32b28500-e884-41dd-9fc5-e655b26ad240
📥 Commits

Reviewing files that changed from the base of the PR and between 176b74a and d0b08de.

📒 Files selected for processing: 3
  • src/commands/contracts/deploy.ts
  • src/commands/contracts/execution.ts
  • tests/actions/deploy.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

📝 Walkthrough

Deployment errors now include available execution details. Deployment also fails if the transaction reaches consensus without returning a contract address.

Changes: Deployment failure reporting

Layer / File(s) Summary
Execution error diagnosis and payloads
src/commands/contracts/execution.ts
Execution diagnosis recognizes timeout and nondeterministic-disagreement results represented as strings or enum values. Failure messages include a payload extracted from GenVM stderr or the decoded receipt result.
Deployment validation and tests
src/commands/contracts/deploy.ts, tests/actions/deploy.test.ts
Deployment reports an error when no contract address is returned. Tests cover a decoded invalid_contract payload, a missing address, and fee-option allocation values.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: muncleuscles

Merge Risk: ⚪ Minimal · up to d0b08

A deployment without a contract address exits unsuccessfully. No actionable merge-blocking issue remains after normal checks.

Pre-merge checks: Passed 3 · Failed 1 · Inconclusive 1

Failed Failed checks: 1 warning · 1 inconclusive

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Linked Issues check Inconclusive [#430] Requirement: after deployment consensus, read the leader execution result. If it is not a success, show the payload, exit non-zero, and do not print a contract address as a successful deploymen… Confirm that BaseAction.failSpinner sets a non-zero process exit code (src/lib/actions/BaseAction.ts). Confirm that the two regression tests in tests/actions/deploy.test.ts assert the failing-payload case and the missing-address case.
Passed Passed checks: 3 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main changes: graceful handling of deployment execution errors and validation of the contract address.
Out of Scope Changes check Passed Changes map to #430:
- src/commands/contracts/execution.ts: adds extractExecutionErrorPayload, appends the payload to assertSuccessfulExecution messages, and adds TIMEOUT (3) and NONDET_DISAGREE (…
Full details: Out of Scope Changes check

Explanation

Changes map to #430:

  • src/commands/contracts/execution.ts: adds extractExecutionErrorPayload, appends the payload to assertSuccessfulExecution messages, and adds TIMEOUT (3) and NONDET_DISAGREE (4) handling in result normalization. These changes support the execution-result check the issue requests.
  • src/commands/contracts/deploy.ts: adds the contract-address assertion and the consensus-status log line. These changes are on the deploy success path the issue describes.
  • tests/actions/deploy.test.ts: adds the two regression tests for #430.

Two test-file edits are not explained by the PR description: the fee-options test now expects an expanded messageAllocations array, and the browser-wallet test spy setup was reformatted. Both edits are test-only. The summary shows no matching product code change for them, and no product behavior change is demonstrated. They are not tied to #430 in the PR text.

Full details: Linked Issues check

Explanation

[#430] Requirement: after deployment consensus, read the leader execution result. If it is not a success, show the payload, exit non-zero, and do not print a contract address as a successful deployment.

Implemented at head (src/commands/contracts/deploy.ts):

  • After waitForTransactionReceipt, assertSuccessfulExecution("Deployment", hash, result) runs before succeedSpinner. For a Studio receipt with consensus_data.leader_receipt[0].execution_result = "ERROR", transactionExecutionResult resolves FINISHED_WITH_ERROR, and the function throws. The success path is not reached.
  • extractExecutionErrorPayload (src/commands/contracts/execution.ts) decodes base64 genvm_result.result/result and strips leading control bytes. For AmludmFsaWRfY29udHJhY3Q=, the decoded value is invalid_contract. The error message includes (payload: invalid_contract).
  • A missing contract_address after consensus throws an explicit error.
  • The thrown errors reach the existing catch, which calls failSpinner("Error deploying contract", error). The address is not printed on these paths.

Unverified:

  • Non-zero exit. The exit status depends on BaseAction.failSpinner. The BaseAction.ts read was truncated before that method, so I could not confirm that it sets a non-zero exit code.
  • Regression tests in tests/actions/deploy.test.ts. I did not read the test file. The PR reports 32/32 deploy tests and 564/564 suite tests passing. I did not re-run them.
  • Non-Studio networks. The fallback txExecutionResultName path is handled in code, but its presence on the returned receipt is not established.

Resolution

Confirm that BaseAction.failSpinner sets a non-zero process exit code (src/lib/actions/BaseAction.ts). Confirm that the two regression tests in tests/actions/deploy.test.ts assert the failing-payload case and the missing-address case.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

… address

Fixes genlayerlabs#430 by ensuring that contract deployments check for leader execution errors, decode error payloads (e.g., invalid_contract), and verify contract address presence before reporting success.
@Lesnak1
Lesnak1 force-pushed the fix/deploy-execution-error-and-missing-address branch from 069dce1 to d0b08de Compare October 23, 2026 21:02
@Lesnak1

Lesnak1 commented Oct 23, 2026

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

This branch has not been deployed

No deployments
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.

1 participant