Get up and running with Kimi, GLM, MiniMax, DeepSeek, gpt-oss, Qwen, Gemma and other models.
openai: preserve images through response compaction (#18245)
Parth Sareenb043d891c2df
diff --git a/openai/responses_compact.go b/openai/responses_compact.goindex 29f3b211e..af41f6c61 100644--- a/openai/responses_compact.go+++ b/openai/responses_compact.go@@ -3,11 +3,13 @@ package openaiimport ("bytes""crypto/sha256"+ "encoding/base64""encoding/hex""encoding/json""errors""fmt""io"+ "net/http""strings""time"@@ -60,9 +62,11 @@ type compactionToolMetadata struct {Description string `json:"description,omitempty"`}-type compactionTranscript struct {- Items []CompactionTranscriptItem `json:"items"`- Tools []compactionToolMetadata `json:"tools,omitempty"`+type compactionTranscriptItemWire struct {+ Ref string `json:"ref"`+ Type string `json:"type"`+ Message api.Message `json:"message"`+ ImageCount int `json:"image_count,omitempty"`}type compactionToolGroup struct {@@ -326,10 +330,6 @@ func payloadToResponsesItems(payload OllamaCompactionPayload) ([]json.RawMessage}func messageToResponsesItems(message api.Message) ([]json.RawMessage, error) {- if len(message.Images) > 0 {- return nil, errors.New("retained images are not supported")- }-var values []anyif message.Thinking != "" {values = append(values, map[string]any{@@ -342,6 +342,9 @@ func messageToResponsesItems(message api.Message) ([]json.RawMessage, error) {return nil, errors.New("retained tool message is missing tool_call_id")}if message.ToolName == "tool_search" {+ if len(message.Images) > 0 {+ return nil, errors.New("retained tool search output cannot contain images")+ }var tools []json.RawMessageif err := json.Unmarshal([]byte(message.Content), &tools); err != nil {return nil, fmt.Errorf("retained tool search output is invalid: %w", err)@@ -351,13 +354,21 @@ func messageToResponsesItems(message api.Message) ([]json.RawMessage, error) {"execution": "client", "status": "completed", "tools": tools,})} else {+ output, err := responsesContentValue(message.Content, message.Images)+ if err != nil {+ return nil, err+ }values = append(values, map[string]any{- "type": "function_call_output", "call_id": message.ToolCallID, "output": message.Content,+ "type": "function_call_output", "call_id": message.ToolCallID, "output": output,})}- } else if message.Content != "" || len(message.ToolCalls) == 0 {+ } else if message.Content != "" || len(message.Images) > 0 || len(message.ToolCalls) == 0 {+ content, err := responsesContentValue(message.Content, message.Images)+ if err != nil {+ return nil, err+ }values = append(values, map[string]any{- "type": "message", "role": message.Role, "content": message.Content,+ "type": "message", "role": message.Role, "content": content,})}for _, call := range message.ToolCalls {@@ -391,6 +402,41 @@ func messageToResponsesItems(message api.Message) ([]json.RawMessage, error) {return items, nil}+func responsesContentValue(text string, images []api.ImageData) (any, error) {+ if len(images) == 0 {+ return text, nil+ }++ content := make([]any, 0, len(images)+1)+ if text != "" {+ content = append(content, map[string]any{"type": "input_text", "text": text})+ }+ for _, image := range images {+ block, err := responsesImageContent(image)+ if err != nil {+ return nil, err+ }+ content = append(content, block)+ }+ return content, nil+}++func responsesImageContent(image api.ImageData) (map[string]any, error) {+ if len(image) == 0 {+ return nil, errors.New("retained image is empty")+ }+ mimeType := http.DetectContentType(image)+ switch mimeType {+ case "image/jpeg", "image/png", "image/webp":+ default:+ return nil, fmt.Errorf("retained image has unsupported content type %q", mimeType)+ }+ return map[string]any{+ "type": "input_image", "detail": "auto",+ "image_url": "data:" + mimeType + ";base64," + base64.StdEncoding.EncodeToString(image),+ }, nil+}+func newResponsesCompactionPlan(req rawResponsesRequest, rawItems []json.RawMessage) (*ResponsesCompactionPlan, error) {if len(rawItems) == 0 {return nil, errors.New("compaction input is empty")@@ -406,9 +452,6 @@ func newResponsesCompactionPlan(req rawResponsesRequest, rawItems []json.RawMessif err != nil {return nil, fmt.Errorf("input[%d]: %w", i, err)}- if len(message.Images) > 0 {- return nil, fmt.Errorf("input[%d]: image inputs are not supported by compaction", i)- }items = append(items, CompactionTranscriptItem{Ref: fmt.Sprintf("item_%06d", i+1), Type: kind, Message: message,})@@ -427,6 +470,9 @@ func newResponsesCompactionPlan(req rawResponsesRequest, rawItems []json.RawMessfunc compactionMessage(item ResponsesInputItem) (api.Message, string, error) {switch value := item.(type) {case ResponsesInputMessage:+ if err := validateCompactionContent(value.Content); err != nil {+ return api.Message{}, "", err+ }message, err := convertInputMessage(value)return message, "message", errcase ResponsesFunctionCall:@@ -444,6 +490,9 @@ func compactionMessage(item ResponsesInputItem) (api.Message, string, error) {content := value.Outputvar images []api.ImageDataif len(value.OutputItems) > 0 {+ if err := validateCompactionContent(value.OutputItems); err != nil {+ return api.Message{}, "", err+ }var err errorcontent, images, err = convertResponsesContent(value.OutputItems)if err != nil {@@ -486,6 +535,22 @@ func compactionMessage(item ResponsesInputItem) (api.Message, string, error) {}}+func validateCompactionContent(contents []ResponsesContent) error {+ for _, content := range contents {+ image, ok := content.(ResponsesImageContent)+ if !ok {+ continue+ }+ if image.FileID != "" {+ return errors.New("file_id image inputs are not supported by Ollama compaction")+ }+ if image.ImageURL == "" {+ return errors.New("compaction image input is missing image_url")+ }+ }+ return nil+}+func analyzeCompactionToolState(items []CompactionTranscriptItem) ([]compactionToolGroup, map[string]struct{}, error) {type pendingGroup struct {callIndex int@@ -587,23 +652,22 @@ func collectCompactionToolMetadata(tools []ResponsesTool) []compactionToolMetadafunc (p *ResponsesCompactionPlan) SummaryRequest(repairError string) ([]byte, error) {// TODO(compaction): enforce the 40% retained-context target after the// selected model's prompt renderer and token budget are available here.- transcript, err := json.Marshal(compactionTranscript{Items: p.items, Tools: p.tools})+ transcript, err := p.summaryTranscriptMessages()if err != nil {return nil, err}- prompt := `Summarize the conversation for another coding agent. Preserve the goal, decisions, constraints, repository state, changed files, test results, failures, active work, and next actions. Use retain_item_ids only for exact source items that cannot safely be paraphrased. Tool calls and results are execution state; do not invent or edit them. Call create_summary exactly once.`+ prompt := `Summarize the conversation for another coding agent. Preserve the goal, decisions, constraints, repository state, changed files, test results, failures, active work, and next actions. After optional tool metadata, each following user message is one ordered transcript item: its JSON input_text describes the source item, and its input_image blocks belong to that item. Use retain_item_ids for exact source items, including images, that cannot safely be paraphrased. Tool calls and results are execution state; do not invent or edit them. Call create_summary exactly once.`if repairError != "" {prompt += " Your previous create_summary call was invalid: " + repairError + ". Return one corrected create_summary call."}description := "Return the compact summary and the exact input item references that must remain verbatim."strict := true+ input := []any{map[string]any{"type": "message", "role": "system", "content": prompt}}+ input = append(input, transcript...)request := map[string]any{"model": p.Model,- "input": []any{- map[string]any{"type": "message", "role": "system", "content": prompt},- map[string]any{"type": "message", "role": "user", "content": string(transcript)},- },+ "input": input,"tools": []ResponsesTool{{Type: "function", Name: CreateSummaryToolName, Description: &description, Strict: &strict,Parameters: map[string]any{@@ -624,6 +688,41 @@ func (p *ResponsesCompactionPlan) SummaryRequest(repairError string) ([]byte, erreturn json.Marshal(request)}+func (p *ResponsesCompactionPlan) summaryTranscriptMessages() ([]any, error) {+ messages := make([]any, 0, len(p.items)+1)+ if len(p.tools) > 0 {+ metadata, err := json.Marshal(struct {+ Tools []compactionToolMetadata `json:"tools"`+ }{Tools: p.tools})+ if err != nil {+ return nil, err+ }+ messages = append(messages, map[string]any{"type": "message", "role": "user", "content": string(metadata)})+ }++ for _, item := range p.items {+ message := item.Message+ images := message.Images+ message.Images = nil+ metadata, err := json.Marshal(compactionTranscriptItemWire{+ Ref: item.Ref, Type: item.Type, Message: message, ImageCount: len(images),+ })+ if err != nil {+ return nil, err+ }+ content := []any{map[string]any{"type": "input_text", "text": string(metadata)}}+ for _, image := range images {+ block, err := responsesImageContent(image)+ if err != nil {+ return nil, fmt.Errorf("%s: %w", item.Ref, err)+ }+ content = append(content, block)+ }+ messages = append(messages, map[string]any{"type": "message", "role": "user", "content": content})+ }+ return messages, nil+}+// Complete validates create_summary and builds the stateless continuation.func (p *ResponsesCompactionPlan) Complete(body []byte) (ResponsesCompactionResult, error) {var response ResponsesResponsediff --git a/openai/responses_compact_test.go b/openai/responses_compact_test.goindex df262acf5..68757da92 100644--- a/openai/responses_compact_test.go+++ b/openai/responses_compact_test.go@@ -44,6 +44,36 @@ func decodeResultPayload(t *testing.T, result ResponsesCompactionResult) OllamaCreturn payload}+func summaryTranscriptText(t *testing.T, requestBody []byte) string {+ t.Helper()+ var request struct {+ Input []struct {+ Content json.RawMessage `json:"content"`+ } `json:"input"`+ }+ if err := json.Unmarshal(requestBody, &request); err != nil {+ t.Fatal(err)+ }+ var transcript strings.Builder+ for _, input := range request.Input[1:] {+ var text string+ if json.Unmarshal(input.Content, &text) == nil {+ transcript.WriteString(text)+ continue+ }+ var blocks []struct {+ Text string `json:"text"`+ }+ if err := json.Unmarshal(input.Content, &blocks); err != nil {+ t.Fatal(err)+ }+ for _, block := range blocks {+ transcript.WriteString(block.Text)+ }+ }+ return transcript.String()+}+func TestPrepareTriggeredCompactionBuildsSummaryRequest(t *testing.T) {description := "Read a file"body := []byte(`{@@ -76,8 +106,7 @@ func TestPrepareTriggeredCompactionBuildsSummaryRequest(t *testing.T) {}var request struct {Input []struct {- Role string `json:"role"`- Content string `json:"content"`+ Role string `json:"role"`} `json:"input"`Tools []ResponsesTool `json:"tools"`Instructions string `json:"instructions"`@@ -95,11 +124,12 @@ func TestPrepareTriggeredCompactionBuildsSummaryRequest(t *testing.T) {if len(request.Tools) != 1 || request.Tools[0].Name != CreateSummaryToolName {t.Fatalf("unexpected callable tools: %+v", request.Tools)}- if len(request.Input) != 2 || !strings.Contains(request.Input[1].Content, description) || !strings.Contains(request.Input[1].Content, "read_file") {+ transcript := summaryTranscriptText(t, requestBody)+ if len(request.Input) != 5 || !strings.Contains(transcript, description) || !strings.Contains(transcript, "read_file") {t.Fatalf("summary transcript is missing tool metadata: %+v", request.Input)}- if strings.Contains(request.Input[1].Content, `"instructions"`) {- t.Fatalf("original instructions leaked into transcript: %s", request.Input[1].Content)+ if strings.Contains(transcript, `"instructions"`) {+ t.Fatalf("original instructions leaked into transcript: %s", transcript)}result, err := plan.Complete(compactionResponseBody(t, map[string]any{@@ -135,24 +165,217 @@ func TestCompactionNamesBuiltInSearchToolMetadata(t *testing.T) {t.Fatalf("prepare: requested=%v err=%v", requested, err)}+ requestBody, err := plan.SummaryRequest("")+ if err != nil {+ t.Fatal(err)+ }+ transcript := summaryTranscriptText(t, requestBody)+ if !strings.Contains(transcript, `"name":"tool_search"`) ||+ !strings.Contains(transcript, `"name":"web_search"`) {+ t.Fatalf("summary transcript is missing built-in tool names: %s", requestBody)+ }+ if strings.Contains(transcript, `"name":""`) {+ t.Fatalf("summary transcript contains unnamed tool metadata: %s", requestBody)+ }+}++const compactionTestPNG = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII="++func TestCompactionSendsImagesAsMultimodalInput(t *testing.T) {+ body := []byte(`{+ "model":"test","stream":true,+ "input":[+ {"type":"message","role":"user","content":[+ {"type":"input_text","text":"describe this"},+ {"type":"input_image","detail":"auto","image_url":"` + compactionTestPNG + `"}+ ]},+ {"type":"compaction_trigger"}+ ]+ }`)+ plan, requested, err := PrepareTriggeredCompaction(body)+ if err != nil || !requested {+ t.Fatalf("prepare: requested=%v err=%v", requested, err)+ }+requestBody, err := plan.SummaryRequest("")if err != nil {t.Fatal(err)}var request struct {Input []struct {- Content string `json:"content"`+ Content json.RawMessage `json:"content"`} `json:"input"`}if err := json.Unmarshal(requestBody, &request); err != nil {t.Fatal(err)}- if len(request.Input) != 2 || !strings.Contains(request.Input[1].Content, `"name":"tool_search"`) ||- !strings.Contains(request.Input[1].Content, `"name":"web_search"`) {- t.Fatalf("summary transcript is missing built-in tool names: %s", requestBody)+ if len(request.Input) != 2 {+ t.Fatalf("input count=%d, want 2", len(request.Input))}- if strings.Contains(request.Input[1].Content, `"name":""`) {- t.Fatalf("summary transcript contains unnamed tool metadata: %s", requestBody)+ var blocks []struct {+ Type string `json:"type"`+ Text string `json:"text"`+ ImageURL string `json:"image_url"`+ }+ if err := json.Unmarshal(request.Input[1].Content, &blocks); err != nil {+ t.Fatal(err)+ }+ if len(blocks) != 2 || blocks[0].Type != "input_text" || blocks[1].Type != "input_image" {+ t.Fatalf("unexpected transcript blocks: %+v", blocks)+ }+ if !strings.Contains(blocks[0].Text, `"ref":"item_000001"`) || !strings.Contains(blocks[0].Text, `"image_count":1`) {+ t.Fatalf("image is not associated with its source item: %s", blocks[0].Text)+ }+ if strings.Contains(blocks[0].Text, "iVBOR") || blocks[1].ImageURL != compactionTestPNG {+ t.Fatalf("image must be a real image block, not transcript text: %+v", blocks)+ }+ var responsesRequest ResponsesRequest+ if err := json.Unmarshal(requestBody, &responsesRequest); err != nil {+ t.Fatal(err)+ }+ chatRequest, err := FromResponsesRequest(responsesRequest)+ if err != nil {+ t.Fatal(err)+ }+ if len(chatRequest.Messages) != 2 || len(chatRequest.Messages[1].Images) != 1 || !strings.Contains(chatRequest.Messages[1].Content, "item_000001") {+ t.Fatalf("local Responses conversion lost the image-to-item association: %+v", chatRequest.Messages)+ }+}++func TestCompactionImageRetentionIsModelSelectedAndReplayed(t *testing.T) {+ body := []byte(`{+ "model":"test","stream":true,+ "input":[+ {"type":"message","role":"user","content":[{"type":"input_image","detail":"auto","image_url":"` + compactionTestPNG + `"}]},+ {"type":"message","role":"assistant","content":"I inspected it."},+ {"type":"compaction_trigger"}+ ]+ }`)+ plan, requested, err := PrepareTriggeredCompaction(body)+ if err != nil || !requested {+ t.Fatalf("prepare: requested=%v err=%v", requested, err)+ }++ t.Run("selected", func(t *testing.T) {+ result, err := plan.Complete(compactionResponseBody(t, map[string]any{+ "summary": "The image was inspected.", "retain_item_ids": []string{"item_000001"},+ }))+ if err != nil {+ t.Fatal(err)+ }+ payload := decodeResultPayload(t, result)+ if len(payload.Retained) != 1 || len(payload.Retained[0].Images) != 1 {+ t.Fatalf("selected image was not retained: %+v", payload.Retained)+ }+ request, err := json.Marshal(map[string]any{"model": "test", "input": []any{result.Item}})+ if err != nil {+ t.Fatal(err)+ }+ expanded, changed, err := ExpandResponsesCompactionInput(request)+ if err != nil || !changed {+ t.Fatalf("expand: changed=%v err=%v", changed, err)+ }+ if !bytes.Contains(expanded, []byte(`"type":"input_image"`)) || !bytes.Contains(expanded, []byte(compactionTestPNG)) {+ t.Fatalf("retained image was not replayed as Responses content: %s", expanded)+ }+ })++ t.Run("not selected", func(t *testing.T) {+ result, err := plan.Complete(compactionResponseBody(t, map[string]any{+ "summary": "The image was inspected.", "retain_item_ids": []string{},+ }))+ if err != nil {+ t.Fatal(err)+ }+ if payload := decodeResultPayload(t, result); len(payload.Retained) != 0 {+ t.Fatalf("unselected image was retained: %+v", payload.Retained)+ }+ })+}++func TestCompactionReplaysRetainedToolOutputImagesWithTheirCall(t *testing.T) {+ body := []byte(`{+ "model":"test","stream":true,+ "input":[+ {"type":"function_call","call_id":"call_1","name":"screenshot","arguments":"{}"},+ {"type":"function_call_output","call_id":"call_1","output":[+ {"type":"input_text","text":"captured"},+ {"type":"input_image","detail":"auto","image_url":"` + compactionTestPNG + `"}+ ]},+ {"type":"message","role":"assistant","content":"done"},+ {"type":"compaction_trigger"}+ ]+ }`)+ plan, requested, err := PrepareTriggeredCompaction(body)+ if err != nil || !requested {+ t.Fatalf("prepare: requested=%v err=%v", requested, err)+ }+ summaryRequest, err := plan.SummaryRequest("")+ if err != nil {+ t.Fatal(err)+ }+ if !bytes.Contains(summaryRequest, []byte(compactionTestPNG)) || !bytes.Contains(summaryRequest, []byte(`image_count\":1`)) {+ t.Fatalf("compactor request did not associate the tool image with its transcript item: %s", summaryRequest)+ }+ result, err := plan.Complete(compactionResponseBody(t, map[string]any{+ "summary": "A screenshot was captured.", "retain_item_ids": []string{"item_000002"},+ }))+ if err != nil {+ t.Fatal(err)+ }+ payload := decodeResultPayload(t, result)+ if len(payload.Retained) != 2 || len(payload.Retained[0].ToolCalls) != 1 || len(payload.Retained[1].Images) != 1 {+ t.Fatalf("tool call and image result were not retained together: %+v", payload.Retained)+ }+ items, err := payloadToResponsesItems(payload)+ if err != nil {+ t.Fatal(err)+ }+ if len(items) != 4 || rawInputItemType(items[2]) != "function_call" || rawInputItemType(items[3]) != "function_call_output" {+ t.Fatalf("tool pairing or order changed: %s", items)+ }+ if !bytes.Contains(items[3], []byte(`"type":"input_image"`)) || !bytes.Contains(items[3], []byte(compactionTestPNG)) {+ t.Fatalf("tool output image was not replayed: %s", items[3])+ }+}++func TestCompactionForcesActiveToolOutputImage(t *testing.T) {+ body := []byte(`{+ "model":"test","stream":true,+ "input":[+ {"type":"function_call","call_id":"call_1","name":"screenshot","arguments":"{}"},+ {"type":"function_call_output","call_id":"call_1","output":[{"type":"input_image","detail":"auto","image_url":"` + compactionTestPNG + `"}]},+ {"type":"compaction_trigger"}+ ]+ }`)+ plan, requested, err := PrepareTriggeredCompaction(body)+ if err != nil || !requested {+ t.Fatalf("prepare: requested=%v err=%v", requested, err)+ }+ result, err := plan.Complete(compactionResponseBody(t, map[string]any{+ "summary": "The screenshot tool just completed.", "retain_item_ids": []string{},+ }))+ if err != nil {+ t.Fatal(err)+ }+ payload := decodeResultPayload(t, result)+ if len(payload.Retained) != 2 || len(payload.Retained[1].Images) != 1 {+ t.Fatalf("active tool state and its image must be forced: %+v", payload.Retained)+ }+}++func TestCompactionRejectsUnsupportedImageSources(t *testing.T) {+ for name, image := range map[string]string{+ "file id": `{"type":"input_image","detail":"auto","file_id":"file_123"}`,+ "remote URL": `{"type":"input_image","detail":"auto","image_url":"https://example.com/image.png"}`,+ } {+ t.Run(name, func(t *testing.T) {+ body := []byte(`{"model":"test","stream":true,"input":[{"type":"message","role":"user","content":[` + image + `]},{"type":"compaction_trigger"}]}`)+ _, requested, err := PrepareTriggeredCompaction(body)+ if !requested || err == nil {+ t.Fatalf("requested=%v err=%v", requested, err)+ }+ })}}diff --git a/server/responses_compact_test.go b/server/responses_compact_test.goindex 02d654419..d4c9fd221 100644--- a/server/responses_compact_test.go+++ b/server/responses_compact_test.go@@ -159,6 +159,89 @@ func TestResponsesCompactUsesOrdinarySelectedCloudModel(t *testing.T) {}}+func TestResponsesCompactionPreservesSelectedImageIntoNextTurn(t *testing.T) {+ const imageURL = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII="+ local, capture := newCompactionTestServer(t, func(attempt int, w http.ResponseWriter, _ *http.Request, _ []byte) {+ w.Header().Set("Content-Type", "application/json")+ if attempt == 1 {+ _, _ = w.Write(summaryResponse(t, "Keep the source image available.", []string{"item_000001"}))+ return+ }+ _, _ = w.Write([]byte(`{"id":"resp_next","object":"response","status":"completed","model":"fixture","output":[],"usage":null}`))+ })++ status, _, body := postCompactionRequest(t, local, "/v1/responses/compact", `{+ "model":"fixture:cloud",+ "input":[{"type":"message","role":"user","content":[+ {"type":"input_text","text":"inspect this image"},+ {"type":"input_image","detail":"auto","image_url":"`+imageURL+`"}+ ]}]+ }`)+ if status != http.StatusOK {+ t.Fatalf("compact status=%d body=%s", status, body)+ }+ var compacted openai.ResponsesCompactedResponse+ if err := json.Unmarshal(body, &compacted); err != nil {+ t.Fatal(err)+ }+ if len(compacted.Output) != 1 {+ t.Fatalf("unexpected compact response: %+v", compacted)+ }++ request, err := json.Marshal(map[string]any{+ "model": "fixture:cloud", "stream": false,+ "input": []any{+ compacted.Output[0],+ map[string]any{"type": "message", "role": "user", "content": "what was in it?"},+ },+ })+ if err != nil {+ t.Fatal(err)+ }+ status, _, body = postCompactionRequest(t, local, "/v1/responses", string(request))+ if status != http.StatusOK {+ t.Fatalf("follow-up status=%d body=%s", status, body)+ }++ paths, bodies := capture.snapshot()+ if len(paths) != 2 || paths[0] != "/v1/responses" || paths[1] != "/v1/responses" {+ t.Fatalf("unexpected upstream requests: %v", paths)+ }+ var summaryRequest struct {+ Input []struct {+ Content json.RawMessage `json:"content"`+ } `json:"input"`+ }+ if err := json.Unmarshal(bodies[0], &summaryRequest); err != nil {+ t.Fatal(err)+ }+ if len(summaryRequest.Input) != 2 {+ t.Fatalf("unexpected summary input: %s", bodies[0])+ }+ var blocks []struct {+ Type string `json:"type"`+ Text string `json:"text"`+ ImageURL string `json:"image_url"`+ }+ if err := json.Unmarshal(summaryRequest.Input[1].Content, &blocks); err != nil {+ t.Fatal(err)+ }+ if len(blocks) != 2 || blocks[0].Type != "input_text" || blocks[1].Type != "input_image" || blocks[1].ImageURL != imageURL {+ t.Fatalf("compactor did not receive the source image as multimodal input: %+v", blocks)+ }+ if strings.Contains(blocks[0].Text, "iVBOR") {+ t.Fatalf("image bytes leaked into transcript text: %s", blocks[0].Text)+ }++ forwarded := string(bodies[1])+ if strings.Contains(forwarded, `"type":"compaction"`) {+ t.Fatalf("opaque compaction item reached the next model: %s", forwarded)+ }+ if strings.Count(forwarded, imageURL) != 1 || !strings.Contains(forwarded, `"type":"input_image"`) {+ t.Fatalf("selected image was not replayed exactly once on the next turn: %s", forwarded)+ }+}+func TestResponsesCompactionTriggerReturnsCodexStream(t *testing.T) {local, capture := newCompactionTestServer(t, func(_ int, w http.ResponseWriter, _ *http.Request, _ []byte) {w.Header().Set("Content-Type", "application/json")