Skip to content

fix(responses): keep attachment-only user items text-less for userMessage matching - #611

Merged
contextablemark merged 3 commits into
mainfrom
fix/responses-attachment-only-user-text
Nov 10, 2026
Merged

contextablemark merged 3 commits into
mainfrom
fix/responses-attachment-only-user-text

Conversation

@contextablemark

@contextablemark contextablemark commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Some SDKs send a single multimodal user turn to /v1/responses as two consecutive user items: the prompt as input_text, then the attachment alone as input_image or input_file. AG2 1.1.2's OpenAI Responses mapper does this (ag2/config/openai/mappers.py).

getLastUserText already skips a trailing user message with no text, for this exact split on the Chat Completions path. But the Responses converter flattened the attachment-only item to "". The guard deliberately treats "" as real text, so userMessage fixtures keyed on the prompt never matched, and strict mode returned 503.

Attachment-only user items now convert to content: null, the same text-less shape the Chat Completions path produces. An explicit empty input_text still converts to "". System, assistant and tool-output conversion are unchanged.

Impact

This makes the CopilotKit showcase's ag2 multimodal cells red on staging (CopilotKit PNI-796). Both the image and PDF prompts get a 503 "no fixture matched".

aimock split turn (AG2 shape) same content as one item
1.37.4 503 200
1.47.0 503 200
this branch 200 200

Test plan

  • New unit tests in responsesInputToMessages: attachment-only items become null, and an explicit empty input_text stays "".
  • New strict-mode end-to-end tests: a prompt followed by an input_image item, and by an input_file item, both match their fixtures. These failed with 503 before the fix.
  • pnpm run format:check, pnpm run lint, pnpm run typecheck, pnpm build, and pnpm api:report (no report change).
  • pnpm run test: 20,064 passed. The one failure is response-a9-equivalence, which fails the same way on main on this machine with "A9 hard-ceiling witness requires 2 GiB free memory".
  • After release: bump the showcase aimock pin and run a local D6 probe for ag2:multimodal to confirm red→green.

🤖 Generated with Claude Code

…sage matching

AG2's OpenAI Responses mapper sends one multimodal turn as a text-only user
item followed by an attachment-only one. The Responses converter flattened the
attachment-only item to "", which getLastUserText treats as real text, so
userMessage fixtures keyed on the prompt never matched and strict mode
returned 503. Such items now convert to null content, matching how the Chat
Completions path already handles the same split.
@pkg-pr-new

pkg-pr-new Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@copilotkit/aimock@611

commit: 1476c7a

@contextablemark
contextablemark marked this pull request as ready for review November 10, 2026 23:57

@jpr5 jpr5 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good: attachment-only Responses user items now convert to the same text-less shape as the Chat Completions path, with strict-mode end-to-end tests for the image and file cases.

@contextablemark
contextablemark merged commit f9c9955 into main Nov 10, 2026
29 checks passed
@contextablemark
contextablemark deleted the fix/responses-attachment-only-user-text branch November 10, 2026 23:58
@jpr5 jpr5 mentioned this pull request Nov 11, 2026
jpr5 added a commit that referenced this pull request Nov 11, 2026
**Merging this publishes @copilotkit/aimock 1.48.0 to npm and
aimock-pytest 0.7.2 to PyPI.**

## [1.48.0] - 2026-11-10

### Added

- A2A `onConversation()` scripts multi-turn tasks that ask for input,
then complete (#591)
- Record and replay native citations and annotations from real provider
turns (#594)
- Record and replay BytePlus Seed Speech TTS, ElevenLabs Scribe and
Audio Isolation (#601)

### Changed

- `aimock-pytest` 0.7.2 defaults to `@copilotkit/aimock` 1.48.0

### Fixed

- A2A Get/CancelTask return task as `result`; split Responses attachment
turns match (#595, #611)

## Version carriers (from `git grep -F 1.47.0`)

Bumped to 1.48.0:
- `package.json` version
- `charts/aimock/Chart.yaml` appVersion
- `.claude-plugin/plugin.json` version
- `.claude-plugin/marketplace.json` source version (`^1.48.0`)
- `docs/index.html` banner
- `packages/aimock-pytest/README.md` `--aimock-version` default
- `packages/aimock-pytest/src/aimock_pytest/_version.py`
`AIMOCK_VERSION`

Also bumped: `packages/aimock-pytest/pyproject.toml` 0.7.1 → 0.7.2,
because the pin moved (same pattern as #589).

Left as is (not carriers): the `## [1.47.0]` CHANGELOG heading, the
three "New in 1.47.0" notes in `docs/docs/index.html`, and the three
"1.47.0+" notes in the `docs/index.html` comparison matrix. These mark
when a feature first shipped.

## README

#601 added docs to the speech page but not to the README. This PR adds:
- Seed Speech, Scribe and Audio Isolation to the LLMock row and the
Multimedia APIs line
- `AIMOCK_PROVIDER_BYTEPLUS_SPEECH_KEY` to the upstream-key table

The CHANGELOG `#600` reference is corrected to `#601`. #600 is not a PR.

The other features already have docs: A2A conversations (#591), citation
recording (#594) and the GetTask result shape (#595). The package.json
description is synced from the README subtitle on publish.

## Local checks
- `pnpm install --frozen-lockfile`, `format:check`, `lint`, `typecheck`,
`build`: pass
- `api:report`: 14 entries, 0 failed, no report change
- `vitest run`: 488 files, 20,073 passed, 11 skipped (includes the docs
tests)
- `pytest` in `packages/aimock-pytest` against the local build: 251
passed
@linear-code

linear-code Bot commented Nov 11, 2026

Copy link
Copy Markdown

PNI-796

JadeCong pushed a commit to CloudEngineHub/CopilotKit that referenced this pull request Nov 11, 2026
AG2's OpenAI Responses mapper sends a prompt and its attachment as two user
items. aimock before 1.48.0 read the attachment-only item as empty text, so the
ag2 multimodal fixtures never matched and strict mode returned 503
(CopilotKit/aimock#611, PNI-796).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
JadeCong pushed a commit to CloudEngineHub/CopilotKit that referenced this pull request Nov 11, 2026
…pilotKit#8324)

## Summary

This bumps the showcase aimock base image to **1.48.0**
(`sha256:51d8e426…`, from `sha256:fcc50103…`) so the `ag2` multimodal
cells can go green on staging. It is a one-line change to
`showcase/aimock/Dockerfile`.

**Cause.** AG2 1.1.2's OpenAI Responses mapper sends one turn with an
attachment as two user items: the prompt as `input_text`, then the
attachment alone as `input_image` or `input_file`. aimock before 1.48.0
read the attachment-only item as empty text instead of no text, so it
never fell back to the prompt. The `ag2` multimodal fixtures never
matched, and strict mode returned 503 "no fixture matched". The fix is
CopilotKit/aimock#611, released in v1.48.0. This closes PNI-796.

The 1.48.0 release also includes the other unreleased aimock changes
since 1.47.0: A2A `onConversation()`, citation record/replay, the audio
record/replay routes, and an A2A result-shape fix. See the aimock
CHANGELOG.

## Evidence

The same isolated local stack, probe and fixtures were used for both
runs. Only the aimock image changed.

| aimock image | `bin/showcase test ag2:multimodal --d6 --direct` |
aimock strict misses |
|---|---|---|
| current pin `fcc50103…` | red: `InternalServerError` banner, 0 turns |
6 |
| 1.48.0 `51d8e426…` | **green**: 2 turns (image + PDF), 7.8s | 0 |

The production image builds from this Dockerfile: the Node donor check
passes (v22.23.4), and `/app/package.json` reports 1.48.0.

Red→green cells: `d6:ag2/multimodal`, proven locally.
`d5:ag2/multimodal` failed on staging with the same 503, so it should
also clear, but I have not verified it.

## Not in this PR

`showcase/scripts/package.json` still pins `@copilotkit/aimock` 1.37.4
for the local/CI frontend-matrix runner. Bumping it changes the lockfile
and moves every matrix cell up 11 minor versions, so it should be a
separate PR.

## After merge

- Check the `showcase-aimock` staging deploy picked up the new image,
then read PocketBase `d6:ag2/multimodal` (and D5) for a fresh green
probe recorded after the deploy.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
contextablemark added a commit to CopilotKit/CopilotKit that referenced this pull request Nov 11, 2026
The frontend-matrix, on-demand e2e, integration-docs and Mastra remote A2UI
workflows run llmock from showcase/scripts. 1.37.4 lacks CopilotKit/aimock#611,
so the AG2 multimodal cell fails there with a strict no-fixture-match 503,
the same bug #8324 fixed for the staging aimock image.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
jpr5 pushed a commit that referenced this pull request Nov 26, 2026
…ompt (#639)

Applies the #611 shape to Anthropic Messages, Gemini generateContent and
Interactions, Bedrock invoke and Converse, and Cohere v2. A user message
whose parts hold no text part converts to null, so getLastUserText falls
back to the prompt before it. An explicit empty text part, string content
and an empty part list keep their current values.
jpr5 added a commit that referenced this pull request Nov 26, 2026
…emini, Bedrock and Cohere (#643)

When a client sends one prompt as a text message followed by an image
only message, `userMessage` fixtures now match on Anthropic, Gemini,
Bedrock and Cohere v2 the same way they already do on OpenAI.

**What this code is for**

Each provider handler turns its request body into the shared
`ChatMessage[]` list before fixture matching, for example
`claudeToCompletionRequest` in `src/messages.ts`.
[`getLastUserText`](https://github.com/CopilotKit/aimock/blob/b5499e2c5db8d2dbf66887a9397a73bab7cecc3c/src/router.ts#L172-L179)
then picks the text a `userMessage` fixture is compared against: it
skips trailing user messages whose content is `null` and stops at the
first one that has a string, including `""`.

**Before this PR**

A test using a strict LLMock with the fixture `{ match: { userMessage:
"what is in this image" } }` sends one turn to `POST /v1/messages` as
two user messages: the prompt, then a message holding only an image
block.

1. `claudeToCompletionRequest` converts the prompt message to `{ role:
"user", content: "what is in this image" }`.
2. It converts the image only message with
[`extractClaudeTextContent`](https://github.com/CopilotKit/aimock/blob/b5499e2c5db8d2dbf66887a9397a73bab7cecc3c/src/messages.ts#L150-L157),
which finds no `text` block and returns `""`.
3. `getLastUserText` reaches that last message first, sees `""`, and
returns it as the user text.
4. No fixture matches `""`, so strict mode answers **503 "Strict mode:
no fixture matched"**.

The same thing happens in the [Gemini generateContent user
branch](https://github.com/CopilotKit/aimock/blob/b5499e2c5db8d2dbf66887a9397a73bab7cecc3c/src/gemini.ts#L219-L223),
Gemini Interactions ([`user_input`
steps](https://github.com/CopilotKit/aimock/blob/b5499e2c5db8d2dbf66887a9397a73bab7cecc3c/src/gemini-interactions.ts#L269-L275)
and [role
turns](https://github.com/CopilotKit/aimock/blob/b5499e2c5db8d2dbf66887a9397a73bab7cecc3c/src/gemini-interactions.ts#L255-L263)),
[Bedrock
invoke](https://github.com/CopilotKit/aimock/blob/b5499e2c5db8d2dbf66887a9397a73bab7cecc3c/src/bedrock.ts#L122-L129),
[Bedrock
Converse](https://github.com/CopilotKit/aimock/blob/b5499e2c5db8d2dbf66887a9397a73bab7cecc3c/src/bedrock-converse.ts#L506-L511)
and [Cohere
v2](https://github.com/CopilotKit/aimock/blob/b5499e2c5db8d2dbf66887a9397a73bab7cecc3c/src/cohere.ts#L146-L155).
OpenAI Chat Completions and Responses (after #611) already return 200.

**After this PR**

Same test, same request.

1. Same as above for the prompt message.
2. The image only message has no text block, so
`extractClaudeUserContent` returns `null` instead of `""`.
3. `getLastUserText` skips the `null` message and returns `"what is in
this image"` from the message before it.
4. The fixture matches and the request gets **200** with "A logo.".
5. A message that does carry a text block, even `{ type: "text", text:
"" }`, still converts to `""`, so fixtures keyed on an empty body behave
as before.

```mermaid
flowchart LR

classDef box fill:#eef1ff,stroke:#4c5bd4,color:#111827
classDef bad fill:#ffd6d6,stroke:#cc0000,color:#111827,stroke-width:3px
classDef good fill:#c8f0c8,stroke:#008800,color:#111827,stroke-width:3px

subgraph BEFORE["BEFORE: 503 on 6 provider paths"]
direction TB
  B1["user: prompt, then user: image only"] --> B2["provider converter"]
  B2 --> B3{"image only message"}
  B3 -->|"content becomes empty string"| B4["getLastUserText returns empty string"]
  B4 --> B5["no fixture matched, 503"]
  B3 -->|"message with a text part"| B6["text kept"]
end

subgraph AFTER["AFTER: 200, same as OpenAI"]
direction TB
  A1["user: prompt, then user: image only"] --> A2["provider converter"]
  A2 --> A3{"THE CHANGE: no text part means null"}
  A3 -->|"image only message is null"| A4["getLastUserText skips it, returns prompt"]
  A4 --> A5["userMessage fixture matches, 200"]
  A3 -->|"explicit empty text part"| A6["still empty string, as before"]
end

B1 ~~~ A1

class B1,B2,B6 box
class A1,A2,A6 box
class B3,B4,B5 bad
class A3,A4,A5 good

linkStyle 2 stroke:#cc0000,stroke-width:5px
linkStyle 7 stroke:#008800,stroke-width:5px

style BEFORE fill:#fff5f5,stroke:#cc0000,color:#111827
style AFTER fill:#f3fff3,stroke:#008800,color:#111827
```

![getLastUserText focus
view](https://raw.githubusercontent.com/abhiramshaji-cyber/Architect/594a49f1054f48cc3020feb48a5083d24fc56924/aimock-639/getLastUserText.png)
getLastUserText with its one caller matchFixtureDiagnostic and its one
callee getTextContent, Functions view in
[Architect](https://github.com/abhiramshaji-cyber/Architect)

![extractClaudeUserContent focus
view](https://raw.githubusercontent.com/abhiramshaji-cyber/Architect/594a49f1054f48cc3020feb48a5083d24fc56924/aimock-639/extractClaudeUserContent.png)
extractClaudeUserContent called by claudeToCompletionRequest and calling
extractClaudeTextContent, Functions view in
[Architect](https://github.com/abhiramshaji-cyber/Architect)

**The change**

Every user message converter now applies the #611 rule: when the message
content is a list of parts and none of them is a text part, the content
is `null`; otherwise it is the joined text as before.

- `src/messages.ts`: new `extractClaudeUserContent`, used for plain
Anthropic user messages.
- `src/bedrock.ts`: new `extractUserContent`, used for plain Bedrock
invoke user messages.
- `src/cohere.ts`: new `extractUserContent`, used for Cohere v2 user
messages.
- `src/gemini.ts`: the plain user branch returns `null` when `textParts`
is empty.
- `src/gemini-interactions.ts`: both the `user_input` step and the user
role turn return `null` when there is no `text` part.
- `src/bedrock-converse.ts`: the plain user message returns `null` when
no block has a `text` key. A block with `text: ""` still counts, so it
stays `""`.

String content, missing content, an empty part list, tool result
messages, system and assistant messages are untouched, so the existing
tests that pin `""` for those (for example `handles Step[] user_input
with empty content`) still pass. The new
`src/__tests__/split-image-turns.test.ts` runs the same three checks on
each of the seven paths (Interactions has two input formats): a strict
server returns 200 for the split turn, the converter gives `[prompt,
null]`, and an explicit empty text part stays `""`. On main the first
two fail on every path (14 failures, 503 and `""`), and all 21 pass on
this branch.

**What changes for a user**

- A split prompt plus image turn now matches its `userMessage` fixture
on Anthropic Messages, Gemini generateContent, Gemini Interactions,
Bedrock invoke, Bedrock Converse and Cohere v2, the same as OpenAI Chat
Completions and Responses.
- Fixtures keyed on an explicit empty text body still see `""`, as you
asked.
- Single message turns, multi message turns where every message has
text, and tool result turns match exactly as before.
- Converse is included for consistency, as you suggested, even though
real Converse clients rarely send this split.
- Ollama `/api/chat` is left alone, since its `content` is always a
string, so `""` there is what the client sent.

One question: the Gemini Live WebSocket has the same plain user branch
in `src/ws-gemini-live.ts`. It wasn't in your list so I kept it out, but
would you like it in this PR too? Happy to add it either way.

Thanks again @jpr5 for the quick go ahead and for pointing at the #611
shape, it made this one really easy to line up.

Closes #639
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.

2 participants