Skip to content

fix(#689): provider cache reset after settings import#726

Merged
edelauna merged 2 commits into
Zoo-Code-Org:mainfrom
JunyongParkDev:fix/settings-provider-import-cache
Jul 1, 2026
Merged

fix(#689): provider cache reset after settings import#726
edelauna merged 2 commits into
Zoo-Code-Org:mainfrom
JunyongParkDev:fix/settings-provider-import-cache

Conversation

@JunyongParkDev

@JunyongParkDev JunyongParkDev commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

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](/CONTRIBUTING.md).

Screenshots / Videos

Documentation Updates

Additional Notes

Get in Touch

Summary by CodeRabbit

  • Bug Fixes

    • Improved settings import handling so the “bust cache” logic runs only once per distinct import timestamp, avoiding repeated cache refreshes and unintended change-detection resets.
    • Fixed settings import replay behavior to correctly merge cached state while preserving the latest API provider selection during saves.
  • Tests

    • Expanded regression tests for settings change detection, including replaying settingsImportedAt and verifying correct provider switching (e.g., Baseten to DeepSeek) and UI reset/sync behavior.

@coderabbitai

coderabbitai Bot commented Jun 26, 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: 9036adc2-f919-4879-8542-4b29368bb128

📥 Commits

Reviewing files that changed from the base of the PR and between ac5d042 and 9198817.

📒 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 due to trivial changes (1)
  • webview-ui/src/components/settings/SettingsView.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • webview-ui/src/components/settings/tests/SettingsView.change-detection.spec.tsx

📝 Walkthrough

Walkthrough

SettingsView now handles each settingsImportedAt value once before refreshing cached settings and clearing change detection. The change-detection spec updates its VS Code mocks, renders provider controls, and adds regression tests for provider changes after imported settings.

Changes

Imported settings replay handling

Layer / File(s) Summary
Guard imported state replay
webview-ui/src/components/settings/SettingsView.tsx
SettingsView stores the last handled settingsImportedAt value, then refreshes cachedState and resets isChangeDetected only for a new import timestamp.
Provider regression test
webview-ui/src/components/settings/__tests__/SettingsView.change-detection.spec.tsx
The spec shares a postMessage mock, renders interactive ApiOptions controls, and adds regression tests that verify provider changes and imported-state replay behavior.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: taltas, hannesrudolph, edelauna

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main fix: preventing provider cache resets after settings import.
Description check ✅ Passed The PR description includes the linked issue, summary, test procedure, and checklist, matching the template well.
Linked Issues check ✅ Passed The code and tests address issue #689 by preventing repeated cache resets after import and preserving provider edits.
Out of Scope Changes check ✅ Passed The changes stay focused on the import cache-reset bug and its regression tests, with no obvious unrelated additions.
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.

@JunyongParkDev
JunyongParkDev force-pushed the fix/settings-provider-import-cache branch from f8ac8ef to 26dea4e Compare June 26, 2026 07:33
@codecov

codecov Bot commented Jun 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@github-actions github-actions Bot added the awaiting-review PR changes are ready and waiting for maintainer re-review label Jun 30, 2026

@edelauna edelauna left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for you contribution just had some additional testing to add.

@github-actions github-actions Bot added awaiting-author PR is waiting for the author to address requested changes and removed awaiting-review PR changes are ready and waiting for maintainer re-review labels Jul 1, 2026
@JunyongParkDev

Copy link
Copy Markdown
Contributor Author

/review

@JunyongParkDev
JunyongParkDev requested a review from edelauna July 1, 2026 07:31
@JunyongParkDev

Copy link
Copy Markdown
Contributor Author

@edelauna Thank you for review.

I checked both points and pushed a follow-up commit with the requested updates. The test now waits for the post-rerender effect before asserting the replayed timestamp case, and I added an additional case for a fresh settingsImportedAt value to verify that imported provider state is applied and the dirty Save state is cleared.

@github-actions github-actions Bot added awaiting-review PR changes are ready and waiting for maintainer re-review and removed awaiting-author PR is waiting for the author to address requested changes labels Jul 1, 2026

@edelauna edelauna left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look good - thanks for your contribution

@edelauna
edelauna added this pull request to the merge queue Jul 1, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 1, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 1, 2026
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.
Strengthen SettingsView regression coverage around settingsImportedAt.

Verify that replaying the same import timestamp does not let the
cache-busting effect overwrite an in-progress provider edit, and add
the inverse case to prove a fresh import timestamp still refreshes
cachedState from the latest extensionState apiConfiguration.

Also assert that a fresh import clears the dirty state by disabling the
Save button after pending edits are replaced by imported settings.
@edelauna
edelauna force-pushed the fix/settings-provider-import-cache branch from ac5d042 to 9198817 Compare July 1, 2026 17:17
@edelauna
edelauna added this pull request to the merge queue Jul 1, 2026
Merged via the queue into Zoo-Code-Org:main with commit 63dec51 Jul 1, 2026
10 of 11 checks passed
hacker-b2k pushed a commit to hacker-b2k/Zoo-Code that referenced this pull request Jul 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-review PR changes are ready and waiting for maintainer re-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants