Skip to content

fix(cpp): preserve serialized session content parts - #3658

Merged
kovtcharov-amd merged 2 commits into
amd:mainfrom
kovtcharov:codex/review-vision-session
Sep 25, 2026
Merged

kovtcharov-amd merged 2 commits into
amd:mainfrom
kovtcharov:codex/review-vision-session

Conversation

@kovtcharov

@kovtcharov kovtcharov commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

The C++ SessionStore saved image-bearing messages but discarded their images on load, so anything that handed it multimodal history got text back. Its save/load round trip now preserves ordered text and image parts and rejects malformed ones, while legacy text and tool histories stay readable.

This is the loader half of #3642, not the whole issue. The agent strips image parts from its own history at the end of every turn, so a session saved straight from agent.history() still has no images in it to reload. Retaining them across turns means carrying base64 into every subsequent request, which is the trade the stripping contract was written to avoid — worth deciding on its own rather than inside this fix. #3642 stays open for that.

Test plan

  • 104 native session, vision, message and REPL tests pass in the Visual Studio build; the two new cases fail on baseline.
  • Real disk save/load cycles preserve image-only and mixed/multiple-image messages, and a resumed Agent sends the preserved history to a real localhost HTTP server.
  • Maintainer review and CI completion.

@github-actions

Copy link
Copy Markdown
Contributor

Request changes

The loader change is good work — saved sessions now keep image content in order instead of silently flattening it to text, and the tests around it are genuinely thorough. The problem is the other half of the reported bug: nothing in the shipped app ever writes an image into a session file, so a user still can't resume a vision conversation and keep the pictures.

The agent deliberately drops image parts from its conversation history at the end of every turn ("text-only retention by contract"), and the REPL saves exactly that history when it exits. So after resuming a vision session and asking one question, the next save writes text-only again — the "saving the resumed session permanently loses that context" half of #3642 is still live. Either extend the fix to the save side (a real decision, since retaining base64 images across turns grows every subsequent request), or drop the Closes #3642 so the issue stays open for that follow-up, and soften the PR/header wording that says saved sessions now retain image parts.

Worth adding before merge: a run through the actual REPL — start a vision session, exit, resume, ask about the image — since that is the path where this gap shows up and where the unit tests can't reach.

Real-world evidence

No evidence bundle was produced for this PR (evidence-bundle.md absent), so the verdict rests on static review plus the test counts the description reports from a local Visual Studio build. I couldn't build the C++ target here — the CMake setup fetches nlohmann/json, httplib and googletest over the network, which this runner doesn't allow — so I did not independently execute the new tests. The surface this touches is the C++ REPL (a CLI surface), and a real resume-and-ask transcript is the evidence that's missing; it is also the check that would have surfaced the save-side gap above.

🔍 Technical details

🟡 Important

The deserializer fix can't be reached by the product's own save path (cpp/src/session.cpp:127-162)

ReplRunner::saveSession() persists agent_.history() (cpp/src/repl.cpp:206-211), and processQueryInternal runs stripImageParts over every message — resumed history included — just before assigning conversationHistory_ (cpp/src/agent.cpp:1433-1436, contract documented at cpp/include/gaia/agent.h:308 and pinned by AgentVlmTest.ProcessQueryWithImagesStripsFromHistory). Consequences:

  • A session file written by gaia never contains an image_url part, so the new load branch only fires for hand-written files.
  • The new ResumedVisionHistoryReachesCompletionRequest test proves load → request works, but it seeds history from a hand-built file rather than from a prior processQuery. A version that saved agent.history() after the turn would fail, which is exactly C++ session-store loading drops serialized image content parts #3642's second sentence.

This is a scope/claim call, not a defect in the diff: either lift the stripping for persistence (and accept the per-turn base64 growth the contract was written to avoid), or re-scope the issue closure. The header doc at cpp/include/gaia/session.h:55 and the PR body both currently read as if the end-to-end behaviour is fixed.

🟢 Minor

Part errors don't name the file they came from (cpp/src/session.cpp:137, :144, :153, :158) — load() adds the path for JSON parse failures (:239) but not for these, so the REPL surfaces bare Unsupported message content part type: audio with no session id, file, or message index. Cheapest fix is to wrap the call site:

    std::vector<Message> history;
    history.reserve(j["messages"].size());
    for (size_t i = 0; i < j["messages"].size(); ++i) {
        try {
            history.push_back(messageFromJson(j["messages"][i]));
        } catch (const std::runtime_error& e) {
            throw std::runtime_error("Session file '" + path + "' message " +
                                     std::to_string(i) + ": " + e.what());
        }
    }
    return history;

A content that is neither string nor array is still silently dropped (cpp/src/session.cpp:128-162) — {"content": 7} or {"content": {...}} falls through both branches and yields an empty message. Given the PR's whole point is rejecting malformed content explicitly, an else if (!j["content"].is_null()) throw closes the gap and matches the no-silent-fallback rule. (null must stay tolerated — the assistant tool-call shape depends on it.)

Session list preview is blank for vision sessions (cpp/src/session.cpp:305-317) — list() reads a preview only when content is a string, so /history shows an empty line for exactly the multimodal sessions this PR makes worth keeping. Pre-existing, but adjacent enough to fold in: joining the text parts would give these sessions a usable preview.

Strengths

  • The validation is fail-loudly in the way CLAUDE.md asks for — each rejected shape names the field that's wrong, replacing a branch that used to quietly discard data.
  • RejectMalformedContentParts is a proper table-driven negative test with the offending payload in the failure message, and LegacyTextAndNativeToolHistoryRemainCompatible pins backward compatibility for unversioned envelopes and native tool_calls.
  • Driving the resumed history through MockLlmServer and asserting on the real outgoing request body is the right level to test at — it checks the wire shape, not just the in-memory struct.
  • Purely additive: no signature or file-format change, so old sessions keep loading.

@kovtcharov kovtcharov changed the title fix(cpp): preserve images in resumed sessions fix(cpp): preserve serialized session content parts Sep 11, 2026
The round trip preserves image parts the caller supplies, but the agent's
history is text-only by contract, so a session saved from it still reloads
without images. Says so at save(), where an SDK reader would otherwise take
the load() guarantee as end-to-end, and amd#3642 stays open for the retention
decision — keeping base64 across turns grows every later request, which is
what the stripping contract exists to avoid.
@kovtcharov-amd

Copy link
Copy Markdown
Collaborator

Took the second option — the claim is now scoped to what the diff does, and #3642 stays open for the retention decision.

You were right that the two halves are separable, and the second one is a real trade rather than a follow-up chore: keeping image parts in the agent history means carrying base64 into every later request, which is exactly what the stripping contract was written to avoid. That deserves its own decision, not a quiet extension of a loader fix.

So: Closes #3642 is gone, the PR description leads with the limitation instead of burying it in a collapsed block, and save() now carries the caveat in the header — that is where an SDK reader would otherwise take load()'s "preserving ordered text/image parts" as an end-to-end guarantee.

Left alone: the 🟢 about part errors not naming their source file. It is a fair point, but I can't build the C++ target here — CMake fetches nlohmann/json, httplib and googletest over the network — so I would be pushing an unverified change to a surface whose tests I cannot run. Better as a follow-up by someone with the toolchain, or I can do it if you want it in this PR and are happy to let CI be the first compile.

@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Sep 25, 2026
Merged via the queue into amd:main with commit 4bb0a42 Sep 25, 2026
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants