Skip to content

SWF(bug): keep Anthropic text and image order - #86

Merged
maplepaladin73 merged 1 commit into
mainfrom
devin/1795402112-anthropic-content-order
Nov 23, 2026
Merged

maplepaladin73 merged 1 commit into
mainfrom
devin/1795402112-anthropic-content-order

Conversation

@maplepaladin73

@maplepaladin73 maplepaladin73 commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

Summary

Anthropic [text, image, text] content blocks were lowered as [image, joined text], and the chat-template JSON then grouped media markers before text again. Lowering and rendering now keep the client's text/media interleaving end to end.

No tracking issue (TASK-68).

Test plan

  • cargo fmt --all -- --check
  • ATLAS_SKIP_BUILD=1 CUDARC_CUDA_VERSION=13000 cargo clippy --workspace --tests
  • bash scripts/check-license-headers.sh
  • ~/.local/bin/typos
  • ATLAS_SKIP_BUILD=1 CUDARC_CUDA_VERSION=13000 cargo test -p spark-server --bin spark — 3269 passed, 14 ignored
  • Added regression tests; GPU/model output not tested (CPU-only box)

Failing → passing:

  • Before: ATLAS_SKIP_BUILD=1 CUDARC_CUDA_VERSION=13000 cargo test -p spark-server --bin spark anthropic::tests::to_ir_blocks::user_text_image_text_preserves_wire_order -- --exact failed with content: [Image(...), Text("beforeafter")], left: 2, right: 3.
  • After: the same command passes, and api::chat::template::json_message_tests::text_and_media_parts_render_in_content_order passes.

Try it: ATLAS_SKIP_BUILD=1 CUDARC_CUDA_VERSION=13000 cargo test -p spark-server --bin spark user_text_image_text_preserves_wire_order -- --exact (after bash scripts/ci_gpu_stubs.sh on a GPU-less host).

Notes for reviewers

  • anthropic/to_ir.rs: assistant/user text blocks now flush into ContentPart::Text around image parts; adjacent text still joins with no separator. Tool-result payloads keep the existing images-then-joined-text layout because they carry one flattened text payload.
  • api/chat/msg_entry.rs: MsgEntry now stores ordered parts (Text/Media) instead of a flat content string plus a media list; prompt-pipeline appends (hints, CWD, repeat notices, error masks) preserve media positions.
  • api/chat/template.rs: JSON content arrays emit text/media markers in that same order. Moved the JSON-message tests to template/json_message_tests.rs to stay under the 500-LoC cap.
  • Untested: real GPU/model output (CPU-only); OpenAI lowering is unchanged and still media-first because its parser flattens text.

CLA


Software Factory opened this PR for Robert
Implemented in session Keep Anthropic text and image order
Review with Devin · Open in Devin Desktop


Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@maplepaladin73
maplepaladin73 merged commit cc940ca into main Nov 23, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant