Skip to content

impl(010): rustev-serve increment 1, the HTTP service over mutual TLS - #186

Closed
bartekus wants to merge 1 commit into
mainfrom
impl/010-serve-http
Closed

bartekus wants to merge 1 commit into
mainfrom
impl/010-serve-http

Conversation

@bartekus

Copy link
Copy Markdown
Contributor

Spec 010 3.7 via spec 042, under the approved binding record (A-47), stacked on #183. HTTP/1.1 and HTTP/2 over TLS 1.3 with required client certificates, Unix sockets, the handler layer, signed plan registration (Ed25519 via ring; Sigstore verified offline via sigstore-verify), decisions, the 042 3.5.1 refusal table, idempotency, lookup, cancellation, SSE progress streaming via a new optional runtime observer (no-observer bytes unchanged), health/readiness/metrics, graceful shutdown, standalone sinks. gRPC, the image and shared conformance cases follow. Checks: rustev-serve, rustev-runtime, rustev-conformance and rustev-release tests; workspace clippy; fmt; boundaries; make gate; couple.

@github-actions

Copy link
Copy Markdown

AI review (findings)

Reviewing the PR, which adds rustev-serve (decision service), a ProgressObserver trait for the runtime, and supporting infrastructure.


Finding 1 — Route function early-exits the function instead of advancing to the next operation

In integrations/rustev-serve/src/transport.rs, the route function iterates over operation_table(). Inside the for loop, when a templated route is encountered, it does:

let end = template.find('}')?;

Because the enclosing function returns Option<…>, the ? operator propagates None as a function return rather than continuing to the next loop iteration. If any operation template contains { but not }, routing returns None for every request path including unrelated, well-formed routes. The intent was clearly continue-on-missing-brace, not silent total routing failure. Whether any current contract template is malformed is not shown in the diff, but the defect is concrete: the logic is wrong for its stated purpose and any future addition of a malformed template would silently break all routing.

Finding 2 — Panic in blocking thread misreported as QueueDeadline

In integrations/rustev-serve/src/offline.rs, Roots::resolve defensively parses the reference via serde_json::from_value::<Reference>, then immediately calls:

let (prefix, relative) = reference.as_str().split_once(':').unwrap();

If the Reference type's invariant (that it always contains :) ever changes, or if a future refactoring removes the gateway parse, this panics inside spawn_blocking. The caller in run does:

match tokio::time::timeout(limit.saturating_sub(started.elapsed()), work).await {
    Ok(Ok(r)) => r,
    _ => Reply::refusal(RefusalCode::QueueDeadline),
}

A JoinError from a blocked-thread panic is indistinguishable from a timeout at this call site, so callers receive QueueDeadline instead of any meaningful diagnostic. A split_once with proper error handling (returning Resolution::Inaccessible) would be consistent with every other failure path in the same function.


No other concrete defects were found. The bearer-token constant-time comparison (HMAC-SHA256 of digests), the inode check in root confinement, the Sigstore inclusion-proof requirement, and the catch_unwind wrapping of observer callbacks all appear correct.

{"head": "15c24b57083afc5485b453445bb2925544180ed6", "verdict": "findings", "findings": [{"path": "integrations/rustev-serve/src/transport.rs", "line": 333, "summary": "Inside the for-loop over operation_table(), `template.find('}')` uses `?` which returns None from the entire route() function rather than skipping to the next operation, so any template with `{` but no `}` silently disables all routing."},{"path": "integrations/rustev-serve/src/offline.rs", "line": 26, "summary": "After the Reference guard, `reference.as_str().split_once(':').unwrap()` can panic in the spawn_blocking thread; the JoinError is indistinguishable from a timeout and is reported to callers as RefusalCode::QueueDeadline."}]}

Subject: 25ef0f0...15c24b5, diff digest 9ddb6ce4bf6668cce27a89d8914a88514a51baf22daa691e1e7fb5e65a4615b6, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus had a problem deploying to statecraft-review-exception October 23, 2026 03:33 — with GitHub Actions Error
@bartekus
bartekus force-pushed the impl/010-serve-http branch from 15c24b5 to cc1288d Compare October 23, 2026 03:34
@bartekus
bartekus force-pushed the spec/010-serve-record branch from 25ef0f0 to 7b4d23c Compare October 23, 2026 03:35
@bartekus
bartekus force-pushed the impl/010-serve-http branch from cc1288d to 1380df6 Compare October 23, 2026 03:35
@github-actions

Copy link
Copy Markdown

AI review (findings)

Finding 1 — per-connection rate limiter (integrations/rustev-serve/src/transport.rs:481)

The rate counter (Arc<Mutex<Connection>>) is allocated once per accepted connection and shared only within that connection's task. A client that opens N connections can sustain N × requests_per_second requests per second against the service. The config field name implies a service-level bound; the implementation enforces a per-connection one.

Finding 2 — delivery error string missing may_have_received: suffix (integrations/rustev-serve/src/sinks.rs:261)

Sinks::deliver uses ? on report_component_health, whose error type is &'static str. If it returns an error, the resulting delivery-failure string (e.g. "unknown configured component") does not include the ; may_have_received: <bool> suffix appended by every other error path in that file. Callers that parse this suffix to determine delivery uncertainty will misclassify this failure.

Finding 3 — internal sources re-exported as public API (integrations/rustev-serve/src/lib.rs:18)

budget, http, phases, pool, and wire are declared pub mod via #[path = "../../rustev-remote-http/src/..."]. This makes the internal source files of rustev-remote-http part of rustev-serve's public surface without a crate boundary or versioned contract. Any change to those files silently alters rustev-serve's public API. The publish = false on rustev-serve limits external exposure but does not prevent in-workspace callers from depending on the leaked surface.

{"head": "1380df60ae833fe69f04c12cedeedc378ad1d1d5", "verdict": "findings", "findings": [{"path": "integrations/rustev-serve/src/transport.rs", "line": 481, "summary": "The requests_per_second rate limiter is scoped per accepted connection (a new Arc<Mutex<Connection>> is allocated on each accept), not per service; a client that opens N connections can send N times the configured limit per second before any refusal."}, {"path": "integrations/rustev-serve/src/sinks.rs", "line": 261, "summary": "The ? operator on report_component_health propagates a &'static str error that lacks the '; may_have_received: <bool>' suffix appended by every other error path in sinks.rs; callers that parse that suffix to classify delivery uncertainty will misclassify this failure."}, {"path": "integrations/rustev-serve/src/lib.rs", "line": 18, "summary": "Internal source files of rustev-remote-http are re-exported as pub mod via #[path], making their full APIs part of rustev-serve's public surface without a crate boundary or versioned contract; changes to the included files silently change rustev-serve's public API."}]}

Subject: 7b4d23c...1380df6, diff digest a8fffbb1818f8ce70b16bc9b6dc08672e93d53d135a9027a4c0f62ead340f02d, 1 call(s). An AI comment is not an approval.

@github-actions

Copy link
Copy Markdown

AI review (findings)

{"head": "15be9797e5f916f654676eed858cc0052d64de43", "verdict": "findings", "findings": [{"path": "integrations/rustev-serve/src/service.rs", "line": null, "summary": "Registration idempotency is broken: the idempotency check compares registration_id() values derived from the full PlanRegistration record including registered_at_ms (the current wall-clock time), so the newly-constructed record always has a different registration_id() than the stored one, causing every re-registration attempt to return RegistrationConflict instead of 200 OK."}]}

Subject: 6003e86...15be979, diff digest 5adafa40f4dff1d5160898d71a56ff0174ddf85b0d2beeff5a7d1f8c3e69c557, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus had a problem deploying to statecraft-review-exception October 23, 2026 05:29 — with GitHub Actions Error
@bartekus
bartekus force-pushed the impl/010-serve-http branch from 15be979 to 3fcef4c Compare October 23, 2026 05:30
@github-actions

Copy link
Copy Markdown

AI review (findings)

Reviewing the PR which adds rustev-serve, a ProgressObserver for the runtime, and associated specs/tests.

Analysis

Security and correctness review

Bearer token comparison (transport.rs): The HMAC-based comparison achieves constant-time equality of SHA-256 hashes, which is equivalent to comparing the tokens. Unusual but not wrong.

Path traversal (offline.rs): canonicalize() + starts_with + Unix inode check is a reasonable defense. TOCTOU limitations are explicitly documented in the README as out of scope.

DER subject extraction (subjects.rs): The custom TLV parser is defensive (checked arithmetic, length limits, strict tag checks), and operates only after WebPKI validates the cert chain. A parse failure returns None, causing the cert to be rejected — the secure fallback.

Sigstore verification (signatures.rs): The any_identity() second-pass check is only used to distinguish error codes (SignatureUntrusted vs SignatureInvalid), not for acceptance. The actual acceptance requires the full identity+issuer policy check.

Admission/shutdown logic, idempotency, progress observer delivery (service.rs, driver.rs, progress.rs): No correctness defects found.


Concrete defect — health state clobber in sinks.rs

In Sinks::deliver, after each delivery attempt, report_component_health is called with:

crate::health::ComponentHealth {
    described: true,
    degraded: result.is_err(),
    ..Default::default()   // ← resets invalidation_degraded, queue_depth, refusals, …
}

report_component_health does a full replacement (item.health = health). Any host-reported fields such as invalidation_degraded: true, queue_depth, refusals, and late_responses_discarded are silently overwritten to their defaults after every delivery event. For embedded callers that independently invoke report_component_health to report invalidation degradation or queue depth, a subsequent delivery — even a successful one — would silently clear those signals, causing the readiness probe to stop reflecting actual component state. The ..Default::default() spread should be replaced with a targeted update of only described and degraded.

{"head": "3fcef4cc814c1ec78f166b1c3ff1ea4422437a0e", "verdict": "findings", "findings": [{"path": "integrations/rustev-serve/src/sinks.rs", "line": null, "summary": "Sinks::deliver calls report_component_health with ..Default::default(), which performs a full health struct replacement and silently resets host-reported fields (invalidation_degraded, queue_depth, refusals, etc.) to zero/false after every delivery attempt."}]}

Subject: 6003e86...3fcef4c, diff digest 696a087e84854eef6a464b42b41e2bd30a1ad9e1e3487810ad05655f744693bc, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus had a problem deploying to statecraft-review-exception October 23, 2026 05:38 — with GitHub Actions Error
@bartekus
bartekus force-pushed the impl/010-serve-http branch from 3fcef4c to 9b1fb2c Compare October 23, 2026 05:40
Base automatically changed from spec/010-serve-record to main October 23, 2026 05:41
@bartekus
bartekus force-pushed the impl/010-serve-http branch from 9b1fb2c to 1102e6b Compare October 23, 2026 05:42
@bartekus
bartekus enabled auto-merge (squash) October 23, 2026 05:42
@github-actions

Copy link
Copy Markdown

AI review (findings)

{"head": "1102e6b1ed336cd9c14eed8a6b6144d80a6aeb93", "verdict": "findings", "findings": [{"path": "integrations/rustev-serve/src/service.rs", "line": null, "summary": "The ticket-settlement task busy-polls for entry.reply with yield_now() instead of awaiting entry.finished.notified(), which the outer decide task notifies immediately after setting entry.reply; this causes repeated mutex acquisitions and unnecessary CPU consumption on every queued-delivery decision."}]}

Subject: 3728c53...1102e6b, diff digest caa4b81d5ce7020be4fdb4d9ab7d3295b09730062184e5e206bcb6c4561a324a, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus had a problem deploying to statecraft-review-exception October 23, 2026 05:56 — with GitHub Actions Error
@bartekus
bartekus force-pushed the impl/010-serve-http branch 2 times, most recently from 98938d0 to 8448653 Compare October 23, 2026 06:08
@github-actions

Copy link
Copy Markdown

AI review (findings)

Review

Finding 1 — SSE stream silently truncated when decision task panics

File: integrations/rustev-serve/src/transport.rs, lines ~540–560

In the streaming request path, after decide_stream returns:

tokio::spawn(async move {
    let reply = service_task
        .decide_stream(&id, principal, &bytes, deadline, Some(events))
        .await;
    let result = if let Ok(d) = Embedded::<ServeDecision>::parse(&reply.body) {
        FinalResult::Decision(d)
    } else if let Ok(r) = Embedded::<ServeRefusal>::parse(&reply.body) {
        FinalResult::Refusal(r)
    } else {
        return;            // ← drops `finish` without sending
    };
    finish.send(result);
});

When the inner decision task panics, decide_stream returns Reply { status: 500, body: vec![], … } (from service.rs's unwrap_or_else). An empty body parses as neither ServeDecision nor ServeRefusal, so the else arm executes return, dropping finish without calling finish.send(). EventBody::poll_frame then receives Poll::Ready(Err(_)) from the dropped oneshot and returns Poll::Ready(None), closing the SSE body without emitting a final event. The client receives a clean stream close but no final event, leaving it unable to distinguish task panic from a normal stream close and potentially issuing a retry with the same decision ID.


Finding 2 — Sigstore error-code misclassification for partially valid bundles

File: integrations/rustev-serve/src/signatures.rs, lines ~120–133

if sigstore_verify::verify(
    input.as_slice(),
    &bundle,
    &VerificationPolicy::any_identity(),
    root,
)
.is_ok()
{
    intact_but_untrusted = true;
}

The first verification loop (with the configured identity/issuer policy) correctly checks result.certificate_verified() && result.tlog_verified(). The second call, used only to decide between SignatureUntrusted and SignatureInvalid, does not. If a bundle carries a valid message signature but an invalid certificate chain or transparency log entry, verify(…, any_identity(), …) can return Ok(result) with certificate_verified() == false or tlog_verified() == false, causing intact_but_untrusted = true and the function to return SignatureUntrusted instead of SignatureInvalid. Security outcome is the same (rejection), but the error code reported to the caller is incorrect.


{"head": "8448653b354234e6400227c7c2b8a3c744ee1406", "verdict": "findings", "findings": [{"path": "integrations/rustev-serve/src/transport.rs", "line": 550, "summary": "In the streaming path, when the decision task panics and decide_stream returns an empty body, the finish sender is dropped without calling finish.send(), causing the SSE stream to close without emitting a final event."}, {"path": "integrations/rustev-serve/src/signatures.rs", "line": 127, "summary": "The any_identity() call used to distinguish SignatureUntrusted from SignatureInvalid does not check certificate_verified() or tlog_verified(), so a bundle with an invalid certificate chain but valid message signature is misclassified as SignatureUntrusted instead of SignatureInvalid."}]}

Subject: e735b7f...8448653, diff digest fdb3d1a6e2da4fe9e2f921815b6941d7e38243d8d1ce1a184209391a46774001, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus had a problem deploying to statecraft-review-exception October 23, 2026 06:17 — with GitHub Actions Error
@bartekus
bartekus force-pushed the impl/010-serve-http branch 2 times, most recently from 8ba10a9 to 26b32cb Compare October 23, 2026 06:22
@github-actions

Copy link
Copy Markdown

AI review (no-findings)

Review

Cargo.lock / Cargo.toml

Dependency additions (sigstore-verify, ring, jiff, cms, der, spki, tls_codec, x509-cert) are consistent with the new integrations/rustev-serve/ crate's declared dependencies. Pinning sigstore-verify = "=0.15.0" is deliberate. No issues.

crates/rustev-runtime/src/progress.rs

catch_unwind(AssertUnwindSafe(…)) correctly isolates panicking observers; the counter uses Ordering::Relaxed, acceptable for a metrics-only counter. The remaining() function correctly skips semantic-backend steps already reported during run_requests by checking against requests. Looks correct.

crates/rustev-runtime/src/driver.rs

The drop(ev) before o.call(|o| o.step(…)) releases the evidence lock before calling the observer, which is correct (observer must not hold the lock). Progress is reported after supply is committed, consistent with spec intent.

integrations/rustev-serve/src/transport.rs — bearer token comparison

ring::hmac::verify(
    &ring::hmac::Key::new(ring::hmac::HMAC_SHA256, expected.as_slice()),
    actual.as_slice(),
    ring::hmac::sign(
        &ring::hmac::Key::new(ring::hmac::HMAC_SHA256, expected.as_slice()),
        expected.as_slice(),
    ).as_ref(),
).is_ok()

This checks HMAC(SHA256(token), SHA256(got)) == HMAC(SHA256(token), SHA256(token)), i.e., SHA256(got) == SHA256(token) in constant time. Functionally equivalent to a constant-time comparison of the two digests. Correct but unusual.

integrations/rustev-serve/src/subjects.rs

The TLV parser only runs on certificates already validated by WebPKI; parser failure returns None which rejects the certificate (safe default). The v3 optional [0] version field is handled correctly. Field skip count (4: serialNumber, signature, issuer, validity) produces the subject correctly per RFC 5280. No issues.

integrations/rustev-serve/src/offline.rs

Path-traversal defence uses canonicalize + starts_with(root) + inode comparison + second canonicalize. The README explicitly acknowledges this is not safe against a concurrent hostile-writer filesystem. Documented limitation, not a hidden bug.

integrations/rustev-serve/src/signatures.rs

Sigstore path requires has_inclusion_proof(), full certificate chain verification, and explicit identity/issuer policy check. The "intact but untrusted" secondary verify correctly distinguishes SignatureUntrusted from SignatureInvalid. Ed25519 key loading enforces exactly 32 raw bytes. Looks correct.

integrations/rustev-serve/src/service.rs

tokio::spawn(…).await with a detached inner task correctly implements "the service owns this task; dropping the transport future never cancels it." The Ordering::Acquire on running pairs with Ordering::Release in Progress::admitted, ensuring visibility. RESERVED = 9 * MIB + 71 pre-allocates before the decision runs; post-decision sizing is computed from actual body length. Shutdown busy-polls every 2 ms — documented and bounded.

integrations/rustev-serve/src/stream.rs

poll_frame registers the waker with both the mpsc receiver and the oneshot receiver in the same cx; both wake the same task, so re-polling covers both. Dropping Finish without calling send causes Poll::Ready(Err(_)) → stream terminates cleanly with no final frame, which is the documented "decision panic" gap in spec 042.

tools/rustev-release/release-set.json

The removed entry had "kind": "crate". The new entry has no kind field. Surrounding entries (rustev-bedrock, rustev-jev) in the same section also lack kind, so this appears consistent with that section's schema. Cannot confirm or deny whether the tool schema requires this field, but no evidence of a defect given the surrounding pattern.

Spec updates

Spec 010 correctly removes planned: true from integrations/rustev-serve/. Spec 042 correctly records the progress-observer addition and honestly flags the unresolved final-event gap for panicking decision tasks.

No concrete defects identified.

{"head": "26b32cbd078976855e33dc02ca893efc9cb9acfc", "verdict": "no-findings", "findings": []}

Subject: e735b7f...26b32cb, diff digest edcee2817a7986ec9ca1f82792db390d794ac74beecefce49ebd1897acae8e58, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus force-pushed the impl/010-serve-http branch from 26b32cb to 6548ee2 Compare October 23, 2026 06:49
@github-actions

Copy link
Copy Markdown

AI review (findings)

{"head": "6548ee2f8660ed8d139e52b62957ea625066998e", "verdict": "findings", "findings": [{"path": "tools/rustev-release/release-set.json", "line": null, "summary": "The new rustev-serve crate exclusion entry is missing the \"kind\" field (expected \"crate\") present on every other exclusion entry in the file; the replaced entry had it, and its absence may cause the release tooling to ignore or misparse this record."}]}

Subject: c2d800e...6548ee2, diff digest edcee2817a7986ec9ca1f82792db390d794ac74beecefce49ebd1897acae8e58, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus had a problem deploying to statecraft-review-exception October 23, 2026 07:04 — with GitHub Actions Error
@bartekus
bartekus force-pushed the impl/010-serve-http branch from 6548ee2 to 889b307 Compare October 23, 2026 07:05
@bartekus

Copy link
Copy Markdown
Contributor Author

Superseded by #189, #190 and #191 (the same change split in three, because this PR's AI review repeatedly exceeded its time limit). #187 now stacks on #191.

@bartekus bartekus closed this Oct 23, 2026
auto-merge was automatically disabled October 23, 2026 08:16

Pull request was closed

bartekus added a commit that referenced this pull request Oct 23, 2026
Split from #186 (its AI review timed out repeatedly). Spec 042 3.7.3:
`ProgressObserver` and `Runtime::decide_observed`; events carry step id,
instance ids, outcome and the derivation class the compiled step
determines, never a value; observer panics are contained and counted.
With no observer, every runtime test, golden and conformance case is
byte-identical. Checks: rustev-runtime tests and clippy, rustev-release
archives, make gate, couple.
bartekus added a commit that referenced this pull request Oct 23, 2026
Split from #186, stacked on #189. The rustev-serve crate sources under
the approved binding record (A-47): HTTP/1.1 and HTTP/2 over TLS 1.3
with required client certificates, Unix sockets, the handler layer,
signed plan registration (Ed25519, offline Sigstore), decisions, the 042
3.5.1 refusal table, idempotency, lookup, cancellation, SSE streaming,
health/readiness/metrics, shutdown and standalone sinks. Every review
finding raised on #186 is already fixed here. Tests and fixtures follow
in the next PR. Checks: build, clippy, make gate, couple.
bartekus added a commit that referenced this pull request Oct 23, 2026
…191)

Split from #186, stacked on the sources PR. The loopback handler and
transport tests, committed test certificates and synthetic Sigstore
fixtures (with their regeneration script), and the section 5 coverage
map. Checks: rustev-serve tests (all pass locally including socket
tests), clippy, make gate, couple.
bartekus added a commit that referenced this pull request Oct 23, 2026
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.
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