Repository navigation
feat(conversations): fork shared history from dashboard messages - #1958
sentry-junior[bot] wants to merge 3 commits into
Conversation
Co-Authored-By: David Cramer <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
11 screenshot changes — 5 changed · 6 added · 0 removed Review screenshots in Frameshift
|
There was a problem hiding this comment.
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–41starts the transaction,chat/conversations/fork.ts:49–52takes the same lock again, andfork-attachments.ts:42–52downloads 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 usesreplaceAllover 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–187copies 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–172preserves reporting usage fields, andreadConversationModelUsageFromSqlcounts 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.
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]>
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.
Shared storage
Event payloads live once in
junior_history_events. Each Conversation owns fixed inherited ranges and one open range for new events. Thejunior_conversation_eventsread 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:
via David Cramer.
--
View Junior Session [Sentry]