Skip to content

Comments

fix: conversation lock, case-insensitive mentions, routing prefix strip#136

Merged
jlia0 merged 4 commits intomainfrom
fix/bugs-2-3-4-from-pr134
Feb 23, 2026
Merged

fix: conversation lock, case-insensitive mentions, routing prefix strip#136
jlia0 merged 4 commits intomainfrom
fix/bugs-2-3-4-from-pr134

Conversation

@jlia0
Copy link
Collaborator

@jlia0 jlia0 commented Feb 23, 2026

Summary

Cherry-picked from #134 with docs/CLAUDE.md and bug 1 (claim/unclaim delivery) stripped out.

  • Diagnostic logging in isTeammate(): Mentions that fail validation now log the reason (team not found, self-mention, agent not in team, agent not in config) instead of failing silently
  • Regex fix in extractTeammateMentions(): \S+?[^\]]+? for correct bracket boundary matching
  • Conversation lock (race condition fix): conv.pending-- was not atomic across concurrent promise chains. Added withConversationLock() mutex, incrementPending()/decrementPending() helpers
  • parseAgentRouting() prefix handling: Messages API prepends [channel/sender]: which broke @agent routing. Regex now optionally matches the prefix while preserving it in the message

Removed from #134

  • CLAUDE.md, docs/bug-fixes/*
  • Bug 1 claim/unclaim delivery pattern (over-engineered for a rare localhost ack failure)
  • validateAgentResponse() (dead code)
  • recoverConversation() on every message (wasteful)

Test plan

  • npm run build compiles cleanly

🤖 Generated with Claude Code

Devain Pal Bansal and others added 4 commits February 23, 2026 21:35
…s, multi-agent race condition

Bug 1 (Response Drops): Channel clients had non-atomic send-then-ack flow
causing random response loss. Added 'delivering' status to SQLite responses
table, claim/unclaim API endpoints, and claim-before-send pattern in Telegram
client with retry tracking (max 3 attempts).

Bug 2 (Inter-Agent Mention Failures): Teammate mentions were silently dropped
due to case sensitivity, typos, and missing validation logging. Added
case-insensitive agent ID lookup, detailed logging in isTeammate() and
extractTeammateMentions(), improved regex for bracket handling, and
validateAgentResponse() helper.

Bug 3 (Multi-Agent Reply Loss): Race condition on conv.pending counter when
multiple agents complete simultaneously caused replies to never arrive. Added
withConversationLock() promise-chain mutex, safe incrementPending/decrementPending
operations, and automatic conversation state recovery.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The messages API route prepends [channel/sender]: to incoming messages,
which caused parseAgentRouting() regex to fail since the message no
longer starts with @agent_id. This made all messages fall back to the
first agent regardless of @mentions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Remove unnecessary files and bug 1 delivery infrastructure:
- Remove CLAUDE.md, docs/bug-fixes/*
- Revert telegram-client.ts to main (no claim/unclaim pattern)
- Remove delivering status, claim/unclaim/recover from db.ts
- Remove claim/unclaim API endpoints from queue routes
- Remove validateAgentResponse dead code from routing.ts
- Remove recoverConversation from queue-processor hot path

Keep bugs 2-4: case-insensitive mentions, conversation lock,
prefix strip for @agent routing.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@jlia0
Copy link
Collaborator Author

jlia0 commented Feb 23, 2026

closes #134

@jlia0 jlia0 merged commit f1dbe9a into main Feb 23, 2026
@jlia0 jlia0 deleted the fix/bugs-2-3-4-from-pr134 branch February 23, 2026 14:30
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.

1 participant