Skip to content

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

Closed
chenmingwei23 wants to merge 1 commit into
mainfrom
fix/discord-recovery-seam-and-wecom-baseline-13743
Closed

chenmingwei23 wants to merge 1 commit into
mainfrom
fix/discord-recovery-seam-and-wecom-baseline-13743

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 slice of the answer taken before the display redaction, and adds only the difference. That keeps the whole-answer tally across a rotation, and it announces the markers the display pass itself introduces instead of netting them to zero.
  • 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, at the live frame, and on the upload-recovery fallback -- that fallback is reached when the files-bearing chunk fails to land, shows text under a message already sealed, and writes the record, so it grades before it splits. The record itself 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: 156 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: 13 of 13 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 and structural 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 seal's two text-showing paths each carrying their own grade, counted per sink so one cannot stand in for the other; the grade preceding every splitter call in that sink; WeCom's baseline preceding the display redaction; the repaired Telegram body 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.

Pattern harvest

Rule candidate: when a guard is added at a sink, enumerate every path that reaches that sink by DERIVING the set from the code rather than listing it, and count the guard per path rather than asking whether the function mentions it.

Pattern: this change fixed the same shape three times in a row. A guard lands on the path a reviewer named; a sibling path into the same sink keeps the old behaviour; and the check written alongside the fix asks only whether the guard appears somewhere in the file, so the sibling passes. It recurred here even inside one function -- adding the recovery grade made the older membership check on the seal pass vacuously, which the mutation caught only after the check began counting per path.

Where it generalises: test_split_credential_boundary.py now derives its population with _modules_that_split() and counts grades per sink, and the same two moves apply to any invariant enforced by a source-scanning test. The exception map is the other half: an exemption has to state the property that makes it true and fail when that property stops holding, otherwise it silently covers code written later.

Predecessor: #13984, merged. Supersedes #14029, which carried this delta without the two fixes above.

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 the slice of the answer taken BEFORE the display redaction, so
the markers that pass introduces are announced rather than netted to zero.
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 seal sink and at its live
frame, so all five of its sealing paths inherit it. Its upload-recovery fallback
shows text too, under a message already sealed, so that path grades before it
splits and the record it writes stands for text that was graded. 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 bolichen97 September 26, 2026 00:17
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Sep 26, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — 🟡 CONCERNS

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

Design-Verdict: CONCERNS

Module-keyed exemptions re-open the invisible-path class this PR exists to close: a new unguarded splitter call in an excepted module passes silently.

Watch

NO_SEAM_TO_GRADE is keyed by module, but each claim it records is about ONE call ("the prefix-stable branch…", "the replay preview keeps chunks[0]…"). whatsapp/renderer.py today holds one legitimately unguarded call plus guarded ones; a future second unguarded call there is skipped by test_every_splitter_call_passes_a_redactor (module not in GRADED_MODULES) while test_no_exception_has_gone_stale still passes (assert unguarded stays true) — so the new call inherits an exemption written for a different call, exactly the "silently covers code written later" failure the harvest section names. Consequence: an ungraded seam ships on WhatsApp or Teams with no red test, the same delivered-key harm the derived walk was built to make impossible.
Clears when: the exemption is keyed to the call site (function name or an expected unguarded-call count per module), so the staleness test fails on any unguarded call the claim does not describe.

Suggestions

Discord's _replay_preview has the same keeps-chunks[0] shape as the exempted Teams preview but was guarded instead — pick one treatment so the exemption map states a rule, not a history.

[DESIGN-REVIEWED] b3ac073

@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/discord-recovery-seam-and-wecom-baseline-13743 branch November 6, 2026 07:26
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