Skip to content

fix(slack): send or drop the stream's held text when a message ends - #17897

Merged
bolichen97 merged 2 commits into
mainfrom
fix/stream-seal-flush-filter
Oct 9, 2026
Merged

bolichen97 merged 2 commits into
mainfrom
fix/stream-seal-flush-filter

Conversation

@bolichen97

@bolichen97 bolichen97 commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A streamed Slack answer never loses its last words. At a wait, a word the stream still holds is shown at the end of its own message once the text after it shows the word is whole; when that cannot be shown, it opens the next message.

The Slack stream holds back the last run of each chunk until more text shows where it ends. Nothing ever settled that held run when a message ended. So:

  • the last word of an answer (forty2, done) never reached the stream;
  • a one-word answer sent nothing, and the turn was counted as a failure;
  • text held before a wait showed up glued to the start of the next message (waitafter ).

Why it matters

Every native Slack streaming turn is hit. Readers see answers with the last word cut off, short replies vanish, and the failure counter climbs on turns that worked.

Not a goal

  • The size bound on how much the stream holds back.
  • The transport-path renderer (slack/renderer.py).
  • Any change to what is redacted: no pattern moves; security/__init__.py only gains two read-only properties.

What changed (motivation → approach → change)

Symptom: the run still held when a streamed answer ended was never sent. Cause: _AnswerStream in slack/handler_runtime/stream.py fed every chunk through its StreamRedactor but never settled what it still held when the turn ended.

Fix: seal calls a new settle_tail. When the final text is clean it sends the held run through the same send-and-rotate path as any other text (if that send, or the last send in finish, fails and no new stream opens, the seal re-sends the whole text as the final update); when it is not, it drops the run and the final copy replaces the message as before. A run held before a tool card stays held, so the text after the call is joined to it and filtered as one.

At a wait the message closes and the held run is kept in carried, so the filter sees it joined to the next text (take_carried, also called on EVENT_COMPLETE in slack/handler.py). When that joined text comes out of the filter whole and unchanged, _give_back reads the closed message back and edits it with chat.update on its own blocks plus the run, so its formatting and task plan stay. The next message then starts after the run, and so do its final copy and the saved answer. When the joined text is changed by the filter, the blocks are not a known shape, or the read or edit fails, the run opens the next message as before. StreamRedactor gets read-only held and discarding. slack/handler.py reads the delivery flag after seal. docs/system-specs/modules/slack-gateway.md states the held-run rule.

Backwards compatibility

Compatible: nothing is rejected or renamed; the stream now sends text it used to drop.

Removes nothing: no key, record, path or function is taken away.

Tests

  • test/test_slack_stream_held_tail.py drives handle_message on the streaming path: the last word of a clean answer arrives; a one-word answer is sent and counted as a success; a value split around a tool card or a wait is filtered as one, on the stream and in the final copy; the last word before a wait that ends the turn is posted; the last word still arrives when its send and retry both fail, and so does the last text when the stream fails while the turn finishes; an agent that dies during a wait still shows the error notice.
  • After a wait: the held word goes back to the end of its message, with its markdown or rich_text blocks and the plan block unchanged, and the next message starts "Results are in." (test_the_word_held_at_a_wait_goes_back_to_its_message_with_its_format); when the edit is refused, the blocks are another shape, or there is no read-back, the word opens the next message (..._when_the_edit_cannot_land); two waits in a row, and two waits each with their own word; the saved answer matches the last message; the next message keeps its own opening word in its final copy; a refused next message does not repeat the word; five split-value cases are never given back and never shown split (test_a_value_split_by_a_wait_is_never_given_back_split).
  • test/test_slack_handler_composition_contract.py: 19 golden transcript digests updated; each diff was read.
  • test/test_security_gate_liveness.py: the package line budget is raised by 10 lines for the two StreamRedactor properties, with its reason comment.
  • Determinism: no clock, sleep or port in the new tests.

Manual verification

N/A — unit coverage: the tests drive the real handler and stream object against a Slack client fake that hands back each message's blocks. Not run against a live workspace. If live Slack hands back a streamed message in another block shape, or refuses the edit, the expected outcome is the fallback: the word opens the next message, as before this change, and nothing is lost.

Related Issues

Closes #16984

Pattern harvest

Rule candidate: review-prompt
Pattern: a stateful buffer (a holdback, a hold, a debt) fed per chunk must be settled at every place the segment it belongs to ends.

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

@bolichen97
bolichen97 requested a review from a team as a code owner October 7, 2026 22:01
@bolichen97
bolichen97 requested a review from iamwhatever October 7, 2026 22:01
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 7, 2026
@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 1e341e03b2c9e0e1ca32d2548c64e670a085223f 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 commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — 🟡 CONCERNS

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

Design-Verdict: CONCERNS

_give_back rewrites an answer the reader has already seen, and only a fake has tested it: nobody knows if live Slack's read-back blocks survive chat.update intact.

Watch

  • A lossy edit has no fallback. The description says that if live Slack returns another block shape, "the expected outcome is the fallback". But the fallback only fires when _blocks_with_run returns None or the edit raises. Here is how that fails: you stream a markdown block, and Slack may return it from conversations.replies as rich_text. _add_to_rich_text then succeeds, and update_message(..., blocks=blocks) writes back a rebuilt copy that may drop formatting. The reader's already-shown message comes back with its formatting changed, and nothing errors to signal it. "Manual verification: N/A" leaves this premise unproven.
    Clears when: one live-workspace run of a turn with a wait after a held word shows the edited message keeps its blocks, or the give-back sends only when the read-back blocks match the ones this stream wrote.
  • Five new mutable flags, and they depend on each other. The new flags are carried, move_back, given_back, finishing and streamed_at_finish. Their correctness depends on the order in which wait, on_text, finish, seal and EVENT_COMPLETE call take_carried. That is a lot of new state for one cosmetic gain: putting the word back on the earlier message instead of opening the next one with it, which the fallback already does safely.
    Clears when: the give-back is split into its own PR, leaving this PR as settle-at-seal plus carry-at-wait (the fallback path), or the state is reduced to one carried-run record with a single owner.

Suggestions

  • Ship settle_tail plus carried alone. That fixes every harm the description lists: lost last words, empty one-word replies, false failure counts and glued text. The rewrite of a closed message can then be decided separately.

[DESIGN-REVIEWED] 1e341e0

Description read

[DESCRIPTION-READ] e969df461f745197705295af7deafc27bff367b0cbe58706bfd121c85d3e4f1b

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

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — 🟡 CONCERNS

Premise-level review of 1e341e03b2c9e0e1ca32d2548c64e670a085223f — 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: CONCERNS

The give-back edit (read the closed message back and rebuild its blocks) costs about 140 lines and four state fields to move one word, and is unverified on live Slack.

Not justified as shipped

  • Item 4 — oversized: _give_back reads the message back, then _blocks_with_run/_add_to_rich_text rebuild its markdown/rich_text blocks, tracked by move_back, given_back, finishing, streamed_at_finish. Item 3's fallback already prevents the loss in slack: StreamController can stop a stream before flushing the StreamRedactor tail #16984; this only moves the word. The description says "Not run against a live workspace".
    Subtraction: delete _give_back, _blocks_with_run, _add_to_rich_text, _ts_before, move_back, given_back, finishing and the trim in seal. Keep the carried run opening the next message.
    Clears when: a live Slack thread shows conversations.replies returning a closed streamed message as markdown/rich_text blocks that chat.update accepts, or the mechanism is removed.
  • Item 7 — zero consumers: handler.py re-exports _add_to_rich_text, _blocks_with_run and _ts_before. Grepping all three names across src/test finds 0 uses through handler.
    Subtraction: delete the three re-export lines.
    Clears when: the re-exports are removed.

What this change ships

Inventory (7 items) — 5 justified

Intent: a streamed Slack answer always shows its last words. FIX (#16984).

  1. The last held word of a clean streamed answer is now sent at the end of the turn — justified
  2. A one-word answer is delivered and counted as a success, because the delivery flag is read after the seal — justified
  3. The word held at a wait is carried into the next text, so the filter sees it joined to that text and nothing is lost — justified
  4. The word held at a wait is edited back onto the end of its own closed message — oversized
  5. If sending the last text fails and the stream drops, the whole answer is re-sent as one final update — justified
  6. StreamRedactor gains read-only held/discarding, and the line budget rises by 10 — justified
  7. handler.py re-exports three new private helpers — zero consumers, undeclared

[FIRST-PRINCIPLES-REVIEWED] 1e341e0

Description read

[DESCRIPTION-READ] 3c3e1ab0467426463f556d1e66284cbc6ce7a45027506fd3b85bbd9cffde773e

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

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings that block the merge; one advisory finding.

FINDING — src/kiro_crew/slack/handler_runtime/stream.py:924 — When a wait arrives while the redactor is dropping a value, self.carried + self.accumulated if self.redactor.discarding carries the whole pre-wait answer into the next message. The discard already set had_redaction, so the seal's redaction overwrite replaces the post-wait message with the pre-wait text plus the new text. I reproduced this: message 1 shows Intro … Header: [REDACTED: credential], then message 2 is updated to Intro … Header: [REDACTED: credential] Post wait text …, so the reader sees the earlier text twice → Fix: record the length of the carried pre-wait prefix and trim it from clean_text at the seal, the same way given_back is trimmed, so the full-text redaction pass still sees the joined text.

[OPUS-REVIEWED] 1e341e0

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

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

@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 1e341e0

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

@bolichen97
bolichen97 force-pushed the fix/stream-seal-flush-filter branch from 6aaf0c4 to d90351d Compare October 7, 2026 22:40
@bolichen97

bolichen97 commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor Author
  • span=36b2fcd53333 Tool-card flushing splits a held value -- fixed in d90351d

settle_tail now runs only at the seal; on_tool_call and the wait branch no longer call it.
A run held before a tool call stays in the redactor and is joined to the next chunk.
test_a_value_split_around_a_tool_call_is_filtered_as_one[tool-card|wait] fails on 6aaf0c4 and passes on d90351d.

@bolichen97

bolichen97 commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor Author
  • span=bbce4d880735 Held last word dropped at a wait -- fixed in d90351d

The wait branch no longer resets the redactor, so nothing is dropped there; the held run joins the next message's text.
At the seal the run is dropped only when the overwrite runs, which rewrites the message from clean_text.

@bolichen97

Copy link
Copy Markdown
Contributor Author

The Windows shard red on d90351d is test/test_session_control_doc.py::test_every_tabulated_refusal_code_is_one_the_source_raises, which also fails on main and is tracked in #17900 / #17902 (fix in #17903 / #17907). This PR does not touch that file; it will be rebased once the fix lands.

@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 Oct 7, 2026
@bolichen97
bolichen97 force-pushed the fix/stream-seal-flush-filter branch from d90351d to 44022f3 Compare October 7, 2026 23:37
@bolichen97

bolichen97 commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor Author
  • span=66de84b68691 Final copy after a wait is built without the held run -- fixed in 1b4c52f

At a wait, accumulated now restarts from the redactor's raw held run instead of empty.
clean_text and the seal overwrite are built from the same text the stream filtered.
test_a_value_split_by_a_wait_that_ends_the_turn_stays_filtered_in_the_final_copy fails on d90351d, passes on 1b4c52f.

@bolichen97

bolichen97 commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor Author
  • span=bbce4d880735 Last word before a wait that ends the turn -- fixed in 1b4c52f

The held run is carried into accumulated at the wait, so the end-of-turn post includes it.
test_the_last_word_before_a_wait_that_ends_the_turn_is_posted fails on d90351d, passes on 1b4c52f.

@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Sensitive Change Review

Sensitive files changed:

  • src/kiro_crew/security/__init__.py

  • @bolichen97 posted a complete reasoning template for 1e341e0.

@bolichen97
bolichen97 force-pushed the fix/stream-seal-flush-filter branch from 44022f3 to 1b4c52f Compare October 7, 2026 23:47
@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 Oct 7, 2026
@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Security Scope Review -- 🟡 CONCERNS

Which legitimate operations does 1e341e03b2c9e0e1ca32d2548c64e670a085223f newly refuse? Updated in place on each push. A script-confirmed regression blocks; the model proposes candidates and never decides a refusal.

Verdict basis: the reviewer's own judgement; no confirmed regression.

Security scope review -- adjudicated candidates

  • macos-latest (platform posix): 4 classified, 0 newly refused, 4 still allowed.
  • ubuntu-latest (platform posix): 4 classified, 0 newly refused, 4 still allowed.
  • windows-latest (platform windows): 3 classified, 0 newly refused, 3 still allowed.

No candidate flipped from allowed to refused.

Scope-Verdict: CONCERNS

TIGHTENING: The Slack egress StreamRedactor now keeps its held run across a wait (and across a tool card) and settles it only at the seal. It no longer lets the run be overwritten at stop_stream. The ONE threat it refuses: a credential split around a wait reaching Slack in two halves that the filter never sees joined. Quoting the hunk: self.carried = (self.carried + self.accumulated if self.redactor.discarding else self.redactor.held), along with the _give_back gate or "[REDACTED" in safe or redact(safe) != safe ... return False. settle_tail does the same at the end of the turn: if redacted: self.redactor.reset(); return. The tool-call deny composite (sensitive-bash, exfil, deny-rules) is not changed. In src/kiro_crew/security/__init__.py the only additions are the read-only held / discarding properties, and no pattern moved.

ADJUDICATED: 7 candidates, verdicts pending from the harness (the deterministic fold reports them). The candidates are controls for maintainer commands in the touched area. No shell matcher changed, so no regression is expected here and none is claimed.

PLATFORM COVERAGE: I wrote posix and windows rows: the three pytest runs for the touched area (held-tail, composition-contract digests, security-gate liveness). The windows rows use .venv\Scripts\python.exe and \ separators. I also wrote one posix git diff read. The diff makes no assumption about paths, separators, interpreters or environment variables in anything the shell classifier sees. The one format it does assume is Slack's ts string secs.micros, in _ts_before, and that is the same on every host. So no platform spelling is left unprobed. Those rows only cover the shell composite, though, not the guard that actually got stricter.

UNADJUDICATED: The guard is the Slack native-stream output redaction path: StreamRedactor together with _AnswerStream.on_text → append_text → _deliver → _give_back (redact(safe) != safe / "[REDACTED" in safe → refuse to edit the earlier message), on_tool_call(wait) → move_back / carried, and seal → settle_tail(redacted=...) → redactor.reset(). That path is reached from handle_message (slack/handler.py, the EVENT_COMPLETE branch calls answer.take_carried(), and the native seal calls answer.seal(...)). It refuses answer text going to Slack, not shell command lines, so the classifier has no verdict for it. If it could, I would have submitted these legitimate inputs, each with a wait between the two chunks:

  • "Checking now " + "v1.2.3 is out.": a version string should be given back to the earlier message, not withheld.
  • "Run " + "git push origin main to publish.": a command in prose.
  • "The commit is " + "4f9c5697b, merged.": a short hex SHA. A 40-char SHA such as 4f9c5697b0123456789abcdef0123456789abcde is the edge case of high-entropy-looking text.
  • "See " + "https://github.com/kirodotdev/KiroCrew/pull/17897 for details.": an ordinary URL.
  • "Path: " + "C:\\Users\\dev\\project\\README.md" and "Path: " + "/home/dev/project/README.md".
  • A UUID such as 550e8400-e29b-41d4-a716-[REDACTED-ACCT] split across the wait.

There are also two policy choices I can argue but not confirm:

  1. If anything earlier in the turn redacted (had_redaction or redacted), settle_tail drops the clean held tail. The overwrite should restore it from the final copy, but that only holds if the final copy is actually posted.
  2. If the joined text changes in any way under the filter, _give_back refuses. The clean run then opens the next message instead of going back to its own. That moves text but does not lose it.

[SCOPE-REVIEWED] 1e341e0

@bolichen97
bolichen97 force-pushed the fix/stream-seal-flush-filter branch from 1b4c52f to a40b4b8 Compare October 8, 2026 00:12
@bolichen97

Copy link
Copy Markdown
Contributor Author
  • span=66de84b68691 Gap inserted inside a run carried across a wait -- fixed in a40b4b8

When the held run is carried into accumulated at a wait, tool_gap is cleared, so no separator lands between that run and the text that continues it.
test_a_key_split_after_its_prefix_by_a_wait_is_filtered_as_one fails on 1b4c52f, passes on a40b4b8.

@bolichen97
bolichen97 force-pushed the fix/stream-seal-flush-filter branch from a40b4b8 to be59605 Compare October 8, 2026 00:38
@bolichen97

Copy link
Copy Markdown
Contributor Author
  • span=66de84b68691 Failed tail send after a failed rotation skips the final update -- fixed in be59605

seal records whether sending the held run demoted the stream; when it did, it re-sends clean_text with _safe_final_update(raise_on_primary_failure=True) and sets delivered only after that returns.
A failed primary send raises into handle_message's existing failure booking. The debt notice is skipped there because the update restates the whole text.
test_the_last_word_reaches_the_reader_when_its_send_and_retry_fail fails on a40b4b8, passes on be59605.

@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 Oct 8, 2026
@bolichen97
bolichen97 force-pushed the fix/stream-seal-flush-filter branch from be59605 to 538b390 Compare October 8, 2026 02:10
@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 9, 2026
@bolichen97
bolichen97 force-pushed the fix/stream-seal-flush-filter branch 2 times, most recently from 7af8a6b to 1afeb8b Compare October 9, 2026 03:41
@bolichen97

bolichen97 commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 1afeb8b
  • What rule changed: none. StreamRedactor keeps its two read-only properties, held and discarding; feed, flush, reset and every pattern are unchanged. This head adds no change to the security package.
  • Before -> after: what is filtered is the same. After a wait, a held run that the filter lets through whole and unchanged is now added back to the end of the message it came from (chat.update on that message's own blocks), instead of opening the next message.
  • Worst case if wrong: the word lands on the wrong message, or the edit is skipped and the word opens the next message as before. The edit runs only on text the filter has already passed unchanged.
  • Evidence checked: N/A, no sandbox rule moved. Unit evidence on this head: test_a_value_split_by_a_wait_is_never_given_back_split (five cases, two block shapes), test_a_value_split_by_a_wait_stays_filtered, test_a_value_split_across_two_waits_stays_filtered, test_a_value_split_by_a_wait_and_a_tool_line_stays_filtered, test_the_word_held_at_a_wait_opens_the_next_message_when_the_edit_cannot_land.
  • No regression:
    • Tools still work: flake8, isort, black, mypy, docs-lint, comment-history and brand gates: clean.
    • Backward compatible: yes; nothing is removed or renamed, and every fallback is the earlier behaviour.
    • Existing tests: test/test_slack*.py, test/test_security*.py and every *redact* test file: 8825 passed, 1 skipped.
  • How to undo: revert the second commit; the first commit's behaviour (the word opens the next message) comes back.

@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 Oct 9, 2026
At a wait the stream holds the last run of text until the next text shows
whether it is a word of its own. The next message used to open with it
("42Results are in.").

Now, once the first text after the wait has passed the filter whole and
unchanged, that run is put back at the end of the message it came from.
The edit is made on that message's own blocks, read back from Slack, so its
formatting and task plan stay as they were. If the joined text is changed
by the filter, the blocks cannot be edited, or the edit fails, the run opens
the next message as before. The next message's final copy and the saved
answer start after a run that was given back.

When the stream goes down while the turn's last text is sent, the seal now
re-sends the whole text as the final update, as it already did when the
held run's send failed.
@bolichen97
bolichen97 force-pushed the fix/stream-seal-flush-filter branch from 1afeb8b to 1e341e0 Compare October 9, 2026 04:16
@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 Oct 9, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 1e341e0
  • What rule changed: none. StreamRedactor keeps its two read-only properties, held and discarding; feed, flush, reset and every pattern are unchanged. This head adds no change to the security package.
  • Before -> after: what is filtered is the same. After a wait, a held run that the filter lets through whole and unchanged is now added back to the end of the message it came from (chat.update on that message's own blocks), instead of opening the next message.
  • Worst case if wrong: the word lands on the wrong message, or the edit is skipped and the word opens the next message as before. The edit runs only on text the filter has already passed unchanged.
  • Evidence checked: N/A, no sandbox rule moved. Unit evidence on this head: test_a_value_split_by_a_wait_is_never_given_back_split (five cases, two block shapes), test_a_value_split_by_a_wait_stays_filtered, test_a_value_split_across_two_waits_stays_filtered, test_a_value_split_by_a_wait_and_a_tool_line_stays_filtered, test_the_word_held_at_a_wait_opens_the_next_message_when_the_edit_cannot_land.
  • No regression:
    • Tools still work: flake8, isort, black, mypy, docs-lint, comment-history and brand gates: clean.
    • Backward compatible: yes; nothing is removed or renamed, and every fallback is the earlier behaviour.
    • Existing tests: test/test_slack*.py, test/test_security*.py and every *redact* test file: 8826 passed, 1 skipped.
  • How to undo: revert the second commit; the first commit's behaviour (the word opens the next message) comes back.

@bolichen97

Copy link
Copy Markdown
Contributor Author

@iamwhatever thanks for the review on 8fcb271. Head 1e341e03b2 now does the wait case the way you suggested.

  • Message 1 gets the word back. At a wait the held run is still carried, so the filter sees it joined to the next text. Once that joined text comes out of the filter whole and unchanged, message 1 is edited with chat.update and the word goes back at its end. Message 2 then starts with its own text: "Checking now 42" / "Results are in.". If the filter changes the joined text, message 1 is left as sent.
  • Formatting is kept. The edit reads message 1 back and changes only the last text of its own markdown or rich_text block. Every other block, including the plan block, goes back unchanged.
  • The fallback is today's behaviour. If the blocks are another shape, or the read or the edit fails, the word opens message 2 as before. That case logs at debug level only, with no content.
  • Saved text matches what is shown. Message 2's final copy and the saved answer both start after the word.
  • The private-field reads were replaced by the read-only held / discarding properties. The rule is now written down in docs/system-specs/modules/slack-gateway.md.

Tests are in test/test_slack_stream_held_tail.py:

  • test_the_word_held_at_a_wait_goes_back_to_its_message_with_its_format: the edit's text and exact blocks, in both block shapes, plus message 2's opening.
  • test_the_word_held_at_a_wait_opens_the_next_message_when_the_edit_cannot_land: the fallback.
  • test_a_word_held_across_two_waits_goes_back_to_the_message_it_ended and test_each_wait_gives_its_own_word_back_to_its_own_message: two waits.
  • test_the_saved_answer_matches_the_message_the_reader_sees.
  • test_a_value_split_by_a_wait_is_never_given_back_split: five split cases, never edited back and never shown split.

Not yet run against a live workspace. Would you take another look?

@bolichen97

Copy link
Copy Markdown
Contributor Author
  • span=28e6924f9f53 A lossy edit has no fallback -- rebutted

The edit sends back the blocks Slack itself returned for that message, with only the last text extended. So whatever shape Slack stores, the message keeps it; nothing is rebuilt from what the stream wrote.
A last text block that is neither markdown nor rich_text is not edited, and the word opens the next message. Not yet run on a live workspace; the PR says so.

@bolichen97

Copy link
Copy Markdown
Contributor Author
  • span=fe852fb22c77 Five new mutable flags, and they depend on each other -- rebutted

The maintainer asked for this edit in this PR. Each flag has one writer and one reader: move_back (wait -> first send), given_back + finishing (send -> seal), streamed_at_finish (finish -> seal).
The orders that matter are pinned by tests: two waits, live versus end-of-turn sends, a failed next message, and a stream that drops while finishing.

@bolichen97

Copy link
Copy Markdown
Contributor Author
  • span=dbbfc9ab5ca6 Ship settle_tail plus carried alone -- rebutted

The maintainer asked for the edit back onto message 1 to land in this PR, not later. When it cannot land, the result is the carry-only behaviour suggested here.

@bolichen97

Copy link
Copy Markdown
Contributor Author
  • span=e4b7ffac3cdd Item 4 — oversized -- rebutted

The maintainer chose this behaviour: the word should end message 1, not open message 2. The fallback keeps every case that does not fit the expected shape at today's result, so no word is lost if live Slack differs.

@bolichen97

Copy link
Copy Markdown
Contributor Author
  • span=07d08766c9c1 Item 7 — zero consumers -- rebutted

compose runs every owner function on the handler module's globals, so _give_back and _blocks_with_run find these three helpers through handler. Without the import lines the first call raises NameError; that was seen in this PR's tests before the lines were added.

@bolichen97

Copy link
Copy Markdown
Contributor Author
  • span=bbce4d880735 Whole pre-wait text carried while a value is being dropped -- rebutted

Same as on the earlier head: it needs one value over the 4096-character hold limit before a wait, and the repeated text is message 1's already-filtered text. No give-back runs in this case.

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

Approve. The held run is now settled wherever a streamed message ends. In the common path no text is lost or duplicated, and the drop path only fires when a full-copy overwrite replaces the message.

What was verified

  • Root cause is confirmed in source: SlackClient.stop_stream never sends final_text (slack/client.py:764-778). On the base, the run StreamRedactor held at the end of a message was on no message at all. seal → settle_tail (stream.py:410-431) now flushes it through _deliver when the final text is clean.
  • Drop only happens together with the overwrite. settle_tail(redacted=had_redaction or redacted) drops in exactly the cases where seal runs _safe_final_update with the full clean copy (stream.py:1037+), or where the demoted branch re-sends the whole text (stream.py:1025-1036). So a drop never takes away text the reader would otherwise see.
  • Normal end, cancel and error: the normal end and a user stop go through seal. A cancel-by-delete removes the stream message. Error arms that replace accumulated still get the visible message's held run settled. The verdict is read after seal (handler.py:2808-2813), so a one-word answer counts as delivered.
  • Edit-in-place at a wait: _give_back (stream.py:486-524) moves the run only when the joined text comes out of the filter unchanged (no [REDACTED, redact(safe) == safe). It edits from the message's own blocks, and every failure (read miss, unknown block shape, chat.update raising) returns False. The run then opens the next message: the change fails closed, and the run is neither lost nor duplicated. After a give-back, accumulated, the final copy (given_back trim) and the saved answer all start after the run.
  • Each new guard/fix was disabled in turn. Each one reddens a named test, with two exceptions: the redacted drop in settle_tail (sending instead stays green, but flush() redacts and the overwrite replaces it, so harmless), and the discarding check on move_back (an equivalent mutant).
  • The earlier blocking finding, where the run held at a wait was glued onto the next message, is addressed by the give-back. Public held/discarding accessors replace the reads of private fields.

Non-blocking follow-ups

  1. Live Slack has not been checked. In the fallback, the run opens the next message with no separator (42Results are in.), because the gap is suppressed on purpose so a split value is filtered as one. If live conversations.replies does not return markdown/rich_text blocks for a chat.startStream message, every wait with a held word takes this path. Please check once against a real workspace that the give-back lands and that chat.update keeps the streamed formatting.
  2. When a value is being dropped across a wait, the whole pre-wait text is carried, so the redaction overwrite of the next message repeats that text (Intro line here. Header: [REDACTED: credential] then more words. under a first message that already shows Intro line here. Header: [REDACTED: credential]). The repeat is safe but redundant, and only happens in the redaction case.
  3. On the demoted re-send, after an earlier successful rotation in the same segment, the overwrite writes the whole segment onto the newer message and repeats the earlier part. This needs two refusals in one segment. Text is repeated, never lost.
  4. No test reddens if the redacted drop in settle_tail becomes a send. A test that asserts no append_stream follows a redacted final would pin it.

Upgrade impact: none. Nothing is persisted, renamed or rejected, and a missing history scope just takes the existing fallback. Audience fit: this fixes the default native-streaming path every Slack user is on, without degrading it.

@iamwhatever

Copy link
Copy Markdown
Contributor

This settles the run that the Slack StreamRedactor holds back when a message ends, so the last word of an answer reaches Slack. The end-of-turn case (seal -> settle_tail) was already fixed at the root cause. Checking iamwhatever's CHANGES_REQUESTED on 8fcb271 point by point against head 1e341e0: (1) the wait case has been reworked. The held run is now carried across the wait, filtered joined with the next text, and given back to message 1 by _give_back with chat.update when the joined text comes out unchanged. That fixes the "42Results" glue in the normal path, and tests now assert what message 1 shows (test_the_word_held_at_a_wait_goes_back_to_its_message_with_its_format, ..._across_two_waits_...). When the edit cannot land, or the filter changed the joined text, the run still opens message 2 with no gap. That is deliberate and tested, but it is still the reported symptom in the fallback. (2) The public accessor is done: StreamRedactor.held and discarding in src/kiro_crew/security/init.py. (3) The request for maintainer sign-off on the credential-redaction path still stands, and the review is still open. I tried to get a split credential past the filter: a key cut by a wait, by wait plus a tool line, or by two waits stays in the redactor and is filtered joined (tests at test_slack_stream_held_tail.py), and _give_back refuses to edit message 1 whenever redact(safe) != safe or [REDACTED is present. I did not find a bypass. I am holding because the PR changes the Slack egress redaction path, iamwhatever's change request is still open, and Security Scope Review is CONCERNS on the current head. A maintainer should verify the redaction behaviour and dismiss or re-review. — crew-pr-reviewer

@iamwhatever

Copy link
Copy Markdown
Contributor

Deep re-review of a held PR. It makes the last word an answer holds back reach Slack. At the seal, settle_tail sends the held run when the text is clean and drops it when the text was redacted. At a wait, the run is carried and filtered together with the next text, then given back to message 1 with chat.update. I tried to get a credential past the redactor by splitting it with a wait, a wait plus a tool line, or two waits. In every case the carried run stays in the redactor, so the whole stream is filtered in order. _give_back only edits when redact(safe) == safe, [REDACTED is absent, and both safe and accumulated start with the run. I found no bypass. The guard reads the same joined text the stream sends. Opus span bbce4d880735 reports pre-wait text shown twice; the author rebutted it on the current head. It only happens when a value over 4096 chars is being dropped at a wait, and the repeated text is already filtered, so it is visual and not a leak. FP span 07d08766c9c1 (dead re-exports) is rightly rebutted: compose resolves those helpers through handler globals. Every whole-design item has a disposition on 1e341e0. The PR is MERGEABLE and checks are green. The hold reason still stands: this is the Slack egress redaction path, and Security Scope is UNADJUDICATED on the head. iamwhatever's CHANGES_REQUESTED on 8fcb271 is still the open review decision. All 3 of its points are now met: the accessors are public, the wait glue is fixed in the normal path, and sign-off is this review. buluoray approved the current head. Still not approving. What is needed: No code change. iamwhatever (as maintainer) verifies the redaction path, then dismisses or re-approves the old CHANGES_REQUESTED on 8fcb271 so the review decision clears. On the owner decision: Accept the give-back by chat.update. If live Slack returns an unknown block shape, the fallback keeps the word whole at the start of message 2, which is today's result, so nothing is lost or leaked. Risk: medium. — crew-pr-reviewer

@bolichen97
bolichen97 merged commit a098d44 into main Oct 9, 2026
111 of 119 checks passed
@bolichen97
bolichen97 deleted the fix/stream-seal-flush-filter branch October 9, 2026 06:24
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 9, 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.

slack: StreamController can stop a stream before flushing the StreamRedactor tail

3 participants