fix(slack-agent): give the bot the whole thread, alert cards included - #351
Merged
Conversation
Replying to a Maple alert in Slack meant hand-writing a recap first: the agent reached the model with no context at all. Two eve behaviours stacked. eve reads a thread message's content from `text` alone, and our alert notifications have none — the blocks ride inside a colored attachment (AlertDeliveryDispatch.ts; top-level text would render as a duplicate line above the color bar). The alert arrived as an empty <content></content>. And `since: "last-agent-reply"` counted that alert as the agent's own last reply — eve's `isMe` is `bot_id !== undefined`, i.e. any bot — so context was cut off *after* it, dropping the alert and everything before. Any third-party app in the channel truncated context the same way. So render context ourselves: same <slack_thread_context> envelope, content falling back to blocks and attachments, and the full thread rather than an incremental boundary (which also survives a session lost to a redeploy). Speakers are attributed with the workspace's real bot user id, learned free from the webhook envelope's `authorizations`, so the agent's own replies are `agent` and alert cards are `bot` — the model no longer reads an alert as something it already reported. Wired through onAppMention/onDirectMessage, which do exactly what eve's defaults did plus return the transcript as `context`. It runs after eve's 200 to Slack, so it is off the webhook budget, and it cannot throw: eve drops the whole mention when that handler does, so a Slack failure degrades to no context instead of no reply. Two bounds documented, not widened: eve's refresh fetches one oldest-first page of 50 replies, and an un-mentioned reply still needs the 30-minute engagement window in thread-follow-up.ts. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
🍁 Maple PR previewNote Preview resources were removed when this pull request closed. Final commit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replying to a Maple alert in Slack meant hand-writing a recap first — the agent reached the model with no context at all. Two eve behaviours stacked:
textalone. Our alert notifications have none: the blocks ride inside a colored attachment (AlertDeliveryDispatch.ts— top-level text would render as a duplicate line above the color bar). eve rendered the alert as an empty<content></content>.since: "last-agent-reply"counted that alert as the agent's own reply (eve'sisMeisbot_id !== undefined, i.e. any bot) and cut context off after it, dropping the alert and everything before. Any third-party app in the channel truncated context the same way.Changes
agent/lib/thread-context.ts— renders turn context ourselves in eve's same<slack_thread_context>/<slack_message>envelope, with content falling back to top-level blocks → attachment blocks → attachmentfallback. Covers header/section/fields/actions (buttons emitlabel: url, so the incident link survives)/context/rich_text/markdown/image, plus a generic text sweep for block types it has no case for. Boundary is the full thread, which also survives a session lost to a redeploy — where an incremental boundary silently assumes history that is gone.agent/lib/bot-identity.ts— learns the workspace's bot user id from each verified webhook'sauthorizations(free, noauth.test), so the agent's own replies areagentand alert cards / other apps arebot. The model no longer reads an alert as something it already reported.thread-follow-up.tsnow shares its envelope parser.agent/channels/slack.ts—threadContextreplaced byonAppMention/onDirectMessagethat do exactly what eve's defaults did (typing indicator +defaultSlackAuth) plus return the transcript ascontext. Runs after eve's 200 to Slack, so it is off the webhook budget, and it cannot throw: eve drops the whole mention when that handler does, so a Slack failure degrades to no context instead of no reply.agent/instructions.md— read the thread context, never ask the user to restate it, and treat an opening alert card as the subject (load the incident-investigation skill).slackChannel({ threadContext }).Verification
bun test188 pass (15 new: alert-card rendering, rich-text paragraphs, attribution, load path),bun typecheckclean, oxfmt/oxlint applied. Verified against eve's compiled channel code, not a live workspace — the end-to-end check is the README's acceptance item (c): @mention in a real alert-notification thread.Two bounds documented rather than silently widened: eve's
thread.refresh()fetches one oldest-first page of 50 replies, and an un-mentioned reply still needs the 30-minute engagement window inthread-follow-up.ts.🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.