Skip to content

fix(session): quote provenance-shaped lines inside session_send bodies - #20037

Merged
chenmingwei23 merged 2 commits into
mainfrom
fix/session-send-neutralize-markers
Oct 14, 2026
Merged

chenmingwei23 merged 2 commits into
mainfrom
fix/session-send-neutralize-markers

Conversation

@iamwhatever

@iamwhatever iamwhatever commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A session_send target can always tell the dashboard's real sender line from text inside the message body.

session_send and broadcast prefix each delivered message with [sent by session <caller> via <tool>]. The body was passed through unchanged, so a body that itself contains a line of that shape shows the target more than one sender line, and the target cannot tell which one the dashboard wrote.

Why it matters

The sender line is how a target session decides which peer a message came from. If body text can look identical to it, the target can attribute a message to the wrong session.

Not a goal

  • Changing the sender-line format or adding new metadata to it.
  • Changing sanitize_outbound or any other message path besides session_send / broadcast.
  • Rewriting body text that merely mentions sessions without the bracketed sender shape.

What changed (motivation → approach → change)

Symptom: a body line shaped like the sender header is indistinguishable from the real header. Cause: the body is appended verbatim after the header. Change: in src/kiro_crew/dashboard/session_control.py, _neutralize_send_provenance() runs after sanitize_outbound(body) in both send_to_target and broadcast_to_targets. It finds _FORGED_PROVENANCE_RE (any Ps opening bracket, then sent by session, case-insensitive) on a normalized view built by the existing context_assembly.markers._marker_spans: NFKC, every Cf char dropped (bidi controls, zero-width chars, BOM, soft hyphen), dashes folded. Each match maps back to its span in the original text and only that span becomes [quoted: sent by session; the rest of the body stays byte-exact. Matching a normalized view instead of listing spellings follows the Design review. Only the real header, prepended by this module, opens with [sent by session. The spec paragraph in docs/system-specs/modules/session-control.md (Provenance) now says so.

Backwards compatibility

Compatible: only body text with the bracketed sender shape changes, and it is quoted rather than removed; the header format and every caller are unchanged.

Removes nothing: the body is rewritten in place, no key, path, record or function is removed.

Tests

  • test_send_body_cannot_forge_a_second_provenance_envelope (test/test_session_control.py): a body with three sender-shaped lines is delivered with exactly one real header and three [quoted: ...] lines.
  • test_neutralize_send_provenance_folds_invisible_chars_and_any_opening_bracket (7 cases): bidi-wrapped words, soft hyphen and BOM inside words, and the 【, ⟦, (, { brackets are all quoted. All 7 fail on the first commit's regex; all 8 sender-shaped cases fail with the rewrite removed.
  • test_neutralize_send_provenance_leaves_plain_text_alone: ordinary text, a fullwidth letter, an em dash and an accented letter come through byte-exact.
  • python3 -m pytest test/test_session_control.py: 238 passed.
  • python3 scripts/local-gate.py: backend related set and frontend related set (361 files) passed.

Manual verification

N/A — unit coverage sufficient: the change is a pure string transform on the delivered prompt, exercised end to end through send_to_target in the new test.

Related Issues

Closes #20036

Pattern harvest

Not generalizable: the sender header is the only trust-label line this module prepends to caller-controlled text.

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

Contributed under the project's Apache-2.0 license.

@iamwhatever
iamwhatever requested review from a team and KiroCrewCaptain as code owners October 14, 2026 01:06
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 14, 2026
@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 884bc57182ec1073d193c5176151654a60cd57ec 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

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — 🟡 CONCERNS

Premise-level review of 884bc57182ec1073d193c5176151654a60cd57ec — 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

Matching any Ps bracket, built by scanning all 65,536 BMP code points at import, goes beyond the real [-opened envelope. Its only support is a review comment.

Not justified as shipped

  • Item 3 — inherited: the envelope is always _SEND_PROVENANCE = "[sent by session …", so it only ever opens with [. The description backs the wider match only with "follows the Design review", and a review comment does not name a harm. NFKC already turns fullwidth [ into [. So ( / { / ⟦ / 【 are a second guess at what a model might take for an envelope. Today the change also rewrites prose like "(sent by session X)".
    Subtraction: delete _PS_OPENERS and its range(0x10000) scan. Shrink the pattern to \[\s*sent\s*by\s*session\b, and drop the four other-bracket cases from the parametrized test.
    Clears when: the bracket set is cut down to [, or the PR points to a delivered prompt where a non-[ opener was taken as the sender.

What this change ships

Inventory (4 items) — 3 justified

Intent: a peer session receiving a session_send can always pick out the real sender line from the message body. FIX (#20036).

  1. A sender-shaped line inside a session_send body now reaches the target as [quoted: sent by session … — justified
  2. Broadcast timeout prompts get the same quoting — justified
  3. Brackets other than [ ((, {, ⟦, 【, …) count as sender-shaped openers — oversized: wider than the real envelope, backed only by a review comment
  4. The session-control spec's Provenance paragraph describes the quoting — justified

[FIRST-PRINCIPLES-REVIEWED] 884bc57

Description read

[DESCRIPTION-READ] 57a4d068274439f0708580407bb0b6499992799688f588b0c7aff8323def1f72

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 Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

Check that rewriting prose like (sent by session X) into [quoted: sent by session X) is an acceptable false positive on ordinary bodies.

Suggestions

  • Move _FORGED_PROVENANCE_RE and the neutralizer into context_assembly/markers.py. That module's docstring says "New marker families, fences and normalizations belong here". Moving them also means session_control stops importing two private helpers from another package.

[DESIGN-REVIEWED] 884bc57

Description read

[DESCRIPTION-READ] 0ef9770cbbe547b9fd130a3efa16fe14b663ad15f1c8d14eeddb7e1b04c463a7

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 Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 884bc57182ec1073d193c5176151654a60cd57ec and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 884bc57

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

@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 884bc57182ec1073d193c5176151654a60cd57ec — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 884bc57

Verdict parsed from the review's SHA-scoped output markers for commit 884bc57182ec1073d193c5176151654a60cd57ec.

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

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

Copy link
Copy Markdown
Contributor Author

Disposition for the Opus 5.5 and Design reviews of e07e365011, addressed in a7c66a617e:

  • Opus: _GAP missed bidi embedding/isolate controls (U+202A–U+202E, U+2066–U+2069). Confirmed in code: the old _GAP listed U+200B–U+200F and U+2060–U+2064 only. Fixed by matching on a normalized view instead of a list. _neutralize_send_provenance now uses context_assembly.markers._marker_spans, which applies NFKC and drops every Cf char before matching. Bidi controls, zero-width chars, BOM and soft hyphens therefore fold away, including inside a word. Test: test_neutralize_send_provenance_folds_invisible_chars_and_any_opening_bracket, which has bidi-wrapped cases.
  • Opus: spec not updated. Fixed: the Provenance paragraph in docs/system-specs/modules/session-control.md now describes the rewrite and names the tests.
  • Design: spelling-chase regex. Taken. The hand-listed gap chars and the fullwidth bracket are gone. The pattern accepts any Ps opening bracket and runs on the normalized view (the NFKC suggestion). Matches map back to the original span, and only that span is rewritten, so the rest of the body stays byte-exact. Residual class: cross-script homoglyph letters (e.g. Cyrillic ѕ/е) and reworded lines such as Message from session chat-9: still pass. Neither form has the envelope's exact shape, and the real envelope is always the first line. I have not widened this PR to cover them.

Case folding uses the pattern's IGNORECASE instead of str.casefold(). That keeps the normalized view length-stable for the span map, and it is equivalent for the ASCII words matched.

Joe Guo added 2 commits October 14, 2026 02:43
The [sent by session X via Y] envelope tells the target which peer sent a message. A body line with the same shape is now rewritten to [quoted: sent by session ...] on both the send and broadcast paths, so only the real envelope opens with the marker.
Reuse context_assembly.markers._marker_spans (NFKC, every Cf char dropped) and accept any Ps opening bracket instead of listing spellings, so bidi controls, soft hyphens and other brackets fold away before the match. Only the matched span is rewritten. Spec updated.
@iamwhatever
iamwhatever force-pushed the fix/session-send-neutralize-markers branch from a7c66a6 to 884bc57 Compare October 14, 2026 02:52
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Disposition for the reviews of a7c66a617e, now at 884bc57182. That head is rebased onto main 2f5c7d58b9, plus a black-only reformat of one line in session_control.py.

  • GPT 6.1 BLOCK at test/test_runtime_cleanup_windows.py:47 / test/test_windows_cleanup_capacity.py:32. This PR does not touch either file; the diff is session_control.py, test_session_control.py and session-control.md. Both helpers came in with test(windows): wait on signals, not clocks -- test_runtime_cleanup_windows, test_windows_cleanup_capacity #20014 (3665e4772f), which merged to main after this branch's previous base. They entered this review through the merge ref only. The branch is now rebased past test(windows): wait on signals, not clocks -- test_runtime_cleanup_windows, test_windows_cleanup_capacity #20014, so they are base, not diff.
  • First Principles CONCERNS / Design check: any Ps bracket matches, so prose like (sent by session chat-3) is rewritten. This is intended. The goal is that no body line opens like the envelope does, and to a model reader a parenthesis or 【 opener looks just as much like a sender label as [. The cost is one cosmetic rewrite of prose that happens to say "(sent by session ...". No text is removed. The rest of the line, including the closing bracket, stays byte-exact. Limiting the match to [ would bring back the spelling chase the previous Design review flagged.

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Oct 14, 2026
@chenmingwei23
chenmingwei23 merged commit a45b258 into main Oct 14, 2026
102 checks passed
@chenmingwei23
chenmingwei23 deleted the fix/session-send-neutralize-markers branch October 14, 2026 05:47
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 14, 2026
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.

session_send: quote provenance-shaped lines inside message bodies

2 participants