From 6c7f0323d01e3c62e77a4ae578cc55526e309cfd Mon Sep 17 00:00:00 2001 From: Nimrod Busany Date: Fri, 27 Nov 2026 22:07:59 +0200 Subject: [PATCH] fix(contract): compliance freshness tokens are optional until the server issues them This relaxes a requirement: review_context on attestation evidence rows and on the sign request becomes optional until the server issues and checks freshness tokens. Co-Authored-By: Claude Sonnet 5.5 --- .../compliance-evidence-contracts.breaking.md | 1 - ...ompliance-review-context-optional.changed.md | 1 + parity/python-js-sdk.json | 2 +- scripts/breaking_schema_allowlist.json | 17 +++++++++++++++++ tests/test_compliance_attestation_contract.py | 7 ++++++- tests/test_compliance_evidence_contract.py | 16 +++++++++++++++- .../compliance_attestation_endpoints.json | 4 ++-- .../compliance_attestation_schema.json | 5 ++--- .../compliance_evidence_response_schema.json | 6 +----- 9 files changed, 45 insertions(+), 14 deletions(-) create mode 100644 changelog.d/compliance-review-context-optional.changed.md diff --git a/changelog.d/compliance-evidence-contracts.breaking.md b/changelog.d/compliance-evidence-contracts.breaking.md index 3bb0e1c3..588359f0 100644 --- a/changelog.d/compliance-evidence-contracts.breaking.md +++ b/changelog.d/compliance-evidence-contracts.breaking.md @@ -1,3 +1,2 @@ - **A `not_applicable` applicability decision requires a rationale.** `DecisionInput` gains an if/then: when `decision` is `not_applicable`, `rationale` is required and must hold at least one character that is not whitespace, a control character or a zero-width/format character (the 2000-character cap is unchanged). `applicable` and `unresolved` keep it optional, and a `carry: true` item is not re-validated. The Backend refuses the violation with a closed 400 `rationale_required` (new closed body `RationaleRequiredError`, declared beside the shared error envelope on the write's 400, acknowledged in `scripts/breaking_schema_allowlist.json`). -- **Compliance attestation signing is bound to the reviewed subject.** `AttestationCreateRequest` gains a REQUIRED `review_context` (64 lowercase hex): the opaque, server-issued, keyed freshness token the signer read from the evidence response (new `Ingredient.review_context`, required on `A` rows as a string or null, absent on other kinds). A stale value is refused with 409 `stale_review_context` and nothing is recorded; the sign operation also declares a 503 for when the server cannot issue or verify the token. The token is never derived from customer text and is not evidence: never store, log or export it. Acknowledged in `scripts/breaking_schema_allowlist.json`. - **Compliance document references: search by link substring (additive; contract only).** New operation `POST /api/v1/projects/{project_id}/agents/{agent_ref}/compliance-document-refs/search` (`project_compliance_document_refs.search_compliance_document_references`, `x-replay: read`) and closed request `DocumentReferenceSearchRequest` (`q` 1 to 200 characters after trimming, optional `include_withdrawn`, `page`, `per_page`). It is a read served as POST so the search text, which is customer content, stays out of URLs, logs and traces; it matches case-insensitively, as a literal substring, against the declared link and answers the existing `DocumentReferenceListResponse` with the list's ordering and paging. Pinned by `tests/test_compliance_document_ref_contract.py`. diff --git a/changelog.d/compliance-review-context-optional.changed.md b/changelog.d/compliance-review-context-optional.changed.md new file mode 100644 index 00000000..bc1aff7b --- /dev/null +++ b/changelog.d/compliance-review-context-optional.changed.md @@ -0,0 +1 @@ +- Compliance freshness tokens are optional until the server issues and checks them: `Ingredient.review_context` may be present on `A` rows and `AttestationCreateRequest.review_context` may be omitted; the closed rules for kinds M, D and L are unchanged. diff --git a/parity/python-js-sdk.json b/parity/python-js-sdk.json index e6100078..cbcb4a32 100644 --- a/parity/python-js-sdk.json +++ b/parity/python-js-sdk.json @@ -399,7 +399,7 @@ "sdk032Surface": "Manifest Python pin advanced from d56e4353 to 6e8e4a54 (origin/develop, the SDK 0.32.0 release candidate) to cover two root exports the js-public-parity gate flagged unclassified on Traigent/Traigent#2861. requirement (traigent.runtime.decorator) is the runtime latency requirement decorator; traigent-js origin/main and origin/develop both export requirement from src/runtime/index.ts and list it in tests/integration/fixtures/api-surface.snapshot.json, so it is classified matched and added to requiredRootExports next to require. SnapshotBindingError (traigent.utils.exceptions) is the typed error of the Python opt-in snapshot store (S0 before dispatch, S1 from the terminal result, online G1); traigent-js has no snapshot store and no export of it (zero occurrences in src or its api-surface snapshot), so it is classified deferred-backlog, Python-only for now with no open JS design and no ticket. Owner may re-bucket." }, "schemaRefresh": { - "lastSchemaFileSha": "b67ecd143e25de91c4347af09316c5c178e0fb24f0f3943ffe16033fb9601d9c", + "lastSchemaFileSha": "52d2225ee443c2d4d5c3fdc6456503157815834929211813e1e27b4d65153a0b", "schemaFileCount": 692, "note": "Auto-stamped by scripts/refresh_parity.py. Do not hand-edit this block." } diff --git a/scripts/breaking_schema_allowlist.json b/scripts/breaking_schema_allowlist.json index 3bb850a1..4ae9afda 100644 --- a/scripts/breaking_schema_allowlist.json +++ b/scripts/breaking_schema_allowlist.json @@ -12039,6 +12039,23 @@ "reason": "A rows of the evidence response gain the review_context freshness token (string or null), a closed additive field that the signer echoes on sign. Pre-release contract; the backend is the only producer and the frontend reads it in the same slice.", "version": "Unreleased pending (TraigentSchema, review_context; backend change pending)", "pr": "pending (TraigentSchema, not yet opened)" + }, + { + "file": "agent_readiness/compliance_evidence_response_schema.json", + "rule": "allOf_branch_count_changed", + "findings": [ + { + "pointer": "#/properties/ingredients/items/allOf", + "role": "response", + "subject": "allOf", + "old": 2, + "new": 1, + "fingerprint": "9ffc86621dadac8da734bd4e02ebee79dcaeec95861a11c317bd6670d5fc202c" + } + ], + "reason": "Freshness tokens become optional until the server issues and checks them; the closed rules for kinds M, D and L are unchanged; readers treat an absent value like null.", + "version": "Unreleased pending (TraigentSchema, review_context optional)", + "pr": "pending (TraigentSchema, not yet opened)" } ] } diff --git a/tests/test_compliance_attestation_contract.py b/tests/test_compliance_attestation_contract.py index 3b2583c3..1db3efcb 100644 --- a/tests/test_compliance_attestation_contract.py +++ b/tests/test_compliance_attestation_contract.py @@ -112,6 +112,12 @@ def test_schema_is_valid_draft7_and_discoverable() -> None: Draft7Validator.check_schema(_SCHEMA) +def test_review_context_is_optional_on_the_sign_request() -> None: + request = _request() + request.pop("review_context") + assert _errors("AttestationCreateRequest", request) == [] + + def test_schema_is_closed_everywhere() -> None: _walk_closed(_SCHEMA) _walk_closed(load_json(ENDPOINTS_PATH)["paths"]) @@ -152,7 +158,6 @@ def test_valid_examples_conform(definition: str, factory: Any) -> None: ("definition", "factory", "mutate"), [ # Server-derived fields are never accepted from the client. - ("AttestationCreateRequest", _request, lambda r: r.pop("review_context")), ("AttestationCreateRequest", _request, lambda r: r.update(review_context=None)), ("AttestationCreateRequest", _request, lambda r: r.update(review_context="C" * 64)), ("AttestationCreateRequest", _request, lambda r: r.update(review_context="c" * 63)), diff --git a/tests/test_compliance_evidence_contract.py b/tests/test_compliance_evidence_contract.py index c4f09e0e..814bff3f 100644 --- a/tests/test_compliance_evidence_contract.py +++ b/tests/test_compliance_evidence_contract.py @@ -157,7 +157,6 @@ def test_valid_populated_and_empty_packs() -> None: lambda r: r["ingredients"][0].update(group="Legal"), lambda r: r["ingredients"][0].update(producer_ref="free text"), lambda r: r["ingredients"][0].update(note="customer text"), - lambda r: r["ingredients"][1].pop("review_context"), # required on A rows lambda r: r["ingredients"][1].update(review_context="B" * 64), lambda r: r["ingredients"][1].update(review_context="b" * 63), lambda r: r["ingredients"][0].update(review_context="b" * 64), # absent on non-A rows @@ -336,6 +335,21 @@ def test_coverage_ingredient_ids_over_cap_is_rejected_shape_only() -> None: assert _errors(_with_ids(**{**_ALL_EMPTY, "supported": unique})) != [] +@pytest.mark.parametrize("kind", ["M", "D", "L"]) +def test_review_context_is_refused_on_non_attestation_rows(kind: str) -> None: + instance = copy.deepcopy(_response()) + instance["ingredients"][0]["kind"] = kind + assert _errors(instance) == [] + instance["ingredients"][0]["review_context"] = "b" * 64 + assert _errors(instance) != [] + + +def test_review_context_is_optional_on_attestation_rows() -> None: + instance = copy.deepcopy(_response()) + instance["ingredients"][1].pop("review_context") + assert _errors(instance) == [] + + def test_review_context_is_a_digest_or_null_on_attestation_rows() -> None: instance = copy.deepcopy(_response()) assert _errors(instance) == [] diff --git a/traigent_schema/schemas/agent_readiness/compliance_attestation_endpoints.json b/traigent_schema/schemas/agent_readiness/compliance_attestation_endpoints.json index 8cd24195..774339ee 100644 --- a/traigent_schema/schemas/agent_readiness/compliance_attestation_endpoints.json +++ b/traigent_schema/schemas/agent_readiness/compliance_attestation_endpoints.json @@ -449,7 +449,7 @@ } }, "409": { - "description": "Conflict", + "description": "Conflict (stale_review_context applies when the server checks freshness tokens)", "content": { "application/json": { "schema": { @@ -511,7 +511,7 @@ } }, "503": { - "description": "The server cannot issue or verify the review context right now; nothing is recorded", + "description": "When the server checks freshness tokens and its key is unavailable: the server cannot issue or verify the review context right now; nothing is recorded", "content": { "application/json": { "schema": { diff --git a/traigent_schema/schemas/agent_readiness/compliance_attestation_schema.json b/traigent_schema/schemas/agent_readiness/compliance_attestation_schema.json index 14eb1cec..10a114c6 100644 --- a/traigent_schema/schemas/agent_readiness/compliance_attestation_schema.json +++ b/traigent_schema/schemas/agent_readiness/compliance_attestation_schema.json @@ -329,8 +329,7 @@ "ingredient_id", "statement_digest", "outcome", - "review_period_days", - "review_context" + "review_period_days" ], "properties": { "agent_id": { @@ -346,7 +345,7 @@ "review_context": { "type": "string", "pattern": "^[0-9a-f]{64}$", - "description": "Echo the review_context of the evidence read the signer reviewed. A stale value is refused with 409 stale_review_context and nothing is recorded. Opaque, server-issued and never derived from customer text." + "description": "Send back only a string token read from the evidence view; omit the field when the row has none or null. When the server checks freshness tokens, it refuses a stale value with 409 stale_review_context. Opaque and server-issued." }, "outcome": { "$ref": "#/definitions/Outcome" diff --git a/traigent_schema/schemas/agent_readiness/compliance_evidence_response_schema.json b/traigent_schema/schemas/agent_readiness/compliance_evidence_response_schema.json index 1d5f2630..fe260ace 100644 --- a/traigent_schema/schemas/agent_readiness/compliance_evidence_response_schema.json +++ b/traigent_schema/schemas/agent_readiness/compliance_evidence_response_schema.json @@ -210,14 +210,10 @@ "review_context": { "type": ["string", "null"], "pattern": "^[0-9a-f]{64}$", - "description": "Present on an `A` ingredient only (a string, or null when the agent configuration or the statement cannot be resolved, or the server has no key to issue it). An opaque, server-issued freshness token, keyed and never derived from customer text. A signer echoes it unchanged in AttestationCreateRequest.review_context; the server refuses a stale value with 409 stale_review_context. It is not evidence: never store, log or export it." + "description": "Present on an `A` ingredient when the server issues freshness tokens; absent or null otherwise (readers treat both alike). When the server checks freshness tokens, a stale value sent back on signing is refused with 409 stale_review_context. An opaque, server-issued, keyed token, never derived from free text. It is not evidence: never store, log or export it." } }, "allOf": [ - { - "if": { "properties": { "kind": { "const": "A" } }, "required": ["kind"] }, - "then": { "required": ["review_context"] } - }, { "if": { "properties": { "kind": { "enum": ["M", "D", "L"] } }, "required": ["kind"] }, "then": { "not": { "required": ["review_context"] } }