Repository navigation
fix(channels): seal fences across a credential-graded rotation cut - #25701
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks. Every item comes from issue #14645. It reuses the splitter's existing What this change shipsInventory (6 items) — 6 justifiedIntent: when a credential-graded rotation cut lands inside a fenced code block, the code should still render as code on Telegram and Discord, and Discord should not upload a file the model only quoted as code. This is a FIX.
[FIRST-PRINCIPLES-REVIEWED] ef13174 Description read[DESCRIPTION-READ] 0d09cba3849e9c9673ad279474df25aac0a205c419fdde5dc5e2353b570cbb6e That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks. Every re-cut site now repairs fences through one shared helper and re-grades the exact pieces it sends. The upload change only takes uploads away, and it is documented. Notes
[DESIGN-REVIEWED] ef13174 Description read[DESCRIPTION-READ] beba7d37448b89e0ff5a5d077d65687d93f98382be08c993cd37b5b161689dd2 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.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
bolichen97
left a comment
There was a problem hiding this comment.
Thanks for this. The shared repair helper is the right shape, and every re-cut path now re-grades the repaired pieces before sending, which keeps the credential guard intact. One blocking problem in rebalance_fenced_cuts itself, and it is the same root cause as the GPT lane finding.
Verified at 2340291: the 11 new tests pass, and the related renderer and split credential suites (test_discord_renderer.py, test_telegram_renderer*.py, test_split_credential_boundary*.py) pass locally, 359 passed. The red mypy job reports _frame_parents errors in files this PR does not touch, which is also red on main.
Blocking:
-
A cut that lands inside a delimiter line breaks the fence it is meant to seal. The helper reads fence state only from finished lines, so the partial line on the head side is treated as body. But
safe_split_offsetsamples offsets atlimit - 2^kwith no line alignment, so a cut through a fence line is reachable. Two cases, both reproduced against the helper directly:- Cut through a closer,
"```\ncode\n```\nafter prose\n"cut two characters into the closer. The head becomes"```\ncode\n``\n```"(fine), but the tail becomes"```\n\nafter prose\n"`: the original closer is gone, so the reopened block never closes and the prose after it renders as code. On main this tail renders as prose, so this case is a regression. - Cut after the backticks of a nested
```pythonbody line (the GPT lane case). The partial```reads as a closer in the head, so the appended closer opens a new block, and the tail showspythonwithout its backticks.
Suggestion: when the partial line at a cut is a prefix of a fence delimiter, or would become one, move the cut back to the start of that line (or treat that cut as unsafe so the caller withholds), then rebalance and grade again. A test for each case above would pin it.
- Cut through a closer,
Not blocking:
- After any re-cut, Discord marks the whole segment upload-ineligible, including a held image outside every fence. That is a safe loss, and the Design lane already asked for the spec line to say it covers the whole segment.
- The WeCom renderer (
wecom/renderer.py) also cutsbody[: safe_split_offset(...)]as a raw slice. A line in the sibling sweep saying whether it can land inside a fence would close that question.
2340291 to
991d1ee
Compare
|
@bolichen97 thanks, both cases were real. Fixed in Blocking: a cut inside a delimiter line. New
The moved cut is a new boundary, so it goes through the same repair and the same re-grade as before, and an answer of Non-blocking:
The mypy |
When the splitter's boundary severs a key, Telegram and Discord re-cut the segment at a graded offset and send two raw source slices. A cut inside an open fence sent a head with an unmatched opener, so the code showed as prose and the next piece's closer opened a block that never closed. On Discord the upload-safety verdict also survived a boundary it was never computed for. Add rebalance_fenced_cuts to messaging/split.py: a piece that ends inside a fence gets the fence's closer and the next piece is reopened with the original opener. Every re-cut path uses it, grades the repaired pieces again and withholds when they sever, and keeps each piece within the budget. A Discord re-cut makes the segment upload-ineligible. Fixes #14645
991d1ee to
ef13174
Compare
bolichen97
left a comment
There was a problem hiding this comment.
Thanks for the update. This looks good to ship and resolves my earlier change request. I will approve once the remaining backend test jobs and the readiness signal finish green on this head.
What changed since 2340291: the new fence_line_safe_offset moves a cut that would split a fence delimiter line back to that line's start, and it runs before rebalance_fenced_cuts at all four re-cut sites (two in the Discord renderer, two in the Telegram renderer). A moved cut only shrinks the head, and every site still grades the repaired pieces with severs_a_credential before anything is sent, so the credential guard holds at the new boundary. The spec now says the Discord upload loss covers the whole segment, and the PR body explains why the WeCom bubble cut is a different path. Both earlier non-blocking notes are resolved.
Verified at ef13174:
- Range-diff against 2340291: only the helper, its four call sites, the spec line and five new tests changed.
- Both earlier failing cases, called directly: the closer case now gives a closed head and a tail whose prose renders as prose; the nested
```pythoncase keeps the inner line intact in the tail. - A randomized check over about 120,000 cuts of mixed fence texts (backtick and tilde fences, nested and indented delimiters, inline backtick runs): with the new helper, the text outside fences after repair always matches the original; without it, about 17,000 cuts broke it.
test_rotation_recut_fences.pyplus the Discord, Telegram, WeCom renderer and split suites: 941 passed locally.
bolichen97
left a comment
There was a problem hiding this comment.
Approving at head ef13174.
Our earlier change request on this PR is resolved by the current head, which our review read in full and found no blocking issues in.
Gates checked at this head: readiness label is passed, every check is green (including the Opus, GPT, Design, First Principles, UX, Security Scope and Sensitive Change review lanes), no AI lane blocks, no other reviewer has requested changes, and the branch merges cleanly into main.
This approval replaces our previous request for changes. Auto merge is pinned to this exact head commit.
Problem / Motivation
Goal: a credential-graded rotation cut that lands inside a fenced code block still sends two pieces that each render as code, and on Discord a re-cut segment uploads no file.
When the splitter's own boundary severs a key, Telegram and Discord re-cut the segment at an offset
safe_split_offsetpicks and send two raw source slices instead of the splitter's chunks. Two things go wrong when that offset falls inside an open fence:_segment_uploads_safewas computed for the splitter's boundary, not the re-cut one. Withinside a fenced block, a cut between the opener and the reference makes the reference read as real markup in the tail, so the final seal can upload a file the author wrote as code.Why it matters
The first corrupts every fenced answer long enough to rotate where a key sits near the cut. The second uploads a local file from text the model quoted as code.
Not a goal
Intended? / Repro
Intended? No. The Opus 5 review of #13494 raised both as non-blocking findings and they were deliberately left out of that PR; the splitter's own cuts already repair fences the same way.
Repro (read on current main
4efafcf60f):src/kiro_crew/telegram/renderer.py:799:chunks = [head, raw[offset:]]sends raw slices with no fence repair; the odd-fence fix-up above it ran on the splitter's chunks, which this line replaces.src/kiro_crew/discord/renderer.py:515-531:candidate_sealed = [split_source[:offset]],tail = candidate_tail, with_segment_uploads_safeleft as the earlier tier analysis set it."```python\n" + 60 code lines + "```\nAfter"over the budget, with the graded offset at line 20: the first Telegram bubble shows```pythonand the code as plain text.What changed (motivation → approach → change)
Symptom: broken fences and a stale upload verdict after a graded re-cut. Cause: the re-cut path skipped the splitter's repair and kept the splitter's verdict. Change: one shared repair, a re-grade, and a fresh verdict.
src/kiro_crew/messaging/split.py: newrebalance_fenced_cuts(pieces). For consecutive source slices, a piece that ends inside a fence gets that fence's closer on a new line, and the next piece is prefixed with the original opener line (run length and info string kept). Fence state comes from_advanceover lines finished before the cut; the last piece is never closed, since it may still be streaming.src/kiro_crew/messaging/split.py: newfence_line_safe_offset(text, offset). A cut that would split a fence delimiter line moves back to that line's start: when the part before the cut starts like a delimiter (up to three spaces, then a backtick or tilde), or a mid-line cut leaves the part after it starting like one. Every re-cut site applies it to the offsetsafe_split_offsetreturns, before the repair; the moved cut is then repaired and graded again like any other, and an answer of0withholds.src/kiro_crew/telegram/renderer.py: the main re-cut measures the repaired head against the rendered cap inside its budget loop, grades the repaired pair again withsevers_a_credential, and withholds (keeps the whole buffer) when it severs._carve_gradedrepairs its pieces, holds each to the rendered cap, and grades the sequence as before.src/kiro_crew/discord/renderer.py: the main re-cut shrinks its budget by what the repair adds, repairs head and tail (tail includes the held remainder), holds the head to the limit, and the existing re-grade reads the repaired pair. After a re-cut,_segment_uploads_safe = Falsefor the whole segment, a held image outside every fence included. The presentation-branch carve repairs its pieces, holds every piece to the limit, and also marks the segment upload-ineligible.docs/system-specs/modules/messaging.md: the rotation rule and thesplit.pyrow describe the repair and the upload rule.Security
This sits next to the credential-split guard. Every path that sends repaired pieces grades exactly those pieces again and withholds on a sever, so the added delimiter lines can never ship ungraded. Withholding keeps all text in the buffer for the next rotation or the final seal. The upload change only removes uploads.
An independent read-only review (a fresh agent that saw only this diff and the issue, asked "can a credential now be split across two messages, or leak in a new way") found no blocking findings. Its two non-blocking notes are applied: the Discord presentation carve now holds the LAST piece to the limit too, and marks the segment upload-ineligible.
Backwards compatibility
Compatible: text with no fence at the cut is sent exactly as before. A repaired pair that would sever, or would exceed the budget, is withheld, which only delays it to the final seal.
Removes nothing: no key, field or error path is removed.
Tests
test/test_rotation_recut_fences.py(new):TestFenceLineSafeOffset: a cut two characters into a closer moves to the closer line, and the repaired tail keeps the closer; a cut after a nested```pythonline's backticks moves to that line; a mid-line cut right before a backtick run moves back; an ordinary mid-line cut stays; a first-line cut can become0.TestRebalanceFencedCuts: no-op outside a fence; close and reopen inside one; a mid-line cut closes on its own line; run length and info string kept (block with an inner``` ```` line); last piece never closed; a line split by the cut opens nothing; every cut of a three-way split repaired.TestTelegramRecutInsideAFence: the re-cut is forced (first sever check true, fixed offset inside the fence); every bubble has balanced<pre>, no literal```on screen, the repaired pair is graded again; a pair the second grade rejects is withheld with the buffer intact.TestDiscordRecutInsideAFence: every frame has an even count of fence lines, the second frame reopens with```python; a re-cut segment's_segment_uploads_safeisFalse.On main the renderer tests fail (unbalanced fences, uploads flag still
True).Proof: not provable -- other: this host runs no local tests; CI runs the new tests
Manual verification
N/A: needs a live Telegram or Discord channel. Static gates run locally: black, isort, flake8 and the Fast Gate scripts. Tests run in CI.
Related Issues
Fixes #14645
Sibling sweep
Swept: git grep -n "safe_split_offset" -- src/kiro_crew
Sibling: src/kiro_crew/telegram/renderer.py (main re-cut,
_carve_graded) -- changed hereSibling: src/kiro_crew/discord/renderer.py (main re-cut, presentation carve) -- changed here
Sibling: src/kiro_crew/messaging/display_safety.py -- not affected (defines the search)
Sibling: src/kiro_crew/wecom/renderer.py -- not affected: its
safe_split_offsetcut truncates the live frame of one bubble, and the remainder goes into the next frame of the same text; it does not seal two source slices as separate messages the way the Telegram and Discord re-cut does. A fence crossing a WeCom bubble rotation is outside this issue.Pattern harvest
Not generalizable: one shared repair helper now used by every re-cut site.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
Contributed under the project's Apache-2.0 license.