Skip to content

fix(client-runtime): images read from paths with %, # or ? show their preview - #7

Closed
smirea wants to merge 3 commits into
mainfrom
fix/viewed-image-percent-path
Closed

smirea wants to merge 3 commits into
mainfrom
fix/viewed-image-percent-path

Conversation

@smirea

@smirea smirea commented Nov 24, 2026 •

Copy link
Copy Markdown
Owner

Note

Claude Opus 5.5 writing on behalf of Stefan.

Problem

When an agent reads an image whose path contains %, # or ?, the work log shows "Image unavailable" instead of the image. Grok hits this on every image it generates, because it saves them under ~/.grok/sessions/%2FUsers%2F<user>%2F<workspace>/<session>/images/N.jpg. That directory name literally contains %2F. resolveViewedImageAsset passes the tool's raw path through markdown destination resolution, which URL-decodes it (%2F → /) and treats # and ? as the start of a fragment or query. The client then asks the server for …/sessions//Users/<user>/…/1.jpg, which doesn't exist.

Change

resolveViewedImageAsset now escapes %, # and ? (new helper viewedImageMarkdownSource) before running the existing markdown classification, so the decoding step gives back the literal path the tool reported. A file: URL is left as it is and still decodes. Workspace-relative joining, Windows paths and the network-path block all behave as before. On mobile, renderViewedImage builds the image's actions source (Copy full path, Open in file viewer) from the same escaped source, so those actions get the literal path too. Markdown images in messages still decode their destinations as they did. Only work-log viewed images change, because their paths come from tool input (viewedImagePath from Claude, Codex and ACP Reads, or a Read row's detail).

Scope

Fixes #ISSUE

This covers every route that shows a viewed image: the web work-group image strip and expanded Read row (TimelineWorkEntryRow.tsx), and the mobile strip and work-log row (ThreadFeed.tsx renderViewedImage). All of them go through resolveViewedImageAsset. Desktop uses the web client. Markdown images in assistant messages are left alone on purpose, because their destinations really are URL-encoded.

Open PR pingdotgg#41930 also changes viewed-image previews, so that each Read shows its stored output image. I ran the scenario below on its head (1276053356) and it still fails, since a call without a stored image falls back to this same path resolution.

Verification

Re-runnable on a Linux VM with no provider account:

  • A unit test in packages/client-runtime/src/work-log/presentation.test.ts checks that a path containing %2F, # and ? resolves to a media-file resource with the literal path. It fails on main: the received path has %2F decoded to /.
  • A real-app scenario (source below) uses a local ACP agent that reports a read of a PNG at <project>/sessions/%2Fhome%2Fme%2Fdemo/images/1.png. vp run scenarios:prove … --base origin/main printed: Proven: the scenario fails on base 01962d4c0b and passes on head c8e96aec57.
Base (main) Head (this PR)
Base: Image unavailable Head: image renders
  • A second unit case checks that file:///repo/my%20shot.png still resolves to /repo/my shot.png.
  • On mobile, I passed /repo/sessions/%2Fhome%2Fme/images/1.png through resolveMarkdownMediaPreview(viewedImageMarkdownSource(path)) in a throwaway test. The actions reference came back as the literal path; without the helper it was /repo/sessions//home/me/images/1.png. I did not run the iOS app itself.
  • vp run check:changed passes. When I reverted presentation.ts alone, the unit test failed.

Needs a real Grok account (found on macOS): a live Grok thread generated images with its image tool and then Read them from ~/.grok/sessions/%2FUsers%2F…/images/1.jpg through 4.jpg. The thread showed "Image unavailable". Those files exist on disk, and the client asks for the %2F-decoded path. Grok's own adapter isn't involved: the scenario reproduces the same client path with a generic ACP agent.

Scenario: scripts/scenarios/viewed-image-percent-path.e2e.ts
/// <reference lib="dom" />
// @effect-diagnostics nodeBuiltinImport:off -- The scenario stages a local ACP executable.
import * as NodeFSP from "node:fs/promises";
import * as NodePath from "node:path";

import { expect } from "e2e";

import { T3_HOME } from "../e2e.config.ts";
import { makeState, runPromise, test, WEB } from "./t3.ts";

// Grok keeps generated images under a directory named after the encoded workspace path.
const IMAGE = "sessions/%2Fhome%2Fme%2Fdemo/images/1.png";
const PNG = Buffer.from(
  "iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAIAAABvFaqvAAAAH0lEQVR4nGN4YGBAFcQwatCoQaMGjRo0atCoQQNvEADjR9AfT4sUJwAAAABJRU5ErkJggg==",
  "base64",
);
const ACP = `
import { createInterface } from "node:readline";

const [file] = process.argv.slice(2);
const sessionId = "viewed-image-scenario";
const send = (message) => process.stdout.write(JSON.stringify({ jsonrpc: "2.0", ...message }) + "\\n");
const update = (update) => send({ method: "session/update", params: { sessionId, update } });
for await (const line of createInterface({ input: process.stdin })) {
  const { id, method } = JSON.parse(line);
  if (id === undefined) continue;
  if (method === "initialize") {
    send({ id, result: { protocolVersion: 1, agentInfo: { name: "image-agent", version: "1.0.0" }, agentCapabilities: {}, authMethods: [] } });
  } else if (method === "session/new") {
    send({ id, result: { sessionId } });
  } else if (method === "session/prompt") {
    update({ sessionUpdate: "tool_call", toolCallId: "read-1", title: "Read", kind: "read", status: "in_progress", rawInput: { file_path: file } });
    update({ sessionUpdate: "tool_call_update", toolCallId: "read-1", kind: "read", status: "completed", rawInput: { file_path: file }, rawOutput: "Viewed image" });
    update({ sessionUpdate: "agent_message_chunk", content: { type: "text", text: "Looked at the image." } });
    send({ id, result: { stopReason: "end_turn" } });
  } else {
    send({ id, error: { code: -32601, message: "Method not found" } });
  }
}
`;

test(
  "An image the agent read from a directory with %2F in its name shows its preview",
  WEB,
  async ({ t3, app, browser, screen }) => {
    const project = await t3.project("demo", { [IMAGE]: PNG });
    const script = NodePath.join(project, "image-acp.mjs");
    const settingsPath = NodePath.join(T3_HOME, "userdata/settings.json");
    const originalSettings = await NodeFSP.readFile(settingsPath, "utf8");
    const settings = JSON.parse(originalSettings);
    await NodeFSP.writeFile(script, ACP);
    settings.providerInstances["image-agent"] = {
      driver: "acpRegistry",
      displayName: "Image Agent",
      enabled: true,
      config: {
        source: "local",
        commandPath: process.execPath,
        commandArgs: [script, NodePath.join(project, IMAGE)],
      },
    };
    try {
      await NodeFSP.writeFile(settingsPath, JSON.stringify(settings));
      const { cli } = makeState(T3_HOME);
      // The watcher reloads settings asynchronously. Retry only before a thread was created.
      let threadId: string | undefined;
      for (let attempt = 0; attempt < 8 && threadId === undefined; attempt++) {
        const started = await runPromise(
          cli(
            [
              "thread",
              "start",
              project,
              "Look at the image.",
              "--title",
              "Viewed image",
              "--provider",
              "image-agent",
              "--model",
              "default",
              "--json",
            ],
            [0, 1],
          ),
        );
        if (!started.stdout.includes("threadId")) continue;
        threadId = (JSON.parse(started.stdout) as { threadId: string }).threadId;
      }
      if (threadId === undefined) throw new Error("Could not start the image agent's turn.");

      await t3.open({ threadId });
      await expect(screen.getByText("Looked at the image.")).toBeVisible({ timeout: 60_000 });
      await screen.getByRole("button", /^Worked for/).tap();
      const loaded = async () =>
        browser.evaluate(() => {
          const unavailable = [...document.querySelectorAll("span")].some((span) =>
            span.textContent?.startsWith("Image unavailable"),
          );
          const image = [...document.querySelectorAll("img")].find(
            (img) => img.alt === "1.png" && img.complete && img.naturalWidth > 0,
          );
          return unavailable ? "unavailable" : image ? "loaded" : "pending";
        });
      let state = await loaded();
      for (let attempt = 0; attempt < 50 && state === "pending"; attempt++) {
        await new Promise((resolve) => setTimeout(resolve, 200));
        state = await loaded();
      }
      await app.screenshot("viewed-image");
      expect(state).toBe("loaded");
    } finally {
      await NodeFSP.writeFile(settingsPath, originalSettings);
    }
  },
);

Claude Opus 5.5 via Claude Code.

… no longer swaps which video plays (pingdotgg#42331)

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:XS size:S and removed size:XS labels Nov 24, 2026
smirea and others added 2 commits November 24, 2026 13:23
… preview

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ill decode

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@smirea
smirea force-pushed the fix/viewed-image-percent-path branch from 160a77e to f62ae31 Compare November 24, 2026 19:24
@smirea

smirea commented Nov 24, 2026

Copy link
Copy Markdown
Owner Author

Opened upstream as pingdotgg#42369 (issue pingdotgg#42368).

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

Labels

size:S 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.

2 participants