Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/AgentOs.Modules.Sessions/Persistence/DeliverySummary.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Delivery quality of a tenant's AI tasks — the numbers that say whether the agents (and the lessons they learn) get
// better: how many tasks merged, how many on the first try (no change ever sent back), how many fix rounds a task
// needs, and how long a ticket takes from task start to merge.

using System;
using System.Collections.Generic;
using System.Linq;

namespace AgentOs.Modules.Sessions.Persistence;

/// <summary>Delivery of merged tasks in a period, plus the tasks stuck right now.</summary>
/// <param name="Merged">Tasks whose changes all merged.</param>
/// <param name="FirstTry">Of those, merged without a single change sent back.</param>
/// <param name="AverageFixRounds">Mean fix rounds per merged task.</param>
/// <param name="MedianHoursToMerge">Median hours from task start to merge.</param>
/// <param name="Stuck">Tasks that couldn't finish or wait for a person, now.</param>
public sealed record DeliverySummary(int Merged, int FirstTry, double AverageFixRounds, double MedianHoursToMerge, int Stuck)
{
/// <summary>No data.</summary>
public static DeliverySummary Empty { get; } = new(0, 0, 0, 0, 0);

/// <summary>Share of merged tasks that passed on the first try (0–1); 0 when nothing merged.</summary>
public double FirstTryRate => Merged == 0 ? 0 : (double)FirstTry / Merged;

/// <summary>Summarise merged tasks given as (fix rounds, hours to merge).</summary>
public static DeliverySummary From(IReadOnlyList<(int FixRounds, double HoursToMerge)> merged, int stuck)
{
ArgumentNullException.ThrowIfNull(merged);
if (merged.Count == 0) { return Empty with { Stuck = stuck }; }
var hours = merged.Select(m => Math.Max(0, m.HoursToMerge)).Order().ToList();
var median = hours.Count % 2 == 1 ? hours[hours.Count / 2] : (hours[hours.Count / 2 - 1] + hours[hours.Count / 2]) / 2;
return new DeliverySummary(merged.Count, merged.Count(m => m.FixRounds == 0), merged.Average(m => m.FixRounds), median, stuck);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,9 @@ public sealed class RemoteSessionEntity
// greenfield router can hard-gate the Quality engine even on the unattended "Run all ai:ready" path
// where there is no per-ticket UI. Null for legacy/migrated sessions or tickets with no type label.
public string? TicketType { get; set; }

// Delivery metrics (Insights › Delivery): how many times the change went back to the Coding agent — red checks,
// conflicts, review, acceptance or a person's "Ask for changes" — and when its last change merged.
public int FixRounds { get; set; }
public DateTimeOffset? MergedAtUtc { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,11 @@ Task<bool> UpdateRepoRunResultAsync(
/// <summary>Roll the child repo statuses up into the parent session: any Failed → Failed; all Done → Done;
/// else Running. Also mirrors the first repo's PR onto the parent for back-compat display.</summary>
Task<bool> RecomputeSessionStatusForTenantAsync(string tenantId, Guid sessionId, CancellationToken ct = default);

/// <summary>Count one more round of fixes on the task (its change went back to the Coding agent).</summary>
Task IncrementFixRoundsForTenantAsync(string tenantId, Guid sessionId, CancellationToken ct = default) => Task.CompletedTask;

/// <summary>Delivery of the tenant's tasks merged since <paramref name="since"/> (null = all time).</summary>
Task<DeliverySummary> GetDeliveryForTenantAsync(string tenantId, DateTimeOffset? since = null, CancellationToken ct = default) =>
Task.FromResult(DeliverySummary.Empty);
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace AgentOs.Modules.Sessions.Persistence.Migrations
{
/// <inheritdoc />
public partial class AddDeliveryMetrics : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
name: "FixRounds",
schema: "sessions",
table: "sessions",
type: "integer",
nullable: false,
defaultValue: 0);

migrationBuilder.AddColumn<DateTimeOffset>(
name: "MergedAtUtc",
schema: "sessions",
table: "sessions",
type: "timestamp with time zone",
nullable: true);
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "FixRounds",
schema: "sessions",
table: "sessions");

migrationBuilder.DropColumn(
name: "MergedAtUtc",
schema: "sessions",
table: "sessions");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
#pragma warning disable 612, 618
modelBuilder
.HasDefaultSchema("sessions")
.HasAnnotation("ProductVersion", "10.0.8")
.HasAnnotation("ProductVersion", "10.0.13")
.HasAnnotation("Relational:MaxIdentifierLength", 63);

NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
Expand Down Expand Up @@ -52,6 +52,9 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Property<string>("Error")
.HasColumnType("text");

b.Property<int>("FixRounds")
.HasColumnType("integer");

b.Property<int?>("IssueNumber")
.HasColumnType("integer");

Expand All @@ -60,6 +63,9 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.HasMaxLength(256)
.HasColumnType("character varying(256)");

b.Property<DateTimeOffset?>("MergedAtUtc")
.HasColumnType("timestamp with time zone");

b.Property<string>("PrUrl")
.HasColumnType("text");

Expand Down
Loading
Loading