Skip to content

refactor(lease): Remove Arc::get_mut anti-pattern from lease injection #211

Closed

Description

@JoshuaChi

Problem

Current lease injection in NodeBuilder::build() uses Arc::get_mut() pattern which is fragile:

// d-engine-server/src/node/builder.rs#L234-259
let mut state_machine: Arc<SM> = self.state_machine.take()?;

if let Some(sm) = Arc::get_mut(&mut state_machine) {
    sm.try_inject_lease(lease_config)?;
} else {
    // CRITICAL error if Arc is cloned
    return Err("State machine Arc must have single ownership");
}

Issues:

  1. Logical contradiction: Comment says "injected before Arc wrapping", but state_machine is already Arc<SM>
  2. Fragile API: Fails with CRITICAL error if Arc is cloned before build()
  3. Anti-pattern: Violates Rust ownership - shouldn't mutate after Arc wrapping

Activity

  1. added this to the v0.2.0 milestone on Dec 20, 2025
  2. added
    type:refactorCode restructuring without changing external behavior
    on Dec 20, 2025
  3. added theissue type on Dec 20, 2025
  4. coderabbitai commented on Dec 20, 2025

    @coderabbitai

    📝 CodeRabbit Plan Mode

    Generate an implementation plan and prompts that you can use with your favorite coding agent.

    • Create Plan
    Examples

    🔗 Similar Issues

    Related Issues

    👤 Suggested Assignees

    🧪 Issue enrichment is currently in open beta.

    You can configure auto-planning by selecting labels in the issue_enrichment configuration.

    To disable automatic issue enrichment, add the following to your .coderabbit.yaml:

    issue_enrichment:
      auto_enrich:
        enabled: false

    💬 Have feedback or questions? Drop into our discord or schedule a call!

  5. added 2 commits that reference this issue on Dec 20, 2025
  6. added 2 commits that reference this issue on Dec 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type:refactorCode restructuring without changing external behavior

    Type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions