fix(agent-core-v2): repair messages API history after resume - #1633
Conversation
🦋 Changeset detectedLatest commit: 394493a The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
commit: |
7954671 to
585127b
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 79546711e8
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| // Restored journal entries carry dehydrated `blobref:` media URLs while | ||
| // live emissions are inline — rehydrate through the agent's blob store so | ||
| // the messages API serves one shape (v1's `readWireTranscript`). |
There was a problem hiding this comment.
Remove new inline implementation comments
packages/agent-core-v2/AGENTS.md says comments must live solely in top-of-file /** */ blocks and never beside functions, methods, or statements. This new inline block in loadMessages narrates an implementation step inside the method, so it violates the package rule; please remove it or fold durable context into the file header.
Useful? React with 👍 / 👎.
- rehydrate restored `blobref:` media URLs to inline `data:` URIs from the agent's blob store, matching the shape of live emissions - pass tool results carrying media (e.g. ReadMediaFile) through as raw content parts instead of flattening them to empty text - use wire record times for `created_at`, nudged to stay strictly increasing, instead of a synthesized session-start offset - carry per-entry record times through `ContextTranscript` and the live-tail merge
585127b to
394493a
Compare
Related Issue
No linked issue — the problem is explained below.
Problem
The v2 messages API (
MessageLegacyService.list) served broken history for sessions read back from the record journal (e.g. after resume), diverging from v1'sreadWireTranscriptbehavior in three ways:blobref:media URLs, so images/audio/video in history were served as unresolvableblobref:links instead of the inlinedata:URIs that live emissions carry.ReadMediaFile) were flattened by joining only the text parts, so their media content collapsed to an empty string.created_atwas synthesized assession.createdAt + index, losing the real wire record time and producing timestamps that do not match v1 or the live event stream.What changed
Single fix commit on top of
origin/main, with tests:MessageLegacyServicerehydratesblobref:media URLs through the agent's blob store (IAgentBlobService.loadParts, mirroring v1'srehydrateBlobRefs); unresolvable refs fall back to the[media missing]placeholder, same as v1 and live replay.messageProjection.buildProtocolContentpasses tool results that carry media parts (image_url/video_url/audio_url) through as the raw kosong content-part array — the same shape the livetool.resultevent stream carries — while text-only results still flatten to joined text.reduceContextTranscriptnow carries the originating wire record time per entry (ContextTranscript.times);created_atuses that time, nudged to stay strictly increasing so cursor consumers keep a stable total order, falling back tosession.createdAt + indexfor entries without a source record (live tail).Tests: new cases in
test/app/messageLegacy/messageLegacy.test.ts(blobref rehydration, media tool-result pass-through, text flattening, record-timecreated_at) andtest/agent/contextMemory/contextTranscript.test.ts(per-entry record times); snapshot hash updates inloop.test.ts/tool.test.ts. Changeset included (patch).Checklist
gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.