Repository navigation
feat(slack): reconnect slack in place so saved credentials apply - #32304
Conversation
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS No design-level blocker. A Slack-only reconnect fixes the real cause (tokens are read once at boot), and the refusals for a workspace switch or owner change stop queued work from being sent to the wrong workspace or owner. Notes
[DESIGN-REVIEWED] d0d50dd Description read[DESCRIPTION-READ] 111a920ed9736acd56c34de262c1fa255125139fcff8d7e6911eb1e7e0959454 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 |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Every item has a named harm and nothing blocks. The hold, give-up and notice machinery only exists because Reconnect closes the old socket before the new one connects. Notes
What this change shipsInventory (10 items) — 8 justifiedIntent: let a person apply Slack credentials saved in Settings with one click instead of restarting the gateway. ADDITION.
[FIRST-PRINCIPLES-REVIEWED] d0d50dd Description read[DESCRIPTION-READ] cb96217ed59a9406857bbd88c8ac6176b2452b4171b2a8b67b6eff910863d53f That sha256 names the PR description this verdict read. Recompute it with |
UX Review (Opus 5.5) — ✅ PASSUX-level review of UX-Verdict: PASS Nothing blocks: the blind reader read the Reconnect button, its in-progress, failed and success states, and the save-row offer correctly, and said they would use it. Notes
[UX-REVIEWED] d0d50dd Description read[DESCRIPTION-READ] 66aaf6ba862db3c845770b650198d1896a847e6b6de954034b16f6caf62095d7 That sha256 names everything this verdict read: the PR description, plus the 10 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 |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
27e2a53 to
2eb33c8
Compare
|
Rebased: main moved in docs/feature-map/README.md, docs/system-specs/modules/messaging.md, src/kiro_crew/dashboard/handlers/init.py, src/kiro_crew/dashboard/state_parts/dashboard_state.py and the website i18n catalogs since this head went green (b764e20 -> 928d145); CI re-running. The same push clears the three reds the old head showed against the newer main: the loopback-gate site count includes the new reconnect route (it uses [operator: bolichen97] |
2eb33c8 to
e5671f8
Compare
|
e5671f8 to
6ecf56c
Compare
6ecf56c to
55d1b88
Compare
|
|
Pull request was closed
55d1b88 to
273fa43
Compare
|
This PR was closed for one minute by mistake: a push raced a local rebase and briefly set the branch to |
0439a04 to
cd4dba8
Compare
|
Slack's tokens and owner ID were read once at gateway start, so a credential saved from Settings needed a full gateway restart, which tears down every running agent turn, task and cron. Add POST /api/slack/reconnect and a Reconnect button in the Slack panel that redo only the Slack handshake from the saved credentials. A reconnect never switches workspaces: work already admitted names the pinned workspace's channels, so a token for another workspace, or any other token while the pinned workspace cannot be named, is refused before the working connection is touched, and the panel shows the refusal. Slack work that arrives while a reconnect runs is held and delivered with the new client, or reported to the owner when Slack stays down. Builds on #25780.
cd4dba8 to
d0d50dd
Compare
|
Rebased: main moved in docs/feature-map/README.md, docs/system-specs/modules/messaging.md, src/kiro_crew/dashboard/handlers/messaging.py, src/kiro_crew/dashboard/state_parts/dashboard_state.py, website/src/i18n/locales/en.manual.json and 29 more files this PR touches since this head went green (601aa4c -> 8f6fe6d); CI re-running. Two conflicts, both kept on both sides: the settings panel's connection hint, where main added the missing-owner hint (#32577), and the queue entries in [operator: bolichen97] |
buluoray
left a comment
There was a problem hiding this comment.
Approve on d0d50dd. New POST /api/slack/reconnect re-reads saved Slack credentials and redoes only the socket handshake. The route is direct-local only and sits behind the app-wide dashboard credential + CSRF middleware. An owner change and a workspace switch are both refused before teardown, so the working connection stays up. No credential value reaches logs, the access log or responses. Targeted tests pass and all three guards were mutation-verified. Decisive lines: src/kiro_crew/dashboard/messaging_api/slack_settings.py:473, src/kiro_crew/slack/reconnect.py:414, src/kiro_crew/slack/reconnect.py:426, src/kiro_crew/slack/reconnect.py:528, src/kiro_crew/dashboard/routes/messaging.py:25
Problem / Motivation
Goal: Slack credentials saved from Settings take effect with one click, without restarting the gateway.
Slack's tokens and owner ID are read once, when the gateway starts. Saving new ones from Settings → Messaging Channels → Slack writes them to the credential store, but the running Slack connection keeps the old ones, and the panel's only advice is "restart the gateway". A restart re-executes the whole process, so every running agent turn, task step and cron is torn down to redo one websocket handshake.
Why it matters
First-run Slack setup is where a token typo or a missing owner ID happens. The issue's reporter ran for hours with no Slack connection because the owner ID was missing at boot; re-entering it in Settings reported success and changed nothing. With Reconnect, the fix is one click and the outcome shows on the same screen.
Not a goal
POST /api/restart, or the slash command's restart requirement (it is registered in the Slack app manifest).What changed (motivation → approach → change)
A saved Slack credential needed a full restart because the tokens are read once and the socket start returns early on a sticky "disabled" flag. This PR adds one action that redoes only the Slack part of a restart, in place.
POST /api/slack/reconnect{connected, connect_error}, the pair the Slack config read already reports. A saved owner ID that differs from the one the gateway authorizes is refused before anything is torn down ("restart the gateway to change the owner"): every queued, held or running Slack message was admitted under that owner. A gateway with no owner yet takes the saved one.SlackPanel.tsx)connect_erroris shown as a failure, even when the old connection stayed up, and a later credential save clears the last outcome.slack/reconnect.py)team_id, is pinned by itsenterprise_id.slack/events_queue.py,slack/events.py,slack/gateway_runtime/result_egress.py)slack/code_channels/routing.py), so a reconnect mid-route cannot drop it; one that arrives with no client waits for the attempt, or gets the undelivered notice in a bound channel. If the reconnect fails and Slack stays down for 5 minutes, each held message leaves its queue and the owner gets one dashboard notice naming the channel and quoting the message.PUT /api/slack/configreturnsreconnect_requiredfor a token write or a first owner ID, andrestart_requiredfor replacing the owner the gateway already uses, or for the slash command.A reconnect re-runs the enterprise workspace check; while its
auth.testruns, an armed workspace allowlist and the bot's own identity stay in force (slack/enterprise.py) instead of reading as open; it runs under the dashboard config lock, and an allowlist reload waits for it, so neither a rolled-back save nor an older read can widen the list. The save row says restart, without offering Reconnect, whenever the save needs one. The rest is wiring: boot keeps its duplicate-event cache and publishes the reconnect hook once its own connect finished (slack/gateway_runtime/service_boot.py,orchestrator_init.py,slack/gateway.py,dashboard/state_parts/dashboard_state.py,dashboard/handlers/,dashboard/routes/messaging.py), and a reconnected client gets the agent-session status driver boot attaches (slack/agent_sessions/status.py). The voice and file paths read the published client once (slack/events_voice.py,slack/files.py). The gateway's log line for a changed Slack credential points at Reconnect (slack/gateway_runtime/channel_lifecycle.py).slack/enterprise.pyandtest/test_enterprise.pyare black-formatted, so.github/black-baseline.txtstops listing them. The client gainsreconnectSlack(website/src/api/client/messaging.ts). The catalogs underwebsite/src/i18n(en.manual.json, the translated locales, the regenerateden-XA.json,en.context.json) gain the new strings and drop four restart-only ones.docs/system-specs/modules/messaging.md,docs/system-specs/modules/slack-gateway.mdanddocs/feature-map/README.mddescribe the route, and the user guidesrc/kiro_crew/docs/slack-integration.mdsays new tokens apply with Reconnect and a changed owner ID still needs a restart.Builds on #25780 by @CrysisDeu, rebased onto current main. Against that PR's last head, a different token is refused while either workspace is unnamed, and a refusal that left the connection up reads as a failure in the panel and in the
slack.reconnectaccess log.Backwards compatibility
Compatible: one new POST route and one new response field (
reconnect_required). A client that reads onlyrestart_requiredseesfalsefor a credential save, and the restart it would have offered is no longer needed.POST /api/restartis unchanged. No config, schema or file on disk changes.Reader: website/src/pages/settings/SlackPanel.tsx:slackPanel.slack_connection_failed_at_startup, slack_rejected_the_stored_tokens_invalid_auth_re, tokens_are_saved_but_not_yet_active_restart_the, verified_with_slack_and_saved_restart_the_gatewa -- crew page -- the only reader on main; this PR replaces those strings with the Reconnect wording, so no other file reads the removed keys
Tests
test/test_slack_reconnect.py(new): the handshake re-reads the tokens and publishes a client only behind a connected socket; each named decline; an unreadable store changes nothing; a token for another workspace is refused before teardown; with the pinned workspace unnamed, or with a new token Slack cannot name, another token is refused and the connection stays up, while the pinned token reconnects, even after a save cleared the bot token in between; an org-wide Grid install is named by itsenterprise_id, and any otherauth.testanswer without ateam_idstill fails; a channels-policy deny closes the socket it built; concurrent clicks share one attempt; work queued across a failed reconnect is held, then delivered with the new client or reported to the owner after the window; the route's 403/503/500 answers and that a refusal with the connection up is logged as an error; a saved owner change (or removal) is refused with the connection left up, a token-only save reconnects in place, and a gateway with no owner yet takes the saved one.test/test_slack_code_channels_routing.py: a reconnect that clears the client mid-route still adopts, binds and routes the code-channel message.test/test_slack_events_coverage_route_flow.py: a code-channel message that arrives with no client waits for the reconnect and its gate and dispatch use the new client, or it is reported undelivered when the attempt fails; a reconnect mid-route keeps the gate and dispatch on the route's client; a voice memo held for a reconnect is still answered by voice.test/test_ssm_loopback_trust_sites.py: the new direct-local gate is listed.test/test_enterprise.py: a re-validation keeps an armed allowlist while it probes, and stays default-open with none.website/src/test/SettingsSlackPanelCoverage.test.tsx(owner): verified tokens saved with an owner change say restart and offer no Reconnect; the owner-change decline is explained.test/test_slack_config_handlers.py: a token save and a first owner ID on a gateway with none flagreconnect_required; replacing the gateway's owner and a command change flagrestart_required.website/src/test/SettingsSlackPanelCoverage.test.tsx: the Reconnect button's pending, success and failure states, each named decline, a refusal that left the connection up shown as a failure, a later credential save clearing the last outcome, the save-row button, and the read-only view.test/test_slack_events_coverage_route_flow.py,test/test_stop_clears_only_its_own_sender_slack.py,test/test_slack_agent_session_stop.py,test/test_slack_gateway_more_coverage.py,test/test_handlers_messaging_composition_contract.pyandwebsite/src/test/ApiClient.refactor.surface.test.tsfollow the new names.Determinism:
test/test_slack_reconnect.pyran 3 times under-n 4and once serially in a seeded shuffled order, all green; the owner-save tests intest/test_slack_config_handlers.pyran 20 times at-n0and 10 times at-n 4besidetest/test_slack_reconnect.pyandtest/test_enterprise.py, and the whole file once in a shuffled order (seed 7583), all green; the held voice-memo test intest/test_slack_events_coverage_route_flow.pyran 20 times at-n0and once at-n 4beside the other Slack tests, and its whole file once in a shuffled order (seed 4127), all green;SettingsSlackPanelCoverage.test.tsxran twice, green. The new tests fail with their fix reverted.Manual verification
The panel ran from this PR's head on an isolated gateway (screenshots below): a first owner ID saved on a gateway with none got
reconnect_required: trueandrestart_required: falsefrom the real save route. Slack itself was not reachable, so the route, the handshake and every refusal are driven through the real code by unit tests with Slack's client faked.Screenshots / video
Before (main): the recorded failure says to restart the gateway, and there is no Reconnect.
After, from this PR's head on an isolated gateway. Slack's answers are faked in the browser; the first-owner save goes to the gateway itself.
After: the recorded failure points at the header Reconnect button.
After: pending, the button reads Reconnecting… and is disabled.
After: a decline, labelled as the click's outcome.
After: connected.
After: saved tokens that are not live yet point at Reconnect.
After: a first owner ID saved on a gateway that has none says to click Reconnect, with the button beside the confirmation. The gateway answered
reconnect_required: true,restart_required: false.Related Issues
Closes #10306
Builds on #25780 by @CrysisDeu.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
Contributed under the project's Apache-2.0 license.