-
Notifications
You must be signed in to change notification settings - Fork 0
Fix 5 runtime bugs found during debug pass #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -8,6 +8,11 @@ import { AutonomousAgent } from './services/agent.js'; | |||||
| import { XMCPServer } from './mcp/server.js'; | ||||||
|
|
||||||
| async function main() { | ||||||
| // Redirect console.log to stderr so it doesn't conflict with | ||||||
| // MCP StdioServerTransport which uses stdout for protocol messages | ||||||
| const origLog = console.log; | ||||||
| console.log = (...args: any[]) => console.error(...args); | ||||||
|
||||||
| console.log = (...args: any[]) => console.error(...args); | |
| console.log = (...args: unknown[]) => console.error(...args); |
Copilot
AI
Feb 6, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
origLog is assigned but never used. Either remove it to avoid dead code, or use it to restore console.log during shutdown/after MCP server init (depending on the intended lifecycle).
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -11,6 +11,7 @@ export class AutonomousAgent { | |||||||||||||
| private grokService: GrokService; | ||||||||||||||
| private config: AgentConfig; | ||||||||||||||
| private processedMentions: Set<string> = new Set(); | ||||||||||||||
| private static readonly MAX_PROCESSED_MENTIONS = 10000; | ||||||||||||||
| private isRunning: boolean = false; | ||||||||||||||
| private pollingIntervalId: NodeJS.Timeout | null = null; | ||||||||||||||
| private isProcessing: boolean = false; | ||||||||||||||
|
|
@@ -95,6 +96,15 @@ export class AutonomousAgent { | |||||||||||||
| await this.processMention(mention); | ||||||||||||||
| this.processedMentions.add(mention.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); | ||||||||||||||
|
||||||||||||||
| this.processedMentions.delete(iter.next().value as string); | |
| const { value, done } = iter.next(); | |
| if (done) { | |
| break; | |
| } | |
| this.processedMentions.delete(value); |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -44,17 +44,26 @@ export class XAPIClient { | |||||
| throw new Error('Failed to get user ID from response'); | ||||||
| } | ||||||
|
|
||||||
| const mentionsResponse = await this.makeXAPIRequest( | ||||||
| `https://api.twitter.com/2/users/${userId}/mentions?max_results=10&expansions=author_id&tweet.fields=created_at,conversation_id,in_reply_to_user_id,referenced_tweets`, | ||||||
| 'GET' | ||||||
| ); | ||||||
| let mentionsUrl = `https://api.twitter.com/2/users/${userId}/mentions?max_results=10&expansions=author_id&tweet.fields=created_at,conversation_id,in_reply_to_user_id,referenced_tweets`; | ||||||
| if (this.lastMentionId) { | ||||||
| mentionsUrl += `&since_id=${this.lastMentionId}`; | ||||||
| } | ||||||
|
Comment on lines
+47
to
+50
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Building URLs via string concatenation can be fragile and hard to read. Using const params = new URLSearchParams({
max_results: '10',
expansions: 'author_id',
'tweet.fields': 'created_at,conversation_id,in_reply_to_user_id,referenced_tweets',
});
if (this.lastMentionId) {
params.set('since_id', this.lastMentionId);
}
const mentionsUrl = `https://api.twitter.com/2/users/${userId}/mentions?${params.toString()}`; |
||||||
|
|
||||||
| const mentionsResponse = await this.makeXAPIRequest(mentionsUrl, 'GET'); | ||||||
|
|
||||||
| if (!mentionsResponse || !Array.isArray(mentionsResponse.data)) { | ||||||
| console.warn('Invalid response from X API (mentions)'); | ||||||
| return []; | ||||||
| } | ||||||
|
|
||||||
| return this.parseMentions(mentionsResponse.data); | ||||||
| const mentions = this.parseMentions(mentionsResponse.data); | ||||||
|
|
||||||
| // Track the newest mention ID for pagination on the next poll | ||||||
| if (mentionsResponse.data.length > 0) { | ||||||
| this.lastMentionId = mentionsResponse.data[0].id; | ||||||
| } | ||||||
|
|
||||||
| return mentions; | ||||||
| } catch (error) { | ||||||
| console.error('Error fetching mentions:', error); | ||||||
| return []; | ||||||
|
|
@@ -77,7 +86,12 @@ export class XAPIClient { | |||||
| 'GET' | ||||||
| ); | ||||||
|
|
||||||
| return this.parseThread(response.data || []); | ||||||
| if (!response || !response.data) { | ||||||
| console.warn('Invalid response from X API (thread)'); | ||||||
| return null; | ||||||
| } | ||||||
|
|
||||||
| return this.parseThread(response.data); | ||||||
|
Comment on lines
+89
to
+94
|
||||||
| } catch (error) { | ||||||
| console.error('Error fetching thread:', error); | ||||||
| return null; | ||||||
|
|
@@ -184,7 +198,7 @@ export class XAPIClient { | |||||
| private parseThread(tweets: { created_at: string; [key: string]: any }[]): XThread | null { | ||||||
|
||||||
| private parseThread(tweets: { created_at: string; [key: string]: any }[]): XThread | null { | |
| private parseThread(tweets: { created_at: string; [key: string]: unknown }[]): XThread | null { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
origLogvariable is declared but never used and can be removed.While redirecting
console.logtostderrworks, be aware that modifying global objects (monkey-patching) can have unintended side effects in larger applications or when using third-party libraries that might not expect this behavior. It can also complicate debugging. For a more robust solution in the future, consider using a dedicated logging library which allows for flexible stream configuration.