Skip to content

Conversation

@quanru
Copy link
Collaborator

@quanru quanru commented Oct 27, 2025

Summary

This PR adds backward compatibility support for legacy MIDSCENE_OPENAI_* environment variables that were renamed during the recent refactoring. This ensures existing users can continue using the old variable names without breaking their configurations.

Background

During the recent environment variable refactoring (#1375), the following variables were renamed but backward compatibility was not fully implemented:

  • MIDSCENE_OPENAI_INIT_CONFIG_JSONMIDSCENE_MODEL_INIT_CONFIG_JSON
  • MIDSCENE_OPENAI_HTTP_PROXYMIDSCENE_MODEL_HTTP_PROXY
  • MIDSCENE_OPENAI_SOCKS_PROXYMIDSCENE_MODEL_SOCKS_PROXY

This caused overrideAIConfig() to reject these legacy variable names with the error:

Failed to apply AI configuration: Failed to override AI config, invalid key: MIDSCENE_OPENAI_INIT_CONFIG_JSON

Changes

Code Changes

  1. packages/shared/src/env/types.ts

    • Added deprecated constants with @deprecated JSDoc tags
    • Added legacy variables to MODEL_ENV_KEYS array to support overrideAIConfig()
    • Updated IModelConfigForDefaultLegacy interface to use legacy variable names
  2. packages/shared/src/env/constants.ts

    • Imported new legacy constants
    • Updated DEFAULT_MODEL_CONFIG_KEYS_LEGACY to use legacy variable names for proxy and init config
  3. packages/shared/src/env/decide-model-config.ts

    • Implemented priority fallback logic in decideOpenaiSdkConfig():
      • When legacy keys are used, check new variable names first
      • Fall back to legacy names if new ones are not set
      • Follows the same pattern as OPENAI_API_KEY / OPENAI_BASE_URL

Documentation Updates

  1. apps/site/docs/zh/model-provider.mdx (Chinese)

    • Updated advanced configuration table with both new (recommended) and legacy (deprecated) variables
    • Added clear deprecation notices
  2. apps/site/docs/en/model-provider.mdx (English)

    • Same updates as Chinese documentation

Priority Logic

When both old and new variables are set, new variables take precedence:

Legacy Variable (Deprecated) New Variable (Recommended) Priority
MIDSCENE_OPENAI_INIT_CONFIG_JSON MIDSCENE_MODEL_INIT_CONFIG_JSON New first
MIDSCENE_OPENAI_HTTP_PROXY MIDSCENE_MODEL_HTTP_PROXY New first
MIDSCENE_OPENAI_SOCKS_PROXY MIDSCENE_MODEL_SOCKS_PROXY New first

Testing

✅ All 139 tests pass in packages/shared

  • Environment configuration tests
  • Global config manager tests
  • Model config manager tests
  • Decision logic tests

Backward Compatibility

This PR ensures:

  • ✅ Existing users can continue using legacy variable names
  • overrideAIConfig() accepts legacy variable names
  • ✅ Gradual migration path to new variable names
  • ✅ Clear deprecation warnings in documentation
  • ✅ No breaking changes to existing configurations

Related

🤖 Generated with Claude Code

…nt variables

Add backward compatibility support for legacy MIDSCENE_OPENAI_* environment variables:
- MIDSCENE_OPENAI_INIT_CONFIG_JSON (now MIDSCENE_MODEL_INIT_CONFIG_JSON)
- MIDSCENE_OPENAI_HTTP_PROXY (now MIDSCENE_MODEL_HTTP_PROXY)
- MIDSCENE_OPENAI_SOCKS_PROXY (now MIDSCENE_MODEL_SOCKS_PROXY)

Changes:
- Add deprecated constants to types.ts with @deprecated tags
- Add legacy variables to MODEL_ENV_KEYS for overrideAIConfig support
- Update DEFAULT_MODEL_CONFIG_KEYS_LEGACY to use legacy variable names
- Implement priority fallback logic in decide-model-config.ts (new variables take precedence)
- Update documentation (zh/en model-provider.mdx) with deprecation notices

All 139 tests pass, confirming backward compatibility works correctly.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@netlify
Copy link

netlify bot commented Oct 27, 2025

Deploy Preview for midscene ready!

Name Link
🔨 Latest commit a754756
🔍 Latest deploy log https://app.netlify.com/projects/midscene/deploys/68ff34f7fdfc53000884dc6b
😎 Deploy Preview https://deploy-preview-1388--midscene.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
2 out of 3 committers have signed the CLA.

✅ quanru
✅ yuyutaotao
❌ Copilot
You have signed the CLA already but the status is still pending? Let us recheck it.

@quanru quanru changed the base branch from main to 1.0 October 27, 2025 09:13
@quanru quanru merged commit 4ee95a8 into 1.0 Oct 27, 2025
9 of 10 checks passed
@quanru quanru deleted the feat/env-vars-backward-compatibility branch October 27, 2025 11:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants