@@ -562,14 +562,6 @@ def next_task(
562
562
563
563
case TaskType .REPLY :
564
564
565
- recent_reply_tasks = self .pr .task_repository .fetch_recent_reply_tasks (
566
- max_age = timedelta (seconds = self .cfg .recent_tasks_span_sec ),
567
- done = False ,
568
- skipped = False ,
569
- limit = 500 ,
570
- )
571
- recent_reply_task_parents = {t .parent_message_id for t in recent_reply_tasks }
572
-
573
565
if task_role == TaskRole .PROMPTER :
574
566
extendible_parents = list (filter (lambda x : x .parent_role == "assistant" , extendible_parents ))
575
567
elif task_role == TaskRole .ASSISTANT :
@@ -580,24 +572,17 @@ def next_task(
580
572
random_parent : ExtendibleParentRow = None
581
573
if self .cfg .p_lonely_child_extension > 0 and self .cfg .lonely_children_count > 1 :
582
574
# check if we have extendible prompter parents with a small number of replies
583
-
584
575
lonely_children_parents = [
585
576
p
586
577
for p in extendible_parents
587
578
if 0 < p .active_children_count < self .cfg .lonely_children_count
588
579
and p .parent_role == "prompter"
589
- and p .parent_id not in recent_reply_task_parents
590
580
]
591
581
if len (lonely_children_parents ) > 0 and random .random () < self .cfg .p_lonely_child_extension :
592
582
random_parent = random .choice (lonely_children_parents )
593
583
594
584
if random_parent is None :
595
- # try to exclude parents for which tasks were recently handed out
596
- fresh_parents = [p for p in extendible_parents if p .parent_id not in recent_reply_task_parents ]
597
- if len (fresh_parents ) > 0 :
598
- random_parent = random .choice (fresh_parents )
599
- else :
600
- random_parent = random .choice (extendible_parents )
585
+ random_parent = random .choice (extendible_parents )
601
586
602
587
# fetch random conversation to extend
603
588
logger .debug (f"selected { random_parent = } " )
@@ -895,7 +880,7 @@ def update_message_ranks(
895
880
logger .warning ("The intersection of ranking results ID sets has less than two elements. Skipping." )
896
881
continue
897
882
898
- # keep only elements in command set
883
+ # keep only elements in common set
899
884
ordered_ids_list = [list (filter (lambda x : x in common_set , ids )) for ids in ordered_ids_list ]
900
885
assert all (len (x ) == len (common_set ) for x in ordered_ids_list )
901
886
@@ -1087,14 +1072,23 @@ def query_incomplete_rankings(self, lang: str) -> list[IncompleteRankingsRow]:
1087
1072
1088
1073
_sql_find_extendible_parents = """
1089
1074
-- find all extendible parent nodes
1075
+ WITH recent_reply_tasks (parent_message_id) AS (
1076
+ -- recent incomplete tasks to exclude
1077
+ SELECT parent_message_id FROM task
1078
+ WHERE not done
1079
+ AND not skipped
1080
+ AND created_date > (CURRENT_TIMESTAMP - :recent_tasks_interval)
1081
+ AND (payload_type = 'AssistantReplyPayload' OR payload_type = 'PrompterReplyPayload')
1082
+ )
1090
1083
SELECT m.id as parent_id, m.role as parent_role, m.depth, m.message_tree_id, COUNT(c.id) active_children_count
1091
1084
FROM message_tree_state mts
1092
- INNER JOIN message m ON mts.message_tree_id = m.message_tree_id -- all elements of message tree
1085
+ INNER JOIN message m ON mts.message_tree_id = m.message_tree_id -- all elements of message tree
1093
1086
LEFT JOIN message_emoji me ON
1094
1087
(m.id = me.message_id
1095
1088
AND :skip_user_id IS NOT NULL
1096
1089
AND me.user_id = :skip_user_id
1097
1090
AND me.emoji = :skip_reply)
1091
+ LEFT JOIN recent_reply_tasks rrt ON m.id = rrt.parent_message_id -- recent tasks
1098
1092
LEFT JOIN message c ON m.id = c.parent_id -- child nodes
1099
1093
WHERE mts.active -- only consider active trees
1100
1094
AND mts.state = :growing_state -- message tree must be growing
@@ -1103,6 +1097,7 @@ def query_incomplete_rankings(self, lang: str) -> list[IncompleteRankingsRow]:
1103
1097
AND m.review_result -- parent node must have positive review
1104
1098
AND m.lang = :lang -- parent matches lang
1105
1099
AND me.message_id IS NULL -- no skip reply emoji for user
1100
+ AND rrt.parent_message_id IS NULL -- no recent reply task found
1106
1101
AND NOT coalesce(c.deleted, FALSE) -- don't count deleted children
1107
1102
AND (c.review_result OR coalesce(c.review_count, 0) < :num_reviews_reply) -- don't count children with negative review but count elements under review
1108
1103
GROUP BY m.id, m.role, m.depth, m.message_tree_id, mts.max_children_count
@@ -1125,6 +1120,7 @@ def query_extendible_parents(self, lang: str) -> tuple[list[ExtendibleParentRow]
1125
1120
"user_id" : user_id ,
1126
1121
"skip_user_id" : self .pr .user_id ,
1127
1122
"skip_reply" : protocol_schema .EmojiCode .skip_reply ,
1123
+ "recent_tasks_interval" : timedelta (seconds = self .cfg .recent_tasks_span_sec ),
1128
1124
},
1129
1125
)
1130
1126
@@ -1165,6 +1161,7 @@ def query_extendible_trees(self, lang: str) -> list[ActiveTreeSizeRow]:
1165
1161
"user_id" : user_id ,
1166
1162
"skip_user_id" : self .pr .user_id ,
1167
1163
"skip_reply" : protocol_schema .EmojiCode .skip_reply ,
1164
+ "recent_tasks_interval" : timedelta (seconds = self .cfg .recent_tasks_span_sec ),
1168
1165
},
1169
1166
)
1170
1167
return [ActiveTreeSizeRow .from_orm (x ) for x in r .all ()]
0 commit comments