Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.
Go agentagenticaichatbotdsh-pluginembeddingsevaluationgenerative-aigolangknowledge-basellmmulti-tenantollamaopenaiquestion-answeringragrerankingsemantic-searchvector-searchwiki
fix(rss): preserve full text during article refresh failures (#4625)
Lucien73903791eb44
diff --git a/internal/datasource/connector/rss/article_retry_test.go b/internal/datasource/connector/rss/article_retry_test.goindex 8cd5d7a4c..2301f7155 100644--- a/internal/datasource/connector/rss/article_retry_test.go+++ b/internal/datasource/connector/rss/article_retry_test.go@@ -2,6 +2,7 @@ package rssimport ("context"+ "encoding/json""fmt""net/http""net/http/httptest"@@ -132,3 +133,46 @@ func TestIncrementalCachesEntryWithoutArticleLink(t *testing.T) {require.Zero(t, f.articleReads.Load())require.EqualValues(t, 1, f.healthyReads.Load())}++func TestIncrementalPreservesFullTextDuringRefreshFailure(t *testing.T) {+ f := newArticleRetryFeed(t)+ f.status.Store(http.StatusOK)+ items, cursor := f.sync(t, nil)+ require.Len(t, items, 2)+ require.Contains(t, string(items[0].Content), "reasonably long article")++ decode := func(cursor *types.SyncCursor) rssCursor {+ t.Helper()+ data, err := json.Marshal(cursor.ConnectorCursor)+ require.NoError(t, err)+ var state rssCursor+ require.NoError(t, json.Unmarshal(data, &state))+ return state+ }+ original := decode(cursor)+ feedURL := f.server.URL + "/feed.xml"+ require.NotEmpty(t, original.FeedSignals[feedURL]["retry"])++ f.summary = "Changed summary while the article is unavailable"+ f.status.Store(http.StatusServiceUnavailable)+ for attempt := 0; attempt < 2; attempt++ {+ items, cursor = f.sync(t, cursor)+ require.Empty(t, items, "a transient failure must not replace the full text with the summary")+ state := decode(cursor)+ require.Equal(t, original.FeedItems, state.FeedItems, "preserve the stored full-text fingerprint")+ require.Equal(t, original.FeedSignals, state.FeedSignals, "keep the previous signal for repeated retries")+ require.EqualValues(t, attempt+2, f.articleReads.Load())+ require.EqualValues(t, 1, f.healthyReads.Load(), "successful sibling should stay cached")+ }++ f.status.Store(http.StatusOK)+ items, cursor = f.sync(t, cursor)+ require.Empty(t, items, "the recovered full text is unchanged and must not be ingested again")+ require.Equal(t, original.FeedItems, decode(cursor).FeedItems)+ require.NotEqual(t, original.FeedSignals[feedURL]["retry"], decode(cursor).FeedSignals[feedURL]["retry"])+ require.EqualValues(t, 4, f.articleReads.Load())+ items, _ = f.sync(t, cursor)+ require.Empty(t, items)+ require.EqualValues(t, 4, f.articleReads.Load(), "recovery should cache the changed feed signal")+ require.EqualValues(t, 1, f.healthyReads.Load())+}diff --git a/internal/datasource/connector/rss/connector.go b/internal/datasource/connector/rss/connector.goindex 2f74fcc4d..b7e3379b2 100644--- a/internal/datasource/connector/rss/connector.go+++ b/internal/datasource/connector/rss/connector.go@@ -261,6 +261,15 @@ func (c *Connector) walk(}resolved := c.resolveItem(ctx, cli, feed, item, feedURL, itemID, feedContent)+ if incremental && resolved.articleFailed && prevItems[itemID] != "" && prevSignals[itemID] != "" {+ // A cached signal records a successful resolution. Preserve its body+ // and old signal so a changed entry retries without replacing the full+ // article with a summary, including across repeated failures.+ newCursor.FeedItems[feedURL][itemID] = prevItems[itemID]+ newCursor.FeedSignals[feedURL][itemID] = prevSignals[itemID]+ skipped+++ continue+ }if incremental && prevItems != nil && isLegacyFingerprint(prevItems[itemID]) {switch {case legacyContentFingerprint(string(resolved.item.Content)) == prevItems[itemID]:diff --git a/internal/datasource/connector/rss/item_identity_test.go b/internal/datasource/connector/rss/item_identity_test.goindex 484ef0828..128916b8d 100644--- a/internal/datasource/connector/rss/item_identity_test.go+++ b/internal/datasource/connector/rss/item_identity_test.go@@ -218,3 +218,40 @@ func TestIncrementalItemContentWithoutLink(t *testing.T) {}assertIdentityUnchanged(t, f, next)}++func TestIncrementalItemIdentityRefreshRetriesAfterArticleFailure(t *testing.T) {+ for _, tt := range []struct{ name, title, path string }{+ {"title only", "Corrected title", "/original"},+ {"link only", "Original title", "/moved"},+ } {+ t.Run(tt.name, func(t *testing.T) {+ f := newIdentityFeed(t)+ original, cursor := f.sync(t, nil)+ if len(original) != 1 {+ t.Fatalf("expected 1 initial item, got %d", len(original))+ }+ fingerprint := storedItemFingerprint(t, f, cursor)+ f.publish(tt.title, tt.path, "Mon, 02 Jan 2006 15:04:05 GMT")+ f.articleStatus.Store(http.StatusServiceUnavailable)+ for attempt := 0; attempt < 2; attempt++ {+ items, next := f.sync(t, cursor)+ if len(items) != 0 || storedItemFingerprint(t, f, next) != fingerprint {+ t.Fatal("failed refresh must preserve the stored full article")+ }+ cursor = next+ }+ if f.fetches.Load() != 3 {+ t.Fatal("every changed-feed refresh must retry the article")+ }+ f.articleStatus.Store(http.StatusOK)+ updated, cursor := f.sync(t, cursor)+ if len(updated) != 1 || updated[0].Title != tt.title || updated[0].URL != f.server.URL+tt.path {+ t.Fatalf("recovery must apply the delayed identity update: %+v", updated)+ }+ if string(updated[0].Content) != string(original[0].Content) {+ t.Fatal("recovered update must retain the complete article")+ }+ assertIdentityUnchanged(t, f, cursor)+ })+ }+}