Skip to content

fix(durable): make compatibility and readiness decisions explicit #794

Closed

Description

@akrock

Parent: #793

What problem should this solve?

DurableRuntimeHealthSnapshot exposes schema compatibility, epoch compatibility, and the runtime states Healthy, NotStarted, Stale, Draining, and Incompatible. Consumers still have to reconstruct which combinations authorize deployment, permit a pump attempt, and mean the worker is ready. A real consumer used compatibility as readiness in seven endpoints.

The PostgreSQL implementation also maps a timeout or unavailable database to Incompatible with the schema-inconsistent problem code. That collapses “the store disproved compatibility” and “the store could not be observed,” which prevents a doctor or host from giving the correct remediation.

Scale-to-zero also proves that readiness cannot replace compatibility: a deployment may need to validate schema and epoch before external activation is enabled and before a pump heartbeat exists.

Proposed shape

Add DurableRuntimeHealthState.Unavailable. PostgreSQL connectivity and command-timeout failures map to Unavailable with the existing DurableProblemCodes.StoreUnavailable (ASDUR103) only when the caller's token was not canceled; caller cancellation still propagates. Observed schema or epoch mismatches remain Incompatible. Under Unavailable, compatibility flags are false because compatibility was not established, not because an incompatibility was observed. Document that distinction on the properties and state.

Add three canonical computed properties to DurableRuntimeHealthSnapshot:

public bool CanEnableActivation =>
    State != DurableRuntimeHealthState.Unavailable
    && State != DurableRuntimeHealthState.Incompatible
    && SchemaCompatible
    && EpochCompatible;

public bool CanAttemptPump =>
    CanEnableActivation
    && State != DurableRuntimeHealthState.Draining;

public bool IsReady =>
    State == DurableRuntimeHealthState.Healthy
    && CanEnableActivation;

CanEnableActivation is a deployment/configuration gate. CanAttemptPump is only a host admission precheck: the provider remains authoritative and may still reject a concurrent pass or identity takeover. It deliberately permits NotStarted so cold activation can establish the first heartbeat and permits Stale so the provider can apply its existing guarded takeover rules. IsReady is the traffic-readiness decision.

Keep the full state and component facts available for diagnostics. Do not add IsLive: process liveness belongs to the host and should not require a durable-store query.

Preserve IDurableRuntimePump.RunOnceAsync exactly, including its current process-local overlap exception and empty results from other closed-admission paths. Add a separate opt-in admission-aware contract:

public enum DurableRuntimePumpAttemptKind
{
    Completed = 0,
    Refused = 1,
    Unavailable = 2,
    Incompatible = 3,
}

public sealed record DurableRuntimePumpAttempt
{
    public DurableRuntimePumpAttempt(
        DurableRuntimePumpAttemptKind kind,
        DurableRuntimePumpResult? result,
        string? problemCode);

    public DurableRuntimePumpAttemptKind Kind { get; }
    public DurableRuntimePumpResult? Result { get; }
    public string? ProblemCode { get; }
}

public interface IDurableRuntimePumpAdmission
{
    ValueTask<DurableRuntimePumpAttempt> TryRunOnceAsync(
        DurableRuntimePumpRequest request,
        CancellationToken cancellationToken = default);
}

Completed requires a non-null result and null problem code, including for a legitimate empty pass. Refused requires both nullable fields to be null. Unavailable requires ASDUR103; Incompatible requires ASDUR108 or ASDUR400–ASDUR403; both require a null result. PostgreSQL implements the new interface and:

  • returns Refused when the process-local pass slot, runtime admission gate, or TryBeginPassAsync guard refuses entry;
  • translates a non-caller-canceled Npgsql/timeout failure to Unavailable;
  • translates DurableRuntimeSchemaException to Incompatible with the existing schema/epoch code;
  • lets caller cancellation and unexpected programming failures propagate.

One internal PostgreSQL failure classifier is shared by health observation and admission-aware pump translation. It is an
allowlist with a propagate-by-default arm:

Evidence Classification
OperationCanceledException and the caller token is canceled Propagate caller cancellation
Provider command timeout, SQLSTATE 57014 caused by that timeout, Npgsql transient connection failure, SQLSTATE class 08, 53300, 57P01, 57P02, or 57P03 Unavailable + ASDUR103
SQLSTATE 42501 while reading runtime health or admission state Unavailable + ASDUR103; diagnostics identify permission configuration without exposing SQL
DurableRuntimeSchemaException or an observed schema/epoch status Incompatible + the existing specific code
Undefined relation/function, malformed row shape, invalid enum/value, contradictory result, unrelated OperationCanceledException, or any unclassified exception Propagate; this is a package/data-contract defect, not an outage

Tests pin every row and the default arm so a future broad catch (NpgsqlException) cannot silently turn malformed schema or
programming failures into an outage. Only observed schema/epoch mismatches become Incompatible; provider failures that
prevent an observation become Unavailable.

Health is explicitly a bounded best-effort observation, not a serializable transaction over schema and worker state. After
schema validation, worker heartbeat and due-dispatch facts are read through one runtime connection and one SQL statement,
using one captured database observation time and one MVCC statement snapshot. A partial read cannot produce a mixed
snapshot; it is Unavailable when the failure classifier recognizes an observation failure and otherwise propagates. A
schema change between precheck and pump remains safe because provider admission validates schema and epoch again.

The implementation shares the existing pump core. Existing hosted and direct-pump callers remain source and binary
compatible; behavior compatibility has the single documented post-pass cancellation correction above.
External-activation helpers require IDurableRuntimePumpAdmission.

Add a normative truth table to the Provider and PostgreSQL package documentation:

State/facts Enable activation Attempt pump Runtime ready Host liveness consequence
Compatible + NotStarted Yes Yes No Host decides; a cold activator may establish the heartbeat
Compatible + Healthy Yes Yes Yes Host decides
Compatible + Stale Yes Yes No Provider applies guarded takeover; alert separately
Compatible + Draining Yes No No Expected during shutdown
Schema or epoch incompatible No No No Fail activation closed; host decides whether process remains live
Store Unavailable No No No Dependency status is unknown; do not call it incompatible or use it as process liveness

Acceptance criteria

  • Public API tests cover every runtime state and all schema/epoch compatibility combinations for all three predicates.
  • Attempt-result tests distinguish a completed empty pass, refusal, provider unavailability, and incompatibility without changing existing pump-result semantics.
  • IsReady is false for contradictory synthetic snapshots even if their state is Healthy but a compatibility flag is false.
  • PostgreSQL connectivity and command-timeout paths return Unavailable/ASDUR103; observed missing, old, too-new, inconsistent, and epoch-mismatched states remain Incompatible with their existing specific codes.
  • The shared PostgreSQL failure-classification matrix covers caller cancellation, deadline cancellation, connection loss,
    permission/provider errors, schema exceptions, malformed query results, and unexpected programming failures through
    both health and admission-aware pump entry points; no downstream host maintains a second exception classifier.
  • Worker and due-dispatch facts come from one connection, one SQL statement, one database observation time, and one MVCC
    statement snapshot. Tests force a failure in each component and prove no partially assembled snapshot escapes.
  • Provider and PostgreSQL READMEs distinguish compatibility/startup, readiness, and host liveness with copyable examples.
  • The PostgreSQL example and tests stop hand-writing readiness expressions.
  • A scale-to-zero test proves NotStarted may enable and attempt activation before it is ready; a stale-worker test proves the precheck permits the provider's guarded takeover; a drain test proves no new pump attempt is made.
  • Existing snapshot constructor behavior remains source compatible; enum and JSON consumers receive release notes for the additive Unavailable value.
  • Existing IDurableRuntimePump, pump-result construction, process-local overlap exception, and closed-admission empty-result behavior remain unchanged except for the documented post-pass cancellation correction. The new interface returns the exact four-kind attempt matrix for process-local overlap, closed runtime admission, drain/takeover races, schema/epoch races, and transient store failures.
  • No HTTP endpoint, route name, authorization rule, restart policy, or orchestrator-specific type is added.

Dependencies and coordination

This case is the first implementation slice and unblocks cases 3, 6, 7, and 8.

Activity

  1. added
    bug
    on Sep 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions