Skip to content

fix(gateway): preserve attachment order in chat history - #121980

Merged
steipete merged 3 commits into
mainfrom
steipete/native-video-durability
Aug 11, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/native-video-durability

Conversation

@steipete

@steipete steipete commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where mixed chat attachments could be reordered in durable history: a turn submitted as video then image was persisted as image then video. The same producer could assign the image layout to the wrong media fact, retain host-local paths beside managed claims, or silently lose an inline image from history when its durable save failed.

Why This Change Was Made

Gateway attachment persistence now carries each attachment's original request index through the byte-to-managed-media boundary, combines saved inline images with existing offloads, and sorts once before writing transcript facts. Durable facts are projected from trusted media-store IDs as claim-only media://inbound/... references; live/plugin path ownership remains transient and separate. Failed inline-image persistence remains nonfatal to the live turn but records a visible durable omission instead of disappearing silently.

This is the ordered-media durability slice extracted from the native-video work. It does not enable provider video input or widen agent, plugin, worker, protocol, config, or storage schemas.

AI-assisted; implementation and review were performed with coding agents under maintainer supervision.

User Impact

Chat history and sessions_history preserve the original order of mixed managed attachments. Operators no longer get a misleading attachment order after reload, and new transcript rows do not retain local media paths or signed/original URLs. If an inline image works for the live turn but cannot be durably saved, history says so explicitly.

Evidence

  • Pre-fix regression reproduced [video, image] persisting as [image, video].
  • Attachment and user-turn tests: 57 passed.
  • Node-event tests: 72 passed.
  • Gateway history integration: 98 passed.
  • Broad directive-tag owner shard after claim-only expectation updates: 189 passed.
  • chat.history and sessions_history preserve [video, image], use image factIndex: 1, and expose managed claims only.
  • Blacksmith Testbox changed gate passed: tbx_01kzr1f84x7dd8b2sgncfs1rsx.
  • Exact-head hosted CI passed: https://github.com/openclaw/openclaw/actions/runs/31481187813
  • Mandatory autoreview completed with no accepted/actionable findings after the final test repair.
  • git diff --check passed.
  • Production LOC: +120/-125, net -5; tests: +412/-112; generated/docs/lockfiles: zero.

Known scope boundary: historical rows are not migrated; the existing history privacy projection continues to sanitize them.

@clawsweeper

clawsweeper Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@steipete
steipete marked this pull request as ready for review August 11, 2026 09:41
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: L maintainer Maintainer-authored PR labels Aug 11, 2026
@steipete steipete self-assigned this Aug 11, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Command router queued. I will update this comment with the next step.

@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready proof for 84248349abdb73ae9db669af355e020c826c4040.

Root cause and owner: Gateway attachment persistence reconstructed durable media through an image-only ordinal (imageOrder) and appended non-image offloads afterward. That producer-owned reconstruction changed [video, image] into [image, video], could assign the image layout to the wrong media fact index, retained host paths beside managed references, and logged-but-dropped an inline image whose durable save failed.

Canonical fix: parseMessageWithAttachments records the authoritative source index on inline and offloaded attachments. persistInboundImagesForTranscript is now the single durable producer: it validates trusted SavedMedia.id values, projects claim-only media://inbound/... facts, merges and sorts once by source index, and returns an explicit inline-save omission outcome. chat.send and node agent.request derive transcript media and the actual image factIndex from that ordered result. Live prompt and plugin-bound paths remain transient and separate.

Removed policy: the image-first/non-image-last reconstruction and durable path projection are gone. A failed inline durable save remains nonfatal to the live turn but records [image attachment omitted: durable managed media claim unavailable] in history.

Scope and size: production +120/-125 (net -5); tests +412/-112; generated/docs/lockfiles 0. No protocol, schema, config, SQLite, dependency, provider, worker, or Plugin SDK changes.

Focused proof:

  • node scripts/run-vitest.mjs src/gateway/chat-attachments.test.ts src/gateway/server-methods/chat-send-user-turn.test.ts — 57 passed.
  • node scripts/run-vitest.mjs src/gateway/server-node-events.test.ts — 72 passed.
  • node scripts/run-vitest.mjs src/gateway/server.chat.gateway-server-chat-b.test.ts — 98 passed.
  • node scripts/run-vitest.mjs src/gateway/server-methods/chat.directive-tags.test.ts — 189 passed.
  • Blacksmith Testbox changed gate — passed: tbx_01kzr1f84x7dd8b2sgncfs1rsx.
  • Exact-head CI — success at 84248349abdb73ae9db669af355e020c826c4040: https://github.com/openclaw/openclaw/actions/runs/31481187813
  • Fresh mandatory autoreview — clean, no accepted/actionable findings.
  • git diff --check origin/main...84248349abdb73ae9db669af355e020c826c4040 — passed.

History behavior: current main's producer groups saved inline images and image offloads by image ordinal, then appends remaining non-image media, so order is already wrong before transcript or display consumers see it. The repair records the authoritative fact at parsing time instead of compensating in history readers. Historical rows are intentionally not migrated; the existing chat.history / sessions_history privacy projection continues to sanitize those rows. New rows preserve [video, image], expose only managed claims, and use image factIndex: 1.

ClawSweeper: the only published review comments are review started placeholders for earlier heads c7d1d7f27aecb74c58bf81967d9e2fc1901c05ab and d54d5615fbac5adb10da9617c53855c3dba82f2e. No verdict, actionable finding, or Rank-up moves: list has been published, so there are no moves to apply or skip. One exact-head re-review was requested here: #121980 (comment)

Native review artifacts validate in PR-head mode with READY FOR /prepare-pr, issueValidation.status=valid, zero findings, and the guarded head equal to 84248349abdb73ae9db669af355e020c826c4040.

@steipete
steipete merged commit 9af35e7 into main Aug 11, 2026
127 checks passed
@steipete
steipete deleted the steipete/native-video-durability branch August 11, 2026 10:37
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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

Labels

gateway Gateway runtime maintainer Maintainer-authored PR size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant