Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/pr-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: PR Checks
on:
pull_request:
types: [opened, reopened, synchronize, edited]
permissions:
pull-requests: write
contents: read
jobs:
validate:
runs-on: ubuntu-latest
Expand Down
15 changes: 10 additions & 5 deletions src/services/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,23 @@ export class AutonomousAgent {

console.log(`\n📬 [${new Date().toLocaleTimeString()}] Found ${newMentions.length} new mention(s)!\n`);

// Process each mention
for (const mention of newMentions) {
await this.processMention(mention);
this.processedMentions.add(mention.post.id);
// Process mentions oldest-first (API returns newest-first, so reverse)
// This ensures Set insertion order matches chronological order for proper pruning
for (let i = newMentions.length - 1; i >= 0; i--) {
await this.processMention(newMentions[i]);
this.processedMentions.add(newMentions[i].post.id);
}

// Prune oldest entries to prevent unbounded memory growth
if (this.processedMentions.size > AutonomousAgent.MAX_PROCESSED_MENTIONS) {
const excess = this.processedMentions.size - AutonomousAgent.MAX_PROCESSED_MENTIONS;
const iter = this.processedMentions.values();
for (let i = 0; i < excess; i++) {
this.processedMentions.delete(iter.next().value as string);
const { value, done } = iter.next();
if (done) {
break;
}
this.processedMentions.delete(value);
}
}
} catch (error) {
Expand Down
5 changes: 5 additions & 0 deletions src/services/xapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ export class XAPIClient {
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);
} catch (error) {
console.error('Error fetching thread:', error);
Expand Down