Skip to content

fix: auto compact settings#1427

Merged
zerob13 merged 2 commits intodevfrom
fix/auto-compact-settings
Apr 2, 2026
Merged

fix: auto compact settings#1427
zerob13 merged 2 commits intodevfrom
fix/auto-compact-settings

Conversation

@zerob13
Copy link
Copy Markdown
Collaborator

@zerob13 zerob13 commented Apr 2, 2026

fixed #1425

Summary by CodeRabbit

Release Notes

  • New Features

    • Settings page header is now sticky, remaining visible at the top while scrolling through form content for improved navigation.
  • Bug Fixes

    • Auto-compaction numeric input fields now properly validate user entries and automatically revert to sensible default values when invalid or incomplete data is provided.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 2, 2026

📝 Walkthrough

Walkthrough

This PR fixes a bug preventing auto-compaction settings from being saved by introducing proper numeric input normalization with min/max bounds, type changes, and enhanced UI with a sticky header component. Test coverage for the new normalization logic and header behavior is included.

Changes

Cohort / File(s) Summary
Component UI & Logic
src/renderer/settings/components/DeepChatAgentsSettings.vue
Restructured page header into a sticky container with blur/border styling. Changed autoCompactionTriggerThreshold and autoCompactionRetainRecentPairs form fields from string to string | number. Added typed normalization helpers with constants defining defaults and min/max bounds. Updated initialization and persistence logic to use the new normalization instead of simple parseNum() fallback.
Test Coverage
test/renderer/components/DeepChatAgentsSettings.test.ts
Added three new test cases verifying sticky header presence/styling, numeric input updates with proper normalization, and fallback to defaults when blank/invalid values are provided. Tests mock presenters, stores, and i18n dependencies dynamically.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

  • #1346: Directly related as it modifies the same auto-compaction settings and normalization/persistence logic for numeric inputs.

Suggested reviewers

  • deepinfect

Poem

🐰✨ A sticky header bounds our way,
With numbers normalized to stay,
No more lost settings in the fray,
The auto-compaction saves the day!
Defaults clamped, the bugs at bay! 🎉

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: auto compact settings' directly relates to the main changes, which address auto-compaction persistence issues in agent settings.
Linked Issues check ✅ Passed The pull request successfully addresses issue #1425 by fixing auto-compaction settings persistence through proper numeric value normalization and form state handling.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing auto-compaction settings persistence; the sticky header improvement and test additions support the main objective.
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-compact-settings

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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
src/renderer/settings/components/DeepChatAgentsSettings.vue (1)

1087-1092: Normalize the loaded compaction values with the same helpers.

fromAgent still passes these fields through numText, so persisted out-of-range values render raw and stringified numbers render blank, then get reset on the next save. Reusing the save-path normalizers here keeps load/save behavior symmetric.

♻️ Proposed fix
-    autoCompactionTriggerThreshold: numText(
-      config.autoCompactionTriggerThreshold ?? AUTO_COMPACTION_TRIGGER_THRESHOLD_DEFAULT
-    ),
-    autoCompactionRetainRecentPairs: numText(
-      config.autoCompactionRetainRecentPairs ?? AUTO_COMPACTION_RETAIN_RECENT_PAIRS_DEFAULT
-    )
+    autoCompactionTriggerThreshold: String(
+      normalizeAutoCompactionTriggerThreshold(config.autoCompactionTriggerThreshold)
+    ),
+    autoCompactionRetainRecentPairs: String(
+      normalizeAutoCompactionRetainRecentPairs(config.autoCompactionRetainRecentPairs)
+    )
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/renderer/settings/components/DeepChatAgentsSettings.vue` around lines
1087 - 1092, The loaded compaction fields are being converted with numText which
differs from the save-path normalizers and causes persisted out-of-range or
stringified numbers to render incorrectly; update the initialization of
autoCompactionTriggerThreshold and autoCompactionRetainRecentPairs to use the
same helper functions used when saving (the save-path normalizers) instead of
numText so load/save behavior is symmetric — locate where fromAgent and the
save-path normalizers are defined and replace the numText conversion for these
two fields with those exact normalize functions that the save path uses.
test/renderer/components/DeepChatAgentsSettings.test.ts (1)

357-483: Please pin the actual #1425 regression path in the test suite.

These cases validate coercion, but they never flip autoCompactionEnabled before saving, and they also skip the new clamp/round branches. One test that toggles the switch and saves, plus one out-of-range/decimal input case, would cover the paths most likely to regress.

Also applies to: 485-611

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/renderer/components/DeepChatAgentsSettings.test.ts` around lines 357 -
483, Add two tests in DeepChatAgentsSettings.test.ts to cover the regression:
one that flips the autoCompactionEnabled switch then saves to ensure
updateDeepChatAgent is called with config.autoCompactionEnabled toggled (use the
component DeepChatAgentsSettings and the switch selector
'[data-testid="auto-compaction-enabled-switch"]'), and one that inputs
out-of-range/decimal values into
'[data-testid="auto-compaction-trigger-threshold-input"]' and
'[data-testid="auto-compaction-retain-recent-pairs-input"]' (e.g., negative or
>max and a decimal) then saves and assert config.autoCompactionTriggerThreshold
is clamped/rounded and config.autoCompactionRetainRecentPairs is clamped/rounded
in the payload passed to configPresenter.updateDeepChatAgent; reuse the existing
mocking pattern for configPresenter and assert updateDeepChatAgent mock.calls
payloads accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/renderer/settings/components/DeepChatAgentsSettings.vue`:
- Around line 1087-1092: The loaded compaction fields are being converted with
numText which differs from the save-path normalizers and causes persisted
out-of-range or stringified numbers to render incorrectly; update the
initialization of autoCompactionTriggerThreshold and
autoCompactionRetainRecentPairs to use the same helper functions used when
saving (the save-path normalizers) instead of numText so load/save behavior is
symmetric — locate where fromAgent and the save-path normalizers are defined and
replace the numText conversion for these two fields with those exact normalize
functions that the save path uses.

In `@test/renderer/components/DeepChatAgentsSettings.test.ts`:
- Around line 357-483: Add two tests in DeepChatAgentsSettings.test.ts to cover
the regression: one that flips the autoCompactionEnabled switch then saves to
ensure updateDeepChatAgent is called with config.autoCompactionEnabled toggled
(use the component DeepChatAgentsSettings and the switch selector
'[data-testid="auto-compaction-enabled-switch"]'), and one that inputs
out-of-range/decimal values into
'[data-testid="auto-compaction-trigger-threshold-input"]' and
'[data-testid="auto-compaction-retain-recent-pairs-input"]' (e.g., negative or
>max and a decimal) then saves and assert config.autoCompactionTriggerThreshold
is clamped/rounded and config.autoCompactionRetainRecentPairs is clamped/rounded
in the payload passed to configPresenter.updateDeepChatAgent; reuse the existing
mocking pattern for configPresenter and assert updateDeepChatAgent mock.calls
payloads accordingly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1dbf2000-d39e-4e13-bbd7-a1528be192e1

📥 Commits

Reviewing files that changed from the base of the PR and between 850336f and 39fa5e6.

📒 Files selected for processing (2)
  • src/renderer/settings/components/DeepChatAgentsSettings.vue
  • test/renderer/components/DeepChatAgentsSettings.test.ts

@zerob13 zerob13 merged commit 02bb6e4 into dev Apr 2, 2026
3 checks passed
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] 修改agents的自动压缩的设置后,配置无法保存

1 participant