Repository navigation
fix(channels): grade the rotation boundary the splitter cannot see - #13494
Conversation
First Principles Review (Fable 5) — 🟡 CONCERNSPremise-level review of First-Principles-Verdict: CONCERNS The seal-redactor hunks ship what the frozen Not justified as shipped
What this change shipsInventory (9 items) — 8 justifiedIntent: stop a reader reassembling a credential from the pieces a long turn is rotated into — a FIX (provenance: tests added here fail on base; measured
[FIRST-PRINCIPLES-REVIEWED] f16e7ff |
Design Review (Fable 5) — 🟡 CONCERNSDesign-level review of Design-Verdict: CONCERNS
Watch
Suggestions
[DESIGN-REVIEWED] f16e7ff |
Opus 5 Review — ✅ no blocking findingsReviewed Review detailsThe graded fallback replaces the splitter's boundaries but not the verdicts and the fence balancing that were derived from them. FINDING — src/kiro_crew/discord/renderer.py:1129 — FINDING — src/kiro_crew/telegram/renderer.py:1581 — [OPUS-REVIEWED] f16e7ff Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 5.6 Review — ✅ human override acceptedHuman judgment by @chenmingwei23 overrides the GPT 5.6 finding for [GPT-OVERRIDE] f16e7ff This comment is updated in place on each push. The model was not re-run because an authorized human decision supersedes it. False positive or not applicable? A repository writer can comment: |
UX Review (Fable 5) — ⏭️ skippedRevision |
8db5ae4 to
62515a5
Compare
c0a6a2a to
0e17027
Compare
27f3c94 to
7570394
Compare
7570394 to
4d4bfca
Compare
`_rotate_on_length` cuts the raw buffer on a length budget and each chunk is sealed as its own message, redacted alone. #13984 closed most of this by giving the shared splitters the redactor, so they reduce the text before choosing any boundary. Two boundaries are outside that fix. Discord's rotation splitter takes no redactor at all -- `split_markdown_safe` is called with text and a limit on both its paths -- so its chunk boundaries are ungraded. And on Telegram the pre-split pass reads the text AS WRITTEN: a horizontal rule standing between the halves of a key keeps them apart there, while the seal strips horizontal rules, so the halves sit flush on screen. `severs_a_credential` is the n-piece case of `joins_to_a_credential`: it grades a delivered SEQUENCE, over the whole join and over each boundary against the rest, because neither reading subsumes the other. Both renderers gate their rotation on it and fall back to `safe_split_offset` to move the cut, withholding the buffer when no sampled offset is safe. Both take an optional `present` and grade BOTH the raw and the delivered form. A delivered-only grade is unsound in one direction that measured here: trimming reveals a join where whitespace kept the halves apart, and CONCEALS one where the pattern needs that whitespace, so `-----BEGIN ` beside `RSA PRIVATE KEY-----` reads clean trimmed and is an intact PEM anchor as sent. Three of nine straddle shapes failed on the delivered-only rule and pass on both. No gate on Telegram's held-image tail. That tail begins AT the ref span, so its first characters are always `![`, and `!` survives canonicalising between the sealed chunk and anything the tail contributes; measured over alt-text, link-target, trailing-text and bare-adjacency shapes, no join reaches a pattern. Tests: 99 pass -- the two rotation-seam classes, the primitive's own unit tests including the both-forms rule, and the `TurnFooter` and table-streaming cases that were red before. Refs #13743 Fixes #12293
The presentation fallback took one safe offset and retained the whole remainder, which is parked as `_delivery_text` where the only cut left is `_seal_current`'s ungraded length re-split. It now carves until the remainder fits the budget and reads the finished list once as a whole. The sequence grader read each boundary forwards only, so every reading ran to the end of the list and carried the next message's first letter, which the patterns anchor on. It now reads prefixes alongside suffixes. It also reads BOUNDED interior runs. A credential can sit with a spoiling message on each side, which no whole, prefix or suffix reading reaches. A window of at most four consecutive messages is slid across the interior, which is a linear number of readings over bounded-size strings; reading every contiguous run is quadratic in a piece count the author controls. The rotation's re-assignment handed back the source remainder plus the held image reference without re-grading, and an image starting at or before the budget makes the source shorter than the budget, so the offset search early-returns the whole string and the refused pair ships unchanged. The pair is now re-graded in its delivered form before it is assigned. Telegram's upload-hold branch sealed its whole prefix and returned before the length path's sequence grade. The splitter reads the raw pieces, where a horizontal rule still stands between two credential fragments, and the seam repair reads the delivered form against one predecessor only. The prefix is now graded as a sequence and carved when it severs. Discord's `_seal_current` split its over-cap payload with no redactor, where Telegram's splitter call has carried one all along. That is the last cut before the wire, with no rotation behind it, and a buffer the rotation withheld as unsafe is parked whole and arrives there over the cap -- so the withhold routed text TO the one ungraded cut. Both of its `split_markdown_safe` calls now pass one. Closes #14587
|
/ai-review override gpt f16e7ff: Reachability test applied: not reachable on a normal path (needs model-authored text deliberately cut into 5+ consecutive interior messages, each end framed by an alphanumeric spoiler), and no regression - measured here, main's pairwise gate misses every spread W>=3 while this head catches W=3 and W=4, so the residual shrinks. The demanded unbounded scan is the measured DoS in #14613 (2451 pieces, ~3M passes, fails test_a_rotation_terminates_on_pathological_input); residual tracked there. |
Human judgment recorded@chenmingwei23 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. |
Problem / Motivation
Goal: A credential can no longer be read off the screen by joining two messages that a long turn was rotated into.
When a turn outgrows one message, the renderers rotate it into several. Each piece is
scanned for credentials on its own, so a key that straddles the rotation boundary passes
every per-piece scan, and the reader joins the halves back together on screen. Nothing
warns anyone: both halves passed, so no redaction notice is posted.
Merged #13984 closed this at the splitter's seams (
_seam_safe). The rotation boundary in_rotate_on_lengthis a different cut, and on main it is still ungraded:are ungraded.
---rule between the two halves of a key keeps them apart for that reading, while the seal
strips rules, so the halves land flush on screen. Measured on this branch:
raw_severs=False,both_severs=True.Why it matters
The leak is silent and user-visible. An agent that echoes an AWS key, a PEM header or a
bearer token in a long reply gets it redacted in the ordinary case and published in the
long case, which is the case a verbose agent hits most. Because each half passes its own
scan, no redaction notice appears and no test that reads one message can see it. The
reader who reassembles the two bubbles is the only party who learns the secret leaked.
Not a goal
_seam_safe. Seven of the eight hunks thisbranch originally carried were a second implementation of that same guarantee and were
dropped rather than rebased.
_seam_safegrades against one predecessor only, so a keycompleted across three messages is invisible to it. That is a finding against the merged
design and belongs in its own PR under channels: seven delivery paths cut model text on a budget and redact per piece, so a severed credential reaches two adjacent messages #13743. One site is worth naming there rather than
leaving invisible:
_seal_without_rich's degraded-table path seals several chunks and thenre-grades only the surviving tail through
_seam_safe, so it inherits exactly that limit.Nothing in this diff reaches it.
edit_message_visibilityclient verb. It existed only to serve the dropped layer.split_markdown_safecall sitespass none, on main and here, so the seal's own over-cap re-split is graded by nothing --
where Telegram wraps the same splitter with one. That asymmetry predates this branch and is
tracked on discord: _seal_current re-splits an over-cap payload with no redactor, so that cut is graded by nothing #14587, which also carries the one narrow route that still reaches the seal with
an over-budget payload.
most four consecutive messages, which is what catches a credential with a spoiling message
on each side. Reading all runs is quadratic in a piece count the author controls -- a
5000-backtick reply splits into 2451 pieces, and the unbounded reading blew the 30-second
pathological-input budget, measured. A credential spread thinner than the cap is the
residual, on channels: the rotation's credential gate never reads an interior run of messages on its own #14613.
ONE unbreakable run longer than the cap, every boundary is inside it and a redactor on the
splitter cannot help. That gap is on Telegram too, and it needs a tradeoff decided (flatten
and scrub, or report WHERE the sequence severs). On channels: the final seal's cut has no safe boundary when the over-cap text is one unbreakable run #14644.
splitter applied, and
_segment_uploads_safe. Neither leaks a credential. On channels: the rotation's graded re-cut drops fence rebalancing and keeps a stale uploads-safe verdict #14645.What changed (motivation -> approach -> change)
Symptom -- a straddled credential is readable across a rotation boundary.
Cause -- the boundary is never graded: Discord passes no redactor to its splitter, and
Telegram's pre-split pass reads a form of the text the reader never sees.
Change -- grade the boundary at the point where the pieces are already in their delivered
shape.
messaging/display_safety.py:severs_a_credentialandsafe_split_offsetnow grade theraw and the delivered form, and a sever in either answers true.
discord/renderer.py,telegram/renderer.py: the three rotation boundaries that thesplitter cannot reach now consult that primitive, and pass the text as it will be
presented rather than pre-transforming it.
discord/renderer.py: the presentation path's fallback carves until the remainder fitsthe budget rather than taking one offset and retaining the whole rest. That retained piece
is parked as
_delivery_textwith no rotation ahead of it, so the only cut left is_seal_current's own re-split -- length only, no grade. Taking a single offset thereforebought the first boundary by handing every later boundary in the same text to that ungraded
cut. Raised by the GPT 5.6 review as F1 and upheld under adjudication.
messaging/display_safety.py: the sequence grader reads each boundary both ways. Everyreading ran to the end of the list, so it always carried the next message's first letter,
and the credential patterns anchor there. A key finished across messages 1 and 2, with
message 3 opening on a letter, matched nothing while the reader saw one whole key. Prefixes
are now read alongside the existing suffixes, which stays linear in the piece count. Raised
by the GPT 5.6 review as F1 on this head and upheld fenced.
messaging/display_safety.py: the grader also reads bounded interior runs. A credentialcan sit with a spoiling message on EACH side of it, and every whole, prefix and suffix
reading carries at least one of those frames, where the anchor classes reject the match. A
rotation of model text makes both frames ordinary rather than crafted -- the splitter rstrips
each chunk, so an alphanumeric edge is the common case. A window of at most
_INTERIOR_RUN_PIECESconsecutive messages is slid across the interior, which is a linearnumber of readings over bounded-size strings. Raised by the GPT 5.6 review as F1 and upheld
fenced. The docstring's "linear" claim is corrected in the same pass: the reading COUNT is
linear, the bytes copied are not, because a prefix and a suffix are rebuilt at each boundary.
discord/renderer.py:_seal_current's own split now passesredactor=_redact_all, astelegram/renderer.pyhas all along, at both call sites. That is the last cut before thewire with no rotation behind it -- and a buffer the rotation WITHHELD as unsafe is parked
whole and arrives there over the cap, so the withhold routed text TO the one ungraded cut
rather than away from it. Raised by the Opus 5 review as a BLOCK, and it closes discord: _seal_current re-splits an over-cap payload with no redactor, so that cut is graded by nothing #14587.
telegram/renderer.py: the upload-hold branch grades its prefix as a sequence beforesealing it. That branch keeps the image reference and everything after it in the live tail,
seals every chunk before it and returns -- ahead of the length path's own grade. Both
readings that did run are blind to one shape: the splitter reads the RAW pieces, where a
horizontal rule still stands between two credential fragments, and the seam repair reads the
delivered form but against ONE predecessor. A key split across three pieces by rules was
clean in both and flush on screen. The prefix is now carved when it severs, and withheld
whole when no safe cut exists. Raised by the GPT 5.6 review as F1 on this head and upheld
fenced under Opus adjudication.
discord/renderer.py: the rotation re-grades the held pair before assigning it. Theoffset search grades the source, but the rotation ships the source's remainder plus the held
image reference. An image reference starting at or before the budget makes the source
shorter than the budget, so the search early-returns the whole string and the re-assignment
hands back the exact pair the gate had just refused, ungraded. Raised by the Opus 5 review
as a BLOCK on this head.
Grading both forms is the second defect this fixes, in my own first design. Trimming
reveals a join that whitespace kept apart, and equally conceals one whose pattern needs
that whitespace:
-----BEGINbesideRSA PRIVATE KEY-----reads clean once trimmed andships an intact PEM anchor. Three of nine straddle shapes failed a delivered-only rule. The
old docstring claim that more trimming is always stricter was false and is corrected.
One boundary is deliberately left ungraded: Telegram's held image tail. It begins at the
ref span, so it always starts
![, and!survives canonicalising between the sealed chunkand anything the tail can contribute -- five shapes measured, every canonical join reading
AKIAIOSF!.... A gate there is unreachable, so it was removed and the reason is a comment atthat branch so nobody re-adds it.
Backwards compatibility
Compatible. The both-form grading arrives as an optional parameter whose default is the
identity transform, pinned by
test_the_default_is_identity, so every existing caller keepsits current behaviour. No public name is renamed or removed, and no input main accepts today
is rejected.
Tests
pytest test/test_display_split_safety.py -n 0 -p no:randomlypytest test/test_telegram.py::TestRotationSeamCredentialSafety test/test_discord.py::TestRotationSeamCredentialSafety -n 0 -p no:randomlypytest test/test_discord.py::TestRotationSplitting -n 0 -p no:randomlypytest 'test/test_channel_table_rendering.py::TestDiscordStreaming::test_a_still_arriving_table_is_not_frozen_half_built' test/test_discord_render_config.py::TestTurnFooter -n 0 -p no:randomlypytest test/test_display_split_safety.py test/test_discord.py::TestSeversACredential test/test_discord.py::TestRotationSplitting test/test_discord.py::TestRotationSeamCredentialSafety -n 0 -p no:randomlypytest test/test_split_credential_boundary.py -n 0 -p no:randomlypytest test/test_telegram.py::TestRotationSeamCredentialSafety test/test_wecom.py -k seam -n 0 -p no:randomlypytest test/test_telegram.py::TestSplitText test/test_telegram.py::TestTableAwareSplitting test/test_telegram.py::TestRotationSeamCredentialSafety test/test_display_split_safety.py -n 0 -p no:randomlypytest test/test_display_split_safety.py test/test_split_credential_boundary.py test/test_discord.py::TestRotationSplitting test/test_discord.py::TestRedactionNotice test/test_discord.py::TestRotationSeamCredentialSafety test/test_telegram.py::TestRotationSeamCredentialSafety test/test_telegram.py::TestSplitText -n 0 -p no:randomlypytest test/test_discord.py -k pathological -n 0 -p no:randomlyWhat the new cases lock in: a key severed between two pieces is caught; one spanning three
pieces is caught though no adjacent pair shows it; a markup span covering a whole piece is
caught; the pieces are graded as delivered, not as split; a raw-only grade accepts an offset
the reader can rejoin, and the delivered grade moves that offset back; a rule between the
halves hides the key from a pre-split scan but not from this one; an innocent body still
rotates; a safe head that renders over the cap is shrunk rather than abandoned; a retained
buffer holds only source text; no piece a presentation fallback retains exceeds the budget; a
key finished across a pair is caught when the message after it opens on a letter; a held image
reference at or before the budget does not let a refused pair through; a prefix sealed whole by
the upload-hold branch is graded as a sequence, so three fragments separated by rules do not
reach the screen flush.
Every new pin was proven to see the regression it guards: each reviewer's exact pre-fix code
was restored in isolation and the pin failed, then the file was restored to a matching
sha256. Two of them needed their fixture corrected before that proof held, and bothcorrections are the same lesson -- a fixture must be measured, not assumed:
the raw grade and severing to the delivered one. With SHORT rules the last two fragments pack
into one chunk, where the blank line between them survives canonicalising and the hazard is
never exercised.
open-ended tail just absorbs the alphanumeric frame and matches anyway, so a suffix reading
catches it and the window proves nothing. With the fixed-length token, no pre-existing
reading hits it and only the interior window does.
every boundary is inside the run and no redactor can help -- that case is channels: the final seal's cut has no safe boundary when the over-cap text is one unbreakable run #14644, not this
fix, and using it made the pin fail against a correct fix.
The third row matters for the board: those lanes were red on shards 3 and 6 because their
fakes lacked
edit_message_visibility. Dropping the superseded layer drops that verb, so thelanes clear with no edit to those files -- they are not in this diff.
Manual verification
N/A -- unit coverage is sufficient. Every boundary this touches is reached by a renderer test
that drives the real rotation path against a fake client and asserts on the frames delivered,
so there is no integration seam the tests cannot observe.
Related Issues
Closes #12293
Closes #14587
Pattern harvest
Rule candidate: review-prompt (and agents-md)
Pattern: model text cut into pieces that are then scanned or redacted individually, with
nothing grading the boundary. The scan is sound per piece and unsound across the pair, so the
defect is invisible to every test that reads one message.
This is the third instance of the class and the second fix for it. #11727 found it in WeCom's
_push, where the cut was a plainbody[:room]slice; this one is in the two renderers'_rotate_on_length, where the cut comes from a markdown splitter. The cut's shape differedeach time, which is why the rule should name the property and not the syntax: any path that
turns one piece of model text into more than one separately-scanned delivery must grade the
boundary.
A second, narrower candidate falls out of the fix: a boundary grader that reads only ONE form
of the text is unsound in both directions. Grading the delivered form alone misses a join the
raw form shows, and grading the raw form alone misses a join trimming creates. Either way the
grader looks correct and passes its own tests.
A third, from the review rounds on this branch: a grader that reads a boundary in ONE
direction only inherits whatever the far end of its reading window contains. Every
forward-only reading here ran to the end of the list, so it always carried the next message's
first character, and a pattern that anchors on a character class was decided by that
character rather than by the boundary. A boundary reader must be read from both sides, and a
gate that refuses a pair must be the same gate the code re-consults before shipping that pair.
Checklist
docs/system-specs/modules/messaging.md)