Skip to content

fix(frontend): export chat handles compacted MESSAGES_SNAPSHOT events#1010

Merged
Gkrumbach07 merged 1 commit intoambient-code:mainfrom
derekhiggins:fix/export-chat-snapshot-support
Mar 24, 2026
Merged

fix(frontend): export chat handles compacted MESSAGES_SNAPSHOT events#1010
Gkrumbach07 merged 1 commit intoambient-code:mainfrom
derekhiggins:fix/export-chat-snapshot-support

Conversation

@derekhiggins
Copy link
Copy Markdown
Contributor

When users export a completed session's chat (as Markdown, PDF, or to Google Drive), only the initial prompt is included — the rest of the conversation is missing. This makes the export feature essentially unusable for reviewing or sharing finished sessions.

The root cause is that the backend compacts finished sessions by replacing streaming events (TEXT_MESSAGE_, TOOL_CALL_) with a single MESSAGES_SNAPSHOT event. The export code only knew how to process streaming events, so all conversation content was silently dropped after compaction.

Add blocksFromSnapshot() to extract conversation blocks from MESSAGES_SNAPSHOT messages, including tool calls and results. When a snapshot is present it takes priority over streaming events since it is the canonical source after compaction.

--
Done in ambient-code, Needs review (I got no knowledge of this codebase)

When users export a completed session's chat (as Markdown, PDF, or to
Google Drive), only the initial prompt is included — the rest of the
conversation is missing. This makes the export feature essentially
unusable for reviewing or sharing finished sessions.

The root cause is that the backend compacts finished sessions by
replacing streaming events (TEXT_MESSAGE_*, TOOL_CALL_*) with a single
MESSAGES_SNAPSHOT event. The export code only knew how to process
streaming events, so all conversation content was silently dropped
after compaction.

Add blocksFromSnapshot() to extract conversation blocks from
MESSAGES_SNAPSHOT messages, including tool calls and results.
When a snapshot is present it takes priority over streaming events
since it is the canonical source after compaction.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 24, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: b6637244-0afb-4344-9c6d-7761fe74efc5

📥 Commits

Reviewing files that changed from the base of the PR and between 7b6f4eb and 3e5b241.

📒 Files selected for processing (2)
  • components/frontend/src/utils/__tests__/export-chat.test.ts
  • components/frontend/src/utils/export-chat.ts

Walkthrough

The changes add support for handling MESSAGES_SNAPSHOT events in chat export functionality. A new SnapshotMessage type and blocksFromSnapshot() helper convert snapshot data into ConversationBlock structures, with snapshot messages taking precedence over streaming events when available. Comprehensive test coverage validates message content rendering, tool call embedding, error handling, and message ordering.

Changes

Cohort / File(s) Summary
Messages Snapshot Support
components/frontend/src/utils/export-chat.ts, components/frontend/src/utils/__tests__/export-chat.test.ts
Added SnapshotMessage type and blocksFromSnapshot() helper to convert MESSAGES_SNAPSHOT events to conversation blocks, including user/assistant messages, embedded tool calls, and tool results. Updated assembleBlocks() to detect and prioritize snapshot data over streaming events. Extensive test coverage for snapshot message handling, tool call rendering, error cases, message precedence, and conversation ordering.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title directly describes the main change: adding support for MESSAGES_SNAPSHOT event handling in the export-chat functionality, which is the core issue addressed in this PR.
Description check ✅ Passed The description clearly explains the problem (missing conversation content in exports), root cause (MESSAGES_SNAPSHOT compaction), and the solution (blocksFromSnapshot function), all directly related to the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Gkrumbach07 Gkrumbach07 merged commit b204abd into ambient-code:main Mar 24, 2026
27 of 28 checks passed
jeremyeder added a commit that referenced this pull request Mar 25, 2026
…me contributors (#1039)

## Summary

- **Group commits by author** with commit counts (e.g., "Gage Krumbach
(18)"), sorted by contribution count
- **Add "First-Time Contributors" section** with 🎉 emoji to celebrate
new contributors
- **Use Python** for reliable parsing of commit data with special
characters
- **Fix `--before` bug**: resolve tag to ISO date since `git log
--before` requires a date, not a ref name — passing a tag name silently
returns wrong results, causing incorrect first-timer detection

## Example Output (v0.0.34)

### Before (flat list):
```
- fix(frontend): resolve agent response buffering (#991) (de50276)
- fix(frontend): export chat handles compacted MESSAGES_SNAPSHOT events (#1010) (b204abd)
- fix(frontend): binary file download corruption (#996) (5b584f8)
...
```

### After (grouped by author):
```
## 🎉 First-Time Contributors

- Derek Higgins
- Pete Savage
- Rahul Shetty

### Gage Krumbach (5)
- fix(runner): improve ACP MCP tools (#1006) (26be0f9)
- chore(manifests): scale up frontend replicas (#1008) (b331da1)
...

### Pete Savage (1)
- fix(frontend): resolve agent response buffering (#991) (de50276)
```

## Bug Fix: `--before` with tag names

`git log --before=v0.0.33` does **not** filter by the tag's date — it
resolves differently and returns commits from after the tag. This caused
first-timer detection to produce wrong results. Fixed by resolving the
tag to its ISO date first:

```python
tag_date = subprocess.run(
    ['git', 'log', '-1', '--format=%ci', latest_tag],
    capture_output=True, text=True
).stdout.strip()
```

## Test Plan

- [x] Verified `--before=<tag>` vs `--before=<date>` returns different
results
- [x] Tested changelog generation locally against v0.0.33→v0.0.34 and
v0.0.34→v0.0.35
- [x] Confirmed first-time contributor detection works correctly with
date-based filtering
- [x] YAML validates (`check-yaml` hook passes)
- [ ] Will validate in next production release

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
jeremyeder pushed a commit to jeremyeder/platform that referenced this pull request Mar 26, 2026
…ambient-code#1010)

When users export a completed session's chat (as Markdown, PDF, or to
Google Drive), only the initial prompt is included — the rest of the
conversation is missing. This makes the export feature essentially
unusable for reviewing or sharing finished sessions.

The root cause is that the backend compacts finished sessions by
replacing streaming events (TEXT_MESSAGE_*, TOOL_CALL_*) with a single
MESSAGES_SNAPSHOT event. The export code only knew how to process
streaming events, so all conversation content was silently dropped after
compaction.

Add blocksFromSnapshot() to extract conversation blocks from
MESSAGES_SNAPSHOT messages, including tool calls and results. When a
snapshot is present it takes priority over streaming events since it is
the canonical source after compaction.

--
Done in ambient-code, Needs review (I got no knowledge of this codebase)

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
jeremyeder added a commit to jeremyeder/platform that referenced this pull request Mar 26, 2026
…me contributors (ambient-code#1039)

## Summary

- **Group commits by author** with commit counts (e.g., "Gage Krumbach
(18)"), sorted by contribution count
- **Add "First-Time Contributors" section** with 🎉 emoji to celebrate
new contributors
- **Use Python** for reliable parsing of commit data with special
characters
- **Fix `--before` bug**: resolve tag to ISO date since `git log
--before` requires a date, not a ref name — passing a tag name silently
returns wrong results, causing incorrect first-timer detection

## Example Output (v0.0.34)

### Before (flat list):
```
- fix(frontend): resolve agent response buffering (ambient-code#991) (de50276)
- fix(frontend): export chat handles compacted MESSAGES_SNAPSHOT events (ambient-code#1010) (b204abd)
- fix(frontend): binary file download corruption (ambient-code#996) (5b584f8)
...
```

### After (grouped by author):
```
## 🎉 First-Time Contributors

- Derek Higgins
- Pete Savage
- Rahul Shetty

### Gage Krumbach (5)
- fix(runner): improve ACP MCP tools (ambient-code#1006) (26be0f9)
- chore(manifests): scale up frontend replicas (ambient-code#1008) (b331da1)
...

### Pete Savage (1)
- fix(frontend): resolve agent response buffering (ambient-code#991) (de50276)
```

## Bug Fix: `--before` with tag names

`git log --before=v0.0.33` does **not** filter by the tag's date — it
resolves differently and returns commits from after the tag. This caused
first-timer detection to produce wrong results. Fixed by resolving the
tag to its ISO date first:

```python
tag_date = subprocess.run(
    ['git', 'log', '-1', '--format=%ci', latest_tag],
    capture_output=True, text=True
).stdout.strip()
```

## Test Plan

- [x] Verified `--before=<tag>` vs `--before=<date>` returns different
results
- [x] Tested changelog generation locally against v0.0.33→v0.0.34 and
v0.0.34→v0.0.35
- [x] Confirmed first-time contributor detection works correctly with
date-based filtering
- [x] YAML validates (`check-yaml` hook passes)
- [ ] Will validate in next production release

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
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