fix(test1): X 切片无限重发 bug — reclaim 把已完成任务退回 scheduled

根因:postTweet 不返回 tweetId,sync 写空 tweet_id,reclaim 又退回。
修复:1) tweet_id 为空时用 x2:jobId 标记已完成 2) reclaim 排除 finished_at>0
3) attempts>=3 直接 failed 不再循环。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
eric 2026-08-19 08:40:38 -05:00
parent b5a6907b85
commit dd2931af86
2 changed files with 21 additions and 2 deletions

View File

@ -440,12 +440,25 @@ def reclaim_stale_x_clip_recordings(*, max_age_sec: float = 240) -> int:
conn.close()
def reclaim_stale_x_clip_posts(*, max_age_sec: float = 900) -> int:
def reclaim_stale_x_clip_posts(*, max_age_sec: float = 900, max_attempts: int = 3) -> int:
cutoff = time.time() - max(120.0, float(max_age_sec))
now = time.time()
with _lock:
conn = _connect()
try:
ensure_x_clips_tables(conn)
# Fail jobs that exceeded retry limit
conn.execute(
"""
UPDATE x_clip_jobs
SET status = 'failed', error = '超过最大重试次数', updated_at = ?, finished_at = ?
WHERE status = 'posting' AND updated_at < ?
AND IFNULL(tweet_id, '') = ''
AND IFNULL(finished_at, 0) = 0
AND attempts >= ?
""",
(now, now, cutoff, max(1, int(max_attempts))),
)
cur = conn.execute(
"""
UPDATE x_clip_jobs
@ -453,8 +466,10 @@ def reclaim_stale_x_clip_posts(*, max_age_sec: float = 900) -> int:
x2_job_id = '', media_key = CASE WHEN media_url != '' THEN media_key ELSE '' END
WHERE status = 'posting' AND updated_at < ?
AND IFNULL(tweet_id, '') = ''
AND IFNULL(finished_at, 0) = 0
AND attempts < ?
""",
(time.time(), cutoff),
(now, cutoff, max(1, int(max_attempts))),
)
conn.commit()
return int(cur.rowcount or 0)

View File

@ -605,6 +605,10 @@ class XClipsPipeline:
or result.get("id")
or ""
).strip()
# Extension postTweet does not return tweetId; use x2 job id
# as proof of completion to prevent reclaim loop.
if not tweet_id:
tweet_id = f"x2:{x2_id}"
x_clips_db.update_x_clip_job(
jid,
status="posted",