Skip to content

fix: provider cache reset after settings import#699

Closed
JunyongParkDev wants to merge 1 commit into
Zoo-Code-Org:mainfrom
JunyongParkDev:fix/settings-provider-import-cache
Closed

fix: provider cache reset after settings import#699
JunyongParkDev wants to merge 1 commit into
Zoo-Code-Org:mainfrom
JunyongParkDev:fix/settings-provider-import-cache

Conversation

@JunyongParkDev

@JunyongParkDev JunyongParkDev commented Jun 23, 2026

Copy link
Copy Markdown

Related GitHub Issue

Closes: #689

Description

SettingsView uses a local cachedState buffer so settings edits do not write through to live extension state before Save. After importing settings, the cache-busting effect could run multiple times for the same settingsImportedAt value whenever extensionState changed identity.

That could overwrite an in-progress provider edit with the previously saved provider, making the UI briefly switch and then revert.

This change tracks the handled settingsImportedAt value and resets cachedState only once per import event. It also adds a regression test covering the imported-settings flow where Baseten is saved with an API key, the same import timestamp replays, and a later DeepSeek provider edit is preserved and saved.

Test Procedure

  • Ran the focused webview regression test: - all 3 tests passed.

    pnpm --dir webview-ui exec vitest run src/components/settings/__tests__/SettingsView.change-detection.spec.tsx
    
  • Verified the new regression coverage for the imported-settings flow:

    1. Start with settingsImportedAt set.
    2. Change Provider to Baseten.
    3. Enter a Baseten API key.
    4. Save the settings.
    5. Change Provider to DeepSeek.
    6. Replay the same imported extension state timestamp.
    7. Confirm the Provider remains DeepSeek and Save posts apiProvider: "deepseek".
  • This verifies that SettingsView only busts cachedState once per settingsImportedAt value, so a replayed imported state does not overwrite an in-progress Provider edit.

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Testing: New and/or updated tests have been added to cover my changes (if applicable).
  • Documentation Impact: I have considered if my changes require documentation updates (see "Documentation Updates" section below).
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Screenshots / Videos

Documentation Updates

Additional Notes

Get in Touch

Summary by CodeRabbit

  • Bug Fixes

    • Prevented repeated settings-import cache resets by applying cache-busting only once per distinct settingsImportedAt timestamp.
  • Tests

    • Improved VS Code message mocking by using a single shared postMessage mock for consistent assertions.
    • Enhanced the API options test mock to support interactive API provider editing.
    • Added a regression test confirming API provider selection persists correctly after editing and subsequent state replay/saves.

@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 4ba043b9-df15-4797-b04d-7914e41b0841

📥 Commits

Reviewing files that changed from the base of the PR and between c088cc8 and f8ac8ef.

📒 Files selected for processing (2)
  • webview-ui/src/components/settings/SettingsView.tsx
  • webview-ui/src/components/settings/__tests__/SettingsView.change-detection.spec.tsx
🚧 Files skipped from review as they are similar to previous changes (2)
  • webview-ui/src/components/settings/SettingsView.tsx
  • webview-ui/src/components/settings/tests/SettingsView.change-detection.spec.tsx

📝 Walkthrough

Walkthrough

SettingsView now ignores repeated handling for the same settingsImportedAt value. The test file now shares one VS Code postMessage mock, uses a functional ApiOptions mock, and adds a regression test for the provider-revert scenario.

Changes

Settings Import Cache-Bust Deduplication

Layer / File(s) Summary
Ref-gated settings import effect
webview-ui/src/components/settings/SettingsView.tsx
Adds handledSettingsImportedAt and updates the settings-import useEffect to skip repeated handling for the same timestamp while still merging extensionState and resetting changeDetected for a new import.
Test mock wiring and ApiOptions functional mock
webview-ui/src/components/settings/__tests__/SettingsView.change-detection.spec.tsx
Shares one mockPostMessage between acquireVsCodeApi() and @src/utils/vscode, and replaces the ApiOptions null mock with an interactive mock that renders the provider, edits basetenApiKey, and switches providers.
Baseten→DeepSeek provider-revert regression test
webview-ui/src/components/settings/__tests__/SettingsView.change-detection.spec.tsx
Replaces the placeholder assertion with an async regression that saves Baseten, switches to DeepSeek, rerenders with the same settingsImportedAt, and checks that the next save uses the DeepSeek payload.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • taltas
  • hannesrudolph
  • edelauna

Poem

🐇 A timestamp hop, a cache won’t stray,
The same old import won’t barge in today.
Baseten to DeepSeek, the path stays true,
With buttons and mocks, the tests hop through.
No replay rabbit can flip the view! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main fix: preventing provider cache resets after settings import.
Description check ✅ Passed The PR description covers the linked issue, implementation approach, and testing, with only optional sections left blank.
Linked Issues check ✅ Passed The code changes address the reported provider-revert bug by handling each settingsImportedAt import event once and adding a matching regression test.
Out of Scope Changes check ✅ Passed The test mock adjustments support the new regression coverage and do not introduce unrelated behavior changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jun 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@JunyongParkDev JunyongParkDev force-pushed the fix/settings-provider-import-cache branch from 0ba829c to c088cc8 Compare June 25, 2026 01:47
SettingsView keeps a local cachedState buffer so settings edits do not write through to the live extension state before Save. After importing settings, the import timestamp was used to bust that cache, but the effect could run again for the same import timestamp whenever extensionState changed identity.

That allowed a later live state update to overwrite an in-progress provider edit with the previously saved provider, causing the provider UI to briefly switch and then revert.

Track the handled settingsImportedAt value and only reset cachedState once per import event.

Add a regression test for the imported-settings flow where Baseten is saved with an API key, the same import timestamp is replayed, and a subsequent DeepSeek provider edit is preserved and saved.
@JunyongParkDev JunyongParkDev force-pushed the fix/settings-provider-import-cache branch from c088cc8 to f8ac8ef Compare June 26, 2026 01:03
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.

[BUG] API Provider can revert to previous Provider after importing settings

1 participant