feedkeeper 0.47.3 → 0.47.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "feedkeeper",
3
- "version": "0.47.3",
3
+ "version": "0.47.4",
4
4
  "description": "A lightweight, self-hosted RSS reader and remote MCP server for your news, blogs, and AI workflows.",
5
5
  "keywords": [
6
6
  "rss",
@@ -87,8 +87,10 @@ export async function executeFullText(userId, itemId, force, priority) {
87
87
  title: result.article.title, byline: result.article.byline, cached: false };
88
88
  }
89
89
  catch (error) {
90
- if (error instanceof SsrfBlockedError)
90
+ if (error instanceof SsrfBlockedError) {
91
+ recordAttempt(itemId, "failed");
91
92
  return { ok: false, error: "extraction_failed" };
93
+ }
92
94
  if (error instanceof ArticleHostBusyError)
93
95
  return { ok: false, error: "source_busy", retryable: true, deferred: true, host: error.host, retryAt: error.retryAt };
94
96
  if (error instanceof ArticleAccessDeniedError)
@@ -10,6 +10,7 @@ import { isBackgroundFullTextLinkPaused, isBackgroundFullTextPaused, pruneFullTe
10
10
  db.function("background_full_text_paused", (link) => Number(isBackgroundFullTextLinkPaused(link)));
11
11
  /** Refillable durable queue, bounded independently of library size. */
12
12
  export function scheduleFullTexts() {
13
+ lastScheduledAt = Date.now();
13
14
  const queued = db.prepare("SELECT COUNT(*) n FROM full_text_jobs").get();
14
15
  const room = Math.max(0, 200 - queued.n);
15
16
  if (!room)
@@ -18,7 +19,25 @@ export function scheduleFullTexts() {
18
19
  if (!eligible.length)
19
20
  return 0;
20
21
  const candidates = db.prepare(`
21
- WITH candidate_articles AS (
22
+ WITH eligible_feeds AS (
23
+ SELECT s.feed_id, MIN(s.user_id) AS user_id
24
+ FROM subscriptions s
25
+ WHERE s.user_id IN (SELECT value FROM json_each(?))
26
+ AND COALESCE(s.full_text_mode, 'auto') = 'auto'
27
+ GROUP BY s.feed_id
28
+ ),
29
+ subscription_candidates AS (
30
+ SELECT i.id AS item_id, ef.user_id, 1 AS priority, i.created_at, i.link,
31
+ ROW_NUMBER() OVER (PARTITION BY i.feed_id ORDER BY i.created_at DESC, i.id DESC) AS feed_rank
32
+ FROM eligible_feeds ef
33
+ JOIN items i ON i.feed_id = ef.feed_id
34
+ WHERE i.link IS NOT NULL AND i.full_content_html IS NULL
35
+ AND i.extraction_status = 'pending'
36
+ AND i.created_at >= strftime('%Y-%m-%dT%H:%M:%fZ','now','-14 days')
37
+ AND (i.extraction_retry_at IS NULL OR i.extraction_retry_at <= strftime('%Y-%m-%dT%H:%M:%fZ','now'))
38
+ AND NOT EXISTS (SELECT 1 FROM full_text_jobs j WHERE j.item_id = i.id)
39
+ ),
40
+ candidate_articles AS (
22
41
  SELECT ids.value AS item_id, e.user_id, 3 AS priority, i.created_at, i.link
23
42
  FROM editions e, json_each(e.item_ids) ids
24
43
  JOIN items i ON i.id = ids.value
@@ -26,7 +45,6 @@ export function scheduleFullTexts() {
26
45
  AND NOT EXISTS (SELECT 1 FROM subscriptions disabled WHERE disabled.user_id=e.user_id AND disabled.feed_id=i.feed_id AND disabled.full_text_mode='never')
27
46
  AND e.status = 'active' AND e.expires_at > strftime('%Y-%m-%dT%H:%M:%fZ','now')
28
47
  AND i.link IS NOT NULL AND i.full_content_html IS NULL
29
- AND i.extraction_status != 'feed_only'
30
48
  AND i.extraction_status = 'pending'
31
49
  AND (i.extraction_retry_at IS NULL OR i.extraction_retry_at <= strftime('%Y-%m-%dT%H:%M:%fZ','now'))
32
50
  AND NOT EXISTS (SELECT 1 FROM full_text_jobs j WHERE j.item_id = i.id)
@@ -39,7 +57,6 @@ export function scheduleFullTexts() {
39
57
  WHERE b.user_id IN (SELECT value FROM json_each(?))
40
58
  AND NOT EXISTS (SELECT 1 FROM subscriptions disabled WHERE disabled.user_id=b.user_id AND disabled.feed_id=i.feed_id AND disabled.full_text_mode='never')
41
59
  AND i.link IS NOT NULL AND i.full_content_html IS NULL
42
- AND i.extraction_status != 'feed_only'
43
60
  AND i.extraction_status = 'pending'
44
61
  AND (i.extraction_retry_at IS NULL OR i.extraction_retry_at <= strftime('%Y-%m-%dT%H:%M:%fZ','now'))
45
62
  AND NOT EXISTS (SELECT 1 FROM full_text_jobs j WHERE j.item_id = i.id)
@@ -52,30 +69,21 @@ export function scheduleFullTexts() {
52
69
  WHERE n.user_id IN (SELECT value FROM json_each(?))
53
70
  AND NOT EXISTS (SELECT 1 FROM subscriptions disabled WHERE disabled.user_id=n.user_id AND disabled.feed_id=i.feed_id AND disabled.full_text_mode='never')
54
71
  AND i.link IS NOT NULL AND i.full_content_html IS NULL
55
- AND i.extraction_status != 'feed_only'
56
72
  AND i.extraction_status = 'pending'
57
73
  AND (i.extraction_retry_at IS NULL OR i.extraction_retry_at <= strftime('%Y-%m-%dT%H:%M:%fZ','now'))
58
74
  AND NOT EXISTS (SELECT 1 FROM full_text_jobs j WHERE j.item_id = i.id)
59
75
 
60
76
  UNION ALL
61
77
 
62
- SELECT i.id AS item_id, s.user_id, 1 AS priority, i.created_at, i.link
63
- FROM subscriptions s
64
- JOIN items i ON i.feed_id = s.feed_id
65
- WHERE s.user_id IN (SELECT value FROM json_each(?))
66
- AND COALESCE(s.full_text_mode, 'auto') = 'auto'
67
- AND i.link IS NOT NULL AND i.full_content_html IS NULL
68
- AND i.extraction_status != 'feed_only'
69
- AND i.extraction_status = 'pending'
70
- AND i.created_at >= strftime('%Y-%m-%dT%H:%M:%fZ','now','-14 days')
71
- AND (i.extraction_retry_at IS NULL OR i.extraction_retry_at <= strftime('%Y-%m-%dT%H:%M:%fZ','now'))
72
- AND NOT EXISTS (SELECT 1 FROM full_text_jobs j WHERE j.item_id = i.id)
78
+ SELECT item_id, user_id, priority, created_at, link
79
+ FROM subscription_candidates
80
+ WHERE feed_rank <= 10
73
81
  )
74
82
  SELECT item_id AS id, user_id, MAX(priority) AS priority
75
83
  FROM candidate_articles
76
84
  WHERE ? = 0 OR background_full_text_paused(link) = 0
77
85
  GROUP BY item_id
78
- ORDER BY (priority + CAST((julianday('now')-julianday(created_at))*1440 / 60 AS INTEGER)) DESC, created_at ASC LIMIT ?`).all(JSON.stringify(eligible), JSON.stringify(eligible), JSON.stringify(eligible), JSON.stringify(eligible), pruneFullTextBlocks(), room);
86
+ ORDER BY MAX(priority) DESC, created_at DESC LIMIT ?`).all(JSON.stringify(eligible), JSON.stringify(eligible), JSON.stringify(eligible), JSON.stringify(eligible), pruneFullTextBlocks(), room);
79
87
  const add = db.prepare("INSERT OR IGNORE INTO full_text_jobs(item_id, user_id, priority, created_at) VALUES (?, ?, ?, strftime('%Y-%m-%dT%H:%M:%fZ','now'))");
80
88
  let count = 0;
81
89
  db.transaction(() => {
@@ -139,6 +147,8 @@ let timer;
139
147
  let seedTimer;
140
148
  let stopping = false;
141
149
  let scheduled = false;
150
+ let lastScheduledAt = 0;
151
+ const PUMP_REFILL_COOLDOWN_MS = 5_000;
142
152
  const startedAt = Date.now();
143
153
  let completed = 0;
144
154
  let failed = 0;
@@ -240,7 +250,7 @@ function pump() {
240
250
  const pool = configureFullTextPool();
241
251
  if (active.size >= pool.limits.concurrency)
242
252
  return;
243
- if (seedTimer && db.prepare("SELECT COUNT(*) n FROM full_text_jobs").get().n < pool.limits.concurrency * 2)
253
+ if (seedTimer && Date.now() - lastScheduledAt >= PUMP_REFILL_COOLDOWN_MS && db.prepare("SELECT COUNT(*) n FROM full_text_jobs").get().n < pool.limits.concurrency * 2)
244
254
  scheduleFullTexts();
245
255
  const jobs = db.prepare(`SELECT j.*, i.link FROM full_text_jobs j JOIN items i ON i.id=j.item_id
246
256
  WHERE julianday(j.available_at) <= julianday(?) ORDER BY (j.priority + CAST((julianday('now')-julianday(j.created_at))*86400000 / ? AS INTEGER)) DESC,
@@ -10,9 +10,18 @@ import { pushOutboxMetrics } from "../pushOutbox.js";
10
10
  // Created when the core is loaded at startup, outside HTTP middleware. Background attempts
11
11
  // must not inherit a request's cached capabilities (or keep that request context alive).
12
12
  const pollingContext = new AsyncResource("FeedKeeperPolling");
13
+ const MAX_ERROR_BACKOFF_MS = 24 * 60 * 60_000;
13
14
  export function retryDelay(attempt, settings, random = Math.random()) {
14
15
  return Math.ceil(Math.min(settings.retryMaxMs, settings.retryBaseMs * 2 ** attempt) * (0.5 + random * 0.5));
15
16
  }
17
+ /** Exponentially back off feeds that fail repeatedly so permanently broken sources do not starve healthy ones. */
18
+ export function errorBackoffMs(pollIntervalMinutes, consecutiveErrors) {
19
+ const baseMs = Math.max(1, pollIntervalMinutes) * 60_000;
20
+ if (consecutiveErrors <= 3)
21
+ return baseMs;
22
+ const factor = 2 ** Math.min(consecutiveErrors - 3, 10);
23
+ return Math.min(MAX_ERROR_BACKOFF_MS, baseMs * factor);
24
+ }
16
25
  function isTransient(error) {
17
26
  return error instanceof FeedHttpError ? [408, 425, 429, 500, 502, 503, 504].includes(error.status)
18
27
  : error instanceof TypeError || error instanceof RequestQueueFullError || (error instanceof Error && ["TimeoutError", "AbortError"].includes(error.name));
@@ -121,9 +130,16 @@ export class PollQueue {
121
130
  ORDER BY f.id LIMIT 200`).all(after);
122
131
  if (!rows.length)
123
132
  break;
124
- db.transaction(() => { for (const feed of rows)
125
- if (!this.active.has(feed.id))
126
- this.enqueue(feed); })();
133
+ const now = Date.now();
134
+ db.transaction(() => {
135
+ for (const feed of rows) {
136
+ if (this.active.has(feed.id))
137
+ continue;
138
+ if (feed.last_polled_at && Date.parse(feed.last_polled_at) + errorBackoffMs(feed.poll_interval_minutes, feed.consecutive_errors ?? 0) > now)
139
+ continue;
140
+ this.enqueue(feed);
141
+ }
142
+ })();
127
143
  after = rows[rows.length - 1].id;
128
144
  this.kick();
129
145
  await yieldTurn();
@@ -263,7 +279,8 @@ export class PollQueue {
263
279
  const transient = isTransient(error);
264
280
  const retry = transient && job.attempts < this.settings.maxRetries;
265
281
  const retryAt = Math.max(Date.now() + retryDelay(job.attempts, this.settings), error instanceof FeedHttpError ? error.retryAt ?? 0 : 0);
266
- const resumeAt = retry ? retryAt : Math.max(retryAt, Date.now() + feed.poll_interval_minutes * 60_000);
282
+ const nextErrors = (feed.consecutive_errors ?? 0) + 1;
283
+ const resumeAt = retry ? retryAt : Math.max(retryAt, Date.now() + errorBackoffMs(feed.poll_interval_minutes, nextErrors));
267
284
  db.transaction(() => {
268
285
  updateFeedAfterPoll(feed.id, { error: message });
269
286
  if (retry) {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@feedkeeper/server",
3
- "version": "0.47.3",
3
+ "version": "0.47.4",
4
4
  "private": true,
5
5
  "type": "module"
6
6
  }