Skip to content

feat: hand a channel agent the whole text of a long attachment - #35086

Merged
bolichen97 merged 1 commit into
mainfrom
fix/32148-channel-text-handover
Nov 12, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
fix/32148-channel-text-handover

Conversation

@bolichen97

@bolichen97 bolichen97 commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: An agent that gets a text file or document on a channel too long for its prompt can read the whole text, and is told how much the prompt left out.

A text file or document sent on a channel (Slack, Feishu, Telegram, Discord, ...) is cut at 50 KB with a bare [… truncated], and its downloaded file is deleted. The agent cannot tell how much is missing and cannot read the rest, so it answers about a long CSV, log or PDF as if it had the whole file. The same file uploaded in the dashboard reaches the agent as a path it can read.

Why it matters

Anyone who sends a long file on a channel gets answers built from its first 50 KB only, with nothing telling either side that the rest was never seen.

Not a goal

  • Accepting text files above 512 KB; they stay refused, and that limit is still open on the issue.
  • Changing the inline limit, any default or setting, or adding a setting or a prompt.
  • Changing dashboard uploads or how a dashboard document reaches the agent.
  • Changing what an attachment that fits the inline limit looks like.

What changed (motivation → approach → change)

The agent needs the rest of a cut file, and an agent that never opens files must not lose what it gets now. So the inline part stays as it is and a readable copy is added beside it.

Attachment's redacted text In the prompt For the agent's tools
fits max_text_inject the whole text, unchanged nothing kept
longer the same first max_text_inject characters, then [… truncated: N of M characters of text shown] and [Its whole text is in <path> until this turn ends] the whole redacted text as a temporary .txt

In messaging/attachments.py, the copy is a new temporary .txt holding the redacted text, created and written through its own file descriptor in one call off the event loop, so the gateway never writes through a path an agent could swap for a link. The download is deleted as before, so the raw bytes are never kept, and a document's copy is its extracted text. The copy goes into IngestResult.file_paths, so its path is listed with the message like any other attached file, and every channel's existing temp cleanup deletes it after the turn; a turn cancelled while the copy is still being written deletes it once that write finishes. If the copy cannot be stored, the block keeps the size marker alone.

The messaging and slack-gateway specs, the Telegram max_text_inject_kb row in src/kiro_crew/docs/telegram-integration.md, the config spec's comment for that key, the slack/files.py docstrings and a slack/events.py comment say this, and docs/decisions/ records the decision.

Backwards compatibility

Compatible: an attachment that fits the limit is byte-identical; a longer one keeps the same inline characters, and only the marker text and the copy's path (listed with the message and named in the block) differ. Telegram's max_text_inject_kb keeps its default and range but now bounds only the inlined part: past it, the agent can read the rest from the copy.

Removes nothing: nothing that is accepted, shown or kept today is refused, hidden or deleted.

Tests

  • test_messaging_attachments.py::test_a_cut_attachment_hands_over_its_whole_redacted_text (text and document): the prompt keeps the first characters with the size marker, the .txt copy holds the whole redacted text with the token gone, the download is deleted, and the copy is in the turn's temp paths.
  • test_messaging_attachments.py::test_an_attachment_that_fits_is_inlined_whole_and_nothing_is_kept: under the limit the block is unchanged and no file is kept.
  • test_telegram_attachments.py::TestTextInjectLimit: the exact marker for the default and the 1 KiB floor, and the path line only on a cut.
  • test_a_copy_that_cannot_be_stored_leaves_the_marker_alone: a failed copy keeps the inline part and marker, adds no rejection and leaves no file.
  • test_a_link_planted_at_the_download_after_it_is_read_is_never_written_through: a symlink swapped in for the download between the read and the copy leaves its target untouched, and the copy is a regular .txt with the whole text.
  • test_a_cancel_while_the_copy_is_written_leaves_no_copy_behind: a turn cancelled mid-write leaves no file behind once the write finishes.
  • test_text_is_truncated and test_slack_files.py::test_text_content_truncated delete the copy they now receive.

The 41 test files that import the changed modules: 2079 passed, 5 skipped. The eleven tests this diff adds or changes: 10 repeats at -n0, one shuffled order and one run at -n 4, all passed.

Manual verification

Ran ingest_attachments on a 406 KB CSV with a planted ghp_ token through the real reader: the prompt was 51,499 characters ending 51200 of 406342 characters of text shown] plus the path line; the .txt copy held all 406,342 characters and every row, without the token; cleanup(result.temp_paths) deleted it.

Screenshots / video

N/A: no frontend file changes.

Related Issues

Part of #32148

Sibling sweep

Siblings: none -- a feature PR, there is no defect to sweep for.

Pattern harvest

Not generalizable: a feature PR, no defect is fixed.

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

@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 48b2609aeaf01159c5ac6e19608219795a22ec2d 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 11, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

Nothing blocks: the copy goes through the same file_paths → temp_paths → cleanup path that opaque files already use in every channel caller, and text that fits the limit is unchanged.

Notes

  • The agent can only read the copy if its sandbox can see the temp dir. Opaque VIDEO files already depend on that today, so this adds no new reach, but the [Its whole text is in <path>] line becomes useful only where that holds.

[DESIGN-REVIEWED] 48b2609

Description read

[DESCRIPTION-READ] 2f1e9d941a0eb57133657a2ee249afa7c0a9653903ebee244ae0051a8d09315d

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 11, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 48b2609aeaf01159c5ac6e19608219795a22ec2d — 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 to check.

What this change ships

Inventory (7 items) — 7 justified

Intent: let an agent on a channel read all of a text file or document that is too long for its prompt, and tell it how much the prompt left out. This is an ADDITION.

  1. The cut marker now says how many characters were shown out of how many — justified
  2. A cut attachment's whole redacted text is given to the agent as a temporary .txt for the turn — justified
  3. The block names the copy's path, and the path is listed with the message — justified
  4. If the turn is cancelled while the copy is being written, the copy is deleted once the write finishes — justified
  5. If the copy cannot be saved, the block keeps only the size marker — justified
  6. Telegram's max_text_inject_kb now limits only the part put in the prompt; its docs and the config spec say so — justified
  7. A decision entry records the maintainer's ruling from issue Channel text and document attachments: refused above 512 KB and cut at 50 KB with no path, unlike dashboard uploads #32148 — justified

[FIRST-PRINCIPLES-REVIEWED] 48b2609

Description read

[DESCRIPTION-READ] 1001747d7094cfb165d8aa8b4984de9bf2b6317314857ec42ac34cf6bf168bea

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 11, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 48b2609aeaf01159c5ac6e19608219795a22ec2d — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 48b2609

Verdict parsed from the review's SHA-scoped output markers for commit 48b2609aeaf01159c5ac6e19608219795a22ec2d.

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

@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 48b2609aeaf01159c5ac6e19608219795a22ec2d and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 48b2609

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

@KiroCrewCaptain

KiroCrewCaptain commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

Code change approver recommendation: Approve

Why: the decider estimates a 12% chance that this change introduces a defect, within the 12% limit for approving on its own, and every check passes.

This PR keeps the inline part of a long channel text file or document, says in the cut marker how much was shown, and writes the whole redacted text to a new temporary .txt (created with mkstemp and written through its own file handle) listed in IngestResult.file_paths. I checked every caller of ingest_attachments (Slack, Telegram, Discord, Feishu, WhatsApp, WeCom, Weixin, Teams, Webex): each already deletes temp_paths after the turn, Slack's queue path included, so the copy follows the existing opaque-file lifecycle. Outside attachments.py, file_paths is only read by slack/files.py. The ACP image sink only claims image suffixes, and the session picture store only copies images. The symlink-swap finding from an earlier review is fixed because the download path is never reopened for writing. A cancel during the write is handled by a done callback that deletes the copy. The signature change to _clean_text/_read_text_file reaches only callers that were updated. Tests cover a cut file, a file that fits, a failed copy, the symlink swap and a cancel, and they use bounded event waits. Text that fits the limit is unchanged.

An automated recommendation, not a review: a maintainer still decides. It approves on its own only when the estimated chance of a defect is at most 12% and the change has at most 400 changed lines. Decider v3c (217fe607) · commit 48b2609aea · 335 changed lines. If this recommendation is wrong, reply here: replies are how the approver is evaluated.

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

Request changes on 6bc665c. A channel text file or document longer than the inline limit keeps the same inline part, the cut now says "N of M characters", and the agent gets the whole redacted text as a temp .txt that every channel's existing temp cleanup deletes; correct on fit, cut, failed-copy and cancelled paths, and every guard is mutation-tested. Decisive lines: src/kiro_crew/messaging/attachments.py:349-356 (_clean_text returns the whole REDACTED text only when cut), src/kiro_crew/messaging/attachments.py:360-368 (_rewrite_text opens r+, never recreates an unlinked download), src/kiro_crew/messaging/attachments.py:371-393 (_hand_over_whole_text: rewrite, rename to .txt, hand to file_paths, else leave dest for the finally to unlink), src/kiro_crew/messaging/attachments.py:589-592 and :623-624 (TEXT and DOCUMENT branches)

A text file or document sent on a channel was cut at max_text_inject
with a bare "[… truncated]" and its file deleted, so the agent could
neither tell how much was missing nor read the rest. The prompt now
keeps the same inline part, the marker states how many characters were
shown of how many, and the whole redacted text is handed over as a new
temporary .txt for the turn, never the raw bytes: the download is
deleted as before. Text under the limit is unchanged; text above
max_text_bytes stays refused.

Part of #32148
@bolichen97
bolichen97 force-pushed the fix/32148-channel-text-handover branch from 6bc665c to 48b2609 Compare November 11, 2026 16:11
@bolichen97

Copy link
Copy Markdown
Contributor Author

self-added: yes
mechanism: the whole-text copy is a new file written through its own mkstemp descriptor

  • span=fe31ebf0dc35 The privileged rewrite follows a replaceable temporary-path symlink

fixed in 48b2609: the gateway no longer reopens or writes the download. The whole redacted text goes into a new file that mkstemp creates with O_CREAT|O_EXCL, written through that same descriptor, so no path another process could swap (symlink or hard link) is opened for writing; the download is only unlinked, which removes a planted link and never its target.
test_a_link_planted_at_the_download_after_it_is_read_is_never_written_through swaps a symlink to a protected file in between the read and the copy: red on 6bc665c (target overwritten), green on 48b2609.
[operator: bolichen97]

@bolichen97

Copy link
Copy Markdown
Contributor Author

self-added: yes
mechanism: the copy is written under asyncio.shield and deleted by a done-callback if the turn is cancelled

  • span=fe31ebf0dc35 Cancellation leaves the attachment behind on Windows

fixed in 48b2609: no worker holds the download open for writing any more; it is only read, as on main, and deleted by the existing finally. The copy is written under asyncio.shield, and on a cancel a done-callback deletes it once the worker (which cannot be stopped) finishes and has closed it, off the loop.
test_a_cancel_while_the_copy_is_written_leaves_no_copy_behind cancels the turn while the copy is being written and checks nothing is left: red on the intermediate head without the shield, green on 48b2609.
[operator: bolichen97]

@bolichen97

Copy link
Copy Markdown
Contributor Author

self-added: yes
mechanism: create, write and close the copy in one executor call; no rename

  • span=fe31ebf0dc35 The final rename blocks the gateway event loop

fixed in 48b2609: the rename is gone. Creating, writing and closing the copy run in one executor call; on the loop the hand-over only submits that call, awaits it and appends the path.
[operator: bolichen97]

@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] @buluoray thank you for the review of 6bc665c. The GPT lane's three blocking findings on that head are fixed in 48b2609aea (one disposition each below):

  • The whole text is no longer written back into the download. It goes into a new temporary .txt created and written through its own descriptor, so the gateway never writes through a path anything else can replace; the download is deleted as before.
  • Creating, writing and closing that copy is one call off the event loop, with no rename.
  • If the turn is cancelled while the copy is being written, the copy is deleted once the worker finishes, so nothing is left behind.

Two tests cover the new paths: test_a_link_planted_at_the_download_after_it_is_read_is_never_written_through and test_a_cancel_while_the_copy_is_written_leaves_no_copy_behind. The inline part, the size marker and the path line are unchanged. Could you take another look at the new head when you have a moment?

@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] Backend Tests (3.12, 6) on 48b2609aea is red on test/test_remove_slot_for_history_key_crew_log.py::TestSessionLedgerOnPermanentDelete::test_a_ledger_the_emitter_itself_opened_is_still_removed, the flaky test tracked in #34376 (this head's run is already reported there), and Coverage Gate fails closed on that shard. This diff does not touch the crew log, the session ledger or that test.

The fix for that test is #35705. This PR waits for it to merge, then re-syncs onto it; the flaky test is not rerun in between.

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

Approve on 48b2609. The earlier blocking point is fixed. The gateway no longer writes the whole text back into the downloaded file. It writes it to a brand-new temporary file through the handle it created, so nothing an agent can reach is ever written through. The download is deleted as before, the rename is gone, and a cancelled turn deletes the copy once the background write finishes. A new test plants a link at the download path and checks that the link target is untouched, and it fails when the old behaviour is put back. The inline part, the size marker and the redaction are unchanged from the earlier head. One older gap remains and is not new in this PR: the gateway reads the downloaded file by its path, so a file swapped in before the read is read too. Before this PR only the inline part of it reached the agent; now the whole redacted text does. Opening the download without following links, and checking it is the same file that was size-checked, would close it in a follow-up. Decisive lines: src/kiro_crew/messaging/attachments.py:360-376 (_write_whole_text: a new mkstemp(suffix=".txt") file written through its own descriptor), src/kiro_crew/messaging/attachments.py:379-387 (_delete_unclaimed_copy), src/kiro_crew/messaging/attachments.py:390-416 (_hand_over_whole_text: shielded executor write, done-callback on cancel, no rename), src/kiro_crew/messaging/attachments.py:612-614 and :645-646 (TEXT and DOCUMENT branches no longer pass or keep dest), test/test_messaging_attachments.py test_a_link_planted_at_the_download_after_it_is_read_is_never_written_through

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention labels Nov 12, 2026
@bolichen97
bolichen97 merged commit b79846a into main Nov 12, 2026
153 of 163 checks passed
@bolichen97
bolichen97 deleted the fix/32148-channel-text-handover branch November 12, 2026 06:23
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 12, 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.

3 participants