From 4693ff493c9fc2a98b14b0d79a682b1695f80458 Mon Sep 17 00:00:00 2001 From: Nimrod Busany Date: Wed, 25 Nov 2026 02:43:42 +0200 Subject: [PATCH] feat(contracts): release candidates, and the agent detail returns its release reference Adds three operations on /api/v1/projects/{project_id}/agents/{agent_ref}/release-candidates: record a candidate after the client's release gate runs (a signed-in person or an SDK API key with editor access and agent WRITE; service tokens are refused), list candidates, and read one. The candidate record carries ids, digests, a closed gate-verdict enum and timestamps only, with the same field shapes as the release acceptance it feeds. Same-body replay returns the original record; a different body for the same version is a closed 409. Denials are the closed release refusal envelope; the 429 body accepts the limiter's values. The agent detail read gains an optional `agent_ref`: the server-issued release reference a portal needs to call the release routes. The content-class lint approves the fixed `release_candidate_` reference pattern. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 1 + docs/content-class-manifest.json | 17 + parity/python-js-sdk.json | 4 +- .../unreachable_schemas.json | 6 +- scripts/breaking_schema_allowlist.json | 17 + scripts/content_class_lint.py | 1 + tests/test_agent_detail_agent_ref_contract.py | 112 +++++ tests/test_release_acceptance_contract.py | 3 + tests/test_release_candidate_contract.py | 354 +++++++++++++++ ..._success_envelope_and_response_coverage.py | 2 +- .../schemas/agents/agent_detail_schema.json | 43 ++ .../schemas/agents/agents_endpoints.json | 4 +- .../release_acceptance_schema.json | 2 +- .../release_candidate_schema.json | 301 +++++++++++++ .../optimization/release_endpoints.json | 403 +++++++++++++++++- 15 files changed, 1259 insertions(+), 11 deletions(-) create mode 100644 tests/test_agent_detail_agent_ref_contract.py create mode 100644 tests/test_release_candidate_contract.py create mode 100644 traigent_schema/schemas/agents/agent_detail_schema.json create mode 100644 traigent_schema/schemas/optimization/release_candidate_schema.json diff --git a/CHANGELOG.md b/CHANGELOG.md index cbd80b86..40470b56 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 +- **Release candidate API contract.** Clients can report a promotion gate verdict and its digests for an agent's best-config version. The portal can list and read those records to prefill a person's release acceptance. The agent detail response (`GET /api/v1/projects/{project_id}/agents/{agent_ref}`, 200 `data`) gains an optional `agent_ref`: the server-issued release reference (`AgentRef`, `opaque_ref`) that the release-acceptance and release routes take in their `{agent_ref}` segment. It is defined by the new `agents/agent_detail_schema.json`, which references each property of `agent_schema.json` by pointer, so the shared `agent_schema.json` and the other endpoints that use it are unchanged. The release-family `agent_ref` path parameters now name where a portal reads the reference. - **BREAKING (pre-release). Production reactive operations move under the project-level agent path (API cutover U1).** In `optimization/tvl_reactive_endpoints.json` the 14 operations at `/api/v1/production-reactive/agents/{agent_ref}/...` move to `/api/v1/projects/{project_id}/agents/{agent_ref}/production-reactive/...` and gain the `project_id` path parameter (string, `opaque_ref` content class, the `project_...` id pattern used by the fleet observe contract). `operationId`s (`production_reactive.*`), methods, bodies and responses are unchanged. The backend answers the closed 404 on the old paths. The content-class manifest pointers and `docs/tvl-reactive-contracts.md` follow. - **Agent readiness detail: optional `scorecard` block (additive; optional, nullable).** `agent_readiness_detail_response_schema.json` gains a top-level `scorecard` (null or a closed `Scorecard`): `basis` (`ACTIVE_CONFIG` when the agent has a promoted head, generation above 0, otherwise `CURRENT_RUN`), `config` (best config id and version, generation, environment, promotion time and run), `run_id`, `run_completed_at`, `metrics` (the same `ReportedMetrics` shape as journey items) and `areas` (`evaluation_set` example count and dataset ref, `evaluator` version ref, `evaluation_progress` stage and trials run). Ids, counts, refs and numbers only. `basis` is enforced: `ACTIVE_CONFIG` needs a non-null `config` with `generation` of at least 1; `CURRENT_RUN` needs a non-null `run_id` and a null `config`; a null `run_id` requires empty `metrics` and null `run_completed_at`, `example_count`, `dataset_ref`, `version_ref`, `stage` and `trials_run`. Not in `required`, so older payloads stay valid; the response is closed, so strict readers must upgrade before the Backend emits it (acknowledged in `scripts/breaking_schema_allowlist.json`). - **Experiment context: display names are marked as customer content (annotations only; additive).** `ExperimentContextResponse.tenant_name` and `project_name` in `evaluation/experiment_context_schema.json` carry `x-content: true` and `x-privacy-classification: user_content`, and their descriptions state they are returned only to the authorized human reader and never logged, sent to telemetry or the Director. Types, required fields and identifiers are unchanged. `tests/test_content_privacy_annotations.py` covers both fields. diff --git a/docs/content-class-manifest.json b/docs/content-class-manifest.json index 74971f02..ae31b2d6 100644 --- a/docs/content-class-manifest.json +++ b/docs/content-class-manifest.json @@ -1090,11 +1090,28 @@ "optimization/release_acceptance_schema.json#/definitions/ReleaseRefusal/properties/error_code": "closed_enum", "optimization/release_acceptance_schema.json#/definitions/ReleaseRefusal/properties/message": "closed_enum", "optimization/release_acceptance_schema.json#/definitions/ReleaseRefusal/properties/success": "closed_enum", + "optimization/release_candidate_schema.json#/definitions/ReleaseCandidate/properties/recorded_by_kind": "closed_enum", + "optimization/release_candidate_schema.json#/definitions/ReleaseCandidate/properties/state": "closed_enum", + "optimization/release_candidate_schema.json#/definitions/ReleaseCandidateConflict/properties/error": "closed_enum", + "optimization/release_candidate_schema.json#/definitions/ReleaseCandidateConflict/properties/error_code": "closed_enum", + "optimization/release_candidate_schema.json#/definitions/ReleaseCandidateConflict/properties/message": "closed_enum", + "optimization/release_candidate_schema.json#/definitions/ReleaseCandidateConflict/properties/success": "closed_enum", + "optimization/release_candidate_schema.json#/definitions/ReleaseCandidateListResponse/properties/success": "closed_enum", + "optimization/release_candidate_schema.json#/definitions/ReleaseCandidateNotFound/allOf/1/properties/error_code": "closed_enum", + "optimization/release_candidate_schema.json#/definitions/ReleaseCandidateRateLimited/properties/details/properties/scope": "closed_enum", + "optimization/release_candidate_schema.json#/definitions/ReleaseCandidateRateLimited/properties/message": "closed_enum", + "optimization/release_candidate_schema.json#/definitions/ReleaseCandidateRef": "opaque_ref", + "optimization/release_candidate_schema.json#/definitions/ReleaseCandidateRequest/properties/gate_verdict": "closed_enum", + "optimization/release_candidate_schema.json#/definitions/ReleaseCandidateResponse/properties/success": "closed_enum", "optimization/release_endpoints.json#/paths/~1api~1v1~1projects~1{project_id}~1agents~1{agent_ref}~1best-config-head~1release/post/parameters/0/schema": "key_material", "optimization/release_endpoints.json#/paths/~1api~1v1~1projects~1{project_id}~1agents~1{agent_ref}~1best-config-head~1rollback/post/parameters/0/schema": "key_material", "optimization/release_endpoints.json#/paths/~1api~1v1~1projects~1{project_id}~1agents~1{agent_ref}~1release-acceptances/get/parameters/0/schema": "key_material", "optimization/release_endpoints.json#/paths/~1api~1v1~1projects~1{project_id}~1agents~1{agent_ref}~1release-acceptances/get/parameters/3/schema": "number", "optimization/release_endpoints.json#/paths/~1api~1v1~1projects~1{project_id}~1agents~1{agent_ref}~1release-acceptances/post/parameters/0/schema": "key_material", + "optimization/release_endpoints.json#/paths/~1api~1v1~1projects~1{project_id}~1agents~1{agent_ref}~1release-candidates/get/parameters/0/schema": "key_material", + "optimization/release_endpoints.json#/paths/~1api~1v1~1projects~1{project_id}~1agents~1{agent_ref}~1release-candidates/get/parameters/3/schema": "number", + "optimization/release_endpoints.json#/paths/~1api~1v1~1projects~1{project_id}~1agents~1{agent_ref}~1release-candidates/post/parameters/0/schema": "key_material", + "optimization/release_endpoints.json#/paths/~1api~1v1~1projects~1{project_id}~1agents~1{agent_ref}~1release-candidates~1{candidate_ref}/get/parameters/0/schema": "key_material", "optimization/semantic_saturation_schema.json#/definitions/ContinuousObjectiveDiagnostic/properties/best": "number", "optimization/semantic_saturation_schema.json#/definitions/ContinuousObjectiveDiagnostic/properties/direction": "closed_enum", "optimization/semantic_saturation_schema.json#/definitions/ContinuousObjectiveDiagnostic/properties/improvement": "number", diff --git a/parity/python-js-sdk.json b/parity/python-js-sdk.json index 9e80e8ff..4e0a9d4b 100644 --- a/parity/python-js-sdk.json +++ b/parity/python-js-sdk.json @@ -399,8 +399,8 @@ "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": "895cd9c9cd67c906e6a4cbfe7f62f77bcb89c2eefae204997a14b86f4a209f12", - "schemaFileCount": 666, + "lastSchemaFileSha": "97a4258b8bbb0fcb4d4f2ea086e0ba46b8fd700506d03631407fe27476f25c86", + "schemaFileCount": 668, "note": "Auto-stamped by scripts/refresh_parity.py. Do not hand-edit this block." } } diff --git a/reports/schema_reachability/unreachable_schemas.json b/reports/schema_reachability/unreachable_schemas.json index 8ffb6cdf..3c38f348 100644 --- a/reports/schema_reachability/unreachable_schemas.json +++ b/reports/schema_reachability/unreachable_schemas.json @@ -10,10 +10,10 @@ "reachableByRule": { "allowlist": 0, "consumerReference": 33, - "refOrEndpointGraph": 570 + "refOrEndpointGraph": 572 }, - "reachableCount": 603, - "schemaFileCount": 666, + "reachableCount": 605, + "schemaFileCount": 668, "unreachableCount": 63 }, "unreachableSchemas": [ diff --git a/scripts/breaking_schema_allowlist.json b/scripts/breaking_schema_allowlist.json index 0303d81c..c874c659 100644 --- a/scripts/breaking_schema_allowlist.json +++ b/scripts/breaking_schema_allowlist.json @@ -11067,6 +11067,23 @@ "reason": "path parameter takes the agent id the agents API returns; the agentref_ digest is retired for these routes and the service answers it with the masked 404. Clients must update their id validation and use the project-scoped paths", "version": "Unreleased", "pr": "pending (TraigentSchema, fix/reactive-agent-ref-is-agent-id)" + }, + { + "file": "agents/agents_endpoints.json", + "rule": "property_added", + "findings": [ + { + "pointer": "#/paths//api/v1/projects/{project_id}/agents/{agent_ref}/get/responses/200/content/application/json/schema/properties/data/properties/agent_ref", + "role": "response", + "subject": "agent_ref", + "old": false, + "new": true, + "fingerprint": "0881379da9343ea95786055c3b4890a125dba49106e1727bee3d062934422848" + } + ], + "reason": "additive optional response field on the agent detail read: the server-issued release reference a portal needs to call the release routes. Payloads valid under the previous schema still validate. A client that validates responses against the previous closed schema can reject a response once the field is emitted; the Python SDK and the JS SDK do not read or validate the agent detail response.", + "version": "Unreleased", + "pr": "pending (TraigentSchema, feat/release-candidates)" } ] } diff --git a/scripts/content_class_lint.py b/scripts/content_class_lint.py index 684f4aa5..505ff344 100644 --- a/scripts/content_class_lint.py +++ b/scripts/content_class_lint.py @@ -155,6 +155,7 @@ "^[0-9a-f]{32}(?![\\s\\S])", # per-request problem id (uuid4 hex) of a closed problem body # server-minted project id: random, tenant-derived default or personal-workspace form PROJECT_ID_PATTERN, + "^release_candidate_[0-9a-f]{32}$", # server-minted release-candidate ref (bounded to 50 by the schema) # Fleet Observe: the signed pagination cursor (see CURSOR_PATTERN: accepted only at # CURSOR_LOCATIONS, checked in _check_cursor_site) and the 16-hex id of the customer-held # digest key (derived by HMAC, so it carries no text). diff --git a/tests/test_agent_detail_agent_ref_contract.py b/tests/test_agent_detail_agent_ref_contract.py new file mode 100644 index 00000000..e5788f4b --- /dev/null +++ b/tests/test_agent_detail_agent_ref_contract.py @@ -0,0 +1,112 @@ +"""Contract for the optional agent_ref on the agent detail response. + +GET /api/v1/projects/{project_id}/agents/{agent_ref} returns the success envelope; its +``data`` is ``agent_detail_schema.json``: the shared agent schema plus the optional +server-issued ``agent_ref``. The shared ``agent_schema.json`` must stay unchanged. +""" + +from __future__ import annotations + +import json +from typing import Any + +import jsonschema +from referencing import Registry, Resource +from referencing.jsonschema import DRAFT7 + +from traigent_schema.utils import get_schemas_dir + +S = get_schemas_dir() +AGENTS = S / "agents" +VALID_REF = "agentref_" + "0" * 32 +PLAIN_AGENT_ID = "agent_9f2c4e1a" + + +def _load(path): + return json.loads(path.read_text(encoding="utf-8")) + + +def _registry() -> Registry: + registry = Registry() + for path in S.rglob("*.json"): + doc = json.loads(path.read_text(encoding="utf-8")) + uri = "https://schemas.traigent.ai/" + path.relative_to(S).as_posix() + registry = registry.with_resource(uri, Resource.from_contents(doc, default_specification=DRAFT7)) + return registry + + +def _validator(schema: dict[str, Any]) -> jsonschema.Draft7Validator: + return jsonschema.Draft7Validator(schema, registry=_registry()) + + +DETAIL = _validator(_load(AGENTS / "agent_detail_schema.json")) + + +def _agent(**extra: Any) -> dict[str, Any]: + body: dict[str, Any] = {"id": PLAIN_AGENT_ID, "name": "Support bot", "agent_type": "chat"} + body.update(extra) + return body + + +def _errors(validator, body): + return list(validator.iter_errors(body)) + + +def test_detail_accepts_a_valid_server_issued_reference(): + assert not _errors(DETAIL, _agent(agent_ref=VALID_REF)) + + +def test_detail_rejects_a_plain_agent_id_in_the_reference_slot(): + assert _errors(DETAIL, _agent(agent_ref=PLAIN_AGENT_ID)) + + +def test_detail_rejects_a_reference_with_uppercase_hex(): + assert _errors(DETAIL, _agent(agent_ref="agentref_" + "A" * 32)) + + +def test_detail_allows_absence_of_agent_ref(): + assert "agent_ref" not in _load(AGENTS / "agent_detail_schema.json").get("required", []) + assert not _errors(DETAIL, _agent()) + + +def test_detail_stays_closed_to_unknown_keys(): + assert _errors(DETAIL, _agent(agent_id=PLAIN_AGENT_ID)) + + +def test_detail_agent_ref_is_the_shared_opaque_reference_definition(): + prop = _load(AGENTS / "agent_detail_schema.json")["properties"]["agent_ref"] + assert "$ref" not in prop + assert prop["allOf"] == [{"$ref": "../labels/label_common_schema.json#/definitions/AgentRef"}] + assert prop["x-content-class"] == "opaque_ref" + assert prop["description"] == ( + "Server-issued release reference of this agent (an `agentref_` digest), scoped to the " + "tenant and project and derived one-way from the agent id. It is not the agent id used in " + "this request's path: the release-acceptance and release routes take this reference in " + "their `{agent_ref}` path segment." + ) + + +def test_detail_property_set_tracks_shared_agent_schema_plus_agent_ref(): + shared = set(_load(AGENTS / "agent_schema.json")["properties"]) + detail = set(_load(AGENTS / "agent_detail_schema.json")["properties"]) + assert detail == shared | {"agent_ref"} + + +def test_shared_agent_schema_is_unchanged_and_still_rejects_agent_ref(): + shared = _load(AGENTS / "agent_schema.json") + assert "agent_ref" not in shared["properties"] + assert shared["additionalProperties"] is False + assert _errors(_validator(shared), _agent(agent_ref=VALID_REF)) + + +def test_get_agent_200_data_is_wired_to_the_detail_schema(): + get_200_pointer = ( + "/paths/~1api~1v1~1projects~1{project_id}~1agents~1{agent_ref}" + "/get/responses/200/content/application~1json/schema" + ) + envelope_ref = {"$ref": "https://schemas.traigent.ai/agents/agents_endpoints.json#" + get_200_pointer} + envelope = _validator(envelope_ref) + ok = {"success": True, "message": "ok", "data": _agent(agent_ref=VALID_REF)} + assert not _errors(envelope, ok) + assert _errors(envelope, {"success": True, "message": "ok", "data": _agent(agent_ref=PLAIN_AGENT_ID)}) + assert not _errors(envelope, {"success": True, "message": "ok", "data": _agent()}) diff --git a/tests/test_release_acceptance_contract.py b/tests/test_release_acceptance_contract.py index 41776fdf..4e65acc0 100644 --- a/tests/test_release_acceptance_contract.py +++ b/tests/test_release_acceptance_contract.py @@ -344,6 +344,9 @@ def test_routes_are_registered_with_operation_ids_and_closed_bodies(): assert ops == { (base + "/release-acceptances", "post"): "best_configs.create_release_acceptance", (base + "/release-acceptances", "get"): "best_configs.list_release_acceptances", + (base + "/release-candidates", "post"): "best_configs.create_release_candidate", + (base + "/release-candidates", "get"): "best_configs.list_release_candidates", + (base + "/release-candidates/{candidate_ref}", "get"): "best_configs.get_release_candidate", (base + "/best-config-head/release", "post"): "best_configs.release_agent_head", (base + "/best-config-head/rollback", "post"): "best_configs.rollback_agent_head", } diff --git a/tests/test_release_candidate_contract.py b/tests/test_release_candidate_contract.py new file mode 100644 index 00000000..516c77bf --- /dev/null +++ b/tests/test_release_candidate_contract.py @@ -0,0 +1,354 @@ +"""Release candidate routes, reports and read models.""" + +import json +import runpy +from pathlib import Path + +import pytest +from jsonschema import Draft7Validator +from referencing import Registry, Resource + +from traigent_schema import SchemaValidator +from traigent_schema.utils import get_schemas_dir +from traigent_schema.validator import _FORMAT_CHECKER + +SCHEMAS = Path(get_schemas_dir()) +SCHEMA_BASE = "https://schemas.traigent.ai/" +CANDIDATE_SCHEMA = "optimization/release_candidate_schema.json" +ACCEPTANCE_SCHEMA = "optimization/release_acceptance_schema.json" +ENDPOINTS = "optimization/release_endpoints.json" +COLLECTION = "/api/v1/projects/{project_id}/agents/{agent_ref}/release-candidates" +ITEM = COLLECTION + "/{candidate_ref}" +ACCEPTANCE_COLLECTION = "/api/v1/projects/{project_id}/agents/{agent_ref}/release-acceptances" +VERDICTS = ("promote", "reject", "no_decision") +CANDIDATE_ROUTES = ((COLLECTION, "post"), (COLLECTION, "get"), (ITEM, "get")) + + +def _document(path): + return json.loads((SCHEMAS / path).read_text(encoding="utf-8")) + + +@pytest.fixture(scope="module") +def registry(): + paths = ( + CANDIDATE_SCHEMA, + ACCEPTANCE_SCHEMA, + "optimization/session_capabilities_schema.json", + "optimization/tvl_reactive_common_schema.json", + "error_envelope_schema.json", + "fleet_observe/fleet_observe_responses_schema.json", + "rate_limit_info_schema.json", + ) + return Registry().with_resources( + (SCHEMA_BASE + path, Resource.from_contents(_document(path))) for path in paths + ) + + +def _validator(registry, name): + ref = f"{SCHEMA_BASE}{CANDIDATE_SCHEMA}#/definitions/{name}" + return Draft7Validator({"$ref": ref}, registry=registry) + + +def _response_validator(registry, path, method, status): + response = _document(ENDPOINTS)["paths"][path][method]["responses"][status] + schema = response["content"]["application/json"]["schema"] + return Draft7Validator( + {"$id": SCHEMA_BASE + ENDPOINTS, "allOf": [schema]}, + registry=registry, + format_checker=_FORMAT_CHECKER, + ) + + +@pytest.fixture +def report(): + return { + "environment": "production", + "best_config_id": "bc_1", + "best_config_version": 3, + "candidate_fingerprint": "a" * 64, + "gate_result_digest": "b" * 64, + "configuration_space_digest": "c" * 64, + "agent_code_version": "d" * 40, + "gate_verdict": "promote", + } + + +@pytest.fixture +def record(report): + return { + **report, + "candidate_ref": "release_candidate_" + "e" * 32, + "recorded_at": "2026-11-20T10:00:00Z", + "recorded_by_kind": "api_key", + "state": "open", + } + + +@pytest.mark.parametrize( + ("path", "method", "operation_id", "status", "response"), + [ + (COLLECTION, "post", "create_release_candidate", "201", "ReleaseCandidateResponse"), + (COLLECTION, "get", "list_release_candidates", "200", "ReleaseCandidateListResponse"), + ( + ITEM, + "get", + "get_release_candidate", + "200", + "ReleaseCandidateResponse", + ), + ], +) +def test_release_candidate_routes(path, method, operation_id, status, response): + paths = _document(ENDPOINTS)["paths"] + operation = paths[path][method] + assert operation["operationId"] == f"best_configs.{operation_id}" + responses = operation["responses"] + body_schema = responses[status]["content"]["application/json"]["schema"] + assert body_schema["$ref"] == f"./release_candidate_schema.json#/definitions/{response}" + assert "reference_not_found" in responses["404"]["description"] + acceptance = paths[ACCEPTANCE_COLLECTION][method] + for code in ("401", "403"): + assert responses[code]["content"] == acceptance["responses"][code]["content"] + parameters = {parameter["name"]: parameter for parameter in operation["parameters"]} + for parameter in acceptance["parameters"]: + if parameter["in"] == "path": + assert parameters[parameter["name"]] == parameter + if path.endswith("/{candidate_ref}"): + candidate_ref = parameters["candidate_ref"] + assert candidate_ref["in"] == "path" + assert candidate_ref["required"] is True + assert candidate_ref["schema"]["$ref"] == ( + "./release_candidate_schema.json#/definitions/ReleaseCandidateRef" + ) + if operation_id == "list_release_candidates": + assert parameters["limit"]["schema"]["maximum"] == 100 + + +def test_create_route_requires_report_and_documents_replay_and_conflict(): + operation = _document(ENDPOINTS)["paths"][COLLECTION]["post"] + body = operation["requestBody"] + assert body["required"] is True + description = operation["description"] + assert ( + "A replay of the same body returns 201 with the same candidate_ref " + "and original recording metadata." + ) in description + assert ( + "A different body for the same (agent, environment, best_config_id, " + "best_config_version) returns 409 candidate_conflict; a fingerprint that does not match " + "the stored version is the masked 404 instead, never a conflict." + ) in description + assert ( + "A candidate_fingerprint that does not match the stored version is refused the same way." + ) in description + responses = operation["responses"] + assert "invalid_request" in responses["400"]["description"] + assert "candidate_conflict" in responses["409"]["description"] + assert responses["409"]["content"]["application/json"]["schema"]["$ref"] == ( + "./release_candidate_schema.json#/definitions/ReleaseCandidateConflict" + ) + conflict = _document(CANDIDATE_SCHEMA)["definitions"]["ReleaseCandidateConflict"] + assert conflict["properties"]["error_code"]["const"] == "candidate_conflict" + + +def test_create_report_through_public_request_validator(report): + validator = SchemaValidator(unknown_endpoint_policy="strict") + path = COLLECTION.format(project_id="project_1", agent_ref="agentref_" + "f" * 32) + assert validator.validate_request(path, "POST", report) == [] + errors = validator.validate_request(path, "POST", {**report, "gate_verdict": "pending"}) + assert any("gate_verdict" in error and "pending" in error for error in errors), errors + + +def test_report_requires_every_field_and_rejects_extras(registry, report): + definition = _document(CANDIDATE_SCHEMA)["definitions"]["ReleaseCandidateRequest"] + validator = _validator(registry, "ReleaseCandidateRequest") + assert definition["additionalProperties"] is False + assert set(definition["required"]) == set(report) + assert validator.is_valid(report) + for field in report: + missing = report.copy() + del missing[field] + assert not validator.is_valid(missing), field + assert not validator.is_valid({**report, "note": "unexpected text"}) + + +def test_report_gate_verdict_is_a_closed_enum(registry, report): + definition = _document(CANDIDATE_SCHEMA)["definitions"]["ReleaseCandidateRequest"] + assert set(definition["properties"]["gate_verdict"]["enum"]) == set(VERDICTS) + validator = _validator(registry, "ReleaseCandidateRequest") + for verdict in VERDICTS: + assert validator.is_valid({**report, "gate_verdict": verdict}) + assert not validator.is_valid({**report, "gate_verdict": "pending"}) + + +@pytest.mark.parametrize("verdict", VERDICTS) +@pytest.mark.parametrize("digest", ["b" * 64, "no_gate_run"], ids=["digest", "no-gate-run"]) +def test_gate_digest_matches_verdict(registry, report, record, verdict, digest): + expected = digest != "no_gate_run" or verdict == "no_decision" + for name, body in (("ReleaseCandidateRequest", report), ("ReleaseCandidate", record)): + validator = _validator(registry, name) + payload = {**body, "gate_verdict": verdict, "gate_result_digest": digest} + assert validator.is_valid(payload) == expected, name + + +def test_report_reuses_acceptance_digest_definitions(): + candidate = _document(CANDIDATE_SCHEMA)["definitions"]["ReleaseCandidateRequest"]["properties"] + definitions = _document(ACCEPTANCE_SCHEMA)["definitions"] + acceptance = definitions["CreateReleaseAcceptanceRequest"]["properties"] + assert "candidate_ref" not in acceptance + for field in ( + "candidate_fingerprint", + "gate_result_digest", + "configuration_space_digest", + "agent_code_version", + ): + assert candidate[field]["$ref"] == acceptance[field]["$ref"] + assert {"type", "pattern", "enum", "anyOf"}.isdisjoint(candidate[field]) + + +def test_candidate_record_requires_all_fields_and_rejects_extras(registry, record): + validator = _validator(registry, "ReleaseCandidate") + assert validator.is_valid(record) + for field in record: + missing = record.copy() + del missing[field] + assert not validator.is_valid(missing), field + assert not validator.is_valid({**record, "note": "unexpected text"}) + + +@pytest.mark.parametrize( + ("field", "invalid"), + [ + ("candidate_ref", "release_candidate_" + "E" * 32), + ("candidate_ref", "release_candidate_" + "e" * 32 + "\n"), + ("recorded_at", 1763632800), + ("recorded_by_kind", "unknown"), + ("state", "pending"), + ], +) +def test_candidate_record_rejects_invalid_metadata(registry, record, field, invalid): + validator = _validator(registry, "ReleaseCandidate") + assert not validator.is_valid({**record, field: invalid}) + + +def test_candidate_record_uses_shared_timestamp(): + properties = _document(CANDIDATE_SCHEMA)["definitions"]["ReleaseCandidate"]["properties"] + assert properties["recorded_at"]["$ref"] == ( + "./tvl_reactive_common_schema.json#/definitions/Timestamp" + ) + definitions = _document("optimization/tvl_reactive_common_schema.json")["definitions"] + assert definitions["Timestamp"]["format"] == "date-time" + + +def test_candidate_read_envelopes_are_closed_and_list_is_bounded(registry, record): + validator = _validator(registry, "ReleaseCandidateResponse") + assert validator.is_valid({"success": True, "data": record}) + assert not validator.is_valid({"success": False, "data": record}) + assert not validator.is_valid({"success": True, "data": record, "extra": 1}) + + validator = _validator(registry, "ReleaseCandidateListResponse") + assert validator.is_valid({"success": True, "data": []}) + assert validator.is_valid({"success": True, "data": [record] * 100}) + assert not validator.is_valid({"success": True, "data": [record] * 101}) + assert not validator.is_valid({"success": True, "data": [{}]}) + assert not validator.is_valid({"success": True, "data": [], "extra": 1}) + + +@pytest.mark.parametrize("path", [COLLECTION, ITEM]) +def test_get_candidate_responses_through_catalog(registry, record, path): + validator = _response_validator(registry, path, "get", "200") + invalid = {**record, "gate_verdict": "reject", "gate_result_digest": "no_gate_run"} + data, invalid_data = ([record], [invalid]) if path == COLLECTION else (record, invalid) + assert validator.is_valid({"success": True, "data": data}) + errors = list(validator.iter_errors({"success": True, "data": invalid_data})) + assert [error.path[-1] for error in errors] == ["gate_result_digest"] + + +@pytest.mark.parametrize(("path", "method"), CANDIDATE_ROUTES) +def test_candidate_not_found_accepts_only_the_masked_refusal(registry, path, method): + validator = _response_validator(registry, path, method, "404") + assert validator.is_valid( + { + "success": False, + "error": "reference_not_found", + "error_code": "reference_not_found", + "message": "Reference not found.", + } + ) + assert not validator.is_valid( + { + "success": False, + "error": "forbidden", + "error_code": "forbidden", + "message": "Forbidden.", + } + ) + + +@pytest.mark.parametrize(("path", "method"), CANDIDATE_ROUTES) +def test_candidate_rate_limit_uses_shared_headers_and_closed_values(registry, path, method): + validator = _response_validator(registry, path, method, "429") + details = {"scope": "global", "retry_after": 60} + body = { + "success": False, + "message": "Rate limit exceeded", + "error": "Too many requests", + "error_code": "RATE_LIMIT_EXCEEDED", + "details": details, + } + assert validator.is_valid(body) + for scope in ("api", "tenant"): + assert validator.is_valid({**body, "details": {**details, "scope": scope}}), scope + + assert validator.is_valid( + { + **body, + "details": { + **details, + "limit": "1 per 1 hour", + "reset_time": "2026-11-20T10:00:00.123456+00:00", + }, + } + ) + for field in ("message", "error"): + assert not validator.is_valid({**body, field: "unexpected text"}), field + for field in ("scope", "limit", "reset_time"): + invalid = {**body, "details": {**details, field: "unexpected text"}} + assert not validator.is_valid(invalid), field + # The limiter renders any configured window, e.g. RATE_LIMIT_GLOBAL="1 per 10000000000 seconds". + for limit in ("1 per 10000000000 second", "10000000000 per 1 hour", "5 per 1 days"): + assert validator.is_valid({**body, "details": {**details, "limit": limit}}), limit + too_wide = "1" * 21 + for limit in ("1 per 1 hour\n", "100 per minute", f"{too_wide} per 1 hour", "1 per 1 week"): + assert not validator.is_valid({**body, "details": {**details, "limit": limit}}), limit + + response = _document(ENDPOINTS)["paths"][path][method]["responses"]["429"] + shared_headers = _document("rate_limit_info_schema.json")["x-response-headers"] + assert response["headers"] == { + header: {"$ref": f"../rate_limit_info_schema.json#/x-response-headers/{header}"} + for header in shared_headers + } + + +def test_candidate_conflict_has_a_fixed_closed_envelope(registry): + validator = _validator(registry, "ReleaseCandidateConflict") + refusal = { + "success": False, + "error": "release_precondition_refused", + "error_code": "candidate_conflict", + "message": "A different release candidate already exists for this best-config version.", + } + assert validator.is_valid(refusal) + assert not validator.is_valid({**refusal, "message": "unexpected text"}) + assert not validator.is_valid({**refusal, "extra": 1}) + + +def test_release_candidate_content_classes_pass_lint(): + script = Path(__file__).resolve().parents[1] / "scripts" / "content_class_lint.py" + result = runpy.run_path(str(script))["run_lint"](SCHEMAS) + assert result.ok, (result.missing, result.invalid, result.unresolved) + assert any( + finding.loc == f"{CANDIDATE_SCHEMA}#/definitions/ReleaseCandidateRef" + and finding.cls == "opaque_ref" + for finding in result.findings + ) diff --git a/tests/test_success_envelope_and_response_coverage.py b/tests/test_success_envelope_and_response_coverage.py index 348173fa..fa321e40 100644 --- a/tests/test_success_envelope_and_response_coverage.py +++ b/tests/test_success_envelope_and_response_coverage.py @@ -75,7 +75,7 @@ def test_detail_gets_use_the_resource_not_an_unrelated_response_schema(): ref = agents["paths"]["/api/v1/projects/{project_id}/agents/{agent_ref}"]["get"]["responses"]["200"]["content"]["application/json"]["schema"]["$ref"] assert ref == "#/components/schemas/AgentDetailEnvelope", ref envelope = agents["components"]["schemas"]["AgentDetailEnvelope"] - assert envelope["properties"]["data"]["$ref"].endswith("agent_schema.json") + assert envelope["properties"]["data"]["$ref"] == "./agent_detail_schema.json" assert "data" in envelope["required"] # bare detail GETs reference the resource schema directly (the canonical experiment detail via # ExperimentRead, the resource with experiment_ref required) diff --git a/traigent_schema/schemas/agents/agent_detail_schema.json b/traigent_schema/schemas/agents/agent_detail_schema.json new file mode 100644 index 00000000..cc1325be --- /dev/null +++ b/traigent_schema/schemas/agents/agent_detail_schema.json @@ -0,0 +1,43 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "$id": "https://schemas.traigent.ai/agents/agent_detail_schema.json", + "type": "object", + "title": "Agent Detail Schema", + "description": "The agent object returned as data by GET /api/v1/projects/{project_id}/agents/{agent_ref}. It is agent_schema.json plus the optional server-issued agent_ref. Every agent property is referenced from agent_schema.json by JSON pointer, so the shared agent schema is not changed and other endpoints keep their shape. agent_schema.json is closed (additionalProperties false), which is why this document lists the properties itself instead of extending it with allOf.", + "properties": { + "id": { "$ref": "./agent_schema.json#/properties/id" }, + "name": { "$ref": "./agent_schema.json#/properties/name" }, + "description": { "$ref": "./agent_schema.json#/properties/description" }, + "agent_type": { "$ref": "./agent_schema.json#/properties/agent_type" }, + "agent_platform": { "$ref": "./agent_schema.json#/properties/agent_platform" }, + "prompt_template": { "$ref": "./agent_schema.json#/properties/prompt_template" }, + "reasoning": { "$ref": "./agent_schema.json#/properties/reasoning" }, + "style": { "$ref": "./agent_schema.json#/properties/style" }, + "tone": { "$ref": "./agent_schema.json#/properties/tone" }, + "format": { "$ref": "./agent_schema.json#/properties/format" }, + "persona": { "$ref": "./agent_schema.json#/properties/persona" }, + "guidelines": { "$ref": "./agent_schema.json#/properties/guidelines" }, + "response_validation": { "$ref": "./agent_schema.json#/properties/response_validation" }, + "chat_history": { "$ref": "./agent_schema.json#/properties/chat_history" }, + "chat_history_params": { "$ref": "./agent_schema.json#/properties/chat_history_params" }, + "custom_validations": { "$ref": "./agent_schema.json#/properties/custom_validations" }, + "custom_tools": { "$ref": "./agent_schema.json#/properties/custom_tools" }, + "custom_responses": { "$ref": "./agent_schema.json#/properties/custom_responses" }, + "source": { "$ref": "./agent_schema.json#/properties/source" }, + "created_at": { "$ref": "./agent_schema.json#/properties/created_at" }, + "updated_at": { "$ref": "./agent_schema.json#/properties/updated_at" }, + "example_sets": { "$ref": "./agent_schema.json#/properties/example_sets" }, + "retrieval_configs": { "$ref": "./agent_schema.json#/properties/retrieval_configs" }, + "measures": { "$ref": "./agent_schema.json#/properties/measures" }, + "model_parameters": { "$ref": "./agent_schema.json#/properties/model_parameters" }, + "agent_ref": { + "allOf": [ + { "$ref": "../labels/label_common_schema.json#/definitions/AgentRef" } + ], + "x-content-class": "opaque_ref", + "description": "Server-issued release reference of this agent (an `agentref_` digest), scoped to the tenant and project and derived one-way from the agent id. It is not the agent id used in this request's path: the release-acceptance and release routes take this reference in their `{agent_ref}` path segment." + } + }, + "required": ["id", "name", "agent_type"], + "additionalProperties": false +} diff --git a/traigent_schema/schemas/agents/agents_endpoints.json b/traigent_schema/schemas/agents/agents_endpoints.json index ecd19b7e..f6f1c7ed 100644 --- a/traigent_schema/schemas/agents/agents_endpoints.json +++ b/traigent_schema/schemas/agents/agents_endpoints.json @@ -1746,7 +1746,7 @@ }, "AgentDetailEnvelope": { "type": "object", - "description": "Success envelope {success, message, data} from response_handler.success_response; data is the agent (agent_routes.py get_agent).", + "description": "Success envelope {success, message, data} from response_handler.success_response; data is the agent plus the optional server-issued agent_ref (agent_routes.py get_agent).", "properties": { "success": { "type": "boolean" @@ -1755,7 +1755,7 @@ "type": "string" }, "data": { - "$ref": "./agent_schema.json" + "$ref": "./agent_detail_schema.json" } }, "additionalProperties": true, diff --git a/traigent_schema/schemas/optimization/release_acceptance_schema.json b/traigent_schema/schemas/optimization/release_acceptance_schema.json index 82c85684..b3af49f5 100644 --- a/traigent_schema/schemas/optimization/release_acceptance_schema.json +++ b/traigent_schema/schemas/optimization/release_acceptance_schema.json @@ -123,7 +123,7 @@ "description": "Head generation the person saw when accepting. A release is refused as head_generation_stale if the head has moved." } }, - "description": "Body of POST /api/v1/projects/{project_id}/agents/{agent_ref}/release-acceptances. A person's decision to release one exact candidate; person only (an API key is refused). The server binds these fields immutably, stamps the decider from the authenticated person and sets the expiry from its own clock. Every field is required; there is no free text." + "description": "Body of POST /api/v1/projects/{project_id}/agents/{agent_ref}/release-acceptances. A person's decision to release one exact candidate; person only (an API key is refused). The server binds these fields immutably, stamps the decider from the authenticated person and sets the expiry from its own clock. Every field is required; there is no free text. The portal copies the shared fields from the selected release candidate and supplies the head generation it showed to the person, omitting candidate_ref." }, "ReleaseAcceptance": { "type": "object", diff --git a/traigent_schema/schemas/optimization/release_candidate_schema.json b/traigent_schema/schemas/optimization/release_candidate_schema.json new file mode 100644 index 00000000..dce62802 --- /dev/null +++ b/traigent_schema/schemas/optimization/release_candidate_schema.json @@ -0,0 +1,301 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "$id": "https://schemas.traigent.ai/optimization/release_candidate_schema.json", + "title": "ReleaseCandidate", + "description": "Closed contracts for reporting and reading an agent's candidates for release acceptance.", + "definitions": { + "ReleaseCandidateRef": { + "x-content-class": "opaque_ref", + "type": "string", + "pattern": "^release_candidate_[0-9a-f]{32}$", + "maxLength": 50, + "description": "Server-issued opaque reference to a recorded release candidate." + }, + "ReleaseCandidateRequest": { + "type": "object", + "additionalProperties": false, + "required": [ + "environment", + "best_config_id", + "best_config_version", + "candidate_fingerprint", + "gate_result_digest", + "configuration_space_digest", + "agent_code_version", + "gate_verdict" + ], + "properties": { + "environment": { + "$ref": "./session_capabilities_schema.json#/definitions/SessionEnvironment" + }, + "best_config_id": { + "$ref": "./release_acceptance_schema.json#/definitions/CreateReleaseAcceptanceRequest/properties/best_config_id" + }, + "best_config_version": { + "$ref": "./release_acceptance_schema.json#/definitions/CreateReleaseAcceptanceRequest/properties/best_config_version" + }, + "candidate_fingerprint": { + "$ref": "./tvl_reactive_common_schema.json#/definitions/Digest" + }, + "gate_result_digest": { + "$ref": "./release_acceptance_schema.json#/definitions/GateResultDigest" + }, + "configuration_space_digest": { + "$ref": "./tvl_reactive_common_schema.json#/definitions/Digest" + }, + "agent_code_version": { + "$ref": "./release_acceptance_schema.json#/definitions/AgentCodeVersion" + }, + "gate_verdict": { + "x-content-class": "closed_enum", + "type": "string", + "enum": [ + "promote", + "reject", + "no_decision" + ], + "description": "Verdict reported by the client after evaluating the candidate. The fixed gate result no_gate_run is allowed only with no_decision." + } + }, + "if": { + "properties": { + "gate_verdict": { + "enum": ["promote", "reject"] + } + } + }, + "then": { + "properties": { + "gate_result_digest": { + "$ref": "./tvl_reactive_common_schema.json#/definitions/Digest" + } + } + }, + "description": "Body of POST /api/v1/projects/{project_id}/agents/{agent_ref}/release-candidates. Reports a candidate for a person's release acceptance. Every field is required." + }, + "ReleaseCandidate": { + "type": "object", + "additionalProperties": false, + "required": [ + "candidate_ref", + "environment", + "best_config_id", + "best_config_version", + "candidate_fingerprint", + "gate_result_digest", + "configuration_space_digest", + "agent_code_version", + "gate_verdict", + "recorded_at", + "recorded_by_kind", + "state" + ], + "properties": { + "candidate_ref": { + "$ref": "./release_candidate_schema.json#/definitions/ReleaseCandidateRef" + }, + "environment": { + "$ref": "./release_candidate_schema.json#/definitions/ReleaseCandidateRequest/properties/environment" + }, + "best_config_id": { + "$ref": "./release_candidate_schema.json#/definitions/ReleaseCandidateRequest/properties/best_config_id" + }, + "best_config_version": { + "$ref": "./release_candidate_schema.json#/definitions/ReleaseCandidateRequest/properties/best_config_version" + }, + "candidate_fingerprint": { + "$ref": "./release_candidate_schema.json#/definitions/ReleaseCandidateRequest/properties/candidate_fingerprint" + }, + "gate_result_digest": { + "$ref": "./release_candidate_schema.json#/definitions/ReleaseCandidateRequest/properties/gate_result_digest" + }, + "configuration_space_digest": { + "$ref": "./release_candidate_schema.json#/definitions/ReleaseCandidateRequest/properties/configuration_space_digest" + }, + "agent_code_version": { + "$ref": "./release_candidate_schema.json#/definitions/ReleaseCandidateRequest/properties/agent_code_version" + }, + "gate_verdict": { + "$ref": "./release_candidate_schema.json#/definitions/ReleaseCandidateRequest/properties/gate_verdict" + }, + "recorded_at": { + "$ref": "./tvl_reactive_common_schema.json#/definitions/Timestamp" + }, + "recorded_by_kind": { + "x-content-class": "closed_enum", + "type": "string", + "enum": [ + "person", + "api_key", + "service" + ], + "description": "Kind of authenticated principal that first recorded the candidate." + }, + "state": { + "x-content-class": "closed_enum", + "type": "string", + "enum": [ + "open", + "accepted", + "released", + "superseded" + ], + "description": "The candidate's state, derived when the candidate is read, in this order: released if a matching acceptance was consumed; otherwise accepted if a matching acceptance is unexpired, not revoked, and its expected head generation equals the current head generation; otherwise superseded if a newer candidate exists for the same agent and environment; otherwise open. For accepted, revoked, expired and stale acceptances do not count; a consumed acceptance keeps the candidate released even after it expires or the head moves. The create response carries the same derived state." + } + }, + "if": { + "properties": { + "gate_verdict": { + "enum": ["promote", "reject"] + } + } + }, + "then": { + "properties": { + "gate_result_digest": { + "$ref": "./tvl_reactive_common_schema.json#/definitions/Digest" + } + } + }, + "description": "The reported release candidate with its server-assigned reference, time, principal kind and state." + }, + "ReleaseCandidateResponse": { + "type": "object", + "additionalProperties": false, + "required": [ + "success", + "data" + ], + "properties": { + "success": { + "x-content-class": "closed_enum", + "type": "boolean", + "const": true + }, + "data": { + "$ref": "./release_candidate_schema.json#/definitions/ReleaseCandidate" + } + }, + "description": "201 body of POST .../release-candidates and 200 body of GET .../release-candidates/{candidate_ref}." + }, + "ReleaseCandidateListResponse": { + "type": "object", + "additionalProperties": false, + "required": [ + "success", + "data" + ], + "properties": { + "success": { + "x-content-class": "closed_enum", + "type": "boolean", + "const": true + }, + "data": { + "type": "array", + "maxItems": 100, + "items": { + "$ref": "./release_candidate_schema.json#/definitions/ReleaseCandidate" + } + } + }, + "description": "200 body of GET .../release-candidates. Candidates of the agent, newest recorded_at first, at most 100." + }, + "ReleaseCandidateNotFound": { + "allOf": [ + { + "$ref": "./release_acceptance_schema.json#/definitions/ReleaseRefusal" + }, + { + "properties": { + "error_code": { + "x-content-class": "closed_enum", + "const": "reference_not_found" + } + } + } + ], + "description": "Masked 404 body for unknown, foreign or invisible references." + }, + "ReleaseCandidateRateLimited": { + "allOf": [ + { + "$ref": "../rate_limit_info_schema.json" + } + ], + "additionalProperties": false, + "properties": { + "success": {}, + "error_code": {}, + "message": { + "x-content-class": "closed_enum", + "const": "Rate limit exceeded" + }, + "error": { + "$ref": "../fleet_observe/fleet_observe_responses_schema.json#/definitions/RateLimitedBody/properties/error" + }, + "details": { + "allOf": [ + { + "$ref": "../rate_limit_info_schema.json#/allOf/1/properties/details" + } + ], + "additionalProperties": false, + "properties": { + "scope": { + "x-content-class": "closed_enum", + "enum": ["global", "api", "tenant"] + }, + "retry_after": {}, + "limit": {}, + "reset_time": {} + }, + "if": { + "required": ["limit"] + }, + "then": { + "properties": { + "limit": { + "pattern": "^[0-9]{1,20} per [0-9]{1,20} (?:second|minute|hour|day|month|year)s?(?![\\s\\S])" + } + } + } + } + }, + "description": "429 body for release candidate routes, with closed rate-limit text and scope." + }, + "ReleaseCandidateConflict": { + "type": "object", + "additionalProperties": false, + "required": [ + "success", + "error", + "error_code", + "message" + ], + "properties": { + "success": { + "x-content-class": "closed_enum", + "type": "boolean", + "const": false + }, + "error": { + "x-content-class": "closed_enum", + "type": "string", + "const": "release_precondition_refused" + }, + "error_code": { + "x-content-class": "closed_enum", + "type": "string", + "const": "candidate_conflict" + }, + "message": { + "x-content-class": "closed_enum", + "type": "string", + "const": "A different release candidate already exists for this best-config version." + } + }, + "description": "409 body of POST .../release-candidates in the ReleaseRefusal envelope shape. Nothing from the request is echoed." + } + } +} diff --git a/traigent_schema/schemas/optimization/release_endpoints.json b/traigent_schema/schemas/optimization/release_endpoints.json index 70c01592..0a75ceed 100644 --- a/traigent_schema/schemas/optimization/release_endpoints.json +++ b/traigent_schema/schemas/optimization/release_endpoints.json @@ -1,11 +1,406 @@ { "openapi": "3.0.0", "info": { - "title": "Traigent Release Acceptance and Head Rollback Routes", + "title": "Traigent Release Candidate, Acceptance and Head Rollback Routes", "version": "1.0.0", - "description": "Project-scoped release acceptance, release and head rollback of the agent promotion head. Closed wire contracts: no free text crosses these routes. Planned routes; the Backend is asserted against these contracts when it ships them." + "description": "Project-scoped routes for reporting release candidates, recording acceptance, releasing an accepted candidate and rolling back the agent promotion head. Planned routes with closed wire contracts." }, "paths": { + "/api/v1/projects/{project_id}/agents/{agent_ref}/release-candidates": { + "post": { + "summary": "Record a candidate for release", + "description": "Planned route. Requires project editor access and agent WRITE as for publishing a best config. A signed-in person or an SDK API key with that access may report candidates. Service tokens are refused, even with project binding and write scope: the response is the closed release refusal, 401 `unauthenticated` or 403 `forbidden` depending on where authentication stops the request. The server resolves the best-config ID and version in the authenticated tenant and requested project and agent before recording the candidate. Unknown, foreign or invisible versions receive the same 404. A candidate_fingerprint that does not match the stored version is refused the same way. The deduplication key is (agent, environment, best_config_id, best_config_version, candidate_fingerprint). A replay of the same body returns 201 with the same candidate_ref and original recording metadata. At most one body may be recorded per (agent, environment, best_config_id, best_config_version). A different body for the same (agent, environment, best_config_id, best_config_version) returns 409 candidate_conflict; a fingerprint that does not match the stored version is the masked 404 instead, never a conflict.", + "operationId": "best_configs.create_release_candidate", + "x-asserted-against-backend": false, + "parameters": [ + { + "name": "project_id", + "in": "path", + "required": true, + "schema": { + "x-content-class": "key_material", + "type": "string", + "pattern": "^[A-Za-z0-9_-]+$", + "minLength": 1, + "maxLength": 128, + "description": "Server-issued project id." + } + }, + { + "name": "agent_ref", + "in": "path", + "required": true, + "description": "A portal reads this reference from the agent detail response's `agent_ref`.", + "schema": { + "$ref": "../labels/label_common_schema.json#/definitions/AgentRef" + } + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "allOf": [ + { + "$ref": "./release_candidate_schema.json#/definitions/ReleaseCandidateRequest" + } + ] + } + } + } + }, + "responses": { + "201": { + "description": "The stored candidate.", + "content": { + "application/json": { + "schema": { + "$ref": "./release_candidate_schema.json#/definitions/ReleaseCandidateResponse" + } + } + } + }, + "400": { + "description": "invalid_request. Closed envelope; nothing is echoed.", + "content": { + "application/json": { + "schema": { + "$ref": "./release_acceptance_schema.json#/definitions/ReleaseRefusal" + } + } + } + }, + "401": { + "description": "unauthenticated. Closed envelope.", + "content": { + "application/json": { + "schema": { + "$ref": "./release_acceptance_schema.json#/definitions/ReleaseRefusal" + } + } + } + }, + "403": { + "description": "forbidden. Closed envelope.", + "content": { + "application/json": { + "schema": { + "$ref": "./release_acceptance_schema.json#/definitions/ReleaseRefusal" + } + } + } + }, + "404": { + "description": "reference_not_found. Unknown, foreign or invisible references are indistinguishable. Closed envelope.", + "content": { + "application/json": { + "schema": { + "$ref": "./release_candidate_schema.json#/definitions/ReleaseCandidateNotFound" + } + } + } + }, + "409": { + "description": "candidate_conflict. Closed envelope. Nothing is echoed.", + "content": { + "application/json": { + "schema": { + "$ref": "./release_candidate_schema.json#/definitions/ReleaseCandidateConflict" + } + } + } + }, + "429": { + "description": "Too many requests \u2014 rate limit exceeded.", + "content": { + "application/json": { + "schema": { + "$ref": "./release_candidate_schema.json#/definitions/ReleaseCandidateRateLimited" + } + } + }, + "headers": { + "Retry-After": { + "$ref": "../rate_limit_info_schema.json#/x-response-headers/Retry-After" + }, + "X-RateLimit-Limit": { + "$ref": "../rate_limit_info_schema.json#/x-response-headers/X-RateLimit-Limit" + }, + "X-RateLimit-Remaining": { + "$ref": "../rate_limit_info_schema.json#/x-response-headers/X-RateLimit-Remaining" + }, + "X-RateLimit-Reset": { + "$ref": "../rate_limit_info_schema.json#/x-response-headers/X-RateLimit-Reset" + } + } + }, + "500": { + "description": "internal_error. Closed envelope.", + "content": { + "application/json": { + "schema": { + "$ref": "./release_acceptance_schema.json#/definitions/ReleaseRefusal" + } + } + } + } + } + }, + "get": { + "summary": "List release candidates of an agent", + "description": "Planned route. Requires project viewer access and agent READ. Newest recorded_at first, at most `limit` items. Errors use a closed refusal envelope or the closed rate-limit envelope.", + "operationId": "best_configs.list_release_candidates", + "x-asserted-against-backend": false, + "parameters": [ + { + "name": "project_id", + "in": "path", + "required": true, + "schema": { + "x-content-class": "key_material", + "type": "string", + "pattern": "^[A-Za-z0-9_-]+$", + "minLength": 1, + "maxLength": 128, + "description": "Server-issued project id." + } + }, + { + "name": "agent_ref", + "in": "path", + "required": true, + "description": "A portal reads this reference from the agent detail response's `agent_ref`.", + "schema": { + "$ref": "../labels/label_common_schema.json#/definitions/AgentRef" + } + }, + { + "name": "environment", + "in": "query", + "required": false, + "description": "Closed run environment; absent means every environment.", + "schema": { + "$ref": "./session_capabilities_schema.json#/definitions/SessionEnvironment" + } + }, + { + "name": "limit", + "in": "query", + "required": false, + "description": "Maximum items, default 50.", + "schema": { + "x-content-class": "number", + "type": "integer", + "minimum": 1, + "maximum": 100 + } + } + ], + "responses": { + "200": { + "description": "Candidates of the agent.", + "content": { + "application/json": { + "schema": { + "$ref": "./release_candidate_schema.json#/definitions/ReleaseCandidateListResponse" + } + } + } + }, + "400": { + "description": "invalid_request. Closed envelope; nothing is echoed.", + "content": { + "application/json": { + "schema": { + "$ref": "./release_acceptance_schema.json#/definitions/ReleaseRefusal" + } + } + } + }, + "401": { + "description": "unauthenticated. Closed envelope.", + "content": { + "application/json": { + "schema": { + "$ref": "./release_acceptance_schema.json#/definitions/ReleaseRefusal" + } + } + } + }, + "403": { + "description": "forbidden. Closed envelope.", + "content": { + "application/json": { + "schema": { + "$ref": "./release_acceptance_schema.json#/definitions/ReleaseRefusal" + } + } + } + }, + "404": { + "description": "reference_not_found. Unknown, foreign or invisible references are indistinguishable. Closed envelope.", + "content": { + "application/json": { + "schema": { + "$ref": "./release_candidate_schema.json#/definitions/ReleaseCandidateNotFound" + } + } + } + }, + "429": { + "description": "Too many requests \u2014 rate limit exceeded.", + "content": { + "application/json": { + "schema": { + "$ref": "./release_candidate_schema.json#/definitions/ReleaseCandidateRateLimited" + } + } + }, + "headers": { + "Retry-After": { + "$ref": "../rate_limit_info_schema.json#/x-response-headers/Retry-After" + }, + "X-RateLimit-Limit": { + "$ref": "../rate_limit_info_schema.json#/x-response-headers/X-RateLimit-Limit" + }, + "X-RateLimit-Remaining": { + "$ref": "../rate_limit_info_schema.json#/x-response-headers/X-RateLimit-Remaining" + }, + "X-RateLimit-Reset": { + "$ref": "../rate_limit_info_schema.json#/x-response-headers/X-RateLimit-Reset" + } + } + }, + "500": { + "description": "internal_error. Closed envelope.", + "content": { + "application/json": { + "schema": { + "$ref": "./release_acceptance_schema.json#/definitions/ReleaseRefusal" + } + } + } + } + } + } + }, + "/api/v1/projects/{project_id}/agents/{agent_ref}/release-candidates/{candidate_ref}": { + "get": { + "summary": "Read one release candidate of an agent", + "description": "Planned route. Requires project viewer access and agent READ. The candidate must belong to the requested project and agent. Errors use a closed refusal envelope or the closed rate-limit envelope.", + "operationId": "best_configs.get_release_candidate", + "x-asserted-against-backend": false, + "parameters": [ + { + "name": "project_id", + "in": "path", + "required": true, + "schema": { + "x-content-class": "key_material", + "type": "string", + "pattern": "^[A-Za-z0-9_-]+$", + "minLength": 1, + "maxLength": 128, + "description": "Server-issued project id." + } + }, + { + "name": "agent_ref", + "in": "path", + "required": true, + "description": "A portal reads this reference from the agent detail response's `agent_ref`.", + "schema": { + "$ref": "../labels/label_common_schema.json#/definitions/AgentRef" + } + }, + { + "name": "candidate_ref", + "in": "path", + "required": true, + "schema": { + "$ref": "./release_candidate_schema.json#/definitions/ReleaseCandidateRef" + } + } + ], + "responses": { + "200": { + "description": "The stored candidate.", + "content": { + "application/json": { + "schema": { + "$ref": "./release_candidate_schema.json#/definitions/ReleaseCandidateResponse" + } + } + } + }, + "401": { + "description": "unauthenticated. Closed envelope.", + "content": { + "application/json": { + "schema": { + "$ref": "./release_acceptance_schema.json#/definitions/ReleaseRefusal" + } + } + } + }, + "403": { + "description": "forbidden. Closed envelope.", + "content": { + "application/json": { + "schema": { + "$ref": "./release_acceptance_schema.json#/definitions/ReleaseRefusal" + } + } + } + }, + "404": { + "description": "reference_not_found. Unknown, foreign or invisible references are indistinguishable. Closed envelope.", + "content": { + "application/json": { + "schema": { + "$ref": "./release_candidate_schema.json#/definitions/ReleaseCandidateNotFound" + } + } + } + }, + "429": { + "description": "Too many requests \u2014 rate limit exceeded.", + "content": { + "application/json": { + "schema": { + "$ref": "./release_candidate_schema.json#/definitions/ReleaseCandidateRateLimited" + } + } + }, + "headers": { + "Retry-After": { + "$ref": "../rate_limit_info_schema.json#/x-response-headers/Retry-After" + }, + "X-RateLimit-Limit": { + "$ref": "../rate_limit_info_schema.json#/x-response-headers/X-RateLimit-Limit" + }, + "X-RateLimit-Remaining": { + "$ref": "../rate_limit_info_schema.json#/x-response-headers/X-RateLimit-Remaining" + }, + "X-RateLimit-Reset": { + "$ref": "../rate_limit_info_schema.json#/x-response-headers/X-RateLimit-Reset" + } + } + }, + "500": { + "description": "internal_error. Closed envelope.", + "content": { + "application/json": { + "schema": { + "$ref": "./release_acceptance_schema.json#/definitions/ReleaseRefusal" + } + } + } + } + } + } + }, "/api/v1/projects/{project_id}/agents/{agent_ref}/release-acceptances": { "post": { "summary": "Record a person's acceptance of one candidate for release", @@ -30,6 +425,7 @@ "name": "agent_ref", "in": "path", "required": true, + "description": "A portal reads this reference from the agent detail response's `agent_ref`.", "schema": { "$ref": "../labels/label_common_schema.json#/definitions/AgentRef" } @@ -151,6 +547,7 @@ "name": "agent_ref", "in": "path", "required": true, + "description": "A portal reads this reference from the agent detail response's `agent_ref`.", "schema": { "$ref": "../labels/label_common_schema.json#/definitions/AgentRef" } @@ -275,6 +672,7 @@ "name": "agent_ref", "in": "path", "required": true, + "description": "A portal reads this reference from the agent detail response's `agent_ref`.", "schema": { "$ref": "../labels/label_common_schema.json#/definitions/AgentRef" } @@ -398,6 +796,7 @@ "name": "agent_ref", "in": "path", "required": true, + "description": "A portal reads this reference from the agent detail response's `agent_ref`.", "schema": { "$ref": "../labels/label_common_schema.json#/definitions/AgentRef" }