Skip to content

fix(web): editing a queued message keeps its attachment chips resolved - #5

Closed
smirea wants to merge 23 commits into
mainfrom
fix/edit-message-pasted-image
Closed

smirea wants to merge 23 commits into
mainfrom
fix/edit-message-pasted-image

Conversation

@smirea

@smirea smirea commented Nov 22, 2026

Copy link
Copy Markdown
Owner

Problem

When a user pastes an image (or attaches a file) into a message with text, sends it while a turn is active so it queues, and then edits the queued message, the inline attachment chip in the composer breaks and renders as an unavailable chip (This context is no longer available. Remove it or attach it again.) even though the attachment is still shown in the thumbnail row above the editor and sent on save.

Expected behavior (docs/internals/composer-context-references.md): pasting an image or attaching a file inserts a resolved inline chip backed by the attachment, while unresolved chips are only for missing records. A prior fix (pingdotgg#30850 / pingdotgg#30889) restored thread and environment context records when opening a queued edit in useQueuedRunEdit.ts, but left image and file records unmapped. apps/mobile/src/state/queued-run-edit.ts already seeds its edit draft with the full message context and does not have this bug.

Root cause: useQueuedRunEdit keeps the queued message's existing attachments in editing.existingAttachments rather than in the edit draft's images/files arrays. Because composerContextRecordsFromDraft only indexed live draft images/files, inline t3-context://v1/image/<contextId> (and file) links had no matching record in ComposerContextRecordsContext.

Change

  • apps/web/src/components/chat/queuedMessageEdit.ts & apps/web/src/components/chat/useQueuedRunEdit.ts:
    • Map each existing queued attachment to its original wire contextIds from editing.context (attachmentContextIdsForRecord), matching record.attachmentId === attachment.id and record.kind === attachment.type.
    • When removing an existing thumbnail (removeEditingAttachment), strip its inline references from the edit draft prompt so removing the attachment doesn't leave an unavailable chip behind.
    • When the queued run leaves the queue and an unsaved edit is recovered into the thread draft (recoverQueuedMessageEdit), strip existing queued attachment inline references first (or discard the recovery if nothing else remains) since the thread draft does not own those server attachments.
  • apps/web/src/components/composerContextPresentation.tsx & apps/web/src/lib/composerContextRecords.ts:
    • Extend composerContextRecordsFromDraft to accept existingAttachments and environmentId, registering image and file records under their original wire contextIds with uploadedAttachmentId (and uploadEnvironmentId for files/SVGs so they don't show as needing reattach).
    • Allow optional contextId passthrough in uploadedAttachmentContextRecord / attachmentContextRecord so uploadedContextRecordFromDraft preserves the original wire contextId.
  • apps/web/src/components/chat/ChatComposer.tsx:
    • Pass editingQueuedAttachments and environmentId into composerContextRecordsFromDraft (also covering collapsed mobile-web prompt preview).
    • Extend composerContextActions (expandImage, openFile, expandVideo) and buildContextClipboardFragment to resolve existing queued attachments alongside live draft attachments.
  • Tests: added unit and browser tests in composerContextPresentation.test.ts, queuedMessageEdit.test.ts, and useQueuedRunEdit.browser.test.tsx.

Scope

  • Issue: Fixes #<issue> (placeholder for upstream PR)
  • Web and Desktop (apps/web): fixed for queued-message editing across inline image, file, and video attachment chips (chip rendering in expanded and collapsed composer, clicking the chip to preview/open, editing/saving/re-editing, removing the thumbnail via ×, copying the chip, and recovering an unsaved edit when the queued run starts or is cancelled).
  • Edit from here (rewindToMessage): left unchanged — recallComposerMessage intentionally strips inline attachment chips when recalling into a new draft (composerPromptHistory.ts), so no unavailable chip appears.
  • Mobile (apps/mobile): left unchanged — apps/mobile/src/state/queued-run-edit.ts already copies the full message context into the edit draft.

Verification

Reproducible on a Linux VM with no provider account

All checks below run headless using the Replay (dev) (showcase) agent with no external provider account:

  1. Scenario proof (vp run scenarios:prove scripts/scenarios/queued-edit-keeps-pasted-image-chip.e2e.ts --base origin/main):
    • Base ad2bdc76a5: ❌ failed (expect.toHaveCount on getByRole("textbox") >> getByRole("button", name: "Image attachment"), expected 1, observed 0 — inline chip rendered as unavailable).
    • Head 057fda86a1: ✅ passed (inline image chip resolves on queued edit, clicking the chip opens and closes the expanded image preview, editing text around the chip + saving + re-editing keeps the chip resolved, and clicking × on the thumbnail removes the inline chip without leaving an unavailable chip).
Base ad2bdc76a5 (broken) Head 057fda86a1 (fixed)
Base ad2bdc76a5: inline image chip shows as unavailable in queued edit Head 057fda86a1: inline image chip stays resolved in queued edit
Scenario source (scripts/scenarios/queued-edit-keeps-pasted-image-chip.e2e.ts)
import { expect } from "e2e";
import type { Browser } from "@e2e-dev/web";

import { test, WEB } from "./t3.ts";

// A 1x1 red PNG, arriving as a clipboard image named image.png.
const RED_PIXEL =
  "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAAD0lEQVR4AQEEAPv/AP8AAAMBAQCNHeWCAAAAAElFTkSuQmCC";

const pastePng = (browser: Browser, base64: string) =>
  browser.evaluate((payload: string) => {
    const bytes = Uint8Array.from(atob(payload), (char) => char.charCodeAt(0));
    const clipboardData = new DataTransfer();
    clipboardData.items.add(new File([bytes], "image.png", { type: "image/png" }));
    const editor = document.querySelector('[contenteditable="true"]');
    if (!editor) throw new Error("No composer editor to paste into");
    return editor.dispatchEvent(
      new ClipboardEvent("paste", { clipboardData, bubbles: true, cancelable: true }),
    );
  }, base64);

test(
  "Editing a queued message keeps its pasted image chip resolved",
  WEB,
  async ({ t3, app, browser, screen }) => {
    const project = await t3.project("demo");
    const thread = await t3.thread({
      project,
      title: "Screenshots",
      messages: ["Show me around"],
      model: "showcase",
    });
    await t3.open(thread);
    await expect(screen.getByText("This turn is a replay", { exact: false })).toBeVisible();

    const composer = screen.getByRole("textbox");
    await composer.tap();
    await composer.pressSequentially("Show me again");
    await composer.press("Enter");
    await expect(screen.getByRole("button", "Stop generation")).toBeVisible();

    await composer.pressSequentially("Check ");
    await pastePng(browser, RED_PIXEL);
    const resolvedChip = composer.getByRole("button", "Image attachment", { exact: false });
    await expect(resolvedChip).toHaveCount(1);

    await browser.keyboard.press("ControlOrMeta+Enter");
    const editQueued = screen.getByRole("button", "Edit queued message");
    await expect(editQueued).toBeVisible();

    // Stopping the active turn holds the queued message so the turn cannot finish mid-edit.
    await screen.getByRole("button", "Stop generation").tap();
    await expect(screen.getByRole("button", "Resume thread")).toBeVisible();

    await editQueued.tap();
    await expect(screen.getByRole("button", "Cancel editing queued message")).toBeVisible();
    await app.screenshot("queued-edit-composer");
    await expect(resolvedChip).toHaveCount(1);

    // Clicking the resolved chip opens the expanded image preview.
    await resolvedChip.tap();
    const closePreview = screen.getByRole("button", "Back, close image preview");
    await expect(closePreview).toBeVisible();
    await closePreview.tap();
    await expect(closePreview).not.toBeVisible();

    // Edit text around the chip, save, and re-open edit to confirm round-trip persistence.
    await composer.tap();
    await composer.press("End");
    await composer.pressSequentially(" closely");
    await screen.getByRole("button", "Update queued message").tap();
    await expect(screen.getByRole("button", "Cancel editing queued message")).not.toBeVisible();
    await expect(screen.getByText("closely", { exact: false })).toBeVisible();

    await editQueued.tap();
    await expect(screen.getByRole("button", "Cancel editing queued message")).toBeVisible();
    await expect(resolvedChip).toHaveCount(1);

    // Removing the thumbnail also strips its inline chip instead of leaving it unavailable.
    await screen.getByRole("button", "Remove image.png").tap();
    await expect(resolvedChip).toHaveCount(0);
    await expect(composer.getByText("image.png")).toHaveCount(0);
  },
);
  1. Focused checks & per-file revert proof:
    • vp run check:changed: passed all 7 checks (format, lint with 0 warnings/errors, knip, typecheck across 2 packages, 48/48 tests across 4 files, React compiler 5/5).
    • Reverting each of the 5 changed source files individually to origin/main caused its covering test or scenario to fail (composerContextRecords.ts & composerContextPresentation.tsx -> composerContextPresentation.test.ts; queuedMessageEdit.ts -> queuedMessageEdit.test.ts; useQueuedRunEdit.ts -> useQueuedRunEdit.browser.test.tsx; ChatComposer.tsx -> queued-edit-keeps-pasted-image-chip.e2e.ts).
  2. Unaffected related paths:
    • vp run scenarios --target web scenarios/queued-edit-keeps-thread-mention.e2e.ts scenarios/distinct-same-size-pasted-images-both-attach.e2e.ts: both passed on the fix.

Needs more than a Linux VM

None — the entire bug and verification reproduce in headless web with Replay (dev) and no provider account.

Written with Gemini 4 Neon in T3 Code (Antigravity harness).

…gg#40874)

Co-authored-by: Abhiram-745 <237478249+Abhiram-745@users.noreply.github.com>
Co-authored-by: Julius Marminge <julius0216@outlook.com>
@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:L labels Nov 22, 2026
juliusmarminge and others added 5 commits November 22, 2026 06:41
…nder its full name (pingdotgg#40877)

Co-authored-by: Abhiram-745 <237478249+Abhiram-745@users.noreply.github.com>
Co-authored-by: Julius Marminge <julius0216@outlook.com>
…l finds no match (pingdotgg#40886)

Co-authored-by: Julius Marminge <julius0216@outlook.com>
Co-authored-by: Abhiram-745 <237478249+Abhiram-745@users.noreply.github.com>
Co-authored-by: Julius Marminge <julius0216@outlook.com>
@smirea
smirea force-pushed the fix/edit-message-pasted-image branch from 7f69469 to 86fa8d0 Compare November 22, 2026 15:47
@github-actions github-actions Bot added size:XL and removed size:L labels Nov 22, 2026
…ingdotgg#40858)

Co-authored-by: LVC-Chakresh <chakresh@example.com>
Co-authored-by: Julius Marminge <julius0216@outlook.com>
@smirea
smirea force-pushed the fix/edit-message-pasted-image branch from 88252b9 to 9250d74 Compare November 22, 2026 16:29
juliusmarminge and others added 16 commits November 22, 2026 08:31
Co-Authored-By: stefan <steven.mirea@gmail.com>
…ource

Co-Authored-By: stefan <steven.mirea@gmail.com>
…atching

Co-Authored-By: stefan <steven.mirea@gmail.com>
Co-Authored-By: stefan <steven.mirea@gmail.com>
…istory

Co-Authored-By: stefan <steven.mirea@gmail.com>
Co-Authored-By: stefan <steven.mirea@gmail.com>
…ions

Co-Authored-By: stefan <steven.mirea@gmail.com>
…tion

Co-Authored-By: stefan <steven.mirea@gmail.com>
@smirea
smirea force-pushed the fix/edit-message-pasted-image branch from 918e482 to 252f4d8 Compare November 22, 2026 17:02
@github-actions github-actions Bot added size:XXL and removed size:XL labels Nov 22, 2026
@smirea

smirea commented Nov 22, 2026

Copy link
Copy Markdown
Owner Author

Moved upstream to pingdotgg#40945 (fixes pingdotgg#40944).

@smirea smirea closed this Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XXL vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants