Skip to content

Refactor RequestHandler God class (extract components, add tests, thread-safety) #45

Description

@ff225

Priority: High

RequestHandler (~780 lines) concentrates too many responsibilities: device-state management, payload decoding, EMA time updates, edge inference, offloading, background I/O scheduling, CSV/JSONL/debug output, and profiling. All shared state lives in mutable class-level variables (device_profiles, model_registry, variance_detector, csv_writer, inference_counter, …), which makes the class hard to test and extend.

Tasks

  • Extract DeviceStateManager (profiles, EMA updates, variance tracking)
  • Extract InferenceCycleRecorder (CSV, JSONL, debug file output)
  • Extract OffloadingService (wrapper around OffloadingAlgo + decision logging)
  • Add unit tests for handle_device_inference_result (EMA update, offloading decision, background I/O scheduling) — currently the most critical component has no dedicated tests
  • Make shared state thread-safe: device_profiles, inference_counter, and the variance sets are mutated from the ASGI thread and the background I/O thread without locks

Files

  • src/server/communication/request_handler.py

From the Feature 042 codebase review (recommendations #2, #9, #14).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions