Repository navigation
feat: hand a channel agent the whole text of a long attachment - #35086
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: the copy goes through the same Notes
[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 |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing to check. What this change shipsInventory (7 items) — 7 justifiedIntent: 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.
[FIRST-PRINCIPLES-REVIEWED] 48b2609 Description read[DESCRIPTION-READ] 1001747d7094cfb165d8aa8b4984de9bf2b6317314857ec42ac34cf6bf168bea That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
Code change approver recommendation: ApproveWhy: 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 |
buluoray
left a comment
There was a problem hiding this comment.
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
6bc665c to
48b2609
Compare
|
self-added: yes
|
|
self-added: yes
|
|
self-added: yes
|
|
[operator: bolichen97] @buluoray thank you for the review of
Two tests cover the new paths: |
|
[operator: bolichen97] 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
left a comment
There was a problem hiding this comment.
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
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
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.
max_text_injectmax_text_injectcharacters, then[… truncated: N of M characters of text shown]and[Its whole text is in <path> until this turn ends].txtIn
messaging/attachments.py, the copy is a new temporary.txtholding 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 intoIngestResult.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
messagingandslack-gatewayspecs, the Telegrammax_text_inject_kbrow insrc/kiro_crew/docs/telegram-integration.md, the config spec's comment for that key, theslack/files.pydocstrings and aslack/events.pycomment say this, anddocs/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_kbkeeps 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.txtcopy 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.txtwith 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_truncatedandtest_slack_files.py::test_text_content_truncateddelete 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_attachmentson a 406 KB CSV with a plantedghp_token through the real reader: the prompt was 51,499 characters ending51200 of 406342 characters of text shown]plus the path line; the.txtcopy 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
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)