Skip to content

Fix Envio init failure with long contract names - #905

Open
moose-code wants to merge 6 commits into
mainfrom
claude/fix-envio-contract-name-aOzyn
Open

Fix Envio init failure with long contract names#905
moose-code wants to merge 6 commits into
mainfrom
claude/fix-envio-contract-name-aOzyn

Conversation

@moose-code

@moose-code moose-code commented Jan 14, 2026

Copy link
Copy Markdown
Member

Entity names are formed as {contract_name}_{event_name} and must be <= 63 chars. Long contract names like InitializableImmutableAdminUpgradeabilityProxy were causing envio init to fail with "Entity name is too long" errors.

Added truncation logic to normalize_contract_name() to cap contract names at 30 characters, leaving 32 chars for event names plus 1 for the separator.

Closes #794

Summary by CodeRabbit

  • New Features

    • Contract names are now limited to 30 characters; longer names are automatically truncated.
    • Spaces, hyphens, and dots in contract names are converted to underscores for consistent naming.
    • Names that already meet the limit, including shorter and exact-length names, continue to be handled correctly.
  • Tests

    • Added coverage for contract-name normalization and truncation across long, exact-length, and short names.

Entity names are formed as {contract_name}_{event_name} and must be <= 63 chars.
Long contract names like InitializableImmutableAdminUpgradeabilityProxy were
causing envio init to fail with "Entity name is too long" errors.

Added truncation logic to normalize_contract_name() to cap contract names at
30 characters, leaving 32 chars for event names plus 1 for the separator.
@coderabbitai

coderabbitai Bot commented Jan 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Essentials

Run ID: 7950cad0-441b-424d-95f4-119e78320acd

📥 Commits

Reviewing files that changed from the base of the PR and between fd9f26c and 673581b.

📒 Files selected for processing (1)
  • packages/cli/src/config_parsing/contract_import/converters.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/cli/src/config_parsing/contract_import/converters.rs

Included review availability: Your plan provides up to 5 included reviews per hour; 2 remain after this review.


📝 Walkthrough

Walkthrough

MAX_CONTRACT_NAME_LENGTH is set to 30. normalize_contract_name now truncates normalized contract names that exceed this limit. Tests cover long, boundary-length, and short names.

Changes

Contract Name Normalization

Layer / File(s) Summary
Normalization and truncation
packages/cli/src/config_parsing/contract_import/converters.rs
Adds MAX_CONTRACT_NAME_LENGTH and applies it after separator replacement in normalize_contract_name. Documentation and tests cover the length boundary and truncation behavior.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 67358

Contract names are now capped before entity names are generated, preventing initialization failures from names exceeding the 63-character limit. The change is narrowly scoped and has coverage for truncation boundaries.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: preventing Envio initialization failures caused by long contract names.
Linked Issues check ✅ Passed The PR meets issue #794 by truncating normalized contract names to 30 characters. This keeps generated entity names within the 63-character limit when combined with the event name and separator. The a…
Out of Scope Changes check ✅ Passed The changes are within scope for issue #794. Name normalization, truncation, documentation, the public length constant, and related tests directly support the fix.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 2 files.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@codegenerator/cli/src/config_parsing/contract_import/converters.rs`:
- Around line 14-15: The truncation uses byte-based slicing on variable
normalized which can panic for multi-byte UTF-8 characters; change the logic to
truncate by Unicode scalar values instead (use
normalized.chars().take(MAX_CONTRACT_NAME_LENGTH).collect::<String>() or an
equivalent char-aware approach) so you measure and cut by characters rather than
bytes, and return that safe String when normalized exceeds
MAX_CONTRACT_NAME_LENGTH.
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5f59a68 and eb2d0bc.

📒 Files selected for processing (1)
  • codegenerator/cli/src/config_parsing/contract_import/converters.rs
⏰ 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: build_and_test
🔇 Additional comments (2)
codegenerator/cli/src/config_parsing/contract_import/converters.rs (2)

5-8: LGTM!

The constant is well-documented with clear rationale. The math correctly accounts for the 63-character limit (30 + 1 + 32 = 63).


176-191: LGTM!

Good test coverage for truncation behavior. Using the actual problematic contract name from the issue ("InitializableImmutableAdminUpgradeabilityProxy") validates the real-world fix.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

Comment on lines +14 to +15
if normalized.len() > MAX_CONTRACT_NAME_LENGTH {
normalized[..MAX_CONTRACT_NAME_LENGTH].to_string()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Potential panic if contract name contains multi-byte UTF-8 characters.

String::len() returns byte count and slicing operates on byte indices. If truncation occurs mid-character on a multi-byte UTF-8 string, this will panic. While contract names are typically ASCII, using character-based truncation would be safer.

Suggested safer truncation
-    if normalized.len() > MAX_CONTRACT_NAME_LENGTH {
-        normalized[..MAX_CONTRACT_NAME_LENGTH].to_string()
+    if normalized.chars().count() > MAX_CONTRACT_NAME_LENGTH {
+        normalized.chars().take(MAX_CONTRACT_NAME_LENGTH).collect()
     } else {
         normalized
     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if normalized.len() > MAX_CONTRACT_NAME_LENGTH {
normalized[..MAX_CONTRACT_NAME_LENGTH].to_string()
if normalized.chars().count() > MAX_CONTRACT_NAME_LENGTH {
normalized.chars().take(MAX_CONTRACT_NAME_LENGTH).collect()
} else {
normalized
}
🤖 Prompt for AI Agents
In `@codegenerator/cli/src/config_parsing/contract_import/converters.rs` around
lines 14 - 15, The truncation uses byte-based slicing on variable normalized
which can panic for multi-byte UTF-8 characters; change the logic to truncate by
Unicode scalar values instead (use
normalized.chars().take(MAX_CONTRACT_NAME_LENGTH).collect::<String>() or an
equivalent char-aware approach) so you measure and cut by characters rather than
bytes, and return that safe String when normalized exceeds
MAX_CONTRACT_NAME_LENGTH.

@coderabbitai

coderabbitai Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

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.

Envio init fails with contract name too long.

3 participants