Skip to content

fix(channels): record the reasoning note as the seam it opens - #14088

Merged
bolichen97 merged 1 commit into
mainfrom
fix/discord-thinking-seam-and-callsite-exemption-13743
Sep 30, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
fix/discord-thinking-seam-and-callsite-exemption-13743

Conversation

@chenmingwei23

@chenmingwei23 chenmingwei23 commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Close the remaining channel-delivery paths where a credential is invisible in any one message yet whole on the reader's screen because two adjacent messages read as one block of text.

A credential can pass every per-message scan and still be readable down the screen: two halves of a key, one per delivered message, rejoin visually once the platform drops the whitespace at each message's edge. This branch closes the last places on the channel delivery paths where that still happens.

  1. Discord's reasoning note opens a seam nobody grades. The note (discord.show_thinking) is posted as its own message, then the answer's first live frame grades its seam against the message that came before the reasoning. A note whose preview ends in a credential prefix is completed by the answer's leading characters. The preview is cut after redaction, which is exactly how a trailing prefix survives a pass that never saw a whole key.
  2. The universal splitter-grade had a hole a whole module could hide in. Every channel delivery path is meant to cut through a redactor so a key cannot straddle a message boundary, but nothing enforced that a new delivery path joined the check. A module the guard's curated list never reached was not merely unchecked — it was invisible.
  3. A test double went stale. discord/session_resume.py passes a redactor to the splitter; test_discord_sessions.py's double did not accept the keyword, so the shard failed with a TypeError.
  4. The byte-delivery path graded no seam of its own. On the byte-capped channels (Webex, WeCom) a key straddling a byte-splitter boundary shipped whole across two messages, because the byte branch fed the raw splitter straight into the bounder.

Why it matters

For (1) the consequence is not recoverable: both bubbles are already delivered when the key becomes readable, so nothing later can take it back, and the reader who scrolls past sees a working credential in a channel the operator believed was redacted. For (2) the harm is in the future: a guard that exists to catch the next unguarded delivery path could not see a path its list never named, so the protection this series added reads as present while being off for a whole module.

Not a goal

  • Generalising the standalone-send enumeration to the other channels' send paths. It is Discord-only here, because Discord is where the defect was found and where the send paths were read one by one; generalising needs each channel's sends read the same way rather than a pattern copied across.

What changed (motivation → approach → change)

The reasoning note records what it delivered. _flush_thinking records the exact subtext it sent, once the send confirms, so the answer's first frame grades against the message the reader is actually looking at. It is not graded on the way in, deliberately: the thought-bubble emoji prefix is unconditional and survives rendering, so it separates the note from the message above in the only form the reader sees. Grading there would model an adjacency that does not exist and give up a leading span for a key the emoji already broke.

A late note no longer loses its record to a rotation. When the note is posted below a still-live answer bubble, _flush_thinking now clears the live message id (_stream_mid) after recording the note. Without that, the next _rotate_on_length → _seal_current → _land_sealed edits the older bubble and records THAT as _sent_tail, displacing the note as the predecessor and leaving the note → next-message seam ungraded. Clearing the id forces the next seal down the send path, so the message that actually lands below the note is the one recorded.

The seal grades against the right neighbour when an edit fails. A failed live edit is classified: a transient failure (429/5xx) leaves the bubble on screen, so the fallback grades against it (_sent_tail); a deleted bubble (a 404 — moderator/automod removed it) means the on-screen neighbour is the message above it (_bubble_above), so the fallback grades against that instead. The client returns the classified outcome (EDIT_OK / EDIT_GONE / EDIT_FAILED) rather than a bare boolean, so the renderer can pick the predecessor the reader actually sees, and the record is only written when the send or edit reports success.

The byte-delivery path grades its own seams. messaging.renderer.chunk_for_transport's byte branch fed split_markdown_bytes (which takes no redactor) straight into bounded_for_delivery, and bounded_for_delivery grades only the slices it cuts inside a chunk — never the byte splitter's own inter-chunk seams. On the two byte-capped channels (Webex, WeCom) a credential straddling a byte-splitter boundary shipped whole across two messages. It now runs repaired_for_delivery over the split sequence before bounding, re-splitting a repair through the same byte splitter — the guarantee the character branch already gets by threading the redactor into its splitter — and shrinks through the real byte floor with a fail-closed terminal grade so an exhausted search never returns an unsafe sequence.

The population that must be graded is read off the tree, not curated. The enforcement test derives its module population by walking src/kiro_crew (SRC.rglob("*.py")) and collecting every module that calls a redactor-accepting splitter — a module joins the moment it calls one, so a new delivery path is enforced without anyone remembering to add it to a list. messaging/split.py is skipped because it defines those functions. Then the check is universal, with no per-module exemptions: every splitter call in every collected module must either pass redactor= or cut already-redacted text (the output of repaired_for_delivery / redact_for_display, which carries the same seam guarantee). A companion assertion fails if the walk stops reaching the known delivery channels, so a derivation that silently finds too little cannot pass quietly.

Backwards compatibility

Compatible: no field, validator, type, or key changes — the diff threads an existing redactor/grade through delivery paths that already existed, clears an internal streaming id earlier, and adds a classified-edit return the renderer reads. Nothing that works today stops working.

Tests

Automated tests added/updated:

  • The reasoning note's record and its order against the send; the failed-edit classification (a transient failure grades against the still-visible bubble, a deleted bubble grades against the neighbour above) and the client's EDIT_OK/EDIT_GONE/EDIT_FAILED outcome on 200/404/503; the session-resume double now asserts the redactor it receives.
  • TestEveryDeliveryPathIsEnumerated: the module population is derived by walking src/kiro_crew, and every splitter call in every collected module must pass a redactor (or cut already-redacted text) — universal, no exceptions. A companion assertion fails if the walk stops reaching the known delivery channels, so an under-reaching derivation cannot pass quietly. An unguarded call in any collected module fails the parametrized check.
  • TestChunkForTransportGradesTheByteSeam: chunk_for_transport closes a key straddling a byte-splitter seam on a byte-capped channel, with an unguarded control (split_markdown_bytes alone) that leaks — locking in the byte-path grade, including that the byte path never returns a rejoining sequence even when the budget search exhausts.

Local verification on the resolved tree (worktree, PYTHONPATH=src): the credential-boundary suite (incl. the derived enumeration and the byte-seam class), test_discord.py, test_discord_sessions.py, test_discord_render_config.py, test_channel_table_rendering.py, test_discord_rate_limits.py → all green (830 passed across the touched sets), plus black / isort / flake8 / mypy clean.

Manual verification

N/A — unit coverage is sufficient; the seam guarantees are exercised by the credential-boundary suite with explicit rejoin controls.

Related Issues

Refs #13743. Predecessor #13984 (merged); supersedes #14047.

Pattern harvest

Rule candidate: when a guard is added to "the paths that do X", enumerate the paths by a property of the code (derive the population from the tree) rather than by a curated list in the diff — a path nobody adds to a curated list is not merely unchecked, it is invisible, and the paths most likely to be forgotten are the new ones. Make the derivation itself fail if it stops reaching the paths you already know deliver.

Rule candidate: an edit that can fail two different ways (transient vs the target being gone) must return which way it failed, not a bare boolean — the caller's correct recovery differs by case, and a collapsed boolean makes it grade against the wrong neighbour.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (fix: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable) — docs/system-specs/modules/messaging.md
  • No secrets, credentials, or internal references in the diff

@chenmingwei23
chenmingwei23 requested review from a team and bolichen97 September 26, 2026 02:31
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge labels Sep 26, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/discord-thinking-seam-and-callsite-exemption-13743 branch from 25f00d7 to 95855f7 Compare September 28, 2026 05:48
@chenmingwei23
chenmingwei23 requested a review from a team as a code owner September 28, 2026 05:48
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge labels Sep 28, 2026
@github-actions

github-actions Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — 🟡 CONCERNS

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

Design-Verdict: CONCERNS

One repair-resistant byte seam halves the global budget, so a long Webex/WeCom reply can ship shredded into many tiny messages for one bad span.

Watch

The byte branch's ladder ("Shrink the byte budget and re-split until the delivered sequence rejoins no key") re-cuts the entire body at the halved budget: a mid-ladder success delivers every chunk at that shrunken size (bounded_for_delivery never re-merges), and each halving re-splits and re-grades the whole body — so one position-dependent straddle (the F7 heading shape this PR itself introduces via _HEADING_MARKER) turns a long reply into a flood of small messages plus repeated whole-body grades on the worker thread. The description states the fail-closed floor but never this whole-reply degradation mode. A span-local repair (neutralize the piece-leading marker in the body, the way _made_collapse_clean gives up only the hiding whitespace) would keep the original budget for everything else.
Clears when: the ladder repairs or neutralizes the offending span instead of halving the global budget, or a stated bound shows the shrunken-budget delivery stays at an acceptable message count for realistic reply sizes.

Suggestions

  • Consolidate _sent_tail / _bubble_above / _pending_note_tail and their write-ordering rules into one seam-ledger object with fresh_send_landed / edit_landed / note_posted transitions — the B1→F1→F1-on-F1→F3 fix lineage in the tests shows the invariants have outgrown fields scattered across four methods, and the AST single-writer test would pin the type instead.

[DESIGN-REVIEWED] 392f457

Description read

[DESCRIPTION-READ] 9fe9ab44f24e68297007d349a754a652dd99a8478e82295c8ef5b83858893165

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 .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ✅ no blocking findings

GPT 5.6 completed its review of 392f45741b5cea11d22748d03ff4049920dd7405 and found no blocking issues.

This comment is updated in place on each push.

Review details

FINDING -- src/kiro_crew/messaging/renderer.py:189 -- function-local "from kiro_crew.messaging.split import" defers required imports until delivery runs -> Fix: move both imports to module scope. (origin: validation)
[GPT-REVIEWED] 392f457

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

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 28, 2026
@github-actions

github-actions Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5) — 🟡 CONCERNS

Premise-level review of 392f45741b5cea11d22748d03ff4049920dd7405 — 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: CONCERNS

Switching the seal to the classified edit verb strands DiscordClient.edit_message_with_files at zero production callers — a second spelling left to diverge.

Not justified as shipped

  • Item 4 — duplicate of src/kiro_crew/discord/client.py::edit_message_with_files_outcome: the new classified verb took over the only caller (_land_sealed, discord/renderer.py:1453); grepping edit_message_with_files across src/ finds 0 remaining callers of the bool verb — only its definition (client.py:1039) and docstring cross-references — so the capability now ships in two spellings, one dead.
    Subtraction: delete DiscordClient.edit_message_with_files (client.py:1039-1055) and drop the test fakes' bool-delegation shim with it.
    Clears when: the bool method is deleted, or a production caller of it is named.

What this change ships

Inventory (10 items) — 9 justified

Intent: FIX — close the remaining channel-delivery seams where a credential invisible in any single message reads whole across two adjacent messages on screen.

  1. Discord's reasoning note becomes the recorded predecessor; the streamed answer seals before a mid-turn note posts — justified
  2. Edits and the final seal of a live Discord bubble grade against the message actually above it — justified
  3. A Discord seal that fails to land now reports failure, so the segment is retried, not dropped — justified
  4. Discord edit failures classified ok/gone/failed so a fallback post grades against the visible neighbour — duplicate of discord/client.py::edit_message_with_files_outcome (the superseded bool verb is kept at zero callers)
  5. Byte-capped channels (Webex, WeCom) via the shared chunker no longer ship a key across a byte-split seam — justified
  6. The shared chunker's char path grades seams, hard-caps oversized fence chunks, and accepts the caller's context-aware redactor — justified
  7. Dashboard, Slack, and Feishu send legs run the now-heavier split off the event loop — justified
  8. Heading, subtext, and blockquote markers collapse in the canonical display reading, catching keys split around them on every channel — justified
  9. The enforcement test derives its module population by walking the tree instead of a curated list, with an under-reach floor — justified
  10. WeCom's redaction notice adds repair-added placeholders instead of overwriting, and Slack ledgers continuation chunks — rides along: notice-count accuracy fixes, not seam closures; harm named (notice under-reports placeholders shipped)

[FIRST-PRINCIPLES-REVIEWED] 392f457

Description read

[DESCRIPTION-READ] 1c48d6fa8eabdd2058bea2d27f949763cbb3097acfc5af17394968465fca3379

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@chenmingwei23
chenmingwei23 force-pushed the fix/discord-thinking-seam-and-callsite-exemption-13743 branch from 95855f7 to 6838ebd Compare September 28, 2026 06:04
@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: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 28, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/discord-thinking-seam-and-callsite-exemption-13743 branch 2 times, most recently from 167ef87 to 2d75f6f Compare September 28, 2026 06:36
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 28, 2026
@github-actions

github-actions Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5 Review — ✅ no blocking findings

Reviewed 392f45741b5cea11d22748d03ff4049920dd7405 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 392f457

Verdict parsed from the review's SHA-scoped output markers for commit 392f45741b5cea11d22748d03ff4049920dd7405.

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

@chenmingwei23
chenmingwei23 force-pushed the fix/discord-thinking-seam-and-callsite-exemption-13743 branch from 2d75f6f to 4b656a8 Compare September 28, 2026 07:25
@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Sep 28, 2026
@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 28, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/discord-thinking-seam-and-callsite-exemption-13743 branch from 2b56cfd to 5829a18 Compare September 28, 2026 09:17
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Sep 28, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/discord-thinking-seam-and-callsite-exemption-13743 branch 2 times, most recently from a3e0a9b to bb1420a Compare September 28, 2026 09:49
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention labels Sep 28, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/discord-thinking-seam-and-callsite-exemption-13743 branch from bb1420a to 8f7fc95 Compare September 28, 2026 22:16
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: passed Eligible automated validation passed for the current revision labels Sep 28, 2026
iamwhatever
iamwhatever previously approved these changes Sep 28, 2026
@iamwhatever
iamwhatever enabled auto-merge (squash) September 28, 2026 22:54
@chenmingwei23
chenmingwei23 force-pushed the fix/discord-thinking-seam-and-callsite-exemption-13743 branch 3 times, most recently from 7763ab1 to 87b6271 Compare September 29, 2026 00:51
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 29, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/discord-thinking-seam-and-callsite-exemption-13743 branch from 87b6271 to 3541d53 Compare September 29, 2026 01:21
B1 (Opus 5): keep the open bubble's predecessor in _bubble_above (which
_record_sent does not clobber) and grade the edit, seal and fallback paths
against it, so an edit or the final seal of the bubble no longer restores a
credential span the fresh-send grade repaired.

B2 (Opus 5): drop redact_for_display/_display_safe from guaranteed_by_call
(they do not collapse whitespace, so AKIA\nIOSFODNN survives) and route the
WhatsApp stable branch and teams _replay_preview through repaired_for_delivery
before the no-redactor cut. The universal splitter gate now recognises the
grade-then-resplit idiom (a measurement split fed to repaired_for_delivery,
and a delivery split of a grade-vouched body).

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed on behalf of the maintainers (sweep 2026-09-30): readiness passed, required checks green on 392f457, no blocking review threads, security posture unchanged. Approving and merging.

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.

3 participants