refactor(agent): remove obsolete compatibility paths

This commit is contained in:
2026-09-27 14:20:57 +08:00
parent bfa0059d3a
commit 083aeef18a
12 changed files with 18 additions and 313 deletions
@@ -19,31 +19,17 @@ public sealed class RemoteAgentHostedService(
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
RemoteAgentOptions? configuredRemote = options.Remote;
if (!string.IsNullOrWhiteSpace(options.RemoteConfigurationFile))
{
try
{
configuredRemote = (await RemoteNodeConfigurationStore.LoadAsync(options.RemoteConfigurationFile, stoppingToken)).Remote;
}
catch (Exception exception) when (exception is IOException or JsonException or WxAgentException)
{
logger.LogWarning("Remote agent is disabled because the external configuration could not be loaded; type={ExceptionType}.", exception.GetType().Name);
return;
}
}
if (configuredRemote is null || !configuredRemote.IsConfigured)
var remote = options.Remote;
if (remote is null || !remote.IsConfigured)
{
logger.LogInformation("Remote agent is disabled because authAddress, token or nodeId is not configured.");
return;
}
var remote = configuredRemote;
using var client = new RemoteControlClient(remote);
var ledger = new RemoteTaskLedger(Path.Combine(options.DataDirectory, "remote-task-ledger.json"));
var eventQueue = remoteQueue ?? new RemoteEventQueue(Path.Combine(options.DataDirectory, "remote-event-queue.json"));
// A configured Agent connection is the data-sync authorization boundary.
// EnableDataSync remains only as a read-compatibility property for old service.json files.
var dataQueue = new RemoteDataBatchQueue(
Path.Combine(options.DataDirectory, "remote-data-queue.json"), options.DataSyncQueueMaxItems, options.DataSyncQueueMaxBytes);
var syncState = new RemoteDataSyncStateStore(Path.Combine(options.DataDirectory, "remote-data-sync-state.json"));
@@ -52,33 +38,14 @@ public sealed class RemoteAgentHostedService(
string? registeredActiveAccountId = null;
bool? registeredActiveAccountVerified = null;
long registeredReportingConfigVersion = -1;
var initialReporting = options.Reporting;
if (!string.IsNullOrWhiteSpace(options.RemoteConfigurationFile))
{
try
{
initialReporting = (await LoadRuntimeConfigurationAsync(options, stoppingToken)).Reporting;
}
catch (Exception exception) when (exception is IOException or JsonException or WxAgentException)
{
logger.LogWarning("Remote reporting configuration could not be loaded for offline collection; type={ExceptionType}.", exception.GetType().Name);
}
}
ReportingConfig? activeReporting = ConnectionAuthorizedReporting(initialReporting, null);
ReportingConfig? activeReporting = ConnectionAuthorizedReporting(options.Reporting, null);
var retry = RetryDelay;
while (!stoppingToken.IsCancellationRequested)
{
try
{
var runtime = await LoadRuntimeConfigurationAsync(options, stoppingToken);
if (!runtime.Remote.IsConfigured || !runtime.Remote.Equals(remote))
{
logger.LogWarning("Remote configuration changed or is not valid; remote work is paused until the service is restarted.");
await DelayAsync(RetryDelay, stoppingToken);
continue;
}
var snapshot = await ReadSnapshotAsync(remote, stoppingToken);
var reporting = ConnectionAuthorizedReporting(runtime.Reporting, snapshot);
var reporting = ConnectionAuthorizedReporting(options.Reporting, snapshot);
activeReporting = reporting;
var registrationNeedsRefresh = client.AuthState != RemoteAuthState.Authenticated
|| !string.Equals(registeredActiveAccountId, snapshot.ActiveAccountId, StringComparison.Ordinal)
@@ -293,11 +260,6 @@ public sealed class RemoteAgentHostedService(
{
remote = await client.GetDataSyncStatusAsync(account.AccountId, cancellationToken, streamKey).ConfigureAwait(false);
}
catch (RemoteClientException exception) when (exception.StatusCode == 404 && exception.Code == "NotFound")
{
// Older control planes do not expose the reconciliation endpoint; retain the legacy ACK path.
continue;
}
catch (RemoteClientException exception) when (exception.StatusCode == 403 && exception.Code == "AccountNotAuthorized")
{
var droppedOnRevoke = queue.DropAllForAccount(account.AccountId);
@@ -879,13 +841,6 @@ public sealed class RemoteAgentHostedService(
JsonElement Content,
IReadOnlyList<RemoteReportingScope> ChatScopes);
private static async Task<RemoteNodeConfiguration> LoadRuntimeConfigurationAsync(ServiceOptions options, CancellationToken cancellationToken)
{
if (string.IsNullOrWhiteSpace(options.RemoteConfigurationFile))
return new RemoteNodeConfiguration { Remote = options.Remote ?? new RemoteAgentOptions(), Reporting = options.Reporting };
return await RemoteNodeConfigurationStore.LoadAsync(options.RemoteConfigurationFile, cancellationToken);
}
private static async Task ReplayUnreportedResultsAsync(
RemoteControlClient client,
RemoteTaskLedger ledger,