Skip to content

fix(slack): spool the pre-ingestion message, not temp paths and file bodies - #21829

Merged
KiroCrewCaptain merged 1 commit into
mainfrom
fix/8911-slack-spool-pre-ingest
Oct 19, 2026
Merged

KiroCrewCaptain merged 1 commit into
mainfrom
fix/8911-slack-spool-pre-ingest

Conversation

@iamwhatever

@iamwhatever iamwhatever commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A Slack message refused at shutdown comes back after restart as what the user typed, plus how many files it had, never as dead temp paths and pasted file contents.

When a Slack message with files is refused by the shutdown gate, the restart notice quotes the turn's ingested prompt. That prompt holds the temp paths of the downloaded files (gone after the restart) and the extracted text of each file. It also says nothing about the files being dropped.

Why it matters

The restart notice is meant to show the sender their own message so they can resend it. On Slack it shows them a wall of temp paths and file bodies instead, and it never tells them to resend the files. Telegram, Discord, Teams and Webex already record the file count, and Weixin, WeCom and WhatsApp spool the pre-ingestion text. Slack does neither, which breaks the InboundRoute.text contract in src/kiro_crew/messaging/inbound_spool.py.

Not a goal

What changed (motivation → approach → change)

The Slack restart notice quoted the ingested prompt because both Slack refusal paths built their InboundRoute from the same text the turn runs on, and _route_message in slack/events.py rewrites that string in place with temp paths and file contents before the handler sees it.

_route_message now captures the user's message (mention stripped, before voice transcription and file ingestion) and the file count, and hands both on as spool_text / spool_attachments on every dispatch path: direct native, direct transport, and the busy-session queue (_dispatch_queued reads them back). This is the same capture Weixin, WeCom and WhatsApp already do.

handle_message in slack/handler.py and handle_message_transport in slack/transport_dispatch.py use those two values only for the spool route: the admission gate refusal, and the transport's SessionClosingError refusal. They set attachments_dropped, so the notice says how many files to resend. _SlackTurn in slack/handler_runtime/turn.py carries both values, so a compaction-failure replay of the same message spools them too. When spool_text is None (button and interaction re-dispatches, which never ingest files), the text is spooled as before. The durable inbound spool section of docs/system-specs/modules/messaging.md names Slack's capture beside Weixin's and WhatsApp's.

Backwards compatibility

Compatible: both new parameters are optional keywords that default to today's behavior, and the turn's own prompt is unchanged.

Removes nothing: the spool keeps every field it had; only the Slack route's text changes from the ingested form to the pre-ingestion form, and attachments_dropped goes from always 0 to the real count.

Tests

Test Locks in
TestRouteMessageAttachments::test_spool_gets_the_pre_ingestion_message (native + transport) the handler gets the ingested prompt for the turn, and spool_text="look" (mention stripped) with spool_attachments=2 for the spool
TestRouteMessageAttachments::test_busy_session_queues_the_pre_ingestion_message a queued message keeps the pre-ingestion text and count
TestDispatchQueued::test_pre_ingestion_message_travels_to_the_handler (native + transport) the queue drain hands both values to the handler
TestTransportAdmissionSpool::test_spool_records_the_pre_ingestion_message (admission + dispatch) both transport refusal points spool the user's text and the file count
TestTransportAdmissionSpool::test_native_admission_spools_the_pre_ingestion_message the native admission refusal does the same; with no capture, the text is spooled as is
TestPastedTableBlocks in test/test_events_forward.py reads the turn's positional arguments only, since spool_text repeats the message for the spool

With the three production files reverted to origin/main, 8 of the 9 new cases fail by name; the one that passes is the no-capture case, which pins unchanged behavior.

Determinism: the 9 new node ids and the 7 TestPastedTableBlocks ids each ran 20 times at -n0 (all green). The three changed test files ran 10 times at -n 4 --dist loadgroup --max-worker-restart=2 (10/10 green). All 222 node ids in those files passed in a shuffled order, seed 4995.

Manual verification

N/A — unit coverage sufficient: the change is argument plumbing between _route_message and the two spool routes, and the tests drive each refusal point with the real handler.

Related Issues

Part of #8911

Built on top of #21040 (merged), which moved handle_message's body into slack/handler_runtime/.

Pattern harvest

Rule candidate: review-prompt
Pattern: a channel builds its shutdown-spool InboundRoute.text from the turn's ingested prompt instead of the pre-ingestion message.

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

@github-actions

github-actions Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision f47d32f643bc6ed56cd6dc0885f959782734c64b touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Advisory — does not block merge.

@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 18, 2026
@github-actions

github-actions Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of f47d32f643bc6ed56cd6dc0885f959782734c64b — 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/CONCERNS are advisory.

First-Principles-Verdict: PASS

Check one thing: a Slack message that is only a voice memo now spools empty text with attachments_dropped=1, so the restart notice shows no words at all.

What this change ships

Inventory (6 items) — 6 justified

Intent: a Slack sender whose message was refused at shutdown gets their own words back after restart, plus how many files to resend. This is a FIX for the InboundRoute.text contract in messaging.md ("A channel that transforms its prompt MUST set it"). 8 of the 9 new tests fail on base.

  1. The Slack restart notice quotes the mention-stripped text the user typed, not temp paths and file bodies — justified
  2. The Slack restart notice now says how many files were dropped (it always said 0 before) — justified
  3. A message queued behind a busy session keeps its typed text and file count until it is spooled — justified
  4. A compaction-failure replay of the same message spools the same typed text and count — justified
  5. The messaging spec names Slack's capture point next to Weixin's and WhatsApp's — justified
  6. The pasted-table test reads only the turn's positional arguments — justified

[FIRST-PRINCIPLES-REVIEWED] f47d32f

Description read

[DESCRIPTION-READ] 0ed213473147ad30192959f969dedc97a1a0d399179cc295b237fce859f50251

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 Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of f47d32f643bc6ed56cd6dc0885f959782734c64b — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Check that a refused Slack message with a pasted table, or with only a voice memo, still spools useful text, since _gate_text is captured before both are added.

[DESIGN-REVIEWED] f47d32f

Description read

[DESCRIPTION-READ] bcae53553cae87114c0f46890ebe2f7891c84196fb8c330e6cb74e1dd3561ea3

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 Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] f47d32f

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

False positive or not applicable? A repository writer can comment:
/ai-review override fable f47d32f643bc6ed56cd6dc0885f959782734c64b: <one-sentence reason>

@github-actions

github-actions Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] f47d32f

False positive or not applicable? A repository writer can comment:
/ai-review override gpt f47d32f643bc6ed56cd6dc0885f959782734c64b: <one-sentence reason>

@iamwhatever

Copy link
Copy Markdown
Contributor Author
  • rebutted: _spool_attachments = len(files) counts every file the user sent, on purpose

The note reads "Its N attachment(s) are not carried over — resend those too." Every file on the refused message is lost, including one ingestion skipped or a voice memo transcription consumed, so each one is a file to resend.
A count of only ingested files would under-report what the user must resend. Weixin uses the same raw count: attachments_dropped=len(inbound.attachments or ()) in weixin/transport_dispatch.py.
No change.

@iamwhatever

Copy link
Copy Markdown
Contributor Author
  • rebutted: a voice-memo-only message spools an empty body plus "1 attachment", as intended

The frozen goal is "what the user typed, plus how many files it had". A voice memo is a file the user sent, and the notice tells them to resend it.
The transcript is speech-to-text output, absent when STT is unavailable, and the InboundRoute.text contract in inbound_spool.py says the route holds the message the USER sent, never the turn's prompt. Quoting it would put machine text in the user's mouth.
No change.

@iamwhatever

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in docs/system-specs/modules/messaging.md since this head went green (1016b01 -> 462c24f); CI re-running. The one red on the old head, Backend Tests (Windows) (6), was a Windows-only timeout in an unrelated Webex test, recorded as #21846.

@iamwhatever
iamwhatever force-pushed the fix/8911-slack-spool-pre-ingest branch from 407a4cd to 7646a0a Compare October 18, 2026 10:21
@iamwhatever

Copy link
Copy Markdown
Contributor Author
  • span=552dbfa89c81 fixed: _spool_text is assigned from _gate_text; the duplicate mention-strip is gone

Verified first: nothing between the _gate_text assignment and the spool capture reassigns text, is_mention or _gate_text, so the two blocks computed the same value.
_route_message now reads _spool_text = _gate_text (3 lines added, 6 removed); the spooled value is unchanged, pinned by test_spool_gets_the_pre_ingestion_message (spool_text == "look" for <@UBOT> look).
Fix SHA: 7646a0a.

@iamwhatever

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in docs/system-specs/modules/messaging.md since this head went green (462c24f -> e5efdaa); CI re-running on 7646a0a, which also carries the First Principles fix above.

@iamwhatever

Copy link
Copy Markdown
Contributor Author

The notice quotes what the user typed, which is nothing, and says "Its 1 attachment(s) are not carried over — resend those too.", so the user resends the memo.
The transcript is speech-to-text output, not the user's message, and InboundRoute.text holds the message the USER sent. No change.

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Oct 18, 2026
@iamwhatever
iamwhatever force-pushed the fix/8911-slack-spool-pre-ingest branch from 7646a0a to d5bf760 Compare October 18, 2026 11:13
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in docs/system-specs/modules/ (same directory as messaging.md) since this head went green (e5efdaa -> 924c159); CI re-running. 7646a0a had passed PR Readiness with no failing check.

@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: passed Eligible automated validation passed for the current revision labels Oct 18, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor Author
  • rebutted: _gate_text is still the raw typed message when the spool copies it

Checked _route_message from the _gate_text assignment to the _spool_text = _gate_text line: nothing there assigns text, is_mention or _gate_text; the stretch only reads them (governance gate, display name, observe and mention checks, auth, dedup).
Transcription and file ingestion, the only writers of text, run after the capture. Pinned by test_spool_gets_the_pre_ingestion_message (spool_text == "look" for <@UBOT> look while the turn text carries the temp path). No change.

@iamwhatever

Copy link
Copy Markdown
Contributor Author
  • rebutted: none of the five interactions.py re-dispatches carries ingested text

None of those paths calls process_slack_files, transcription or any file ingestion, so their turn text holds no temp paths and no file contents; spool_text=None spools it as is, which is what main already does.
The review-revise prompt at interactions.py:3859 is built from the bot's own draft and the user's feedback. Quoting it in a restart notice is unchanged behavior and outside this PR's goal ("Any change to the spool, its replay notice, or other channels" is a Not-a-goal). No change.

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Oct 18, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Review-ready at d5bf760: PR Readiness passed with 103 checks and no failures, the branch is mergeable, and every Design and First Principles item on this head has an answer above. The one code change from review (span=552dbfa89c81, reuse _gate_text) is in. No overrides were used. Overlap with #21040 in src/kiro_crew/slack/handler.py stands: whichever lands second rebases. This needs a maintainer's approval; this Crew will not merge, approve, or enable auto-merge.

@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Oct 18, 2026
@iamwhatever
iamwhatever force-pushed the fix/8911-slack-spool-pre-ingest branch from d5bf760 to f47d32f Compare October 18, 2026 22:08
@github-actions github-actions Bot added readiness: checking Automated validation is still running 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 labels Oct 18, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Rebased onto #21040 (merged), which moved handle_message's body into slack/handler_runtime/ and conflicted with this PR in src/kiro_crew/slack/handler.py. The spool plumbing now runs through _SlackTurn in slack/handler_runtime/turn.py, so a compaction-failure replay keeps the pre-ingestion text and file count. The PR body is updated to match. CI re-running on f47d32f.

@iamwhatever

Copy link
Copy Markdown
Contributor Author
  • rebutted: a pasted table is already in text when _gate_text is captured; a voice memo spools the file count

Pasted table blocks are rendered into the message text by _extract_blocks_text before _route_message runs, so _gate_text holds them. TestPastedTableBlocks::test_table_only_message_is_routed_once shows it: a table-only message routes with spool_text='Name | Qty\\nApple | 3'.
A voice-memo-only message spools empty text plus "Its 1 attachment(s) are not carried over — resend those too.", the ruling at #21829 (comment). No change.

@iamwhatever

Copy link
Copy Markdown
Contributor Author

The notice quotes what the user typed, which is nothing, and tells them to resend the one attachment, the memo itself.
The transcript is speech-to-text output, not the user's message, and InboundRoute.text holds the message the USER sent. No change.

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Oct 18, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Review-ready at f47d32f: PR Readiness passed with 106 checks and no failures, the branch is mergeable, and both whole-design items on this head have an answer above. This head is rebased onto #21040 (merged); the spool plumbing runs through _SlackTurn in slack/handler_runtime/turn.py. No overrides were used. This needs a maintainer's approval; this Crew will not merge, approve, or enable auto-merge.

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

Every review lane on the head is clean (only runner notices and PR Scope size warnings); held by the triage cron on a path, category, checklist or P0-area rule, not a finding. Approved on the watch holder's request.

@KiroCrewCaptain
KiroCrewCaptain enabled auto-merge (squash) October 19, 2026 01:17
@KiroCrewCaptain
KiroCrewCaptain merged commit 37161d6 into main Oct 19, 2026
107 checks passed
@KiroCrewCaptain
KiroCrewCaptain deleted the fix/8911-slack-spool-pre-ingest branch October 19, 2026 01:50
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 19, 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.

2 participants