fix started value on session list

This commit is contained in:
Oliver Kieselbach
2026-02-13 13:01:55 +01:00
parent 543b574014
commit ee489449fa
2 changed files with 40 additions and 5 deletions
@@ -91,6 +91,35 @@ namespace AutopilotMonitor.Functions.Services
{
var tableClient = _tableServiceClient.GetTableClient(Constants.TableNames.Sessions);
// If the agent restarts with the same session ID, preserve timeline/progress fields
// from the existing session row instead of resetting them to "fresh start".
DateTime startedAt = registration.StartedAt;
int currentPhase = (int)EnrollmentPhase.Start;
string status = SessionStatus.InProgress.ToString();
int eventCount = 0;
DateTime? completedAt = null;
string failureReason = string.Empty;
try
{
var existing = await tableClient.GetEntityAsync<TableEntity>(registration.TenantId, registration.SessionId);
var existingEntity = existing.Value;
var existingStartedAt = existingEntity.GetDateTimeOffset("StartedAt")?.UtcDateTime;
if (existingStartedAt.HasValue && existingStartedAt.Value < startedAt)
startedAt = existingStartedAt.Value;
currentPhase = existingEntity.GetInt32("CurrentPhase") ?? currentPhase;
status = existingEntity.GetString("Status") ?? status;
eventCount = existingEntity.GetInt32("EventCount") ?? eventCount;
completedAt = existingEntity.GetDateTimeOffset("CompletedAt")?.UtcDateTime;
failureReason = existingEntity.GetString("FailureReason") ?? string.Empty;
}
catch (RequestFailedException ex) when (ex.Status == 404)
{
// New session row - use defaults above.
}
var entity = new TableEntity(registration.TenantId, registration.SessionId)
{
["SerialNumber"] = registration.SerialNumber ?? string.Empty,
@@ -104,14 +133,20 @@ namespace AutopilotMonitor.Functions.Services
["AutopilotProfileId"] = registration.AutopilotProfileId ?? string.Empty,
["IsUserDriven"] = registration.IsUserDriven,
["IsPreProvisioned"] = registration.IsPreProvisioned,
["StartedAt"] = registration.StartedAt,
["StartedAt"] = startedAt,
["AgentVersion"] = registration.AgentVersion ?? string.Empty,
["EnrollmentType"] = registration.EnrollmentType ?? "v1",
["CurrentPhase"] = (int)EnrollmentPhase.Start,
["Status"] = SessionStatus.InProgress.ToString(),
["EventCount"] = 0
["CurrentPhase"] = currentPhase,
["Status"] = status,
["EventCount"] = eventCount
};
if (completedAt.HasValue)
entity["CompletedAt"] = completedAt.Value;
if (!string.IsNullOrWhiteSpace(failureReason))
entity["FailureReason"] = failureReason;
await tableClient.UpsertEntityAsync(entity);
_logger.LogInformation($"Stored session {registration.SessionId}");
return true;
@@ -545,7 +545,7 @@ export default function SessionDetailPage() {
{/* Session Info Card */}
{session && (
<div className="bg-white shadow rounded-lg p-6 mb-6">
<h2 className="text-xl font-semibold text-gray-900 mb-4">Device Information</h2>
<h2 className="text-xl font-semibold text-gray-900 mb-4">Session Info</h2>
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4">
<InfoItem label="Device" value={session.deviceName || session.serialNumber} />
<InfoItem label="Model" value={`${session.manufacturer} ${session.model}`} />