Skip to content

discord: harden preflight/reply path against slow lookup latency#23158

Closed
danielstarman wants to merge 4 commits into
openclaw:mainfrom
danielstarman:fix/discord-preflight-latency-22378
Closed

discord: harden preflight/reply path against slow lookup latency#23158
danielstarman wants to merge 4 commits into
openclaw:mainfrom
danielstarman:fix/discord-preflight-latency-22378

Conversation

@danielstarman

@danielstarman danielstarman commented Feb 22, 2026

Copy link
Copy Markdown

Summary

  • Fix Discord preflight/reply stalls tied to slow channel and PluralKit lookups.
  • Add bounded timeout/abort handling and guarded retry behavior so monitor flow fails fast instead of hanging.
  • Harden thread-bound routing when Discord payload thread metadata is incomplete.
  • Keep scope strictly to Discord monitor/pluralkit paths and related tests.

Linked Issue

Closes #22378.

What Changed

  • Preflight guild fast path: skip early channel REST lookup for guild traffic.
  • Channel lookup timeout support in preflight/thread-parent resolution.
  • PluralKit lookup timeout + abort support; bot-path retry only on timeout/abort-like failures.
  • Thread binding lookup now consistently uses channel_id.
  • Bound-thread session detection based on binding/session key presence.
  • Reply typing start is non-blocking (fire-and-forget) so reply dispatch is not delayed by typing REST latency.

Scope

Changed files:

  • src/discord/monitor/message-handler.preflight.ts
  • src/discord/monitor/message-handler.process.ts
  • src/discord/monitor/message-utils.ts
  • src/discord/monitor/threading.ts
  • src/discord/pluralkit.ts
  • Discord test updates only

Validation

  • pnpm build passes.
  • pnpm check passes.
  • pnpm test passes.
  • Targeted Discord suites pass:
    • src/discord/monitor/message-handler.process.test.ts
    • src/discord/monitor/message-utils.test.ts
    • src/discord/pluralkit.test.ts
    • src/discord/monitor.tool-result.sends-status-replies-responseprefix.test.ts
    • src/discord/monitor/message-handler.preflight.test.ts

Risk Notes

  • No new permissions, auth model changes, or config migrations.
  • Network behavior changed only by adding timeout/abort bounds on existing Discord/PluralKit calls.

Transparency

  • AI-assisted: Yes (Codex).
  • Testing level: fully tested (pnpm build, pnpm check, pnpm test, plus targeted Discord suites).

Context

Greptile Summary

Added timeout/abort handling to Discord channel and PluralKit lookups to prevent monitor flow from stalling when external APIs are slow. Guild messages now skip early channel REST lookup (payload-first fast path), PluralKit lookups retry with extended timeout on abort-like errors for bot messages, and reply typing starts fire-and-forget to avoid blocking dispatch. Thread binding detection now consistently uses channel_id and checks binding presence rather than threadChannel existence.

Confidence Score: 4/5

  • This PR is safe to merge with low risk - adds defensive timeout handling without changing core business logic.
  • The PR implements well-scoped timeout and retry mechanisms with comprehensive test coverage. All changes are defensive additions (timeouts, abort handling, fast paths) that fail safely. Tests validate timeout behavior, PluralKit retry logic, and non-blocking typing. However, one minor issue was found: the timeout wrapper in message-utils.ts doesn't call unref() conditionally, which could cause subtle issues in environments where it's not available.
  • Pay close attention to src/discord/monitor/message-utils.ts line 90 - the unref() call should be conditional.

Last reviewed commit: 13e72ca

(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!

@openclaw-barnacle openclaw-barnacle Bot added channel: discord Channel integration: discord size: M labels Feb 22, 2026

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

9 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment thread src/discord/monitor/message-utils.ts
@danielstarman
danielstarman force-pushed the fix/discord-preflight-latency-22378 branch 3 times, most recently from 98062db to 3f14c0e Compare February 22, 2026 08:05
@danielstarman
danielstarman force-pushed the fix/discord-preflight-latency-22378 branch from 3f14c0e to 8e3e8c2 Compare February 22, 2026 15:05
@danielstarman
danielstarman deleted the fix/discord-preflight-latency-22378 branch February 23, 2026 04:32
@danielstarman

Copy link
Copy Markdown
Author

Closing pull request and cleaning up branch as #22396 was merged in for this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: discord Channel integration: discord size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Discord MESSAGE_CREATE events not routed to agent (fire-and-forget bug in DiscordMessageListener)

1 participant