feat(slack): add button-based approval flow for dangerous commands - #3898
Closed
LevSky22 wants to merge 4 commits into
Closed
feat(slack): add button-based approval flow for dangerous commands#3898LevSky22 wants to merge 4 commits into
LevSky22 wants to merge 4 commits into
Conversation
The original PR was built on the old post-loop pop_pending approval architecture, which upstream replaced with a blocking mechanism in tools/approval.py (agent thread blocks until user responds via /approve or /deny). Rebased onto current main and adapted: - _handle_platform_approval_action now calls has_blocking_approval / resolve_gateway_approval instead of terminal_tool(force=True) and self._pending_approvals, matching the blocking flow used by _handle_approve_command and _handle_deny_command. - Updated TestPlatformApprovalActions tests to mock the blocking approval API (has_blocking_approval, resolve_gateway_approval) instead of the removed _pending_approvals dict. Replaced the timestamp-expiry test (no longer applicable) with a no-pending test. - Preserved _download_slack_file team_id parameter added upstream. All 93 tests in test_slack.py and test_approve_deny_commands.py pass.
LevSky22
force-pushed
the
feat/slack-approval-buttons
branch
from
April 5, 2026 19:01
92b505d to
fb086a4
Compare
When a gateway user chose "once", approve_session() was still being
called (because the condition tested `choice in ("once", "session")`),
silently adding the pattern to the session allowlist and making every
subsequent identical command skip the prompt.
Fix: only call approve_session() when choice is "session" or "always".
Also adds a regression test (TestApproveOnceScope) that runs two
dangerous commands sequentially, approves the first with "once", and
asserts the second still triggers a fresh prompt.
Refs: NousResearch#4698
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
LevSky22
force-pushed
the
feat/slack-approval-buttons
branch
from
April 5, 2026 19:50
b916961 to
86f8725
Compare
19 tasks
teknium1
added a commit
that referenced
this pull request
Apr 7, 2026
…ontext Slack: - Add Block Kit interactive buttons for command approval (Allow Once, Allow Session, Always Allow, Deny) via send_exec_approval() - Register @app.action handlers for each approval button - Add _fetch_thread_context() — fetches thread history via conversations.replies when bot is first @mentioned mid-thread - Fix _has_active_session_for_thread() to use build_session_key() instead of manual key construction (fixes session key mismatch bug where thread_sessions_per_user flag was ignored, ref PR #5833) Telegram: - Add InlineKeyboard approval buttons via send_exec_approval() - Add ea:* callback handling in _handle_callback_query() - Uses monotonic counter + _approval_state dict to map button clicks back to session keys (avoids 64-byte callback_data limit) Both platforms now auto-detected by the gateway runner's _approval_notify_sync() — any adapter with send_exec_approval() on its class gets button-based approval instead of text fallback. Inspired by community PRs #3898 (LevSky22), #2953 (ygd58), #5833 (heathley). Implemented fresh on current main. Tests: 24 new tests covering button rendering, action handling, thread context fetching, session key fix, double-click prevention.
teknium1
added a commit
that referenced
this pull request
Apr 7, 2026
…ontext Slack: - Add Block Kit interactive buttons for command approval (Allow Once, Allow Session, Always Allow, Deny) via send_exec_approval() - Register @app.action handlers for each approval button - Add _fetch_thread_context() — fetches thread history via conversations.replies when bot is first @mentioned mid-thread - Fix _has_active_session_for_thread() to use build_session_key() instead of manual key construction (fixes session key mismatch bug where thread_sessions_per_user flag was ignored, ref PR #5833) Telegram: - Add InlineKeyboard approval buttons via send_exec_approval() - Add ea:* callback handling in _handle_callback_query() - Uses monotonic counter + _approval_state dict to map button clicks back to session keys (avoids 64-byte callback_data limit) Both platforms now auto-detected by the gateway runner's _approval_notify_sync() — any adapter with send_exec_approval() on its class gets button-based approval instead of text fallback. Inspired by community PRs #3898 (LevSky22), #2953 (ygd58), #5833 (heathley). Implemented fresh on current main. Tests: 24 new tests covering button rendering, action handling, thread context fetching, session key fix, double-click prevention.
teknium1
added a commit
that referenced
this pull request
Apr 7, 2026
…ontext (#5890) Slack: - Add Block Kit interactive buttons for command approval (Allow Once, Allow Session, Always Allow, Deny) via send_exec_approval() - Register @app.action handlers for each approval button - Add _fetch_thread_context() — fetches thread history via conversations.replies when bot is first @mentioned mid-thread - Fix _has_active_session_for_thread() to use build_session_key() instead of manual key construction (fixes session key mismatch bug where thread_sessions_per_user flag was ignored, ref PR #5833) Telegram: - Add InlineKeyboard approval buttons via send_exec_approval() - Add ea:* callback handling in _handle_callback_query() - Uses monotonic counter + _approval_state dict to map button clicks back to session keys (avoids 64-byte callback_data limit) Both platforms now auto-detected by the gateway runner's _approval_notify_sync() — any adapter with send_exec_approval() on its class gets button-based approval instead of text fallback. Inspired by community PRs #3898 (LevSky22), #2953 (ygd58), #5833 (heathley). Implemented fresh on current main. Tests: 24 new tests covering button rendering, action handling, thread context fetching, session key fix, double-click prevention.
Contributor
Tommyeds
pushed a commit
to Tommyeds/hermes-agent
that referenced
this pull request
Apr 12, 2026
…ontext (NousResearch#5890) Slack: - Add Block Kit interactive buttons for command approval (Allow Once, Allow Session, Always Allow, Deny) via send_exec_approval() - Register @app.action handlers for each approval button - Add _fetch_thread_context() — fetches thread history via conversations.replies when bot is first @mentioned mid-thread - Fix _has_active_session_for_thread() to use build_session_key() instead of manual key construction (fixes session key mismatch bug where thread_sessions_per_user flag was ignored, ref PR NousResearch#5833) Telegram: - Add InlineKeyboard approval buttons via send_exec_approval() - Add ea:* callback handling in _handle_callback_query() - Uses monotonic counter + _approval_state dict to map button clicks back to session keys (avoids 64-byte callback_data limit) Both platforms now auto-detected by the gateway runner's _approval_notify_sync() — any adapter with send_exec_approval() on its class gets button-based approval instead of text fallback. Inspired by community PRs NousResearch#3898 (LevSky22), NousResearch#2953 (ygd58), NousResearch#5833 (heathley). Implemented fresh on current main. Tests: 24 new tests covering button rendering, action handling, thread context fetching, session key fix, double-click prevention.
angelburgosrosado
pushed a commit
to angelburgosrosado/hermes-agent
that referenced
this pull request
Apr 27, 2026
…ontext (NousResearch#5890) Slack: - Add Block Kit interactive buttons for command approval (Allow Once, Allow Session, Always Allow, Deny) via send_exec_approval() - Register @app.action handlers for each approval button - Add _fetch_thread_context() — fetches thread history via conversations.replies when bot is first @mentioned mid-thread - Fix _has_active_session_for_thread() to use build_session_key() instead of manual key construction (fixes session key mismatch bug where thread_sessions_per_user flag was ignored, ref PR NousResearch#5833) Telegram: - Add InlineKeyboard approval buttons via send_exec_approval() - Add ea:* callback handling in _handle_callback_query() - Uses monotonic counter + _approval_state dict to map button clicks back to session keys (avoids 64-byte callback_data limit) Both platforms now auto-detected by the gateway runner's _approval_notify_sync() — any adapter with send_exec_approval() on its class gets button-based approval instead of text fallback. Inspired by community PRs NousResearch#3898 (LevSky22), NousResearch#2953 (ygd58), NousResearch#5833 (heathley). Implemented fresh on current main. Tests: 24 new tests covering button rendering, action handling, thread context fetching, session key fix, double-click prevention.
02356abc
pushed a commit
to 02356abc/hermes-agent
that referenced
this pull request
May 14, 2026
…ontext (NousResearch#5890) Slack: - Add Block Kit interactive buttons for command approval (Allow Once, Allow Session, Always Allow, Deny) via send_exec_approval() - Register @app.action handlers for each approval button - Add _fetch_thread_context() — fetches thread history via conversations.replies when bot is first @mentioned mid-thread - Fix _has_active_session_for_thread() to use build_session_key() instead of manual key construction (fixes session key mismatch bug where thread_sessions_per_user flag was ignored, ref PR NousResearch#5833) Telegram: - Add InlineKeyboard approval buttons via send_exec_approval() - Add ea:* callback handling in _handle_callback_query() - Uses monotonic counter + _approval_state dict to map button clicks back to session keys (avoids 64-byte callback_data limit) Both platforms now auto-detected by the gateway runner's _approval_notify_sync() — any adapter with send_exec_approval() on its class gets button-based approval instead of text fallback. Inspired by community PRs NousResearch#3898 (LevSky22), NousResearch#2953 (ygd58), NousResearch#5833 (heathley). Implemented fresh on current main. Tests: 24 new tests covering button rendering, action handling, thread context fetching, session key fix, double-click prevention.
gweeteve
pushed a commit
to gweeteve/hermes-agent
that referenced
this pull request
Jun 2, 2026
…ontext (NousResearch#5890) Slack: - Add Block Kit interactive buttons for command approval (Allow Once, Allow Session, Always Allow, Deny) via send_exec_approval() - Register @app.action handlers for each approval button - Add _fetch_thread_context() — fetches thread history via conversations.replies when bot is first @mentioned mid-thread - Fix _has_active_session_for_thread() to use build_session_key() instead of manual key construction (fixes session key mismatch bug where thread_sessions_per_user flag was ignored, ref PR NousResearch#5833) Telegram: - Add InlineKeyboard approval buttons via send_exec_approval() - Add ea:* callback handling in _handle_callback_query() - Uses monotonic counter + _approval_state dict to map button clicks back to session keys (avoids 64-byte callback_data limit) Both platforms now auto-detected by the gateway runner's _approval_notify_sync() — any adapter with send_exec_approval() on its class gets button-based approval instead of text fallback. Inspired by community PRs NousResearch#3898 (LevSky22), NousResearch#2953 (ygd58), NousResearch#5833 (heathley). Implemented fresh on current main. Tests: 24 new tests covering button rendering, action handling, thread context fetching, session key fix, double-click prevention.
waefrebeorn
pushed a commit
to waefrebeorn/slermes
that referenced
this pull request
Jul 2, 2026
…ontext (NousResearch#5890) Slack: - Add Block Kit interactive buttons for command approval (Allow Once, Allow Session, Always Allow, Deny) via send_exec_approval() - Register @app.action handlers for each approval button - Add _fetch_thread_context() — fetches thread history via conversations.replies when bot is first @mentioned mid-thread - Fix _has_active_session_for_thread() to use build_session_key() instead of manual key construction (fixes session key mismatch bug where thread_sessions_per_user flag was ignored, ref PR NousResearch#5833) Telegram: - Add InlineKeyboard approval buttons via send_exec_approval() - Add ea:* callback handling in _handle_callback_query() - Uses monotonic counter + _approval_state dict to map button clicks back to session keys (avoids 64-byte callback_data limit) Both platforms now auto-detected by the gateway runner's _approval_notify_sync() — any adapter with send_exec_approval() on its class gets button-based approval instead of text fallback. Inspired by community PRs NousResearch#3898 (LevSky22), NousResearch#2953 (ygd58), NousResearch#5833 (heathley). Implemented fresh on current main. Tests: 24 new tests covering button rendering, action handling, thread context fetching, session key fix, double-click prevention.
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.
What does this PR do?
Adds Slack-native approval buttons for dangerous command prompts.
Hermes currently replies in Slack threads, but Slack custom slash commands are not supported in threads. That makes the existing text-based approval flow awkward for Slack, especially when a dangerous command needs explicit approval. This PR adds Block Kit approval buttons for Slack so approvals can happen directly inside the threaded conversation without relying on slash commands.
Rebase note: This branch has been rebased onto current main and adapted to the blocking gateway approval mechanism introduced after the original commit. The old
_pending_approvalsdict +terminal_tool(force=True)approach has been replaced withhas_blocking_approval/resolve_gateway_approvalfromtools/approval.py.This PR also includes the fix from #4698 (
approve-oncemust not grant session-wide approval) along with its regression test, so both features land together and are covered end-to-end.Related Issue
No existing issue — this is a new feature.
Type of Change
Changes Made
gateway/platforms/slack.py.gateway/run.py(has_blocking_approval/resolve_gateway_approval).approve_session()being called forchoice == "once"(refs fix(gateway): make plain /approve truly one-time #4698) — one-time approvals no longer silently become session-wide.How to Test
Approve Once,Approve Session, orDenyin the Slack thread and verify the pending command behaves correctly.Approve Onceprompts again on the next identical dangerous command (regression for fix(gateway): make plain /approve truly one-time #4698).pytest tests/gateway/test_slack.py tests/gateway/test_approve_deny_commands.py -q.Checklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/AScreenshots / Logs
pytest tests/gateway/test_slack.py tests/gateway/test_approve_deny_commands.py -qtest_approve_deny_commands.pypass