fix(slack-channel-monitor): stop silently dropping trigger messages (search lag, @mention search, thread context, auth cache) - #541
Conversation
…search lag, @mention search, thread context, auth cache) Four fixes for the poller, all hit in production on a real deployment: 1. search.messages index lag: Slack's search index lags the live stream by ~1-2 min, so filtering search results by last_poll silently dropped any trigger message posted during the lag. Search now runs over a fixed 1-hour window (SEARCH_LOOKBACK_SECONDS) and processed_ts dedupes. 2. @mention triggers unsearchable: search.messages does not index the leading "@" of a mention and a quoted phrase does not match a mention either, so a quoted TRIGGER_PHRASE query never matched. Search for the bare term and keep the exact _has_trigger() match afterwards. 3. Lost thread context: search results carry no thread_ts, so a trigger posted as a thread reply looked like a root message. Resolve the real parent via conversations.replies when thread_ts is missing. 4. Bot identity with user token: auth.test on a user token returns the human owner, so with SLACK_USER_TOKEN every message from that human was treated as bot output and skipped. Resolve bot identity from SLACK_BOT_TOKEN when present, and cache the whole auth resolution (_slack_auth_once) to cut Slack HTTP calls ~90% on no-trigger runs. Also: INITIAL_LOOKBACK 70 -> 600 (processed_ts makes a wide window safe), channel_history gains an optional latest param used for root-level context gathering, and root-level triggers now include recent channel history (previously only thread replies did). Co-authored-by: openhands <openhands@all-hands.dev>
|
👋 This PR needs a couple of things fixed before OpenHands can review it:
Push an update once this is addressed and this check re-runs automatically. This is an automated check - no AI was used to generate this comment. |
|
AI note: this PR was created by an AI agent (OpenHands) on behalf of @hboisgibault. @OpenHands/team — friendly ping for triage: the linked issue #542 cannot receive the |
|
I'm on it! hboisgibault can track my progress at all-hands.dev |
|
@OpenHands/team — follow-up from @hboisgibault's comment: I verified the failing check locally, and the only error is the linked-issue gate: Everything else passes:
The block is purely that a contributor account can't add the This comment was created by an AI agent (OpenHands) on behalf of @hboisgibault. |
|
I'm on it! hboisgibault can track my progress at all-hands.dev |
|
The comment on PR #541 asked a maintainer-triaged question — I investigated and answered it, posting a comment on the PR. What I found The PR's only failing check is "Validate PR description", and the sole error in the latest run is: Verification I ran (all local, against the current PR head
The blocker A contributor token cannot add labels to the upstream repo ( What I did Posted a comment on PR #541 (permalink)) confirming there's no code change needed. As soon as a maintainer adds the |
|
Investigation complete. Here's my full assessment of the comment addressed to me on PR #541. What the comment asksThe comment (from @hboisgibault, on behalf of the PR author) is a triage request to @OpenHands/team, not a code-change request: "Could a maintainer add the What I verified (all fresh, just now)
Why I can't unblock it from this sideMy token is the contributor account ( …exactly what the comment reported. Issue #542 still has no labels as of this check — a maintainer hasn't acted yet. . What a maintainer needs to do (and what happens next, automatically)gh issue edit 542 --repo OpenHands/extensions --add-label bugOr use the GitHub UI (Issues → #542 → Labels →
What I did / did not do
Bottom line: The PR is code-complete and ready; the only thing standing between it and a green check is a maintainer adding the |
Why
Four bugs in the
slack-channel-monitorpoller cause trigger messages to be silently dropped or mishandled. All four were reproduced against a real long-running deployment (polling 1×/min for ~1 month, 33 channels):search.messagesindex lag: Slack's search index lags the live stream by ~1-2 min, and the script bounded search results bylast_poll(which advances every run). A message posted just before a run was often only searchable afterlast_pollmoved past it — dropped forever.@mentiontriggers unsearchable:search.messagesdoes not index the leading@of a mention, and a quoted phrase ("openhands") does not match an@openhandsmention either. Since the default trigger phrase is an @mention, the search path effectively never matched.thread_ts, so a trigger posted as a thread reply looked like a root message and started a fresh conversation instead of continuing the tracked one.auth.teston a user token returns the human owner, so withSLACK_USER_TOKENevery message that human posted was classified as bot output and skipped.Summary
SEARCH_LOOKBACK_SECONDS) withprocessed_tsdeduplication, instead of bounding bylast_poll.trigger.lstrip("@"));_has_trigger()remains the authoritative exact match.conversations.replieswhen a search result has nothread_ts.SLACK_BOT_TOKENwhen configured (user tokenauth.testreturns the human), and cache the whole auth resolution in_slack_auth_once()(~90% fewer Slack calls on no-trigger runs).INITIAL_LOOKBACK70 → 600 (safe with dedup),channel_history()gains optionallatestparam, root-level triggers now include recent channel history in the conversation prompt.Issue Number
Fixes #542 — filed while operating a production deployment of this skill (needs
ready-for-devtriage, see PR comment).How to Test
SLACK_BOT_TOKENandSLACK_USER_TOKEN.@mentiontrigger in a monitored channel and confirm the conversation opens within 1-2 poll runs even though the message is brand-new (fixes 1 & 2: previously it was often never detected).SLACK_USER_TOKENconfigured and confirm the human owner's own trigger messages are processed and the bot identity logged is the bot's (fix 4).This exact code has been running in production for ~3 weeks on the deployment described above.
Video/Screenshots
N/A — behavior is observable in the poller's debug logs (
slack_poller_debug.log):search.messages returned N trigger candidate(s),Resolved thread parent …, and the loggedBot user IDnow matching the bot rather than the token owner.Notes
INITIAL_LOOKBACKwidening only adds catch-up fetches on cold start;processed_tsdeduplication prevents double-processing.Co-authored-by: openhands openhands@all-hands.dev