Skip to content

fix(run): --id loads the configured provider before resolving the lease claim #1257

Description

@coygeek

Summary

crabbox run --id <lease-or-slug> can fail before resolving a healthy reusable lease when the
configured default provider differs from the provider recorded in the lease's local claim. The run
loads the configured provider first, so a missing credential for that unrelated provider prevents
reuse even though the exact claim already identifies the correct provider and the lease is ready.

This is a non-security lifecycle-routing bug. It was reproduced with a local-container lease while
the configured default was Hetzner with no Hetzner credential.

Steps to reproduce

  1. In a Git repository, configure or inherit provider=hetzner without setting HCLOUD_TOKEN or
    HETZNER_TOKEN.

  2. Create a reusable local-container lease:

    crabbox warmup \
      --provider local-container \
      --slug provider-resolution-repro \
      --os ubuntu:24.04
  3. Confirm the claim and lease are healthy:

    crabbox inspect \
      --provider local-container \
      --id provider-resolution-repro \
      --json

    The reproduced lease reported provider=local-container and state=leased with a ready SSH
    endpoint.

  4. From the same repository, use the documented run-by-ID form without repeating the provider:

    crabbox run --id provider-resolution-repro --no-sync -- true
    echo "exit=$?"
  5. Run the negative control against the same lease:

    crabbox run \
      --provider local-container \
      --id provider-resolution-repro \
      --no-sync \
      -- true
  6. Release the lease:

    crabbox stop \
      --provider local-container \
      --target linux \
      --id provider-resolution-repro

Expected behavior

When --id names an exact local claim for the current repository and the caller did not explicitly
select a provider, run should resolve the claim and use its recorded provider to reuse the lease.
An unrelated configured provider should not need to initialize successfully.

The red/green closure signal is:

  • with provider=hetzner configured and no Hetzner token, a claimed local-container lease succeeds
    through crabbox run --id <slug> --no-sync -- true without an explicit provider; and
  • an explicit --provider remains authoritative, while a new run without --id retains the normal
    configured-provider behavior.

Actual behavior

The run without --provider exits with status 3 before reaching the lease:

HCLOUD_TOKEN or HETZNER_TOKEN is required
exit=3

The negative control with --provider local-container reuses the same claim and lease successfully:

lease=cbx_98151bfa77b4 slug=provider-resolution-repro provider=local-container target=linux
running on 127.0.0.1 true
command complete

Affected area

  • internal/cli/run.go, particularly provider loading and reusable-lease resolution in
    runCommandWithBenchmarkRecord.
  • Local lease claims used by run --id to bind a lease to its repository and provider.
  • The provider-agnostic run --id examples and reuse contract in docs/commands/run.md.

Runtime or environment

  • Crabbox CLI: 0.40.0
  • Current source also inspected at main revision
    ce9487f552054326d9209d3ba9606d01a36f5666
  • Host: macOS ARM64
  • Container runtime: Docker client/server 29.6.2, Linux ARM64 server
  • Lease provider: local-container
  • Configured default provider: hetzner
  • Coordinator: not configured

Evidence

The current main implementation loads configuration, applies lease flags, and calls
loadBackend(cfg, ...) before reusable-lease resolution. When --provider is absent, the configured
Hetzner provider therefore initializes first and rejects the missing credential before the supplied
slug can resolve to its local-container claim.

The claim itself was valid: explicit-provider inspect returned a ready local-container lease, and
the explicit-provider control ran true on it successfully. The only changed input between the red
and green runs was --provider local-container.

docs/commands/run.md describes --id as reusing an existing lease and repeatedly demonstrates
crabbox run --id <slug> ... without a provider flag. The concepts documentation also says the local
claim is required for run --id to resolve slugs and enforce repository ownership.

Open and closed Crabbox issues and pull requests were searched on 2026-08-08 for run --id, provider
resolution, lease claims, configured defaults, and the Hetzner credential error. No report for this
exact run-by-ID failure was found.

Impact

Reusable lease handles are not self-sufficient when the user's configured provider changes or when a
lease was created with a one-command provider override. Documented run --id workflows can fail with
an opaque credential error for a provider unrelated to the target lease, forcing callers to remember
and repeat provider-specific routing state already present in the claim.

This affects automation and handoffs in particular: a stable lease ID or slug appears sufficient, but
the command can stop before inspecting it.

Additional context

This is distinct from these existing open issues:

The current workaround is to repeat the provider on every reused command:

crabbox run --provider local-container --id <lease-or-slug> -- <command>

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Normal priority bug or improvement with limited blast radius.clawsweeper:bulk-filedClawSweeper detected a high recent issue-filing volume from this author.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:otherThis issue has meaningful maintainer-visible impact outside the owned taxonomy.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions