Repository navigation
fix(slack): deliver a single-session dm reply when the edit is refused - #39257
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks. The fix targets the real cause: an edit Slack refused was failing the whole turn. It reuses the proactive-send rule for deciding whether a failed call may still have landed, so it does not post twice. Notes
[DESIGN-REVIEWED] bfde1f3 Description read[DESCRIPTION-READ] 5ac0e8f4e8cbc8cde702058aeab40fe534c1f45e955819796de5b784461c3b51 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 Nothing blocks. The fix is at the right level: the answer-carrying What this change shipsInventory (8 items) — 8 justifiedIntent: a person using
[FIRST-PRINCIPLES-REVIEWED] bfde1f3 Description read[DESCRIPTION-READ] ef72d7e0084ec098a94bdebb7b8f79e499884fe49da8263225891c23ff193c7d That sha256 names the PR description this verdict read. Recompute it with |
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: |
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: |
17566a1 to
e465366
Compare
|
self-added: yes
|
|
|
Rebased: main moved in the renderer module ( The shard-8 backend red on the old head ( |
A top-level message in a single-session DM has no thread to stream into, so its reply is sealed into a placeholder with one chat.update. That edit carried the whole answer and was allowed to raise: any edit Slack refuses (edit_window_closed, cant_update_message, ratelimited, ...) reached the transport catch-all, which posted the "transport path" error and dropped the answer. A threaded reply streams and reaches that edit only when Slack refuses its stream, which is why the flat DM, which never streams, was the one hit. An edit Slack refuses (a 429, or an ok:false answer other than internal_error and fatal_error) now posts the reply as its own message. A failed post, or an edit that fails any other way (a timeout, a 5xx, or one of those two errors, after which the edit may have landed), still fails the turn, and the turn's rescue only edits the placeholder, so it never posts a second copy. The placeholder and every reply part are sent as one Block Kit markdown block, so the reply renders the way the stream's markdown_text does; as a mrkdwn text field, which chat.update reads under parse=client, the model's links showed raw. Closes #36269 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
e465366 to
bfde1f3
Compare
|
Rebased: main moved in the two spec files this PR edits, its call-site baseline test and the module directory of the new delivery code since this head was tested (89438fd -> dc531c1); CI re-running. The backend red on the old head ( |
Code change approver recommendation: ApproveWhy: the decider estimates a 12% chance that this change introduces a defect, within the 12% limit for approving on its own, and every check passes. The fix is at the right place: on the no-stream path, the Tier: 1, every tier gate passed. An automated recommendation, not a review: a maintainer still decides. It approves on its own only when the estimated chance of a defect is at most 12% and the change has at most 400 changed lines. Decider v3c (217fe607) · commit |
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Approved automatically by the code change approver, not by a person. The decider estimates a 12% chance that this change introduces a defect, within the 12% limit for approving on its own, and the change has at most 400 changed lines.
The fix is at the right place: on the no-stream path, the chat.update that seals the placeholder with the whole answer could fail the turn when Slack refused the edit. seal_placeholder now posts the reply only after a refusal, judged by the same rule the dashboard's proactive Slack sends already use (an ok:false answer other than internal_error/fatal_error, or a 429). Timeouts, 5xx and internal_error/fatal_error still propagate, with no second post. release_held_text only edits the placeholder, so it can't post a duplicate. Both edits of the placeholder (_render_fallback and release_held_text) send the markdown block, so no edit with plain text only can leave the old block on screen. The native path already edits markdown blocks on stream messages, so the block shape has precedent. The client checks (remote-media refusal, channel policy, mute, no unfurl) still apply. The new tests would fail without the change, the updated tests keep what they checked, the spec text is updated, and CI is green.
Tier: 1, every tier gate passed.
Criteria: no merge conflict, no owner block, no change request, the default branch, no security-sensitive path, no design document to agree on, the readiness status, the review lanes, the P0 history, the linked issues' tier, the review lessons, no concern label, the file count, a safe change category, not its own change, the decider, the security checklist, the change matches its title, no competing change.
Design documents ride along with the code (docs/system-specs/modules/messaging.md, docs/system-specs/modules/slack-gateway.md): they were not reviewed as a design, and a person who changes what they decide should ask for that review.
Decider v3c (217fe607). To overrule it, request changes or dismiss this review.
Problem / Motivation
Goal: A top-level message in a single-session Slack DM gets its whole answer at the DM root, with no "transport path" error.
With
slack.dm_single_session: trueon the default messaging transport, the reporter's top-level DM turn ended with🔧 Something went wrong (transport path). Please try again., the failure reaction, and no answer. Links that did show came out as raw<url|label>markup. The same request answered in a thread worked.Why it matters
slack.dm_single_sessionis the only way to get replies at the DM root instead of in a thread. While a turn there can lose its whole answer, the setting cannot be used, and every one-line command reply in a DM needs its own thread.Not a goal
chat.startStreamstreams only into a thread, so the root reply still shows a placeholder and is sealed at the end of the turn.messaging.use_transport=false, review-mode channels).What changed (motivation → approach → change)
Symptom → cause. A flat DM's top-level reply has no thread, so
SlackRendererfalls back to posting a_Thinking…_placeholder and sealing the answer into it with onechat.update(_render_fallback). That edit carried the whole answer and was allowed to raise, so any edit Slack refuses reached theexceptinhandle_message_transport. That handler posted_TRANSPORT_ERROR_TEXTand flipped the reaction to failure. Slack documents many such refusals:edit_window_closedunder an org's edit-window setting,cant_update_message,ratelimited. A threaded reply streams and reaches that edit only when Slack refuses its stream, which is why the flat DM, which never streams, was the one hit. Fault injection over every Slack call of the flat turn confirms this: the finalchat.updateis the only call whose failure produces the transport error.The links: the fallback sent the model's Markdown as a mrkdwn
textfield, andchat.update'sparsedefaults toclient(unlikechat.postMessage). The stream sends the same text asmarkdown_text, which renders it.Change. A new module
slack/no_stream_reply.py(renderer.pyis at the line cap) holds the no-stream delivery:seal_placeholderedits the placeholder. If Slack refuses the edit (a 429, or anok: falseanswer such asedit_window_closed), it posts the reply as its own message in the same place (DM root, or the thread). It reads a refusal with the rule the dashboard's proactive Slack sends already use (_slack_rejected_outright, plus_slack_rate_limitedfor the 429), so both paths agree on which answers may have landed. If that post fails too, the turn fails as before, so a reader who got nothing is still booked as a failure. After a timeout, a 5xx, or aninternal_error/fatal_erroranswer, the edit may have landed, so the error propagates as before and nothing is posted. The rescue that runs when a turn fails (release_held_text) only edits the placeholder, so it never posts a second copy of an answer the turn's own post may have delivered.markdownblock, with the same text intextfor notifications. That is the grammar the stream'smarkdown_textrenders, so links and emphasis render as they do in a threaded reply.The owning spec lines are updated in
messaging.md(→SlackRenderer) andslack-gateway.md(Streaming UX).Backwards compatibility
Compatible: no setting, signature or accepted input changes.
SlackClientOps.update_messagealready tookblocks, andpost_blocksalready existed. A threaded reply that streams is untouched. A threaded reply that falls back to the placeholder (Slack refused its stream, or refused every append) takes the same no-stream path:markdownblock, and a post when Slack refuses the edit, where it used to fail the turn.Removes nothing: the change adds a post when an edit is refused and changes the block shape of the no-stream reply. No path, key, record or public function is hidden or removed.
Tests
test/test_slack_transport_dispatch_flat_dm.py::TestFlatDmReplyDelivery::test_a_refused_edit_still_delivers_the_whole_answer_at_the_dm_root(new). It driveshandle_message_transportfor a top-levelD…message withdm_single_sessionandshow_thinkingon, through a turn with reasoning, narration, a tool call and a final answer with links, against a Slack that refuses everychat.updatewithedit_window_closed. It asserts that no transport error is posted, that the whole answer is posted exactly once at the DM root (thread_tsNone), and that every edit and post carrying it is amarkdownblock.test_an_edit_that_may_have_landed_is_not_posted_again(new, same class): an edit that fails withinternal_error,fatal_error, an HTTP 503 or a timeout raises, and nothing is posted.test_a_post_that_may_have_landed_is_not_repeated_by_the_rescue(new, same class): every edit is refused and the answer's post times out. The answer is sent once, counting every post method, and the turn still ends with the transport error.test/conftest_slack.pyMockSlackClient.update_messagetakesblocks, asSlackClientOps.update_messagedoes.post_message):test_slack_renderer.py,test_slack_backports.py,test_channel_control_tag_strip.pyandtest_slack_status_reaction.py. Each keeps what it checks;test_slack_status_reaction.pyrefuses the block post too, so "nothing delivered → failure" is still what it proves.test_slack_post_message_call_sites.pylowersslack/renderer.py's direct-post_messagerow from 5 to 2. The fake intest_slack_thinking_order.pyrecords amarkdown-block post as a message rather than as the timing footer, so its no-stream cases still find the answer.Proof: PROVEN test/test_channel_control_tag_strip.py::TestSlackRenderer::test_no_stream_final_text_is_stripped, test/test_slack_post_message_call_sites.py::test_no_new_direct_post_message_call_sites, test/test_slack_renderer.py::TestStreamMachinery::test_no_stream_falls_back_to_chat_update, test/test_slack_renderer.py::TestRendererPresentationGuards::test_raising_start_stream_and_placeholder_still_delivers, test/test_slack_transport_dispatch_flat_dm.py::TestFlatDmReplyDelivery::test_a_refused_edit_still_delivers_the_whole_answer_at_the_dm_root (head e33c52d3b76a)
Determinism of the three new tests (no sleeps, no wall clock, no network, every await bounded by the scripted turn or an
AsyncMock), on the head's tree (37f90949; the proof host applied this commit withgit am, hence its own head id):Gates on that tree: all 66 entries of the project profile's gate list (black, isort, flake8,
mypy src/kiro_crew, the scoped backend and frontend test runners, the frontend build,tsc, eslint, jscpd,test:electronand the other checks) exit 0, plusscripts/local-gate.py(backend related: 18,155 passed; frontend related: 14,526 + 6,902 passed), semgrep on the diff (0 findings), the flake-pattern ratchet (75 passed) and the changed and neighbouring Slack test files (466 passed). This diff touches nowebsite/file.Manual verification
How it was verified, on Ubuntu 24.04 (Linux). Real Slack is not reachable from the host. The product's own path was driven instead:
handle_message_transport, the realSlackRenderer,TurnDriverandRealSlackClient. Underneath sat a fakeAsyncWebClientthat refuses what Slack's API reference documents:chat.startStreamwithoutthread_ts→invalid_thread_ts,chat.appendStreamon a non-stream message →message_not_in_streaming_state,assistant.threads.setStatuswithout a thread refused, andchat.updateneeding a realtsand non-empty text. Runs were made with and without achat.updaterefusal (edit_window_closed).Before, with the edit refused (flat DM, top-level):
After, same script:
When Slack accepts the edit, the placeholder is sealed with the answer as a
markdownblock, with no extra post. When the edit times out or Slack answersinternal_error, the turn ends with the error text as before and the answer is not posted a second time. When the edit is refused and the answer's post then times out, the answer is posted once and the turn ends with the error text; the rescue after it does not post the answer again. A flat turn with no tool call and no thinking behaves the same in both cases. The threaded control's Slack calls are identical before and after, apart from the elapsed time in the footer.Two known edges. After a refused edit the
_Thinking…_placeholder stays above the posted reply. No delete is tried, since an org that refuses edits may refuse deletes too. And in a workspace that refuses edits, a turn that fails before its reply is sealed does not show its held text, as on main: the rescue only edits the placeholder and never posts a second copy. The answer can still show twice when the turn's final send may have landed and the rescue's later edit or stream appends then go through. On main that send is a timed-out edit. Here it can also be the post after a refused edit, for example after a 429.Which refusal the reporter's workspace returned is not known: with
chat.updateaccepted, about 15 turn shapes on the fake all delivered, so the reproduction models one documented refusal (edit_window_closed) and the fix makes delivery survive any refused edit rather than one error code. Still worth a live check on a real workspace: that amarkdown-block placeholder seals in place (the samemarkdown→markdownedit the native path's_give_backmakes on stream messages), and that a Slack-style<url|label>link renders inside amarkdownblock.Related Issues
Closes #36269
Sibling sweep
Swept: git grep -nE "update_message(|post_message(" -- src/kiro_crew/slack/renderer.py src/kiro_crew/slack/handler_runtime/
Sibling: src/kiro_crew/slack/renderer.py -- changed here
Sibling: src/kiro_crew/slack/handler_runtime/stream.py -- not affected -- native path, converts with render_one_for_slack and is outside this PR's goal
Swept: git grep -nE "update_message(|post_message(" -- src/kiro_crew/slack/renderer_thinking.py
Sibling: src/kiro_crew/slack/renderer_thinking.py -- not affected -- the Thinking reply carries no answer and is best-effort; a refused edit there leaves what it already shows
Swept: git grep -nE "except SlackApiError" -- src/kiro_crew/slack/
Sibling: src/kiro_crew/slack/interactions_approvals.py -- not affected -- restores a review draft for a person to press again; nothing is re-sent automatically
Pattern harvest
Rule candidate: review-prompt
Pattern: an answer-carrying Slack send that has a single fallible form (one edit) and no second delivery, so a documented API refusal drops the whole answer.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)