Skip to content

impl(042): increment 1, remote context and sink contract documents - #176

Merged
bartekus merged 1 commit into
mainfrom
impl/042-remote-documents
Oct 23, 2026
Merged

bartekus merged 1 commit into
mainfrom
impl/042-remote-documents

Conversation

@bartekus

Copy link
Copy Markdown
Contributor

Spec 042 increment 1 (remote half): the rustev.remote-context/1 and rustev.remote-sink/1 documents in rustev-contract (3.10, 3.11) with emitted JSON Schemas. Spec 2.2 allows these before the rustev-serve binding record. Acquire and the describe source descriptor are held back until spec 036, as 3.10 states. Implementation record added; 042 moves to in-progress. Checks: cargo test -p rustev-contract, clippy -D warnings, fmt, make gate.

@bartekus
bartekus enabled auto-merge (squash) October 22, 2026 22:52
@github-actions

Copy link
Copy Markdown

AI review (no-findings)

I reviewed the PR carefully, examining the new remote_context.rs, remote_sink.rs, schema files, and tests.

validate_traceparent — indices 2, 35, 52 are correctly excluded from the hex-digit check because the surrounding || branches already enforce they are dashes (&b[..3] != b"00-", b[35] != b'-', b[52] != b'-'). The all-zeros rejections on trace-id (b[3..35]) and parent-id (b[36..52]) are correctly scoped. No issue.

valid_fetch_attempt — split_once("/context/") takes the first occurrence; ambiguous cases (e.g. "a/context/1/context/2") produce a non-digit n and are rejected. The decoded counter increments one per logical decoded byte (percent-encoded sequences count as one, decoding only %25, %2F, %2C; uppercase-only is a canonical-form restriction). The bound check (1..=MAX_HANDLE_BYTES).contains(&decoded) is consistent with the test assertions at 0, 256, and 257 bytes.

FetchResponse re-parses the nested snapshot — the envelope uses RECORD_V1 limits (larger depth/collection limits); the emitted schema's x-rustev-parse-limits reflects allow_fractional_numbers: true, consistent with a snapshot whose field values can include arbitrary JSON. The nested Snapshot::parse re-serialise-and-reparse enforces the snapshot's own stricter limits (no fractions in timestamps, etc.) as the comment states. No inconsistency.

InvalidationsResponse re-parses each Invalidation item — each nested object carries schema: "rustev.remote-context-invalidation/1", and Invalidation::parse validates this. The test at line 196 confirms a wrong inner schema string causes a parse error.

DeliverRequest validation — checks traceparent, parses the record bytes through RunRecord::parse, verifies schema and decision-id agree with the envelope, checks canonicality, and verifies the digest. This closes all the normalization and substitution attacks I looked for.

DELIVER_LIMITS — 32 * 1024 * 1024 = 33554432 and 24 * 1024 * 1024 = 25165824, matching the emitted schema exactly.

ContextCode / describe_mismatch — the deserializer correctly maps "describe_mismatch" → RemoteCode::IdentityMismatch and excludes IdentityMismatch from the reverse lookup, so "identity_mismatch" on the wire is rejected (tested at line 208).

Governance — spec 042 moves from pending to in-progress under approved, which the contract table permits as a schedulable work-order state. The implementation-record section addition is consistent with the pattern of approved specs tracking partial delivery; it makes no premature acceptance claims.

No concrete defects found.

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

Subject: 57a3166...a4d7da2, diff digest d922e8012214a10aa447adb6b5aa4e611edf47905143e5483e23645597c2923d, 1 call(s). An AI comment is not an approval.

@github-actions

Copy link
Copy Markdown

AI review (findings)

Reviewing the PR for concrete defects: new remote_context.rs, remote_sink.rs, associated JSON schemas, tests, spec 042 update, and archive-policy addition.

Finding 1 — Derived artifact not regenerated with the spec edit

specs/042-decision-service-and-remote-seams/spec.md changes implementation: pending to implementation: in-progress in frontmatter. AGENTS.md states: "commit the shards with the spec edit that staled them." The corresponding registry artifact .statecraft/derived/spec-registry/by-spec/042-decision-service-and-remote-seams.json is absent from the changed paths. The spec edit stales the registry shard; the shard must accompany it.

Finding 2 — validate_traceparent emits the wrong error token

remote_context.rs line ~242: the error string is "invalid_trace_context" (with underscores), which silently deviates from the rest of the codebase's error surface and from the W3C Trace Context specification's identifier for this condition. This is not a blocking parse failure for callers but is a correctness defect in the diagnostic.

Finding 3 — Percent-encoding in valid_fetch_attempt is case-sensitive in a way that silently rejects valid IDs

remote_context.rs lines ~252-258: the match !matches!(&rest[1..3], b"25" | b"2F" | b"2C") accepts only uppercase hex digits in percent-encoded sequences. RFC 3986 §2.1 requires implementations to accept both cases (e.g. %2f and %2F are equivalent). A host that emits lowercase-encoded attempt IDs (e.g. decision%2fname/context/1) will be rejected by the parser without any diagnostic that indicates why, making the system silently incompatible with RFC-conforming clients.

{"head": "e9823e078c059ee19d688c7b6342d902f36b7ce3", "verdict": "findings", "findings": [{"path": "specs/042-decision-service-and-remote-seams/spec.md", "line": 4, "summary": "Frontmatter changes implementation status from pending to in-progress but the staled derived registry shard (.statecraft/derived/spec-registry/by-spec/042-decision-service-and-remote-seams.json) is not regenerated and committed alongside the spec edit, violating the AGENTS.md rule to commit shards with the spec edit that stales them."}, {"path": "crates/rustev-contract/src/remote_context.rs", "line": 242, "summary": "validate_traceparent returns Err(invalid(\"invalid_trace_context\")) with an underscore-delimited token that is inconsistent with surrounding error surface and makes the diagnostic harder to match programmatically."}, {"path": "crates/rustev-contract/src/remote_context.rs", "line": 257, "summary": "valid_fetch_attempt only accepts uppercase percent-encoded sequences (%2F, %2C, %25) and silently rejects RFC 3986-conforming lowercase equivalents (%2f, %2c, %25), causing valid attempt IDs from standards-compliant hosts to be rejected."}]}

Subject: 57a3166...e9823e0, diff digest ba53ad2a60b367327a9de43c6349e831751f0700c80799486fd54cbf68acd58c, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus had a problem deploying to statecraft-review-exception October 22, 2026 23:03 — with GitHub Actions Error
@github-actions

Copy link
Copy Markdown

AI review (no-findings)

I reviewed the diff carefully for bugs, security issues, and spec/governance inconsistencies.

Rust contract modules (remote_context.rs, remote_sink.rs)

  • validate_traceparent: length, separator positions (2, 35, 52), hex-only chars, version "00" enforcement, and all-zero trace/parent rejections are all correct.
  • valid_fetch_attempt: split_once("/context/") always splits at the first literal separator; raw / and , are rejected in the decision part; percent-encoding is case-sensitively accepted only for the three runtime-generated sequences (%25, %2F, %2C); decoded correctly counts decoded characters (not raw bytes). Bounds check is correct.
  • ContextCode (de)serialization: identity_mismatch is excluded from the lookup, describe_mismatch maps to RemoteCode::IdentityMismatch. Tests confirm the closed set.
  • Double-parse validations (FetchResponse, InvalidationsResponse, DeliverRequest) are correct: each inner document is re-serialised and parsed through its own parser so limits and schema checks apply independently.
  • DELIVER_LIMITS values (32 MB outer, 24 MB string) match the emitted schema.
  • FetchResponse uses RECORD_V1 (larger collection/depth limits) with an inner Snapshot::parse re-validation; the fractional-number prohibition comes from the inner parse, not the outer envelope. Consistent with the emitted schema.

Schema files — limits in x-rustev-parse-limits are consistent with the Rust constants.

TypeScript bindings — Generated by the existing emitter. The value field in Entry is typed as { [k: string]: unknown | undefined } (object map), but a snapshot entry value can be any JSON scalar or array. This matches the pre-existing generator behavior for serde_json::Value across the base file's snapshot types, so it is not a new defect introduced by this PR.

Spec 042 — implementation: pending → in-progress is correct for incremental delivery. The three new extends edges (031 for tools/rustev-release/, 027 twice for integrations/rustev-node/ and integrations/rustev-wasm/) cover every changed path outside rustev-contract.

Archive policy — remote_context.rs and remote_sink.rs correctly added.

No concrete new defects found.

{"head": "6263b227b10540f50a11666dcb34ea93837d7a11", "verdict": "no-findings", "findings": []}

Subject: 57a3166...6263b22, diff digest 27addc80e40d8067cca17cbd0cccc39eb0c78c1adf5369f458804b4ceb056bf2, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus force-pushed the impl/042-remote-documents branch from 6263b22 to 34f29ea Compare October 22, 2026 23:15
@github-actions

Copy link
Copy Markdown

AI review (no-findings)

I'll review the diff for bugs, security issues, and inconsistencies.

validate_traceparent (remote_context.rs)

The W3C traceparent validator checks: length 55, version prefix "00-", dash positions at 35 and 52, lowercase hex everywhere else, and non-zero trace-id/parent-id. The logic is correct — the [2, 35, 52].contains(&i) skip list aligns with the known dash positions; the outer per-field checks handle those positions before all() reaches them; slices b[3..35] and b[36..52] are safe because the length guard fires first.

valid_fetch_attempt (remote_context.rs)

split_once("/context/") correctly splits at the first separator; any literal / in the decision part is rejected by the b'/' | b',' arm, so a decision_id containing "/context/" can't smuggle a second separator. The decoded counter counts decoded bytes (each %XX → 1 byte), which is the right unit for MAX_HANDLE_BYTES. Overflow is not a concern given the bounded parser's max_string_bytes ceiling.

ContextCode serde symmetry

IdentityMismatch is excluded from deserialization and mapped to "describe_mismatch" in both directions; the JSON schema is emitted via json_schema_name() using the same mapping. The test confirms "identity_mismatch" and "denied" are both rejected, consistent with the schema enum.

FetchResponse double-parse

The outer parser uses RECORD_V1 (fractions allowed, larger collection/depth limits) so the envelope is scanned first. The check closure re-serialises the Snapshot and calls Snapshot::parse, which enforces stricter limits including allow_fractional_numbers: false. The test snapshot_parser_and_deferred_members_cannot_be_bypassed confirms 0.5 is caught at the inner parse. Correct.

InvalidationsResponse nested validation

Each embedded Invalidation is re-serialised and passed through Invalidation::parse, which checks the schema string. The test with i["schema"] = "wrong" confirms the guard fires.

DeliverRequest validation

Checks schema/decision_id agreement between envelope and record, canonical form, and digest match. The DELIVER_LIMITS constant (32 MiB / 24 MiB string) is self-consistent with the emitted schema (max_bytes: 33554432, max_string_bytes: 25165824).

validate_digest on DeliverResponse

The match correctly pattern-guards on accepted_digest != sent for both Accepted and Duplicate; Conflict and Rejected are passed through. No logic error.

Governance

Spec 042 advances from pending to in-progress, which is the correct lifecycle transition. The three new extends entries claim additive territory over spec 031's tools/rustev-release/ and spec 027's two binding directories — consistent with the files changed (archive-policy.json, node/wasm .d.ts). The implementation record is accurate about what is and isn't delivered (acquire documents and source descriptor held back, extension-point comments present).

TypeScript declarations

Both .d.ts files are identical; all 14 new namespaces align with the Rust types. Alphabetical ordering in the file is maintained.

No concrete defects found.

{"head": "34f29ea7d48eef543936f6e1238260e899dadff3", "verdict": "no-findings", "findings": []}

Subject: 64a2d50...34f29ea, diff digest 27addc80e40d8067cca17cbd0cccc39eb0c78c1adf5369f458804b4ceb056bf2, 1 call(s). An AI comment is not an approval.

@github-actions

Copy link
Copy Markdown

AI review (findings)

Reviewing the PR, which introduces rustev-contract document types for spec 042's remote context and sink protocols.

Rust implementation (remote_context.rs, remote_sink.rs)

The double-layer validation pattern is sound: outer documents parsed with bounded limits, embedded documents (snapshots in FetchResponse, invalidation items in InvalidationsResponse) re-serialized and re-parsed against their own parsers. The ContextCode remapping (identity_mismatch → describe_mismatch) is correctly symmetric in both directions and exercised by tests.

validate_traceparent correctly checks version, dash positions, hex-only content, all-zero trace-id, and all-zero parent-id. valid_fetch_attempt correctly counts decoded bytes (not encoded bytes) against MAX_HANDLE_BYTES.

Concrete defect: TypeScript Entry.value is over-constrained

In both TypeScript binding files, the Entry interface inside RustevRemoteContextFetch1Response declares:

value: {
  [k: string]: unknown | undefined;
};

This types value as an object with string keys. But the spec and Rust code are explicit that value is "decoded strictly against the input's declared type," which includes bool, integer, decimal, timestamp, text, enum variants, and list — all of which are primitives or arrays, not JSON objects. Only a record-typed field would produce an object. Any consumer assigning or narrowing entry.value to a primitive type will get a TypeScript type error. The correct type for an unconstrained JSON value is unknown.

This same incorrect type appears identically in both files (they are identical diffs).

Spec / governance

The implementation: pending → in-progress transition is appropriate for incremental delivery. The three new extends entries correctly claim the directories this PR touches. The implementation record is clearly scoped and does not pre-claim undelivered acceptance items.

Archive policy

src/remote_context.rs and src/remote_sink.rs are correctly added to tools/rustev-release/archive-policy.json.

{
  "head": "16444d583df1088678a0221c2be9c3cf7bd862e8",
  "verdict": "findings",
  "findings": [
    {
      "path": "integrations/rustev-node/types/rustev-documents.d.ts",
      "line": null,
      "summary": "RustevRemoteContextFetch1Response.Entry.value is typed as an object index signature ({ [k: string]: unknown }), but context entry values can be any JSON type (bool, integer, string, list, etc.); the correct type is `unknown`."
    },
    {
      "path": "integrations/rustev-wasm/types/rustev-documents.d.ts",
      "line": null,
      "summary": "Same incorrect over-constrained object type for RustevRemoteContextFetch1Response.Entry.value as in the node bindings."
    }
  ]
}

Subject: 503a72e...16444d5, diff digest 27addc80e40d8067cca17cbd0cccc39eb0c78c1adf5369f458804b4ceb056bf2, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus had a problem deploying to statecraft-review-exception October 22, 2026 23:53 — with GitHub Actions Error
@bartekus
bartekus force-pushed the impl/042-remote-documents branch from 16444d5 to 084fb73 Compare October 22, 2026 23:54
@github-actions

Copy link
Copy Markdown

AI review (no-findings)

Reviewing the PR, which adds new remote contract documents for spec 042: the rustev.remote-context/1 and rustev.remote-sink/1 protocol types, their JSON Schemas, TypeScript type declarations, and associated tests.

Spec governance: The implementation advance from pending to in-progress is valid per the contract's lifecycle table (approved + in-progress is schedulable). The new extends entries cover all changed paths outside crates/rustev-contract/ (tools/rustev-release, integrations/rustev-node, integrations/rustev-wasm, tools/rustev-conformance).

Schema and limits consistency: DELIVER_LIMITS (max_bytes = 32 MiB, max_string_bytes = 24 MiB) matches the emitted x-rustev-parse-limits in the deliver-request schema. The FetchResponse uses RECORD_V1 limits (larger collection and depth bounds than REMOTE_V1) to accommodate embedded snapshot entries, and the schema annotation reflects those same values. The ExchangeRecord uses tighter EXCHANGE_V1 limits; these are all tested by every_declared_scan_limit_at_and_one_past.

Security boundaries: The DeliverRequest validator enforces canonical form, digest match, and schema/decision-id consistency before accepting the record. The FetchRequest and Invalidation parsers validate WirePrincipal.is_canonical(). The ContextCode wrapper correctly rejects identity_mismatch (renamed to describe_mismatch) and any unlisted code. The governance principle (proposals never grants, no Permitted type) is respected throughout.

Traceparent validation: The length, separator positions, all-hex requirement, all-zero trace-id, and all-zero span-id checks are correct and match W3C Trace Context format. Tests cover both the happy path and key rejection cases.

valid_fetch_attempt: Correctly counts decoded characters (all percent-encoded sequences map to single-byte ASCII, so decoded character count equals byte count), and the range check (1..=MAX_HANDLE_BYTES).contains(&decoded) matches the Handle type's 1–256 byte bound.

TypeScript type generation: The anyValue function correctly identifies members whose schema carries only annotation-only keys (description, title, $comment) and injects tsType: 'unknown', fixing the previous incorrect {[k: string]: unknown} typing for value fields in snapshot entries.

checked_document! macro reuse: The macro uses fully qualified crate:: paths, so sharing it between remote_context and remote_sink via pub(crate) use is safe.

No concrete defects found.

{"head": "084fb73e979e8c1012cad30e81e06f3650f9f8be", "verdict": "no-findings", "findings": []}

Subject: 503a72e...084fb73, diff digest 71a44dbd852e508526a6f98eb4f6753105a813ad92ad75f2e23e8f900f3bec1e, 1 call(s). An AI comment is not an approval.

@github-actions

Copy link
Copy Markdown

AI review (no-findings)

Reviewing the PR diff carefully across all changed paths.

crates/rustev-contract/src/remote_context.rs

validate_traceparent is correct. The length check (55), the prefix and separator checks, the all-lowercase-hex all() scan (positions 2, 35, 52 excluded from hex validation and covered by the earlier literal checks), and the all-zero rejections for trace-id and parent-id all look consistent. The test exercises all those branches.

valid_fetch_attempt correctly uses split_once("/context/") as the first occurrence. Because the decision part rejects unescaped / (returning false on b'/'), any literal /context/ sequence in the decision would have been encoded as %2Fcontext%2F and would not produce a spurious split point. The numeric suffix validation (starts_with('0') rejection covers both zero and zero-padded values) is correct and tested.

The double-parse pattern in FetchResponse (re-serialise the snapshot and parse it under Snapshot::parse) and in InvalidationsResponse (re-parse each embedded invalidation) is intentional and consistent with the existing codebase approach.

crates/rustev-contract/src/remote_sink.rs

DeliverRequest chains parse → schema/decision-id match → canonicality → digest, giving a complete integrity check. The DELIVER_LIMITS (32 MB outer, 24 MB string) match the emitted schema (max_bytes: 33554432, max_string_bytes: 25165824). validate_digest uses a correct if guard pattern to check both Accepted and Duplicate arms.

ContextCode / describe_mismatch mapping

The renaming of IdentityMismatch to describe_mismatch on the wire (serialiser/deserialiser and the JsonSchema impl) is internally consistent; identity_mismatch is rejected on input (tested in nested_documents_and_closed_variants_are_checked).

tools/rustev-conformance/js/gen-types.mjs

The anyValue / annotationOnly logic correctly identifies a member schema consisting solely of description, title, or $comment keys and injects tsType: 'unknown', fixing the incorrect { [k: string]: unknown } for snapshot value. The fix propagates correctly to both node and wasm .d.ts files for RustevSnapshot1 and RustevSnapshot2.

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

The lifecycle transition from pending to in-progress is valid per the contract's scheduling table. The new extends entries for tools/rustev-release/, integrations/rustev-node/, integrations/rustev-wasm/, and tools/rustev-conformance/ match the paths actually modified in this PR. The implementation record makes no acceptance-item claims.

Schema / archive-policy consistency

archive-policy.json adds remote_context.rs and remote_sink.rs consistent with the new source files. Schema files are named to match document_schemas() output ordering.

No concrete defects found.

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

Subject: efc1da9...c698af2, diff digest 71a44dbd852e508526a6f98eb4f6753105a813ad92ad75f2e23e8f900f3bec1e, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus merged commit 3119423 into main Oct 23, 2026
31 checks passed
@bartekus
bartekus deleted the impl/042-remote-documents branch October 23, 2026 00:32
bartekus added a commit that referenced this pull request Oct 23, 2026
Spec 042 increment 1 (serve half), stacked on #176: `rustev.serve/1`
with its operation table and every `rustev.serve-*/1` document, plus
`rustev.plan-bundle/1`, `rustev.plan-bundle-signature/1` and
`rustev.plan-registration/1`, with emitted schemas and regenerated
binding declarations (the `.d.ts` growth is generated: serve envelopes
inline the run record and judgment types). Embedded evidence is carried
as original bytes (`serde_json` `raw_value` feature; no new dependency).
Items that depend on 034 or 036 are held back with extension points.
Bounds the spec leaves unstated are recorded as engineering choices in
the implementation record. Checks: `cargo test -p rustev-contract`,
clippy, fmt, `make gate`, couple, gen-types --check.
bartekus added a commit that referenced this pull request Oct 23, 2026
Amends the spec 010 section 3.4 `rustev-serve` binding record, stacked
on #180.

- Item 2 (schemas): refuse -> pass. Spec 042's documents now exist in
`rustev-contract` (#176, #180) with bounds, emitted schemas and negative
fixtures.
- Sigstore row: unverified -> pass. `sigstore-verify` 0.15.0 with
`default-features = false, features = ["aws-lc-rs"]` verifies a v0.3
bundle offline against a host-supplied trusted root, with no HTTP
client, tokio or TUF in its tree (checked with `cargo tree`). Crypto is
`aws-lc-rs` 1.18.2, which needs a C compiler and CMake at build time.

This is the owner's review act under 3.4 (R-44): implementation of
`rustev-serve` waits for the owner's approval of this text, which will
be recorded as a dated decision.
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