docs(grpc-data): H2 evidence - review fixes, flake check

This commit is contained in:
Joseph Doherty
2026-11-23 22:31:48 -05:00
parent b66ee52086
commit a6ca919fb2
+28 -5
View File
@@ -27,7 +27,7 @@ Phase H2 of `docs/plans/2026-11-23-grpc-data-connections-history-alarms-plan.md`
refusal is the same `Bad_HistoryOperationUnsupported` with no diagnostic and no backend call (byte-identical on the wire,
`Denied_and_unhistorized_and_unknown_are_byte_identical…`). Authority is re-checked after the backend answers.
Metadata `historizing` = historized AND granted, so metadata does not separate them either.
- **Limits.** Per-principal admission (`MaxConcurrentHistoryReads` ⇒ every item `BadTooManyOperations`); Raw pages at
- **Limits** (bounded per request and per principal since review fix 1, below). Per-principal admission (`MaxConcurrentHistoryReads` ⇒ every item `BadTooManyOperations`); Raw pages at
`MaxHistoryValuesPerPage` (0 or more ⇒ the ceiling, with a continuation); answers above
min(`MaxHistoryResponseBytes`, listener max) − 64 KiB are split into chunks (`chunk_continues`) held as single-use
remainders in the session; a remainder the session cannot hold is `BadTooManyOperations`, never a truncation.
@@ -37,8 +37,8 @@ Phase H2 of `docs/plans/2026-11-23-grpc-data-connections-history-alarms-plan.md`
- **Store/scope lifecycle.** One `OriginHistorySession` (H1 `PeerHistoryContinuationStore` + chunk remainders) per
(principal, API key, credential version, transport channel). The gRPC channel is the HTTP/2 connection
(`HttpContext.Connection.Id`), cleared when Kestrel's `IConnectionLifetimeFeature.ConnectionClosed` fires (idle expiry
60 s is the backstop); a direct `LocalDataConnection` is its own channel, cleared on `DisposeAsync`. Bounded at 4096
sessions (oldest-used evicted and cleared). ONE `PeerHistoryContinuationScope` per request; the serving incarnation it
60 s is the backstop; the hook is proven on a real Kestrel HTTP/2 host); a direct `LocalDataConnection` is its own
channel, cleared on `DisposeAsync`. Bounded at 64 sessions per principal and 4096 overall (review fix 5). ONE `PeerHistoryContinuationScope` per request; the serving incarnation it
snapshots is `incarnation/serving-generation/role`, so a restart, failover or role change invalidates tokens. A miswired
scope ⇒ `BadInternalError` + "Origin history continuation wiring fault." + an error log — never unsupported/denied.
- **Consumer** (`GrpcDataConnection.History.cs`). `IDataHistoryService` implemented explicitly (`ReadHistoryAsync` /
@@ -62,6 +62,31 @@ Phase H2 of `docs/plans/2026-11-23-grpc-data-connections-history-alarms-plan.md`
- **Found on the way:** `DataConnectionEndpoints.Methods` (the listener's method allowlist) did not include the new RPC, so
the auth middleware rejected every HistoryRead before the service saw it.
## Review fixes (Fable, approve-with-changes)
| # | Finding | Resolution |
|---|---|---|
| 1 | Origin memory unbounded | Nodes are read in sub-batches sized so one sub-batch at the per-page ceiling fits the response budget; once the budget is spent no further sub-batch starts. Unread nodes get a **deferred** chunk token (transport; on resume the node is read from its original continuation — any variant, not only Raw) or `BadTooManyOperations` (direct consumer). Processed intervals and AtTime times above `MaxHistoryValuesPerPage` are `BadTooManyOperations` unsent. Remainder bytes (encoded `CalculateSize`) are charged to a per-principal budget across sessions = concurrent reads × max(response budget, page × 64 B); past it a node is `BadTooManyOperations`. Proven by `Origin_memory_is_bounded…` (100 nodes × uncapped Raw: ≤ 10 nodes materialised per response, retained bytes ≤ budget at every step, every value delivered exactly once); a mutation removing the stop makes it fail |
| 2 | Not-ready origin ⇒ "unsupported" | `CapabilitiesResponse.history` is present whenever the origin has a historian; `Ready(…, HistoryRead)` answers Unavailable (not ready / demoted) or PermissionDenied (no export grant), so the client fails over like v1 Read |
| 3 | Client exceptions escape | Malformed/undecodable answers are endpoint failures (a fresh read moves on); resumed items ⇒ `BadContinuationPointInvalid`, fresh items of the same batch ⇒ `BadNoCommunication`; caller cancel throws; the deployment lease maps inner/scope faults to `BadNoCommunication` |
| 4 | HistoryTimeout capped by the origin's UnaryTimeout | Origin `Cancelled` without a caller cancel ⇒ `BadTimeout`, no endpoint failure recorded; the cap is documented next to the AdminUI field and in `DataConnections.md` |
| 5 | One principal can evict others | 64 sessions per principal (its own LRU evicted first); at the global 4096 the principal holding the most pays; a release never creates a session |
| 6 | Per-node rebuilds | `Implemented(target)` once per node, ACL before tagname; `OriginHistoryPort.Serving` cached per historian source instance (`A_v1_metadata_call_does_not_rebuild…`) |
| 7 | Mapped HistoryRead authorisable | Pinned: a real SDK HistoryRead on a projected variable with the mapping bit and a local HistoryRead grant is `Bad_HistoryOperationUnsupported`, no data, no continuation (projected nodes carry no HistoryRead access-level bit until H3) |
| 8 | Scope fingerprint | Limits ride the artifact's entity JSON like `TimeoutMilliseconds`; `HistoryTimeoutMilliseconds` removed from `DataConnectionScopeRevision` (no upgrade scope bump); plan §6 corrected |
| 9 | Nits | Upper bounds (timeout 1 h, reads 64, values/page 1,000,000, response 64 MiB, assembly 1 GiB; validator + AdminUI `max`); encoded sizes; a single oversized value is a per-item `BadTooManyOperations`; discovery backoff on the history path; a fresh read tries the next endpoint when one lacks history; channel-close registrations unregistered; remote reads hold at most N − max(1, N/4) of the node manager's N history batch slots (`OriginHistoryLimiterTests`). `UseSimpleBounds` is **kept on the wire** (it is in the §4.2 contract) but not plumbed: the H1 port's AtTime variant has no such flag and the evaluator applies its own bounds rule — documented as carried and ignored |
| 10 | Kestrel close hook | Proven with a real in-process Kestrel HTTP/2 (h2c loopback) host: `IConnectionLifetimeFeature.ConnectionClosed` is exposed on the stream context and disposing the client connection clears the session |
**Flake check (coordinator request).** `GrpcDataConfiguredDiscoveryWireTests` ×10 on this branch: 6 clean runs;
`Failed_sdk_item_construction_releases_candidate_and_fanout_ownership` failed 2/10, `New_primary_renews_same_monitored_item_after_a_prior_mapped_read(warmByRead: True)`
1/10, `Two_sdk_cadences_renew_before_expiry_without_reviving_old_notification_evidence` 1/10. Master (coordinator, 14 runs)
failed `Bad_null_sdk_notification_cannot_borrow_unproven_sample_evidence` 2/8. The `Failed_sdk_item…` path uses an origin
fixture without a history port and a direct (non-gRPC) peer connection, so no H2 history code, probe header or capability
change is on it; the only H2 delta it sees is the extra (null) `DataMetadata.History` field. Its assertion compares the
shared projected candidate budget's `RetainedEntries` before and after a failed second item while the first item stays live;
a candidate the live item holds between sampling ticks (`WarmStandby.AddCandidate`) makes it 1 at the second read — a race
in the test, not an H2 cause. Not changed here (the class flakiness is the coordinator's issue).
## Recorded-v1-client gate
Both gates extended per X0.md §2 BEFORE asserting, goldens untouched (`git diff master -- …Goldens.cs` is empty):
@@ -114,8 +139,6 @@ Not reproduced on master here (no second checkout from this worktree) — coordi
## Not verified
- The docker-dev smoke above (coordinator-run).
- Kestrel exposing `IConnectionLifetimeFeature` on HTTP/2 stream contexts: tests use `DefaultHttpContext` (feature absent ⇒
idle expiry only). If absent in production, sessions of closed connections live until idle expiry / eviction.
- The real `OriginHistoryPort` behind the gRPC service end to end: the wire suite fakes the port; the port facade is
tested against a real node manager separately (`OriginHistoryPortTests`).
- A consumer projection (H3) receiving negotiated metadata with bit 32/`HistoryInfo` from an H2 origin: covered only by