Commit 25243ef
committed
fix(cot): address code quality issues from PR review
Implements critical code quality improvements from PR #490 review:
1. **ReDoS Protection (Security)**:
- Added MAX_REGEX_INPUT_LENGTH constant (10KB limit)
- Length checks before all regex operations in:
- _parse_xml_tags
- _parse_json_structure
- _parse_final_answer_marker
- Prevents regex denial of service attacks
2. **Pre-compiled Regex Patterns (Performance)**:
- XML_ANSWER_PATTERN for <answer> tags
- JSON_ANSWER_PATTERN for JSON structures
- FINAL_ANSWER_PATTERN for "Final Answer:" markers
- Improves performance by compiling patterns once
3. **Specific Exception Handling**:
- Changed generic Exception to specific types
- Catches LLMProviderError, ValidationError, PydanticValidationError
- Wraps exceptions in LLMProviderError on final retry
- Maintains retry logic with proper exception chaining
4. **Production Logging**:
- Changed verbose logger.info to logger.debug
- Applies to answer_synthesizer.py and chain_of_thought_service.py
- Reduces production log noise
Related: #4901 parent cc32c86 commit 25243ef
1 file changed
+32
-9
lines changedLines changed: 32 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
3 | 5 | | |
4 | 6 | | |
5 | 7 | | |
| |||
37 | 39 | | |
38 | 40 | | |
39 | 41 | | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
40 | 50 | | |
41 | 51 | | |
42 | 52 | | |
| |||
299 | 309 | | |
300 | 310 | | |
301 | 311 | | |
302 | | - | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
303 | 316 | | |
304 | | - | |
| 317 | + | |
305 | 318 | | |
306 | 319 | | |
307 | 320 | | |
| |||
325 | 338 | | |
326 | 339 | | |
327 | 340 | | |
328 | | - | |
329 | | - | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
330 | 345 | | |
331 | 346 | | |
332 | 347 | | |
333 | | - | |
| 348 | + | |
334 | 349 | | |
335 | 350 | | |
336 | 351 | | |
| |||
349 | 364 | | |
350 | 365 | | |
351 | 366 | | |
352 | | - | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
353 | 371 | | |
354 | 372 | | |
355 | | - | |
| 373 | + | |
356 | 374 | | |
357 | 375 | | |
358 | 376 | | |
| |||
600 | 618 | | |
601 | 619 | | |
602 | 620 | | |
603 | | - | |
| 621 | + | |
604 | 622 | | |
605 | 623 | | |
606 | | - | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
607 | 630 | | |
608 | 631 | | |
609 | 632 | | |
| |||
0 commit comments