Skip to content

impl(010): rustev-serve increment 2, the gRPC transport - #187

Merged
bartekus merged 1 commit into
mainfrom
impl/010-serve-grpc
Oct 23, 2026
Merged

bartekus merged 1 commit into
mainfrom
impl/010-serve-grpc

Conversation

@bartekus

Copy link
Copy Markdown
Contributor

Spec 042 3.9 and 3.18, stacked on #186. The .proto is generated from the rustev.serve/1 operation table and the Rust gRPC code from it with tonic-prost-build 0.14.6 at development time (both committed, drift-checked, no build script). Messages carry the canonical JSON document as bytes; refusals use the 3.5.1 gRPC codes with rustev-refusal-bin; evidence_not_delivered is INTERNAL with rustev-decision-id. Same mTLS listeners and handler layer as HTTP; a loopback differential test shows byte-identical documents across transports. Adds the integration-only gRPC and Sigstore families to rustev-boundaries. Checks: rustev-serve (57 tests incl. socket tests, run outside the sandbox), rustev-boundaries, make boundaries, clippy, fmt, make gate, couple.

@github-actions

Copy link
Copy Markdown

AI review (findings)

Reviewing the PR changes: gRPC transport layer for rustev-serve (spec 042 increment 2), plus boundary family additions and spec narrative updates.

Key areas examined: grpc.rs request framing and validation, transport.rs decode_path_id behavior change, grpc_generation.rs test design, GrpcBody SSE parsing, boundary updates, and spec narrative additions.


Finding 1 — grpc_generation.rs: hardcoded macOS-specific protoc path will fail on Linux CI

config.protoc_executable("/opt/homebrew/bin/protoc");

/opt/homebrew/bin/protoc exists only on macOS ARM64 with Homebrew. The GitHub Actions CI profile (github-actions-rust, revision 17) runs on Linux. When cargo test -p rustev-serve --locked executes the committed_grpc_declarations_are_current test on Linux, compile_with_config(...) will return an error and .unwrap() will panic, failing CI. There is no #[ignore], capability probe, or environment-variable skip guard. The scratch directory created before the panic is also not cleaned up in the failure path. The README documents this restriction but the test has no matching guard.


Finding 2 — transport.rs:160: decode_path_id is now applied to plain HTTP requests, silently changing existing behavior

-                return Some((op, Some(id.into())));
+                return Some((op, Some(decode_path_id(id)?)));

decode_path_id percent-decodes the raw path segment for both gRPC-rewritten requests and direct HTTP requests. A plan or decision that was registered (or looked up) using a percent-encoded ID like foo%2Fbar over plain HTTP previously received the literal string "foo%2Fbar" as its handle. After this change it receives "foo/bar". A client holding a prior handle "foo%2Fbar" will no longer find the same record. This is a silent, non-refusal behavioral change that is not documented in the spec narrative or README change log.

{"head": "19766a695b1a68b7c94d80266df28f8a00918c76", "verdict": "findings", "findings": [{"path": "integrations/rustev-serve/tests/grpc_generation.rs", "line": 29, "summary": "protoc_executable is hardcoded to /opt/homebrew/bin/protoc (macOS Homebrew only); the test panics on Linux CI because that path does not exist and there is no skip guard."}, {"path": "integrations/rustev-serve/src/transport.rs", "line": 160, "summary": "decode_path_id is now applied to all HTTP requests, silently changing the stored ID for any plan or decision whose path segment contained percent-encoded characters, breaking clients that registered or retain handles under the previously stored literal form."}]}

Subject: cbe69b4...19766a6, diff digest 518f7514b0c6fa9c235c21b7ede520a6f5c62b7790a05b5ed3f587a972462251, 1 call(s). An AI comment is not an approval.

@github-actions

Copy link
Copy Markdown

AI review (findings)

Review

integrations/rustev-serve/src/grpc.rs — GrpcBody::poll_frame, SSE-to-gRPC transcoding

In the Poll::Ready(Some(Ok(data))) arm of GrpcBody::poll_frame, when self.terminal.is_some() (i.e. the final SSE event has already been consumed and the terminal Status has been set), the code fast-returns the raw inner-body bytes as a gRPC data frame:

if self.terminal.is_some() {
    return Poll::Ready(Some(Ok(Frame::data(data))));
}

Those bytes are unstripped SSE wire format (data: …\n\n), not gRPC-framed protobuf (\0<4-byte-len><proto>). Any gRPC client receiving such a frame would fail to decode it. The guard exists because GrpcBody is also used in the unary path where terminal is pre-set, but in that path the inner body is a Full<Bytes> whose single frame is processed before this arm is reached. In the streaming path, the invariant that the SSE channel closes after the final event prevents the branch from being hit today, but the code is provably wrong if the invariant ever breaks — there is no panic, no discard, and no gRPC framing applied to the raw bytes.

integrations/rustev-serve/src/grpc.rs — empty rustev-wait-ms passes digit validation

In pub(crate) async fn request, the guard for the optional cancel wait parameter is:

if request.headers().get_all("rustev-wait-ms").iter().count() != 1
    || !wait.bytes().all(|b| b.is_ascii_digit())
{
    return refused(RefusalCode::InvalidRequest, &service);
}
route.push_str(&format!("?wait_ms={wait}"));

Iterator::all is vacuously true on an empty iterator, so a present-but-empty rustev-wait-ms header passes the check and appends ?wait_ms= to the route. The gRPC layer should reject this with InvalidRequest; instead the malformed query string reaches the HTTP dispatch layer, where behavior depends on how the Cancel handler parses an absent value for wait_ms.


Both are concrete defects supported by the diff. The streaming one is latent but the code path is wrong; the wait-ms one is a missing boundary check.

{"head": "f09134bef654fb66e4d42a1adb2592ca972c9ef8", "verdict": "findings", "findings": [{"path": "integrations/rustev-serve/src/grpc.rs", "line": 263, "summary": "When terminal.is_some() and the inner SSE body emits another data frame, raw SSE-formatted bytes are returned as a gRPC data frame without the 5-byte length-prefix framing or protobuf encoding, producing an undecodable frame for any gRPC client."}, {"path": "integrations/rustev-serve/src/grpc.rs", "line": 130, "summary": "Empty rustev-wait-ms header passes the all(is_ascii_digit) check vacuously and appends ?wait_ms= to the route, bypassing the gRPC-layer InvalidRequest refusal that should guard malformed wait values."}]}

Subject: cbe69b4...f09134b, diff digest 5c3fc9efebd3eb04f248e4e579ad70fed3edb16455bf5a08efe28d32a24757d5, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus had a problem deploying to statecraft-review-exception October 23, 2026 05:02 — with GitHub Actions Error
@bartekus
bartekus force-pushed the impl/010-serve-grpc branch from f09134b to bfd0c6f Compare October 23, 2026 05:06
@github-actions

Copy link
Copy Markdown

AI review (findings)

Review

Summary

This PR adds gRPC transport to rustev-serve (spec 042 increment 2): a committed .proto file and Rust service stub generated by tonic-prost-build, a framing layer in grpc.rs that unpacks gRPC frames into the shared HTTP handler, drift-check tests, and boundary-tool updates. The design (pass-through bytes document, same authenticated listener, shared handler) is sound, and the differential tests are thorough.

Finding 1 — Panic in streaming GrpcBody::poll_frame on non-data frames

integrations/rustev-serve/src/grpc.rs — GrpcBody::poll_frame:

Poll::Ready(Some(Ok(data))) => {
    let data = data.into_data().expect("shared handler emits data frames");

poll_frame yields Poll::Ready(Some(Ok(frame))) for both data and trailer frames. Frame::into_data() returns Err(original_frame) on a trailer frame, so .expect(…) panics. A panic in an async task causes an ungraceful RST_STREAM rather than gRPC terminal trailers with a meaningful status code.

The same function also uses .expect("SSE event") and the unchecked slice &data[start + 6..data.len() - 2]. If data.len() < 2 or the frame lacks the "data: " prefix (e.g., an SSE comment or keepalive emitted by the inner body), both paths also panic. The Body trait contract does not forbid these, so the code relies entirely on a behavioural invariant of EventBody that is not enforced at compile time.

Finding 2 — Silence when protoc is absent leaves committed generated code unchecked

integrations/rustev-serve/tests/grpc_generation.rs, around line 57:

None => eprintln!(
    "generated Rust gRPC code NOT drift-checked: no protoc ..."
),

When protoc is not on PATH and PROTOC is unset, the test prints a warning and exits successfully. Only the .proto file is always drift-checked; src/generated/rustev.serve.v1.rs is never verified. A CI environment without protoc will pass this test regardless of whether the committed Rust stub has drifted from the proto. Passing without checking is stronger than an explicitly skipped test and makes drift invisible.

{"head": "bfd0c6f951878d1edaadacf2591743320bb10b48", "verdict": "findings", "findings": [{"path": "integrations/rustev-serve/src/grpc.rs", "line": 322, "summary": "GrpcBody::poll_frame calls into_data().expect() on frames that may be trailers, causing a panic and ungraceful stream termination instead of proper gRPC error trailers."}, {"path": "integrations/rustev-serve/tests/grpc_generation.rs", "line": 57, "summary": "When protoc is absent the test prints a warning and exits successfully, leaving the committed generated Rust gRPC stub entirely unchecked for drift."}]}

Subject: cbe69b4...bfd0c6f, diff digest 986055316a2e19d6f50c6b50b5d66405d2e44dcd13ffa0228807783e469de325, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus had a problem deploying to statecraft-review-exception October 23, 2026 05:14 — with GitHub Actions Error
@bartekus
bartekus force-pushed the impl/010-serve-http branch from cbe69b4 to 15be979 Compare October 23, 2026 05:15
@bartekus
bartekus force-pushed the impl/010-serve-grpc branch from bfd0c6f to 0b16df8 Compare October 23, 2026 05:17
@github-actions

Copy link
Copy Markdown

AI review (findings)

Reviewing the PR, which adds gRPC transport to rustev-serve (spec 042 increment 2). The approach — a document-passthrough proto with path parameters in gRPC metadata, translating to the existing HTTP handler — is architecturally coherent. Here are the concrete defects found.


Finding 1 — Panic on unexpected SSE frame in streaming path

integrations/rustev-serve/src/grpc.rs, GrpcBody::poll_frame, the streaming branch:

let start = data
    .windows(6)
    .position(|s| s == b"data: ")
    .expect("SSE event");                              // panics if "data: " absent
let document = &data[start + 6..data.len() - 2];
let event = ServeEvent::parse(document).expect("shared event document");   // panics on parse failure

If the inner body delivers a frame that lacks data: — e.g., an SSE comment line, a blank keep-alive, or a bug in the event producer — the first .expect panics inside the tokio task. The second .expect panics if the JSON fails to parse. Both panics abort the task, disconnecting the client without emitting gRPC status trailers. The server continues running (task isolation), but the client receives no grpc-status and will see a stream reset as an unclassified transport error. The correct handling is to set terminal = Status::internal(...) and break out of the poll, which emits clean trailers on the next call.


Finding 2 — tonic-prost-build is a workspace-level runtime dependency, but is only needed in dev

Cargo.toml:

tonic-prost-build = { version = "=0.14.6", default-features = false }

integrations/rustev-serve/Cargo.toml lists it under [dev-dependencies], which is correct. But the workspace [workspace.dependencies] table entry makes it available as a non-dev dependency to every member. Any crate that adds tonic-prost-build.workspace = true under [dependencies] (not [dev-dependencies]) would silently pass the boundary check (in_integrations for rustev-serve) while actually pulling a code-generation tool into a release binary. Since SERVICE_FAMILIES includes prost-build and tonic-prost-build's transitive deps (which prost-build depends on tempfile, petgraph, etc.), declaring it at workspace level without default-members or exclude-guard creates a footgun for future crates. The workspace entry should either be absent (since only one crate uses it, as a dev dep) or marked with a workspace-level annotation preventing non-dev use.


Finding 3 — decode_path_id silently accepts %2F, making / reachable in stored decision IDs

integrations/rustev-serve/src/transport.rs, decode_path_id:

fn decode_path_id(id: &str) -> Option<String> {
    ...
    // %2F decodes to b'/', which String::from_utf8 accepts
    ...
}

The pre-existing validation in route:

&& !id.contains('/')

checks the raw segment, so a%2Fb passes. After decoding, the stored decision ID becomes "a/b". Since path_id re-encodes for outbound metadata, round-tripping is safe. However, a decision ID containing a literal / can never be looked up via a plain HTTP URL (the path router would split it), only through the gRPC path. This creates an asymmetry where decisions are only accessible over one transport — a behavioral divergence the README and spec do not mention. Whether this is intended or a gap is unclear from the evidence, but it's an inconsistency introduced by this PR that should be documented or blocked.


{"head": "0b16df855f83492cc658b48a6035bc34a88c5e10", "verdict": "findings", "findings": [{"path": "integrations/rustev-serve/src/grpc.rs", "line": 337, "summary": "GrpcBody::poll_frame panics via .expect() on unexpected SSE frame data in the streaming path, aborting the task without emitting gRPC status trailers and giving the client an unclassified stream reset."}, {"path": "Cargo.toml", "line": 79, "summary": "tonic-prost-build is declared as a workspace-level non-dev dependency even though it is only used in dev-dependencies of rustev-serve, creating a footgun where any future crate could pull a code-generation tool into release binaries while bypassing the SERVICE_FAMILIES boundary check."}, {"path": "integrations/rustev-serve/src/transport.rs", "line": 186, "summary": "decode_path_id accepts %2F and stores a decoded '/' in the decision ID, making decisions with that character unreachable over HTTP while accessible over gRPC, an undocumented transport asymmetry."}]}

Subject: 15be979...0b16df8, diff digest fd238097d558f02142963fa792c41e6239d3dba5c0c6614c7e2e2a4d3c11faaa, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus had a problem deploying to statecraft-review-exception October 23, 2026 05:23 — with GitHub Actions Error
@bartekus
bartekus force-pushed the impl/010-serve-grpc branch from 0b16df8 to fb3fe18 Compare October 23, 2026 05:26
@bartekus
bartekus force-pushed the impl/010-serve-http branch from 15be979 to 3fcef4c Compare October 23, 2026 05:30
@bartekus
bartekus force-pushed the impl/010-serve-grpc branch from fb3fe18 to c76065b Compare October 23, 2026 05:30
@bartekus
bartekus force-pushed the impl/010-serve-http branch from 3fcef4c to 9b1fb2c Compare October 23, 2026 05:40
@bartekus
bartekus force-pushed the impl/010-serve-grpc branch from c76065b to 563245b Compare October 23, 2026 05:40
@bartekus
bartekus force-pushed the impl/010-serve-http branch from 9b1fb2c to 1102e6b Compare October 23, 2026 05:42
@github-actions

Copy link
Copy Markdown

AI review (findings)

Looking at the PR carefully, focusing on the gRPC transport implementation in integrations/rustev-serve/src/grpc.rs, the boundary additions in tools/rustev-boundaries/src/lib.rs, the spec edits, and the transport refactor in src/transport.rs.

Route placeholder chaining in grpc::request()

In grpc.rs, the metadata-value validation filter (around line 161–171) rejects '/', '?', and '#' but does not exclude '{' or '}':

let Some(value) = value.filter(|v| {
    !v.is_empty()
        && v.len() <= 768
        && !v.contains(['/', '?', '#'])   // { and } not excluded
        && values.iter().count() == 1
}) else {
    return refused(RefusalCode::InvalidRequest, &service);
};
route = route.replace(placeholder, value);

The replacement loop runs sequentially over [("{planId}", "rustev-plan-id"), ("{decisionId}", "rustev-decision-id")]. For any plan-based operation (Decide, Registration, Stream), the route template contains only {planId}. If a client sends rustev-plan-id: {decisionId} (passes validation), the first iteration replaces {planId} with the literal string {decisionId}, leaving the route as e.g. /v1/plans/{decisionId}/decisions. The second iteration then finds {decisionId} in the route, reads the rustev-decision-id header, and substitutes its value as the plan ID. A client can therefore send rustev-plan-id: {decisionId} and rustev-decision-id: some-other-plan to address some-other-plan instead of the plan named in rustev-plan-id, violating the intended one-header-per-parameter binding. No authentication bypass is possible (the target plan must be registered), but the routing invariant—that rustev-plan-id exclusively controls plan addressing for plan-scoped operations—is broken.

No other concrete defects were found. The boundary additions, decode_path_id, body-size framing arithmetic, SSE-to-gRPC stream conversion, spec edits, and Cargo dependency pins are consistent with their stated intent.

{"head": "563245bbc530e846117df1b648ba3f56f976eb53", "verdict": "findings", "findings": [{"path": "integrations/rustev-serve/src/grpc.rs", "line": 165, "summary": "The metadata-value filter does not exclude '{' or '}', allowing a client to set rustev-plan-id to the literal string '{decisionId}' so the substitution loop resolves the plan ID from the rustev-decision-id header instead, breaking the intended one-header-per-parameter binding for plan-scoped operations."}]}

Subject: 9b1fb2c...563245b, diff digest c74c33f7d917b43ec1e5cf86a4ef7ceadaabea542c95f1e2e569a9613349492e, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus had a problem deploying to statecraft-review-exception October 23, 2026 05:48 — with GitHub Actions Error
@bartekus
bartekus force-pushed the impl/010-serve-grpc branch from 563245b to 4137cc0 Compare October 23, 2026 05:49
@bartekus
bartekus force-pushed the impl/010-serve-http branch from 1102e6b to 98938d0 Compare October 23, 2026 05:58
@bartekus
bartekus force-pushed the impl/010-serve-grpc branch from 4137cc0 to 1f6fb36 Compare October 23, 2026 05:58
@github-actions

Copy link
Copy Markdown

AI review (findings)

Reviewing the PR, which adds a gRPC transport layer to rustev-serve (spec 042 increment 2): proto definition, generated Rust stub, grpc.rs framing, transport.rs dispatch, boundary check updates, and spec amendments.

Code-level checks:

  • decode_path_id in transport.rs: correctly decodes percent-encoded UTF-8, returns None on bad encoding, and uses String::from_utf8 to catch invalid UTF-8. Safe.
  • path_id in grpc.rs: encodes to alphanumeric plus -._~:%; the expect("escaped ASCII handle") on the metadata parse is valid because the output is always printable ASCII.
  • gRPC metadata ID validation (!v.is_empty() && v.len() <= 768 && all ascii_alphanum | "-._~:%") allows %GG; the resulting route either fails URI parsing or hits decode_path_id's to_digit(16)? guard, producing EndpointUnavailable. Safe.
  • GrpcBody::poll_frame streaming termination: when terminal is set after a Final event, next call short-circuits to Poll::Ready(None) and emits trailers with the final status. Correct.
  • status() maps ServeRefusal codes exhaustively via grpc_code() (Rust enforces this at compile time) and handles EvidenceNotDelivered in ServeDecision with INTERNAL + rustev-decision-id metadata. Correct.
  • encode_response correctly limits the ServeDecision-as-failure path to Operation::Decide only; Lookup always returns OK per the spec and test assertions.
  • Rate limiting and header-size checks in transport::request run before the if grpc branch, so gRPC requests go through the same limits as HTTP. Correct.
  • Boundary check: SERVICE_FAMILIES includes tonic-build (a transitive dep, not a direct workspace dep), which is defensively correct. The service_families_are_integration_only_and_transitively_impure test covers both direct and transitive cases.
  • Spec updates in 010 and 042 record the implementation increment correctly.

One concrete defect:

integrations/rustev-serve/README.md (newly added section) states: "The development generator requires protoc 29.3 at /opt/homebrew/bin/protoc". The actual protoc() function in tests/grpc_generation.rs checks $PROTOC first and then searches $PATH; it never references /opt/homebrew/bin/protoc. The stated requirement is factually wrong and will mislead developers on non-macOS-Homebrew systems who have protoc available elsewhere on their PATH.

{"head": "1f6fb366da9e3148377e42337b3a4ddbf8e1d3e0", "verdict": "findings", "findings": [{"path": "integrations/rustev-serve/README.md", "line": null, "summary": "README claims protoc must be at the hardcoded path `/opt/homebrew/bin/protoc`, but grpc_generation.rs::protoc() searches $PROTOC env var and $PATH — the hardcoded path is never consulted by the code."}]}

Subject: 98938d0...1f6fb36, diff digest 19e4f4da56bfdd0c95379dfdc420b91214750cc03e89bef2f7223ca8363d5f23, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus had a problem deploying to statecraft-review-exception October 23, 2026 06:05 — with GitHub Actions Error
@bartekus
bartekus force-pushed the impl/010-serve-grpc branch from 1f6fb36 to 4eec3ca Compare October 23, 2026 06:06
@bartekus
bartekus force-pushed the impl/010-serve-http branch from 98938d0 to 8448653 Compare October 23, 2026 06:08
@bartekus
bartekus force-pushed the impl/010-serve-grpc branch 2 times, most recently from 51246e1 to 7164119 Compare October 23, 2026 06:10
@bartekus
bartekus changed the base branch from impl/010-serve-http to impl/010-serve-tests October 23, 2026 08:15
@bartekus
bartekus force-pushed the impl/010-serve-tests branch from 946f7eb to f1e945b Compare October 23, 2026 08:19
@bartekus
bartekus force-pushed the impl/010-serve-grpc branch from 36db0f2 to 4904ed7 Compare October 23, 2026 08:19
@github-actions

Copy link
Copy Markdown

AI review (no-findings)

Looking at this PR carefully across the changed paths.

Cargo / dependency hygiene: New gRPC crates (tonic, prost, tonic-prost-build) are pinned to exact versions and placed in the correct sections (runtime vs dev). tonic-build appears only as a transitive dep, which is acceptable since SERVICE_FAMILIES in the boundary tool lists it explicitly and the transitive-purity tests cover it.

tools/rustev-boundaries/src/lib.rs: SERVICE_FAMILIES is added and used consistently in forbidden_for_pure, FacadeFamily, and ForbiddenFamily checks. The new test service_families_are_integration_only_and_transitively_impure exercises all members for both crates/ (should reject) and integrations/ (should pass). No gaps found.

integrations/rustev-serve/src/grpc.rs – main gRPC framing layer:

  • Routing: uses format!("/rustev.serve.v1.Serve/{:?}", op.operation). The proto file is itself generated with the same {:?} format, and the generated stub embeds the exact same path strings. External gRPC clients see the proto method names (PascalCase), which is what derive(Debug) produces for unit enum variants. Internally consistent and compatible with standard clients.
  • Size limits: the 5-byte gRPC framing header + 6-byte protobuf overhead allowance (max + 11, max + 6) is arithmetically correct.
  • ID validation: the allowed alphabet [-._~:%a-zA-Z0-9] combined with decode_path_id(v).is_some() (rejects malformed %GG) gates before route substitution, preventing injection into the URI template.
  • wait_ms forwarding: digit-only check prevents query injection.
  • content-type duplicate check before body reading is correct defense-in-depth.
  • status() called twice (once in encode_response, once inside refusal_response): redundant but not incorrect.
  • SSE parsing: data.len() - 2 is only reached when data.len().saturating_sub(2) >= start + 6, so no underflow risk; documented as internal-only.

integrations/rustev-serve/src/transport.rs: decode_path_id is straightforward; the change from Some(id.into()) to Some(decode_path_id(id)?) decodes percent-escaped segments for both transports. The inline comment correctly notes this is safe because the service is unreleased and no ID was stored in percent-encoded form.

tests/grpc_generation.rs: digest header is a 64-character SHA-256 hex string (correct length). The bless path correctly requires protoc to be present. Without protoc, only the proto file content and the stub's digest-header line are verified; the limitation is acknowledged.

tests/handlers.rs – grpc_differential: covers in-memory duplex and loopback TCP, success paths, all refusal classes, streaming (retained + fresh), evidence-not-delivered with rustev-decision-id, and opaque IDs containing /, non-ASCII, and %. The SOCKET task-local correctly drives both variants from the same cases() function.

Spec edits (010-integrations/spec.md, 042-decision-service-and-remote-seams/spec.md): both accurately describe the implementation without overclaiming (image and shared conformance suite remain open; spec 042 is still in-progress). No lifecycle or ratification anomaly visible.

No concrete defects found.

{"head": "4904ed75f828f262d82dcb70c5e273fd96fa622a", "verdict": "no-findings", "findings": []}

Subject: f1e945b...4904ed7, diff digest 89cb37dd6045fa7fb37a36aff84d844d5dd35f84963c8ff4ba51862eb27d0dcf, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus force-pushed the impl/010-serve-tests branch from f1e945b to d188a03 Compare October 23, 2026 08:51
@bartekus
bartekus force-pushed the impl/010-serve-grpc branch from 4904ed7 to c3f5928 Compare October 23, 2026 09:11
@bartekus
bartekus force-pushed the impl/010-serve-tests branch from d188a03 to 4765355 Compare October 23, 2026 09:19
@bartekus
bartekus force-pushed the impl/010-serve-grpc branch from c3f5928 to 6b54929 Compare October 23, 2026 09:19
@bartekus
bartekus force-pushed the impl/010-serve-tests branch from 4765355 to 78eabbd Compare October 23, 2026 09:22
@bartekus
bartekus force-pushed the impl/010-serve-grpc branch from 6b54929 to 367b15a Compare October 23, 2026 09:22
@github-actions

Copy link
Copy Markdown

AI review (no-findings)

Reviewing the gRPC transport addition to rustev-serve (spec 042 increment 2). Checking for bugs, security issues, and governance inconsistencies.

grpc.rs path parameter substitution: The ID values substituted into route via route.replace(placeholder, value) are validated to contain only [a-zA-Z0-9\-._~:%], which excludes {, }, and path separators, so injection into template placeholders is not possible.

decode_path_id now called in transport::route(): A %2F-encoded ID passes the !id.contains('/') guard on the raw segment but decodes to a / in the stored key. The comment correctly documents this as intentional and safe because the service has not yet been released.

GrpcBody streaming termination: Once terminal is set after the Final SSE event, the data frame for that event is still emitted before the trailers. The test final_stops_consumption_before_trailing_sse_data verifies this. Behavior is correct.

{:?} formatting for gRPC path matching: operation_table().find(|op| path == format!("/rustev.serve.v1.Serve/{:?}", op.operation)) relies on the Debug format of Operation producing the exact PascalCase variant name. Both production routing and the differential test use identical {:?} formatting, so any deviation would also fail the test; not a latent silent bug.

Content-length overflow (max + 11) as u64: max is a usize; on 64-bit targets this is fine. On 32-bit, a configured limit near u32::MAX could overflow, but no plausible body limit would be set that high.

refusal_response calls status() twice for EvidenceNotDelivered: encode_response evaluates status(&document) to get terminal, then calls refusal_response which calls status() again. Redundant but idempotent; not a bug.

Boundary check additions in tools/rustev-boundaries/src/lib.rs: SERVICE_FAMILIES correctly covers the gRPC and Sigstore families. The forbidden_for_pure, FacadeFamily, and ForbiddenFamily checks are all updated symmetrically. The new test exercises both transitive purity and facade violations for every family member.

Spec changes: specs/010-integrations/spec.md accurately describes the implementation. specs/042-decision-service-and-remote-seams/spec.md records the boundary family update. Neither makes unsupported claims about lifecycle state (the implementation is still documented as in-progress).

No concrete defects found.

{"head": "367b15abb3d3cd7474623a638cae69b39081af81", "verdict": "no-findings", "findings": []}

Subject: 78eabbd...367b15a, diff digest 7108dac43e6dde1f0214a19e7feb768b1e6e18d720a429cc1a87e2c9b018b3a5, 1 call(s). An AI comment is not an approval.

Base automatically changed from impl/010-serve-tests to main October 23, 2026 09:50
@bartekus
bartekus force-pushed the impl/010-serve-grpc branch from 367b15a to 2777e6e Compare October 23, 2026 09:51
@bartekus
bartekus enabled auto-merge (squash) October 23, 2026 09:51
@github-actions

Copy link
Copy Markdown

AI review (findings)

Reviewing the PR, which adds a gRPC transport layer to rustev-serve (spec 042 increment 2), I focused on the grpc.rs dispatcher, the transport refactor, the boundary tool update, and the generation test.


Finding 1 — boundary test omits dev-dependencies

tools/rustev-boundaries/src/lib.rs — the new test for SERVICE_FAMILIES iterates only over [None, Some("build")] for dependency kind; it never tests Some("dev"). If the underlying check() function treats dev-dependencies the same as ordinary ones (which the existing pattern for other families suggests), then a non-integration crate adding, e.g., tonic as a dev-dependency would not be caught and would not produce a ForbiddenFamily violation. The test loop should include Some("dev") to close this gap, or the code should explicitly document that dev-dependencies are exempt.

Finding 2 — unchecked usize addition in body-size guard

integrations/rustev-serve/src/grpc.rs, body accumulation loop: max + 11 and max + 6 are bare usize additions. The .saturating_add call is correctly used one line above for the running-length check, but the two comparison thresholds use regular +. On a 32-bit target (or with a pathological configuration limit) these would overflow and undercut the size guard. The fix is max.saturating_add(11) and max.saturating_add(6) for consistency.


{"head": "2777e6e623f5d350b661928669dc50ae508ad349", "verdict": "findings", "findings": [{"path": "tools/rustev-boundaries/src/lib.rs", "line": 594, "summary": "The new SERVICE_FAMILIES boundary test iterates over [None, Some(\"build\")] but omits Some(\"dev\"), leaving dev-dependencies on tonic/prost family crates in non-integration packages untested and potentially unchecked."}, {"path": "integrations/rustev-serve/src/grpc.rs", "line": 88, "summary": "max + 11 and max + 6 are bare usize additions in the body-size guards; .saturating_add is used for the accumulation check one line above but not for these comparison thresholds, risking wraparound overflow on 32-bit targets or extreme configurations."}]}

Subject: 15214cb...2777e6e, diff digest 7108dac43e6dde1f0214a19e7feb768b1e6e18d720a429cc1a87e2c9b018b3a5, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus had a problem deploying to statecraft-review-exception October 23, 2026 09:59 — with GitHub Actions Error
@bartekus
bartekus force-pushed the impl/010-serve-grpc branch from 2777e6e to 2cb84a9 Compare October 23, 2026 10:13
@github-actions

Copy link
Copy Markdown

AI review (findings)

Reviewing this PR, which adds gRPC transport (rustev-serve increment 2) via tonic/prost, a generated proto/stub checked for drift by a test, gRPC-aware refusal formatting in the transport layer, and boundary-check additions for the service families.

Scope of review: Cargo dependencies, proto/stub generation, grpc.rs framing logic, transport.rs changes (decode_path_id, handle extraction), boundary tests, spec narrative updates.


Finding: route() returns None on malformed percent-encoding, yielding HTTP 404 instead of HTTP 400

File: integrations/rustev-serve/src/transport.rs

The hunk at @@ -160,7 +160,13 @@ changes the ID extraction in route():

// before
return Some((op, Some(id.into())));
// after
return Some((op, Some(decode_path_id(id)?)));

When decode_path_id encounters a malformed escape (e.g., %GG in /v1/decisions/%GG), it returns None. The ? propagates None out of route(), causing the caller in handle() to respond with RefusalCode::EndpointUnavailable (HTTP 404).

The gRPC path explicitly rejects the same input with RefusalCode::InvalidRequest (HTTP 400 / gRPC INVALID_ARGUMENT):

// grpc.rs – header validation
&& crate::transport::decode_path_id(v).is_some()
// → None → filter fails → InvalidRequest

The RFC 3986 contract says a malformed percent-encoding is a syntactic error in the request, not an indication that the endpoint does not exist. Returning 404 for a syntactically invalid request is misleading and inconsistent with the gRPC branch. The comment in the transport diff ("A malformed escape (%GG) is an invalid request here, not an unknown endpoint after routing") describes the gRPC intent but the HTTP path still ends up at EndpointUnavailable.


No other concrete defects found. The status() function correctly handles refusals vs. evidence-not-delivered decisions, the SSE-to-gRPC frame conversion logic is consistent with the streaming protocol, the body-size bounds are coherent (5-byte header + 6-byte protobuf overhead = 11-byte slack), the wait-ms and path-ID character validations prevent injection, and the boundary-check additions (including dev-dependency coverage) match the spec claim.

{"head": "2cb84a971d7677b4633368133b65af725482bd1c", "verdict": "findings", "findings": [{"path": "integrations/rustev-serve/src/transport.rs", "line": 167, "summary": "decode_path_id returning None for a malformed percent-encoded HTTP path segment (e.g. %GG) propagates None out of route(), causing handle() to respond EndpointUnavailable (404) instead of InvalidRequest (400), inconsistent with the gRPC path which correctly returns InvalidArgument for the same input."}]}

Subject: 15214cb...2cb84a9, diff digest 4dbf4c3ad4c522d9dd558e1b8b7fe94e89c5c823f8c33faa1ae5926f51a6c9fa, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus had a problem deploying to statecraft-review-exception October 23, 2026 10:21 — with GitHub Actions Error
@bartekus
bartekus force-pushed the impl/010-serve-grpc branch from 2cb84a9 to ba715bd Compare October 23, 2026 10:42
@github-actions

Copy link
Copy Markdown

AI review (findings)

Looking at the diff, I'll work through the significant new files and changes systematically.

integrations/rustev-serve/tests/grpc_generation.rs — The test declares use sha2::{Digest, Sha256}; at line 4 and calls Sha256::digest(...) to compute the proto digest. The integrations/rustev-serve/Cargo.toml diff adds only tonic-prost-build to [dev-dependencies] and tonic, tonic-prost, prost to [dependencies] — sha2 appears neither in the added lines nor in the unchanged context lines visible around the hunks (rcgen, tokio on the dev side; rustls, tokio-rustls, ring, sigstore-verify, webpki-roots on the prod side). In Rust 2018+ edition, a use of a crate not listed as a direct dependency (regular or dev) is a compilation error; transitive availability is not sufficient. If sha2 is absent from the original file (as the diff context strongly suggests), the grpc_generation test target will not compile.

integrations/rustev-serve/src/grpc.rs — route lookup via {:?} — The gRPC method name is matched with format!("/rustev.serve.v1.Serve/{:?}", op.operation), coupling the routing to the derived Debug representation of Operation enum variants. The proto generator in grpc_generation.rs uses the same {:?} format, so the committed .proto and the server routing stay mutually consistent, but only as long as Operation's Debug output is never overridden. This is not broken now but is an unusual coupling; it is not a separate reportable defect beyond what I can evidence here.

integrations/rustev-serve/src/grpc.rs — GrpcBody unary path and terminal emission — For the unary (non-streaming) path, the inner body is Full::new(frame(document)).boxed() which has no trailers. The Poll::Ready(None) branch fires and emits the terminal Status as gRPC trailers. This is correct. The trailers_pass_through_and_end_the_body test uses with_trailers, which exercises a path that sets ended = true before terminal is emitted, but that test body is Full::new(Bytes::new()) (zero data bytes) so no real content is lost. No defect.

integrations/rustev-serve/src/transport.rs — decode_path_id change — HTTP paths that formerly returned the raw percent-encoded segment as the id now return the decoded string. The comment acknowledges the behaviour change and notes the service is pre-release. No defect.

tools/rustev-boundaries/src/lib.rs — SERVICE_FAMILIES is added to forbidden_for_pure and to both FacadeFamily/ForbiddenFamily checks. Tests cover the crates/ vs. integrations/ boundary and dev-dependency cases. No defect.

Spec updates — Both specs/010-integrations/spec.md and specs/042-decision-service-and-remote-seams/spec.md add narrative text. Frontmatter is not shown; the governance system (not this review) enforces lifecycle state and coupling gate. No evidence of a contradiction in the visible text.

Concrete defect: missing sha2 dependency

integrations/rustev-serve/tests/grpc_generation.rs line 4 imports sha2::{Digest, Sha256}. The Cargo.toml diff for rustev-serve does not add sha2 to any dependency section, and the surrounding context lines in the diff do not show it as an existing entry. Without an explicit declaration, the test target will fail to compile.

{"head": "ba715bd4cacb470a20fc16772eba1dc3cbe3ed6d", "verdict": "findings", "findings": [{"path": "integrations/rustev-serve/tests/grpc_generation.rs", "line": 4, "summary": "The test imports `sha2::{Digest, Sha256}` but `sha2` does not appear as a declared dependency in `integrations/rustev-serve/Cargo.toml`; without an explicit entry the test target will not compile."}]}

Subject: 15214cb...ba715bd, diff digest 761a26d2a7507ffcddd1f43b5d228b92f68f78c07af848c580b7dcffc0a367ea, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus had a problem deploying to statecraft-review-exception October 23, 2026 10:50 — with GitHub Actions Error
@bartekus
bartekus force-pushed the impl/010-serve-grpc branch from ba715bd to 928c6b9 Compare October 23, 2026 10:50
@github-actions

Copy link
Copy Markdown

AI review (no-findings)

Reviewing the PR, which adds a gRPC transport to rustev-serve (increment 2 of spec 042), new boundary family enforcement, and spec record updates.

Cargo / dependency additions (Cargo.toml, Cargo.lock): tonic, tonic-prost, prost, tonic-prost-build added at pinned versions under the integration family. tonic-prost-build is correctly a dev-dependency only in rustev-serve. The lock file entries are consistent with the declared versions. No unexpected transitive additions observed.

Proto definition and generated stub (serve.proto, generated/rustev.serve.v1.rs): The service definition uses a single opaque bytes document field, consistent with the pass-through design. The digest header // serve.proto SHA-256: … on line 1 of the stub binds the committed Rust source to the proto bytes even without protoc available.

gRPC handler (grpc.rs):

  • Body framing: The five-byte gRPC length-prefix is checked incrementally during accumulation (bytes.len() >= 5 && u32::from_be_bytes(…) > max.saturating_add(6)) and again after full collection. The sentinel bytes[0] != 0 rejects compressed messages. This is consistent.
  • ID validation: The rustev-plan-id/rustev-decision-id metadata values are checked against a strict alphabet [A-Za-z0-9-._~:%], validated through decode_path_id, limited to one header instance, and limited to 768 bytes before substitution into the route. Path-separator injection via percent-encoded / (%2F) is therefore decoded into the stored ID rather than breaking routing, matching the HTTP behavior.
  • Wait-ms injection: rustev-wait-ms is validated to be non-empty ASCII digits before appending ?wait_ms=… to the route, preventing query injection.
  • Duplicate content-type headers: The handler enforces get_all("content-type").iter().count() == 1 after the primary content-type check. is_grpc only inspects the first value; duplicate headers could misroute in theory, but the count check inside grpc::request catches any such case.
  • status() called twice per error: For refusals and EvidenceNotDelivered, status(document) is invoked once to compute terminal and again inside refusal_response. The document is a local Vec<u8> so there is no TOCTOU issue; this is merely redundant.
  • expect("escaped ASCII handle"): path_id produces only [A-Za-z0-9-._~:%], which are all valid HTTP header value bytes; the expect cannot reasonably panic.

Transport refactoring (transport.rs): The Routed type alias exposes the new Result<Option<String>, ()> return from route. The new handle function (now pub(crate)) correctly unwraps the Ok variant and returns InvalidRequest for malformed percent-encoding, matching gRPC behavior. The outer request function routes gRPC early (after rate-limit and header-size checks) and delegates to grpc::request, which in turn calls transport::handle for shared handler logic.

Streaming body (GrpcBody): The terminal flag correctly stops SSE consumption after a Final event is parsed (test final_stops_consumption_before_trailing_sse_data). Trailer pass-through from the inner body short-circuits cleanly via self.ended = true. The fallback Status::internal("stream ended without final event") is appropriate.

Boundary check (tools/rustev-boundaries/src/lib.rs): SERVICE_FAMILIES adds the gRPC and Sigstore families to forbidden_for_pure and to the facade/forbidden-family checks for non-integration crates. The tests cover transitive impurity, forbidden families, and dev-dependency placement for all entries.

Spec updates: The record in specs/010-integrations/spec.md accurately describes the implementation (committed proto/stub, digest binding test, same handler layer, loopback differential test). The boundary-family note in spec 042 matches the code changes.

No concrete defects found.

{"head": "928c6b9b7f3f306b10e436133dd209201815cdbb", "verdict": "no-findings", "findings": []}

Subject: 15214cb...928c6b9, diff digest a3d2ca570adc2b28ff6adc9767ad99177729368f087add1a992c6ef1ff23bf28, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus merged commit 4e2cc8e into main Oct 23, 2026
31 checks passed
@bartekus
bartekus deleted the impl/010-serve-grpc branch October 23, 2026 11:31
bartekus added a commit that referenced this pull request Oct 23, 2026
…lete (#188)

Stacked on #187. Maps every applicable spec 010 section 5 row to a
rustev-serve test (tests/COVERAGE.md, three new regression tests), adds
rustev-serve to 010's declared verification, removes the stale 'not
implemented' text, and marks 010 complete: all three 3.4 records pass
with owner review (R-44, A-45, A-47), each integration builds alone with
minimum features, and no live qualification ran. 042's image and
conformance cases remain 042's work.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant