Repository navigation
fix: flush StreamRedactor tail before stopping Slack stream - #4762
jiapingzeng wants to merge 1 commit into
Conversation
|
👋 Hi! This PR is currently in draft status. Workflow runs won't be auto-approved until it's marked as ready for review. When you're ready, click "Ready for review" and the workflows will be approved on the next cycle automatically. |
2 similar comments
|
👋 Hi! This PR is currently in draft status. Workflow runs won't be auto-approved until it's marked as ready for review. When you're ready, click "Ready for review" and the workflows will be approved on the next cycle automatically. |
|
👋 Hi! This PR is currently in draft status. Workflow runs won't be auto-approved until it's marked as ready for review. When you're ready, click "Ready for review" and the workflows will be approved on the next cycle automatically. |
c5ab712 to
73f09c2
Compare
|
👋 Hi! This PR is currently in draft status. Workflow runs won't be auto-approved until it's marked as ready for review. When you're ready, click "Ready for review" and the workflows will be approved on the next cycle automatically. |
73f09c2 to
cc8f1e8
Compare
99b18b6 to
810a4a4
Compare
GPT 5.6 Review (fork) — 🔴 changes requested (blocking)Reviewed 1 of 1 blocking finding(s) are security-class and were withheld from adjudication, so the blocking verdict stands. BLOCKING -- src/kiro_crew/slack/handler.py:5452 -- stale redactor tail can disclose a credential after an error Adjudication (Opus 5) — is blocking on each finding proportionate?UNBOUNDED (credential disclosure). Conditions confirmed: the per-chunk redactor withholds the trailing credential-class run and Recovery: none — the overwrite gate ( Real fix cost: one [ADJUDICATION] ca033ff total=0 uphold=0 downgrade=0 [ADJUDICATION-FENCED] ca033ff fenced=1 flagged=0 |
First Principles Review (Fable 5, fork) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Verify the new tests fail on base — the defect's only provenance is a screenshot plus tests this lane could read but not run. Every load-bearing premise checked out against the base checkout: What this change shipsInventory (10 items) — 10 justifiedIntent: streamed Slack replies arrive complete without weakening stream redaction — a FIX.
[FIRST-PRINCIPLES-REVIEWED] ca033ff Description read[DESCRIPTION-READ] 76701c916db1c589cfe238a9c6da5c93773fc3669481c442fe5c7b736bbf13ec That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Fable 5, fork) — 🟡 CONCERNSDesign-level review of Design-Verdict: CONCERNS Tail dropped at a tool-card boundary is restored only if the end-of-turn render also redacts — a prefix-only redaction verdict loses text silently. Watch
Suggestions
[DESIGN-REVIEWED] ca033ff Description read[DESCRIPTION-READ] 1bb89ebec3ffe30129cc681c51c7ca787fb45ce2d3f7631eec2f7385577e0778 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 |
Opus 5 Review (fork) — ✅ no blocking findingsReviewed Review detailsA turn whose answer is delivered only by the tail-abandon overwrite is still booked a delivery failure. FINDING — src/kiro_crew/slack/handler.py:5518 — when the end-of-turn [OPUS-REVIEWED] 45a5ba9 |
c0021fb to
0c700f1
Compare
|
Kiro Crew [operator: chenmingwei23#de330d0c]: Pushed 8cf0df9 addressing both GPT round-3 BLOCKING findings on 07f146b (both verified real):
Module 189/189 green; isort/flake8/black gate pass (baseline intact). Single commit amended; head is now 8cf0df9. |
8cf0df9 to
73c920b
Compare
|
Kiro Crew [operator: chenmingwei23#de330d0c]: Pushed 73c920b addressing the GPT round-4 BLOCKING finding on 8cf0df9 (verified real): a REDACTED pre-wait turn silently lost its safe trailing text -- the withheld tail was dropped and, worse, the already-streamed obfuscated credential stayed visible in the stopped message with nothing correcting it. Fix as prescribed: after stopping a redacted pre-wait stream, overwrite it with the complete redacted render via _safe_final_update -- the exact recovery the end-of-turn stop already uses -- so safe text survives and only credential spans are masked. New test test_redacted_pre_wait_turn_overwritten_not_truncated (fails on 8cf0df9, passes now). Module 190/190; isort/flake8/black gate pass, baseline intact. Round table for this function span (each round a DIFFERENT cell of the clean/redacted x flush/overwrite space, none re-opened):
The state space is now fully covered: clean turns append the proven-safe tail (no truncation); redacted turns never append unverified bytes and always receive the complete redacted overwrite, at both the wait boundary and end of turn. If a further blocking finding lands in this span, we will escalate to the maintainer with this table rather than continue point-patching. |
|
Kiro Crew [operator: chenmingwei23#de330d0c]: STOPPING the automated fix loop on this PR per the consecutive-rounds rule -- GPT round 5 is the 5th consecutive blocking round inside the same ~40-line span (_flush_sred_tail + the wait boundary), and this round's advisory finding asks to REMOVE the wait-boundary flush that round 3's blocking finding required us to ADD. The reviewer is no longer converging on this span; a maintainer call is needed. Round table:
Assessment: r5's blocking finding is a genuine but progressively narrower edge (requires two consecutive Slack API append failures with a successful rotation in between, at a wait boundary, on a clean render). Each round has been a different cell of the state space and every prescribed fix so far came from the reviewer itself; r5 now points in two directions at once (extend the boundary overwrite vs delete the boundary flush). Options for the maintainer:
The branch is NOT push-frozen; whoever picks an option can direct the next step. All other lanes are clean on this head (Design, First Principles, UX green; Opus round 4 was in flight at freeze). CI is fully green (two unrelated flakes -- test_sel Windows, test_safety_override 3.10 -- cleared on attempt-3 retry). |
73c920b to
d9d3e43
Compare
|
Rebased onto main Clean rebase, no conflicts. The end-of-turn flush site survived #9260's rewrite of Gates run locally on the changed files only: Please review the rebase. A maintainer push makes the maintainer the last pusher, so a second approver is needed under the repo's last-push rule. Reply if anything looks wrong. |
|
Rebased onto current Conflicts resolved1. The 2. The end-of-turn stop ( Two follow-on fixes the restructure requiredBoth are integration with main's new shape, not changes to what this PR does.
TestsInterpreter-only run (no editable install on this host),
Gates: Left openWhether the flushed tail should additionally be sent as |
|
Pushed F1 — F2 — Non-blocking finding — Red-beforeBoth fixes are pinned by new tests, and both tests were confirmed to FAIL with only the two behaviour changes reverted (tests kept in place):
Verification on this head
The previous head was 82 checks passing with GPT the only blocking lane, so this push carries only the two findings above. The |
|
Stopping the automated fix loop here and handing back. The rebase itself is done and sound: on Why I am not pushing a third roundRound 1's two blocking findings were on the code the rebase itself had to add. Round 2's F1 is on the line I added to fix round 1's F2. That is the compounding shape this PR already hit once — an earlier operator stopped the automated loop here after four such rounds — and both remaining findings are security-class fenced, which the lane itself says adjudication cannot clear:
So a machine cannot clear these, and I am not recording an override on a security-class finding on my own reading. Both also sit on the PR's design rather than on the rebase. F2 —
|
Both fenced findings dispositioned — I built the fix for F1 and then deleted itI tried to fix F1 exactly as suggested, proved it worked, and then removed it because it silently overturns a main-owned accounting invariant protected by an issue-specific regression test. Details below so the next reader does not rebuild it. No code change is pushed: this head is unchanged. F1
|
|
/ai-review override gpt 62e693a: Both fenced findings verified at this head. F1's fix flips two main-owned tests (test_native_stream_all_appends_refused_books_failure, test_append_retry_raise_after_successful_rotation_still_delivers): StreamRedactor withholds a tail even for plain text, so both DO reach the tail-abandon branch and assert no-append-landed => failure -- a product decision. F2's truncate-then-_safe_final_update pattern is base behaviour (handler.py:4643,4656,4869). Residual accepted by the maintainer. Recording this after checking both fenced findings against the code at this head. One of my own working hypotheses was wrong and the check is what caught it, so both are written out. F1
|
| chunk fed | feed() emits |
flush() tail |
|---|---|---|
The answer is 42 |
The answer is |
42 |
the answer is 42 |
the answer is |
42 |
hello world |
hello |
world |
So _flush_sred_tail has a non-empty tail in both tests. _AllAppendsRefusedSlack refuses every append and AlwaysRaisingAppendSlack raises on every append; MockSlackClient.start_stream succeeds on rotation (neither sets _start_stream_fails), so rotation lands, the retry fails again, and use_slack_stream = False (handler.py:3580). Both tests therefore DO reach the tail-abandon branch, and both assert success == 0, failure == 1. There is no narrower scoping available — the tests' scenario is the tail-abandon scenario.
Main also holds the opposite rule on the sibling arm: test_transport_stream_all_appends_refused_but_fallback_delivers_stays_success asserts "the fallback chat.update delivered the answer, so the turn is a success". The native and transport arms genuinely disagree, and picking one is a product decision about the consecutive-failure breaker, not something a PR about a dropped stream tail should settle by editing an issue's regression suite. The residual is bounded as the adjudicator described: the breaker trips only at 5 consecutive failures and any successful turn zeroes it.
F2 handler.py:4260 — base behaviour, verbatim, including the redaction gate
Confirmed on the PR's base (0140fdd57), not inferred from the diff:
render_one_for_slackhard-truncates atSLACK_MAX_TEXT = 39_000and appends the "…truncated (N chars total)" notice (format.py:16,format.py:934-941).handler.py:4643renders into_render,4644takes_render.text,4656assignsclean_text.handler.py:4867gates on_stream_had_redaction or _render_redacted or exfil_warnings or cred_warningsand feeds that already-truncatedclean_textinto_safe_final_update(basehandler.py:4869), which is itself pre-existing and split-capable (basehandler.py:6092, and the comment at6081says so).
So on main today a >39,000-char redacted reply loses its suffix at the end-of-turn overwrite, with no mid-turn wait anywhere in it, under the same redaction condition the finding names. The pre-wait branch mirrors that site rather than adding the loss. Fixing only the pre-wait site would leave the two boundaries disagreeing while base keeps losing the same bytes; lifting the render ceiling is its own change with its own evidence.
Clearing the lane on this head. Both residuals are accepted as maintainer decisions, not as refutations of the findings — F1 is real and F2 is real; neither is introduced by this PR's own code.
Human judgment recorded@iamwhatever marked the gpt AI finding as false positive, not applicable, or explicitly accepted for
This decision applies only to this commit. A new push requires a new judgment. |
|
Human judgment recorded, but the following reviewer lane(s) could not be re-run automatically: GPT 5.6. Re-run the lane's latest workflow run for |
Security Scope Review (fork) — 🔴 BLOCK (blocking)Which legitimate operations does no leg reported, and this was not the nothing-to-adjudicate short circuit Scope-Verdict: CONCERNS TIGHTENING: the Slack stream-tail disclosure rule in ADJUDICATED: 10 candidates, 0 confirmed newly-refused PLATFORM COVERAGE: posix (interpreter path UNADJUDICATED: The tightening does not live in the tool-call deny composite at all; the classifier can attest nothing about it, and the zero-confirmed adjudicated set above is NOT evidence for this guard. The guard: [SCOPE-REVIEWED] dabf967 |
Slack's stop_stream ignores final_text, so the StreamRedactor's withheld tail was silently dropped at end-of-turn, truncating the visible reply. Flush it as an append frame -- but ONLY when the end-of-turn full-text render proved the turn clean. When that render redacted anything, a flushed tail could complete a display-obfuscated credential whose prefix already streamed (the per-chunk redactor does not normalise ANSI or zero-width obfuscation), and an appended frame is visible and capturable the instant it lands -- the later overwrite cannot recall it. In that case the tail is reset and the guaranteed _safe_final_update overwrite posts the complete, fully-redacted text, so nothing is lost. The mid-turn wait boundary never flushes: that message is stopped and never re-rendered, so a leak there would be final. Original fix authored by Jiaping Zeng (@jiapingzeng); hardened per the GPT 5.6 review finding on the prior head (a redacted-render tail flush could briefly stream a credential before the final overwrite corrected it). Co-authored-by: Kiro Crew <noreply@kirodotdev.github.io>
|
Thank you for this fix, @jiapingzeng — the diagnosis is right: the stream can stop before the withheld Since this PR was opened, main moved the Slack streaming path out of |
|
Open-PR triage (2026-10-05) — #4762 I read the full diff at head 1. Needs a port, not a rebase. #16908 (merged 2026-10-05) moved the native Slack streaming path out of 2. Credential-disclosure finding still applies to this head (open, not new). I checked the GPT 5.6 blocking finding against 3. Overlap with #10192 (merge discussion). #10192 (pako links) also adds a withheld-tail flush before Recommendation: keep open / continue development (port onto |
bolichen97
left a comment
There was a problem hiding this comment.
[P0] Error arms flush the redactor's withheld credential tail to Slack
Class: Redaction bypass (credential leak to Slack).
Mechanism: On the error arms the reply text is replaced but the stream redactor's withheld tail is not reset. The end-of-turn render then reads only the error text, reports clean, and the new tail flush appends the withheld, unredacted tail to the Slack stream.
User impact: A credential the redactor was holding back can reach the Slack thread when a turn ends in an error.
Location: src/kiro_crew/slack/handler.py:5454 @ ca033fff5c58e2081f53aabb5d458a2a0423f06e
Minimum fix: Do not treat the error-text render as proof the tail is clean: drop or reset the withheld tail on every error / replacement arm (e.g. _flush_sred_tail(_render_redacted or _had_error)).
How to verify: A handler test that streams a split secret, then raises AcpError (and AcpPromptBusy), and asserts the secret is absent from all streamed frames. It fails on this head and passes after the fix.
Exploit details are left out on purpose. They are available to maintainers through the repo's private security reporting.
Independently re-verified on head ca033fff5c with a focused local reproduction.
| if stream_buffer: | ||
| stream_buffer, _ = strip_thinking_tags(stream_buffer, strip_whitespace=False) | ||
| await _append_stream(stream_buffer) | ||
| await _flush_sred_tail(_render_redacted) |
There was a problem hiding this comment.
[P0] Error arms flush the redactor's withheld credential tail to Slack — see the review summary for mechanism, fix and test.
|
Thanks for this. The Slack stream code moved into |


Problem / Motivation
Goal: Streamed Slack replies arrive complete, and the credential redaction on the stream stays as strong as it is today.
The last word of a streamed Slack reply goes missing. When the agent calls a tool mid-reply, the last word before the tool card lands in its own block after the card instead.
Why it matters
Any reply whose final characters are letters, digits or punctuation (almost every reply) loses its last word on the wire. Replies that use tools also show stray one-word lines between task cards. Users read incomplete or broken-up answers, and the only workaround is to ask the agent to repeat itself.
Not a goal
StreamRedactordecides what to withhold.test_native_stream_all_appends_refused_books_failurerule stays).What changed (motivation → approach → change)
wait(message is stopped)StreamRedactorholds back the trailing run of credential-class characters in case a credential is split across chunks. The handler assumedstop_streamwould post the complete text, butSlackClient.stop_streamnever sendsfinal_text, so that tail was dropped. The tail was also released only with the next chunk, so before a tool card it landed after the card.In
slack/handler.py,_flush_sred_tailnow settles the tail at each boundary above, gated on a render of the complete visible text (thinking, control comments and OPTIONS removed, as at end of turn). The render normalises ANSI and zero-width obfuscation, which the per-chunk scan does not. So a flushed tail can never complete an obfuscated credential whose prefix already streamed. A tail that lands counts as a delivery (_stream_delivered). A tail whose append and rotated retry both fail where the segment ends drops the turn out of stream mode, so the complete text is posted by overwrite; before a task card the stream stays live and the loss is recorded as delivery debt, like any refused delta. Awaitcall skips the task-card flush and settles its tail at thewaitboundary. When a redacted reply streamed no text at all, the end-of-turn overwrite is its only delivery: it runs withraise_on_primary_failureand books the answer as reached.Backwards compatibility
Compatible: no config, API or wire-format change; Slack messages gain the text they were losing.
Tests
test/test_slack_handler.py:test_trailing_run_survives_on_stream_wire-- the append frames carry the whole reply.test_redacted_render_drops_flushed_tail_from_wire,test_exfil_url_in_flushed_tail_is_redacted-- a redacting end-of-turn render keeps the withheld half of an ANSI-split key / split URL off the wire; the overwrite carries the redacted text.test_wait_boundary_does_not_flush_uncorrectable_tail,test_tail_buffered_before_wait_never_flushed_after_it-- a redacted pre-wait tail is never appended, before or after the wait.test_clean_tail_flushed_into_pre_wait_message-- a clean pre-wait tail lands in the pre-wait message.test_redacted_pre_wait_turn_overwritten_not_truncated,test_lost_pre_wait_tail_overwrites_the_stopped_message-- the stopped pre-wait message is overwritten when its tail was redacted or lost.test_pre_wait_overwrite_excludes_thinking_text-- that overwrite renders only what the stream showed (no inline thinking).test_clean_tail_lands_before_task_card,test_redacted_tail_not_flushed_before_task_card-- the tool-card boundary appends a clean tail before the card; a redacted one reaches no append frame, before or after the card.test_flush_retry_failure_falls_back_to_final_update-- a tail that fails append and retry is recovered by the final update.test_refused_tail_before_task_card_keeps_streaming-- a tail refused twice before a task card leaves the stream live and discloses the loss as debt.test_tail_only_reply_is_not_booked_a_delivery_failure,test_redacted_credential_only_reply_is_not_booked_a_failure-- a reply delivered only by the flush, or only by the redacted overwrite, is not booked a failure.Manual verification
Ran on a local build against a real Slack workspace; replies arrive complete.
Before:

After:

Screenshots / video
N/A -- no dashboard UI change; Slack before/after is under Manual verification.
Related Issues
no linked issue: symptom reported directly (screenshot above).
Pattern harvest
Rule candidate: review-prompt
Pattern: a buffering filter in front of an append-only sink must be drained at every point the sink's segment ends (stop, rotation, interleaved non-text frames), gated on the strongest verdict available there.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)