Skip to content

fix(imessage): skip a break too early in the chunk when splitting - #28277

Merged
KiroCrewCaptain merged 1 commit into
mainfrom
crew/conductor/imsg-cut-ae3
Nov 2, 2026
Merged

KiroCrewCaptain merged 1 commit into
mainfrom
crew/conductor/imsg-cut-ae3

Conversation

@RohanK6

@RohanK6 RohanK6 commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A long iMessage reply that opens with a short line is sent in as few messages as fit, the way the shared splitter already sends it.

chunk_plaintext cuts at the last paragraph, line or space break in reach, however near the start. "Hi\n\n" plus a 6,000-character answer is sent as 3 messages (2, 4000, 2000) when 2 fit.

Why it matters

Every iMessage user who gets a long answer that opens with a greeting, a title or a one-word line gets a stray tiny bubble and one more message than needed.

Not a goal

  • Changing the Slack splitters, which cut at newlines with their own contract.
  • Changing how a fenced code block, emphasis or links are flattened.
  • Changing the grapheme rules of a hard cut.

What changed (motivation → approach → change)

Symptom: a short opening line becomes its own message. Cause: _preferred_cut takes any break with an index above 0. Fix: each tier gets a floor, taken from the ladder in split_markdown_safe. A paragraph break must sit at least halfway in, a line break or a space at least a quarter in. A break below its floor falls to the next tier. With no tier left, the last break is still taken when the word after it fits one chunk, so a long URL behind Open: moves whole. A word longer than any chunk is hard-cut to fill the budget.

Backwards compatibility

Compatible: same function and signature; every chunk stays within the limit and no text is lost.
Removes nothing: only where a long reply is cut moves.

Tests

test/test_imessage_plaintext.py, new class TestAnEarlyBreakDoesNotStrandTheBudget:

  • the two repros in the issue give 2 messages, not 3;
  • an early line break, space or paragraph falls through to a later break or a hard cut;
  • a word longer than a chunk fills the budget.

Guards that pass on main and on this change: a long URL behind a short lead-in moves whole; a paragraph a quarter to halfway in splits the same as split_markdown_safe; a paragraph halfway in, a line or space a quarter in, and a 9,000-character run keep their cuts.

Proof: PROVEN test/test_imessage_plaintext.py::TestAnEarlyBreakDoesNotStrandTheBudget::test_a_short_greeting_paragraph_does_not_cost_a_message, test/test_imessage_plaintext.py::TestAnEarlyBreakDoesNotStrandTheBudget::test_a_short_greeting_before_wrapped_prose_does_not_cost_a_message, test/test_imessage_plaintext.py::TestAnEarlyBreakDoesNotStrandTheBudget::test_an_early_line_break_falls_through_to_a_later_space, test/test_imessage_plaintext.py::TestAnEarlyBreakDoesNotStrandTheBudget::test_an_early_space_falls_through_to_a_hard_cut, test/test_imessage_plaintext.py::TestAnEarlyBreakDoesNotStrandTheBudget::test_an_early_paragraph_falls_through_to_a_later_line_break (head 96ae078)

Determinism: pure string functions, no clock, I/O or order. test_imessage_plaintext.py passed 5 repeats with -n0, once with -n 4, and once in a shuffled order (seed 4271). Related backend set via scripts/local-gate.py: 5988 passed, 5 skipped.

Manual verification

N/A — unit coverage sufficient: chunk_plaintext is a pure function and the tests drive it with the exact reply shapes.

Related Issues

Fixes #28275

Sibling sweep

Swept: git grep -nE "rfind(" -- "src/kiro_crew/*.py" (every break search in a splitter or truncator)
Sibling: src/kiro_crew/messaging/split.py -- not affected -- it holds the floors this change copies
Sibling: src/kiro_crew/slack/format.py:1223 -- tracked in #27600
Sibling: src/kiro_crew/slack/reply_pieces.py:76 -- tracked in #27600

Both Slack splitters have the same early-cut shape: they take the last newline (or space) in reach, however near the start. They are left for a separate follow-up PR, opened once our #27600 (open on slack/format.py) lands.
Sibling: src/kiro_crew/tips_text.py:96 -- not affected -- truncates one tip, never splits into messages

Pattern harvest

Not generalizable: the one channel splitter with its own break ladder lacked the floors of the shared ladder; the shared one has them.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

@RohanK6
RohanK6 requested review from a team and KiroCrewCaptain as code owners November 2, 2026 15:41
@RohanK6
RohanK6 requested a review from bolichen97 November 2, 2026 15:42
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 2, 2026
@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 96ae0788b5b559d2aca1a4c2850322ca957750a0 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 96ae0788b5b559d2aca1a4c2850322ca957750a0 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: this is a small fix to a pure function, it targets the real cause (tiers had no floors), and it can be reverted cleanly.

Notes

  • This is the second copy of the floor ladder from split_markdown_safe, and _BREAK_TIERS is maintained separately. If the shared ladder's floors change, the two will drift apart without any test failing except the single equality test. A follow-up could import the divisors from messaging/split.py instead of restating them.

[DESIGN-REVIEWED] 96ae078

Description read

[DESCRIPTION-READ] 1f27077f49ca313096669af1ccd9aea6a6aa7afe60f67866c3fb92b11f0070c4

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 Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 96ae0788b5b559d2aca1a4c2850322ca957750a0 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 96ae078

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 96ae0788b5b559d2aca1a4c2850322ca957750a0 false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 96ae0788b5b559d2aca1a4c2850322ca957750a0 — 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 does not.

First-Principles-Verdict: PASS

Nothing blocks: the floors fix the cut rule that caused #28275, the URL fallback keeps a cut that main already makes, and the floors match the shared splitter's.

What this change ships

Inventory (4 items) — 4 justified

Intent: a long iMessage reply that opens with a short line goes out in the fewest messages that fit. This is a FIX.

  1. A paragraph, line or space break near the start of a chunk no longer ends that chunk, so "Hi\n\n" plus a long answer goes out as 2 messages instead of 3 — justified
  2. When no break clears its floor, the last break is still used if the word after it fits in one chunk, so a long URL after "Open:" moves whole, as it does on main — justified
  3. A word longer than any chunk is hard-cut to fill the budget instead of leaving a short "Open:" bubble — justified
  4. Inside chunk_plaintext, the floors come from a three-row table (_BREAK_TIERS) and a small _word_end helper; neither is a public surface — justified

[FIRST-PRINCIPLES-REVIEWED] 96ae078

Description read

[DESCRIPTION-READ] 70574ed24edcf7cab2d3ef66730b601e836af971cc455e1bb6029788290130e3

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

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 96ae0788b5b559d2aca1a4c2850322ca957750a0 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 96ae078

Verdict parsed from the review's SHA-scoped output markers for commit 96ae0788b5b559d2aca1a4c2850322ca957750a0.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 96ae0788b5b559d2aca1a4c2850322ca957750a0 false-positive: <reason, 20 to 500 characters>

@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 Nov 2, 2026
@RohanK6
RohanK6 force-pushed the crew/conductor/imsg-cut-ae3 branch from 1fd92d8 to 96ae078 Compare November 2, 2026 18:07
@RohanK6

RohanK6 commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in #28301, which fixed the red test/test_mate_conductor_agent.py tests behind the backend and coverage failures on the last head. New head 96ae078 on main 0c3a9a6; no conflicts, related backend set 5988 passed.

@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 Nov 2, 2026
@KiroCrewCaptain
KiroCrewCaptain enabled auto-merge (squash) November 2, 2026 20:04

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Tier 1 auto-approve: fix (2 files). Criteria: no conflict, no requested changes, security path denylist clean, design-doc gate clean, security checklist all-NO, no reviewer-lane findings, readiness signal fresh for this head SHA, declared category matches the diff. Category: bug fix in iMessage plain-text chunking: a paragraph, line or space break counts only when it reaches its share of the limit, so a short lead-in no longer costs an extra message; covered by new unit tests, including parity with the shared Markdown splitter.

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.

iMessage splitter sends an extra message when a short break sits near the start

2 participants