Repository navigation
fix(gateway): images sent to Claude CLI sessions show as raw cache-path links in chat history - #130463
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 28, 2026, 6:55 PM ET / 22:55 UTC. ClawSweeper reviewWhat this changesThe PR adds an opaque per-turn marker to Claude CLI image prompts and suppresses only the matching imported cache-path row when merging it with OpenClaw’s local image-bearing transcript row. Merge readinessNo blocking correctness finding: the PR repairs the current-main duplicate-history path with exact local-turn correlation. It remains open for protected maintainer handling because it deliberately establishes prospective history-display policy for Claude CLI image turns. Priority: P1 Review scores
Verification
How this fits togetherThe CLI runner converts inbound images to local paths for Claude CLI, which records the altered prompt in its JSONL history. Gateway history import then merges that external transcript with the local transcript before chat clients display it. flowchart LR
A[Inbound image turn] --> B[Local transcript row]
A --> C[Claude CLI prompt]
C --> D[Claude JSONL history]
B --> E[History merge]
D --> E
E --> F[Gateway chat history]
Decision needed
Why: The code proves the narrow behavior and avoids ambiguous deletion, but choosing this durable user-visible history policy requires owner intent. Before merge
Agent review detailsSecurityNone. PR surfaceSource +171, Tests +536. Total +707 across 8 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep the exact prospective correlation design after an owner confirms that preserving legacy/orphaned rows while suppressing only new marker-bearing duplicates is the intended session-history policy. Do we have a high-confidence way to reproduce the issue? Yes, source-reproducible: current main merges the altered Claude CLI prompt as a distinct user row, while the supplied isolated-Gateway scenario exercises that same path. This read-only review did not execute the scenario, and GitHub attachment retrieval was unavailable locally. Is this the best way to solve the issue? Yes, subject to the explicit history-policy decision: exact persisted-turn correlation is safer than parser-time deletion or text/timestamp inference because it preserves unmatched and pre-marker imports. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 3c00dbc71bfe. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (13 earlier review cycles; latest 8 shown)
|
|
Addressed the P1 in 09bbd3d with the recommended merge-time correlation: mention-only imported rows are no longer deleted at parse time. The importer keeps their original content and tags them |
|
Live before/after UI evidence is now attached in the PR body: one real image turn on an isolated dev gateway ( |
09bbd3d to
5ae6b20
Compare
5ae6b20 to
a2ebc4c
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
@clawsweeper review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
ef35b45 to
62f0dc1
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
…CLI user rows The CLI runner appends @<.openclaw-cli-images path> mention lines to prompts for backends that read images from disk. Claude Code records that mutated prompt as its user message, so the transcript importer re-surfaced it as a duplicate user row that failed text dedupe against the local row carrying the media facts — showing inbound images as raw path links instead of previews. Strip trailing image cache mention lines from imported user rows (string and text-block content) and drop rows left empty, so imported rows dedupe into the local row that already renders the thumbnail.
…ia merge-time correlation Address ClawSweeper P1: the importer no longer drops image-only user rows at parse time, where it cannot know whether a local media-bearing counterpart survives. Mention-only rows keep their original content and are tagged with __openclaw.cliImageMentionOnly; mergeImportedChatHistoryMessages suppresses a tagged row only when a local user row carrying image media facts falls within the existing dedupe timestamp window. With local history reset or lost, the imported turn is retained instead of silently disappearing.
… safety ratchet The assertion-safety ratchet flags uncommented non-const assertions beyond each file's baseline. Narrow imported block and metadata access through asOptionalRecord instead of inline casts; the one remaining cast into normalizeMediaFacts carries its SAFETY invariant.
62f0dc1 to
82b345f
Compare
…th links in chat history (openclaw#130463) * fix(gateway): strip CLI-injected image mentions from imported Claude CLI user rows The CLI runner appends @<.openclaw-cli-images path> mention lines to prompts for backends that read images from disk. Claude Code records that mutated prompt as its user message, so the transcript importer re-surfaced it as a duplicate user row that failed text dedupe against the local row carrying the media facts — showing inbound images as raw path links instead of previews. Strip trailing image cache mention lines from imported user rows (string and text-block content) and drop rows left empty, so imported rows dedupe into the local row that already renders the thumbnail. * fix(gateway): preserve orphaned mention-only Claude CLI image turns via merge-time correlation Address ClawSweeper P1: the importer no longer drops image-only user rows at parse time, where it cannot know whether a local media-bearing counterpart survives. Mention-only rows keep their original content and are tagged with __openclaw.cliImageMentionOnly; mergeImportedChatHistoryMessages suppresses a tagged row only when a local user row carrying image media facts falls within the existing dedupe timestamp window. With local history reset or lost, the imported turn is retained instead of silently disappearing. * chore(gateway): replace new type assertions with record narrowing for safety ratchet The assertion-safety ratchet flags uncommented non-const assertions beyond each file's baseline. Narrow imported block and metadata access through asOptionalRecord instead of inline casts; the one remaining cast into normalizeMediaFacts carries its SAFETY invariant. * fix(gateway): require image history timestamp correlation * fix(gateway): consume image history matches once * fix(gateway): preserve orphaned CLI image captions * fix(gateway): retain ambiguous CLI image turns * fix(gateway): correlate Claude image turns exactly * test(gateway): document legacy image row retention
What Problem This Solves
Fixes an issue where users sending images to a Claude CLI-backed session would see the image appear in WebChat/Control UI chat history as a raw path link (for example
@/…/.openclaw-cli-images/<sha>.png) instead of the inline thumbnail preview that API-backed models show, plus a duplicate user row for the same turn.Why This Change Was Made
The CLI runner cannot pass structured image blocks to the Claude CLI, so it appends
@<image cache path>mention lines to the prompt it hands the CLI. Claude Code records that mutated prompt as its user message, and the transcript importer merges it back into chat history, where it does not text-dedupe against OpenClaw's local media-bearing user row.For new image turns, the runner now adds an opaque correlation key derived from the persisted local transcript entry ID. The Claude transcript importer records that key, and history merge suppresses the imported cache-path row only when it exactly matches the local media-bearing turn. Genuine user-typed
@pathmentions outside the cache directories are untouched. Ambiguous rows, malformed markers, repeated candidates, and imported rows whose local counterpart no longer exists all fail open and remain visible.Pre-marker Claude transcript rows cannot be correlated safely. They are intentionally retained, even when caption and timestamp resemble a local image turn, because inference could suppress a distinct user turn. This is a prospective exact-correlation fix rather than a migration or self-healing policy for legacy rows.
User Impact
New images sent to Claude CLI-backed conversations render as inline previews in chat history without a duplicate raw cache-path user row. Sessions whose local transcript was reset or lost keep their imported image turns visible. Existing pre-marker conversations retain their legacy raw-path rows until a separate loss-safe legacy policy exists.
Evidence
Live before/after on an isolated dev gateway
Procedure: isolated profile (
--profile evd, own state dir, port 23117, never the operator gateway), modelclaude-cli/claude-sonnet-5. One real image turn sent throughchat.send(the same RPC the composer uses); the Claude CLI ran, wrote the content-addressed cache image, recorded the@path-mutated prompt in its project JSONL, and the session got itsclaude-clibinding.Before — gateway built from the PR's merge base (
116f364b505): the imported CLI transcript row fails dedupe and renders as a duplicate user bubble with the raw cache filename link:Target rendering — the correlated row is removed and the local media-bearing row renders as one user bubble with the inline thumbnail; the assistant reply remains intact:
These captures predate the final exact-correlation refinement. They demonstrate the original defect and target rendering, while current-head automated coverage proves marker-bearing suppression and intentional legacy-row retention. They do not claim that pre-marker histories self-heal.
Tests and checks
src/gateway/cli-session-history.test.tscovers exact producer-marker correlation, same-caption disambiguation, one-time candidate consumption, malformed markers, orphan retention, mention stripping in string/text-block content, and legacy captioned/cache-only rows retained beside nearby local media-bearing turns.node scripts/run-vitest.mjs run --config test/vitest/vitest.gateway.config.ts src/gateway/cli-session-history.test.ts— 198 passed across the gateway core/server/client projects.node scripts/run-tsgo-core-test-shards.mjs src— clean;oxlintandoxfmt --checkclean on changed files.