Commit 47e8097
committed
fix: handle lone Unicode surrogates in artifact persistence
External tool outputs (e.g. Exa Search) can contain lone Unicode
surrogate characters (U+D800..U+DFFF) that are invalid in both UTF-8
and JSON, causing UnicodeEncodeError in _serialize_payload_bytes and
surfacing as "Tool storage unavailable" in the chat UI.
- Add _sanitize_surrogates() to recursively strip lone surrogates and
null bytes from payload dicts before serialization, using the same
encode-surrogatepass/decode-ignore technique as OWUI's
sanitize_text_for_db
- Move _prepare_rows_for_storage inside the try-except in _db_persist
so serialization errors return [] instead of crashing streaming
- Add 5 regression tests covering surrogates, null bytes, valid
Unicode preservation, recursive sanitization, and round-trip safety1 parent a903e47 commit 47e8097
2 files changed
Lines changed: 92 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
687 | 687 | | |
688 | 688 | | |
689 | 689 | | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
690 | 717 | | |
691 | 718 | | |
692 | | - | |
| 719 | + | |
| 720 | + | |
693 | 721 | | |
694 | 722 | | |
695 | 723 | | |
| |||
1018 | 1046 | | |
1019 | 1047 | | |
1020 | 1048 | | |
1021 | | - | |
1022 | | - | |
1023 | 1049 | | |
| 1050 | + | |
1024 | 1051 | | |
1025 | 1052 | | |
1026 | 1053 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
585 | 585 | | |
586 | 586 | | |
587 | 587 | | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
588 | 650 | | |
589 | 651 | | |
590 | 652 | | |
| |||
0 commit comments