Repository: unoplatform/uno
File: src/Uno.UI.RemoteControl/HotReload/ClientHotReloadProcessor.Common.Status.cs (C#)

Code before:
		{
			var op = new HotReloadClientOperation(_source, types, NotifyStatusChanged);
			ImmutableInterlocked.Update(ref _localOperations, static (history, op) => history.Add(op).Sort(Compare), op);
			NotifyStatusChanged();

			return op;

			static int Compare(HotReloadClientOperation left, HotReloadClientOperation right)
				=> Comparer<long>.Default.Compare(left.Id, right.Id);
		}

		private void NotifyStatusChanged()
		{
			var status = BuildStatus();

			Current = status;
			try
			{
				owner.StatusChanged?.Invoke(this, status);
			}
			catch (Exception error)
			{
				this.Log().Error("Failed to notify the status changed.", error);
			}

			foreach (var serverOp in _serverOperations)
			{
				owner.ReportDiagnostics(serverOp.Value.Diagnostics);
			}
		}

		private Status BuildStatus()
		{
			var serverState = _serverState ?? (_localOperations.Any() ? HotReloadState.Ready /* no info */ : HotReloadState.Initializing);
			var localState = _localOperations.Any(op => op.Result is null) ? HotReloadState.Processing : HotReloadState.Ready;
			var globalState = _serverState switch
			{
				HotReloadState.Disabled => HotReloadState.Disabled,
				HotReloadState.Initializing => HotReloadState.Initializing,
				_ => (HotReloadState)Math.Max((int)serverState, (int)localState)
			};

			return new(globalState, (serverState, _serverOperations.Values.ToImmutableArray()), (localState, _localOperations));
		}
	}

	private void ReportDiagnostics(IImmutableList<string>? diagnostics)
	{
		if (
			diagnostics is { Count: > 0 }


Review comment (suggestion):
`_serverOperations` contains all operations since the start of the app, you will dump stale diagnostics here (cf. other suggestions)

Code after:
		}
#endif

		public void ConfigureSourceForNextOperation(HotReloadSource source)
			=> _source = source;

		public HotReloadClientOperation ReportLocalStarting(Type[] types)
		{
			var op = new HotReloadClientOperation(_source, types, NotifyStatusChanged);
			ImmutableInterlocked.Update(ref _localOperations, static (history, op) => history.Add(op).Sort(Compare), op);
			NotifyStatusChanged();

			return op;

			static int Compare(HotReloadClientOperation left, HotReloadClientOperation right)
				=> Comparer<long>.Default.Compare(left.Id, right.Id);
		}

		private void NotifyStatusChanged()
		{
			var status = BuildStatus();

			Current = status;
			try
			{
				owner.StatusChanged?.Invoke(this, status);
			}
			catch (Exception error)
			{
				this.Log().Error("Failed to notify the status changed.", error);
			}
		}

		private Status BuildStatus()
		{
			var serverState = _serverState ?? (_localOperations.Any() ? HotReloadState.Ready /* no info */ : HotReloadState.Initializing);
			var localState = _localOperations.Any(op => op.Result is null) ? HotReloadState.Processing : HotReloadState.Ready;
			var globalState = _serverState switch
			{
				HotReloadState.Disabled => HotReloadState.Disabled,
				HotReloadState.Initializing => HotReloadState.Initializing,
				_ => (HotReloadState)Math.Max((int)serverState, (int)localState)
			};

			return new(globalState, (serverState, _serverOperations.Values.ToImmutableArray()), (localState, _localOperations));
		}
	}

#if HAS_UNO_WINUI
	private void ReportDiagnostics(IImmutableList<string>? diagnostics)
	{