@@ -50,7 +50,7 @@ normalize_comment_sync_mode() {
5050 fi
5151 sync_comments_only=true
5252 if [ " ${scheduled_comment_sync:- false} " = " true" ]; then
53- apply_kind=" pull_request "
53+ apply_kind=" all "
5454 comment_sync_min_age_days=0
5555 fi
5656}
@@ -80,6 +80,27 @@ trim_comment_sync_cycle_batch() {
8080 fi
8181}
8282
83+ comment_sync_uses_default_mutation_policy () {
84+ [ " ${apply_close_reasons:- ${CLAWSWEEPER_AUTO_CLOSE_REASONS:- all} } " = " ${CLAWSWEEPER_AUTO_CLOSE_REASONS:- all} " ] &&
85+ [ " ${stale_min_age_days:- 60} " = " 60" ] &&
86+ [ " ${close_delay_ms:- 2000} " = " 2000" ] &&
87+ [ " ${checkpoint_size:- 40} " = " 40" ] &&
88+ [ " ${limit:- 40} " = " 40" ]
89+ }
90+
91+ comment_sync_uses_automatic_policy () {
92+ [ " ${sync_open_pr_batch:- false} " = " true" ] &&
93+ comment_sync_matches_automatic_policy
94+ }
95+
96+ comment_sync_matches_automatic_policy () {
97+ [ " ${apply_kind:- all} :${comment_sync_min_age_days:- 0} " = " all:0" ] &&
98+ [ " ${sync_batch_size:- 40} " = " 40" ] &&
99+ [ " ${min_age_days:- 0} " = " 0" ] &&
100+ [ -z " ${min_age_minutes:- } " ] &&
101+ comment_sync_uses_default_mutation_policy
102+ }
103+
83104prepare_comment_sync_batch () {
84105 comment_sync_pending_items=" "
85106 comment_sync_cursor_advance_count=0
@@ -91,9 +112,27 @@ prepare_comment_sync_batch() {
91112 fi
92113 if [ -z " ${item_numbers:- } " ] &&
93114 [ " ${scheduled_comment_sync:- false} " != " true" ] &&
94- { [ " ${apply_kind:- all} " != " pull_request" ] ||
95- [ " ${comment_sync_min_age_days:- 0} " != " 0" ]; }; then
115+ ! comment_sync_matches_automatic_policy; then
96116 cursor_path=" results/comment-sync-cursors/${target_slug} -${apply_kind:- all} -age${comment_sync_min_age_days:- 0} .json"
117+ if ! comment_sync_uses_default_mutation_policy ||
118+ [ " ${sync_batch_size:- 40} " != " 40" ] ||
119+ [ " ${min_age_days:- 0} " != " 0" ] ||
120+ [ -n " ${min_age_minutes:- } " ]; then
121+ local mutation_policy
122+ mutation_policy=" $( printf ' %s\n' \
123+ " ${apply_close_reasons:- ${CLAWSWEEPER_AUTO_CLOSE_REASONS:- all} } " \
124+ " ${stale_min_age_days:- 60} " \
125+ " ${close_delay_ms:- 2000} " \
126+ " ${checkpoint_size:- 40} " \
127+ " ${limit:- 40} " \
128+ " ${sync_batch_size:- 40} " \
129+ " ${min_age_days:- 0} " \
130+ " ${min_age_minutes:- } " | sha256sum | cut -c1-16) "
131+ cursor_path=" ${cursor_path% .json} -policy-${mutation_policy} .json"
132+ fi
133+ fi
134+ if [ -z " ${cursor_path:- } " ] && [ -z " ${item_numbers:- } " ]; then
135+ cursor_path=" results/comment-sync-cursors/${target_slug} .json"
97136 fi
98137 if [ -f " ${cursor_path:- } " ]; then
99138 comment_sync_initial_cursor=" $( jq -er '
@@ -185,18 +224,62 @@ complete_comment_sync_batch() {
185224 if [ -n " ${item_numbers:- } " ]; then
186225 IFS=, read -r -a selected_items <<< " $item_numbers"
187226 fi
227+ local canonical_target_slug=" ${target_slug:- } "
228+ if [ -z " $canonical_target_slug " ]; then
229+ canonical_target_slug=" $( printf ' %s' " $TARGET_REPO " | tr ' [:upper:]' ' [:lower:]' | sed ' s/[^a-z0-9_.-]/-/g' ) "
230+ fi
231+ local selected_item
232+ for selected_item in " ${selected_items[@]} " ; do
233+ case " ,$completed_csv ," in
234+ * " ,$selected_item ," * ) continue ;;
235+ esac
236+ local canonical_items_dir=" records/${canonical_target_slug} /items"
237+ local canonical_closed_dir=" records/${canonical_target_slug} /closed"
238+ if [ ! -f " ${canonical_items_dir} /${selected_item} .md" ] &&
239+ [ ! -f " ${canonical_items_dir} /${canonical_target_slug} -${selected_item} .md" ] &&
240+ { [ -f " ${canonical_closed_dir} /${selected_item} .md" ] ||
241+ [ -f " ${canonical_closed_dir} /${canonical_target_slug} -${selected_item} .md" ]; }; then
242+ completed_csv=" ${completed_csv: +$completed_csv ,} $selected_item "
243+ fi
244+ done
188245 local completed_count=0
189246 local cursor_count=0
190247 local safe_cursor=" "
191248 local blocked_prefix=false
249+ local initial_cursor=" ${comment_sync_initial_cursor:- 0} "
192250 local unfinished_items=()
193- local selected_item
194251 for selected_item in " ${selected_items[@]} " ; do
195252 case " ,$completed_csv ," in
196253 * " ,$selected_item ," * )
197254 completed_count=$(( completed_count + 1 ))
198255 if [ " $blocked_prefix " != " true" ]; then
199- safe_cursor=" $selected_item "
256+ if [ " $sync_open_pr_batch " = " true" ] && [ -n " ${next_cursor:- } " ] &&
257+ { [ " $selected_item " -gt " $next_cursor " ] ||
258+ { [ " $selected_item " -le " $initial_cursor " ] &&
259+ [ " $next_cursor " -ge " $initial_cursor " ]; }; }; then
260+ continue
261+ fi
262+ local blocks_cursor_advance=false
263+ local pending_item
264+ for pending_item in " ${selected_items[@]} " ; do
265+ case " ,$completed_csv ," in
266+ * " ,$pending_item ," * ) continue ;;
267+ esac
268+ if [ " $pending_item " -lt " $selected_item " ] &&
269+ { { [ " $selected_item " -gt " $initial_cursor " ] &&
270+ [ " $pending_item " -gt " $initial_cursor " ]; } ||
271+ { [ " $selected_item " -le " $initial_cursor " ] &&
272+ [ " $pending_item " -le " $initial_cursor " ]; }; }; then
273+ blocks_cursor_advance=true
274+ break
275+ fi
276+ done
277+ if [ " $blocks_cursor_advance " = " true" ]; then
278+ continue
279+ fi
280+ if [ -z " $safe_cursor " ] || [ " $selected_item " -gt " $safe_cursor " ]; then
281+ safe_cursor=" $selected_item "
282+ fi
200283 cursor_count=$(( cursor_count + 1 ))
201284 fi
202285 ;;
@@ -222,15 +305,15 @@ complete_comment_sync_batch() {
222305 --cursor-path " $cursor_path " \
223306 --next-cursor " $next_cursor " \
224307 --target-repo " $TARGET_REPO "
225- if [ " $TARGET_REPO " != " openclaw/openclaw" ] ||
226- [ " ${apply_kind:- pull_request} " != " pull_request" ] ||
227- [ " ${comment_sync_min_age_days:- 0} " != " 0" ]; then
228- local initial_cursor=" ${comment_sync_initial_cursor:- 0} "
308+ if [ " ${scheduled_comment_sync:- false} " != " true" ] &&
309+ { [ " $TARGET_REPO " != " openclaw/openclaw" ] ||
310+ ! comment_sync_uses_automatic_policy; }; then
229311 local cycle_start=" ${comment_sync_cycle_start:- 0} "
230312 local cycle_wrapped=" ${comment_sync_cycle_wrapped:- false} "
231313 if [ " ${# selected_items[@]} " -gt 0 ] &&
232314 [ " ${selected_items[0]} " -le " $initial_cursor " ] &&
233- [ " $initial_cursor " -gt 0 ]; then
315+ [ " $initial_cursor " -gt 0 ] &&
316+ [ " $safe_cursor " -le " $initial_cursor " ]; then
234317 cycle_wrapped=true
235318 fi
236319 local lookahead_env
@@ -260,8 +343,11 @@ complete_comment_sync_batch() {
260343 if [ " $cycle_wrapped " = " true" ] && [ " $lookahead_count " -gt 0 ]; then
261344 local lookahead_items
262345 lookahead_items=" $( awk -F= ' $1 == "item_numbers" { print $2 }' " $lookahead_env " ) "
263- local first_lookahead_item=" ${lookahead_items%% ,* } "
264- if [ " $first_lookahead_item " -gt " $cycle_start " ]; then
346+ if ! jq -enr --arg selected " $lookahead_items " --argjson boundary " $cycle_start " '
347+ $selected | split(",")
348+ | map(tonumber? | select(. > 0 and . <= $boundary))
349+ | length > 0
350+ ' > /dev/null; then
265351 lookahead_count=0
266352 fi
267353 fi
@@ -510,6 +596,18 @@ publish_reconciled_records() {
510596 publish_changes_with_strategy normal " $message " " ${publish_paths[@]} " || return 1
511597}
512598
599+ prepare_apply_reconciliation_args () {
600+ reconcile_args=(--target-repo " $TARGET_REPO " --skip-closed-at)
601+ if [ -z " ${item_numbers:- } " ]; then
602+ return 0
603+ fi
604+ reconcile_args+=(--item-numbers " $item_numbers " )
605+ if [ " ${sync_comments_only:- false} " = " true" ] &&
606+ [ " ${sync_open_pr_batch:- false} " = " true" ]; then
607+ reconcile_args+=(--only-item-numbers)
608+ fi
609+ }
610+
513611persist_reconciliation () {
514612 local reconcile_json
515613 local canonical_baseline_dir
0 commit comments