Skip to content
Merged
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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fullstackhouse/agentloop",
"version": "0.7.2",
"version": "0.7.3",
"description": "AI agent that monitors chat platforms and responds using Claude Code",
"repository": {
"type": "git",
Expand Down
10 changes: 9 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,15 @@ async function serve(options: CliOptions): Promise<void> {
}

const slackApi = new SlackApi(xoxc, xoxd);
const adapter = new SlackAdapter(agent, slackApi, slackChannels, slackChannelBlacklist);
const adapter = new SlackAdapter(
agent,
slackApi,
slackChannels,
slackChannelBlacklist,
config.slackUsers,
10_000, // pollIntervalMs
config.maxRetries,
);
await adapter.start();
adapters.push(adapter);
}
Expand Down
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export interface AppConfig {
slackChannels?: string[];
slackChannelBlacklist?: string[];
slackUsers?: string[];
maxRetries?: number; // Max retries before giving up on a message (default: 3)
workspaceDir?: string; // Working directory for Claude Code subprocess
mcpServers?: Record<string, McpServerConfig>;
}
Expand Down
21 changes: 20 additions & 1 deletion src/platforms/slack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export class SlackAdapter {
private threadSessions = new Map<string, { sessionId: string; lastBotTs: string }>();
/** Cache of user IDs to display names */
private userNames = new Map<string, string>();
/** Tracks retry attempts per message */
private retryCount = new Map<string, number>();

constructor(
private agent: Agent,
Expand All @@ -22,6 +24,7 @@ export class SlackAdapter {
private channelBlacklist?: string[],
private users?: string[],
private pollIntervalMs = 10_000,
private maxRetries = 3,
) {}

async start(): Promise<void> {
Expand Down Expand Up @@ -262,18 +265,34 @@ ${cleanText}
await this.slackApi.reactionsRemove(channel, msg.ts, 'eyes').catch(this.ignoreSlackError('no_reaction'));
await this.slackApi.reactionsAdd(channel, msg.ts, 'white_check_mark').catch(this.ignoreSlackError('already_reacted'));

// Clear retry counter on success
this.retryCount.delete(key);

const elapsed = Date.now() - startTime;
console.log(`[slack] ${key}: Completed successfully in ${elapsed}ms`);
} catch (e) {
const elapsed = Date.now() - startTime;
console.error(`[slack] ${key}: Failed after ${elapsed}ms:`, e);
const attempt = (this.retryCount.get(key) || 0) + 1;
this.retryCount.set(key, attempt);

if (attempt < this.maxRetries) {
console.error(`[slack] ${key}: Failed after ${elapsed}ms (attempt ${attempt}/${this.maxRetries}), will retry:`, e);
// Don't add ✅, let next poll retry
return;
}

console.error(`[slack] ${key}: Failed after ${elapsed}ms (attempt ${attempt}/${this.maxRetries}, giving up):`, e);
this.retryCount.delete(key);

try {
const threadTs = msg.thread_ts || msg.ts;
console.log(`[slack] ${key}: Notifying user of error`);
await this.slackApi.chatPostMessage(channel, `Error: ${e instanceof Error ? e.message : String(e)}`, threadTs);
await this.slackApi.reactionsRemove(channel, msg.ts, 'eyes').catch((e) => {
console.warn(`[slack] ${key}: Failed to remove eyes reaction:`, e);
});
// Add ✅ after max retries to prevent endless retry loop
await this.slackApi.reactionsAdd(channel, msg.ts, 'white_check_mark').catch(this.ignoreSlackError('already_reacted'));
console.log(`[slack] ${key}: Error notification sent`);
} catch (e) {
console.warn(`[slack] ${key}: Failed to notify user of error:`, e);
Expand Down
Loading