Path: redb-route/redb.Route.Llm/Engine/Storage/IApprovalStore.cs Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route.Llm/Engine/Storage/IApprovalStore.cs ---- using System.Collections.Concurrent; using redb.Route.Abstractions; using redb.Route.Llm.Engine.Governance; namespace redb.Route.Llm.Engine.Storage; /// /// Persists approval decisions for audit and replay. Every call answered by /// should land here so reviewers can correlate the /// gate's verdict with the resulting tool call. /// /// The optional exchange parameter on every method carries the route /// pipeline's current exchange; REDB-backed implementations resolve a /// per-exchange through /// IRouteContext.GetRedbService(name, exchange) using the named-redb /// hint stored in . In-memory implementations /// ignore it. /// Without an exchange a redb-backed implementation opens a redb scope of its own for the call. That scope joins an /// ambient (a , a /// route's .Transacted()) as every redb connection does, but not a transaction begun on the context's shared /// IRedbService (ExecuteAtomicAsync, BeginTransaction), which it does not see: pass the exchange, /// or use a TransactionScope, when the call must commit or roll back with that work. In-memory implementations /// take part in no transaction. /// /// public interface IApprovalStore { /// Records a decision against the pending request. Task RecordAsync(ApprovalRequest request, ApprovalDecision decision, IExchange? exchange = null, CancellationToken ct = default); /// Looks up the previously-recorded decision for . Task FindAsync(string approvalId, IExchange? exchange = null, CancellationToken ct = default); } /// An approval decision joined with the request that triggered it. public sealed class ApprovalRecord { /// Approval identifier (also stored on the audit row). public required string ApprovalId { get; init; } /// Conversation the approval belonged to. public string? ConversationId { get; init; } /// Tool name that was gated. public required string ToolName { get; init; } /// Tool input JSON as it was about to be dispatched. public required string InputJson { get; init; } /// True when the gate allowed the call. public required bool Approved { get; init; } /// Reason text supplied by the approver (especially on denial). public string? Reason { get; init; } /// Wall-clock timestamp the decision was recorded. public DateTime CreatedAtUtc { get; init; } = DateTime.UtcNow; } /// In-memory approval store — sufficient for tests and demos. public sealed class InMemoryApprovalStore : IApprovalStore { private readonly ConcurrentDictionary _records = new(StringComparer.Ordinal); /// public Task RecordAsync(ApprovalRequest request, ApprovalDecision decision, IExchange? exchange = null, CancellationToken ct = default) { var id = decision.ApprovalId ?? Guid.NewGuid().ToString("N"); _records[id] = new ApprovalRecord { ApprovalId = id, ConversationId = request.ConversationId, ToolName = request.Tool.Name, InputJson = request.InputJson, Approved = decision.Approved, Reason = decision.Reason }; return Task.CompletedTask; } /// public Task FindAsync(string approvalId, IExchange? exchange = null, CancellationToken ct = default) => Task.FromResult(_records.TryGetValue(approvalId, out var rec) ? rec : null); }