Files
loader/_docs/02_tasks/done/08_refactor_cleanup.md
T
Oleksandr Bezdieniezhnykh 4eaf218f09 Quality cleanup refactoring
Made-with: Cursor
2026-04-13 06:21:26 +03:00

3.1 KiB

Dead Code Removal and Minor Fixes

Task: 08_refactor_cleanup Name: Remove dead code, fix log path and error handling Description: Remove orphan methods and constants, make log path configurable, log os.remove failure Complexity: 2 points Dependencies: 06_refactor_crypto_uploads Component: Resource Management, Core Models, HTTP API Tracker: PENDING Epic: PENDING (01-quality-cleanup)

Problem

The codebase contains 5 never-called methods in ApiClient and 8 orphan constant declarations. The log file path is hardcoded with no environment override. A file removal error is silently swallowed.

Outcome

  • Dead methods and constants are removed from source and declaration files
  • Log file directory is configurable via environment variable
  • File removal failure is logged instead of silently ignored
  • Codebase is smaller and cleaner with no behavioral regressions

Scope

Included

  • Delete 5 orphan methods from api_client.pyx: get_user, list_files, check_resource, upload_to_cdn, download_from_cdn
  • Delete corresponding declarations from api_client.pxd
  • Delete 5 unused constants from constants.pyx: CONFIG_FILE, QUEUE_CONFIG_FILENAME, AI_ONNX_MODEL_FILE, MODELS_FOLDER, ALIGNMENT_WIDTH
  • Delete 8 orphan declarations from constants.pxd (keep CDN_CONFIG, SMALL_SIZE_KB, log, logerror)
  • Make log directory configurable via LOG_DIR env var in constants.pyx
  • Replace bare except: pass with warning log in main.py _run_unlock

Excluded

  • Modifying any live code paths or method signatures
  • Changing the logging format or levels
  • Removing hardware_service.pyx silent catches (those are by-design for cross-platform compatibility)

Acceptance Criteria

AC-1: Dead methods removed Given the source code When searching for get_user, list_files, check_resource, upload_to_cdn, download_from_cdn Then no definitions or declarations exist in api_client.pyx or api_client.pxd

AC-2: Dead constants removed Given constants.pyx and constants.pxd When the files are inspected Then only CDN_CONFIG, SMALL_SIZE_KB, log, logerror declarations remain in the pxd

AC-3: Configurable log path Given LOG_DIR environment variable is set When the application starts Then logs are written to the specified directory

AC-4: Error logged on tar removal failure Given os.remove fails on the tar file during unlock When the failure occurs Then a warning-level log message is emitted

AC-5: No regressions Given the current e2e test suite When all tests are run Then all 18 tests pass

Blackbox Tests

AC Ref Initial Data/Conditions What to Test Expected Behavior NFR References
AC-5 Docker services running Full e2e suite 18 passed, 0 failed

Risks & Mitigation

Risk 1: Removing a method that's called via dynamic dispatch

  • Risk: A method could be invoked dynamically (getattr, etc.) rather than statically
  • Mitigation: All removed methods are cdef/cpdef — cdef methods cannot be called dynamically from Python; cpdef methods were grep-verified to have zero callers