fix: prevent type definitions from being duplicated in optimized code#1221
Closed
misrasaurabh1 wants to merge 1 commit intomainfrom
Closed
fix: prevent type definitions from being duplicated in optimized code#1221misrasaurabh1 wants to merge 1 commit intomainfrom
misrasaurabh1 wants to merge 1 commit intomainfrom
Conversation
Type definitions (interfaces, types) that are found during context extraction were being combined with read_only_context, which gets prepended to the target code and becomes part of the code to be replaced. This caused the AI to include these type definitions in the optimized output, duplicating imported types. Fix: - Add `type_definitions_context` field to CodeContext to keep type definitions separate from global variables - Pass type definitions as `read_only_context_code` to the optimizer (true read-only context, not part of code to be replaced) - Add tests to verify type definitions are properly separated This fixes the bug where imported interfaces like `TreeNode` were being duplicated in the optimization output even though they were already imported. See: codeflash-ai/appsmith#20 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.
Summary
Root Cause
Type definitions extracted during context extraction were being combined with
read_only_context, which gets prepended to the target code and becomes part of the "read-writable" code to be replaced. This caused the AI to see the type definitions as part of the code it should return, duplicating imported types.Fix
type_definitions_contextfield toCodeContextto keep type definitions separate from global variablesread_only_context_codeto the optimizer (true read-only context that is NOT part of the code to be replaced)read_only_contextand are prepended to target codeTest plan
type_definitions_context, notread_only_contextread_only_context_codeto the optimizerRelated
Fixes the bug in codeflash-ai/appsmith#20 where
TreeNodeinterface was duplicated in the optimization output.🤖 Generated with Claude Code