@oss-autopilot/core 3.42.0 → 3.42.2

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.
@@ -195,6 +195,7 @@ async function fetchPRData(prMonitor, token, warnings) {
195
195
  return {
196
196
  searchedPRs: [...mergedResult.searchedPRs, ...closedResult.searchedPRs],
197
197
  recentlyMergedFetchFailed: didRecentlyMergedFetchFail,
198
+ wasMergedSearchTruncated: mergedResult.truncated,
198
199
  successorGaps,
199
200
  prs,
200
201
  failures,
@@ -214,7 +215,7 @@ async function fetchPRData(prMonitor, token, warnings) {
214
215
  * Applies stale repo reset, updates merged/closed counts, computes and stores
215
216
  * repo signals from open PR data, refreshes star counts, and syncs trusted projects.
216
217
  */
217
- async function updateRepoScores(prMonitor, prs, mergedCounts, closedCounts, searchedPRs, warnings) {
218
+ async function updateRepoScores(prMonitor, prs, mergedCounts, wasMergedSearchTruncated, closedCounts, searchedPRs, warnings) {
218
219
  const stateManager = getStateManager();
219
220
  // Batch all synchronous score mutations for a single disk write.
220
221
  // Per-repo try-catch: a single corrupted repo should not prevent updates to others.
@@ -235,6 +236,10 @@ async function updateRepoScores(prMonitor, prs, mergedCounts, closedCounts, sear
235
236
  if (mergedCounts.size === 0 && existingReposWithMerges.length > 0) {
236
237
  warn(MODULE, `Skipping stale repo reset: API returned 0 merged PR results but state has ${existingReposWithMerges.length} repo(s) with merges. Possible API issue.`);
237
238
  }
239
+ else if (wasMergedSearchTruncated) {
240
+ // A repo absent from a pagination-capped search may still have merges (#1897).
241
+ debug(MODULE, 'Skipping stale repo reset: merged PR search was truncated.');
242
+ }
238
243
  else {
239
244
  for (const score of Object.values(stateManager.getState().repoScores)) {
240
245
  if (!mergedCounts.has(score.repo)) {
@@ -288,6 +293,9 @@ async function updateRepoScores(prMonitor, prs, mergedCounts, closedCounts, sear
288
293
  });
289
294
  warn(MODULE, `[CLOSED_COUNT_UPDATES_FAILED] ${closedCountFailures} of ${closedCounts.size} closed count update(s) failed.`);
290
295
  }
296
+ // The search counts above are capped at 300 PRs; raise each repo back
297
+ // to its ledger count so a prolific user's totals never drop (#1897).
298
+ stateManager.tryReconcilePRCounts();
291
299
  // Ledger-derived signals, recomputed each run for every scored repo so a
292
300
  // corrected closeReason clears hostility and repos without samples reset to null.
293
301
  const ledgerSignals = computeLedgerRepoSignals([...stateManager.getMergedPRs(), ...stateManager.getClosedPRs()], prs);
@@ -853,9 +861,9 @@ async function executeDailyCheckInternal(token) {
853
861
  (loadRecovery.rejectedPath ? `; rejected file preserved at ${loadRecovery.rejectedPath}` : '')));
854
862
  }
855
863
  // Phase 1: Fetch all PR data from GitHub
856
- const { prs, failures, mergedCounts, closedCounts, searchedPRs, monthlyCounts, monthlyClosedCounts, openedFromMerged, openedFromClosed, recentlyClosedPRs, recentlyMergedPRs, recentlyMergedFetchFailed, commentedIssues, successorGaps, } = await fetchPRData(prMonitor, token, warnings);
864
+ const { prs, failures, mergedCounts, wasMergedSearchTruncated, closedCounts, searchedPRs, monthlyCounts, monthlyClosedCounts, openedFromMerged, openedFromClosed, recentlyClosedPRs, recentlyMergedPRs, recentlyMergedFetchFailed, commentedIssues, successorGaps, } = await fetchPRData(prMonitor, token, warnings);
857
865
  // Phase 2: Update repo scores (signals, star counts, trust sync)
858
- await updateRepoScores(prMonitor, prs, mergedCounts, closedCounts, searchedPRs, warnings);
866
+ await updateRepoScores(prMonitor, prs, mergedCounts, wasMergedSearchTruncated, closedCounts, searchedPRs, warnings);
859
867
  // Phase 3: Persist monthly analytics and store merged/closed PR history.
860
868
  // try-catch: analytics are supplementary — save failure should not crash the daily check.
861
869
  try {
@@ -40,6 +40,11 @@ export interface PRCountsResult<R> {
40
40
  url: string;
41
41
  title: string;
42
42
  }>;
43
+ /**
44
+ * True when the search had more results than it fetched (pagination cap),
45
+ * so `repos` undercounts and a repo missing from it may still have PRs.
46
+ */
47
+ truncated: boolean;
43
48
  }
44
49
  /** Returns an empty PRCountsResult. Used as the fallback when stats fetches fail or username is empty. */
45
50
  export declare function emptyPRCountsResult<R>(): PRCountsResult<R>;
@@ -74,7 +74,14 @@ export function mentionedIssueUrls(title, body, prUrl) {
74
74
  }
75
75
  /** Returns an empty PRCountsResult. Used as the fallback when stats fetches fail or username is empty. */
76
76
  export function emptyPRCountsResult() {
77
- return { repos: new Map(), monthlyCounts: {}, monthlyOpenedCounts: {}, dailyActivityCounts: {}, searchedPRs: [] };
77
+ return {
78
+ repos: new Map(),
79
+ monthlyCounts: {},
80
+ monthlyOpenedCounts: {},
81
+ dailyActivityCounts: {},
82
+ searchedPRs: [],
83
+ truncated: false,
84
+ };
78
85
  }
79
86
  /** Type guard for deserialized cache data — prevents crashes on corrupt/stale cache. */
80
87
  function isCachedPRCounts(v) {
@@ -114,6 +121,7 @@ async function fetchUserPRCounts(octokit, githubUsername, query, label, accumula
114
121
  monthlyOpenedCounts: cached.monthlyOpenedCounts,
115
122
  dailyActivityCounts: cached.dailyActivityCounts,
116
123
  searchedPRs: Array.isArray(cached.searchedPRs) ? cached.searchedPRs : [],
124
+ truncated: cached.truncated === true,
117
125
  };
118
126
  }
119
127
  debug(MODULE, `Fetching ${label} PR counts for @${githubUsername}...`);
@@ -180,7 +188,8 @@ async function fetchUserPRCounts(octokit, githubUsername, query, label, accumula
180
188
  }
181
189
  page++;
182
190
  }
183
- if (fetched < totalCount && page >= MAX_PAGINATION_PAGES) {
191
+ const isTruncated = fetched < totalCount;
192
+ if (isTruncated && page >= MAX_PAGINATION_PAGES) {
184
193
  warn(MODULE, `Pagination capped at ${MAX_PAGINATION_PAGES} pages: fetched ${fetched} of ${totalCount} ${label} PRs. Stats may be incomplete for prolific contributors.`);
185
194
  }
186
195
  debug(MODULE, `Found ${fetched} ${label} PRs across ${repos.size} repos`);
@@ -190,12 +199,13 @@ async function fetchUserPRCounts(octokit, githubUsername, query, label, accumula
190
199
  // for up to 24 hours, but these are cosmetic and self-heal on the next cache expiry.
191
200
  cache.set(cacheKey, '', {
192
201
  reposEntries: Array.from(repos.entries()),
202
+ truncated: isTruncated,
193
203
  monthlyCounts,
194
204
  monthlyOpenedCounts,
195
205
  dailyActivityCounts,
196
206
  searchedPRs,
197
207
  });
198
- return { repos, monthlyCounts, monthlyOpenedCounts, dailyActivityCounts, searchedPRs };
208
+ return { repos, monthlyCounts, monthlyOpenedCounts, dailyActivityCounts, searchedPRs, truncated: isTruncated };
199
209
  }
200
210
  /**
201
211
  * Fetch merged PR counts and latest merge dates per repository for the configured user.
@@ -101,9 +101,10 @@ export declare class StateManager {
101
101
  static createWithGist(token: string): Promise<StateManager>;
102
102
  /**
103
103
  * Attempt PR count reconciliation, logging a warning on failure.
104
- * Called after every state load from disk.
104
+ * Called after every state load and ledger addition, and by daily after it
105
+ * overwrites counts from the pagination-capped search (#1897).
105
106
  */
106
- private tryReconcilePRCounts;
107
+ tryReconcilePRCounts(): void;
107
108
  /**
108
109
  * Execute multiple mutations as a single batch, deferring disk I/O until the
109
110
  * batch completes. Nested `batch()` calls are flattened — only the outermost saves.
@@ -258,7 +258,8 @@ export class StateManager {
258
258
  }
259
259
  /**
260
260
  * Attempt PR count reconciliation, logging a warning on failure.
261
- * Called after every state load from disk.
261
+ * Called after every state load and ledger addition, and by daily after it
262
+ * overwrites counts from the pagination-capped search (#1897).
262
263
  */
263
264
  tryReconcilePRCounts() {
264
265
  try {
@@ -793,6 +794,7 @@ export class StateManager {
793
794
  this.state.mergedPRs.push(...newPRs);
794
795
  this.state.mergedPRs.sort((a, b) => b.mergedAt.localeCompare(a.mergedAt));
795
796
  debug(MODULE, `Added ${newPRs.length} merged PRs (total: ${this.state.mergedPRs.length})`);
797
+ this.tryReconcilePRCounts();
796
798
  this.autoSave();
797
799
  return { added: newPRs.length, dropped };
798
800
  }
@@ -856,6 +858,7 @@ export class StateManager {
856
858
  this.state.closedPRs.push(...newPRs);
857
859
  this.state.closedPRs.sort((a, b) => b.closedAt.localeCompare(a.closedAt));
858
860
  debug(MODULE, `Added ${newPRs.length} closed PRs (total: ${this.state.closedPRs.length})`);
861
+ this.tryReconcilePRCounts();
859
862
  this.autoSave();
860
863
  return { added: newPRs.length, dropped };
861
864
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oss-autopilot/core",
3
- "version": "3.42.0",
3
+ "version": "3.42.2",
4
4
  "description": "CLI and core library for managing open source contributions",
5
5
  "type": "module",
6
6
  "bin": {
@@ -55,7 +55,7 @@
55
55
  "@octokit/plugin-retry": "^8.1.1",
56
56
  "@octokit/plugin-throttling": "^11.0.5",
57
57
  "@octokit/rest": "^22.0.1",
58
- "@oss-scout/core": "^1.14.0",
58
+ "@oss-scout/core": "^1.14.1",
59
59
  "commander": "^15.0.0",
60
60
  "zod": "^4.6.7"
61
61
  },