fix(configdb): opt-in config-audit retention purge + after-state size cap (review 2026-10-21 08/G1)

This commit is contained in:
Joseph Doherty
2026-10-22 08:32:40 -04:00
parent 394234b450
commit 036f341a9d
7 changed files with 292 additions and 2 deletions
@@ -23,6 +23,15 @@ public class AuditService : IAuditService
MaxDepth = 32
};
/// <summary>
/// Upper bound (characters) on a serialized <c>AfterStateJson</c>. A larger payload (e.g. a
/// whole template graph with every script body) is replaced by a small truncation marker so
/// one audit row can never grow without bound. Valid JSON is preserved either way.
/// </summary>
public const int MaxAfterStateChars = 256 * 1024;
private const int TruncatedPreviewChars = 4 * 1024;
/// <summary>
/// Initializes the audit service with the EF Core context and correlation context.
/// </summary>
@@ -72,7 +81,17 @@ public class AuditService : IAuditService
{
try
{
return JsonSerializer.Serialize(afterState, AuditSerializerOptions);
var json = JsonSerializer.Serialize(afterState, AuditSerializerOptions);
if (json.Length <= MaxAfterStateChars)
return json;
return JsonSerializer.Serialize(new
{
AuditTruncated = true,
OriginalLength = json.Length,
StateType = afterState.GetType().FullName,
Preview = json[..TruncatedPreviewChars]
});
}
catch (Exception ex) when (ex is JsonException or NotSupportedException)
{