Files
seaweedfs/seaweed-block/docs/design/answer-classification.md
T

227 lines
15 KiB
Markdown

# Shared failure policy
The operator policy is a pure lookup of `(phase, error kind)`. Its result
contains a typed code, retryable flag, same-operation retry rule, cure and
exit code. Transport adapters retain facts and translate concrete errors
to kinds. They do not decide which operations may be resent.
A definite typed domain answer from the server takes precedence over a
local transport diagnosis. Otherwise an initial attempt is **unsent** only
when the transport proves that no request stream was sent. Missing evidence
is **possibly admitted**. A reset, EOF, cancellation or deadline after a
request may have left cannot authorize a second non-idempotent operation.
Recover through the original operation's replay key or existing poll handle.
This projects the existing CutTime `Poll` / `CliGiveUp` boundary and the
snapshot same-request-id replay contract. It introduces no server state or
authority transition.
## Transport registry
The registry is in `core/rpc/answer`. Classification precedes one global
class-to-exit projection. A short explicit legacy list preserves documented
v1.1.x exceptions; every row has a source, reason, test and v1.2 removal
boundary. An undocumented exit is canonicalized.
The common chunk contract is shown below. Thirteen wire contracts
(chunk, incomplete verify, workspace, create, resolve, cluster, restore, failover, whole-job
volume operations, stop, placement, shell and ops) remain explicit cells
in that same registry. The legacy exit never changes class or authorizes unsafe retry.
| Kind | Unsent | Possibly admitted |
| --- | --- | --- |
| Connection failure or EOF | `remote_unavailable`, retryable, resend the same operation, 75 | `outcome_unknown`, recover by replay key or poll, 3 |
| DNS failure | `remote_unavailable`, retryable, check resolution and resend the same operation, 75 | `outcome_unknown`, recover by replay key or poll, 3 |
| Timeout | `remote_unavailable`, retryable, resend the same operation, 75 | `outcome_unknown`, recover by replay key or poll, 3 |
| Caller-owned deadline | `deadline_exceeded`, resend the same operation with a sufficient caller window, 1 | `outcome_unknown`, recover by replay key or poll, 3 |
| Local credential load, parse or validity failure | `bad_request`, terminal until local credentials are fixed, 78 | The same local configuration provenance, with the wire contract preserved |
| Caller cancellation | `canceled`, no automatic retry, 1 | `outcome_unknown`, recover by replay key or poll, 3 |
| Certificate rejected or invalid | `not_authorized`, terminal until certificate configuration is fixed, 5 | The same terminal certificate policy, 5 |
| Unknown certificate authority | `not_authorized`, terminal until the CA is fixed, 5 | The same terminal CA policy, 5 |
| Certificate name mismatch | `not_authorized`, terminal until the address or names are fixed, 5 | The same terminal name policy, 5 |
TLS 1.3 can deliver a server's client-certificate rejection on the first
read after the client has written its request. That certificate-family
alert is a definite rejection of this connection, not an ambiguous applied
request. It remains terminal even in the post-write phase. The TLS adapter
recognizes the finite certificate-alert family at the structured TLS error
boundary; it does not search arbitrary gRPC diagnostic text.
HTTP records connection acquisition across the entire call. A missing
`WroteHeaders` callback never proves that a partial write did not happen.
Polling an admitted operation retains its admission evidence even if the
poll's own dial fails. Response-body read failures retain post-send evidence.
gRPC records `OutHeader` per RPC, monotonically across transparent retry
attempts. Unary and streaming failures preserve the original gRPC status
and details. Typed connection-attempt causes are captured before gRPC
flattens the final failure into `Unavailable`. Credentials options retain no
channel-wide last cause. Established RPCs use their own connection's
late-alert evidence; unsent calls require the fresh peer-set proof below. A two-peer control holds a trusted RPC open while another peer fails TLS
verification, then loses the trusted RPC answer. The trusted call remains
UNKNOWN; substituting the channel-wide last TLS error makes the control fail.
## Evidence and remaining work
Tests produce actual loopback TCP refusal and reset, owned DNS NXDOMAIN,
read timeout, caller cancellation, EOF and TLS verification failures. A TLS
1.3 test completes the client handshake and write before observing a missing
client-certificate alert. HTTP and gRPC tests distinguish an unsent call
from a received request whose answer is lost. Unlisted errors, kinds and
phases fail the registry check.
The registry now includes every gRPC status, typed domain answers, local
kernel refusals and caller-owned deadline provenance. Workspace rendering,
chunk catalog and partial verify errors, restore, volume create/resolve,
cluster finalize/retire and failover use the shared policy. HTTP boundaries
retain phase evidence, including snapshot polls and whole-job volume reads.
A thirteen-contract grid checks produced TCP refusal/reset, DNS and timeout
errors in both phases, with an unlisted-row negative for each contract.
The transport semantics correction is `Unavailable` after a
request stream may have been sent: it is UNKNOWN, never proof of safe resend.
A bare status without evidence is conservative. TLS certificate rejection
is a terminal, not-admitted exception even after a TLS 1.3 request write.
Whole-job backup, restore, cut and stop presentation, shell inspection,
and the older ops HTTP/RPC clients use the shared registry. All owned RPC
constructors and HTTP request boundaries are inventoried by a source census;
a raw-client bypass is a failing control. Generated code and explicitly
inventoried non-network sync.Once callbacks are excluded. The inventory
pins current entries; aliases, reflection and future transport libraries
require a new entry and an admission-evidence control.
Typed server codes have a finite registry inventory. A source census checks
constant domain codes and an actual HTTP unlisted-code answer fails closed.
Unknown errors, status codes and output contracts never acquire a safe-resend
default. HTTP protocol callers retain their existing 404/409 state rules;
only responses they already treat as failures enter the registry. The
registered HTTP error statuses project definite rejection or conservative
UNKNOWN according to [HTTP semantics](https://www.rfc-editor.org/rfc/rfc9110.html#section-15.5);
the retry rule follows the [non-idempotent retry constraint](https://www.rfc-editor.org/rfc/rfc9110.html#section-9.2.2).
Native short tests cover the registry, RPC, ops, CSI and launcher packages.
Linux/race and whole CLI qualification remain pending. Native Windows cannot
qualify real-master fixtures that require directory Sync. Transport evidence
and presentation do not change server admission, cleanup or authority guards.
## Cost cells
| Operation | Formula and bound | Exhaustion | Attribution |
| --- | --- | --- | --- |
| Policy lookup | O(1) lookup and fixed registry space, independent of S/C/N/V/H/T | Unlisted key is an explicit check error; never a safe-resend default | Shared registry |
| HTTP evidence | O(1) state per in-flight request, independent of S/C/N/V/H/T | Unsupported trace evidence remains possibly admitted | Calling command |
| RPC evidence | O(1) state per in-flight RPC and per TLS connection, plus O(P) peer-attempt state per channel | Missing provenance cannot prove unsent or certificate rejection | Calling RPC client |
| Local credential validation | O(config bytes) parsing; runs before dialing, independent of stored S/C/N/V/H/T | Invalid or expired material is terminal with local provenance | Client constructor |
| Error presentation | O(diagnostic bytes), with existing caller response limits | Unlisted code fails closed; diagnostic text never authorizes retry | Calling command |
| Command-family policy grid | Thirteen compatibility projections, two admission phases, produced failure controls | Linux/race qualification pending; source census does not prove alias/reflection coverage | CLI adapters |
## Exit compatibility
`exit_projection.go` maps unsent remote failure to 75, possibly-admitted
UNKNOWN to 3, certificate/trust/name rejection to 5, and typed local
credential/configuration failure to 78. Local command syntax and definite
server argument refusals remain distinct from credential validation.
`LegacyExits()` is the complete exception inventory. The documented
`ops volume create` and read-only `ops volume resolve` exceptions retain
75 for UNKNOWN and 78 for definite refusal. Cluster finalize/retire typed
precondition refusal retains 2. Incomplete verify UNKNOWN retains 1 (3 means completed findings); failover unsent remote failure retains 3 with read-before-another-move recovery. Every exception is removed in v1.2. Typed non-retryable remote-unavailable answers are definite refusals, never exit 75.
The create exception is safe only for identical name, geometry and placement:
`FileStore.CreateVolume` returns the existing compatible record and layout
identity or refuses a conflict. `RegisterWorkspaceBinding` and placement
preserve conflicting assignments. `TestOpsVolumeCreateAndPlaceRetriesAgainstRunningMaster`
loses each of the three replies and proves a same-input rerun converges;
its Linux qualification remains required. This is not permission to change
settings or issue a different operation as a retry.
`TestCanonicalExitProjectionGrid` covers every changed transport class across
the command contracts; `TestEveryLegacyExitHasADocumentedGridRow` covers each
legacy row and its source/removal metadata. Actual credential-file failures
also traverse command entry points, including workspace, create/resolve,
cluster and failover. See the [v1.1.2 corrections](../releases/v1.1.2.md).
## Multi-peer attempt evidence
Connection-attempt facts come from the public gRPC SubConn state listener,
including the typed Origin of TCP/TLS failures before a stream exists. Its
notifications are asynchronous, so delivery time never proves freshness.
The TLS credential/read boundary stamps the actual attempt start and failure;
a terminal certificate proof requires that attempt to have started after
the RPC. An older attempt or a missing source stamp stays conservative. A
Picker associates that peer set with the RPC that is waiting for it. The
observer delegates the existing pick-first algorithm; it does not replace
the dialer, proxy handling, backoff or admission. Established RPCs continue
to use only their own connection's late TLS fact.
Terminal certificate rejection requires fresh certificate-family failures
for every peer attempted for the call, with no pending, unknown or network
failure. Resolver changes during the call invalidate that proof. A mixed
certificate/network failure remains unsent/retryable and reports both peer
causes. Unsupported custom policies lack this proof and remain conservative.
| Evidence operation | Formula / bound | Exhaustion or uncertainty | Attribution |
| --- | --- | --- | --- |
| Peer attempt tracking | O(P) state per channel, P = resolved peers; fixed counters and last typed causes per peer, no history growing with retries | Resolver change, duplicate peer identity, multi-address SubConn or missing cause cannot prove every attempt was certificate-rejected | Resolver-owned peer set |
| Picker observation | O(P) scan on a failed pick; O(1) retained evidence per RPC | No fresh complete set means retryable unsent failure | Waiting RPC |
| Peer diagnostic | At most 8 peer causes plus omitted count; existing individual diagnostics retained | Truncation never authorizes terminal classification | Failing call |
## Plaintext preface compatibility correction
The configured gRPC transport supplies one additional fact: plaintext mode.
An observed unsent connection failure in that mode retains `remote_unavailable`
and same-operation retry. Its shared cure adds a conditional hint to configure
`SW_BLOCK_TLS_CERT`, `SW_BLOCK_TLS_KEY` and `SW_BLOCK_TLS_CA` if the endpoint
requires TLS. A closed preface cannot prove that requirement: a restarting or
closing plaintext endpoint looks identical. Workspace's old heuristic terminal
5 therefore becomes 75 when unsent is proven (3 without admission evidence).
No handshake probe, string-based TLS diagnosis or extra network request is
introduced. `TestPlaintextPrefaceFailureKeepsUnsentRetryAndTLSHint` exercises
both a real TLS server and a closing plaintext peer. The channel retains one
immutable transport-mode boolean; no per-attempt history or new cost bound.
## Trusting HTTP trace evidence
Only `NewHTTPTransport`'s privately owned native path supplies positive
GetConn/GotConn no-send evidence. A concrete `*http.Transport` can delegate
through `RegisterProtocol` before native tracing; its type alone proves nothing.
All caller-supplied transports, including unmodified standard transports, stay
possibly admitted on transport errors unless cancellation prevented dispatch.
A client with nil Transport uses the adapter's owned standard-default transport,
not the mutable global `http.DefaultTransport`. Caller client options (timeout,
redirect policy, jar) are retained. Redirect connection evidence stays monotone.
The owned transport exposes only RoundTrip and CloseIdleConnections, with no
protocol registration, custom dial callback, or inner transport access. It is
constructed from standard default settings, never from a caller's transport.
HTTPPool exposes idle retention limits only; the blob client retains its current
256 total / 64 per-host idle limits. Defaults remain 100 total / 2 per-host;
request concurrency and per-call bounds are unchanged. No new RPC or retry.
The real received-POST/lost-answer controls cover both a GetConn-only custom
transport and that same custom transport registered on a concrete Transport.
Both remain UNKNOWN. The native refused-dial positive still yields UNSENT75.
A separate control poisons the mutable global's protocol registration and proves
a newly owned transport receives the original server answer instead.
`TestDelayedPeerNotificationCannotRefreshAnOldTLSFailure` queues the
SubConn notifications of a failed TLS attempt until after a new RPC starts;
the delayed failure cannot become a terminal answer for that RPC. A fresh
attempt remains eligible, while an unobserved failure lacks proof. This
projects the existing admission/recovery obligation with no new state
machine or request. Source stamps add only fixed counters per TLS attempt
and connection, preserving O(1) connection/RPC state and O(P) peer state.
The observed TLS auth info forwards the underlying `AuthorityValidator`.
A matching per-RPC authority override still reaches the server; a mismatching
name is refused by the original certificate validator before any RPC receipt.
No validator means refusal, never an implicit authorization.
`TestObservedTLSForwardsPerCallAuthorityValidation` exercises the wrapped
master link with matching DNS/IP names and a mismatching name.
An already-ended single-filer preflight records UNSENT and both the context's
completion and its opaque caller cause. No census request starts. The owned
verify-silence sentinel retains its documented deadline mapping.
`TestChunkCensusPreflightPreservesOpaqueContextCause` covers custom cancellation
and deadline causes with zero census calls.