Skip to content

API/Reflector: no context/dependency injection for Reflector<T>::to() forces ReflType leakage across DTOs, endpoints, and schemas (and caused wolf#465) #186

Not planned

Description

@clockblocker

Part of #138
Popularity: 1/7 corpus consumers (wolf)

Related issues

Problem

rfl::Reflector<T> only supports stateless 1-argument static T to(const ReflType&) deserialization. In real servers where domain structs hold non-serializable runtime dependencies (such as an EventBus pointer, immer::atom, or polymorphic std::shared_ptr<Runner> constructed via a factory), consumers cannot use rfl::json::read<DomainType> directly.

Instead, they must define non-standard 2-argument Reflector<T>::to(const ReflType&, Context) methods (or write-only Reflector<T> specializations with only from()) and manually bypass automatic Reflector<T> dispatch everywhere — leaking rfl::Reflector<T>::ReflType into API DTOs, endpoint handlers, tests, and rfl::json::to_schema<...>().

Observed Downstream Workarounds

games-on-whales/wolf (ac2461f6)

  1. Non-standard 2-arg Reflector<T>::to(ReflType, ev_bus) and write-only Reflector<T> specializations:
    src/moonlight-server/events/reflectors.hpp#L33-L203 defines 6 reflectors (events::Runner, events::App, events::Profile, events::StartRunner, events::StreamSession, events::Lobby) that cannot be used by rfl::json::read<T>() directly:

    template <> struct Reflector<events::Runner> {
      using ReflType = events::RunnerTypes;
      static ReflType from(const events::Runner &v) { return v.serialize(); }
      static std::shared_ptr<events::Runner> to(const ReflType &v,
                                                const std::shared_ptr<events::EventBusType> &ev_bus) {
        return state::get_runner(v, ev_bus);
      }
    };
    
    template <> struct Reflector<events::App> {
      struct ReflType {
        ...
        Reflector<events::Runner>::ReflType runner;
      };
      static ReflType from(const events::App &v) { ... }
      static events::App to(const ReflType &app, const std::shared_ptr<events::EventBusType> &ev_bus) { ... }
    };
  2. rfl::Reflector<T>::ReflType leaked across DTOs, endpoints, tests, and schemas:

  3. Real production drift bug caused by manual ReflType / to() duplication (wolf#465):
    Commit 00e16b11 ("fix(api): keep start_audio_server when deserialising an App", Fixes games-on-whales/wolf#465) fixed a silent bug where Reflector<events::App>::to() omitted .start_audio_server = app.start_audio_server, leaving every app added via POST /api/v1/apps/add with audio silently disabled even though from() and configTOML.cpp both populated it.

Root Cause in reflect-cpp

  • rfl::Reflector<T> is purely static/context-free (to(const ReflType&)); there is no mechanism to pass a read/deserialization context (or custom converter context) through rfl::json::read<T>(input, ctx).
  • When to_schema<Reflector<T>::ReflType>() is called directly (as forced by the above), make_type_name mangles the full rfl::Reflector<...>::ReflType nested type name into the schema $defs key.

Suggested Direction

Upstream Overlap

Activity

  1. added
    known-downstream-workarounds
    on Nov 29, 2026
  2. added
    wontfix
    on Nov 29, 2026
  3. clockblocker commented on Nov 29, 2026

    @clockblocker
    OwnerAuthor

    Triage decision: closing as wontfix (not planned) for the upstream adoption track.

    Rationale: Injecting runtime context / dependency injection (e.g., EventBus or service lifecycles) into Reflector<T>::to() mixes runtime state into pure deserialization — an anti-pattern that would complicate reflect-cpp's core parser API across all formats. Explicit DTO-to-domain mapping at the application boundary is standard C++.

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

    known-downstream-workaroundswontfix

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions