Skip to content

feat: let agents read the owner's replies in a tracked Slack channel - #30735

Merged
KiroCrewCaptain merged 1 commit into
mainfrom
fix/18747-read-slack-history
Nov 7, 2026
Merged

KiroCrewCaptain merged 1 commit into
mainfrom
fix/18747-read-slack-history

Conversation

@bolichen97

@bolichen97 bolichen97 commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: An agent can read the owner's reply in a tracked Slack channel or thread, so an unattended agent can wait for an approval given in Slack.

Agents can send Slack messages (send_message) and read a profile (read_slack_profile), but nothing reads what was said back. A "the owner approves in a thread, the agent picks it up" flow has to move to the dashboard chat, and an unattended cron agent has no way to see the answer at all unless the operator has set up the separate per-user OAuth Slack MCP server.

Why it matters

Reply-driven Slack automation (approval loops, "reply here to continue") cannot be built today. The tool closes the send-only gap with the bot token the install already holds, and adds no new way in: it reads only channels the operator already tracks, and only the words of the sender the inbound gate already lets talk to the agent.

Not a goal

  • Reading the owner's DMs. That is a broader authorization call and stays out.
  • Returning what anyone other than the owner wrote. Their messages are listed, without text.
  • New Slack scopes, a UI surface, or any change to an existing tool or route.

What changed (motivation → approach → change)

Piece What it does
read_slack_history MCP tool (mcp_tools/messaging.py) channel, optional thread_ts, oldest (only later messages) and limit (1-100, default 20). Returns [{user, ts, admitted, text}], newest first
POST /api/slack-history (dashboard/messaging_api/slack_workspace.py) Refuses (403) a channel that is untracked, that the inbound gate's channels policy refuses, or whose home workspace its origin check (slack.allowed_enterprise_ids) does not admit. Text comes back only when is_allowed_user admits the sender; any other message has admitted: false and empty text. A failed Slack read is a 502 with a non-empty error, never an empty list. Every refusal carries a code
RealSlackClient.fetch_history (slack/client.py) Reads the channel timeline or one thread on the bot-token client and channels:history / groups:history scopes that fetch_thread_replies already reads channel threads with, keeps only messages after oldest (a thread's parent included), drops bot posts before the limit applies, and raises on every error, a read that runs out of pages first included

The shape mirrors read_slack_profile (tool, then gateway route, then Slack client). It reuses the tracked-channel allowlist the pins and reactions routes apply, and the same channels-policy and workspace-origin checks the inbound message gate runs, so a channel or workspace the gate closes is closed to this read too. Text from a channel member the gate does not admit could carry instructions into an unattended agent. Of the two ways to stop that (wrap it as untrusted, or withhold it) this withholds it: the inbound gate already decides who may talk to the agent, and the read follows that decision instead of adding a second policy. A channel agent is refused at dispatch and listed in CHANNEL_AGENT_BLOCKED_TOOLS (channel.py), for the reason session_read_message is: it could relay one channel's messages into its own thread. A thread is read to its last page, since replies arrive oldest first, and its parent, which Slack returns on every page whatever oldest says, is kept once and only when it is newer than oldest. Everything else is registration beside the profile tool's: the route in dashboard/server_runtime/mcp_routes.py and dashboard/server_internal_paths.py, its re-exports in dashboard/handlers/, the argument schema in validation_parts/messaging_session_schemas.py, validation_parts/server_registries.py and validation.py, and the title in data/mcp_tool_titles.json. docs/architecture/mcp.md, the slack-gateway, messaging and persistent-agent-channels specs, and a docs/feature-map/README.md row describe the tool.

Backwards compatibility

Compatible: a new tool, route and client method; no existing field, validator, route or tool changes.

Removes nothing: the diff only adds a read path.

Tests

  • test/test_slack_history_read.py: an untracked channel, a tracked one the policy refuses (the channel itself, or the Slack transport), and one whose workspace the origin check does not admit are refused before any Slack read; only the owner's text comes back; a failed Slack read is an error, a timeout with an empty message included; bot posts (bot_id or subtype: bot_message) are dropped before the limit and the timeline stops paging once it has enough; a thread read pages to its newest reply and drops what is not after oldest; a parent repeated on every page comes back once; a timeline or thread read past the page cap raises; the tool refuses a channel agent (at dispatch and in the permission-prompt list); the tool forwards its arguments with the verified caller key and redacts the text. Each of those guards was reverted once and its test went red.
  • Registration pins updated for the new name: test_dashboard_server_composition_contract_reach.py (MCP route table rows and digest), test_handlers_messaging_composition_contract.py (re-export count), test_messaging_api_non_object_body.py (non-object body row), test_remote_session_local_only_tools.py (remote-safe core tool), test_validation_parts_facade.py (schema name).
  • Determinism: the new file is green 20/20 at -n0, 10/10 at -n 4 --dist loadgroup --max-worker-restart=2 beside test_send_message_targeted.py and test_fetch_thread_replies.py, and in a shuffled order (seed 17311).

Manual verification

Not run against a live Slack workspace. The unit tests drive the route through aiohttp, the client through a fake web client returning real conversations.history / conversations.replies page shapes, and the tool through the MCP dispatcher.

Screenshots / video

N/A — no frontend change.

Related Issues

Closes #18747

Builds on #18748 by @iamwhatever, which reworked #7930 by @Patcurley1.

Sibling sweep

N/A — feature PR.

Pattern harvest

N/A — feature PR.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

Contributed under the project's Apache-2.0 license (see CONTRIBUTING.md).

@bolichen97
bolichen97 requested review from a team and KiroCrewCaptain as code owners November 5, 2026 19:56
@bolichen97
bolichen97 requested a review from mbriones98 November 5, 2026 19:56
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 5, 2026
@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 76cc7d5c3d439fc5f058c88cea186fe23b33bcfa touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 76cc7d5c3d439fc5f058c88cea186fe23b33bcfa — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

No design-level concerns. The read reuses the inbound gate's existing admission decisions (tracked channel, channels policy, workspace origin, is_allowed_user), so it adds no new trust policy, and it removes nothing.

Notes

  • "The owner" in the tool description is really whoever is_allowed_user admits, which can be several allow-listed humans. An approval flow built on admitted: true should be documented as "an admitted sender", not "the owner".

[DESIGN-REVIEWED] 76cc7d5

Description read

[DESCRIPTION-READ] aeda9e5a6f3aa05739abf593436f0009366bcee16d86b954a03d43ac4ea2aad9

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 76cc7d5c3d439fc5f058c88cea186fe23b33bcfa — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

Nothing blocks: each item traces to #18747's send-only gap or to a boundary already on record (the inbound sender gate, channel-agent containment). The one undeclared rider is a harm-free retry on the gate's own lookup.

What this change ships

Inventory (7 items) — 6 justified

Intent: An unattended agent can see the owner's Slack reply (an approval, a follow-up) in a tracked channel or thread. ADDITION (Closes #18747).

  1. Agents get a new read_slack_history tool that reads a tracked channel or one thread, newest first — justified
  2. A new gateway route POST /api/slack-history refuses untracked channels, channels the policy refuses, and channels in a workspace that isn't allowed — justified
  3. Only the owner's words come back; other senders show up as admitted: false with no text — justified
  4. Channel agents are refused the tool, both at dispatch and in the blocked-tools list — justified
  5. A failed or truncated Slack read comes back as an error, never as "no messages" — justified
  6. Bot posts are dropped before the limit applies, so a run of bot posts can't hide a reply — justified
  7. The channel-workspace lookup can now retry after a failed lookup, and a later success clears the failure mark — undeclared

[FIRST-PRINCIPLES-REVIEWED] 76cc7d5

Description read

[DESCRIPTION-READ] 0157fa495ae438d2b11f0b8cb599d030c64ec83244d7e1b5033d50d449166ad7

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 76cc7d5c3d439fc5f058c88cea186fe23b33bcfa — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 76cc7d5

Verdict parsed from the review's SHA-scoped output markers for commit 76cc7d5c3d439fc5f058c88cea186fe23b33bcfa.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 76cc7d5c3d439fc5f058c88cea186fe23b33bcfa false-positive: <reason, 20 to 500 characters>

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 5, 2026
@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 76cc7d5c3d439fc5f058c88cea186fe23b33bcfa and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 76cc7d5

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 76cc7d5c3d439fc5f058c88cea186fe23b33bcfa false-positive: <reason, 20 to 500 characters>

@bolichen97
bolichen97 enabled auto-merge (squash) November 5, 2026 20:13
@bolichen97
bolichen97 force-pushed the fix/18747-read-slack-history branch from 84d729e to 3eafcf6 Compare November 5, 2026 23:33
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Nov 5, 2026
@bolichen97

bolichen97 commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97]

  • History reads bypass the workspace allowlist (span=95131bdc5ec7)

fixed in 3eafcf6: the history route now runs the existing workspace origin check on the channel's home workspace before any Slack read, so a workspace removed from slack.allowed_enterprise_ids is refused (403 workspace_not_allowed), the same as its inbound messages.
Pinned by test_a_workspace_the_origin_gate_refuses_is_refused_before_any_slack_read, which fails with the check removed.

@bolichen97

bolichen97 commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97]

  • The new history feature is absent from the feature map (span=8ef0489d1123)

fixed in 3eafcf6: docs/feature-map/README.md has an "Agent chat history read" row naming the read_slack_history tool, the handlers/messaging.py facade and POST /api/slack-history.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 6, 2026
@bolichen97
bolichen97 force-pushed the fix/18747-read-slack-history branch from 3eafcf6 to b91cd72 Compare November 6, 2026 00:38
@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97]

  • Timeline page-cap exhaustion silently hides owner replies (span=1b57716b46b4)

fixed in b91cd72: fetch_history now raises when it runs out of pages on the channel timeline too, not only on a thread, so the route answers 502 history_read_failed instead of an empty or short list. The error tells the agent to pass a later oldest.
Pinned by test_a_read_past_the_page_cap_raises_rather_than_return_a_partial_list, parametrized over the timeline and a thread with a bot-only page; the timeline case fails on the previous head.

@github-actions github-actions Bot added readiness: checking Automated validation is still running merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Nov 6, 2026
@bolichen97
bolichen97 force-pushed the fix/18747-read-slack-history branch from b91cd72 to 63ede75 Compare November 6, 2026 02:22
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Nov 6, 2026
@bolichen97
bolichen97 force-pushed the fix/18747-read-slack-history branch from ba0aaf6 to 41aab35 Compare November 6, 2026 12:33
@bolichen97

bolichen97 commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in docs/architecture/mcp.md, docs/feature-map/README.md, docs/system-specs/modules/messaging.md, docs/system-specs/modules/slack-gateway.md and src/kiro_crew/mcp_tools/messaging.py since this head went green (c90e2c0 -> 090dad8); CI re-running. The rebase was clean and the patch is unchanged; the related tests, mypy and the lint and doc gates pass on the new base.

[operator: bolichen97]

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed readiness: passed Eligible automated validation passed for the current revision readiness: checking Automated validation is still running labels Nov 6, 2026
buluoray
buluoray previously approved these changes Nov 6, 2026

@buluoray buluoray 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.

🤖 Kiro Crew Auto-Pipeline [operator: buluoray]:

APPROVE at 41aab35.

What it does for users: an agent, including an unattended cron agent, can check whether the owner replied in a Slack channel the owner tracks, or in one thread there. An approval given in Slack can then move the agent forward, and the owner no longer has to repeat it in the dashboard.

Evidence for the read boundary

  • Only the owner's words come back. The route returns text only when is_allowed_user(user) is true, and returns empty text with admitted false otherwise (src/kiro_crew/dashboard/messaging_api/slack_workspace.py, the loop at the end of api_slack_history). At this head is_allowed_user is exactly is_owner (slack/handler_runtime/access.py:245-253: "only the owner ... is authorized"). The tool then runs credential and exfiltration-URL redaction again before the model sees the text (mcp_tools/messaging.py, read_slack_history).
  • Only a channel the owner chose to track. is_tracked_channel is checked first (access.py:273, membership in the tracking set the owner's track approval fills). After that come the inbound channels policy (channel_refusal plus channel_inbound_permitted) and the workspace origin gate (check_message_origin on the channel's own team). All of these run before any Slack call.
  • Containment. The route is on the strict internal path list (dashboard/server_internal_paths.py:125), so it needs loopback plus the internal secret and has no browser caller. The tool requires a strict caller identity and refuses a channel agent at dispatch (_deny_channel_agent_messaging). The name is also on CHANNEL_AGENT_BLOCKED_TOOLS (channel.py:196), so the permission matcher refuses it too.
  • Stateless. Each call is one request to the route, which does one bounded Slack read (fetch_history: at most 20 pages of 200) and keeps nothing apart from the audit record. Polling belongs to the agent, which passes oldest.
  • Mutation 1: making the text unconditional (dropping "if admitted else ''") reddens test_slack_history_read.py::test_only_the_owners_text_comes_back. Another person's text then reaches the response.
  • Mutation 2: removing the tracked-channel check reddens test_slack_history_read.py::test_an_untracked_channel_is_refused_before_any_slack_read (200 instead of 403). The worktree was clean after each mutation, and they were run one at a time.
  • Tests: test_slack_history_read.py together with the five registration pin files and test_fetch_thread_replies.py, 353 passed. CI on this head: 78 success, 18 skipped, 0 failing. PR Readiness success. GPT, Opus, Design and First Principles all pass and UX is skipped. There are no review threads. It merges cleanly onto main (merge-tree exit 0).

Value gate: passes. The need is filed (#18747) and two earlier community attempts preceded this one. The only existing way to read a reply is the separate per-user OAuth Slack MCP server, which an unattended agent on a plain install does not have. The new agent-facing surface is read-only and admits no sender the inbound gate refuses.

Disposition of the Design lane note on this head: the note says text comes back for any sender is_allowed_user admits, which on a multi-user allow-list would be more than the owner. At this head is_allowed_user admits the owner only (access.py:245-253), so "the owner" in the tool description is accurate. This does not gate.

Source-only: the new tests patch is_allowed_user to an owner check, so the real gate function is not exercised through this route. The owner-only claim rests on reading access.py. Nothing ran against a live Slack workspace, and the conversations.replies page shapes come from fakes.

Follow-ups (non-blocking)

  • The route uses whatever is_allowed_user returns. If that gate is ever widened past the owner, this read widens with it, and the tool description, the slack-gateway spec line and the feature-map row would then be false. A test that drives the route through the real is_allowed_user with a non-owner allow-list entry would pin that.
  • The audit records for this route log session_key "dashboard" and not the verified caller the tool forwards. That matches the profile route beside it, but it means an operator cannot tell from the audit which session read a channel.

@bolichen97

Copy link
Copy Markdown
Contributor Author

Re-sync budget reset. Maintainer decision: this PR is approved and green at 41aab35, but main has since changed the MCP route-table pin this PR also edits, so it now conflicts. One more rebase is needed to land it, and the approval will need renewing on the new head.

[operator: bolichen97]

@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in test/test_dashboard_server_composition_contract_reach.py (the MCP route-table pin, now 337 rows), docs/architecture/mcp.md, docs/feature-map/README.md, docs/system-specs/modules/messaging.md and its gateway sibling spec, src/kiro_crew/dashboard/handlers/__init__.py, src/kiro_crew/dashboard/server_internal_paths.py and src/kiro_crew/dashboard/server_runtime/mcp_routes.py since this head went green (090dad8 -> 39717a0); CI re-running.

[operator: bolichen97]

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed readiness: passed Eligible automated validation passed for the current revision merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: checking Automated validation is still running labels Nov 6, 2026
An agent can post to Slack but cannot read what was said back, so a
"wait for the owner to approve in a thread" loop has nowhere to read
the answer. Add a read_slack_history MCP tool: it reads one tracked
channel's timeline, or one thread, with the bot token the install
already holds.

The read adds no new way in. Any channel outside the tracked list is
refused, a channel agent is refused at dispatch, and text comes back
only for messages whose sender the inbound gate admits (the owner).
Anyone else's message is listed with admitted false and no text. Bot
posts are dropped before the limit applies, so a run of them cannot
hide a reply, and a failed Slack read is an error, never an empty list.
Reading the owner's DMs stays out of scope.

Builds on #18748 by @iamwhatever and #7930 by @Patcurley1.

Co-authored-by: Patcurley1 <101998702+Patcurley1@users.noreply.github.com>
@bolichen97
bolichen97 force-pushed the fix/18747-read-slack-history branch from b5824e4 to 76cc7d5 Compare November 7, 2026 02:33
@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] New head 76cc7d5: rebased onto main 10e0a06 (main fixed the shared shard-7 allowlist red in #31803, and the persistent-agent-channels spec conflict is resolved keep-both with main's CHANNEL_AGENT_BLOCKED_DISPATCH_OPERATION rename).

The local pre-push review found two defects in this PR's own code, both fixed with a red/green test in test/test_slack_history_read.py:

  • A transient conversations.info failure left the channel in the client's negative cache for the rest of the run, so under slack.allowed_enterprise_ids every later history read was refused. The history route now calls ensure_channel_team(channel, retry=True) and still refuses while the workspace is unresolved; inbound handling keeps its one-lookup-per-process behaviour.
  • read_slack_history never checked the caller's own channels governance scope (the route checks the host's). The tool now runs _vet_channel_governance(caller, "slack") before the read and writes its SEL rows under the caller's session key.

The approval on 41aab35 needs renewing on this head.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Nov 7, 2026

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approved for the on-call. Review lanes pass on 76cc7d5, no conflict, no open change request.

@KiroCrewCaptain
KiroCrewCaptain merged commit e6524c8 into main Nov 7, 2026
99 checks passed
@KiroCrewCaptain
KiroCrewCaptain deleted the fix/18747-read-slack-history branch November 7, 2026 03:31
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(slack): add a read_slack_history MCP tool so agents can read channel/thread replies

3 participants