Repository navigation
Add Dashboard run history access for agents - #18934
James Newton-King (JamesNK) wants to merge 4 commits into
Conversation
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 18934Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 18934" |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Pull request overview
Adds stable Dashboard run IDs and historical telemetry access across Hosting, Dashboard HTTP APIs, CLI commands, and MCP tools.
Changes:
- Adds validated named run creation and launch output.
- Adds request-scoped historical telemetry and console-log APIs.
- Adds CLI/MCP query options, tests, localization, and specifications.
Reviewed changes
Copilot reviewed 81 out of 83 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
tests/Aspire.Hosting.Tests/Dashboard/DashboardEventHandlersTests.cs |
Tests duplicate run IDs. |
tests/Aspire.Hosting.Tests/Backchannel/AuxiliaryBackchannelRpcTargetTests.cs |
Tests backchannel run IDs. |
tests/Aspire.Dashboard.Tests/Model/DashboardDataSourceTests.cs |
Tests validation, storage, and leases. |
tests/Aspire.Dashboard.Tests/Integration/TelemetryApiTests.cs |
Tests historical API selection. |
tests/Aspire.Dashboard.Tests/Integration/StartupTests.cs |
Tests run-ID startup logging. |
tests/Aspire.Cli.Tests/Mcp/ListTraceStructuredLogsToolTests.cs |
Tests MCP run-ID forwarding. |
tests/Aspire.Cli.Tests/Mcp/ListTracesToolTests.cs |
Tests trace run-ID forwarding. |
tests/Aspire.Cli.Tests/Mcp/ListStructuredLogsToolTests.cs |
Tests log run-ID forwarding. |
tests/Aspire.Cli.Tests/Mcp/ListConsoleLogsToolTests.cs |
Tests historical console logs. |
tests/Aspire.Cli.Tests/Commands/StartCommandTests.cs |
Tests start validation. |
tests/Aspire.Cli.Tests/Commands/RunCommandTests.cs |
Tests launch behavior and output. |
tests/Aspire.Cli.Tests/Commands/LogsCommandTests.cs |
Tests historical log queries. |
tests/Aspire.Cli.Tests/Commands/AgentMcpCommandTests.cs |
Tests dashboard-only MCP tools. |
src/Shared/Otlp/Serialization/TelemetryApiResponse.cs |
Adds console-log DTOs. |
src/Shared/Otlp/Serialization/OtlpJsonSerializerContext.cs |
Registers console-log serialization. |
src/Shared/DashboardUrls.cs |
Builds run-scoped API URLs. |
src/Shared/DashboardRunStorage.cs |
Shares run-directory naming. |
src/Shared/DashboardConfigNames.cs |
Adds run configuration and validation. |
src/Aspire.Hosting/DistributedApplicationBuilder.cs |
Registers run identity. |
src/Aspire.Hosting/Dashboard/DashboardRunIdentity.cs |
Stores effective run identity. |
src/Aspire.Hosting/Dashboard/DashboardEventHandlers.cs |
Resolves and forwards run IDs. |
src/Aspire.Hosting/Backchannel/DashboardUrlsHelper.cs |
Reports run IDs over backchannel. |
src/Aspire.Hosting/Backchannel/BackchannelDataTypes.cs |
Extends backchannel contracts. |
src/Aspire.Hosting/Backchannel/AuxiliaryBackchannelRpcTarget.cs |
Returns run IDs through RPC. |
src/Aspire.Hosting/Aspire.Hosting.csproj |
Links shared storage helpers. |
src/Aspire.Dashboard/ServiceClient/DashboardRunStore.cs |
Supports named runs and metadata ordering. |
src/Aspire.Dashboard/ServiceClient/DashboardDataSource.cs |
Adds strict run selection. |
src/Aspire.Dashboard/DashboardWebApplication.cs |
Scopes telemetry API services. |
src/Aspire.Dashboard/DashboardEndpointsBuilder.cs |
Adds historical API routing. |
src/Aspire.Dashboard/Configuration/ValidateDashboardOptions.cs |
Validates configured IDs. |
src/Aspire.Dashboard/Configuration/PostConfigureDashboardOptions.cs |
Binds run configuration. |
src/Aspire.Dashboard/Configuration/DashboardOptions.cs |
Stores configured run ID. |
src/Aspire.Dashboard/Aspire.Dashboard.csproj |
Links shared storage helpers. |
src/Aspire.Dashboard/Api/TelemetryApiService.cs |
Queries selected-run telemetry. |
src/Aspire.Cli/Resources/xlf/TelemetryCommandStrings.zh-Hant.xlf |
Updates localization resources. |
src/Aspire.Cli/Resources/xlf/TelemetryCommandStrings.zh-Hans.xlf |
Updates localization resources. |
src/Aspire.Cli/Resources/xlf/TelemetryCommandStrings.tr.xlf |
Updates localization resources. |
src/Aspire.Cli/Resources/xlf/TelemetryCommandStrings.ru.xlf |
Updates localization resources. |
src/Aspire.Cli/Resources/xlf/TelemetryCommandStrings.pt-BR.xlf |
Updates localization resources. |
src/Aspire.Cli/Resources/xlf/TelemetryCommandStrings.pl.xlf |
Updates localization resources. |
src/Aspire.Cli/Resources/xlf/TelemetryCommandStrings.ko.xlf |
Updates localization resources. |
src/Aspire.Cli/Resources/xlf/TelemetryCommandStrings.ja.xlf |
Updates localization resources. |
src/Aspire.Cli/Resources/xlf/TelemetryCommandStrings.it.xlf |
Updates localization resources. |
src/Aspire.Cli/Resources/xlf/TelemetryCommandStrings.fr.xlf |
Updates localization resources. |
src/Aspire.Cli/Resources/xlf/TelemetryCommandStrings.es.xlf |
Updates localization resources. |
src/Aspire.Cli/Resources/xlf/TelemetryCommandStrings.de.xlf |
Updates localization resources. |
src/Aspire.Cli/Resources/xlf/TelemetryCommandStrings.cs.xlf |
Updates localization resources. |
src/Aspire.Cli/Resources/xlf/RunCommandStrings.zh-Hant.xlf |
Updates launch localization. |
src/Aspire.Cli/Resources/xlf/RunCommandStrings.zh-Hans.xlf |
Updates launch localization. |
src/Aspire.Cli/Resources/xlf/RunCommandStrings.tr.xlf |
Updates launch localization. |
src/Aspire.Cli/Resources/xlf/RunCommandStrings.ru.xlf |
Updates launch localization. |
src/Aspire.Cli/Resources/xlf/RunCommandStrings.pt-BR.xlf |
Updates launch localization. |
src/Aspire.Cli/Resources/xlf/RunCommandStrings.pl.xlf |
Updates launch localization. |
src/Aspire.Cli/Resources/xlf/RunCommandStrings.ko.xlf |
Updates launch localization. |
src/Aspire.Cli/Resources/xlf/RunCommandStrings.ja.xlf |
Updates launch localization. |
src/Aspire.Cli/Resources/xlf/RunCommandStrings.it.xlf |
Updates launch localization. |
src/Aspire.Cli/Resources/xlf/RunCommandStrings.fr.xlf |
Updates launch localization. |
src/Aspire.Cli/Resources/xlf/RunCommandStrings.es.xlf |
Updates launch localization. |
src/Aspire.Cli/Resources/xlf/RunCommandStrings.de.xlf |
Updates launch localization. |
src/Aspire.Cli/Resources/xlf/RunCommandStrings.cs.xlf |
Updates launch localization. |
src/Aspire.Cli/Resources/TelemetryCommandStrings.resx |
Adds telemetry messages. |
src/Aspire.Cli/Resources/TelemetryCommandStrings.Designer.cs |
Exposes telemetry resources. |
src/Aspire.Cli/Resources/RunCommandStrings.resx |
Adds launch messages. |
src/Aspire.Cli/Resources/RunCommandStrings.Designer.cs |
Exposes launch resources. |
src/Aspire.Cli/Mcp/Tools/McpToolHelpers.cs |
Parses optional MCP arguments. |
src/Aspire.Cli/Mcp/Tools/ListTraceStructuredLogsTool.cs |
Adds historical trace-log access. |
src/Aspire.Cli/Mcp/Tools/ListTracesTool.cs |
Adds historical trace access. |
src/Aspire.Cli/Mcp/Tools/ListStructuredLogsTool.cs |
Adds historical structured logs. |
src/Aspire.Cli/Mcp/Tools/ListConsoleLogsTool.cs |
Adds Dashboard console-log access. |
src/Aspire.Cli/Commands/TelemetryTracesCommand.cs |
Adds trace run selection. |
src/Aspire.Cli/Commands/TelemetrySpansCommand.cs |
Adds span run selection. |
src/Aspire.Cli/Commands/TelemetryLogsCommand.cs |
Adds structured-log run selection. |
src/Aspire.Cli/Commands/TelemetryCommandHelpers.cs |
Adds shared run-query behavior. |
src/Aspire.Cli/Commands/StartCommand.cs |
Forwards named run IDs. |
src/Aspire.Cli/Commands/RunCommand.cs |
Creates and displays named runs. |
src/Aspire.Cli/Commands/LogsCommand.cs |
Queries historical console logs. |
src/Aspire.Cli/Commands/AppHostLauncher.cs |
Propagates run IDs for detached launches. |
src/Aspire.Cli/Commands/AgentMcpCommand.cs |
Enables console logs in dashboard-only MCP. |
src/Aspire.Cli/Backchannel/AppHostAuxiliaryBackchannel.cs |
Carries run IDs through compatibility fallback. |
docs/specs/dashboard-persistence.md |
Documents named-run persistence. |
docs/specs/dashboard-http-api.md |
Documents historical HTTP APIs. |
docs/specs/cli-output-formats.md |
Documents CLI run output and queries. |
docs/specs/agent-run-history-diagnostics.md |
Adds the agent diagnostic workflow. |
Files not reviewed (2)
- src/Aspire.Cli/Resources/RunCommandStrings.Designer.cs: Generated file
- src/Aspire.Cli/Resources/TelemetryCommandStrings.Designer.cs: Generated file
| public static async Task<ResourceInfoJson[]> GetAllResourcesAsync(HttpClient client, string baseUrl, CancellationToken cancellationToken, string? runId = null) | ||
| { | ||
| var url = DashboardUrls.TelemetryResourcesApiUrl(baseUrl); | ||
| var url = DashboardUrls.TelemetryResourcesApiUrl(baseUrl, runId); |
| if (dashboardUrls.DashboardHealthy is false) | ||
| { | ||
| if (runId is not null) | ||
| { | ||
| await CancelAppHostStartupAsync(runCts, runTask, cancellationToken).ConfigureAwait(false); | ||
| return CommandResult.Failure(CliExitCodes.FailedToDotnetRunAppHost, RunCommandStrings.DashboardFailedToStartWithRunId); |
| foreach (var character in value) | ||
| { | ||
| if (!IsAsciiLetterOrDigit(character) && character is not '-' and not '_' and not '.') | ||
| { | ||
| errorMessage = "it may contain only ASCII letters, numbers, periods, underscores, and hyphens"; | ||
| return false; |
| _innerBuilder.Services.AddSingleton(new DashboardRunIdentity | ||
| { | ||
| RunId = configuredDashboardRunId, | ||
| IsUserSpecified = configuredDashboardRunId is not null | ||
| }); |
| var totalCount = logs.Count; | ||
| if (limit is > 0 && logs.Count > limit.Value) | ||
| { | ||
| logs = logs.Skip(logs.Count - limit.Value).ToList(); | ||
| } |
| else | ||
| { | ||
| if (_dashboardInfoProvider is null || _httpClientFactory is null) | ||
| { | ||
| throw new McpProtocolException("Historical console logs require a Dashboard connection.", McpErrorCode.InternalError); | ||
| } |
| if (runId is not null && ex.StatusCode == HttpStatusCode.NotFound) | ||
| { | ||
| return new TelemetryErrorInfo(FormatHistoricalRunNotFound(runId)); | ||
| } |
| if (runId is not null && ex is HttpRequestException { StatusCode: System.Net.HttpStatusCode.NotFound }) | ||
| { | ||
| throw new McpProtocolException(TelemetryCommandHelpers.FormatHistoricalRunNotFound(runId), McpErrorCode.InternalError); | ||
| } |
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
48c7529 to
e78b6b0
Compare
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 81 out of 83 changed files in this pull request and generated no new comments.
Files not reviewed (2)
- src/Aspire.Cli/Resources/RunCommandStrings.Designer.cs: Generated file
- src/Aspire.Cli/Resources/TelemetryCommandStrings.Designer.cs: Generated file
Suppressed comments (9)
src/Aspire.Hosting/DistributedApplicationBuilder.cs:233
- An empty configured value skips validation but is still marked user-specified and retained as
RunId = "". Hosting then either treats therunsdirectory itself as a duplicate or reports an empty run ID while the Dashboard'sfallbackOnEmptylogic creates a different timestamp ID. Normalize empty values to an unspecified run.
src/Aspire.Dashboard/Api/TelemetryApiService.cs:417 logsis populated one resource at a time, so it is grouped by resource rather than globally ordered. ApplyingSkiphere means an unfiltered multi-resource request returns lines from whichever resources were enumerated last, not the newest matching lines promised bylimit. Establish a global chronological/insertion order before taking the tail.
src/Aspire.Cli/Mcp/Tools/ListConsoleLogsTool.cs:104- The
ExcludeFromMcpcheck is confined to this live branch. SupplyingrunIdtakes the Dashboard branch and returns console logs for an excluded resource, violating the invariant that excluded resources are omitted from all MCP tool results. Apply exclusion handling to historical requests as well, using the selected run's resource metadata where necessary.
if (runId is null && _auxiliaryBackchannelMonitor is not null)
src/Aspire.Cli/Commands/TelemetryCommandHelpers.cs:358
- A 404 does not establish that the run is missing:
/console-logsalso returns 404 when the run exists but the requested resource does not. BecauseLogsCommandroutes that response through this method with a non-nullrunId,aspire logs typo --run-id valid-runincorrectly reports thatvalid-runwas not found. Preserve or inspect the problem details, or validate the run/resource separately.
if (runId is not null && ex.StatusCode == HttpStatusCode.NotFound)
{
return new TelemetryErrorInfo(FormatHistoricalRunNotFound(runId));
}
src/Aspire.Cli/Mcp/Tools/ListConsoleLogsTool.cs:217
- This similarly treats every historical console-log 404 as a missing run, but the endpoint returns the same status for an unknown resource in a valid run. MCP callers therefore receive the wrong diagnosis. Distinguish the Dashboard
Run not foundproblem fromResource not foundbefore formatting the exception.
if (runId is not null && ex is HttpRequestException { StatusCode: System.Net.HttpStatusCode.NotFound })
{
throw new McpProtocolException(TelemetryCommandHelpers.FormatHistoricalRunNotFound(runId), McpErrorCode.InternalError);
src/Aspire.Dashboard/DashboardEndpointsBuilder.cs:317
- This allows
follow=truewhenrunIdnames the current run because that selection is not read-only. The CLI rejects every--follow --run-idcombination, and the new HTTP contract says every request combining these parameters returns 400. Check whether an explicit run ID was supplied rather than whether it currently resolves as historical.
src/Aspire.Cli/Mcp/Tools/ListConsoleLogsTool.cs:141 resourceNameis required for this tool, and the live MCP path can query hidden resources (MCP discovery also requests hidden snapshots). PassingincludeHidden: falsemakes the historical path return “resource not found” for the same hidden resource. Preserve the live behavior for explicit resource queries.
includeHidden: false,
src/Aspire.Cli/Mcp/Tools/ListConsoleLogsTool.cs:21
- The summary is now inaccurate: this class forwards retained-run requests through the Dashboard API, and dashboard-only mode also uses that path without a
runId. Update it to describe the live-backchannel and Dashboard-snapshot behaviors.
internal sealed class ListConsoleLogsTool : CliMcpTool
tests/Aspire.Dashboard.Tests/Integration/TelemetryApiTests.cs:290
- This exercises only an empty historical response. It would still pass if console-log run selection accidentally returned the current repository or if persisted rows were never exposed. Seed distinct console lines in the historical and current runs, then assert that the
runIdrequest returns only the historical content.
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
e78b6b0 to
40e03c0
Compare
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 81 out of 83 changed files in this pull request and generated 1 comment.
Files not reviewed (2)
- src/Aspire.Cli/Resources/RunCommandStrings.Designer.cs: Generated file
- src/Aspire.Cli/Resources/TelemetryCommandStrings.Designer.cs: Generated file
Suppressed comments (9)
src/Aspire.Hosting/DistributedApplicationBuilder.cs:233
- An empty
ASPIRE_DASHBOARD_RUN_IDis skipped by validation but is still stored as a user-specified, non-null ID.ResolveRunIdentity()then preserves the empty string while the Dashboard treats it as absent, so launch output/backchannel metadata can report""instead of the Dashboard's generated ID (and non-Run persistence can fail unexpectedly). Normalize empty values tonullhere.
src/Aspire.Dashboard/Api/TelemetryApiService.cs:417 logsis grouped by resource because each resource is enumerated separately, so taking the finallimitentries does not return the newest lines across resources. For an unfilteredconsole-logs?limit=Nrequest, older lines from the last resource can displace newer lines from earlier resources, contradicting the endpoint's “newest matching lines” contract. Apply the limit against a global persisted ordering (or merge the per-resource streams by that ordering).
src/Aspire.Cli/Mcp/Tools/ListConsoleLogsTool.cs:136- The historical/HTTP branch bypasses the
ExcludeFromMcpcheck performed by the live branch, so supplyingrunIdcan expose console logs for a resource that the current AppHost explicitly removed from MCP. Preserve the exclusion check before issuing the historical request, matching the structured-log tools andMcpToolHelpers' requirement that excluded resources be omitted from all MCP results.
var (apiToken, apiBaseUrl, _) = await _dashboardInfoProvider.GetDashboardInfoAsync(cancellationToken).ConfigureAwait(false);
using var client = TelemetryCommandHelpers.CreateApiClient(_httpClientFactory, apiToken);
var url = DashboardUrls.TelemetryConsoleLogsApiUrl(
src/Aspire.Cli/Mcp/Tools/ListConsoleLogsTool.cs:217
- This treats every historical console-log 404 as a missing run, but
/console-logsalso returns 404 whenresourceNameis unknown. With a valid run and a mistyped resource, the MCP tool returns the wrong diagnostic. Inspect the ProblemDetails response (or otherwise distinguish resource-not-found) before emittingHistoricalRunNotFound.
if (runId is not null && ex is HttpRequestException { StatusCode: System.Net.HttpStatusCode.NotFound })
{
throw new McpProtocolException(TelemetryCommandHelpers.FormatHistoricalRunNotFound(runId), McpErrorCode.InternalError);
src/Aspire.Cli/Commands/LogsCommand.cs:388
- The console-log endpoint returns 404 for both an unknown run and an unknown resource, but passing
runIdto this formatter classifies every 404 as “run not found.” A typo inaspire logs <resource> --run-id <valid-run>therefore reports that the valid run is missing. Preserve the endpoint's ProblemDetails distinction (or otherwise distinguish the resource 404) before formatting the error.
dashboardOnly: false,
_httpClientFactory,
_logger,
cancellationToken,
runId).ConfigureAwait(false);
src/Aspire.Hosting/Backchannel/DashboardUrlsHelper.cs:163
DashboardRunIdentity.RunIdis allocated before the Dashboard creates or opens the run. Returning it from an unhealthy connection causesaspire run/startto print a “Dashboard run ID” (and emitrunIdin JSON) even when the Dashboard never persisted that run. Unhealthy connection info should not advertise the proposed ID as an available persisted run.
docs/specs/dashboard-http-api.md:129- This states that any request combining
follow=trueandrunIdreturns 400, butValidateRunSelectiononly rejects when the selected run is historical; passing the current run's ID streams successfully. Document the actual historical-only restriction (or change the endpoint contract) so direct HTTP clients are not given a false guarantee.
Streaming is available only for the current run. Requests that combine `follow=true` with `runId` return `400 Bad Request`.
docs/specs/agent-run-history-diagnostics.md:233
- The implementation permits
follow=truewhenrunIdnames the current run and rejects only historical selections, so this unconditional statement is inaccurate. Align this direct-HTTP contract withValidateRunSelection.
- `follow=true` with `runId` returns `400 Bad Request`; and
src/Aspire.Cli/Commands/StartCommand.cs:97
- This user-visible option relies on several process boundaries—
startforwarding to detachedrun, environment propagation into the AppHost, Dashboard persistence/backchannel output, shutdown, and a later historical query—but the added tests exercise those pieces only with mocks. Add a CLI E2E scenario that starts an AppHost with--run-id, captures the emitted ID, stops it, and queries retained logs/telemetry; otherwise argument or protocol integration regressions can ship while all focused tests pass.
if (runId is not null)
{
debugSessionArgs.Add(AppHostLauncher.s_runIdOption.Name);
debugSessionArgs.Add(runId);
}
| { | ||
| await foreach (var batch in _dataSource.ResourceRepository.GetConsoleLogs(resource.Name, cancellationToken).ConfigureAwait(false)) | ||
| { | ||
| logs.AddRange(batch |
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
40e03c0 to
c42c0f5
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 81 out of 83 changed files in this pull request and generated 1 comment.
Files not reviewed (2)
- src/Aspire.Cli/Resources/RunCommandStrings.Designer.cs: Generated file
- src/Aspire.Cli/Resources/TelemetryCommandStrings.Designer.cs: Generated file
Suppressed comments (8)
src/Aspire.Hosting/DistributedApplicationBuilder.cs:228
- An explicitly configured empty run ID bypasses both validation checks, but is stored as user-specified.
ResolveRunIdentitythen does not generate an ID and checks the existingrunsdirectory as the run directory, producing a misleading duplicate-ID failure. Treat every non-null configured value as input to validate so empty values fail with the intended validation error.
src/Aspire.Dashboard/Api/TelemetryApiService.cs:417 - The list is built resource-by-resource, so taking the final
limitentries does not select the globally newest console lines. Foraspire logs --run-id ... --tail Nwithout a resource filter, results depend on resource enumeration order and can omit newer lines from earlier resources. Merge/order lines globally (for example by the persisted console-log sequence/timestamp) before applying the limit.
src/Aspire.Dashboard/Api/TelemetryApiService.cs:397 limitis applied only after every selected resource has loaded all console rows.SqliteResourceRepository.GetConsoleLogsperforms an unboundedSELECTfollowed byToArray, so even a tail request for 100 lines materializes the entire retained run and can consume excessive memory. Push filtering and limiting into a repository-level SQLite query.
src/Aspire.Cli/Commands/TelemetryCommandHelpers.cs:358- A 404 does not uniquely mean the run is missing: the telemetry API also returns 404 for an unknown resource and for a missing trace. With a valid
runId, those failures are now reported as “Dashboard run ... was not found,” hiding the actual error. Classify the RFC 7807 response (or retain endpoint-specific context) before formatting a run-not-found message.
if (runId is not null && ex.StatusCode == HttpStatusCode.NotFound)
{
return new TelemetryErrorInfo(FormatHistoricalRunNotFound(runId));
}
src/Aspire.Cli/Commands/TelemetryCommandHelpers.cs:525
- Older Dashboard telemetry endpoints ignore unknown query parameters, so they accept
runIdbut return current resources and telemetry. Because this helper never verifies run-selection support or the selected run, new CLI/MCP clients can silently diagnose current data as a requested historical run, contrary to the strict no-fallback contract. Add a capability/selected-run check (for example via backchannel info or an echoed API run identity) and reject unsupported Dashboards.
public static async Task<ResourceInfoJson[]> GetAllResourcesAsync(HttpClient client, string baseUrl, CancellationToken cancellationToken, string? runId = null)
{
var url = DashboardUrls.TelemetryResourcesApiUrl(baseUrl, runId);
var response = await client.GetAsync(url, cancellationToken).ConfigureAwait(false);
EnsureTelemetryApiResponse(response);
src/Aspire.Cli/Mcp/Tools/ListConsoleLogsTool.cs:105
ExcludeFromMcppromises that a resource is excluded from console-log and telemetry results, but the exclusion check is only executed in the live (runId is null) branch. Supplying any run ID bypasses it and exposes that resource’s retained console logs to the agent. When a backchannel monitor is available, enforce the exclusion before choosing the live or historical transport.
if (runId is null && _auxiliaryBackchannelMonitor is not null)
{
src/Aspire.Cli/Mcp/Tools/ListConsoleLogsTool.cs:218
- The console-log endpoint also returns 404 when the requested resource does not exist. For a valid historical run plus an unknown resource, this branch incorrectly throws “Dashboard run ... was not found.” Inspect the problem response or validate the resource separately so resource-not-found remains distinguishable.
if (runId is not null && ex is HttpRequestException { StatusCode: System.Net.HttpStatusCode.NotFound })
{
throw new McpProtocolException(TelemetryCommandHelpers.FormatHistoricalRunNotFound(runId), McpErrorCode.InternalError);
}
src/Shared/DashboardConfigNames.cs:73
- Interpolated
DateTimeOffsetformatting uses the current culture. Under a non-Gregorian culture, the automatic ID can use a different calendar year (for example 2569 instead of 2026), violating the documented fixed UTC timestamp format and making IDs locale-dependent. Format invariantly as the previous implementation did.
| // PruneRuns, so a non-Gregorian current culture (th-TH, ar-SA) would produce IDs that sort | ||
| // against previous runs incorrectly and let retention delete newer runs. | ||
| var runId = startedAt.ToString("yyyyMMddTHHmmssfffZ", CultureInfo.InvariantCulture); | ||
| var runId = $"{startedAt:yyyyMMddTHHmmssfffZ}"; |
2230993 to
13adb39
Compare
Tests selector (audit mode)The full test matrix and all jobs still run in audit mode. The tests and jobs below are what selective CI would run under enforcement. 53 / 100 test projects · 5 jobs, from 79 changed files. Selected test projects (53 / 100)
Selected jobs (5)
How these were chosen — grouped by what changed
🔧 show 42
🧪 🔧 📦 affected project 📦 affected project 🔧 🧪 🧪 🧪 🧪 🧪 🧪 🧪 🧪 🧪 🧪 🧪 🧪 Job reasons
Selection computed for commit |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 81 out of 83 changed files in this pull request and generated 1 comment.
Files not reviewed (2)
- src/Aspire.Cli/Resources/RunCommandStrings.Designer.cs: Generated file
- src/Aspire.Cli/Resources/TelemetryCommandStrings.Designer.cs: Generated file
Suppressed comments (6)
src/Aspire.Cli/Commands/TelemetryCommandHelpers.cs:357
- A 404 does not uniquely mean the run is missing: these endpoints also return 404 for an unknown resource or trace, and an older Dashboard/API-disabled route can do the same. For example, a valid run plus a missing trace is now reported as “Dashboard run ... was not found.” Preserve and inspect the RFC 7807 response (or a typed error code) before choosing the run-not-found message.
if (runId is not null && ex.StatusCode == HttpStatusCode.NotFound)
{
return new TelemetryErrorInfo(FormatHistoricalRunNotFound(runId));
src/Aspire.Cli/Mcp/Tools/ListConsoleLogsTool.cs:217
- This also treats every historical console-log 404 as a missing run, but
/console-logsreturns 404 when the requested resource is absent from an existing run. That case now throws the wrong MCP error. Distinguish the API'sRun not foundProblemDetails fromResource not foundinstead of relying only on status code.
if (runId is not null && ex is HttpRequestException { StatusCode: System.Net.HttpStatusCode.NotFound })
{
throw new McpProtocolException(TelemetryCommandHelpers.FormatHistoricalRunNotFound(runId), McpErrorCode.InternalError);
src/Aspire.Dashboard/Api/TelemetryApiService.cs:417
- The list is built resource-by-resource, so applying
Skiphere returns the last lines of the last enumerated resource, not the newest matching lines across resources. Consequently,aspire logs --run-id ... --tail Nwithout a resource can omit newer logs from earlier resources. Apply the limit using a globally ordered persisted key/timestamp.
src/Aspire.Cli/Mcp/Tools/ListConsoleLogsTool.cs:128 - This historical/API branch skips the
resource.excludeFromMcpcheck that protects the live branch, so an agent can read excluded console logs by supplyingrunId. The historical snapshot's exclusion metadata must be enforced before returning logs; checking only the current AppHost model is insufficient when resources or annotations changed between runs.
else
{
src/Aspire.Cli/Commands/RunCommand.cs:325
- This cross-process contract is covered only by mocked CLI unit tests; no test under
tests/Aspire.Cli.EndToEnd.Testsuses--run-id. Add a Hex1b E2E scenario that launches a named run, verifies the emitted ID, stops it, and queries its retained telemetry so argument/environment forwarding, Dashboard persistence, backchannel output, and historical lookup are validated together.
if (runId is not null)
{
context.EnvironmentVariables[DashboardConfigNames.DashboardRunIdName.EnvVarName] = runId;
}
src/Aspire.Hosting/Backchannel/DashboardUrlsHelper.cs:163
- This unconditionally exposes the precomputed identity when the Dashboard is unhealthy. If the Dashboard process fails before creating its run directory, a normal unnamed launch continues and displays/serializes this
RunIdeven though it cannot be queried. Only expose the run ID after Dashboard health establishes that the persisted run started.
| { | ||
| public const int MaxLength = 64; | ||
|
|
||
| public static string Create(DateTimeOffset startedAt) => $"{startedAt:yyyyMMddTHHmmssfffZ}"; |
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
13adb39 to
9f1f357
Compare
9f1f357 to
1e5fc30
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 81 out of 83 changed files in this pull request and generated no new comments.
Files not reviewed (2)
- src/Aspire.Cli/Resources/RunCommandStrings.Designer.cs: Generated file
- src/Aspire.Cli/Resources/TelemetryCommandStrings.Designer.cs: Generated file
Suppressed comments (6)
src/Shared/DashboardConfigNames.cs:73
- Automatic run IDs are now formatted with the ambient current culture. Under a non-Gregorian culture (for example
th-TH), the year can differ from the UTC/GregorianyyyyMMdd...identifier expected by the storage contract and tests. Format withInvariantCulture, as the extracted code did before this refactor.
src/Aspire.Cli/Commands/TelemetryCommandHelpers.cs:358 - A
404is not sufficient to conclude that the run is missing. For example,aspire otel traces --trace-id missing --run-id valid-runreaches the trace-detail endpoint and receivesTrace not found, but this branch reportsDashboard run 'valid-run' was not found; a missing console-log resource is similarly misreported. Preserve or inspect the API problem details (or separately validate the run) before converting the error.
if (runId is not null && ex.StatusCode == HttpStatusCode.NotFound)
{
return new TelemetryErrorInfo(FormatHistoricalRunNotFound(runId));
}
src/Aspire.Cli/Mcp/Tools/ListConsoleLogsTool.cs:104
- The
ExcludeFromMcpguard now runs only on the live-backchannel path. SupplyingrunIdtakes the HTTP path and returns historical console output for the same resource without checking the exclusion, exposing data that this MCP policy is intended to hide. PerformCheckResourceExcludedAsyncbefore branching whenever a backchannel monitor is available.
if (runId is null && _auxiliaryBackchannelMonitor is not null)
src/Aspire.Dashboard/Api/TelemetryApiService.cs:417
- For an all-resource query, logs are appended resource-by-resource and
limitis applied only after concatenation. The result is therefore the tail of the last enumerated resource, not the newest matching lines across the run as the API specifies; newer lines from an earlier resource can be discarded. Apply a globally ordered limit, ideally in the repository query.
src/Aspire.Dashboard/DashboardEndpointsBuilder.cs:318 - The documented HTTP contract rejects
follow=truewheneverrunIdis supplied, but this condition allows streaming when the explicit ID names the current run. This also differs from the CLI, which rejects every--follow --run-idcombination. Check the presence ofrunId, not whether the selected run happens to be historical.
src/Aspire.Dashboard/Api/TelemetryApiService.cs:395 - This endpoint can only return console rows that were already copied into SQLite. The only production writes occur when
DashboardClient.GetConsoleLogs/SubscribeConsoleLogsis called, so a run whose console stream was never viewed or exported still returns an empty snapshot after the AppHost exits. That leaves the advertised after-the-fact console diagnosis unavailable; persist console streams independently of a live reader before considering the run retained.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 81 out of 83 changed files in this pull request and generated no new comments.
Files not reviewed (2)
- src/Aspire.Cli/Resources/RunCommandStrings.Designer.cs: Generated file
- src/Aspire.Cli/Resources/TelemetryCommandStrings.Designer.cs: Generated file
Suppressed comments (7)
src/Shared/DashboardConfigNames.cs:73
- This reintroduces culture-dependent automatic run IDs: interpolated
DateTimeOffsetformatting uses the current culture, so cultures with non-Gregorian calendars can produce different years and break the durable ID format and chronological ordering. The previous implementation explicitly used invariant culture; preserve that invariant here.
src/Aspire.Dashboard/Api/TelemetryApiService.cs:395 limitis applied only after every matching console line has been materialized.SqliteResourceRepository.GetConsoleLogsalready loads each resource's complete log into an array, and this code copies all matches into another list before retaining the tail, so MCP's bounded requests still consume memory proportional to the entire persisted run. Push tail/search filtering into the repository, or maintain a bounded tail while scanning.
src/Aspire.Cli/Commands/TelemetryCommandHelpers.cs:357- A 404 with
runIddoes not prove that the run is missing: the new API also returns 404 for an unknown resource and for an unknown trace. For example, querying a missing trace in a valid historical run now reports that the run was not found. Preserve/inspect the RFC 7807 response or otherwise distinguish run-selection failures before emittingHistoricalRunNotFound.
if (runId is not null && ex.StatusCode == HttpStatusCode.NotFound)
{
return new TelemetryErrorInfo(FormatHistoricalRunNotFound(runId));
src/Aspire.Cli/Mcp/Tools/ListConsoleLogsTool.cs:134
- Supplying
runIdbypasses theExcludeFromMcpcheck performed by the live-log branch, exposing historical console logs for resources that explicitly opted out of all MCP results. Apply the same exclusion check before querying the Dashboard whenever a backchannel monitor is available.
var (apiToken, apiBaseUrl, _) = await _dashboardInfoProvider.GetDashboardInfoAsync(cancellationToken).ConfigureAwait(false);
src/Aspire.Hosting/DistributedApplicationBuilder.cs:221
- The documented
Dashboard:Data:RunIdconfiguration key is ignored here; only the environment-variable key is read. The Dashboard itself gives the config key precedence, so an AppHost configured withDashboard:Data:RunId=incident-42will createincident-42while hosting reports and preflights an unrelated generated timestamp ID. Read both keys with the same precedence and empty-value handling asPostConfigureDashboardOptions.
src/Aspire.Cli/Mcp/Tools/ListConsoleLogsTool.cs:141 resourceNameis required for this tool, and MCP resource discovery includes hidden resources, but the historical request excludes them. A resource returned bylist_resourcescan therefore be queried live yet incorrectly return 404 when the same call addsrunId. Explicit resource selection should include hidden resources, asLogsCommandalready does.
includeHidden: false,
src/Aspire.Cli/Commands/AppHostLauncher.cs:83
- This user-visible launch option has only mocked/unit coverage; there is no CLI E2E test under
Aspire.Cli.EndToEnd.Testsproving--run-idsurvives a real detached launch, appears in JSON output, and can be used to query the retained run after the AppHost stops. That cross-process path spans CLI argument forwarding, environment propagation, hosting preflight, Dashboard storage, backchannel reporting, and the telemetry API, so add a Hex1b E2E scenario covering the advertised agent workflow.
command.Options.Add(s_runIdOption);
Description
Agents need a stable way to diagnose an Aspire application after an AppHost run has ended and to compare telemetry across reproductions. This change makes persisted Dashboard runs addressable from the CLI, the CLI MCP server, and the Dashboard telemetry HTTP API.
Users can assign a validated, unique run ID with
aspire start --run-idoraspire run --run-id. The effective ID is included in launch output. Console logs, structured logs, traces, and spans can then be queried from an immutable retained run by passing--run-id; the four corresponding MCP tools accept the same optionalrunId. Historical streaming is rejected, and missing runs return explicit errors rather than falling back to current data.The Dashboard performs the authoritative duplicate check using an adjacent run lock, exposes request-scoped historical snapshots, and persists console-log snapshots for historical access. The specs include an end-to-end agent workflow for before/after diagnosis and trace-to-log correlation.
This PR is stacked on and depends on #18925.
User-facing usage
Create named runs for a before/after investigation:
Compare retained telemetry after either AppHost has stopped:
The CLI MCP server exposes
runIdon:list_console_logslist_structured_logslist_traceslist_trace_structured_logsScreenshots / Recordings
TODO: Capture
aspire start --run-id incident-42 --format jsonand a historical telemetry query.Security considerations
The user-provided run ID becomes part of a path under the Dashboard data directory. Run IDs are restricted to portable ASCII slugs, reject traversal, separators, Unicode, edge punctuation, and Windows device names, and are checked again by the Dashboard before creating storage. Historical telemetry remains protected by the Dashboard API's existing authentication mode and may contain sensitive diagnostic data. Security review has not yet been completed.
Validation
Aspire.Cli.Tests: 243 affected tests passed.Aspire.Dashboard.Tests: 119 affected tests passed.Aspire.Hosting.Tests: 88 affected tests passed.build.cmd /p:SkipNativeBuild=truesucceeded.Fixes # (issue)
Checklist
<remarks />and<code />elements on your triple slash comments?