Skip to content

Cải tiến đề xuất

PRIORITY

Sắp xếp theo impact × effort ratio. IMP-01 và IMP-02 nên fix đầu tiên.

IMP-01: Config mutation không thread-safe

Files: self_improver.py, config.py

Vấn đề: Config.CLF_PARAMSConfig.REG_PARAMSmodule-level mutable dicts. apply_suggestion() mutate in-place. 2 cycles chạy cùng lúc sẽ corrupt config.

Đề xuất: Per-instance config copies hoặc thread-safe config store.


IMP-02: Warehouse config hardcoded trong TypeScript

File: workforcePlanningEngine.ts (lines 186-282)

Vấn đề: 4 warehouse configs (UPH, headcount, tables, channels) hardcoded constants. DB config loaded nhưng bị override.

Đề xuất: warehouse_configs table trong Supabase với versioning. Frontend dùng DB values.


IMP-03: Feature engineering chạy lại mỗi request

File: backtester.pyrun() (line ~74-76)

Vấn đề: FeatureEngineer.create_all_features() chạy trên toàn bộ dataset mỗi lần. Nếu gọi nhiều lần → lặp computation 40+ features.

Đề xuất: Cache feature DataFrames keyed by (client_id, date_range_hash).


IMP-04: Không có rate limiting cho LLM calls

File: self_improver.py

Vấn đề: generate_all_suggestions() gọi 5 LLM calls tuần tự, không có rate limiting hoặc cost tracking.

Đề xuất: Token counting, cost estimation, configurable rate limits.


IMP-05: Error handling cho _extract_json()

File: self_improver.py_extract_json() (line ~29-34)

Vấn đề: Malformed JSON từ LLM → JSONDecodeError. Mỗi caller handle riêng.

Đề xuất: Retry mechanism với simpler prompt fallback.


IMP-06: expand_dates() memory pressure

File: features.pyexpand_dates() (line ~19-62)

Vấn đề: 10,000 SKUs × 730 ngày = 7.3M rows trước feature engineering → memory pressure.

Đề xuất: Chunked processing hoặc streaming. Logging memory usage.


IMP-07: _llm_complete_sync() thread-pool workaround

File: self_improver.py (line ~37-49)

Vấn đề: Detect event loop → dùng ThreadPoolExecutor workaround. Fragile, có thể deadlock.

Đề xuất: httpx synchronous hoặc fully async handlers.


IMP-08: Frontend forecast engine nên dùng ML results trực tiếp hơn

File: forecastEngine.ts

Vấn đề: Frontend có Holt-Winters + event engine riêng, trùng lặp với backend ML. ML results chỉ là overlay.

Đề xuất: Khi ML wMAPE < 15% → dùng ML-primary, BAU fallback. Thêm confidence threshold.

Tài liệu liên quan

BoxMe Forecast — Tài liệu kỹ thuật nội bộ