Skip to content

Fix replica parent resource state#18641

Draft
adamint wants to merge 2 commits into
microsoft:mainfrom
adamint:adamint-fix-replica-resource-state
Draft

Fix replica parent resource state#18641
adamint wants to merge 2 commits into
microsoft:mainfrom
adamint:adamint-fix-replica-resource-state

Conversation

@adamint

@adamint adamint commented Jul 4, 2026

Copy link
Copy Markdown
Member

Description

The dashboard could show a replica as Running while the parent resource row stayed stuck on a custom scale-to-zero state. That made Azure Container Apps with min replicas set to 0 look idle even after traffic woke up a replica.

This keeps the original resource snapshots around and derives an effective parent state for the Resources page: if a nested replica with the same display name is Running, the parent row is shown as Running; when replicas scale back down, the parent goes back to its own snapshot state.

The follow-up fix from review keeps effective state out of the raw resource cache so query/filter refreshes cannot make the parent stay Running after the replica disappears.

Screenshots / Recordings

This PR includes UI changes. Please add screenshots or screen recordings so reviewers can evaluate the visual changes without running locally.

  • For before/after comparisons, place them side-by-side or label them clearly.
  • For interactive changes (animations, transitions, new flows), prefer a short screen recording (GIF or video).
  • If you cannot capture visuals now, note what scenario to test and mark this section as TODO.

TODO: Capture an ACA scale-to-zero resource before/after. The scenario to verify is an Azure Container App parent row that starts as Scaled to zero, receives traffic, and has a child replica transition to Running.

User-facing usage

Users do not need to change anything. On the Resources page, a scale-to-zero parent resource now reflects a running child replica instead of continuing to look scaled down.

Validation

Passed locally on 16f1f93f7049c6b4e80642bd373ccbec7d00eef1:

dotnet test tests/Aspire.Dashboard.Components.Tests/Aspire.Dashboard.Components.Tests.csproj --no-launch-profile -- --filter-class "*.ResourcesTests" --filter-not-trait "quarantined=true" --filter-not-trait "outerloop=true"
dotnet test tests/Aspire.Dashboard.Components.Tests/Aspire.Dashboard.Components.Tests.csproj --no-launch-profile -- --filter-not-trait "quarantined=true" --filter-not-trait "outerloop=true"
dotnet test tests/Aspire.Dashboard.Tests/Aspire.Dashboard.Tests.csproj --no-launch-profile -- --filter-not-trait "quarantined=true" --filter-not-trait "outerloop=true"
git diff --check

Review fleet completed. The high-confidence raw/effective cache finding was fixed and covered by regression tests.

Resolves #13909

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 4, 2026 15:49
@github-actions

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 18641

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 18641"

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 fixes a Resources-page state inconsistency where an Azure Container App parent row could remain stuck on a custom scale-to-zero state even after one of its replicas woke up and became Running. It does this by keeping the raw resource snapshots separate from a derived "effective" view: when a nested replica (same ParentName and display name) is Running, the parent row is projected as Running; when replicas scale back down, the parent reverts to its own snapshot state.

Changes:

  • Split resource storage into _rawResourceByName (source-of-truth snapshots) and _resourceByName (effective/derived view), and rebuild the effective view via UpdateEffectiveResourceStateCache / TryCreateEffectiveReplicaParentResource / CanShowReplicaRunningState.
  • Added ResourceViewModel.WithState(...) to clone a resource with overridden State/StateStyle/KnownState, and refreshed the selected resource to its effective projection so the details view stays in sync.
  • Added a component test covering the parent-tracks-running-child transition and its revert.
Show a summary per file
File Description
src/Aspire.Dashboard/Components/Pages/Resources.razor.cs Introduces raw vs. effective resource caches and derives parent state from running child replicas; keeps the selected resource projection in sync.
src/Aspire.Dashboard/Model/ResourceViewModel.cs Adds internal WithState helper to produce a state-overridden copy while preserving all other properties.
tests/Aspire.Dashboard.Components.Tests/Pages/ResourcesTests.cs Adds a test for the parent-follows-running-child behavior plus displayName/CreateParentProperties test helpers.

Review details

  • Files reviewed: 3/3 changed files
  • Comments generated: 2
  • Review effort level: Medium

Comment on lines 382 to 394
UpdateEffectiveResourceStateCache();

foreach (var effectiveResource in _resourceByName.Values)
{
PageViewModel.ResourceTypesToVisibility.AddOrUpdate(resource.ResourceType, resourceTypeVisible(resource.ResourceType), (_, _) => resourceTypeVisible(resource.ResourceType));
// Don't add Parameter to resource type filters. Parameters have their own dedicated view
// and are excluded from the Table and Graph views regardless of the type filter.
if (!effectiveResource.IsParameter)
{
PageViewModel.ResourceTypesToVisibility.AddOrUpdate(effectiveResource.ResourceType, resourceTypeVisible(effectiveResource.ResourceType), (_, _) => resourceTypeVisible(effectiveResource.ResourceType));
}
PageViewModel.ResourceStatesToVisibility.AddOrUpdate(effectiveResource.State ?? string.Empty, stateVisible(effectiveResource.State ?? string.Empty), (_, _) => stateVisible(effectiveResource.State ?? string.Empty));
PageViewModel.ResourceHealthStatusesToVisibility.AddOrUpdate(effectiveResource.HealthStatus?.Humanize() ?? string.Empty, healthStatusVisible(effectiveResource.HealthStatus?.Humanize() ?? string.Empty), (_, _) => healthStatusVisible(effectiveResource.HealthStatus?.Humanize() ?? string.Empty));
}
};
}

private static ImmutableDictionary<string, ResourcePropertyViewModel> CreateParentProperties(string parentName)
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Resource state isn't updating on replica state

2 participants