Skip to content

The verdict contract ​

The scan decides a file asynchronously, long after the upload answered 200. The module that asked for the file — the report that rendered it, the notification that carries it — still has to learn what became of it, and it has to learn it after the module's own commit, at least once, and in its own tenant. That is the contract of IFileOutcomeHandler (RN-GF-13, decision 9). This page is what a consumer has to implement and what it can rely on.

What is delivered, and when ​

The transition of a verdict is one transaction of GrydFiles: the new state, the sha256, the FileReference of the expected owner and the record of the verdict to deliver — carrying the file's tenant and the owner (ownerScope, ownerKey) — are written together, through the module's outbox (ADR 0012). After the commit, the outbox delivers the record to the handler registered for the ownerScope. A process that dies between the commit and the delivery delivers when it comes back.

The owner goes in the record, because a negative verdict zeroes the expected reference in the same transaction, and a re-scan that finds a signature releases the references: without the owner stored with the verdict, nobody would know whom to tell.

FileOutcomeKindWhenNotes
AvailableScanning → AvailableThe reference of the expected owner now exists
InfectedScanning → Infected, or the re-scan taking an Available file to InfectedAfter a re-scan, one verdict per owner that had an active reference: the file was clean and stopped being. The hold and retention of the file are untouched
RejectedScanning → Purged with a rejectionCodeThe content type did not match, or the object changed after the confirmation (FILE_OBJECT_CHANGED_UNPROCESSABLE). FileOutcome.RejectionCode carries the code
FailedThe automatic passes ran out (Scanning → Failed with the budget spent)So the consumer can show the failure and offer a new scan — never to release

A file reserved without an expected owner is applied the same way, but nobody is told: the notification exists for the owner the consumer declared when it confirmed. A size rejection at the confirmation (FILE_SIZE_MISMATCH_UNPROCESSABLE) is not delivered either — the caller already received the 422 in the same request (DEC-GF-13-3).

What the handler receives ​

csharp
public sealed record FileOutcome(
    Guid MessageId,          // the outbox message; the same on every redelivery
    Guid FileId,
    Guid TenantId,           // restored for the delivery
    string OwnerKey,         // the key the consumer declared
    FileOutcomeKind Kind,
    string? RejectionCode,
    DateTimeOffset OccurredAt);

It is a notice, not the truth. Two notices of one file can arrive in either order (Available, and, after a re-scan, Infected), and the same notice can arrive twice.

What the handler must be ​

  1. Idempotent. The same MessageId twice has one effect.
  2. Decided by the state now. It reads the file again through its own port (IFileStore<TScope>.GetAsync — which asks for no user) and acts on what it finds, not on what the notice says. A late Available after an Infected therefore ends in Infected (RN-GF-13 (c)).
  3. Without a person. It runs outside any request, in the file's tenant, with no user. It runs no command on anyone's behalf and never places a legal hold; a hold needs an author (RN-GF-27).
  4. Tolerant of a missing owner. An owner that no longer exists, or no longer points at this file, is a normal outcome: the handler releases the reference (IFileStore<TScope>.ReleaseReferenceAsync) and returns.
  5. Honest about being early. The verdict can overtake the consumer's own write of the pointer to the file (the report execution has not stored its StoredFileId yet). That is not "owner gone": the handler throws FileOutcomeRedeliveryException and the delivery is repeated (DEC-GF-13-5).

An exception from the handler asks the module to deliver again; it never undoes the verdict. A delivery that arrives without the tenant restored, or with another, fails closed before the handler can read anything.

FileOutcomeFlow: the sequence, written once ​

Points 2, 4 and 5 are the same sequence in every consumer, so the module offers it as a static helper, FileOutcomeFlow.HandleAsync. It takes the port calls as delegates the handler declares itself — the gate that keeps a port inside its consumer reads the calling assembly (Registered consumers), so there is no base class to inherit:

csharp
public sealed class AttachmentOutcomes(IFileStore<AttachmentScope> files, IAttachments attachments)
    : IFileOutcomeHandler
{
    public Task HandleAsync(FileOutcome outcome, CancellationToken ct) =>
        FileOutcomeFlow.HandleAsync(
            outcome,
            readFile: () => files.GetAsync(outcome.FileId, ct),
            findOwner: async () => await attachments.FindAsync(outcome.OwnerKey, outcome.FileId, ct) switch
            {
                { PointerWritten: false } => FileOwnerState.NotYet,   // redelivered
                null => FileOwnerState.Gone,                          // reference released
                _ => FileOwnerState.Holds
            },
            releaseReference: () => files.ReleaseReferenceAsync(outcome.FileId, outcome.TenantId, outcome.OwnerKey, ct),
            apply: file => attachments.RecordAsync(outcome.OwnerKey, file.Status, file.RejectionCode, ct));
}

A file the module no longer knows (FILE_NOT_FOUND) leaves nothing to decide, and the helper returns. Any other failure to read it is redelivered. The shorter overload, without findOwner and releaseReference, is for a consumer whose owner cannot disappear.

What the consumers in this repository do ​

ConsumerNegative verdict
GrydReportsMarks a Completed execution as Failed when the file is Infected or was refused; a file Failed only logs a warning
GrydNotificationsReports the negative
GrydAudit.Export · GrydAudit.IntegrityReport the negative

Product files: no notice yet ​

A product file (no tenant) is scanned, released and quarantined like any other, but its verdict is not delivered: the Core outbox refuses a message with no tenant, and a product file has none (DEC-GF-13-1). The verdict still applies to the file; the gap is visible in the counter gryd_files.scan.verdict_undeliverable (meter GrydFiles.Scanner), and the owner only learns by reading the file. The place that switches this on once the Core accepts a message without a tenant is a single condition in RecordVerdictStep.StageVerdict. The same gap exists for the trail of product files — see The audit trail and the outbox.

Failures a consumer sees ​

SituationWhat happens
Registered scope with no handlerThe host does not start
Handler throwsThe delivery repeats under the outbox's retry policy; the verdict stands
Tenant not restored in the deliveryFails closed; nothing is read
The process that drains has no AddGrydFiles or no AddGrydFilesConsumerThe record waits in files.outbox; compose both there
Same notice twiceThe handler's idempotence is what makes it harmless

The proof is in FileOutcomeDeliveryTests (Postgres: (a) to (g) of RN-GF-13 — the process killed between the commit and the delivery, the same delivery twice, the swapped order, no tenant, Failed with the budget spent, the owner of a negative verdict, no user in the context) and in the end-to-end ReportsConsumerTests.


The decisions behind this page are in ADR 0010; the contract is RN-GF-13 of the specification.

Released under the MIT License.