Skip to content

impl(042): increment 6 part 1, the explanation request and answer documents - #411

Merged
bartekus merged 1 commit into
mainfrom
impl/042-explain-contract
Oct 30, 2026
Merged

bartekus merged 1 commit into
mainfrom
impl/042-explain-contract

Conversation

@bartekus

Copy link
Copy Markdown
Contributor

Spec 042, increment 6 part 1: the explanation documents of 3.8.3, as amended by #404.

What

  • rustev.serve-explain/1 (ServeExplain):
    • evidence is { record, plan? } or { bundle }, each member a DocumentInput (embedded bytes or a resolver reference) of rustev.run, rustev.plan and the replay bundle.
    • query is spec 040 3.3's query or { diff: { other } }.
    • options has optional scope and now_ms.
    • The parser admits each option alone. 3.8.3 makes a combination that does not match the bundle sides invalid_request, which is the handler's refusal, not a parse failure. has_bundle() names whether either side is a bundle.
  • rustev.serve-explanation/1 (ServeExplanation): explanation (the embedded rustev.explanation/1 record, bytes unchanged) and markdown. Its bounds, EXPLANATION_LIMITS, are 33 MiB with strings up to 16 MiB: an explanation parses under REPLAY_V1 (16 MiB), and its rendering gets the same byte count.
  • Operation table: explain names the two schemas and answers a document. Until the handler PR, the service still answers explain as unavailable.
  • Regenerated: the two JSON Schemas, the Node and WebAssembly TypeScript document types, and the gRPC stub's operation comments. Review the source in serve.rs, not the generated bytes.

Not in this PR

The handler: resolving references and the scope check, the per-listener redaction policy, the blocking pool and rustev-deadline-ms, mapping spec 040 refusals to invalid_document, and the gRPC path.

Checks

make gate, scripts/check-authored-content.sh, cargo fmt --all --check, cargo test -p rustev-contract -p rustev-serve (schemas and gRPC generation drift included) pass locally.

@github-actions

Copy link
Copy Markdown

AI review (no-findings)

Reviewing the PR, which adds ServeExplain/ServeExplanation document types and updates the operation table and proto stubs for the /v1/explain route.

crates/rustev-contract/src/serve.rs

The ExplainEvidence untagged enum with deny_unknown_fields on each inner struct is the right approach: the comment correctly notes that deny_unknown_fields on the enum container itself is silently ignored by serde when the enum is untagged. Placing it on RecordEvidence and BundleEvidence individually is the proper workaround. The test in 042_serve_documents.rs validates the mixed-field case and explicit-null case, so any failure of this pattern would surface in CI.

ExplainQuery is untagged with Diff tried first. Since DiffQuery requires an object key diff and crate::explanation::Query appears to be a string-or-object enum, there is no practical ambiguity for the common cases; the test confirms string queries parse as Query(_) and the diff object parses as Diff(_).

EXPLANATION_LIMITS inherits SERVICE_LIMITS with max_bytes: 33 * MIB and max_string_bytes: 16 * MIB. The spec note asserts these match the replay bundle bounds; this cannot be verified from the diff alone, but there is no contradicting evidence in the supplied context.

has_bundle checks evidence.is_bundle() or query is a Diff with a bundle other. This correctly covers both sides referenced in the spec note.

crates/rustev-contract/src/schema_emit.rs

ServeExplain and ServeExplanation are inserted between ServeEvaluate and ServeReadiness. Position is irrelevant to correctness here; no duplication.

Operation table / proto / generated file

Request schema changed from None to Some("rustev.serve-explain/1"), response from ["rustev.explanation/1"] to ["rustev.serve-explanation/1"], format from Explanation to Document. The proto comment and the generated file's SHA-256 header are updated consistently.

specs/042-decision-service-and-remote-seams/spec.md

The increment note is accurate relative to the implementation. Ownership is on spec 042, which is the correct owning spec for this path. The spec note explicitly defers handler enforcement of the bundle-side consistency check to runtime (invalid_request), which matches the parser's permissive ExplainOptions struct.

No concrete defects found.

{"head": "158e253f5931e718de734db1c611a8bd28330586", "verdict": "no-findings", "findings": []}

Subject: a1e0fd3...158e253, diff digest 2cfdf6d2e54298d2ccbf391ad8e956221679180b538bacca4f0e5d999181b97e, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus added this pull request to the merge queue Oct 30, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Oct 30, 2026
@bartekus
bartekus force-pushed the impl/042-explain-contract branch from 158e253 to 72d96cb Compare October 30, 2026 15:08
@github-actions

Copy link
Copy Markdown

AI review (no-findings)

Reviewing the diff for concrete bugs, security issues, and inconsistencies.

crates/rustev-contract/src/serve.rs

The ExplainEvidence and ExplainQuery untagged enums both carry a serde caveat: #[serde(deny_unknown_fields)] on an #[serde(untagged)] enum is silently ignored by serde. The PR addresses this correctly for ExplainEvidence by placing deny_unknown_fields on the inner arm structs (RecordEvidence, BundleEvidence). The same pattern is applied to DiffQuery / DiffOther.

ExplainOptions carries deny_unknown_fields and the present deserializer on both optional fields, consistently rejecting explicit nulls. EXPLANATION_LIMITS sets max_bytes: 33 * MIB and max_string_bytes: 16 * MIB; the Text<0, 16777216> on markdown is consistent with those bounds.

has_bundle covers exactly the two cases that require scope/now_ms under spec 040 3.16.2: main evidence in bundle form, and the diff's other side in bundle form.

crates/rustev-contract/tests/042_serve_documents.rs

Tests exercise: both evidence arms round-tripping; has_bundle for all three live cases (record-only, bundle-main, record+bundle-diff); rejection of mixed forms, plan-without-record, unknown diff keys, unknown query strings, and explicit-null optional fields. Coverage appears thorough.

crates/rustev-contract/src/schema_emit.rs

Two new emit calls are inserted in the correct position (before ServeReadiness). No ordering issues.

integrations/rustev-serve/proto/rustev/serve/v1/serve.proto / generated .rs

The operation comment is updated consistently in both files. The SHA-256 comment in the generated file is updated to reflect the new proto content.

specs/042-decision-service-and-remote-seams/spec.md

The increment note accurately describes the code changes, including limits rationale, has_bundle semantics, the operation table update, and which tests cover the behavior. No forward-looking claim overstates the state of the handler.

No concrete defects found.

{"head": "72d96cb83861b1327957fcf9d26915599e2e4d0e", "verdict": "no-findings", "findings": []}

Subject: d2a496f...72d96cb, diff digest c8371816018438ffc57dd8221889308cc4fa551af39edde473a4865527400a48, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus added this pull request to the merge queue Oct 30, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Oct 30, 2026
@bartekus
bartekus force-pushed the impl/042-explain-contract branch from 72d96cb to 520a880 Compare October 30, 2026 16:28
@github-actions

Copy link
Copy Markdown

AI review (no-findings)

Looking at each changed file for concrete defects:

crates/rustev-contract/src/serve.rs

The ExplainEvidence untagged enum comment correctly notes that deny_unknown_fields must be on each arm's struct, not the outer enum, and each arm carries it. The ordering — Record first, Bundle second — is safe: RecordEvidence requires record, so a pure-bundle object fails it (the bundle field is unknown under deny_unknown_fields) and falls through to BundleEvidence.

ExplainOptions carries deny_unknown_fields and both fields use the present deserializer, consistent with the same pattern on plan in RecordEvidence. The test coverage of explicit-null rejection confirms the intent.

EXPLANATION_LIMITS sets max_string_bytes: 16 * MIB = 16,777,216 bytes; markdown: Text<0, 16777216> caps at the same value. Consistent.

ServeExplain uses SERVICE_LIMITS (request bound) and ServeExplanation uses EXPLANATION_LIMITS (answer bound). That matches "an explanation is bounded as a replay bundle is."

crates/rustev-contract/src/schema_emit.rs

The two new emit::<> entries are inserted between ServeEvaluate and ServeReadiness, consistent with the ordering in operation_table().

crates/rustev-contract/tests/042_serve_documents.rs

The explanation() fixture path (../../rustev-cli/tests/golden/explain/backend-changed.explanation.json relative to crates/rustev-contract/tests/) resolves to crates/rustev-cli/tests/golden/explain/backend-changed.explanation.json, which appears in REPO CONTEXT. The round-trip contract and the explain_requests_take_either_evidence_form_and_name_their_bundle_sides test cover both evidence arms, the bundle-detection helper, unknown-field rejection, mixed-arm rejection, and explicit-null rejection.

integrations/rustev-serve/proto/rustev/serve/v1/serve.proto and generated .rs

The operation comment on Explain is updated to reflect the new request and response schemas and "response_format":"document". The SHA-256 in the generated file header is updated to match the new proto content. No structural change to the gRPC method signatures (still Document → Document).

specs/042-decision-service-and-remote-seams/spec.md

The increment note accurately describes the new types, limits, test references, and the "handler still answers unavailable" interim state. The spec is approved; the increment note is an additive prose block under the existing approved text, which is the established pattern for this spec.

No concrete defects found.

{"head": "520a880900eed87345069a9ac3d8587516172c0d", "verdict": "no-findings", "findings": []}

Subject: b258132...520a880, diff digest f3255003c2754e6762c830ab83fe9a0e6cfa45167d746f55ed1b1353f948040d, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus added this pull request to the merge queue Oct 30, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Oct 30, 2026
@bartekus
bartekus force-pushed the impl/042-explain-contract branch from 520a880 to 17f4e76 Compare October 30, 2026 18:21
@github-actions

Copy link
Copy Markdown

AI review (no-findings)

I'll review each changed file systematically.

crates/rustev-contract/src/serve.rs

The core addition. Key points:

  • ExplainEvidence is #[serde(untagged)] over RecordEvidence and BundleEvidence, each with #[serde(deny_unknown_fields)]. The comment correctly notes that serde ignores deny_unknown_fields on the untagged enum itself but respects it on each variant struct. Ordering is correct: a {"bundle":…} object fails RecordEvidence (bundle is an unknown field) and falls through to BundleEvidence.

  • ExplainQuery is likewise untagged over DiffQuery (which has deny_unknown_fields) and Query. A {"diff":{"other":…,"extra":1}} object fails at DiffOther's deny_unknown_fields, then fails Query's string parser, producing an error — consistent with the test assertion.

  • ExplainOptions with deny_unknown_fields and both fields optional correctly accepts {} (used in the round-trip test).

  • EXPLANATION_LIMITS sets max_bytes: 33 * MIB, max_string_bytes: 16 * MIB. The markdown bound Text<0, 16777216> matches max_string_bytes exactly. Consistent with the spec claim "bounded as a replay bundle is."

  • ServeExplain::has_bundle() correctly handles both the primary evidence side and the diff's other side.

crates/rustev-contract/src/schema_emit.rs

The two new schemas are inserted in the right position. No issues.

crates/rustev-contract/tests/042_serve_documents.rs

Tests cover: both evidence forms in the round-trip, has_bundle() for all three bundle-containing combinations, mixed-field rejection, missing-required-field rejection, unknown-field-in-diff rejection, explicit-null rejection for optional fields, and unknown query string rejection. Coverage is adequate for the contract.

integrations/rustev-serve/proto/rustev/serve/v1/serve.proto

The operation comment on Explain is updated to request_schema: {"some":"rustev.serve-explain/1"}, response_schemas: ["rustev.serve-explanation/1"], response_format: "document". Consistent with the Rust-side change.

integrations/rustev-serve/src/generated/rustev.serve.v1.rs

SHA-256 and operation comment updated to match the new proto. This is a generated file; the digest update confirms consistency.

specs/042-decision-service-and-remote-seams/spec.md

The increment is documented as "Increment 6 part 1: explanation documents (2026-10-30)." The spec correctly notes the handler is not yet implemented and the service still returns unavailable for explain. The spec frontmatter is not changed in the diff (no lifecycle field change visible), consistent with an in-progress approved spec adding an increment.

No concrete defects found across any of the changed paths.

{"head": "17f4e764271bc418fae9566e025fd89f7b0df2e7", "verdict": "no-findings", "findings": []}

Subject: 8e4dec0...17f4e76, diff digest bcc6b22057aa067b0822f141bdbf1d49371c93c8443522a3226cd665da35ed7c, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus added this pull request to the merge queue Oct 30, 2026
Merged via the queue into main with commit 23ab2dd Oct 30, 2026
30 checks passed
@bartekus
bartekus deleted the impl/042-explain-contract branch October 30, 2026 19:19
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