Repository navigation
fix(chat): keep transcript images renderable after their scratch file is reclaimed - #9680
Pearcekieser wants to merge 1 commit into
Conversation
|
Intent: fix. Keep chat images renderable after their scratch file is reclaimed by falling back to the durable artifact copy the backend already makes, and stop that copy being pruned by the widget-preview sweep. Cleanup only on permanent chat delete. Reviewed locally at 28c1bc4 (gpt + opus lanes, all Critical/High closed). |
UX Review (Opus 5.5, fork) — ✅ PASSUX-level review of UX-Verdict: PASS Nothing blocks: the diff adds no new control or string, and the four attachments show the restored image, the broken-image chip that remains as the last resort, and variant browsing. No first-time reader has looked at them, because this fork lane runs without a blind read. [UX-REVIEWED] 8ad6c80 Description read[DESCRIPTION-READ] e80036520822ce9242b6e017bb9ee32656118cff7091749fd3df20eb047161c8 That sha256 names everything this verdict read: the PR description, plus the 7 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 |
Design Review (Fable 5, fork) — 🟡 CONCERNSDesign-level review of Design-Verdict: CONCERNS Fork availability regresses: legacy or over-bound lineage metadata now draws 422 on sessions forkable yesterday, protecting an image fallback that could instead be marked unprovable. Watch
Suggestions
[DESIGN-REVIEWED] 7a5679d Description read[DESCRIPTION-READ] 16e654e19faf14ca8c8de0f2a1ffc3b7350a9a1c9d75eec8d503182f813a6d4d 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, fork) — 🔴 BLOCKPremise-level review of First-Principles-Verdict: BLOCK The sidecar inode pinning and SHA-256 re-check protect an owner check that the caller chooses to apply. Dropping Notes
What this change shipsInventory (9 items) — 5 justifiedIntent: keep chat images rendering after scratch reclamation — FIX
Blockers
[FIRST-PRINCIPLES-REVIEWED] 8ad6c80 Description read[DESCRIPTION-READ] cc898cbbc7b8f35245efa043345f6df45edace49ecc4884a1cd1bd632fb2f644 That sha256 names the PR description this verdict read. Recompute it with |
GPT 6.1 Review (fork) — ✅ no blocking findings (all downgraded on adjudication)Reviewed Opus 5.5 adjudication downgraded every blocking finding. Downgraded: the remedy each one needs is disproportionate to the harm it prevents. Adjudication downgraded all 1 blocking finding(s): the remedy each one requires is disproportionate to the harm it prevents. Review detailsBLOCKING -- src/kiro_crew/dashboard/fork_lineage.py:140 -- Cron alias folding merges unrelated dashboard sessions
Adjudication (Opus 5.5) — is blocking on each finding proportionate?F1 — LOW (downgrade). Both conditions are confirmed in the code. First, the user must create two dashboard slots named The result fails toward keeping data: the deleted session's image copies stay on local disk, and nothing is lost or exposed. It also clears itself later. When The fix the finding asks for is to resolve aliases from recorded linked-session bindings. That is a new piece of state and lookup that serves only this rare slot-naming collision. Its cost to build and maintain is more than an occasional orphaned image on local disk is worth. |
Opus 5.5 Review (fork) — 🔴 changes requested (blocking)Reviewed Two block-offset errors in BLOCKING — website/src/hooks/useBlockAssembler.ts:544 Trigger: a reply that streamed in the current mount ( BLOCKING — website/src/hooks/useBlockAssembler.ts:412 Trigger: an assistant reply where text is glued to a closing fence, e.g. |
28c1bc4 to
6694838
Compare
|
span=2ba85e28e288 — FIXED
|
|
span=b5d058672d9b — FIXED
|
|
span=60b3c2f95d8f — FIXED
|
|
span=36a1681ea1b2 — FIXED
|
|
span=65a0f34dedbc — DECLINED (scope)
|
|
span=821bee51788b — FIXED
|
|
span=37ac1628884b — FIXED
|
|
span=761bb0ea81a9 — FIXED
|
|
span=553629a4ee7d — FIXED
|
|
span=5a97b535bb22 — FIXED
|
|
span=425ace55b753 — FIXED
|
|
Addressed the GPT 5.6 finding on d325d70 at the root, amended into the second commit (still two commits). F1 Local: 434 tests pass across the sessions-clear, image-artifact, fork-lineage and session-storage suites; black, flake8 and mypy clean on the touched files. |
|
Addressed the upheld GPT 5.6 finding on 5813c4e at the root, amended into the second commit (still two commits). F1 Windows shard 3 on 5813c4e failed two untouched tests, Local: 456 tests pass across the sessions-clear, session-storage, fork-lineage, image-artifact and fork-error-code suites; black gate, flake8, isort and mypy clean on the touched files. |
|
Addressed the GPT 5.6 finding on 91965d0 at the root, amended into the second commit (still two commits). F1 Local: 416 artifact tests pass; black gate, flake8 and mypy clean on the touched files. |
|
Readiness passed on a7e07a6: all 89 checks green, GPT 5.6 and Opus 5 with no blocking findings. The two items from the 09-10 review are on this head ( |
|
Rebased onto main ( |
|
Fresh head after the 05:32Z CI-app rate-limit wave on One real failure on that head, now fixed: main's new star-import surface pin in |
|
GPT 5.6 round on F1, F3 and F4 were downgraded by the adjudicator (disproportionate remedy) and are left as is. Also rebased onto main |
|
Fresh head: rebased onto main |
|
GPT 5.6 round on F1 F2 Opus 5 on |
|
GPT 5.6 round on F1 F2 Still two commits; 874 passed across the targeted suites, black gate, flake8, isort and mypy clean. The shard 3 red on |
|
Fresh head after the 09:33Z CI-app rate-limit wave on |
|
Fresh head: rebased onto main |
|
GPT 5.6 round on Still two commits; 875 passed across the targeted suites, black gate, flake8 and mypy clean. The Windows shard 4 red on |
|
Opus 5 round on Also rebased onto main |
|
Fresh head |
|
Pushed
Re-review would be appreciated when convenient. |
|
Rebased onto current main as |
|
Rebased onto current main as |
|
Pushed
Re-review would be appreciated when convenient. |
|
Rebased onto current main as |
|
Rebased onto current main as |
|
Rebased onto current main as |
|
Pushed
Re-review would be appreciated when convenient. |
|
Pushed
The new tests in Re-review would be appreciated when convenient. |
bolichen97
left a comment
There was a problem hiding this comment.
PR triage (agent-assisted) at head 7a5679ddbe against origin/main af1eb612da.
Breaking change: a pre-upgrade fork whose source was deleted can no longer be forked.
The case: the user forked a chat before this change, so the fork carries only forked_from and no fork_ancestors. Later they deleted the original, which is ordinary cleanup. On main, forking that fork works. On this head it returns 422 fork_ancestry_unprovable.
How it happens:
chat_fork.py:1133walks the legacy chain throughfork_lineage.ancestry_chain.fork_lineage.py:381skips every spelling of the parent, becausehas_logis False once the transcript is deleted. The parent is then reported unreadable at:528, the walk returnsNone, andchat_fork.py:1145-1156refuses the fork.- The unit tests do not catch this because the
MagicMocklog intest_fork_lineage.py::_logreports every key as present.
Repro: the test below is a copy of _seeded_state with the root transcript never written. It returns 422 on this head and 200 on origin/main.
@pytest.mark.asyncio
async def test_legacy_fork_whose_source_was_deleted_can_still_be_forked(tmp_path):
state = _make_state(tmp_path)
mid = state.get_or_create_slot("mid")
mid.forked_from = "dashboard:root" # pre-upgrade fork; root since deleted
mid.fork_ancestors = []
mid.append("user", "q2", "msg msg-u"); mid.drain()
async with TestClient(TestServer(_make_app(state))) as client:
resp = await client.post("/api/chat/slots/mid/fork", json={})
assert resp.status == 200 # head: 422 fork_ancestry_unprovableThe same thing happens at any depth when a legacy intermediate fork has been deleted. This takes away an operation that works today, so it needs either a take-away-changes justification or a fix.
A fix that keeps the PR's goal, also suggested by the Design and First-Principles reviews: a deleted ancestor ends the chain, the same as a root with no parent. A walk that is genuinely unreadable mints the fork with UNPROVABLE_CHAIN_RECORD instead of returning 422. In both cases the readers already fail closed: the asset fallback is refused and the reap keeps the copies.
Rebase needed. The branch is 375 commits behind main. git merge-tree reports conflicts in:
dashboard/chat_handlers.pydashboard/chat_runner.pytest/test_chat_fork_error_codes.py
Overlap check. origin/main has none of delete_auto_images_for_sessions, fork_ancestors, imageArtifactSlug or drain_registrations, so nothing here is superseded. Two open PRs touch the same areas:
- #15720 also edits
ImgWithFallback.tsx. It addsrelocateRequestUrlfor pane byte requests, so whichever PR lands second should route the new/api/artifacts/<slug>/assetfallback URL through it. - #15980 (scratch continuity on resume) is complementary, not a duplicate.
The earlier blocker on api_chat_slot_resume is addressed: it now reads fork_ancestors at chat_handlers.py:13069.
|
@Pearcekieser this branch now conflicts with
Could you rebase onto current |
… is reclaimed A local markdown image in a chat message is served from /api/file-raw. When the agent's scratch directory is reclaimed, the renderer now retries the durable copy registered at finalize time (/api/artifacts/<slug>/asset?session=<slot>) before showing the broken-image chip. Chat image copies are exempt from the widget sweep and are reaped only when their session is permanently deleted (single delete, bulk clear, empty trash), keeping copies a surviving or trashed fork still renders. Forks record their full fork_ancestors chain so a fork keeps access to its source's images after an intermediate is deleted. Rebased onto current main: the ports follow main's owner splits (metadata_codec row, state_parts slot fields, artifacts_disk/scans/writes, session_storage_parts.staged_lineage, handlers/sessions_parts.image_reap, chat_api send/create, segment_flush). Review fix (2026-10-05): a pre-upgrade fork (forked_from set, no fork_ancestors) whose source transcript was deleted forks again as on main. fork_lineage tells a missing transcript (has_log false for every spelling) from an unreadable one; a missing ancestor ends the walk like a root, and only an existing-but-unreadable link answers 422 fork_ancestry_unprovable. The fork walks from the source's forked_from, so the source's own live edge is kept. Adds the review's repro test, a deeper-chain case and a deleted-intermediate case; test_fork_lineage's catalog double now says which transcripts exist. Fixes kirodotdev#9679 Co-authored-by: iamwhatever <iamwhatever@users.noreply.github.com>
|
Thank you, @Pearcekieser! Issue #9679 is done on main via #10424 (per bolichen97), so closing this one. Please reopen if transcript images still break. |
Problem / Motivation
Goal: A local image an agent showed in chat keeps rendering after its scratch file is reclaimed, for exactly as long as the transcript (or a fork of it) that produced it exists.
An agent that writes a picture into its scratch directory and shows it in chat as
gets a working image — until the scratch directory is reclaimed (gateway restart, agent exit, the periodic sweep). After that the transcript shows the broken-image chip for a message that used to have a picture in it.The backend already copies each local chat image into the artifact store when the message is finalized (
register_images, one deterministic slug per image ordinal). It does not help today because (1) the frontend never tries that copy — a failed/api/file-rawload goes straight to the chip — and (2) the copies are auto-registered widgets to the store, so the rolling widget-preview sweep prunes them like any other auto widget.Why it matters
Pictures are how agents show their work (charts, screenshots, diagrams). A transcript that silently loses them a few hours later is not a record you can go back to. It also hits everyone who sends the dashboard to the background overnight: scratch reclamation is the normal lifecycle, not a fault.
Not a goal
(message ts, ordinal)identity, or namespacing stored copies by owner. The owner check on the asset route closes the cross-session disclosure; the remaining same-tick durability gap is an artifact-identity contract change for its own issue.What changed (motivation → approach → change)
Symptom: broken chip after the scratch file is gone. Root cause: no fallback path to the durable copy, and the durable copy itself is not durable.
Approach: keep the backend's existing deterministic identity (
derive_widget_slug(f"{ts}#image", ordinal)) and make both ends honor it, rather than inventing a second registry.Backend (
src/kiro_crew/artifacts.py,src/kiro_crew/dashboard/handlers/sessions.py):_is_sweepable_auto_widgetexcludeskind == "image", so chat-image copies are no longer pruned by the widget-preview policy.ArtifactStore.delete_auto_images_for_sessions(keys)removes the untouched auto-registered image copies of a set of sessions.api_session_deletecalls it (off-loop viaasyncio.to_thread) so the copies live exactly as long as the chat that produced them — permanent delete, not clear.Frontend (
website/src/components/MarkdownRenderer.tsx, newwebsite/src/lib/imageArtifactSlug.ts):ImgWithFallbackfirst loads/api/file-raw?path=…as before. On error it tries/api/artifacts/<slug>/assetfor the image's durable copy, and only when every candidate fails does it show the broken chip. Its fallback state is keyed to the image identity (src+ message ts) and resets when either changes, so a component reused for another image (variant browsing, an edited message) starts from the original file again.<mcwidget …>tags (whose title can contain an opener),MarkdownBlockstrips stray<tool_use>/<mcwidget>markup and repairs fences, and a reference-style![alt][ref]renders an<img>the backend never registered. So the renderer builds one map over the raw message text, destination → all ordinals holding that destination, using a port of the backend'sIMAGE_MD_REandmd_destinationgrammar (shared parity fixturetest/fixtures/image_grammar_parity.jsondrives both suites; the Python regex carries a KEEP IN SYNC pointer). Each rendered image looks itself up by the destination written at its own source offset.startOffset) and the raw slice holds the same number of that destination's openers as the rendered block — i.e. preprocessing removed nothing — so the node's in-block occurrence maps onto the raw ordinal the backend stored for that very image; other copies of the same destination are tried after it. In every other case the image gets no artifact fallback rather than a guessed one: a wrong picture is worse than the broken chip.AssistantMessagenow passes the ts of the variant being shown (variants[activeIdx].ts, falling back to the message ts) toMarkdownRenderer. A regenerated reply registers its own image copies under its own ts, so browsing back to an older variant must key its images (cache-busting&v=and the fallback) by that variant's ts, not the active one's.Backend lifetime, refined during review:
DELETE /api/sessions) reaps image copies for every session it permanently deletes, the same as the single delete; an AST test pins that every handler referencingdelete_sessionalso calls_reap_session_images.forked_from) before unlinking and skips any deleted session a surviving transcript descends from, through any depth of fork-of-fork._is_unclaimed_auto_artifact), so "nobody has claimed this" cannot drift between them.GET /api/artifacts/<slug>/asset?session=<slot>) and the endpoint returns 404 unless the copy's recorded session is that session or one it descends from by fork lineage (kiro_crew/dashboard/fork_lineage.py, the single ancestry walker used by both the endpoint and the reap). Callers that name no session (the artifact library) are unchanged. Forks persist their full ancestry (fork_ancestors) so lineage stays provable after an intermediate fork is deleted; a fork of a pre-upgrade fork reconstructs the chain from the catalog at fork time.POST /api/system/session-storage/empty) is the permanent delete of a staged transcript, so_run_empty_jobreads each batch's transcript stems (session_storage.staged_transcript_stems) and the fork-lineage snapshot before the empty and reaps copies for the batches that are actually gone afterwards; a kept (refused) batch stays restorable and keeps its copies. The AST pin now covers this handler withempty_trashas an unlinker.fork_ancestorsis agent-writable metadata, so it carries shared bounds (MAX_FORK_ANCESTORS,MAX_ANCESTOR_KEY_CHARS), checked before anything is retained; an over-bounds record reads as unprovable and every consumer fails closed (asset refused, reap keeps) rather than truncating. The pre-delete lineage snapshot also cross-checks the catalog against the transcript directory (ConversationLog.transcript_stems_on_disk), so a transcript the projection dropped on a stat failure makes the reap keep everything.image_artifacts.track_registration/drain_registrations, 30 s cap) before reaping, so a late copy can never outlive its transcript. If the wait times out the reap is skipped and logged.Positional counting was the first design and was rejected during local review: every preprocessing step that removes or adds an opener shifted the ordinal onto a neighbouring image. Keying by destination and refusing to guess removes the dependency on preprocessing entirely.
Tests
test/test_image_artifacts.py: image artifacts survive the widget-preview prune;delete_auto_images_for_sessionsremoves only untouched auto images of the named sessions and leaves user-touched artifacts and other sessions alone;api_session_deleteinvokes the cleanup.test/test_dashboard_sessions_clear.py: bulk clear reaps for exactly the sessions it deleted and skips the store when nothing was deleted; everydelete_sessionhandler is pinned to call the reap (AST); a surviving fork (any depth) protects its ancestors' copies; the session-key spellings match whatregister_imagesrecords.test/test_image_grammar_parity.py+website/src/test/imageGrammarParity.test.ts: one fixture, both grammars.test/test_fork_lineage.py: the shared ancestry walker — fold, materialize, descend through forks/grandforks, survive a deleted intermediate via the recorded chain, walk legacyforked_from-only forks, reconstruct a legacy source chain at fork time, fail closed on unreadable metadata, terminate on cycles.test/test_image_artifacts.py(asset): owner check accepts the owner in every spelling and its forks (incl. after the intermediate is deleted), refuses unrelated sessions and unreadable lineage; registration drain waits and reports timeouts.website/src/test/AssistantMessage.test.tsx: the rendered markdown is keyed to the ts of the variant being shown.website/src/test/imageArtifactSlug.test.ts: destination parser parity with the backend (balanced parens,_MD_ESCAPABLE-only escapes so Windows paths survive,<…>unwrap, title stripping, control characters, CR/LF), ordinal numbering over raw text incl. fenced/widget-title/stray-tag openers and reference images; exact-or-nothing candidate resolution (unique destination, exact raw span, disagreeing counts → none).website/src/test/MarkdownRenderer.imageArtifactFallback.test.tsx: local → artifact → broken chip progression; per-image ordinals; openers hidden in widget titles and stray protocol tags; duplicate destinations across fences and same-line widget closes resolve to their exact ordinal with the other copies after it and never a different image; fallback state resets when the message ts changes under a live image; reference-style images never borrow a direct image's artifact.Full gates run locally: backend lint/format/mypy/sync-io checks green; backend suite has 84 pre-existing failures that reproduce identically on a clean
origin/mainworktree (host uid / missing gh+electron binaries), none in touched files; frontend vendor/tsc/build/i18n/bundle green; full vitest 1957 files / 30,834 tests green; electron 1824 green.Manual verification
N/A — unit coverage exercises the load-error path directly via
fireEvent.error; the fallback URL is a pure function of message text and message id, so a browser run adds no information the tests do not already assert.Screenshots / video
Captured against a throwaway harness gateway (
kiro_crew.testing.harness.spawn_feature_gateway, fixtureminimal, this branch's built dist) with one transcript: an assistant reply whose picture is a local scratch PNG, with an older variant carrying its own picture, and the durable copies the backend registers at finalize placed in the artifact store under the slot key.1. Before: the original scratch file loads (
/api/file-raw?path=…), unchanged behaviour.2. After scratch reclamation: the durable copy renders. The scratch file and the session's attachments copy are gone; the
<img>fails on/api/file-raw, the fallback resolves/api/artifacts/<slug>/asset?session=evidence, and the same chart shows where the broken chip used to.3. Every candidate exhausted: the broken-image chip. The durable copy is deleted too; the fallback tries its one candidate, fails, and renders the chip ("Image file no longer exists") rather than a blank or a stale picture.
4. Variant browsing keys images by the variant shown. Browsing back to the older variant (
effectiveTsinAssistantMessage.tsx) renders that variant's own durable copy (the orange first draft), not the active variant's.Related Issues
Fixes #9679
Pattern harvest
Rule candidate: review-prompt
Pattern: "frontend derives an identity by counting positions in a string the renderer has preprocessed (stripped/repaired) — count over the raw source the backend saw, or key by content instead"
Checklist
feat|fix|docs|refactor|perf|test|chore|ci|build|revert: ...)docs/system-specs/modules/artifacts.md— retention bullet rewritten to the shipped lifecycle, asset endpoint gains the?session=owner check, new "Chat image fallback" section documents the transcript consumer