Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Feb 9, 2026

Addresses three review comments from PR #26 review thread #3771558129: insufficient API response validation, incorrect mention processing order, and a missing type safety fix confirmation.

Changes:

  • Strengthen fetchThread() validation: Add Array.isArray() guard after null check to prevent crashes when X API returns non-array objects (e.g., error shapes). Previous truthiness check allowed objects to reach parseThread() where .length access would throw.

  • Fix mention processing order: Process mentions oldest→newest (reverse iteration) instead of newest→oldest. X API returns [newest, ..., oldest], but Set iteration is FIFO. Without reversal, pruning the first N entries deletes the newest mentions instead of the oldest, inverting the intended LRU behavior.

  • Confirm type safety fix: Verified parseThread parameter already uses unknown instead of any in index signature (fixed in commit 2407087).

Additional fix:

  • Install missing @types/node package to resolve pre-existing TypeScript compilation error.
// Before: Would crash on { error: "..." } response
if (!response || !response.data) return null;
return this.parseThread(response.data);

// After: Validates array shape
if (!response || !response.data) return null;
if (!Array.isArray(response.data)) {
  console.warn('Unexpected response shape from X API (thread): data is not an array');
  return null;
}
return this.parseThread(response.data);
// Before: Processed newest→oldest, pruning deleted newest
for (const mention of newMentions) {
  await this.processMention(mention);
  this.processedMentions.add(mention.post.id);
}

// After: Process oldest→newest, pruning deletes oldest
for (let i = newMentions.length - 1; i >= 0; i--) {
  await this.processMention(newMentions[i]);
  this.processedMentions.add(newMentions[i].post.id);
}

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Fix 5 runtime bugs found during debug pass Address type safety and correctness issues from PR #26 review Feb 9, 2026
Copilot AI requested a review from groupthinking February 9, 2026 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants