Skip to content

fix(chat): keep transcript images renderable after their scratch file is reclaimed - #9680

Closed
Pearcekieser wants to merge 1 commit into
kirodotdev:mainfrom
Pearcekieser:feat/chat-owned-scratch-artifacts
Closed

Pearcekieser wants to merge 1 commit into
kirodotdev:mainfrom
Pearcekieser:feat/chat-owned-scratch-artifacts

Conversation

@Pearcekieser

@Pearcekieser Pearcekieser commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

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 ![alt](/…/scratch/…/chart.png) 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-raw load 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

  • Re-keying image copies away from the backend's existing (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.
  • Making images durable on surfaces that render a message without its slot key (completion cards, the plain transcript view): they have no owner to name, so they get no fallback rather than an ownerless request.
  • Restoring copies already pruned by the widget-preview sweep before this change, or migrating existing copies.
  • Changing how the artifact library lists, pins or deletes image artifacts a user has claimed.

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_widget excludes kind == "image", so chat-image copies are no longer pruned by the widget-preview policy.
  • New ArtifactStore.delete_auto_images_for_sessions(keys) removes the untouched auto-registered image copies of a set of sessions. api_session_delete calls it (off-loop via asyncio.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, new website/src/lib/imageArtifactSlug.ts):

  • ImgWithFallback first loads /api/file-raw?path=… as before. On error it tries /api/artifacts/<slug>/asset for 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.
  • The slug needs the image's ordinal in the raw message as the backend counted it. That cannot be derived from positions in the rendered tree: the block assembler strips <mcwidget …> tags (whose title can contain an opener), MarkdownBlock strips 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's IMAGE_MD_RE and md_destination grammar (shared parity fixture test/fixtures/image_grammar_parity.json drives 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.
  • Exact or nothing. A destination that appears once in the message is unambiguous. A repeated destination is resolved only when the block's exact raw span is known (the assembler records 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.
  • Variants: AssistantMessage now passes the ts of the variant being shown (variants[activeIdx].ts, falling back to the message ts) to MarkdownRenderer. 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:

  • Bulk clear (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 referencing delete_session also calls _reap_session_images.
  • Forks copy messages with their ts intact and image slugs derive from ts alone, so a fork renders its source's copies. The reap snapshots fork lineage (forked_from) before unlinking and skips any deleted session a surviving transcript descends from, through any depth of fork-of-fork.
  • The widget sweep and the image reap share one investment predicate (_is_unclaimed_auto_artifact), so "nobody has claimed this" cannot drift between them.
  • Owner check on the asset endpoint. Image slugs are keyed by (message ts, ordinal) only, so two sessions finalizing in the same instant can collide on a slug. The transcript fallback therefore names its own session (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.
  • Trash empty reaps too. Emptying the session trash (POST /api/system/session-storage/empty) is the permanent delete of a staged transcript, so _run_empty_job reads 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 with empty_trash as an unlinker.
  • Bounded ancestry. fork_ancestors is 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.
  • Registration drain on delete. Image registration is a detached task at finalize time; a permanent delete first removes the slot (killing its kiro-cli session), then waits for that session's in-flight registrations (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_sessions removes only untouched auto images of the named sessions and leaves user-touched artifacts and other sessions alone; api_session_delete invokes 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; every delete_session handler is pinned to call the reap (AST); a surviving fork (any depth) protects its ancestors' copies; the session-key spellings match what register_images records.
  • 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 legacy forked_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/main worktree (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, fixture minimal, 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.

Before: transcript renders the revenue chart from its scratch file

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.

After: same transcript, picture served from the durable copy

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.

Exhausted: broken-image chip after the durable copy is gone

4. Variant browsing keys images by the variant shown. Browsing back to the older variant (effectiveTs in AssistantMessage.tsx) renders that variant's own durable copy (the orange first draft), not the active variant's.

Older variant browsed back, rendering its own picture

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

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|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: 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
  • No secrets, credentials, or internal references in the diff

@Pearcekieser
Pearcekieser requested review from a team September 9, 2026 09:05
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

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

@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Sep 9, 2026
@github-actions

github-actions Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5, fork) — ✅ PASS

UX-level review of 8ad6c809f0f4dcb7ee1ce6454d1033fce2012e63 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

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 .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 Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5, fork) — 🟡 CONCERNS

Design-level review of 7a5679ddbecbc0b9911aaaa29023c4d081690537 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

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

  • fork_slot refuses (fork_ancestry_unprovable / fork_ancestry_over_bound) when the source's ancestry walk fails or an entry exceeds the new bounds — "A pre-upgrade source whose legacy forked_from walk cannot be completed … answers 422." A pre-upgrade session admitted with a slot name over the new MAX_SLOT_NAME_CHARS, or with damaged legacy metadata, loses forkability entirely, even though the PR itself defines the state (UNPROVABLE_CHAIN_RECORD, fork_ancestors_unprovable) that the restore path uses to carry exactly this condition with the same fail-closed image behavior (no asset fallback, reap keeps). Refusing a core operation to protect a convenience this PR adds inverts their importance.
    Clears when: fork mints with the unprovable record instead of 422, or a test/decision shows a pre-upgrade over-bound-named or unreadable-lineage session still forks (and the truncated description's backwards-compatibility section, cut at 8000 bytes, lists these refusals).

Suggestions

  • Follow-up (not this PR): persisting the destination→slug map at register_images time would retire the byte-for-byte frontend grammar port, its permanent parity obligation, and the exact-or-nothing cases that today get no fallback.
  • When the deferred (session, ts, ordinal) identity fix lands, plan the retirement of fork_ancestors and its 422 codes — they are new persisted, agent-visible surface that exists only to compensate for the deferred identity.

[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 .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 Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5, fork) — 🔴 BLOCK

Premise-level review of 8ad6c809f0f4dcb7ee1ce6454d1033fce2012e63 via the fork AI-review pipeline — 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: BLOCK

The sidecar inode pinning and SHA-256 re-check protect an owner check that the caller chooses to apply. Dropping ?session= gets the same bytes without any check, so the protection costs every image load something and protects no one.

Notes

  • Item 6 — symptom-level: the fork-lineage stack (fork_lineage.py, 641 lines; fork_ancestors; staged_lineage.py; reap snapshots) exists only because slugs are keyed by (ts, ordinal). That cause is in ## Not a goal, so this note just records that it is left open.
  • Item 8 — rides along: MAX_SLOT_NAME_CHARS returns a new 400 on chat-send and slot-create. It is only needed because this PR removed session_key[:256]. Subtraction: keep the truncation and drop the two admission refusals.

What this change ships

Inventory (9 items) — 5 justified

Intent: keep chat images rendering after scratch reclamation — FIX

  1. A broken transcript image falls back to its durable artifact copy — justified
  2. Chat-image copies are no longer pruned by the widget sweep — justified
  3. Deleting a session, clearing all sessions or emptying the trash removes its untouched image copies — justified
  4. The asset route checks the owner when ?session= is given — justified
  5. The variant being shown keys its images by its own ts — justified
  6. Forks persist their full ancestry; deep or unprovable chains get a 422 — symptom-level
  7. Every image asset read is pinned to an inode and re-hashed — rides along
  8. Long session names are refused with a 400 — rides along
  9. Every artifact meta.json read is capped at 4 MiB — undeclared

Blockers

  • Asset identity pinning guards a check the caller can skip — rides along
    Trigger: read_image_bytes now goes through read_image_bytes_with_owner → _read_pinned_sidecar plus hashlib.sha256(data) on every serve. Meanwhile the diff itself says "Callers that name no session (the artifact library) are unaffected."
    Outcome: every image load, library loads included, re-hashes up to 25 MiB and can now 404 on a digest mismatch. The only payoff is closing a delete-and-recreate race inside a single read, under a check the requester controls.
    Subtraction: delete _sidecar_identity, _read_pinned_sidecar, _SidecarIdentity, _stat_identity and the sha256 parameter, and keep the owner read under the lock.
    Clears when: the pinning and the digest re-check are removed.

[FIRST-PRINCIPLES-REVIEWED] 8ad6c80

Description read

[DESCRIPTION-READ] cc898cbbc7b8f35245efa043345f6df45edace49ecc4884a1cd1bd632fb2f644

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 Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review (fork) — ✅ no blocking findings (all downgraded on adjudication)

Reviewed 8ad6c809f0f4dcb7ee1ce6454d1033fce2012e63 via the fork AI-review pipeline; updated in place on each push.

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 details

BLOCKING -- src/kiro_crew/dashboard/fork_lineage.py:140 -- Cron alias folding merges unrelated dashboard sessions

return transcript_stem(_tab_to_session(strip_dashboard_prefix(key)))
Trigger: Create dashboard slots named cron-42 and cron_42, finalize an image in the former, then delete dashboard:cron-42 while the latter survives. _delete_claimed_session → _fork_lineage → _image_reap_set folds both distinct transcripts to cron_42.
Outcome: The unrelated surviving session makes the reap return an empty set, retaining the deleted transcript’s untouched image copies after permanent deletion.
Anchor: defect
Fix: Preserve distinct dashboard transcript identities; resolve cron-tab aliases from recorded linked-session bindings rather than the slot-name prefix.

[BLOCK-MERGE-DOWNGRADED] 8ad6c80
[GPT-REVIEWED] 8ad6c80

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 cron-42 and cron_42, and fold (patch fork_lineage.py:1107) must fold them to one stem: _tab_to_session rewrites cron- to cron: (patch :1074-1078), and transcript_stem → _safe_key turns that into cron_42 (history_files.py:280-294). Second, the surviving slot's stem must land in survivors (patch sessions _image_reap_set :2259-2264).

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 cron_42 is deleted, owner_spellings maps the cron_ prefix back to cron-42 (patch :1096-1098), so the leftover copies are reaped then.

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.

[ADJUDICATION] 8ad6c809f0f4dcb7ee1ce6454d1033fce2012e63 total=1 uphold=0 downgrade=1
DOWNGRADE F1 src/kiro_crew/dashboard/fork_lineage.py:140 reason=disproportionate-remedy
[GPT-ADJUDICATED] 8ad6c809f0f4dcb7ee1ce6454d1033fce2012e63

@github-actions

github-actions Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review (fork) — 🔴 changes requested (blocking)

Reviewed 8ad6c809f0f4dcb7ee1ce6454d1033fce2012e63 via the fork AI-review pipeline; updated in place on each push.

Two block-offset errors in useBlockAssembler.ts give an image the wrong raw span, so a repeated image can be served another occurrence's durable copy, or none at all.

BLOCKING — website/src/hooks/useBlockAssembler.ts:544

  pieces.push({
    ...last,

Trigger: a reply that streamed in the current mount (streamedHere, so splitMarkdownBlocks runs) has one markdown block ![x](/tmp/a.png)\n\nSee again ![x](/tmp/a.png), and the scratch file has been reclaimed. splitParagraphs spreads last into the final piece, so that piece keeps the WHOLE block's startOffset (now set by parseBlocks line 210) but holds only the tail. MarkdownBlock builds rawSpan = [startOffset, startOffset + content.length), which covers the first opener, not the second. imageOrdinalCandidates then gets before=0, inRawBlock=1, inRendered=1, and returns k=0.
Outcome: the second image is served the copy of ordinal 0, the first occurrence, instead of ordinal 1. That is the wrong picture when the two copies hold different bytes, or a broken image when only ordinal 1 was stored. This breaks the "exact or nothing" contract.
Anchor: defect
Fix: give each split piece its own startOffset (the parent offset plus the length of the lines before it, newlines included), or remove startOffset from the final piece so it takes the no-span path like the earlier pieces.

BLOCKING — website/src/hooks/useBlockAssembler.ts:412

    lineOffset += line.length + 1

Trigger: an assistant reply where text is glued to a closing fence, e.g. ```![x](/tmp/a.png) followed later by ![x](/tmp/a.png). The glued branches of the 'fence' and 'widget-fence' states set lines[i] = glued[2]; i--; break. The break still adds the full original line.length + 1 (line is the original line), and the re-read adds glued[2].length + 1 again. So the glued block's pushMd records mdStartOffset past its true start, and every later block's startOffset is too large by glued[2].length + 1.
Outcome: the shifted RawBlockSpanCtx makes before and inRawBlock disagree with the rendered count, so same-destination images in or after that block show the broken-image chip even though their durable copies exist. When the shifted window happens to hold an equal count, an image resolves to another occurrence's copy instead.
Anchor: defect
Fix: on the glued re-read, advance lineOffset only by the consumed prefix (line.length - glued[2].length, with no +1), or skip the end-of-loop increment on iterations that re-read the line.

[BLOCK-MERGE] 8ad6c80
[OPUS-REVIEWED] 8ad6c80

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 9, 2026
@Pearcekieser
Pearcekieser force-pushed the feat/chat-owned-scratch-artifacts branch from 28c1bc4 to 6694838 Compare September 9, 2026 09:59
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

span=2ba85e28e288 — FIXED

get_default_store() is now evaluated inside the asyncio.to_thread lambda (new _reap_session_images helper in handlers/sessions.py), so the singleton's first-call resolve+mkdir runs off the loop. Codebase idiom, as the adjudication suggested.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

span=b5d058672d9b — FIXED

The block assembler now records each markdown block's exact raw startOffset; imageOrdinalCandidates receives the block's raw span and, when the raw slice holds the same number of same-destination openers as the rendered block (nothing stripped/added by preprocessing), applies the node's in-block occurrence to the RAW occurrences before the block — the exact ordinal the backend stored for this image. Only when the counts disagree (an earlier same-destination copy was stripped from this block) does it fall back to block-local order, and every copy of the destination is still tried before the broken chip. Tests: imageArtifactSlug.test.ts (exact vs fallback), fallback render suite (fence copy → ordinal 2 first, same-line widget title → ordinal 1 first).

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

span=60b3c2f95d8f — FIXED

api_sessions_clear now reaps image copies for every session it permanently deletes (one store pass for the batch) via the shared _reap_session_images helper; test test_bulk_clear_reaps_untouched_image_copies_of_deleted_sessions covers it, plus a no-op test when nothing was deleted.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

span=36a1681ea1b2 — FIXED

IMAGE_MD_RE in outbound_files.py now carries a KEEP IN SYNC pointer to the TS port, and a shared fixture test/fixtures/image_grammar_parity.json drives both test/test_image_grammar_parity.py and website/src/test/imageGrammarParity.test.ts.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

span=65a0f34dedbc — DECLINED (scope)

Recording a canonical session key on image artifacts changes the write path in register_images and the artifact schema, which is out of scope for a rendering/lifetime fix. The spelling set is now in one helper (_image_artifact_session_keys) shared by both delete paths, so a fifth spelling is a one-line change with a single owner. Tracked as a follow-up.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

span=821bee51788b — FIXED

Both permanent-delete handlers now reap (single delete and bulk clear); the description's lifetime claim is now true of the shipped code.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

span=37ac1628884b — FIXED

docs/system-specs/modules/artifacts.md retention bullet and the image_artifacts.py comment now describe the shipped exemption and the per-session reap.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

span=761bb0ea81a9 — FIXED

Bulk clear now runs the image reap. Orphan cleanup in channel_transcript_migration.py is a one-off migration for channel transcripts, not a user-facing permanent delete; left unchanged.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

span=553629a4ee7d — FIXED

Both passages rewritten to the shipped exemption (see span 37ac1628884b).

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

span=5a97b535bb22 — FIXED

The investment test is now one method, _is_unclaimed_auto_artifact, called by both _is_sweepable_auto_widget and the image reap's eligible().

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

span=425ace55b753 — FIXED

countImageOccurrencesBefore is no longer exported; the parity test uses the new exported countImageOpeners instead of a duplicated regex.

@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 readiness: checking Automated validation is still running labels Sep 9, 2026
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

Addressed the GPT 5.6 finding on d325d70 at the root, amended into the second commit (still two commits).

F1 handlers/sessions.py (a live record could overwrite a staged fork's lineage in the merge): _image_reap_set merged before, staged and after lineage with the live snapshots winning, so a session recreated under a trashed fork's stem and forked from a different source replaced the staged edge, and deleting the staged fork's real source would reap copies that fork renders once restored. The merge is now preceded by a conflict check: a stem present in the staged lineage and in either live snapshot with a different parent_of or known_ancestors fails the decision closed (reap nothing), the same disposition the trash-internal duplicate already takes in _retain_staged_lineage. An agreeing live record changes nothing. Test: test_a_staged_fork_whose_stem_is_live_with_other_lineage_fails_the_reap_closed covers the conflict and the agreement.

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.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

Addressed the upheld GPT 5.6 finding on 5813c4e at the root, amended into the second commit (still two commits).

F1 handlers/sessions.py (lineage snapshot decoded an unbounded metadata line): _fork_lineage called get_metadata_status on every transcript, which reads the first line with no size cap, so a huge agent-written fork_ancestors array was materialized and cached before recorded_chain could refuse it. The snapshot now pre-reads each first line with a bounded readline against fork_lineage.MAX_METADATA_LINE_BYTES (64 KiB, the same bound the staged-trash reader already applied as _META_LINE_CAP, now one shared constant), and a longer line marks the transcript unreadable so the reap fails closed and the decoder never sees it. Test: test_the_lineage_snapshot_bounds_the_metadata_line_before_decoding_it writes a line past the bound beside two conforming ones and asserts the oversized transcript is unreadable and its metadata read is never called.

Windows shard 3 on 5813c4e failed two untouched tests, test_agent_panel_crew_log::test_eviction_ranks_on_fold_order_not_on_a_stamp and the recurring test_session_export Windows unlink timing.

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.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

Addressed the GPT 5.6 finding on 91965d0 at the root, amended into the second commit (still two commits).

F1 handlers/artifacts.py (owner authorization not audited): the ?session= owner decision in api_artifact_asset returned 200 or 404 without a SEL event. It now emits _audit(tool="artifact_asset_owner_check", outcome="success" | "denied", extra={slug, session, owner}) for every decision, through the module's redacting writer, in the convention the other permission decisions in the file use. Requests that name no session make no owner decision and are unchanged. The existing owner-check test now asserts the four decisions it exercises are audited in order with their outcomes and the denied event's metadata.

Local: 416 artifact tests pass; black gate, flake8 and mypy clean on the touched files.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

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 (fork_ancestors restored on resume; the Asset endpoint's ?session= documented), so this is ready for another look.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

Rebased onto main (fac6dd9153) after the branch went CONFLICTING: one import-block hunk in src/kiro_crew/artifacts.py (kept both sides, no behaviour change). Head is now 14361b69b2, still two commits. Targeted suites: 790 passed (Python), 184 passed (vitest), tsc clean, black/isort/flake8/mypy gates clean on the touched file.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

Fresh head after the 05:32Z CI-app rate-limit wave on 14361b69b2 (GPT 5.6, Opus 5, Internal Content Scan and Security Scope all "could not run"). Rebased onto main 20a9365a1b; still two commits.

One real failure on that head, now fixed: main's new star-import surface pin in test/test_artifacts_refactor_store_contract.py did not list the names this branch binds in kiro_crew/artifacts.py (MAX_REAP_SCAN_ENTRIES, MAX_SESSION_KEY_CHARS, MAX_SLUG_CHARS, plus the stat and Iterable imports). Added them to the pin; __all__ is derived so the module needs no change. That file is 81/81 locally; targeted suites 790 passed (Python), 184 passed (vitest), tsc and black gate clean.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

GPT 5.6 round on cba4ab58bc: F2 (fenced) fork_lineage.py:349 fixed at the root. _read_meta, the live-catalog walk behind the asset route's descends_from and fork-time ancestry_chain, now pre-reads each spelling's first line with a bounded readline (fork_lineage.metadata_line_within_bound, same MAX_METADATA_LINE_BYTES bound) before get_metadata_status decodes and caches it; a line over the bound reads as unreadable, so the chain is unprovable and no positive match is drawn. handlers.sessions._metadata_line_within_bound now delegates to that same function, so the snapshot reader and the walk share one check. Test test_the_live_catalog_walk_bounds_the_metadata_line_before_decoding_it covers a real ConversationLog with a 64 KiB+ metadata line (unreadable, chain None, descends_from False) beside in-bound lines with and without a trailing newline.

F1, F3 and F4 were downgraded by the adjudicator (disproportionate remedy) and are left as is.

Also rebased onto main d5bdff64e0; still two commits. Local: 963 passed across the targeted suites; the two test_vector_memory_composition_contract.py::TestOneBindingPerSharedName failures on this head are inherited from main 600d4b9515 (identical files on both sides, lessons.py:1206 reads _row_stem_tokens_for_scan bare). Could the AI lane re-review this head?

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

Fresh head: rebased onto main d8fa6a527e, which carries the lessons.py name fix and the regenerated fold catalogue behind the nine inherited reds on 6f997ddeba (flake8 F821, six Backend shards, Coverage Gate). Opus 5 on that head ended "review incomplete" (lane did not run); GPT 5.6 passed it with no blocking findings. Still two commits, no code change since 6f997ddeba. Local: 1001 passed across the targeted suites plus test_fold_catalogue.py and test_vector_memory_composition_contract.py, black gate and flake8 clean.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

GPT 5.6 round on 49b134593d: both upheld findings fixed at the root.

F1 artifacts.py:1504: _read_text takes a max_bytes bound (bounded descriptor read, at most max_bytes + 1 bytes leave it, ArtifactError past the bound) and _read_meta_file passes the new MAX_META_BYTES (4 MiB), so every meta.json decode in the store is bounded before the JSON decoder materializes it. The reap walk sizes each record first and aborts fail-closed on one over the bound, the same way it already does for an over-long slug or owner. Test test_the_reap_walk_bounds_the_meta_file_before_decoding_it.

F2 session_storage.py:5141: new _stream_manifest_entries yields manifest entries one at a time with exactly _read_manifest's guards (raising _UnreadableManifest instead of returning None), and both staged readers (staged_transcript_stems, _retain_staged_lineage) consume it, so the O(sessions) entries list is never materialized; only the bounded stem set / lineage map is retained, and a listing that cannot be read to the end is discarded whole rather than kept in part. Test test_the_manifest_is_streamed_and_a_partial_listing_is_discarded_whole.

Opus 5 on 49b134593d ended "review incomplete" again; the Windows shard 1 red is test_subagent_continuable (untouched), E2E hit its 25 min budget, and the Integration red (test_a_second_boot_touches_only_known_module_globals, module global kiro_crew.security.paths._path_resolve_thread_waits left changed by the second boot) is in a module this branch does not touch; it passes locally and on main's run of the same base. Still two commits; 874 passed across the targeted suites, black gate, flake8, isort and mypy clean. Could the AI lane re-review this head?

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

GPT 5.6 round on ded5d1b8a1 (adjudication did not run, so both findings stood unreviewed):

F1 fork_lineage.py:393 fixed at the root: metadata_line_within_bound now reads through hooks.safe_read_file_bytes_nolink pinned to the transcript directory (max_bytes = the line cap + 1, truncating), the same chokepoint the staged reader already uses, so a transcript name swapped for a link, a hardlink outside the directory, or a non-regular file is refused by the read itself and the record reads as unreadable. Test extended with a non-regular transcript name; test_fork_lineage.py 29/29.

F2 test_image_artifacts.py:963 is the two platform guards on the hardlink and FIFO sidecar tests (os.link unsupported, os.mkfifo absent on Windows); the adjudicator downgraded this one as disproportionate on cba4ab58bc. They are left as they are: the guarded assertions have no portable counterpart, and both run on every CI runner (ext4 and NTFS both support hardlinks; the FIFO case is POSIX-only by construction).

Still two commits; 874 passed across the targeted suites, black gate, flake8, isort and mypy clean. The shard 3 red on ded5d1b8a1 is test_session_export (untouched, known timing flake). Could the AI lane re-review this head?

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

Fresh head after the 09:33Z CI-app rate-limit wave on c3b157e9fc (GPT 5.6, Opus 5, Internal Content Scan and Security Scope all "could not run"). Rebased onto main d7aa10b222, no code change since c3b157e9fc; still two commits. Targeted suites green locally (519 passed on the touched files, black gate clean).

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

Fresh head: rebased onto main fecca3ea56, no code change since c3b157e9fc; still two commits. On 264c02cd45 GPT 5.6 passed with no blocking findings, Security Scope and Internal Content Scan were clean, and Opus 5 ended "review incomplete" (lane did not run). The two shard reds there were runner flakes in untouched code: Frontend shard 4 (the same shard passes locally in full, 634 files / 10517 tests) and Windows shard 3 (test_runloop_integration throttle timing). Local: 874 passed across the targeted suites, black gate clean.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

GPT 5.6 round on 8d0787d125: F1 (fenced) artifacts.py:2784 fixed at the root, along the lines the finding named. read_image_bytes_with_owner now captures the record's meta.image.sha256 under the same metadata lock as the owner and the inode identity, and _read_image_asset_bytes refuses bytes whose SHA-256 differs from it, so an in-place overwrite of the pinned inode between the descriptor's fstat and its read (same inode, same length, same clock tick, which the identity alone cannot tell) is refused rather than served under the authorized record. _read_pinned_sidecar also re-checks the identity on the descriptor after the read and requires exactly the pinned byte count, so a file grown or truncated mid-read is caught even with the clock pinned back. A record with no digest (legacy) keeps the identity check alone. Test test_pinned_read_refuses_bytes_overwritten_in_place_between_check_and_read drives both windows through an os.fstat hook and covers the public read path.

Still two commits; 875 passed across the targeted suites, black gate, flake8 and mypy clean. The Windows shard 4 red on 8d0787d125 is test_autonudge_refactor_contract (file lock timing, untouched). Could the AI lane re-review this head?

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

Opus 5 round on 3147c6098d (GPT 5.6 passed that head): the one blocking finding, history.py:1447, fixed at the root. MAX_TRANSCRIPT_STEM_CHARS and artifacts.MAX_SESSION_KEY_CHARS were two separate 256 literals bounding one population (a transcript stem is a folded session key). Both are now re-exports of a single leaf constant, constants.SESSION_KEY_MAX_CHARS (a leaf because history and artifacts cannot import each other), alongside fork_lineage.MAX_ANCESTOR_KEY_CHARS which already aliased the artifacts name, so the stem bound, the owner-key bound and the ancestor-key bound cannot drift apart. Pinned by test_the_session_key_and_transcript_stem_bounds_are_one_constant (identity, not just equality); the facade surface pin lists the new import.

Also rebased onto main 8ae5dff6ee; still two commits. 876 passed across the targeted suites plus test_history.py, black gate, flake8, isort and mypy clean. The shard 3 red on 3147c6098d was test_session_export (untouched, timing). Could the AI lane re-review this head?

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

Fresh head 8281e15fb0: identical tree to 2836bf2c76 (re-stamped; main has not moved since), pushed only to re-run the one red on that head, Windows shard 2 test_auto_improvement_members (CancelledError, untouched by this branch). On 2836bf2c76 both AI lanes passed with no blocking findings (GPT 5.6 and Opus 5) and the other 87 checks were green. Still two commits.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

Pushed 6d19c01ae4, rebased on main tip and still two commits, addressing the Opus 5 round on 8281e15fb0.

  • Blocking, artifacts.py:1593, fixed: the reap walk now keeps a record only when its slug is well-formed and matches the directory it was read from, and the eligibility check in delete_auto_images_for_sessions also refuses malformed slugs. A planted "." slug can no longer reach _rmtree through either the walk or an only_slugs snapshot. The new test test_a_planted_dot_slug_never_reaches_the_reap_and_the_store_root_survives fails on the previous head and passes on this one.
  • Non-blocking, chat_fork.py:1145 (a legacy fork whose parent was permanently deleted reads as unprovable): not changed in this push. That refusal is fail-closed and only affects forks created before this change.

Re-review would be appreciated when convenient.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

Rebased onto current main as e5a8208375, with no code change and still two commits. On 6d19c01ae4 GPT 5.6 and Opus 5 both passed with no blocking findings. The only red was Windows shard 7, in test_crew_log_edge_concurrency.py, a file this PR does not touch. This push gives that shard a fresh run.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

Rebased onto current main as 4cd9b5152d, with no code change and still two commits. On e5a8208375 GPT 5.6 and Opus 5 both passed with no blocking findings. The only red was Windows shard 5, in test_chat_agent_selection.py (CancelledError), a file this PR does not touch. This push gives that shard a fresh run.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

Pushed 05c519fa91, still two commits, addressing the GPT 5.6 round on 4cd9b5152d.

  • Upheld under a-ratchet-may-only-tighten, test_image_artifacts.py:1031, fixed: both new skips are gone. The hardlink test now fakes the descriptor's link count through a small _StatView wrapper over the real os.fstat result. The FIFO test fakes the descriptor's file type as S_IFIFO and records the open call, then asserts the read is refused and the open was non-blocking. Both run on every host. Each test fails when its check is removed from _read_pinned_sidecar (link-count/S_ISREG check, nonblocking=True) and passes with it in place.

Re-review would be appreciated when convenient.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

Rebased onto current main as 8f954976f8, with no code change and still two commits. On 05c519fa91 GPT 5.6 and Opus 5 both passed with no blocking findings, which clears the ratchet finding. The only red was Windows shard 7, test_runtime_cleanup_windows.py, a file this PR does not touch. This push gives that shard a fresh run.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

Rebased onto current main as ccf945d90e, with no code change and still two commits. On 8f954976f8 GPT 5.6 and Opus 5 both passed with no blocking findings, and every Windows shard was green. The two reds came from the base commit, not from this PR. Backend Lint was a flake8 F811 in autonudge.py, which main has since fixed. Frontend shard 2 was the widthFamilyGc drag-timing test, which main fixed in #16028. Neither file is touched here.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

Rebased onto current main as 3869880cef to clear the conflict with #16104, still two commits and no behaviour change. #16104 moved the slot metadata-line save code out of chat_persistence.py into slot_persistence/metadata_line.py. The two fork_ancestors writes this PR adds beside forked_from now sit at the same two save sites in metadata_line.py. The two rehydrate reads stay in chat_persistence.py. Targeted tests pass, including the chat-persistence composition contract and the fork suites, and black, flake8, mypy and tsc are clean.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

Pushed 577cb54550, still two commits, addressing the GPT 5.6 round on 3869880cef.

  • Fenced F1, chat_fork.py:1161 (fork admission ignored the metadata-line bound), fixed at the root. A new fork_lineage.MAX_FORK_ANCESTRY_BYTES caps the serialized fork_ancestors chain at half of MAX_METADATA_LINE_BYTES, which leaves the other half for the rest of the line. materialize_ancestors refuses a chain over that budget, so fork_slot answers the existing 422 fork_ancestry_over_bound before the child exists. recorded_chain reads such a chain as unprovable, so admission and the reader share one bound. The count and per-entry bounds alone allowed about 260 KiB. New tests in test_fork_lineage.py and test_dashboard_chat.py fail on the previous head and pass on this one.
  • Backend shard 1 red on the previous head was test_subagent_continuable, a file this PR does not touch.

Re-review would be appreciated when convenient.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

Pushed 7a5679ddbe, still two commits, addressing the GPT 5.6 round on 577cb54550.

  • F1, upheld, fork_lineage.py:326: walk_ancestors now refuses a start over MAX_ANCESTOR_KEY_CHARS before folding or retaining it and returns None, so callers fail closed. The ?session= value on the asset route is bounded like every other key the walk keeps.
  • F2, upheld, session_storage.py:5221: staged_transcript_stems counts each named batch against MAX_STAGED_LINEAGE_TRANSCRIPTS before keeping it, empty and unreadable batches included, and refuses past the cap.
  • Finding, handlers/sessions.py:3159: the comment no longer claims the second registration wait is bounded. It now says the wait has no timeout and the reap task stays held until the registration finishes or the process exits.

The new tests in test_fork_lineage.py and test_session_storage.py fail on the previous head and pass on this one. The two Frontend shard reds on the previous head (SessionActionsMenu.duplicate.test.tsx, hoverVariantPolicy.test.ts) fail identically on current main and are not touched by this PR.

Re-review would be appreciated when convenient.

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

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:1133 walks the legacy chain through fork_lineage.ancestry_chain.
  • fork_lineage.py:381 skips every spelling of the parent, because has_log is False once the transcript is deleted. The parent is then reported unreadable at :528, the walk returns None, and chat_fork.py:1145-1156 refuses the fork.
  • The unit tests do not catch this because the MagicMock log in test_fork_lineage.py::_log reports 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_unprovable

The 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.py
  • dashboard/chat_runner.py
  • test/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 adds relocateRequestUrl for pane byte requests, so whichever PR lands second should route the new /api/artifacts/<slug>/asset fallback 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.

@bolichen97

Copy link
Copy Markdown
Contributor

@Pearcekieser this branch now conflicts with main in seven files:

  • src/kiro_crew/dashboard/chat_fork.py
  • src/kiro_crew/dashboard/chat_handlers.py
  • src/kiro_crew/dashboard/chat_persistence.py
  • src/kiro_crew/dashboard/chat_runner.py
  • src/kiro_crew/dashboard/slot_persistence/metadata_line.py
  • test/link_screen_sites.py
  • test/test_chat_fork_error_codes.py

Could you rebase onto current main? The change request from 2026-10-05 still stands: a pre-upgrade fork whose source was deleted gets 422 fork_ancestry_unprovable on this head (chat_fork.py:1145-1156) and 200 on main. The test in that review reproduces it, so please fold the fix into the same push.

… 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>
@iamwhatever

Copy link
Copy Markdown
Contributor

Thank you, @Pearcekieser! Issue #9679 is done on main via #10424 (per bolichen97), so closing this one. Please reopen if transcript images still break.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor) merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: action required A blocking check or review needs attention

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Chat images referenced from agent scratch break after the scratch dir is reclaimed

6 participants