Skip to content

Fix StarAgentSetting.OnLoaded overwriting user-cleared Services config with example entries#158

Merged
nnhy merged 2 commits into
masterfrom
copilot/fix-onloaded-example-services
Jul 20, 2026
Merged

Fix StarAgentSetting.OnLoaded overwriting user-cleared Services config with example entries#158
nnhy merged 2 commits into
masterfrom
copilot/fix-onloaded-example-services

Conversation

Copilot AI commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

StarAgentSetting.OnLoaded unconditionally populated 4 example services whenever Services was null or empty, causing every subsequent Save() call (e.g. via WebPanel) to persist those examples — silently overwriting an intentionally empty user config.

Changes

  • StarAgent/Setting.cs: Gate example-service population on IsNew so it only runs on first-time config creation, not on every load of an empty/cleared config
  • Add Services ??= [] in the else branch to ensure Services is never null after load
// Before
if (Services == null || Services.Length == 0)
{
    Services = [si, si2, si3, si4];
}

// After
if ((Services == null || Services.Length == 0) && IsNew)
{
    Services = [si, si2, si3, si4];
}
else
{
    Services ??= [];
}

First-run behavior (example services as reference) is preserved; existing configs with a cleared <Services> node are left untouched.

Copilot AI changed the title [WIP] Fix OnLoaded to prevent overriding user configurations with example services Fix StarAgentSetting.OnLoaded overwriting user-cleared Services config with example entries Jul 20, 2026
Copilot finished work on behalf of nnhy July 20, 2026 14:11
Copilot AI requested a review from nnhy July 20, 2026 14:11
@nnhy
nnhy marked this pull request as ready for review July 20, 2026 15:01
Copilot AI review requested due to automatic review settings July 20, 2026 15:01
@nnhy
nnhy merged commit e263afd into master Jul 20, 2026
1 check passed

Copilot AI 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.

Pull request overview

This PR prevents StarAgentSetting.OnLoaded() from repopulating example Services entries after a user has intentionally cleared the services configuration, avoiding silent reintroduction of sample services on subsequent Save() calls (e.g., via WebPanel).

Changes:

  • Gate example service population behind IsNew, so sample services are only added on first-time config creation.
  • Ensure Services is never left null after load by initializing it to an empty array when appropriate.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

StarAgentSetting.OnLoaded 在 Services 为空时强制填充示例服务,覆盖用户真实配置

3 participants