Skip to content

fix: auto-close files setting cannot be unchecked — always reverts to checked#668

Merged
edelauna merged 2 commits into
mainfrom
fix/auto-close-settings-not-persisting
Jun 21, 2026
Merged

fix: auto-close files setting cannot be unchecked — always reverts to checked#668
edelauna merged 2 commits into
mainfrom
fix/auto-close-settings-not-persisting

Conversation

@navedmerchant

@navedmerchant navedmerchant commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Related GitHub Issue

Closes: #667

Description

The three auto-close settings (autoCloseZooOpenedFiles, autoCloseZooOpenedFilesAfterUserEdited, autoCloseZooOpenedNewFiles) were saved to global state via contextProxy.setValue() but never included in the state posted back to the webview or returned by getState(). This had two effects:

  1. UI symptom: getStateToPostToWebview() omitted these fields, so the webview always received undefined. When the SettingsView re-mounted, cachedState was initialized from extensionState (with undefined), and the checkbox rendered checked={undefined ?? true} → always checked. The user could uncheck and save, but the value was never sent back, so it appeared unsaved on reopen.

  2. Functional symptom: getState() omitted these fields, so the DiffViewProvider (which reads saveState?.autoCloseZooOpenedFiles ?? true) always got undefined and fell back to the default true — the auto-close behavior ignored the user's saved preference entirely.

Fix: Added the three fields to both getState() (reading from stateValues) and getStateToPostToWebview() (destructuring from getState() and including in the return object with their documented defaults: true, false, false).

Also added a changeset instruction to AGENTS.md per maintainer request.

Test Procedure

Unit tests (added to src/core/webview/__tests__/ClineProvider.taskHistory.spec.ts):

  1. getStateToPostToWebview returns saved autoCloseZooOpenedFiles value — Sets values via contextProxy.setValue(), calls getStateToPostToWebview(), and asserts the saved values are present in the returned state.
  2. getStateToPostToWebview defaults autoCloseZooOpenedFiles to true when unset — Verifies unset values default to true/false/false in posted state.
  3. getState returns saved autoCloseZooOpenedFiles value for DiffViewProvider — Verifies getState() returns the saved value so DiffViewProvider can read it.

Run tests:

cd src && npx vitest run core/webview/__tests__/ClineProvider.taskHistory.spec.ts
cd src && npx vitest run core/webview/__tests__/ClineProvider.spec.ts integrations/editor/__tests__/DiffViewProvider.spec.ts

All 188 tests pass (18 + 170). Lint and type-check also pass.

Pre-Submission Checklist

  • Issue Linked: This PR is linked to issue [BUG] Auto close files setting cannot be unchecked — always reverts to checked #667.
  • Scope: My changes are focused on the linked issue (one fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Testing: New regression tests have been added to cover the changes.
  • Documentation Impact: No documentation updates required (internal state serialization fix).
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Screenshots / Videos

N/A — no visual UI changes; the fix corrects data flow so the existing checkbox behaves correctly.

Documentation Updates

  • No documentation updates are required.

Additional Notes

The root cause was a straightforward omission: the fields were added to the ExtensionState type and globalSettingsSchema, the webview correctly sends them in updateSettings, and the DiffViewProvider correctly reads them from getState() — but the getState() and getStateToPostToWebview() return objects were never updated to include them. Since all fields are optional in the type, TypeScript did not flag the missing properties.

Get in Touch

N/A

Summary by CodeRabbit

Release Notes

  • New Features

    • Added three new auto-close settings: auto-close opened files (enabled by default), auto-close opened files after user edits, and auto-close newly created files.
  • Tests

    • Added test coverage for the new auto-close settings.

The autoCloseZooOpenedFiles, autoCloseZooOpenedFilesAfterUserEdited, and
autoCloseZooOpenedNewFiles settings were saved to global state but never
included in the state posted back to the webview (getStateToPostToWebview)
or returned by getState. This caused the checkbox to always revert to
checked after saving, and the DiffViewProvider to always use the default
value regardless of the user's preference.

Also adds a changeset instruction to AGENTS.md.

Closes #667
@coderabbitai

coderabbitai Bot commented Jun 20, 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: 9c56ab39-e592-41fb-9af1-068335eafc27

📥 Commits

Reviewing files that changed from the base of the PR and between 3115873 and b2a7f80.

📒 Files selected for processing (1)
  • src/core/webview/__tests__/ClineProvider.spec.ts
✅ Files skipped from review due to trivial changes (1)
  • src/core/webview/tests/ClineProvider.spec.ts

📝 Walkthrough

Walkthrough

Three auto-close settings (autoCloseZooOpenedFiles, autoCloseZooOpenedFilesAfterUserEdited, autoCloseZooOpenedNewFiles) are added to ClineProvider.getState() and getStateToPostToWebview() with default fallbacks, fixing a bug where saved values were never sent back to the webview. Tests and an AGENTS.md rule are also added.

Changes

Auto-close Settings State Serialization Fix

Layer / File(s) Summary
ClineProvider state serialization for auto-close fields
src/core/webview/ClineProvider.ts, src/core/webview/__tests__/ClineProvider.spec.ts
getStateToPostToWebview() now destructures and emits the three auto-close fields with explicit defaults (autoCloseZooOpenedFilestrue, others → false); getState() returns all three from stateValues. Tests verify saved values appear in both methods and that defaults apply when unset.
AGENTS.md changeset rule
AGENTS.md
Adds an instruction prohibiting agents from creating .changeset files, noting changesets are managed separately by maintainers.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐇 Three checkboxes longed to be heard,
Lost in state, never transferred.
Now getState() sends them along,
Default or saved — they finally belong!
No more "undefined" bugs, hurray —
The rabbit fixed the webview today. ✅

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title directly and clearly describes the main bug being fixed: auto-close settings reverting to checked. It accurately reflects the primary issue and is specific enough to understand the change.
Description check ✅ Passed The description comprehensively addresses the template requirements: linked issue (#667), detailed implementation explanation, thorough test procedures with commands, completed pre-submission checklist, and appropriate 'N/A' sections for non-applicable items.
Linked Issues check ✅ Passed The PR fully addresses issue #667: adds missing fields to both getState() and getStateToPostToWebview() in ClineProvider, includes tests for state persistence and defaults, and verifies DiffViewProvider receives correct values.
Out of Scope Changes check ✅ Passed All changes are directly scoped to issue #667. Code changes fix the state serialization bug, tests validate the fix, and AGENTS.md addition was per maintainer request. No extraneous modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/auto-close-settings-not-persisting

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 and usage tips.

@codecov

codecov Bot commented Jun 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Comment on lines +724 to +729
await provider.contextProxy.setValue("autoCloseZooOpenedFiles", false)

const state = await provider.getState()

// DiffViewProvider reads from getState(); the field must be present.
expect(state.autoCloseZooOpenedFiles).toBe(false)

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.

Does this test need assertions for autoCloseZooOpenedFilesAfterUserEdited and autoCloseZooOpenedNewFiles too? Since the bug was about all three fields being missing from getState(), a regression that drops those two would pass this test as-is.

Suggested change
await provider.contextProxy.setValue("autoCloseZooOpenedFiles", false)
const state = await provider.getState()
// DiffViewProvider reads from getState(); the field must be present.
expect(state.autoCloseZooOpenedFiles).toBe(false)
await provider.contextProxy.setValue("autoCloseZooOpenedFiles", false)
await provider.contextProxy.setValue("autoCloseZooOpenedFilesAfterUserEdited", true)
await provider.contextProxy.setValue("autoCloseZooOpenedNewFiles", true)
const state = await provider.getState()
// DiffViewProvider reads from getState(); the field must be present.
expect(state.autoCloseZooOpenedFiles).toBe(false)
expect(state.autoCloseZooOpenedFilesAfterUserEdited).toBe(true)
expect(state.autoCloseZooOpenedNewFiles).toBe(true)

})
})

describe("auto-close settings are included in posted state", () => {

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.

Is there a reason these tests live in ClineProvider.taskHistory.spec.ts rather than ClineProvider.spec.ts? The existing getState settings coverage (e.g. autoCondenseContext, writeDelayMs) is in the latter, so a contributor looking for where settings persistence is tested would miss these.

@github-actions github-actions Bot added the awaiting-author PR is waiting for the author to address requested changes label Jun 20, 2026
…ert all three fields

Address review comments on PR #668:
- Move the auto-close settings test block from ClineProvider.taskHistory.spec.ts
  to ClineProvider.spec.ts, where existing getState settings coverage
  (autoCondenseContext, writeDelayMs) already lives.
- Expand the getState regression test to assert autoCloseZooOpenedFiles,
  autoCloseZooOpenedFilesAfterUserEdited, and autoCloseZooOpenedNewFiles so a
  regression dropping any of the three fields is caught.
@edelauna edelauna added this pull request to the merge queue Jun 21, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 21, 2026
@edelauna edelauna added this pull request to the merge queue Jun 21, 2026
Merged via the queue into main with commit de8886a Jun 21, 2026
11 checks passed
@edelauna edelauna deleted the fix/auto-close-settings-not-persisting branch June 21, 2026 01:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-author PR is waiting for the author to address requested changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Auto close files setting cannot be unchecked — always reverts to checked

2 participants