fix(share): preserve share ID on import/re-share and handle missing metadata#29982
Open
lexlian wants to merge 1 commit into
Open
fix(share): preserve share ID on import/re-share and handle missing metadata#29982lexlian wants to merge 1 commit into
lexlian wants to merge 1 commit into
Conversation
…etadata Closes anomalyco#29821 ## What changed - Fix 1: Added share reuse logic in ShareNext.create() - checks for existing share before creating a new one, preserving the original share ID after import - Fix 2: Added defensive null checks in fromV1() for missing assistant metadata and tool metadata, preventing TypeError on malformed share data - Fix 3: Added validateImportMessages() to validate imported message metadata and warn/error on malformed data during import ## Why Share ID was derived from session ID at creation time. When a session was imported on another machine, it got a new session ID, causing re-share to create a different share ID and orphan the original share data. Also, fromV1() crashed on missing metadata using non-null assertions. ## How to verify - bun test packages/web/test/components/Share.test.ts (9 tests) - bun test packages/opencode/test/import.test.ts (8 tests)
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #29821
Type of change
What does this PR do?
The bug had two root causes:
Share ID corruption on import/re-share: Share ID is derived from session ID at creation time on the server. When a session was imported on another machine, it got a new local session ID. When re-sharing, the server generated a new share ID from the new session ID, orphaning the original share data and causing "Sharing content found empty" errors.
TypeError on missing metadata: The
fromV1()function used non-null assertions (!) on assistant metadata and tool metadata that may be missing in imported sessions, causingTypeError: Cannot read properties of undefined (reading 'id').Fixes (3 total)
Fix 1: Preserve original share ID
packages/opencode/src/session/session.ts,packages/opencode/src/share/share-next.tsShareNext.create(): if session already has a share (from previous share or import), reuse it instead of creating newFix 2: Defensive handling of missing metadata
packages/web/src/components/Share.tsxv1.metadata.assistant!tov1.metadata.assistant(using optional chaining?.)v1.metadata.tool?.[part.toolInvocation.toolCallId]to use defensive checksFix 3: Validate messages on import
packages/opencode/src/cli/cmd/import.tsvalidateImportMessages()to check for missing ID and sessionID during importHow did you verify your code works?
bun test packages/web/test/components/Share.test.ts— 9 tests cases covering fromV1() with missing/partial metadatabun test packages/opencode/test/import.test.ts— 8 tests cases covering import scenariosbun run typecheck— passes in all packagesChecklist