mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-15 15:02:04 +00:00
The generate route caught `FeaturesPayloadTooLargeError` from the raw-mode `extractFeatures` call and retried in aggregated mode. The retry ran the same `enforceSizeGuard` from `features.ts`, so a very large medication history plus multi-year context could blow past the 5 MB ceiling a second time → the uncaught throw bubbled to the apiHandler's generic 500 path. The retry now sits in its own try/catch. On a second oversize the route applies the existing `applyInsightsExcludeFilter` with the optional context blocks (anthropometrics, medications, sleep, steps, hrv, resting_hr) excluded and re-extracts. A third failure annotates `insights_payload_too_large` for ops visibility and returns 422 with a readable user-facing message rather than 500. Unit test mocks all three extractor calls to throw and asserts the 422 + annotate.