Defat hero_rpc_osis: gate legacy RPC server, redis, and herolib_ai behind features #22

Open
opened 2026-04-17 10:24:24 +00:00 by timur · 0 comments
Owner

Problem

Every Hero service that uses hero_rpc_server transitively compiles heavy dependencies it never uses:

  • redis + deadpool-redis — not used (OServer uses filesystem storage, not Redis)
  • herolib_ai — only used by the legacy AxumRpcServer mock data generator in osis/src/rpc/server.rs
  • The old AxumRpcServer (3200+ lines in rpc/server.rs) — completely superseded by hero_rpc_server::OServer

Dependency chain today

hero_books / hero_voice / hero_logic / hero_osis / ...
  -> hero_rpc_server
    -> hero_rpc_osis features=["rpc"]
      -> redis, deadpool-redis, herolib_ai, axum, tower, tower-http, hyper, ...

The server crate only needs a few traits and types from osis::rpc:

  • OsisAppRpcHandler, OsisDomainInit (from handler.rs, osis_app_bridge.rs)
  • RequestContext (from request_context.rs)
  • JsonRpcRequest, JsonRpcResponse, JsonRpcError (from jsonrpc.rs)
  • OsisLifecycleHooks (from lifecycle.rs)

It does NOT need rpc/server.rs (the legacy Axum server), rpc/client.rs (Redis client), or herolib_ai.

Solution

Split the rpc feature in hero_rpc_osis/Cargo.toml:

  1. New rpc-core feature — just the traits, types, and dispatch logic the server needs. Zero heavy deps (no redis, no AI, no axum/tower/hyper).
  2. Existing rpc feature — keeps everything for backwards compat, depends on rpc-core + the heavy deps.
  3. hero_rpc_server switches from osis[rpc] to osis[rpc-core].

Files in osis/src/rpc/ by category:

Keep in rpc-core Gate behind rpc (legacy)
mod.rs (re-exports only) server.rs (3200 lines, old AxumRpcServer)
handler.rs (OsisRpcHandler trait) client.rs (Redis-based client)
osis_app_bridge.rs (OsisAppRpcHandler) unix_server.rs (old UDS server)
jsonrpc.rs (JSON-RPC types)
request_context.rs
lifecycle.rs (hooks trait)
dispatch.rs
protocol.rs
error.rs
context.rs
debug.rs

Deps split:

rpc-core (lean) rpc-only (heavy)
serde, serde_json redis, deadpool-redis
(already in base) herolib_ai
axum, tower, tower-http
hyper, hyper-util, http-body-util
tracing, tracing-subscriber
uuid

Impact

All downstream services (hero_osis, hero_books, hero_voice, hero_logic, hero_biz, hero_services) get faster compiles and smaller binaries. No API changes — generated code imports from hero_rpc_osis::rpc::* which still works.

Acceptance criteria

  • rpc-core feature compiles without redis/AI/axum deps
  • hero_rpc_server depends on osis[rpc-core] only
  • cargo check --workspace passes in hero_rpc
  • cargo check --workspace passes in hero_osis
  • Legacy rpc feature still works for any direct users
## Problem Every Hero service that uses `hero_rpc_server` transitively compiles heavy dependencies it never uses: - **redis + deadpool-redis** — not used (OServer uses filesystem storage, not Redis) - **herolib_ai** — only used by the legacy `AxumRpcServer` mock data generator in `osis/src/rpc/server.rs` - **The old `AxumRpcServer`** (3200+ lines in `rpc/server.rs`) — completely superseded by `hero_rpc_server::OServer` ### Dependency chain today ``` hero_books / hero_voice / hero_logic / hero_osis / ... -> hero_rpc_server -> hero_rpc_osis features=["rpc"] -> redis, deadpool-redis, herolib_ai, axum, tower, tower-http, hyper, ... ``` The `server` crate only needs a few **traits and types** from `osis::rpc`: - `OsisAppRpcHandler`, `OsisDomainInit` (from `handler.rs`, `osis_app_bridge.rs`) - `RequestContext` (from `request_context.rs`) - `JsonRpcRequest`, `JsonRpcResponse`, `JsonRpcError` (from `jsonrpc.rs`) - `OsisLifecycleHooks` (from `lifecycle.rs`) It does NOT need `rpc/server.rs` (the legacy Axum server), `rpc/client.rs` (Redis client), or `herolib_ai`. ## Solution Split the `rpc` feature in `hero_rpc_osis/Cargo.toml`: 1. **New `rpc-core` feature** — just the traits, types, and dispatch logic the server needs. Zero heavy deps (no redis, no AI, no axum/tower/hyper). 2. **Existing `rpc` feature** — keeps everything for backwards compat, depends on `rpc-core` + the heavy deps. 3. **`hero_rpc_server`** switches from `osis[rpc]` to `osis[rpc-core]`. ### Files in `osis/src/rpc/` by category: | Keep in rpc-core | Gate behind rpc (legacy) | |---|---| | `mod.rs` (re-exports only) | `server.rs` (3200 lines, old AxumRpcServer) | | `handler.rs` (OsisRpcHandler trait) | `client.rs` (Redis-based client) | | `osis_app_bridge.rs` (OsisAppRpcHandler) | `unix_server.rs` (old UDS server) | | `jsonrpc.rs` (JSON-RPC types) | | | `request_context.rs` | | | `lifecycle.rs` (hooks trait) | | | `dispatch.rs` | | | `protocol.rs` | | | `error.rs` | | | `context.rs` | | | `debug.rs` | | ### Deps split: | rpc-core (lean) | rpc-only (heavy) | |---|---| | serde, serde_json | redis, deadpool-redis | | (already in base) | herolib_ai | | | axum, tower, tower-http | | | hyper, hyper-util, http-body-util | | | tracing, tracing-subscriber | | | uuid | ## Impact All downstream services (`hero_osis`, `hero_books`, `hero_voice`, `hero_logic`, `hero_biz`, `hero_services`) get faster compiles and smaller binaries. No API changes — generated code imports from `hero_rpc_osis::rpc::*` which still works. ## Acceptance criteria - [ ] `rpc-core` feature compiles without redis/AI/axum deps - [ ] `hero_rpc_server` depends on `osis[rpc-core]` only - [ ] `cargo check --workspace` passes in hero_rpc - [ ] `cargo check --workspace` passes in hero_osis - [ ] Legacy `rpc` feature still works for any direct users
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_rpc#22
No description provided.