caelum0x 90a79c426b fix: Trial Matcher — CT.gov query broadening + bounded eligibility, no false degrade
Live dogfooding showed Trial Matcher extracted the patient profile perfectly but returned
0 matches in 'degraded mode'. Three real bugs, each fixed:

1. ClinicalTrials.gov search 400'd: buildQuery joins all profile search terms into one
   query.term, and Essie ANDs them — ~11+ terms 400s and even fewer over-constrains to zero
   matches. searchTrialsForMatching now PROGRESSIVELY BROADENS (10→6→4→3→2 leading terms),
   returning the first attempt that matches; throws only if every attempt errors, else [].
2. Eligibility assessment failed on trials with many criteria: the per-criterion JSON array
   overran maxTokens (3072) and failed to parse. Bounded to 15 criteria/type + raised to 4096.
3. Degraded banner over-fired: a single per-trial JSON hiccup (already dropped) flipped the
   whole run to 'eligibility unavailable' even with good matches. Now a plain error only
   degrades when it leaves ZERO matches; quota always surfaces.

Verified locally: 5 real HER2-breast-cancer trials matched, scored, and grounded, degraded=null.
tsc + build green; 2 failing tests are pre-existing NER tests unrelated to these files.
2026-07-12 00:22:29 +03:00
..