← Back to PRs

#21721: fix: bind Slack slash options handler context

by AIflow-Labs open 2026-02-20 08:46 View on GitHub →
channel: slack size: S
## What this fixes Closes #21715. Slack Socket Mode can crash on startup due to invoking Slack Bolt `App.options` with a detached context (`this` undefined) during external select argument menu registration. ## Root cause `ctx.app.options` is extracted and invoked without binding in `registerArgOptions`. ## Fix Bind the method to `ctx.app` before registration: ```ts const optionsHandler = (ctx.app as unknown as { options?: (...) => void }).options?.bind(ctx.app); ``` This preserves the method context and avoids runtime `Cannot read properties of undefined (reading 'listeners')`. ## Validation - `pnpm test src/slack/monitor/slash.test.ts` - `pnpm test` - `pnpm tsgo` - `pnpm check` ## Notes Added regression coverage in `src/slack/monitor/slash.test.ts` to assert option registration receives bound `app` context. <!-- greptile_comment --> <h3>Greptile Summary</h3> Fixed a critical runtime bug where Slack Socket Mode would crash on startup due to `this` context loss when registering external select menu options. The root cause was extracting the `options` method from `ctx.app` without binding it, causing `Cannot read properties of undefined (reading 'listeners')` errors when Slack Bolt attempted to access `this.listeners` internally. The fix applies `.bind(ctx.app)` to preserve method context, consistent with how Slack Bolt's `App` class expects its methods to be called. Added regression test that validates the `options` handler receives proper `this` binding. <h3>Confidence Score: 5/5</h3> - This PR is safe to merge with minimal risk - The fix addresses a clear bug (method context loss) with a standard JavaScript solution (`.bind()`), adds appropriate regression test coverage, and follows the same pattern used elsewhere in the codebase where methods are called directly. The change is minimal, focused, and prevents a production crash. - No files require special attention <sub>Last reviewed commit: 7763038</sub> <!-- greptile_other_comments_section --> <sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub> <!-- /greptile_comment -->

Most Similar PRs