Commit 8383208
committed
fix(knowledge): give failed documents a grace while their retries are still scheduled
The sweep treats failed as terminal — "the run that produced it has ended" — and
that was true when processing ran inline. Since dispatch became asynchronous the
worker writes failed and then rethrows, and the processing task retries up to
three times, so failed is a resting state between attempts rather than a final
one. The sweep gave it no grace at all, so it reclaimed a document mid-retry
chain, deleted its embeddings, and re-dispatched with a fresh pass id: two live
runs, two indexing passes, two bills, through the one state deliberately left
unguarded.
Aged from processingCompletedAt, which every failure write stamps, so it reads
exactly when the last attempt ended rather than when the document was dispatched.
Sized at the queue grace rather than a run-duration bound. What is being waited
on between attempts is a re-queue behind the same global concurrency limit, not
another run, so on a large backlog the next attempt starts hours after the
previous one ended and a run-duration bound would still reclaim live work.
The grace itself is now an expression rather than a constant — corpus over queue
concurrency, times occupancy, times a contention factor — with each input
documented where it can be re-measured. The previous 240 was derived from a
2,600-document corpus and sat below the drain time of the 7,730-document
connector it was written for. Rounding is up: too small silently re-bills live
work, too large only delays recovery of documents nothing is processing.
Also withdraws the queue stamp when every dispatch in a batch fails, so a
provably-undispatched document keeps next-sync recovery instead of waiting out a
grace it never earned. Scoped to the batch's own ids, to rows still pending, and
by compare-and-set on the exact stamp that call wrote, so a concurrent batch that
re-stamped a document keeps its grace. Best-effort by design, while the stamp
write still throws: a failed stamp means the grace cannot be promised and
dispatching anyway is the unsafe direction, whereas a failed withdrawal only
delays recovery and must not mask the dispatch error underneath it.1 parent 1ced0b6 commit 8383208
4 files changed
Lines changed: 208 additions & 41 deletions
File tree
- apps/sim/lib/knowledge
- connectors
- documents
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
713 | 713 | | |
714 | 714 | | |
715 | 715 | | |
| 716 | + | |
716 | 717 | | |
717 | 718 | | |
718 | 719 | | |
719 | 720 | | |
720 | 721 | | |
721 | 722 | | |
| 723 | + | |
722 | 724 | | |
723 | 725 | | |
724 | 726 | | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
725 | 734 | | |
726 | 735 | | |
727 | | - | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
728 | 740 | | |
729 | 741 | | |
730 | 742 | | |
731 | 743 | | |
732 | 744 | | |
733 | 745 | | |
734 | 746 | | |
735 | | - | |
| 747 | + | |
736 | 748 | | |
737 | 749 | | |
738 | 750 | | |
| |||
742 | 754 | | |
743 | 755 | | |
744 | 756 | | |
745 | | - | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
746 | 761 | | |
747 | 762 | | |
748 | 763 | | |
749 | 764 | | |
750 | | - | |
| 765 | + | |
751 | 766 | | |
752 | 767 | | |
753 | 768 | | |
| |||
757 | 772 | | |
758 | 773 | | |
759 | 774 | | |
760 | | - | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
761 | 788 | | |
762 | 789 | | |
763 | 790 | | |
764 | | - | |
765 | | - | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
766 | 829 | | |
767 | 830 | | |
768 | | - | |
| 831 | + | |
769 | 832 | | |
770 | 833 | | |
771 | 834 | | |
| |||
794 | 857 | | |
795 | 858 | | |
796 | 859 | | |
797 | | - | |
| 860 | + | |
798 | 861 | | |
799 | 862 | | |
800 | 863 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
61 | 69 | | |
62 | | - | |
63 | | - | |
| 70 | + | |
| 71 | + | |
64 | 72 | | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
77 | 86 | | |
78 | | - | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
79 | 92 | | |
80 | 93 | | |
81 | 94 | | |
| |||
84 | 97 | | |
85 | 98 | | |
86 | 99 | | |
| 100 | + | |
87 | 101 | | |
88 | 102 | | |
89 | 103 | | |
| |||
99 | 113 | | |
100 | 114 | | |
101 | 115 | | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
108 | 132 | | |
109 | | - | |
110 | | - | |
111 | | - | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
112 | 138 | | |
113 | 139 | | |
114 | 140 | | |
| |||
126 | 152 | | |
127 | 153 | | |
128 | 154 | | |
129 | | - | |
130 | | - | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
131 | 162 | | |
132 | 163 | | |
133 | 164 | | |
| |||
1473 | 1504 | | |
1474 | 1505 | | |
1475 | 1506 | | |
| 1507 | + | |
1476 | 1508 | | |
1477 | 1509 | | |
1478 | 1510 | | |
| |||
Lines changed: 32 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
| 77 | + | |
77 | 78 | | |
78 | 79 | | |
79 | 80 | | |
| |||
86 | 87 | | |
87 | 88 | | |
88 | 89 | | |
| 90 | + | |
89 | 91 | | |
90 | 92 | | |
91 | 93 | | |
| |||
121 | 123 | | |
122 | 124 | | |
123 | 125 | | |
124 | | - | |
| 126 | + | |
125 | 127 | | |
126 | 128 | | |
127 | 129 | | |
| |||
132 | 134 | | |
133 | 135 | | |
134 | 136 | | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
135 | 165 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
706 | 706 | | |
707 | 707 | | |
708 | 708 | | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
709 | 739 | | |
710 | 740 | | |
711 | 741 | | |
| |||
728 | 758 | | |
729 | 759 | | |
730 | 760 | | |
731 | | - | |
732 | | - | |
733 | | - | |
734 | | - | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
735 | 764 | | |
736 | 765 | | |
737 | 766 | | |
| |||
748 | 777 | | |
749 | 778 | | |
750 | 779 | | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
751 | 793 | | |
752 | 794 | | |
753 | 795 | | |
| |||
0 commit comments