Skip to content

fix(channels): guard every delivery path the enumeration derives - #14029

Closed
chenmingwei23 wants to merge 1 commit into
mainfrom
fix/cross-delivery-redaction-13743-followup
Closed

chenmingwei23 wants to merge 1 commit into
mainfrom
fix/cross-delivery-redaction-13743-followup

Conversation

@chenmingwei23

Copy link
Copy Markdown
Contributor

What is the problem?

Three of the delivery paths that grade a delivered sequence read a subject narrower than the answer, so the redaction notice under-counts what shipped, and one repair leaves a table run cut mid-body.

  • wecom/renderer.py re-counts remainder = answer[self._carried:] and assigns the result. After a bubble rotation that subject starts past everything already delivered, so a placeholder in an earlier bubble drops out of the notice.
  • slack/renderer.py's no-stream fallback writes the delivery ledger for chunks[0] only, while the continuation posts record nothing. The notice counts that ledger, so an over-limit answer announces fewer placeholders than it shipped.
  • telegram/renderer.py's table-aware cut hands a repaired body to the prose splitter, which knows neither the table blocks nor the rich budget. The table run is re-cut against the wrong budget and its rows strand as literal pipes.

Separately, the enforcement that every path delivering one chunk as one message passes a redactor was a hand-written list of seven modules. A path nobody adds to such a list is not merely unchecked, it is invisible, and the paths most likely to be forgotten are the new ones. Walking the tree finds three delivery paths outside that list with no redactor at all: Discord's rotation and seal, Feishu's reply split, and the shared transport chunker every channel-neutral sink calls.

The module spec also states something the code contradicts: that the splitter is "stdlib-only and pure -- no config objects, no modes".

Why this issue matters to the user

The redaction notice is how a user learns a credential was removed from the reply they just read. A tally that drops the placeholders already on screen tells them nothing was redacted when something was, so they do not know to rotate the key.

On the three unguarded paths the consequence is the one this work exists to close. A key written across a line break matches nothing as written, so every per-message scan passes it; the cut then removes that break and the reader scrolling two messages reads the key whole while neither message holds it. Both messages are already delivered, so there is no recovery. Discord and Feishu are ordinary answer-delivery paths, and the shared chunker carries the dashboard's channel-addressed sends and the Slack mirror.

A stranded table row is a smaller harm: the answer is complete but reads as literal pipes.

How our fix solves it

Each tally counts what it can see, and the count is an addition rather than a replacement:

  • WeCom measures the shipped chunks against the same redacted remainder they were cut from and adds only the difference, so the whole-answer tally survives a rotation.
  • Slack records every confirmed continuation in the ledger, which makes the ledger the delivered text the notice already assumes it is.
  • Telegram's repair re-enters the same block assembly that graded it, so the table run keeps its own budget. Sound without a second grade, because repaired_for_delivery answers only with text that reads clean even with every whitespace run removed.

The enumeration is derived instead of listed. _modules_that_split() walks every module under src/kiro_crew that calls a splitter accepting a redactor, and each call must pass one. Two calls are excepted, and each entry states the property that makes it true rather than an intention: the Teams replay preview keeps chunks[0] and discards the rest, so no second message exists to rejoin across; WhatsApp's prefix-stable branch cuts an already-redacted body at its own budget and nowhere else, because searching for a safer budget would move a boundary under a message already sent. A staleness test fails when either claim stops holding, so an exception cannot outlive its reason, and a walk that returns a subset of the tree fails against the channels it must reach.

That walk's three findings are closed rather than deferred:

  • Discord passes its redactor at every rotation and seal split, bounds the fail-closed answer through bounded_for_delivery with its own last-resort cutter, and gains one grader and one writer for the sealed predecessor. The grade runs at the seal sink and at the live frame; the record is written only where a send or edit confirms, because recording unsent text would cost the next delivered message a leading span for a key nobody read.
  • Feishu passes the redactor and bounds the result, since each chunk is its own reply.
  • chunk_for_transport guards both units. The character path passes the redactor; the byte path grades the sequence split_markdown_bytes produced, using the byte cutter it measured in, because that splitter reaches its budget by shrinking a character limit and retrying and a cut free to decline would not terminate on it.

The shared splitter drops its stable mode. One streaming caller selected it, and the branch is two calls that caller's own renderer already makes, so the contract now lives with the caller that needs it and the pure primitive carries no mode. The spec sentence is corrected to match, and the credential-aware cutting contract is written down beside the others.

What tests we did

Every run scoped with an explicit -n0.

  • Owned file test/test_split_credential_boundary.py: 154 passed, 5 skipped.
  • Touched and adjacent modules: Discord 271, Telegram 334, security posture 53, Slack renderer 73, WeCom 33, WhatsApp renderer 46, WhatsApp turn renderer 39, Feishu client 47, Feishu renderer 21, Webex renderer 34, messaging transport 17, display split safety 50, Discord outbound files 78, dashboard messaging handlers 252, messaging import purity 8, cron channel delivery 52, cross-surface mirror 33, capability ledger 20.
  • Reverse mutation on every new guard: 11 of 11 discriminate, each gated on a control run of that selector passing unmutated, a sha256 change proving the mutation applied, an explicit failure count in the mutated run, and a restore verified by hash against a pristine copy held outside the repository.
  • New behaviour cases: a key straddling a Discord rotation boundary at the channel's real 2000-character cap, with the plain cut as the control that ships it; the repaired Telegram body still honouring the rich budget, which the prose splitter cannot; and the derived enumeration failing when any one path drops its redactor.
  • Gates: black, isort, flake8 and the comment-history gate clean; docs_lint.py clean; mypy over src/kiro_crew/ reports 4 errors in transcribe.py and ops_mission_control/backend/providers/cloudwatch.py, neither touched here.

Any other suggestions on the work

The content-revision half of the streaming case stays open and is not addressed here: a sealed message can render differently once a later frame arrives, which a delivered-chunk count cannot observe. Closing it needs grading against what is already on screen, which is #13494's subject. The disclosure half -- a sealed credential prefix completed by text arriving afterwards -- is closed on every path this touches.

Predecessor: #13984, merged. This carries only the work that followed it.

Refs #13743

Three paths that grade a delivered sequence read a subject narrower than the
answer, and the enumeration enforcing the guard was a hand-written list, so the
paths most likely to be missed were invisible to it.

WeCom re-counted a remainder starting at the rotation offset and assigned the
result, dropping every placeholder already delivered; the count is an addition
measured against that remainder. Slack's no-stream fallback recorded only chunk
0 in the ledger the notice counts, so an over-limit answer announced fewer
placeholders than it shipped; every confirmed continuation is recorded.
Telegram's table-aware cut re-split a repaired body with the prose splitter,
which knows neither the table blocks nor the rich budget and cut the table run
mid-body; the repair re-enters the assembly that graded it.

The population is derived by walking every module that calls a splitter
accepting a redactor, with an exception map whose entries state the property
making them true and fail when it stops holding. The walk finds three delivery
paths with no redactor: Discord's rotation and seal, Feishu's reply split, and
the shared transport chunker, whose units every caller sends as its own message.
Discord also gains the sealed-predecessor record at its one seal sink and at its
live frame, so all five of its sealing paths inherit it. The byte unit is
guarded by grading the sequence the byte splitter produced, because that
splitter reaches its budget by shrinking a character limit and retrying, which a
cut free to decline would not terminate on.

The shared splitter drops its `stable` mode: one streaming caller selects it and
the branch is two calls that caller's own renderer already makes. The module
spec is corrected to match and states the credential-aware cutting contract.

Refs #13743
@chenmingwei23
chenmingwei23 requested review from a team and cixuuz September 25, 2026 23:38
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — ✅ PASS

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

Design-Verdict: PASS

Nothing to check.

Suggestions

  • The derivation matches splitter calls by bare name, so a new module importing split_markdown_safe as x silently exits the population; matching the import binding too would close the one evasion the KNOWN_DELIVERY_MODULES floor doesn't (floor only covers already-known modules).

[DESIGN-REVIEWED] 04fed51

@github-actions

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5) — ✅ PASS

Premise-level review of 04fed51a28801dd6d2f7166992f682986a8e1325 — 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

The module-keyed NO_SEAM_TO_GRADE exemption: a later unguarded splitter call in whatsapp/renderer.py or teams/session_resume.py would inherit it unseen — confirm that residual is accepted.

What this change ships

Inventory (10 items) — 10 justified

Intent: make every multi-message delivery path cut and count credential-aware, and make that enforcement derived rather than hand-listed — a FIX.

  1. WeCom's redaction notice keeps placeholders from already-delivered bubbles (re-count is additive) — justified
  2. Slack's over-limit notice counts continuation posts, not just chunk 0 — justified
  3. Telegram's repaired table body is re-cut by the same table-aware assembly, so rows keep their pipes and rich budget — justified
  4. Discord's rotation and seal splits become credential-aware — justified
  5. Discord grades each shown message against the last delivered one, recorded only on confirmed delivery — justified
  6. Discord over-cap payloads are bounded and re-graded instead of blind-flattened — justified
  7. Feishu reply splits become credential-aware and bounded — justified
  8. The shared transport chunker guards both char and byte paths (dashboard channel sends, Slack mirror) — justified
  9. The shared splitter's stable mode is deleted; WhatsApp carries its own two calls, spec sentence corrected — justified
  10. Test enforcement is derived from a tree walk, with two verified exceptions and staleness tests — justified

Notes a human may want: the reversal of the old "Enumerated rather than discovered" pin carries its own evidence (three unguarded paths the list missed, all closed here); both exception claims were verified against the code (teams/session_resume.py:346 keeps chunks[0]; whatsapp/turn_renderer.py grades its own seam at lines 283/301/585); _fit_platform_cap's new limit parameter has a real consumer (bounded_for_delivery calls cutter(chunk, budget), split.py:498); no unfixed narrow-subject tally siblings found (whatsapp/turn_renderer.py:611 and teams/renderer.py:429 already count the whole delivered answer).

[FIRST-PRINCIPLES-REVIEWED] 04fed51

@github-actions

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — 🔴 changes requested (blocking)

GPT 5.6 found at least one blocking issue that must be resolved before merging 04fed51a28801dd6d2f7166992f682986a8e1325. 1 of 1 blocking finding(s) are security-class and were withheld from adjudication, so the blocking verdict stands.

This comment is updated in place on each push.

BLOCKING -- src/kiro_crew/discord/renderer.py:1309 -- upload recovery bypasses the new seam repair
recovery = await asyncio.to_thread(bounded_for_delivery, recovery, ...)
sealed credential prefix + multipart upload failure -> fallback posts the un-repaired suffix -> adjacent messages reconstruct the credential
Anchor: residual/security
Fix: pass the transformed recovery source through _seam_safe before splitting.

FINDING -- src/kiro_crew/wecom/renderer.py:324 -- using display-redacted "remainder" as the baseline subtracts newly introduced placeholders, so the notice undercounts -> Fix: compare against answer[self._carried:].

[BLOCK-MERGE] 04fed51
[GPT-REVIEWED] 04fed51

Adjudication (Opus 5) — is blocking on each finding proportionate?

UNBOUNDED (credential exposure across adjacent messages) — the harm class this PR exists to close.
Conditions confirmed: src/kiro_crew/discord/renderer.py:1286-1288 breaks to recovery when the files-bearing chunk 0 fails to land (an ordinary transient), :1303-1311 splits and bounds the restored source with no _seam_safe call, while :1268 and :1053 grade every other shown text, and :1320-1321 still records the recovery chunk as the next seam's predecessor; the ungraded seam is between the predecessor recorded at :1197/:1210 and recovery chunk 0. Recovery path: none — repaired_after_a_sent_tail (src/kiro_crew/messaging/renderer.py:431-455) is the only repair and it is not reached; inner recovery boundaries are graded, the leading one is not.
Real fix: one call to the existing _seam_safe on source before :1305 — no new state, no new invariant, no new branch.

[ADJUDICATION] 04fed51a28801dd6d2f7166992f682986a8e1325 total=0 uphold=0 downgrade=0
[GPT-ADJUDICATED] 04fed51a28801dd6d2f7166992f682986a8e1325

[ADJUDICATION-FENCED] 04fed51a28801dd6d2f7166992f682986a8e1325 fenced=1 flagged=0
UPHOLD-FENCED F1 src/kiro_crew/discord/renderer.py:1309 -- The only condition beyond the seam class this PR already treats as plausible is a transient multipart upload failure, and the graded helper is two lines above, so no residual-risk argument is available.
[GPT-ADJUDICATED-FENCED] 04fed51a28801dd6d2f7166992f682986a8e1325

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

@github-actions

Copy link
Copy Markdown
Contributor

Opus 5 Review — ✅ no blocking findings

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

Review details

Three ungraded or mis-subjected seams in the new credential-boundary machinery — none blocking.

FINDING — src/kiro_crew/messaging/renderer.py:184 — bounded_for_delivery(split_markdown_bytes(text, max_bytes), max_bytes, _default_redactor, chunk_utf8_bytes) is a guaranteed no-op because every chunk split_markdown_bytes returns already fits the budget, so chunk_utf8_bytes yields a one-element list and _rejoins_a_key's if len(chunks) < 2: return False short-circuits repaired_for_delivery to None, leaving the byte splitter's own boundaries ungraded so a key severed at a newline still reaches two adjacent Webex/WeCom messages whole on screen → Fix: grade the sequence against the source instead — repaired = repaired_for_delivery(text, byte_chunks, _default_redactor) and re-split repaired with split_markdown_bytes when it is not None.

FINDING — src/kiro_crew/wecom/renderer.py:324 — before_creds, before_urls = count_redaction_tags(remainder) reads remainder after remainder = self.redact_for_target(remainder) inserted the display-form placeholders, so a credential only the render-aware pass catches gives max(0, 1 - 1) == 0 and the reply ships [REDACTED: credential] with no security notice that the pre-change assignment did send → Fix: count before_* over the pre-redaction remainder (answer[self._carried :]), keeping the +=.

FINDING — src/kiro_crew/discord/renderer.py:1321 — the multipart-recovery sink calls self._record_sent(chunk) on text built from source = _redact_transformed(source) that never passed through _seam_safe, so when a length rotation sealed a bubble ending in a credential prefix and the file upload then fails, the recovery message ships the characters completing the key while every per-message scan passes → Fix: source = await asyncio.to_thread(self._seam_safe, source) before building recovery.

[OPUS-REVIEWED] 04fed51

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

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

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Superseded by #14088 at exact head 25f00d7. The replacement is based on repaired main, carries the verified one-commit fix, uses Refs #13743, and leaves the issue open. Closing this predecessor unmerged.

@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Sep 26, 2026
@bolichen97
bolichen97 deleted the fix/cross-delivery-redaction-13743-followup branch November 6, 2026 07:25
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.

1 participant