From ec59dd008b547b438063c48bca0d3406e1b1fc98 Mon Sep 17 00:00:00 2001 From: Nimrod Busany Date: Thu, 19 Nov 2026 02:32:41 +0200 Subject: [PATCH 1/4] feat(agent-readiness): search compliance document references by URL substring (AGB-79 B2b) Adds POST .../compliance-document-refs/agents/{agent_id}/search (searchComplianceDocumentReferences, x-replay: read) and the closed DocumentReferenceSearchRequest. The search text is customer content, so it travels in the body only; the response is the existing list response. Spine-Trail: st_f6fb29f7a817 Co-Authored-By: Claude Sonnet --- CHANGELOG.md | 1 + parity/python-js-sdk.json | 2 +- .../test_compliance_document_ref_contract.py | 34 ++++++ .../compliance_document_ref_endpoints.json | 102 ++++++++++++++++++ .../compliance_document_ref_schema.json | 30 ++++++ 5 files changed, 168 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 57c913fe..55ed37b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added +- **Compliance document references: search by link substring (AGB-79 B2b; additive; contract only).** New operation `POST /api/v1beta/projects/{project_id}/compliance-document-refs/agents/{agent_id}/search` (`searchComplianceDocumentReferences`, `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. Marked `x-asserted-against-backend: false` until the Backend merges. Pinned by `tests/test_compliance_document_ref_contract.py`. - **BREAKING (pre-release). Agent readiness and production satellites: project-level `/api/v1` contract (API revision Phase 3).** The agent readiness module moves from `/api/v1beta/projects/{project_id}/agent-readiness[/{agent_id}]` and `/agent-compliance-evidence/{agent_id}` to `/api/v1/projects/{project_id}/agent-readiness/search` (POST; the former list query is now the request body, marked `x-replay: read`) and the per-agent routes `/agents/{agent_ref}/readiness`, `/lifecycle-history`, `/target-revisions`, `/posture-revisions` and `/compliance-evidence`. The reactive policy read keeps its path but renames `agent_id` to `agent_ref`. All operationIds become the backend operation ids (`project_agent_readiness.get_agent_readiness`, ...). New: `GET .../agents/{agent_ref}/next-step` (`agent_next_step_response_schema.json`) and `.../production-status` and `.../production-breaches` (`production_requirements/production_breaches_endpoints.json`, `production_status_response_schema.json`). `x-replay` joins the extension vocabulary. Response shapes of the moved operations are unchanged; the fleet-posture route stays out of the public schema. - **Backend API revision Phase 2 contract declarations (additive new schemas; descriptions corrected).** New `global_error_schema.json` declares the catch-all handler's closed body `{success, error, code}` (no `message`, `code` rather than `error_code`, never a request id) and is referenced by the 500 of the three guidance operations; `error_envelope_schema.json` is unchanged apart from a pointer in its description, so 4xx consumers are unaffected. New `validation_error_loc_type_schema.json` declares the closed `{loc, type}` validation list (error_code `VALIDATION_ERROR` on the guidance session routes) for the guidance 400s. New `agents/agent_conflict_error_schema.json` (409 on agent create and delete, with the server-built `archive_url_template` and `can_archive`), `agents/agent_import_validation_error_schema.json` (import 400 with closed `{index, code}` entries; `IMPORT_TOO_LARGE` is a 400, not a 413) and `agents/agent_import_credential_error_schema.json` (closed 400 `provider_credential_not_accepted`). New `projects/write_scope_error_schema.json` declares the 422 `PROJECT_CONTEXT_REQUIRED` body for a write with no explicit project, referenced from `POST /api/v1/agents`, `POST /api/v1/agents/import` and the two guidance session writes. `PROJECT_CONTEXT_REQUIRED_FOR_WRITE` is deliberately not added to `project_context_error_schema.json`: the backend raises it only as an internal 500 fault, never as a client 422. Package version unchanged until a release is cut. - **Crew domain contract: new `crew/` schema domain (additive; contract only; no existing schema changed).** Thirty JSON Schema documents plus `crew/crew_endpoints.json` (registered in `mep_endpoints.json` as "Crews") and `crew/README.md`. A crew is a named set of agents that cooperate on one job. Covers crews, immutable revisions, roles with opaque server-issued `role_token`s (`rtk_` + 26 lowercase base32 characters), role bindings, membership proposals (list, accept, dismiss) and the execution shapes later work will fill in (crew runs, member executions, handoffs, trial allocations). Adds the optional session-create declaration `crew_declaration` (`crew_key`, `role_key`) and the `crew_binding` result with the closed statuses `bound`, `pending_portal`, `conflict`, `disabled`, `unknown`. Customer-chosen labels (`crew_key`, `name`, `description`, `role_key`) carry `x-content` and `user_content`; telemetry and error bodies carry only opaque identifiers, counts and closed enums; errors use closed codes with fixed messages and never echo client values. `unit_ref` must be null on bindings in this version. Routes are declared under `/api/v1beta/projects/{project_id}/crews` and marked `x-asserted-against-backend: false` until the Backend implements them. Parity capability registry, parity manifest and reachability report updated; pinned by `tests/test_crew_contract.py`. Package version unchanged until a release is cut. diff --git a/parity/python-js-sdk.json b/parity/python-js-sdk.json index 30794173..40695fbc 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": "f95c44488657e55e2328b68508436c2b03c46f25eb96000ea41e1e4d1c9728ee", + "lastSchemaFileSha": "b06de8b365093203d63c1b5d52285b481666fb8e47bb9ae4f2521f73e7fb9b0a", "schemaFileCount": 617, "note": "Auto-stamped by scripts/refresh_parity.py. Do not hand-edit this block." } diff --git a/tests/test_compliance_document_ref_contract.py b/tests/test_compliance_document_ref_contract.py index ef9e19a4..6b4aeb8d 100644 --- a/tests/test_compliance_document_ref_contract.py +++ b/tests/test_compliance_document_ref_contract.py @@ -277,8 +277,42 @@ def test_endpoints_are_registered_and_wired() -> None: base, base + "/{reference_id}/withdrawals", base + "/agents/{agent_id}", + base + "/agents/{agent_id}/search", } for item in paths.values(): for operation in item.values(): assert operation["x-asserted-against-backend"] is False assert "429" in operation["responses"] + + +def test_search_is_a_body_only_read_with_a_closed_request() -> None: + base = "/api/v1beta/projects/{project_id}/compliance-document-refs/agents/{agent_id}" + paths = load_json(ENDPOINTS_PATH)["paths"] + assert set(paths[base + "/search"]) == {"post"} + operation = paths[base + "/search"]["post"] + assert operation["operationId"] == "searchComplianceDocumentReferences" + assert operation["x-replay"] == "read" + assert [p["in"] for p in operation["parameters"]] == ["path", "path"] + request_ref = operation["requestBody"]["content"]["application/json"]["schema"]["$ref"] + assert request_ref.endswith("#/definitions/DocumentReferenceSearchRequest") + ok = operation["responses"]["200"]["content"]["application/json"]["schema"]["$ref"] + assert ok == paths[base]["get"]["responses"]["200"]["content"]["application/json"]["schema"][ + "$ref" + ] + assert {"400", "401", "403", "404", "429"} <= set(operation["responses"]) + for valid in ( + {"q": "tech"}, + {"q": "x" * 200, "include_withdrawn": True, "page": 3, "per_page": 100}, + ): + assert _errors("DocumentReferenceSearchRequest", valid) == [] + for invalid in ( + {}, + {"q": ""}, + {"q": "x" * 201}, + {"q": 5}, + {"q": "a", "page": 0}, + {"q": "a", "per_page": 101}, + {"q": "a", "include_withdrawn": "yes"}, + {"q": "a", "url": "https://x.example.test"}, + ): + assert _errors("DocumentReferenceSearchRequest", invalid) != [], invalid diff --git a/traigent_schema/schemas/agent_readiness/compliance_document_ref_endpoints.json b/traigent_schema/schemas/agent_readiness/compliance_document_ref_endpoints.json index c0477217..50ff2557 100644 --- a/traigent_schema/schemas/agent_readiness/compliance_document_ref_endpoints.json +++ b/traigent_schema/schemas/agent_readiness/compliance_document_ref_endpoints.json @@ -352,6 +352,108 @@ } } } + }, + "/api/v1beta/projects/{project_id}/compliance-document-refs/agents/{agent_id}/search": { + "post": { + "summary": "Search the document references of one Agent by a substring of the link (project members only; the search text travels in the body)", + "description": "A read served as POST so the search text, which is customer content, stays out of URLs, access logs and traces. Case-insensitive substring match against the declared link; every character of the text is literal. Same members-only rule, response shape, ordering (newest first) and paging as the list; the text is never logged, audited or echoed. Takes no idempotency key and is never replayed.", + "operationId": "searchComplianceDocumentReferences", + "x-asserted-against-backend": false, + "parameters": [ + { + "name": "project_id", + "in": "path", + "required": true, + "schema": { + "type": "string", + "minLength": 1 + } + }, + { + "name": "agent_id", + "in": "path", + "required": true, + "schema": { + "type": "string", + "minLength": 1, + "maxLength": 512 + } + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "$ref": "./compliance_document_ref_schema.json#/definitions/DocumentReferenceSearchRequest" + } + } + } + }, + "responses": { + "200": { + "description": "Matching document references, newest first", + "content": { + "application/json": { + "schema": { + "$ref": "./compliance_document_ref_schema.json#/definitions/DocumentReferenceListResponse" + } + } + } + }, + "400": { + "description": "Closed-request violation", + "content": { + "application/json": { + "schema": { + "$ref": "./agent_readiness_error_schema.json" + } + } + } + }, + "401": { + "description": "Unauthenticated", + "content": { + "application/json": { + "schema": { + "$ref": "./agent_readiness_error_schema.json" + } + } + } + }, + "403": { + "description": "Denied", + "content": { + "application/json": { + "schema": { + "$ref": "./agent_readiness_error_schema.json" + } + } + } + }, + "404": { + "description": "Not found, or the feature is off", + "content": { + "application/json": { + "schema": { + "$ref": "./agent_readiness_error_schema.json" + } + } + } + }, + "429": { + "description": "Too many requests \u2014 rate limit exceeded.", + "content": { + "application/json": { + "schema": { + "$ref": "../rate_limit_info_schema.json" + } + } + } + } + }, + "x-replay": "read" + } } } } diff --git a/traigent_schema/schemas/agent_readiness/compliance_document_ref_schema.json b/traigent_schema/schemas/agent_readiness/compliance_document_ref_schema.json index 587f268f..1b656b94 100644 --- a/traigent_schema/schemas/agent_readiness/compliance_document_ref_schema.json +++ b/traigent_schema/schemas/agent_readiness/compliance_document_ref_schema.json @@ -70,6 +70,36 @@ "properties": {}, "description": "Empty by design: a withdrawal carries no free text." }, + "DocumentReferenceSearchRequest": { + "type": "object", + "additionalProperties": false, + "required": ["q"], + "properties": { + "q": { + "type": "string", + "minLength": 1, + "maxLength": 200, + "description": "CUSTOMER CONTENT. A case-insensitive substring matched against the declared document link; every character is literal (no wildcards). Trimmed of surrounding whitespace first: 1 to 200 characters after trimming, no control characters. Sent in the body only, never in a URL; the Backend never logs, audits or echoes it." + }, + "include_withdrawn": { + "type": "boolean", + "default": false, + "description": "When true, withdrawal rows and withdrawn references that match are listed too; a withdrawal row has no link, so it never matches a search text." + }, + "page": { + "type": "integer", + "minimum": 1, + "default": 1 + }, + "per_page": { + "type": "integer", + "minimum": 1, + "maximum": 100, + "default": 25 + } + }, + "description": "Closed request of the document-reference search (a read served as POST so the search text stays out of URLs). The agent is named in the path; actor, tenant and project are server-derived." + }, "DocumentReferenceRecord": { "type": "object", "additionalProperties": false, From 2f3e40094a2796f8db9face9a35c390c99c0c485 Mon Sep 17 00:00:00 2001 From: Nimrod Busany Date: Thu, 19 Nov 2026 04:04:04 +0200 Subject: [PATCH 2/4] feat(agent-readiness): review_context binds attestation signing to the reviewed subject (AGB-79 C1) Ingredient gains review_context on A rows (a 64-hex string or null, absent on other kinds): an opaque, server-issued, keyed freshness token. AttestationCreateRequest gains a REQUIRED review_context to echo it; 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. Coordinated pre-release break, acknowledged in scripts/breaking_schema_allowlist.json. Spine-Trail: st_f6fb29f7a817 Co-Authored-By: Claude Sonnet --- CHANGELOG.md | 1 + parity/python-js-sdk.json | 2 +- scripts/breaking_schema_allowlist.json | 115 ++++++++++++++++++ tests/test_compliance_attestation_contract.py | 16 +++ tests/test_compliance_evidence_contract.py | 13 ++ .../compliance_attestation_endpoints.json | 13 ++ .../compliance_attestation_schema.json | 8 +- .../compliance_evidence_response_schema.json | 17 ++- 8 files changed, 182 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 55ed37b3..b8049eb4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added +- **BREAKING (pre-release). Compliance attestation signing is bound to the reviewed subject (AGB-79 C1).** `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. Coordinated pre-release break: the feature is dark in production and the Backend and Frontend change in the same slice (acknowledged in `scripts/breaking_schema_allowlist.json`). - **Compliance document references: search by link substring (AGB-79 B2b; additive; contract only).** New operation `POST /api/v1beta/projects/{project_id}/compliance-document-refs/agents/{agent_id}/search` (`searchComplianceDocumentReferences`, `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. Marked `x-asserted-against-backend: false` until the Backend merges. Pinned by `tests/test_compliance_document_ref_contract.py`. - **BREAKING (pre-release). Agent readiness and production satellites: project-level `/api/v1` contract (API revision Phase 3).** The agent readiness module moves from `/api/v1beta/projects/{project_id}/agent-readiness[/{agent_id}]` and `/agent-compliance-evidence/{agent_id}` to `/api/v1/projects/{project_id}/agent-readiness/search` (POST; the former list query is now the request body, marked `x-replay: read`) and the per-agent routes `/agents/{agent_ref}/readiness`, `/lifecycle-history`, `/target-revisions`, `/posture-revisions` and `/compliance-evidence`. The reactive policy read keeps its path but renames `agent_id` to `agent_ref`. All operationIds become the backend operation ids (`project_agent_readiness.get_agent_readiness`, ...). New: `GET .../agents/{agent_ref}/next-step` (`agent_next_step_response_schema.json`) and `.../production-status` and `.../production-breaches` (`production_requirements/production_breaches_endpoints.json`, `production_status_response_schema.json`). `x-replay` joins the extension vocabulary. Response shapes of the moved operations are unchanged; the fleet-posture route stays out of the public schema. - **Backend API revision Phase 2 contract declarations (additive new schemas; descriptions corrected).** New `global_error_schema.json` declares the catch-all handler's closed body `{success, error, code}` (no `message`, `code` rather than `error_code`, never a request id) and is referenced by the 500 of the three guidance operations; `error_envelope_schema.json` is unchanged apart from a pointer in its description, so 4xx consumers are unaffected. New `validation_error_loc_type_schema.json` declares the closed `{loc, type}` validation list (error_code `VALIDATION_ERROR` on the guidance session routes) for the guidance 400s. New `agents/agent_conflict_error_schema.json` (409 on agent create and delete, with the server-built `archive_url_template` and `can_archive`), `agents/agent_import_validation_error_schema.json` (import 400 with closed `{index, code}` entries; `IMPORT_TOO_LARGE` is a 400, not a 413) and `agents/agent_import_credential_error_schema.json` (closed 400 `provider_credential_not_accepted`). New `projects/write_scope_error_schema.json` declares the 422 `PROJECT_CONTEXT_REQUIRED` body for a write with no explicit project, referenced from `POST /api/v1/agents`, `POST /api/v1/agents/import` and the two guidance session writes. `PROJECT_CONTEXT_REQUIRED_FOR_WRITE` is deliberately not added to `project_context_error_schema.json`: the backend raises it only as an internal 500 fault, never as a client 422. Package version unchanged until a release is cut. diff --git a/parity/python-js-sdk.json b/parity/python-js-sdk.json index 40695fbc..705c3f7f 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": "b06de8b365093203d63c1b5d52285b481666fb8e47bb9ae4f2521f73e7fb9b0a", + "lastSchemaFileSha": "a7f2a53e9934eaccf66a7bca89c17916c6d2acd61c22e487097f4ecc26bcc431", "schemaFileCount": 617, "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 d43bc3b1..610374ec 100644 --- a/scripts/breaking_schema_allowlist.json +++ b/scripts/breaking_schema_allowlist.json @@ -9500,6 +9500,121 @@ "reason": "Adds the x-replay vocabulary entry (value 'read') that marks a POST operation as a non-mutating search. The meta schema is a vocabulary document that is not applied to request or response bodies at runtime, so no consumer can observe the new property.", "version": "Unreleased pending (TraigentSchema, feat/api-p3-readiness-satellites-paths; backend API revision Phase 3 satellites)", "pr": "pending (TraigentSchema, feat/api-p3-readiness-satellites-paths, not yet opened)" + }, + { + "file": "agent_readiness/compliance_attestation_endpoints.json", + "rule": "enum", + "findings": [ + { + "pointer": "#/paths//api/v1beta/projects/{project_id}/compliance-attestations/post/responses/409/content/application/json/schema/properties/error", + "role": "response", + "subject": { + "direction": "added", + "values": [ + "\"stale_review_context\"" + ] + }, + "old": [ + "\"linked_reference_invalid\"", + "\"linked_reference_required\"", + "\"stale_fingerprints\"", + "\"stale_statement\"" + ], + "new": [ + "\"linked_reference_invalid\"", + "\"linked_reference_required\"", + "\"stale_fingerprints\"", + "\"stale_review_context\"", + "\"stale_statement\"" + ], + "fingerprint": "975140ed8df96ec41636ebcbd8f4bbad46d3e6cbf55039ff552e8d8a8807c4b5" + }, + { + "pointer": "#/paths//api/v1beta/projects/{project_id}/compliance-attestations/post/responses/409/content/application/json/schema/properties/error_code", + "role": "response", + "subject": { + "direction": "added", + "values": [ + "\"stale_review_context\"" + ] + }, + "old": [ + "\"linked_reference_invalid\"", + "\"linked_reference_required\"", + "\"stale_fingerprints\"", + "\"stale_statement\"" + ], + "new": [ + "\"linked_reference_invalid\"", + "\"linked_reference_required\"", + "\"stale_fingerprints\"", + "\"stale_review_context\"", + "\"stale_statement\"" + ], + "fingerprint": "b6e8f5ecd9f7e4c3dccec9bad4c6a4f2b09332d46c4b164ba0ce2462bf66fb79" + }, + { + "pointer": "#/paths//api/v1beta/projects/{project_id}/compliance-attestations/post/responses/409/content/application/json/schema/properties/message", + "role": "response", + "subject": { + "direction": "added", + "values": [ + "\"The agent or its standing attestation changed since it was displayed.\"" + ] + }, + "old": [ + "\"A linked document reference is not valid for this agent.\"", + "\"A statement of this kind needs at least one linked document reference.\"", + "\"The agent changed since it was displayed.\"", + "\"The statement changed since it was displayed.\"" + ], + "new": [ + "\"A linked document reference is not valid for this agent.\"", + "\"A statement of this kind needs at least one linked document reference.\"", + "\"The agent changed since it was displayed.\"", + "\"The agent or its standing attestation changed since it was displayed.\"", + "\"The statement changed since it was displayed.\"" + ], + "fingerprint": "4d98f11cdacd1af758bfab94605854cc634460db43adf1e684ab2fb60de7cb48" + } + ], + "reason": "AGB-79 C1: the sign operation's 409 answers a new closed reason stale_review_context (with its fixed message) when the echoed review_context no longer matches the server's recomputation. Pre-release contract, feature dark in production, backend and frontend change in the same slice.", + "version": "Unreleased pending (TraigentSchema, AGB-79 C1 review_context; backend feature/agb-79-compliance-evidence-next)", + "pr": "pending (TraigentSchema, AGB-79 C1, not yet opened)" + }, + { + "file": "agent_readiness/compliance_attestation_endpoints.json", + "rule": "required", + "findings": [ + { + "pointer": "#/paths//api/v1beta/projects/{project_id}/compliance-attestations/post/requestBody/content/application/json/schema", + "role": "request", + "subject": "review_context", + "old": false, + "new": true, + "fingerprint": "0e2ea0fee935c7ebb32e7580840901399d5cb45ff021335ca9cb4db4cf3e625f" + } + ], + "reason": "AGB-79 C1: attestation signing must echo review_context, the keyed freshness token read from the evidence response, so a signature is bound to the subject the signer reviewed. Coordinated pre-release break: the feature is dark in production and no external client signs; backend and frontend change in the same slice.", + "version": "Unreleased pending (TraigentSchema, AGB-79 C1 review_context; backend feature/agb-79-compliance-evidence-next)", + "pr": "pending (TraigentSchema, AGB-79 C1, not yet opened)" + }, + { + "file": "agent_readiness/compliance_evidence_response_schema.json", + "rule": "property_added", + "findings": [ + { + "pointer": "#/properties/ingredients/items/properties/review_context", + "role": "response", + "subject": "review_context", + "old": false, + "new": true, + "fingerprint": "4168aaf4afd50a070c88bb86d61e61f0a6ecc955a07d7aabcb54826ed89f0e6c" + } + ], + "reason": "AGB-79 C1: 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, AGB-79 C1 review_context; backend feature/agb-79-compliance-evidence-next)", + "pr": "pending (TraigentSchema, AGB-79 C1, not yet opened)" } ] } diff --git a/tests/test_compliance_attestation_contract.py b/tests/test_compliance_attestation_contract.py index 83eaa945..8e43b4f6 100644 --- a/tests/test_compliance_attestation_contract.py +++ b/tests/test_compliance_attestation_contract.py @@ -90,6 +90,7 @@ def _request() -> dict[str, Any]: "agent_id": "agent-1", "ingredient_id": "A1", "statement_digest": _DIGEST, + "review_context": "c" * 64, "outcome": "affirmed", "review_period_days": 90, } @@ -151,6 +152,10 @@ 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)), ("AttestationCreateRequest", _request, lambda r: r.update(signer_user_id="u")), ("AttestationCreateRequest", _request, lambda r: r.update(recorded_at=_NOW)), ("AttestationCreateRequest", _request, lambda r: r.update(tenant_id="t")), @@ -313,6 +318,7 @@ def test_evidence_response_accepts_an_attestation_summary_but_no_note() -> None: "title": "Example", "state": "SUPPORTED", "producer_ref": "ATTESTATION_RECORDS_V1", + "review_context": "d" * 64, "attestation": summary, "links": [], } @@ -484,3 +490,13 @@ def test_an_exported_record_requires_the_marker_fields(missing: str) -> None: record = _exported("current", "wording") del record[missing] assert _errors("ExportedAttestationRecord", record) != [] + + +def test_sign_operation_declares_stale_review_context_and_503() -> None: + operation = load_json(ENDPOINTS_PATH)["paths"][ + "/api/v1beta/projects/{project_id}/compliance-attestations" + ]["post"]["responses"] + body = operation["409"]["content"]["application/json"]["schema"]["properties"] + assert "stale_review_context" in body["error"]["enum"] + assert "stale_review_context" in body["error_code"]["enum"] + assert "503" in operation diff --git a/tests/test_compliance_evidence_contract.py b/tests/test_compliance_evidence_contract.py index 660a9a07..c4f09e0e 100644 --- a/tests/test_compliance_evidence_contract.py +++ b/tests/test_compliance_evidence_contract.py @@ -104,6 +104,7 @@ def _response() -> dict[str, Any]: "group": "Transparency", "title": "Example attestation", "state": "NOT_ASSESSED", + "review_context": "b" * 64, "links": [], }, ], @@ -156,6 +157,11 @@ 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 + lambda r: r["ingredients"][0].update(review_context=None), lambda r: r["ingredients"][0]["links"][0].update(relation="equal"), lambda r: r["ingredients"][0]["links"][0].update(relation="exact-ish"), lambda r: r["ingredients"][0]["links"][0].pop("limitations"), @@ -328,3 +334,10 @@ def test_coverage_ingredient_ids_over_cap_is_rejected_shape_only() -> None: assert len(set(unique)) == 101 assert _errors(_with_ids(**{**_ALL_EMPTY, "supported": unique[:100]})) == [] assert _errors(_with_ids(**{**_ALL_EMPTY, "supported": unique})) != [] + + +def test_review_context_is_a_digest_or_null_on_attestation_rows() -> None: + instance = copy.deepcopy(_response()) + assert _errors(instance) == [] + instance["ingredients"][1]["review_context"] = None + 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 b129afc2..eabdc96f 100644 --- a/traigent_schema/schemas/agent_readiness/compliance_attestation_endpoints.json +++ b/traigent_schema/schemas/agent_readiness/compliance_attestation_endpoints.json @@ -470,6 +470,7 @@ "enum": [ "The statement changed since it was displayed.", "The agent changed since it was displayed.", + "The agent or its standing attestation changed since it was displayed.", "A statement of this kind needs at least one linked document reference.", "A linked document reference is not valid for this agent." ] @@ -479,6 +480,7 @@ "enum": [ "stale_statement", "stale_fingerprints", + "stale_review_context", "linked_reference_required", "linked_reference_invalid" ] @@ -488,6 +490,7 @@ "enum": [ "stale_statement", "stale_fingerprints", + "stale_review_context", "linked_reference_required", "linked_reference_invalid" ] @@ -506,6 +509,16 @@ } } } + }, + "503": { + "description": "The server cannot issue or verify the review context right now; nothing is recorded", + "content": { + "application/json": { + "schema": { + "$ref": "./agent_readiness_error_schema.json" + } + } + } } } } diff --git a/traigent_schema/schemas/agent_readiness/compliance_attestation_schema.json b/traigent_schema/schemas/agent_readiness/compliance_attestation_schema.json index 5b6ef38a..14eb1cec 100644 --- a/traigent_schema/schemas/agent_readiness/compliance_attestation_schema.json +++ b/traigent_schema/schemas/agent_readiness/compliance_attestation_schema.json @@ -329,7 +329,8 @@ "ingredient_id", "statement_digest", "outcome", - "review_period_days" + "review_period_days", + "review_context" ], "properties": { "agent_id": { @@ -342,6 +343,11 @@ "type": "string", "pattern": "^[0-9a-f]{64}$" }, + "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." + }, "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 8b94780e..1d5f2630 100644 --- a/traigent_schema/schemas/agent_readiness/compliance_evidence_response_schema.json +++ b/traigent_schema/schemas/agent_readiness/compliance_evidence_response_schema.json @@ -206,8 +206,23 @@ "maxItems": 100, "description": "Obligations of the visible packs this ingredient may contribute to. Empty when no pack is visible.", "items": { "$ref": "#/definitions/RequirementLink" } + }, + "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." } - } + }, + "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"] } } + } + ] } } } From 1dc466bc0a51881e02c6a90a358bfa48c6b472b8 Mon Sep 17 00:00:00 2001 From: Nimrod Busany Date: Thu, 19 Nov 2026 05:37:17 +0200 Subject: [PATCH 3/4] feat(agent-readiness)!: a not_applicable applicability decision requires a rationale (AGB-79 R4) DecisionInput gains an if/then: when decision is not_applicable, rationale is required and must hold a non-whitespace character (cap unchanged); applicable and unresolved keep it optional and a carry item is not re-validated. The write's 400 also admits the closed RationaleRequiredError (rationale_required, fixed message, no obligation id, no client text). Coordinated pre-release break, acknowledged in scripts/breaking_schema_allowlist.json. Spine-Trail: st_f6fb29f7a817 Co-Authored-By: Claude Sonnet --- CHANGELOG.md | 1 + scripts/breaking_schema_allowlist.json | 99 +++++++++++++++++++ .../test_compliance_applicability_contract.py | 42 ++++++++ .../compliance_applicability_endpoints.json | 7 +- .../compliance_applicability_schema.json | 22 ++++- 5 files changed, 168 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b8049eb4..6f5c8d15 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added +- **BREAKING (pre-release). A `not_applicable` applicability decision requires a rationale (AGB-79 R4).** `DecisionInput` gains an if/then: when `decision` is `not_applicable`, `rationale` is required and must hold at least one non-whitespace 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`). Pre-release contract in the same slice as the Backend and Frontend. - **BREAKING (pre-release). Compliance attestation signing is bound to the reviewed subject (AGB-79 C1).** `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. Coordinated pre-release break: the feature is dark in production and the Backend and Frontend change in the same slice (acknowledged in `scripts/breaking_schema_allowlist.json`). - **Compliance document references: search by link substring (AGB-79 B2b; additive; contract only).** New operation `POST /api/v1beta/projects/{project_id}/compliance-document-refs/agents/{agent_id}/search` (`searchComplianceDocumentReferences`, `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. Marked `x-asserted-against-backend: false` until the Backend merges. Pinned by `tests/test_compliance_document_ref_contract.py`. - **BREAKING (pre-release). Agent readiness and production satellites: project-level `/api/v1` contract (API revision Phase 3).** The agent readiness module moves from `/api/v1beta/projects/{project_id}/agent-readiness[/{agent_id}]` and `/agent-compliance-evidence/{agent_id}` to `/api/v1/projects/{project_id}/agent-readiness/search` (POST; the former list query is now the request body, marked `x-replay: read`) and the per-agent routes `/agents/{agent_ref}/readiness`, `/lifecycle-history`, `/target-revisions`, `/posture-revisions` and `/compliance-evidence`. The reactive policy read keeps its path but renames `agent_id` to `agent_ref`. All operationIds become the backend operation ids (`project_agent_readiness.get_agent_readiness`, ...). New: `GET .../agents/{agent_ref}/next-step` (`agent_next_step_response_schema.json`) and `.../production-status` and `.../production-breaches` (`production_requirements/production_breaches_endpoints.json`, `production_status_response_schema.json`). `x-replay` joins the extension vocabulary. Response shapes of the moved operations are unchanged; the fleet-posture route stays out of the public schema. diff --git a/scripts/breaking_schema_allowlist.json b/scripts/breaking_schema_allowlist.json index 610374ec..fb3b5a27 100644 --- a/scripts/breaking_schema_allowlist.json +++ b/scripts/breaking_schema_allowlist.json @@ -9615,6 +9615,105 @@ "reason": "AGB-79 C1: 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, AGB-79 C1 review_context; backend feature/agb-79-compliance-evidence-next)", "pr": "pending (TraigentSchema, AGB-79 C1, not yet opened)" + }, + { + "file": "agent_readiness/compliance_applicability_endpoints.json", + "rule": "additionalProperties", + "findings": [ + { + "pointer": "#/paths//api/v1beta/projects/{project_id}/compliance-applicability/post/responses/400/content/application/json/schema", + "role": "response", + "subject": "additionalProperties", + "old": "closed (false)", + "new": "open (true/absent)", + "fingerprint": "5e65fdf6f39123c950003f9654e45aa8edcebcf90744b29b604af48f4bbc8aad" + } + ], + "reason": "AGB-79 R4: the applicability write's 400 now also admits the closed body RationaleRequiredError (reason rationale_required, fixed message, no obligation id, no client text), returned when a not_applicable decision has no non-blank rationale. The shared error envelope is unchanged. Pre-release contract, feature dark in production, backend and frontend change in the same slice.", + "version": "Unreleased pending (TraigentSchema, AGB-79 R4 rationale_required; backend feature/agb-79-compliance-evidence-next)", + "pr": "pending (TraigentSchema, AGB-79 R4, not yet opened)" + }, + { + "file": "agent_readiness/compliance_applicability_endpoints.json", + "rule": "oneOf_branch_count_changed", + "findings": [ + { + "pointer": "#/paths//api/v1beta/projects/{project_id}/compliance-applicability/post/responses/400/content/application/json/schema/oneOf", + "role": "response", + "subject": "oneOf", + "old": 8, + "new": 2, + "fingerprint": "ed5ade56862200cbd4685a23861b3ae97ad72d7f454b0ef18615cc8ee7d51ab5" + } + ], + "reason": "AGB-79 R4: the applicability write's 400 now also admits the closed body RationaleRequiredError (reason rationale_required, fixed message, no obligation id, no client text), returned when a not_applicable decision has no non-blank rationale. The shared error envelope is unchanged. Pre-release contract, feature dark in production, backend and frontend change in the same slice.", + "version": "Unreleased pending (TraigentSchema, AGB-79 R4 rationale_required; backend feature/agb-79-compliance-evidence-next)", + "pr": "pending (TraigentSchema, AGB-79 R4, not yet opened)" + }, + { + "file": "agent_readiness/compliance_applicability_endpoints.json", + "rule": "required", + "findings": [ + { + "pointer": "#/paths//api/v1beta/projects/{project_id}/compliance-applicability/post/responses/400/content/application/json/schema", + "role": "response", + "subject": "error", + "old": true, + "new": false, + "fingerprint": "f12a1bd937d4d1c35af7106b8d4e1bb634cd115c799c2b33742c8c5dfb191b5a" + }, + { + "pointer": "#/paths//api/v1beta/projects/{project_id}/compliance-applicability/post/responses/400/content/application/json/schema", + "role": "response", + "subject": "error_code", + "old": true, + "new": false, + "fingerprint": "363cf75b243525d78cf04cb4cfdc675ae4c2528b3105e02c7b6882580265fb8f" + }, + { + "pointer": "#/paths//api/v1beta/projects/{project_id}/compliance-applicability/post/responses/400/content/application/json/schema", + "role": "response", + "subject": "message", + "old": true, + "new": false, + "fingerprint": "4ae3fd7787cb2d64c6849bdee8b7bdb46f71e3838011a28e30db25c03ffca5f0" + }, + { + "pointer": "#/paths//api/v1beta/projects/{project_id}/compliance-applicability/post/responses/400/content/application/json/schema", + "role": "response", + "subject": "success", + "old": true, + "new": false, + "fingerprint": "8c3d522264942e2bfe8ef56bc75b1633cd5ae3b7524883d596fc15ab0eab09bd" + } + ], + "reason": "AGB-79 R4: the applicability write's 400 now also admits the closed body RationaleRequiredError (reason rationale_required, fixed message, no obligation id, no client text), returned when a not_applicable decision has no non-blank rationale. The shared error envelope is unchanged. Pre-release contract, feature dark in production, backend and frontend change in the same slice.", + "version": "Unreleased pending (TraigentSchema, AGB-79 R4 rationale_required; backend feature/agb-79-compliance-evidence-next)", + "pr": "pending (TraigentSchema, AGB-79 R4, not yet opened)" + }, + { + "file": "agent_readiness/compliance_applicability_endpoints.json", + "rule": "type", + "findings": [ + { + "pointer": "#/paths//api/v1beta/projects/{project_id}/compliance-applicability/post/responses/400/content/application/json/schema", + "role": "response", + "subject": { + "direction": "added", + "values": [ + "" + ] + }, + "old": [ + "object" + ], + "new": null, + "fingerprint": "da551006e00999b93838d984e747786f0daa5cbd4786bfca84a3e69193d59212" + } + ], + "reason": "AGB-79 R4: the applicability write's 400 now also admits the closed body RationaleRequiredError (reason rationale_required, fixed message, no obligation id, no client text), returned when a not_applicable decision has no non-blank rationale. The shared error envelope is unchanged. Pre-release contract, feature dark in production, backend and frontend change in the same slice.", + "version": "Unreleased pending (TraigentSchema, AGB-79 R4 rationale_required; backend feature/agb-79-compliance-evidence-next)", + "pr": "pending (TraigentSchema, AGB-79 R4, not yet opened)" } ] } diff --git a/tests/test_compliance_applicability_contract.py b/tests/test_compliance_applicability_contract.py index 4565d4ee..1a955ca3 100644 --- a/tests/test_compliance_applicability_contract.py +++ b/tests/test_compliance_applicability_contract.py @@ -252,6 +252,17 @@ def test_valid_examples_conform(definition: str, factory: Any) -> None: _request, lambda r: r["decisions"][0].update(rationale="x" * 2001), ), + ( + "ApplicabilityRevisionCreateRequest", + _request, + lambda r: r["decisions"][0].update(decision="not_applicable", rationale=None) + or r["decisions"][0].pop("rationale"), + ), + ( + "ApplicabilityRevisionCreateRequest", + _request, + lambda r: r["decisions"][0].update(decision="not_applicable", rationale=" "), + ), ( "ApplicabilityRevisionCreateRequest", _request, @@ -438,3 +449,34 @@ def test_every_decision_record_names_the_revision_it_was_decided_in() -> None: assert _errors("ApplicabilityRevisionRecord", record) == [] record["decisions"][0].pop("decided_in_revision_id") assert _errors("ApplicabilityRevisionRecord", record) != [] + + +def test_not_applicable_requires_a_rationale_the_other_decisions_do_not() -> None: + """AGB-79 R4: a not_applicable decision carries a non-empty rationale; the others may omit it.""" + + def item(decision: str, **extra: Any) -> dict[str, Any]: + return {"obligation_id": _OBL, "decision": decision, **extra} + + assert _errors("DecisionInput", item("not_applicable", rationale="Out of scope for this agent")) == [] + assert _errors("DecisionInput", item("not_applicable")) != [] + assert _errors("DecisionInput", item("not_applicable", rationale="")) != [] + assert _errors("DecisionInput", item("not_applicable", rationale=" \n\t ")) != [] + assert _errors("DecisionInput", item("applicable")) == [] + assert _errors("DecisionInput", item("unresolved")) == [] + assert _errors("DecisionItem", {"obligation_id": _OBL, "carry": True}) == [] + + +def test_rationale_required_is_a_closed_declared_400_on_the_write() -> None: + body = { + "success": False, + "message": "A rationale is required when an obligation is marked not applicable.", + "error": "rationale_required", + "error_code": "rationale_required", + } + assert _errors("RationaleRequiredError", body) == [] + assert _errors("RationaleRequiredError", {**body, "obligation_id": _OBL}) != [] + assert _errors("RationaleRequiredError", {**body, "error_code": "invalid_request"}) != [] + endpoints = load_json(ENDPOINTS_PATH) + post = endpoints["paths"]["/api/v1beta/projects/{project_id}/compliance-applicability"]["post"] + refs = [b["$ref"] for b in post["responses"]["400"]["content"]["application/json"]["schema"]["oneOf"]] + assert "./compliance_applicability_schema.json#/definitions/RationaleRequiredError" in refs diff --git a/traigent_schema/schemas/agent_readiness/compliance_applicability_endpoints.json b/traigent_schema/schemas/agent_readiness/compliance_applicability_endpoints.json index 2ede2042..6000d201 100644 --- a/traigent_schema/schemas/agent_readiness/compliance_applicability_endpoints.json +++ b/traigent_schema/schemas/agent_readiness/compliance_applicability_endpoints.json @@ -44,11 +44,14 @@ } }, "400": { - "description": "Closed-request violation", + "description": "Closed-request violation. A not_applicable decision without a non-blank rationale is the distinct closed reason rationale_required; the body names no obligation and echoes no client text.", "content": { "application/json": { "schema": { - "$ref": "./agent_readiness_error_schema.json" + "oneOf": [ + { "$ref": "./agent_readiness_error_schema.json" }, + { "$ref": "./compliance_applicability_schema.json#/definitions/RationaleRequiredError" } + ] } } } diff --git a/traigent_schema/schemas/agent_readiness/compliance_applicability_schema.json b/traigent_schema/schemas/agent_readiness/compliance_applicability_schema.json index 462af245..f9dc245f 100644 --- a/traigent_schema/schemas/agent_readiness/compliance_applicability_schema.json +++ b/traigent_schema/schemas/agent_readiness/compliance_applicability_schema.json @@ -71,8 +71,16 @@ "type": "string", "minLength": 1, "maxLength": 2000, - "description": "Optional free text. CUSTOMER CONTENT: stored with the snapshot, returned only to project members, kept on user erasure, never logged and never sent to the Director, an LLM or observability." + "description": "Optional free text, except that it is REQUIRED (at least one non-whitespace character) when `decision` is `not_applicable`. CUSTOMER CONTENT: stored with the snapshot, returned only to project members, kept on user erasure, never logged and never sent to the Director, an LLM or observability." } + }, + "if": { + "properties": { "decision": { "const": "not_applicable" } }, + "required": ["decision"] + }, + "then": { + "required": ["rationale"], + "properties": { "rationale": { "type": "string", "minLength": 1, "pattern": "\\S" } } } }, "DecisionCarry": { @@ -89,6 +97,18 @@ "oneOf": [{ "$ref": "#/definitions/DecisionInput" }, { "$ref": "#/definitions/DecisionCarry" }], "description": "Either a new decision made in this submission, or `carry: true` for the predecessor's decision." }, + "RationaleRequiredError": { + "type": "object", + "additionalProperties": false, + "required": ["success", "message", "error", "error_code"], + "properties": { + "success": { "const": false }, + "message": { "const": "A rationale is required when an obligation is marked not applicable." }, + "error": { "const": "rationale_required" }, + "error_code": { "const": "rationale_required" } + }, + "description": "The closed 400 for a `not_applicable` decision whose rationale is absent, null, empty or whitespace only. Nothing is recorded. It names no obligation id and carries no client text." + }, "ApplicabilityRevisionCreateRequest": { "type": "object", "additionalProperties": false, From 7422029c91beab7e7cf1d8f43b822696ab905796 Mon Sep 17 00:00:00 2001 From: Nimrod Busany Date: Thu, 19 Nov 2026 05:50:13 +0200 Subject: [PATCH 4/4] fix(agent-readiness): explicit engine-independent blank-rationale pattern (AGB-79 R4) Replace \S with an explicit class excluding Z*, Cc and Cf BMP code points. Co-Authored-By: Claude Sonnet --- .../test_compliance_applicability_contract.py | 30 +++++++++++++++++++ .../compliance_applicability_schema.json | 4 +-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/tests/test_compliance_applicability_contract.py b/tests/test_compliance_applicability_contract.py index 1a955ca3..2acf1650 100644 --- a/tests/test_compliance_applicability_contract.py +++ b/tests/test_compliance_applicability_contract.py @@ -480,3 +480,33 @@ def test_rationale_required_is_a_closed_declared_400_on_the_write() -> None: post = endpoints["paths"]["/api/v1beta/projects/{project_id}/compliance-applicability"]["post"] refs = [b["$ref"] for b in post["responses"]["400"]["content"]["application/json"]["schema"]["oneOf"]] assert "./compliance_applicability_schema.json#/definitions/RationaleRequiredError" in refs + + +_BLANK_RATIONALES = [ + "", + " ", + " \t\n\r ", + "\u0085", + "\u00a0", + "\u200b", + "\u200c", + "\u200d", + "\ufeff", + "\u2060", + "\u3000", + " \ufeff\u200b\u2060 ", +] +_PRESENT_RATIONALES = ["a", "\ufeffa", "\u200bx\u200b", "\u05e9\u05dc\u05d5\u05dd", "\u4e2d\u6587", " why "] + + +@pytest.mark.parametrize("text", _BLANK_RATIONALES) +def test_a_blank_rationale_is_refused_for_not_applicable(text: str) -> None: + """Same case table as the backend and frontend tests: separators, controls, format characters.""" + item = {"obligation_id": _OBL, "decision": "not_applicable", "rationale": text} + assert _errors("DecisionInput", item) != [] + + +@pytest.mark.parametrize("text", _PRESENT_RATIONALES) +def test_a_visible_rationale_is_accepted_for_not_applicable(text: str) -> None: + item = {"obligation_id": _OBL, "decision": "not_applicable", "rationale": text} + assert _errors("DecisionInput", item) == [] diff --git a/traigent_schema/schemas/agent_readiness/compliance_applicability_schema.json b/traigent_schema/schemas/agent_readiness/compliance_applicability_schema.json index f9dc245f..f175642c 100644 --- a/traigent_schema/schemas/agent_readiness/compliance_applicability_schema.json +++ b/traigent_schema/schemas/agent_readiness/compliance_applicability_schema.json @@ -71,7 +71,7 @@ "type": "string", "minLength": 1, "maxLength": 2000, - "description": "Optional free text, except that it is REQUIRED (at least one non-whitespace character) when `decision` is `not_applicable`. CUSTOMER CONTENT: stored with the snapshot, returned only to project members, kept on user erasure, never logged and never sent to the Director, an LLM or observability." + "description": "Optional free text, except that it is REQUIRED (at least one character outside Unicode categories Z*, Cc and Cf: whitespace, control and zero-width/format characters alone count as blank; this schema lists the BMP code points explicitly, the server is the authority for the full rule) when `decision` is `not_applicable`. CUSTOMER CONTENT: stored with the snapshot, returned only to project members, kept on user erasure, never logged and never sent to the Director, an LLM or observability." } }, "if": { @@ -80,7 +80,7 @@ }, "then": { "required": ["rationale"], - "properties": { "rationale": { "type": "string", "minLength": 1, "pattern": "\\S" } } + "properties": { "rationale": { "type": "string", "minLength": 1, "pattern": "[^\\u0000-\\u0020\\u007F-\\u00A0\\u00AD\\u0600-\\u0605\\u061C\\u06DD\\u070F\\u1680\\u180E\\u2000-\\u200F\\u2028-\\u202F\\u205F-\\u2064\\u2066-\\u206F\\u3000\\uFEFF\\uFFF9-\\uFFFB]" } } } }, "DecisionCarry": {