Skip to content

feat(conversations): fork shared history from dashboard messages - #1958

Closed
sentry-junior[bot] wants to merge 3 commits into
mainfrom
feat/web-conversation-forks
Closed

sentry-junior[bot] wants to merge 3 commits into
mainfrom
feat/web-conversation-forks

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Implementation status: The shared-history changes below were implemented and tested in the previous Sandbox but were not committed or pushed before that Sandbox was replaced. This PR still points to 949a458ed, the copy-based implementation. The shared-history patch must be restored or rebuilt before this description matches the code.

Add a fork action to saved user and assistant Messages in the dashboard.

  • An assistant Message shares history through that reply.
  • A user Message shares through the preceding reply and puts the selected text in the composer. The first user Message creates an empty fork.
  • No Turn starts until the user sends a Message.

Shared storage

Event payloads live once in junior_history_events. Each Conversation owns fixed inherited ranges and one open range for new events. The junior_conversation_events read view serves replay, pagination, search, and reporting. Nested forks use flat ranges, not recursive reads.

Forks record their source identity without inheriting its permissions or retention. Purging a source removes only events no remaining Conversation owns. New source events after purge use a fresh history id. Attachment metadata belongs to each Conversation, but bytes are shared and deleted only after the last owner releases them. Fork creation performs no remote file I/O.

Only referenced annotations are copied. Inherited events do not count as new spending. Active work, watches, automations, agent bindings, and Sandbox files are not copied. Source lineage is stored but not exposed as a public link.

Deployment

Stop old writers before migration 0046. It renames the event table and adds the read view without copying existing payloads. Old releases cannot write through the view; rollback requires compatible writers. Existing copied forks remain valid but are not retroactively deduplicated. The old memory scope-label migration now handles either physical event table.

Prior local validation

These results apply to the unpushed patch, not the current PR commit:

  • Core suite: 2,931 passed, one skipped.
  • Memory suite: 95 passed.
  • TypeScript, lint, migration metadata, and schema generation checks passed.
  • Fork tests covered unchanged payload counts, nested ranges, pagination across the cutoff, concurrent fork/purge, continuation after source purge, source reuse, inherited accounting, and final-owner attachment cleanup.

via David Cramer.

--

View Junior Session [Sentry]

@vercel

vercel Bot commented Sep 27, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
junior-docs Ready Ready Preview Sep 27, 2026 12:51am UTC

Request Review

@github-actions

github-actions Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

11 screenshot changes — 5 changed · 6 added · 0 removed

Review screenshots in Frameshift

Code · Desktop
Code · Desktop
Changed
Code · Mobile
Code · Mobile
Changed
Conversation Detail · Desktop
Conversation Detail · Desktop
Changed
Conversation Detail · Mobile
Conversation Detail · Mobile
Changed
System Cache Missing · Desktop
System Cache Missing · Desktop
Changed

@sentry-junior sentry-junior Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I would not merge this version yet. The normal fork/continue flow works and CI is green, but the deeper review found three issues:

  • File copying holds the source Conversation's write lock across network I/O. api/conversations/fork.ts:22–41 starts the transaction, chat/conversations/fork.ts:49–52 takes the same lock again, and fork-attachments.ts:42–52 downloads and uploads every file before either lock is released. I reproduced a concurrent source-event append timing out while the copy was held. A slow file copy can stall the original conversation. Give the operation one transaction owner, keep remote file I/O outside the source write lock, and recheck access/retention before publishing the fork. The attachment code also uses replaceAll over serialized event payloads, which changes ordinary message text and opaque model history containing an attachment id. Do not treat every occurrence as a mutable reference.

  • Annotations ignore the selected history boundary. chat/conversations/fork.ts:175–187 copies every current annotation, including work created after the selected reply. I reproduced a first-user-message fork with zero events but a later PR in its annotations. Copy only the annotation identities needed by the retained history; an empty fork must not inherit later work. Existing cards may still resolve to their latest saved facts without importing unrelated objects.

  • Copied model usage is reported as spending in a conversation that has never run. The raw event copy at chat/conversations/fork.ts:166–172 preserves reporting usage fields, and readConversationModelUsageFromSql counts those rows as calls. I reproduced an idle new fork with $0.30 of model usage and no cumulative execution usage. The dashboard prefers model usage, while persisted execution totals do not include it. Mark the inherited boundary and exclude copied calls/cost events from new-work accounting without changing replayable model messages.

The main simplification should be in persistence, not a new framework: one transaction owner, boundary-scoped reads, and SQL-side event copying where possible. The current path loads and decodes the whole conversation, reads the prefix again, then serializes it again for attachment replacement. Keep the existing web composer/mutation flow.

Verification: reran all five existing fork tests successfully and ran two temporary Postgres probes for annotation/accounting behavior and concurrent writes. Removed the probes; no source changes in this review. The current tests do not cover these cases.

Copy files before taking the source write lock, then recheck access and retention before SQL publication. Preserve history through conversation-scoped attachment aliases and copy only referenced annotations. Exclude inherited model and auxiliary costs from new-work accounting, including Guardian totals, and reset the boundary on purge.
@sentry-junior sentry-junior Bot changed the title feat(conversations): Fork message history from the dashboard feat(conversations): fork from dashboard messages Sep 27, 2026
Keep fork draft handling in the reply footer. Reuse the reply list for boundary checks, remove repeated test setup, and shorten the fork documentation without changing its safeguards.

Co-Authored-By: David Cramer <[email protected]>
@sentry-junior sentry-junior Bot changed the title feat(conversations): fork from dashboard messages feat(conversations): fork shared history from dashboard messages Sep 28, 2026
@dcramer dcramer closed this Oct 1, 2026

This branch was successfully deployed

1 active deployment
Preview – junior-docs — 949a458e Deployed Sep 27, 2026 by vercel[bot]
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.

1 participant