Skip to content

fix: keep a telegram picture visible in the dashboard after the turn - #36520

Merged
bolichen97 merged 1 commit into
mainfrom
fix/10871-telegram-picture
Nov 19, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
fix/10871-telegram-picture

Conversation

@bolichen97

@bolichen97 bolichen97 commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A picture someone sends the bot on Telegram still shows in the dashboard after the turn ends and after a reload.

A Telegram photo is downloaded to a temp file, and that file is deleted when the turn ends. The transcript's user row kept the bare temp path plus the model-facing note [Image <name> is saved in the folder /tmp/ until this turn ends; ...]. So a dashboard tab on that conversation showed a dead path and a stale note where the picture had been. Feishu had the same defect and was fixed in #31807; Telegram is the next channel #10871 wires.

Why it matters

Anyone who sends the bot a picture on Telegram and then opens that conversation in the dashboard sees text instead of the picture, and the note points at a file that no longer exists. The picture is gone from the history for good.

Not a goal

What changed (motivation → approach → change)

The user row named a temp file the turn deletes. ConversationLog.store_ingested_images already copies a channel's own downloads into the session's attachments store and rewrites the row to name the copy (the #31807 step, which #38076 made callable on its own). Telegram needs that step a moment earlier than Feishu: when a dashboard tab is open on the conversation, Telegram shows the row there live before it appends it, and that window rewrites its rows on disk on every save. A window still holding the temp path would undo the copy.

Piece Change
Telegram turn (telegram/dispatch/turn_engine.py) Keeps the photos it downloaded (IngestResult.image_paths), stores them through ConversationLog.store_ingested_images right before the row is scrubbed and written, and hands the stored text to both the live dashboard window and the transcript append. Each picture becomes a copy in sessions/<stem>.attachments/, its path line becomes ![image](<copy>), and its turn-only note is dropped. A store that fails leaves both the text as it came in, so the turn is still recorded. Nothing changes when the session is restricted, since that turn writes nothing.
Docs history.md and messaging.md say Telegram stores its pictures before both writers.

A picture that cannot be kept (too large, the session cap reached, or the session being deleted) leaves the row exactly as it is today. The model's prompt for the turn is unchanged, and the temp files are still deleted when the turn ends.

Backwards compatibility

Compatible: no function, signature or key changes; only a Telegram user row carrying a downloaded photo changes, to ![image](...) markup the dashboard already renders.

Removes nothing: no key, function or record is removed; the stored row loses only a note that stopped being true when the turn deleted the file.

Tests

  • test/test_telegram_attachments.py::TestAPictureOutlivesTheTurn::test_the_row_and_the_live_window_name_a_copy_kept_with_the_session drives a Telegram photo turn into a real ConversationLog. The user row names the one stored copy in the session's attachments directory with no note left, the live dashboard window is handed that same text, and the downloaded temp file is gone after the turn.
  • test/test_telegram_attachments.py::TestAPictureOutlivesTheTurn::test_a_store_that_fails_still_writes_the_row makes the store raise a lock timeout: the live window and the transcript still get the user row, as it came in.

Proof: PROVEN test/test_telegram_attachments.py::TestAPictureOutlivesTheTurn::test_the_row_and_the_live_window_name_a_copy_kept_with_the_session (head a095f53d257a)

Determinism: both TestAPictureOutlivesTheTurn tests 20 of 20 runs at -n0, the two in reversed order, and all of test/test_telegram_attachments.py with the new tests run after the rest.

Manual verification

Reproduced and smoke-tested on Ubuntu 24.04 (Linux x86_64) on a clean checkout of this PR's base. No live Telegram bot can be reached there, so the run drives the real Telegram dispatcher (handle_message) with a fake client whose download writes a PNG, a real ConversationLog in an isolated data home, and a spy on the real live-window projection. An isolated gateway on that same home then serves the dashboard's view-time file endpoint, /api/file-raw.

Before (base):

"user_row": "look\n/tmp/tmpj32f7_ct.png\n\n[Image tmpj32f7_ct.png is saved in the folder /tmp/ until this turn ends; join the two to open the original file]",
"temp_downloads": {"/tmp/tmpj32f7_ct.jpg": false}, "store_exists": false, "until_turn_ends_note": true
GET /api/crons -> HTTP 200 application/json 72 bytes      (control: auth works)
GET /api/file-raw?path=/tmp/tmpj32f7_ct.png -> HTTP 404 {"error": "not found"}

After (this PR):

"user_row": "look\n![image](<home>/sessions/telegram_kirocrew_direct_7.attachments/8c6806d8d6093084-tmpvuav24w1.png)",
"live_equals_row": true, "temp_downloads": {"/tmp/tmpvuav24w1.jpg": false}, "store_exists": true, "until_turn_ends_note": false
GET /api/file-raw?path=<home>/sessions/telegram_kirocrew_direct_7.attachments/8c6806d8d6093084-tmpvuav24w1.png -> HTTP 200 image/png 72 bytes
GET /api/file-raw?path=/tmp/tmpvuav24w1.png -> HTTP 404 {"error": "not found"}

A photo whose caption carries a valid GitHub token is kept the same way, and its row and live window both read look [REDACTED: credential] above the stored picture. A Telegram text-only turn writes "hello there" as its row and creates no attachments store.

Screenshots / video

N/A — the diff touches no frontend file; the dashboard already draws a user row's ![image](...) markup.

Related Issues

Part of #10871

Sibling sweep

Swept: git grep -n "append_attachment_context(" -- src/kiro_crew
Sibling: src/kiro_crew/telegram/dispatch/turn_engine.py -- changed here
Sibling: src/kiro_crew/feishu/transport_dispatch.py -- not affected -- fixed by #31807
Sibling: src/kiro_crew/discord/transport_dispatch.py -- tracked in #10871
Sibling: src/kiro_crew/teams/transport_dispatch.py -- tracked in #10871
Sibling: src/kiro_crew/webex/transport_dispatch.py -- tracked in #10871
Sibling: src/kiro_crew/wecom/transport_dispatch.py -- tracked in #10871
Sibling: src/kiro_crew/weixin/transport_dispatch.py -- tracked in #10871
Sibling: src/kiro_crew/whatsapp/transport.py -- tracked in #10871

Pattern harvest

Not generalizable: each channel has its own ingest, write and cleanup order, so the fix is wiring that channel's downloaded paths into the store before its writers, not a rule a scanner could hold.

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

Submitted under the project's Apache-2.0 license (see CONTRIBUTING.md).

@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 4005c3aad1abd25a63fc7d30a5ae35ceeed71ca9 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 4005c3a

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

@github-actions

github-actions Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 4005c3aad1abd25a63fc7d30a5ae35ceeed71ca9 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 14, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 4005c3aad1abd25a63fc7d30a5ae35ceeed71ca9 — 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

The fix reuses the existing ConversationLog.store_ingested_images step. The 6 unfixed sibling channels are deferred to #10871 under ## Not a goal.

Notes

What this change ships

Inventory (4 items) — 4 justified

Intent: a picture someone sends the bot on Telegram stays visible in that dashboard conversation after the turn ends and after a reload. FIX.

  1. A Telegram user row with a photo now points to a copy kept with the session, not a deleted temp file. — justified
  2. The live dashboard window gets the same stored text, so its next save does not bring back the temp path. — justified
  3. If storing the picture fails, the row is still written as it came in, and a warning is logged. — justified
  4. The specs (history.md, messaging.md) now say Telegram stores its pictures before both writers. — justified

[FIRST-PRINCIPLES-REVIEWED] 4005c3a

Description read

[DESCRIPTION-READ] dcf5fed404d77ee1c3509d3ec6fbda7b1e982788c5f9fc29194b1633ca3d887f

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

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

Nothing blocks: it reuses the existing store_ingested_images step, puts it ahead of both writers so the live window can't write the temp path back over the copy, and falls back to the old row if the store fails.

[DESIGN-REVIEWED] 4005c3a

Description read

[DESCRIPTION-READ] 6a94f859c3f70a578a660acb8eb5517638e3e7fb95eeb2f5c963160a2c828644

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

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 4005c3aad1abd25a63fc7d30a5ae35ceeed71ca9 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 4005c3a

Verdict parsed from the review's SHA-scoped output markers for commit 4005c3aad1abd25a63fc7d30a5ae35ceeed71ca9.

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

@buluoray

Copy link
Copy Markdown
Contributor

Review passed on this head. Please rebase onto the latest main so CI can run fresh; the current CI run predates fixes on main and cannot go green as is. The approval will follow once the rebased head is green.

@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 14, 2026
A photo sent on Telegram was downloaded to a temp file that the turn
deletes, and the user row kept that bare path plus a note that the file
lasts until the turn ends. A dashboard tab on the conversation then
showed a dead path where the picture had been.

The Telegram turn now copies the photos it downloaded into the
session's attachments store right before it writes the row, through
ConversationLog.store_ingested_images (the copy step of
append(ingested_images=...) on its own), and hands the stored text to
both the live dashboard window and the transcript append. The live
window rewrites its rows on every save, so it has to hold the same text
the transcript does. A store that fails leaves both writers the text as
it came in, so the turn is still recorded.

Part of #10871
@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in src/kiro_crew/history.py, src/kiro_crew/history_append.py, src/kiro_crew/telegram/dispatch/turn_engine.py, test/test_history_bindings.py, docs/system-specs/modules/history.md and docs/system-specs/modules/messaging.md since this head went green (2f7e9f2 -> 2d7d2df); CI re-running.

Why this rebase: GitHub reported the pull request as conflicting, and a fresh run on today's main was asked for above. Two changes on main meet this one:

On main Resolution
#36640 scrubs credentials from the user text and the reply at the same Telegram write site Kept both: the turn stores its downloaded pictures first, then scrubs that stored text, and the live dashboard window and the transcript both get the scrubbed stored text (the order ConversationLog.append already uses).
#38076 added ConversationLog.store_ingested_images itself, for another channel's linked threads This pull request had added a method of that name. Kept main's method as it is (it also skips the store while the session is being deleted) and dropped this pull request's own copy, its binding and its inventory line. The pull request now changes only the Telegram turn, its tests and the two specs, and the description says so.

What was checked, on a clean Ubuntu 24.04 (Linux x86_64) host, on this exact commit on 5c747a0: every gate of the repository's gate list and the related tests on both surfaces, semgrep and the flake ratchet green; prove.py PROVEN; the two TestAPictureOutlivesTheTurn tests 20 of 20 runs; every Telegram and redaction test module (4395 passed, 0 failed) plus the bindings inventory and main's linked-thread picture tests (239 passed); and the smoke run in the description, before and after. Both local reviews ran on the rebased diff with no findings.

[operator: bolichen97]

@bolichen97
bolichen97 force-pushed the fix/10871-telegram-picture branch from cc9f424 to 4005c3a Compare November 17, 2026 10:00
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Nov 17, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] One correction to the note above: the host checks ran on the same patch at a095f53d, on 5c747a0. main moved once more before the push, in none of this pull request's files, so the pushed head 4005c3a is that same patch on 2d7d2df, and this head's CI run is the test run on today's main.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: checking Automated validation is still running labels Nov 17, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] The one red check on this head, Analyze (javascript-typescript), is not caused by this change. Its upload step failed with API rate limit exceeded for installation (job log). CodeQL on main has failed with the same error since 21:03 UTC today, and the shared Actions API pool running dry is tracked in #38885.

Nothing is pushed for it. The job gets its one re-run once CodeQL on main passes again. Every other check on this head is green.

@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 19, 2026
@KiroCrewCaptain

Copy link
Copy Markdown
Collaborator

Code change approver recommendation: A person should decide

Why: the decider estimates a 10% chance that this change introduces a defect, within the 12% limit for approving on its own, but it is held at tier 2: design-doc-gate: A.

Telegram now calls ConversationLog.store_ingested_images on its downloaded photos before redaction and before both the live dashboard window and the transcript append, so both writers name the stored copy. The order (store, then redact) matches the existing append path. The step only runs when _session_restricted allows a write, and that check covers channel-native incognito/temporary sessions through the privacy_mode fallback. Under the session lock it does nothing if a delete is in flight. A failed store is caught and the row is written as before. Telegram has a single ingest point, so no other path is left out. Two new tests cover the success and failure paths, and CI is green.

Tier: 2, held for a person: design-doc-gate: A.

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 4005c3aad1 · 131 changed lines. If this recommendation is wrong, reply here: replies are how the approver is evaluated.

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

I reviewed head 4005c3a. Telegram now stores the photos it downloaded in the session's attachments store before the redaction step, and the live dashboard window and the transcript append both get that stored text, so neither one can write the deleted temp path back. If the store fails, the turn falls back to the original text, so the row is still recorded. The new test fails when the turn engine is reverted to main and passes on this head. The full Telegram test set passes locally. I found no correctness, security or data-loss problem that blocks merging.

@bolichen97
bolichen97 merged commit b81bdda into main Nov 19, 2026
100 of 101 checks passed
@bolichen97
bolichen97 deleted the fix/10871-telegram-picture branch November 19, 2026 13:03
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 19, 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