fix startup #42

Open
opened 2026-04-03 06:00:33 +00:00 by despiegk · 1 comment
Owner

check how we start all components in heroledger

and make sure we use hero_proc properly

use skills

/hero_proc_service_selfstart
/hero_crates_best_practices_check

check how we start all components in heroledger and make sure we use hero_proc properly use skills /hero_proc_service_selfstart /hero_crates_best_practices_check
Author
Owner

Implementation Spec for Issue #42 — Fix Startup (hero_proc selfstart pattern)

Objective

Replace the current ad-hoc startup model (where heroledger gateway runs the gateway inline inside the CLI process) with the canonical hero_proc_service_selfstart pattern. The heroledger CLI binary gains dedicated start and stop subcommands that register and manage the heroledger_gateway process via the hero_proc supervisor.


Current State

Component File Current behaviour
heroledger CLI src/bin/heroledger.rs Has Commands::Gateway which runs the gateway inline in the CLI process (blocking)
Gateway inline launcher src/cli/cli/execute.rs execute_gateway() Calls run_gateway() directly — no hero_proc
heroledger_gateway daemon src/bin/heroledger_gateway.rs Standalone binary — starts Axum server
Provisioning (zinit) src/provision/gateway_service.rs Registers/starts the gateway via zinit SDK
hero_proc Cargo.toml Not a dependency at all

Requirements

  • Add hero_proc_sdk as an optional dependency, activated by the cli feature
  • Add heroledger start and heroledger stop subcommands to the CLI
  • heroledger start: connect to hero_proc, register heroledger_gateway action, start it
  • heroledger stop: connect to hero_proc and stop the service
  • heroledger_gateway daemon must NOT call hero_proc on startup (already clean)
  • Remove the Commands::Gateway inline-runner (superseded by start)
  • Health check via tcp_port: Some(9090) (HTTP port the gateway exposes)

Files to Modify

File Change
Cargo.toml Add hero_proc_sdk optional dep, pull into cli feature
src/cli/cli/mod.rs Add Start and Stop variants; remove Gateway variant
src/cli/cli/execute.rs Add execute_start() and execute_stop(); remove execute_gateway()
src/bin/heroledger.rs Wire Start/Stop arms; remove Gateway arm

Implementation Plan

Step 1 — Add hero_proc_sdk to Cargo.toml

Add as optional dep in [dependencies]:

hero_proc_sdk = { git = "https://forge.ourworld.tf/lhumina_code/hero_proc.git", branch = "development", optional = true }

Pull into cli feature in [features].

Dependencies: none

Step 2 — Add Start/Stop commands to CLI enum + wire main()

File: src/cli/cli/mod.rs — add Start and Stop variants; remove Gateway variant.
File: src/bin/heroledger.rs — add explicit Commands::Start and Commands::Stop arms calling execute_start()/execute_stop() via a tokio runtime; remove Commands::Gateway arm.

Dependencies: Step 1

Step 3 — Implement execute_start and execute_stop

File: src/cli/cli/execute.rs — add service definition builder (using current_exe() for binary path, tcp_port: Some(9090) for health check), execute_start(), execute_stop(); remove execute_gateway().

Dependencies: Step 1


Acceptance Criteria

  • cargo build --features cli succeeds with no errors
  • heroledger start registers heroledger_gateway with hero_proc and starts it
  • heroledger stop stops the service
  • heroledger_gateway does not import hero_proc_sdk
  • heroledger gateway command is removed
  • heroledger --help shows start and stop
  • Gateway process stays alive after heroledger start exits (supervised by hero_proc)
  • cargo build --no-default-features still compiles (no accidental hero_proc_sdk pull)
  • Running heroledger start twice is idempotent (no error)

Notes

  • Why remove Commands::Gateway? Inline runner requires CLI to stay alive; not supervised. The standalone heroledger_gateway binary is the correct artifact.
  • No HeroNearCmd needed for start/stop — they only need the hero_proc socket, not RPC URLs.
  • Binary path discovery: Use std::env::current_exe()?.parent() to find sibling heroledger_gateway binary.
  • Provisioning/zinit path (src/provision/gateway_service.rs) is a separate concern — do not touch it.
  • Reference: Mirror the pattern in hero_inspector CLI binary for start/stop structure.
## Implementation Spec for Issue #42 — Fix Startup (hero_proc selfstart pattern) ### Objective Replace the current ad-hoc startup model (where `heroledger gateway` runs the gateway inline inside the CLI process) with the canonical `hero_proc_service_selfstart` pattern. The `heroledger` CLI binary gains dedicated `start` and `stop` subcommands that register and manage the `heroledger_gateway` process via the `hero_proc` supervisor. --- ### Current State | Component | File | Current behaviour | |---|---|---| | `heroledger` CLI | `src/bin/heroledger.rs` | Has `Commands::Gateway` which runs the gateway **inline** in the CLI process (blocking) | | Gateway inline launcher | `src/cli/cli/execute.rs` `execute_gateway()` | Calls `run_gateway()` directly — no hero_proc | | `heroledger_gateway` daemon | `src/bin/heroledger_gateway.rs` | Standalone binary — starts Axum server | | Provisioning (zinit) | `src/provision/gateway_service.rs` | Registers/starts the gateway via zinit SDK | | hero_proc | `Cargo.toml` | **Not a dependency at all** | --- ### Requirements - Add `hero_proc_sdk` as an optional dependency, activated by the `cli` feature - Add `heroledger start` and `heroledger stop` subcommands to the CLI - `heroledger start`: connect to hero_proc, register `heroledger_gateway` action, start it - `heroledger stop`: connect to hero_proc and stop the service - `heroledger_gateway` daemon must NOT call hero_proc on startup (already clean) - Remove the `Commands::Gateway` inline-runner (superseded by `start`) - Health check via `tcp_port: Some(9090)` (HTTP port the gateway exposes) --- ### Files to Modify | File | Change | |---|---| | `Cargo.toml` | Add `hero_proc_sdk` optional dep, pull into `cli` feature | | `src/cli/cli/mod.rs` | Add `Start` and `Stop` variants; remove `Gateway` variant | | `src/cli/cli/execute.rs` | Add `execute_start()` and `execute_stop()`; remove `execute_gateway()` | | `src/bin/heroledger.rs` | Wire `Start`/`Stop` arms; remove `Gateway` arm | --- ### Implementation Plan #### Step 1 — Add `hero_proc_sdk` to `Cargo.toml` Add as optional dep in `[dependencies]`: ```toml hero_proc_sdk = { git = "https://forge.ourworld.tf/lhumina_code/hero_proc.git", branch = "development", optional = true } ``` Pull into `cli` feature in `[features]`. **Dependencies:** none #### Step 2 — Add `Start`/`Stop` commands to CLI enum + wire `main()` File: `src/cli/cli/mod.rs` — add `Start` and `Stop` variants; remove `Gateway` variant. File: `src/bin/heroledger.rs` — add explicit `Commands::Start` and `Commands::Stop` arms calling `execute_start()`/`execute_stop()` via a tokio runtime; remove `Commands::Gateway` arm. **Dependencies:** Step 1 #### Step 3 — Implement `execute_start` and `execute_stop` File: `src/cli/cli/execute.rs` — add service definition builder (using `current_exe()` for binary path, `tcp_port: Some(9090)` for health check), `execute_start()`, `execute_stop()`; remove `execute_gateway()`. **Dependencies:** Step 1 --- ### Acceptance Criteria - [ ] `cargo build --features cli` succeeds with no errors - [ ] `heroledger start` registers `heroledger_gateway` with hero_proc and starts it - [ ] `heroledger stop` stops the service - [ ] `heroledger_gateway` does not import `hero_proc_sdk` - [ ] `heroledger gateway` command is removed - [ ] `heroledger --help` shows `start` and `stop` - [ ] Gateway process stays alive after `heroledger start` exits (supervised by hero_proc) - [ ] `cargo build --no-default-features` still compiles (no accidental hero_proc_sdk pull) - [ ] Running `heroledger start` twice is idempotent (no error) --- ### Notes - **Why remove `Commands::Gateway`?** Inline runner requires CLI to stay alive; not supervised. The standalone `heroledger_gateway` binary is the correct artifact. - **No `HeroNearCmd` needed for start/stop** — they only need the hero_proc socket, not RPC URLs. - **Binary path discovery:** Use `std::env::current_exe()?.parent()` to find sibling `heroledger_gateway` binary. - **Provisioning/zinit path** (`src/provision/gateway_service.rs`) is a separate concern — do not touch it. - **Reference:** Mirror the pattern in `hero_inspector` CLI binary for `start`/`stop` structure.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
lhumina_code/hero_ledger#42
No description provided.