Skip to content

fix(enterprise): clean up share_event and share_compaction on unshare - #11376

Closed
sazary wants to merge 1 commit into
anomalyco:devfrom
sazary:fix-share-cleanup-on-unshare
Closed

sazary wants to merge 1 commit into
anomalyco:devfrom
sazary:fix-share-cleanup-on-unshare

Conversation

@sazary

@sazary sazary commented Jan 30, 2026

Copy link
Copy Markdown

What does this PR do?

Fixes #11372

When a session is unshared and then reshared, stale data from the previous share appeared mixed with the new data.
This happened because share_event and share_compaction storage entries were not being cleaned up during unshare,
causing old sync events to be replayed when the session was reshared.

Changes:

  • Clean up share_compaction entries in Share.remove()
  • Clean up share_event entries in Share.remove()
  • Add test for the reshare scenario

Memory storage adapter:

A simple in-memory storage adapter was added to enable local development and testing of the enterprise package
without requiring R2/S3 credentials. It is only activated when explicitly setting OPENCODE_STORAGE_ADAPTER=memory - production deployments are unaffected and will continue using r2 or s3 adapters.
If this is not okay then tell me to remove it.

How did you verify your code works?

You can take a look at the attached video.

Screen.Recording.1404-11-11.at.2.19.01.AM.mov
  1. Create a session and send a message ("hi 1" in the shared video)
  2. Share the session with /share
  3. Open the share URL in a browser (this triggers compaction cache)
  4. Unshare with /unshare
  5. /undo and edit the previous message ("hi 2" in the shared video)
  6. Share again with /share
  7. Open/refresh the share URL in browser
  8. Only the new message ("hi 2") is visible, which is the expected behaviour.

When a session is unshared and then reshared, stale data from the
previous share appeared mixed with the new data. The share_event and
share_compaction storage entries were not being cleaned up during
unshare, causing old sync events to be replayed when the session was
reshared.

This commit:
- Adds cleanup for share_compaction entries in Share.remove()
- Adds cleanup for share_event entries in Share.remove()
- Adds memory storage adapter for local testing
- Adds test for reshare scenario

Fixes anomalyco#11372
Copilot AI review requested due to automatic review settings January 30, 2026 23:08
@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

No duplicate PRs found

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a data consistency bug where stale data from a previous share appeared when a session was unshared and then reshared. The root cause was that share_event and share_compaction storage entries were not being cleaned up during unshare operations.

Changes:

  • Added cleanup of share_compaction and share_event storage entries in the Share.remove() function
  • Added a memory storage adapter for local development and testing (activated via OPENCODE_STORAGE_ADAPTER=memory)
  • Added a comprehensive test that verifies resharing works correctly with fresh data after unsharing

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
packages/enterprise/src/core/share.ts Added cleanup of share_compaction entry and all share_event entries in the Share.remove() function to ensure complete data cleanup on unshare
packages/enterprise/src/core/storage.ts Added memory storage adapter implementation for local testing and development, providing an in-memory Map-based storage that matches the behavior of S3/R2 adapters
packages/enterprise/test/core/share.test.ts Added comprehensive test case that verifies resharing after unsharing works correctly with fresh data, ensuring old compaction and events don't leak through

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@sazary

sazary commented Jan 31, 2026

Copy link
Copy Markdown
Author

@thdxr ready for your review

@github-actions

github-actions Bot commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

Closing this pull request because it has had no updates for more than 60 days. If you plan to continue working on it, feel free to reopen or open a new PR.

@github-actions github-actions Bot closed this Apr 2, 2026
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.

some session data are not cleaned up on unshare, leading to inconsistencies on reshare

2 participants