Skip to content

fix(discord): mark a reply part that could not be delivered - #19031

Merged
iamwhatever merged 1 commit into
kirodotdev:mainfrom
javenciu:fix/discord-lost-part-is-never-silent
Oct 11, 2026
Merged

iamwhatever merged 1 commit into
kirodotdev:mainfrom
javenciu:fix/discord-lost-part-is-never-silent

Conversation

@javenciu

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: when one part of a long Discord reply cannot be delivered, the reader is told, and the later parts still arrive.

DiscordRenderer splits a reply that outgrows Discord's message limit into several messages. Each length rotation seals one part with _seal_current(extract_uploads=False), drops that part's text, and opens the next message. Both rotation sites ignored the seal's result: the presentation branch (src/kiro_crew/discord/renderer.py, the for chunk in chunks[:-1] loop) and the source branch (the for ch in sealed loop). A part whose every send and edit failed was gone, the later parts went out below the part before it, and the reader read the two sides of the gap as one continuous answer. delivery_failed stayed False, because by its docstring it means that nothing of the reply landed.

Why it matters

A reply can lose a middle paragraph, a list item or a code block with no sign that anything is missing. Discord can refuse one part while accepting the others, for example when an AutoMod rule blocks a word that only that part contains.

Not a goal

  • The Telegram renderer has the same gap, fixed in fix(telegram): mark a reply part that could not be delivered #19028 with the same notice text.
  • Slack's continuation chunks (_render_fallback in src/kiro_crew/slack/renderer.py) are skipped on failure as a documented best-effort, and are left alone here.
  • When the final edit fails and the fallback send lands, the last live frame stays above the answer. That is the documented fallback in _land_sealed, and this change does not touch it.
  • delivery_failed keeps its meaning. A turn where some parts landed is still delivered, and the notice does not count as a delivery.

What changed

  • Root cause: the rotation in DiscordRenderer discarded _seal_current's return value. It now seals through the new _seal_rotated_part, which reads that value.
  • When a part was attempted and did not land, _seal_rotated_part logs a warning and sends LOST_PART_NOTICE, "Part of this reply may not have been delivered.", in the part's place, then the later parts continue.
  • A part with nothing to send attempts nothing (_seals_attempted does not move), so it gets no notice. A part whose edit failed and whose fallback send landed is delivered (_seal_current returns True), so it gets none either.
  • The landed notice is recorded as the next part's predecessor (_record_sent), like every other send, and it consumes a held reasoning note (_pending_note_tail), as a fresh send does in _land_sealed.
  • The wording is a choice. It matches the Telegram fix so both channels say the same thing, and reviewers can change it in one constant.
  • Tests: test/test_discord_lost_part_notice.py, three tests that drive the real DiscordRenderer through test_discord.FakeClient. The one seam is a refusal for any send or edit carrying a marker. test/test_split_credential_boundary.py lists every standalone send in the renderer, and the notice is added there as a fixed literal.

Backwards compatibility

Compatible: a reply whose parts all land is unchanged, message for message.
Removes nothing: no setting, field or event is removed.
Reader: a part that cannot be delivered now shows "Part of this reply may not have been delivered." where it would have been.

Tests

Red on origin/main d8185f1 (a throwaway detached worktree with only the new test file copied in), pytest test/test_discord_lost_part_notice.py -p no:cacheprovider -q -n 0, RC=1 in 3 of 3 runs:

FAILED test/test_discord_lost_part_notice.py::test_a_part_that_fails_for_good_is_replaced_by_a_notice - AssertionError: assert ['PART-A', 'PART-C'] == ['PART-A', 'NOTICE', 'PART-C']
==================== 1 failed, 2 passed, 1 warning in 2.65s ====================

Green on the branch, rebased onto d8185f1, the same command, RC=0 in 3 of 3 runs:

========================= 3 passed, 1 warning in 2.47s =========================

The two controls pass on both sides: a reply whose parts all land shows A, B and C with no notice, and a part whose edits fail but whose fresh send lands shows B with no notice. Discord renderer neighbours, 24 files run serially (test_discord.py, test_discord_empty_turn.py, test_discord_outbound_files.py, test_discord_render_config.py, test_discord_sessions.py, test_discord_approval_press_race_13539.py, test_channel_turns.py, test_channel_control_tag_strip.py, test_channel_table_rendering.py, test_split_credential_boundary.py and the others that name the renderer): 3167 passed, 5 skipped, exit 0, including the existing delivery_failed tests. mypy, flake8, isort, black, scripts/check_black_formatting.py, scripts/check_harness_parity.py, scripts/docs-lint.sh and the comment-history check with COMMENT_HISTORY_BASE_REF=origin/main exit 0.

Manual verification

Not run against a live Discord bot.

Related Issues

#19028 fixes the same gap in the Telegram renderer. It edits no file this change edits, and the two merge cleanly.

Open PRs that edit src/kiro_crew/discord/renderer.py, each checked with git merge-tree against this branch:

Pattern harvest

Rule candidate: a loop that drops text after handing it to a send reads the send's result.

Checklist

  • Regression test fails before the fix and passes after
  • Gates pass locally
  • No unrelated changes

A long Discord reply is split across messages. Each length rotation
seals one part and drops its text, but both rotation sites in
DiscordRenderer ignored _seal_current's result. A part whose every
send and edit failed was gone, the later parts still went out, and
nothing told the reader. delivery_failed stays False in that case,
because it means that nothing of the reply landed.

The rotation now seals through _seal_rotated_part. When a part was
attempted and did not land, it logs a warning and sends
"Part of this reply could not be delivered." in its place, then the
later parts continue. A part with nothing to send and a part whose
fallback send landed get no notice. The notice is not counted as a
delivery, so delivery_failed keeps its documented meaning.
@javenciu
javenciu requested review from a team and KiroCrewCaptain as code owners October 11, 2026 04:07
@javenciu
javenciu requested a review from CrysisDeu October 11, 2026 04:07
@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention labels Oct 11, 2026
@github-actions

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5, fork) — ⏭️ skipped

Revision 6aaabb322323baf33334f509eeb12abd72eb2b60 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Advisory — does not block merge.

@github-actions

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5, fork) — ✅ PASS

Premise-level review of 6aaabb322323baf33334f509eeb12abd72eb2b60 via the fork AI-review pipeline — 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

Check one thing: _seal_current's docstring tells callers to retry a failed segment, not drop it. Both rotation sites now drop the part and mark its place.

What this change ships

Inventory (5 items) — 5 justified

Intent: when one part of a long Discord reply fails to send, the reader is told the reply has a gap, and the later parts still arrive. This is a FIX.

  1. A rotation part that failed to send now shows "Part of this reply may not have been delivered." where it would have been — justified
  2. A warning is logged when a part is lost, and another if the notice itself fails — justified
  3. The notice is recorded as the message the next part's credential seam is checked against, and it uses up a held reasoning note — justified
  4. A new module constant, LOST_PART_NOTICE, used once in the renderer, so the wording is in one place — justified
  5. The renderer's list of standalone sends in test_split_credential_boundary.py now names _seal_rotated_part — justified

[FIRST-PRINCIPLES-REVIEWED] 6aaabb3

Description read

[DESCRIPTION-READ] 11991ade09f729331df52e11998733a2e18941940cf2d801fe83e115ad6bda50

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.

@github-actions

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5, fork) — ✅ PASS

Design-level review of 6aaabb322323baf33334f509eeb12abd72eb2b60 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Not run against a live Discord bot. Check that an AutoMod-blocked part comes back as a failed send (None or an exception), so the notice actually fires.

[DESIGN-REVIEWED] 6aaabb3

Description read

[DESCRIPTION-READ] a0760049e384997c378ba71eee2c0767e0e3ae5189c17eb9a58fabe8359256db

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

Copy link
Copy Markdown
Contributor

GPT 6.1 Review (fork) — ✅ no blocking findings

Reviewed 6aaabb322323baf33334f509eeb12abd72eb2b60 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 6aaabb3

@github-actions

Copy link
Copy Markdown
Contributor

Opus 5.5 Review (fork) — ✅ no blocking findings

Reviewed 6aaabb322323baf33334f509eeb12abd72eb2b60 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 6aaabb3

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Oct 11, 2026

@iamwhatever iamwhatever 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.

Both length-rotation loops in DiscordRenderer._rotate_on_length used to ignore _seal_current's result. A part whose sends and edits all failed vanished, and the parts around the gap read as one continuous answer. The new _seal_rotated_part (discord/renderer.py) reads that result and sends a fixed LOST_PART_NOTICE in the part's place, which fixes the root cause. I read _seal_current and _land_sealed at head 6aaabb3 to check the edge cases. A part with nothing to send returns False without incrementing _seals_attempted, so it gets no notice. A failed edit whose fallback send lands returns True, so it gets none either. A split part where only some chunks landed returns False and gets the notice, which the "may not have been" wording covers. The notice is a fixed literal, so it cannot rebuild a credential across the seam. It is recorded as the next part's predecessor and consumes a held reasoning note, consistent with every other send. A failed notice send is caught and logged. delivery_failed keeps its meaning, because the notice does not count as a landed seal. The new test is red on main and green here. It has controls for the all-landed and fallback-landed cases, and the credential-boundary inventory names the new send. All lanes PASS, checks are green, and no change request is open. — crew-pr-reviewer (deep re-check)

@iamwhatever
iamwhatever enabled auto-merge (squash) October 11, 2026 06:05
@iamwhatever
iamwhatever merged commit eb3222f into kirodotdev:main Oct 11, 2026
103 checks passed
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants