Skip to content

fix: improve type safety in legacy config migration#375

Open
hobostay wants to merge 1 commit intobytedance:mainfrom
hobostay:fix/config-type-safety
Open

fix: improve type safety in legacy config migration#375
hobostay wants to merge 1 commit intobytedance:mainfrom
hobostay:fix/config-type-safety

Conversation

@hobostay
Copy link

@hobostay hobostay commented Feb 6, 2026

Summary

This PR improves type safety in the legacy configuration migration code by adding defensive checks for top_k parameter.

Changes

  • Add None check for top_k: Prevents potential type errors when the legacy config has missing or null top_k values
  • Code refactoring: Extract provider_config variable to eliminate code duplication
  • Improved readability: Reduced repeated attribute access from 10+ times to a single variable

Problem

When migrating from legacy JSON configs, the top_k field could theoretically be None, which would cause type mismatches since ModelConfig.top_k expects an int.

Solution

Added defensive check: top_k=provider_config.top_k if provider_config.top_k is not None else 0

This ensures we always pass a valid int value to ModelConfig, maintaining backward compatibility while improving type safety.

Testing

  • No functional changes for existing valid configs
  • Defensive measure for edge cases
  • Reduces code duplication (11 insertions, 15 deletions)

🤖 Generated with Claude Code

- Add None check for top_k with default value fallback
- Extract provider_config variable to reduce code duplication
- Improve code readability and maintainability

This prevents potential type errors when migrating from legacy JSON configs
and makes the code more defensive against edge cases.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
maharab549 pushed a commit to maharab549/trae-agent that referenced this pull request Mar 1, 2026
This workflow creates two offical container images:

* `ghcr.io/codingjoe/deer-flow:main`
* `ghcr.io/codingjoe/deer-flow-web:main`
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