diff --git a/CHANGELOG.d/interpretation-run-collection-http.md b/CHANGELOG.d/interpretation-run-collection-http.md new file mode 100644 index 000000000..2077751b9 --- /dev/null +++ b/CHANGELOG.d/interpretation-run-collection-http.md @@ -0,0 +1 @@ +- `orchestrator_live` loopback `GET /v1/interpretation-runs` enumerates accepted hypothetical interpretation runs on `tepp-orchestrator-loopback` (ADR 0069). Metric-free identities only (`claim_status=hypothetical`, `scientific_authority=false`). `tepp.scientific_acceptance.v1` never appears. Does not infer causality. Naruon and LineageWeave are refused. Not interpretation-run CLI, not project-history collection GET, not persistence. diff --git a/DOCUMENTATION.md b/DOCUMENTATION.md index c75777834..7b3268308 100644 --- a/DOCUMENTATION.md +++ b/DOCUMENTATION.md @@ -14,6 +14,7 @@ TEPP's approved PRD v0.4 and implementation plan are the primary product baselin | contextual-orchestrator interpretation port | [`docs/connectors/contextual-orchestrator-interpretation-port.md`](docs/connectors/contextual-orchestrator-interpretation-port.md) | | Orchestrator live HTTP doctoring | [`docs/research/orchestrator-live-http.md`](docs/research/orchestrator-live-http.md) | | Interpretation-run CLI doctoring | [`docs/research/interpretation-run-cli.md`](docs/research/interpretation-run-cli.md) | +| Interpretation-run collection GET doctoring | [`docs/research/interpretation-run-collection-http.md`](docs/research/interpretation-run-collection-http.md) | | UML/runtime/scientific flows | [`docs/UML.md`](docs/UML.md) | | Logical/physical ERD | [`docs/ERD.md`](docs/ERD.md) | | Security policy | [`SECURITY.md`](SECURITY.md) | diff --git a/crates/orchestrator_live/src/http.rs b/crates/orchestrator_live/src/http.rs index cba272962..f95844d78 100644 --- a/crates/orchestrator_live/src/http.rs +++ b/crates/orchestrator_live/src/http.rs @@ -194,6 +194,25 @@ pub(crate) fn split_header_line(line: &str) -> Result<(&str, &str), Orchestrator pub(crate) fn refuse_live_headers( headers: &HashMap, +) -> Result<(), OrchestratorLiveError> { + refuse_common_live_headers(headers)?; + let _idempotency_key = header_value(headers, "idempotency-key")?; + Ok(()) +} + +/// Collection GET admits empty bodies and refuses `idempotency-key`. +pub(crate) fn refuse_collection_get_headers( + headers: &HashMap, +) -> Result<(), OrchestratorLiveError> { + refuse_common_live_headers(headers)?; + if headers.contains_key("idempotency-key") { + return Err(OrchestratorLiveError::InvalidWirePayload); + } + Ok(()) +} + +fn refuse_common_live_headers( + headers: &HashMap, ) -> Result<(), OrchestratorLiveError> { for (name, value) in headers { if header_is_credential(name) || header_is_credential(value) { @@ -213,7 +232,6 @@ pub(crate) fn refuse_live_headers( if header_value(headers, "tepp-contract-version")? != "1" { return Err(OrchestratorLiveError::InvalidWirePayload); } - let _idempotency_key = header_value(headers, "idempotency-key")?; Ok(()) } @@ -262,7 +280,8 @@ pub(crate) fn status_for(error: OrchestratorLiveError) -> (u16, &'static str) { mod tests { use super::{ declared_content_length, header_is_credential, map_io_error, parse_headers, - parse_request_line, refuse_live_headers, split_header_line, split_request, status_for, + parse_request_line, refuse_collection_get_headers, refuse_live_headers, split_header_line, + split_request, status_for, }; use crate::error::OrchestratorLiveError; use std::collections::HashMap; @@ -423,4 +442,36 @@ mod tests { assert!(header_is_credential("x-nvidia_nim_api_key")); assert!(!header_is_credential("x-safe-header")); } + + #[test] + fn collection_get_headers_refuse_idempotency_key_and_foreign_consumers() { + let mut headers = HashMap::new(); + headers.insert("host".into(), "127.0.0.1".into()); + headers.insert("content-type".into(), "application/json".into()); + headers.insert("tepp-consumer".into(), "contextual-orchestrator".into()); + headers.insert("tepp-contract-version".into(), "1".into()); + headers.insert("idempotency-key".into(), "idem".into()); + assert_eq!( + refuse_collection_get_headers(&headers), + Err(OrchestratorLiveError::InvalidWirePayload) + ); + headers.remove("idempotency-key"); + refuse_collection_get_headers(&headers).expect("collection headers"); + headers.insert("tepp-consumer".into(), "naruon".into()); + assert_eq!( + refuse_collection_get_headers(&headers), + Err(OrchestratorLiveError::InvalidWirePayload) + ); + headers.insert("tepp-consumer".into(), "lineageweave".into()); + assert_eq!( + refuse_collection_get_headers(&headers), + Err(OrchestratorLiveError::InvalidWirePayload) + ); + headers.insert("tepp-consumer".into(), "contextual-orchestrator".into()); + headers.insert("authorization".into(), "Bearer x".into()); + assert_eq!( + refuse_collection_get_headers(&headers), + Err(OrchestratorLiveError::AuthorizationDenied) + ); + } } diff --git a/crates/orchestrator_live/src/interpretation_run_collection_http.rs b/crates/orchestrator_live/src/interpretation_run_collection_http.rs new file mode 100644 index 000000000..6d2b4e169 --- /dev/null +++ b/crates/orchestrator_live/src/interpretation_run_collection_http.rs @@ -0,0 +1,556 @@ +//! Provider-owned interpretation-run collection GET contracts. +//! +//! GAP-003A unique slice: `GET /v1/interpretation-runs` enumerates accepted +//! hypothetical interpretation runs on `OrchestratorLiveService` / +//! `tepp-orchestrator-loopback` so operators do not guess idempotency keys. +//! Collection rows stay metric-free identities with `claim_status=hypothetical` +//! and `scientific_authority=false`. `tepp.scientific_acceptance.v1` never +//! appears. The page does not infer causality or call a model provider. This +//! module does not duplicate interpretation-run CLI (#425), project-history +//! collection GET (#424), collection CLI (#428), GET-by-id (#429), retrieval +//! CLI (#431), analysis-run collection GET (#368), Leiden, or GAP-010 +//! Figma/export. Persistence remains GAP-003B. Naruon and `LineageWeave` are +//! refused. `NaruonLiveService` stays POST-only. + +use serde::{Deserialize, Serialize}; + +use crate::error::OrchestratorLiveError; +use crate::interpretation_run_cli::CONTEXTUAL_ORCHESTRATOR_CONSUMER_CODE; +use crate::mode::OrchestrationMode; +use crate::request::{ + DEFAULT_INTERPRETATION_BYTE_LIMIT, HYPOTHETICAL_CLAIM_STATUS, + INTERPRETATION_RUN_CONTRACT_VERSION, INTERPRETATION_RUN_PATH, from_json, + host_implies_table_access, require_byte_limit, require_contract_version, require_nonempty, + to_json, +}; + +/// Default page size for loopback interpretation-run collection GET. +pub const INTERPRETATION_RUN_COLLECTION_DEFAULT_LIMIT: usize = 32; + +/// Maximum page size accepted on loopback interpretation-run collection GET. +pub const INTERPRETATION_RUN_COLLECTION_MAX_LIMIT: usize = 64; + +/// Maximum opaque cursor / idempotency-key length on the collection path. +pub const INTERPRETATION_RUN_COLLECTION_CURSOR_MAX_LEN: usize = 128; + +const FORBIDDEN_COLLECTION_KEYS: [&str; 14] = [ + "rmse", + "rmse_standard_error", + "mean_bias", + "bias_standard_error", + "interval_coverage", + "se_gate_accepted", + "scientific_acceptance", + "evidence_span_ids", + "tenant_workspace_id", + "compute_budget_tokens", + "causal_score", + "findings", + "evidence_text", + "report", +]; + +/// One metric-free collection row for an accepted interpretation run. +#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] +#[serde(deny_unknown_fields)] +pub struct InterpretationRunCollectionItem { + /// Server-assigned opaque interpretation-run identity. + pub interpretation_run_id: String, + /// Exact request idempotency key that minted the stored run. + pub idempotency_key: String, + /// Selected orchestration mode. + pub orchestration_mode: OrchestrationMode, + /// Fixed claim boundary: accepted output is hypothetical. + pub claim_status: String, + /// Always `false`; LLM output is never scientific authority. + pub scientific_authority: bool, +} + +impl InterpretationRunCollectionItem { + /// Construct a validated metric-free collection row. + /// + /// # Errors + /// + /// Returns a fail-closed error for empty identities or a non-hypothetical + /// claim. + pub fn new( + interpretation_run_id: impl Into, + idempotency_key: impl Into, + orchestration_mode: OrchestrationMode, + claim_status: impl Into, + scientific_authority: bool, + ) -> Result { + let item = Self { + interpretation_run_id: interpretation_run_id.into(), + idempotency_key: idempotency_key.into(), + orchestration_mode, + claim_status: claim_status.into(), + scientific_authority, + }; + item.validate()?; + Ok(item) + } + + fn validate(&self) -> Result<(), OrchestratorLiveError> { + require_nonempty(&self.interpretation_run_id)?; + require_nonempty(&self.idempotency_key)?; + if self.idempotency_key.len() > INTERPRETATION_RUN_COLLECTION_CURSOR_MAX_LEN { + return Err(OrchestratorLiveError::LimitExceeded); + } + if self.claim_status != HYPOTHETICAL_CLAIM_STATUS || self.scientific_authority { + return Err(OrchestratorLiveError::ScientificAuthorityRefused); + } + Ok(()) + } +} + +/// Metric-free interpretation-run collection page. +#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] +#[serde(deny_unknown_fields)] +pub struct InterpretationRunCollection { + /// Semantic contract version. + pub contract_version: u16, + /// Metric-free rows on this page. + pub items: Vec, + /// Exclusive cursor for the next page, when more rows exist. + #[serde(skip_serializing_if = "Option::is_none")] + pub next_cursor: Option, +} + +impl InterpretationRunCollection { + /// Construct a validated collection page. + /// + /// # Errors + /// + /// Returns a fail-closed error for an oversized page or a hostile cursor. + pub fn new( + items: Vec, + next_cursor: Option, + ) -> Result { + if items.len() > INTERPRETATION_RUN_COLLECTION_MAX_LIMIT { + return Err(OrchestratorLiveError::LimitExceeded); + } + for item in &items { + item.validate()?; + } + if let Some(cursor) = next_cursor.as_deref() { + parse_interpretation_run_collection_page_cursor(Some(cursor))?; + } + Ok(Self { + contract_version: INTERPRETATION_RUN_CONTRACT_VERSION, + items, + next_cursor, + }) + } + + /// Parse a collection page. + /// + /// # Errors + /// + /// Returns a size, JSON, version, or claim-boundary error. + pub fn from_json(payload: &str) -> Result { + require_byte_limit(payload, DEFAULT_INTERPRETATION_BYTE_LIMIT)?; + refuse_metrics_on_interpretation_run_collection_payload(payload)?; + let collection: Self = from_json(payload)?; + require_contract_version( + collection.contract_version, + INTERPRETATION_RUN_CONTRACT_VERSION, + )?; + InterpretationRunCollection::new(collection.items, collection.next_cursor) + } + + /// Serialize a validated collection page. + /// + /// # Errors + /// + /// Returns a validation or serialization error. + pub fn to_json(&self) -> Result { + require_contract_version(self.contract_version, INTERPRETATION_RUN_CONTRACT_VERSION)?; + InterpretationRunCollection::new(self.items.clone(), self.next_cursor.clone())?; + let payload = to_json(self)?; + refuse_metrics_on_interpretation_run_collection_payload(&payload)?; + Ok(payload) + } +} + +/// Typed GET exchange for interpretation-run collection. +#[derive(Clone, Debug, Eq, PartialEq)] +pub struct InterpretationRunCollectionHttpExchange { + /// HTTP method, always `GET`. + pub method: &'static str, + /// Absolute HTTPS target ending in [`INTERPRETATION_RUN_PATH`]. + pub target_url: String, + /// Exact version, consumer, and content headers. No credentials. + pub headers: Vec<(String, String)>, + /// GET body, always empty. + pub body: String, +} + +/// Whether a path is the interpretation-run collection resource. +#[must_use] +pub fn is_interpretation_run_collection_path(path: &str) -> bool { + path == INTERPRETATION_RUN_PATH +} + +/// Parse the optional `tepp-page-limit` header. +/// +/// # Errors +/// +/// Returns [`OrchestratorLiveError::InvalidWirePayload`] for a non-integer or +/// zero limit, and [`OrchestratorLiveError::LimitExceeded`] above the maximum. +pub fn parse_interpretation_run_collection_page_limit( + raw: Option<&str>, +) -> Result { + let Some(raw) = raw else { + return Ok(INTERPRETATION_RUN_COLLECTION_DEFAULT_LIMIT); + }; + require_nonempty(raw)?; + let limit: usize = raw + .parse() + .map_err(|_| OrchestratorLiveError::InvalidWirePayload)?; + if limit == 0 { + return Err(OrchestratorLiveError::InvalidWirePayload); + } + if limit > INTERPRETATION_RUN_COLLECTION_MAX_LIMIT { + return Err(OrchestratorLiveError::LimitExceeded); + } + Ok(limit) +} + +/// Parse the optional exclusive `tepp-page-cursor` header. +/// +/// # Errors +/// +/// Returns [`OrchestratorLiveError::InvalidWirePayload`] for an empty cursor +/// and [`OrchestratorLiveError::LimitExceeded`] when oversized. +pub fn parse_interpretation_run_collection_page_cursor( + raw: Option<&str>, +) -> Result, OrchestratorLiveError> { + let Some(raw) = raw else { + return Ok(None); + }; + require_nonempty(raw)?; + if raw.contains('/') || raw.contains('\0') { + return Err(OrchestratorLiveError::InvalidWirePayload); + } + if raw.len() > INTERPRETATION_RUN_COLLECTION_CURSOR_MAX_LEN { + return Err(OrchestratorLiveError::LimitExceeded); + } + Ok(Some(raw.to_owned())) +} + +/// Page stored collection rows with an exclusive idempotency-key cursor. +#[must_use] +pub fn page_interpretation_run_collection_items( + mut items: Vec, + cursor: Option<&str>, + limit: usize, +) -> (Vec, Option) { + items.sort_by(|left, right| left.idempotency_key.cmp(&right.idempotency_key)); + let start = cursor.map_or(0, |cursor| { + items + .iter() + .position(|item| item.idempotency_key.as_str() > cursor) + .unwrap_or(items.len()) + }); + let end = (start + limit).min(items.len()); + let next_cursor = if end < items.len() { + Some(items[end - 1].idempotency_key.clone()) + } else { + None + }; + (items[start..end].to_vec(), next_cursor) +} + +/// Refuse metric, evidence, and causal-score keys on collection JSON. +/// +/// Empty payloads are admitted for the GET request body. +/// +/// # Errors +/// +/// Returns [`OrchestratorLiveError::InvalidWirePayload`] when a forbidden key +/// or `tepp.scientific_acceptance.v1` appears, or nonempty JSON is not an +/// object. +pub fn refuse_metrics_on_interpretation_run_collection_payload( + payload: &str, +) -> Result<(), OrchestratorLiveError> { + if payload.trim().is_empty() { + return Ok(()); + } + if payload.contains("tepp.scientific_acceptance.v1") { + return Err(OrchestratorLiveError::InvalidWirePayload); + } + let value: serde_json::Value = + serde_json::from_str(payload).map_err(|_| OrchestratorLiveError::InvalidWirePayload)?; + if !value.is_object() { + return Err(OrchestratorLiveError::InvalidWirePayload); + } + refuse_metrics_on_json(&value) +} + +fn refuse_metrics_on_json(value: &serde_json::Value) -> Result<(), OrchestratorLiveError> { + match value { + serde_json::Value::Object(object) => { + if FORBIDDEN_COLLECTION_KEYS + .iter() + .any(|key| object.contains_key(*key)) + { + return Err(OrchestratorLiveError::InvalidWirePayload); + } + for nested in object.values() { + refuse_metrics_on_json(nested)?; + } + Ok(()) + } + serde_json::Value::Array(items) => { + for nested in items { + refuse_metrics_on_json(nested)?; + } + Ok(()) + } + _ => Ok(()), + } +} + +/// Build a credential-free contextual-orchestrator collection GET exchange. +/// +/// # Errors +/// +/// Returns a fail-closed origin or pagination error. +pub fn contextual_orchestrator_interpretation_run_collection_exchange( + origin: &str, + page_cursor: Option<&str>, + page_limit: Option<&str>, +) -> Result { + require_nonempty(origin)?; + if !origin.starts_with("https://") || origin.ends_with('/') { + return Err(OrchestratorLiveError::InvalidWirePayload); + } + let rest = origin + .strip_prefix("https://") + .ok_or(OrchestratorLiveError::InvalidWirePayload)?; + if rest.contains('@') || rest.contains('?') || rest.contains('#') || rest.contains('\\') { + return Err(OrchestratorLiveError::InvalidWirePayload); + } + if host_implies_table_access(rest) { + return Err(OrchestratorLiveError::InvalidWirePayload); + } + parse_interpretation_run_collection_page_cursor(page_cursor)?; + parse_interpretation_run_collection_page_limit(page_limit)?; + let mut headers = vec![ + ("content-type".into(), "application/json".into()), + ( + "tepp-consumer".into(), + CONTEXTUAL_ORCHESTRATOR_CONSUMER_CODE.into(), + ), + ("tepp-contract-version".into(), "1".into()), + ]; + if let Some(cursor) = page_cursor { + headers.push(("tepp-page-cursor".into(), cursor.to_owned())); + } + if let Some(limit) = page_limit { + headers.push(("tepp-page-limit".into(), limit.to_owned())); + } + Ok(InterpretationRunCollectionHttpExchange { + method: "GET", + target_url: format!("{origin}{INTERPRETATION_RUN_PATH}"), + headers, + body: String::new(), + }) +} + +#[cfg(test)] +mod tests { + use super::{ + INTERPRETATION_RUN_COLLECTION_CURSOR_MAX_LEN, INTERPRETATION_RUN_COLLECTION_MAX_LIMIT, + InterpretationRunCollection, InterpretationRunCollectionItem, + contextual_orchestrator_interpretation_run_collection_exchange, + is_interpretation_run_collection_path, page_interpretation_run_collection_items, + parse_interpretation_run_collection_page_cursor, + parse_interpretation_run_collection_page_limit, + refuse_metrics_on_interpretation_run_collection_payload, + }; + use crate::error::OrchestratorLiveError; + use crate::mode::OrchestrationMode; + use crate::request::INTERPRETATION_RUN_PATH; + + fn sample_item(id: &str, idem: &str) -> InterpretationRunCollectionItem { + InterpretationRunCollectionItem::new( + id, + idem, + OrchestrationMode::Direct, + "hypothetical", + false, + ) + .expect("item") + } + + #[test] + fn collection_exchange_is_metric_free_get_without_credentials() { + let exchange = contextual_orchestrator_interpretation_run_collection_exchange( + "https://tepp.example.test", + Some("idem-a"), + Some("8"), + ) + .expect("exchange"); + assert_eq!(exchange.method, "GET"); + assert!(exchange.target_url.ends_with(INTERPRETATION_RUN_PATH)); + assert!(exchange.body.is_empty()); + assert!( + !exchange + .headers + .iter() + .any(|(name, _)| name.eq_ignore_ascii_case("authorization") + || name.eq_ignore_ascii_case("idempotency-key")) + ); + assert!(is_interpretation_run_collection_path( + INTERPRETATION_RUN_PATH + )); + assert!(!is_interpretation_run_collection_path( + "/v1/interpretation-runs/extra" + )); + let json = + InterpretationRunCollection::new(vec![sample_item("orch-run-1", "idem-a")], None) + .expect("page") + .to_json() + .expect("json"); + assert!(!json.contains("rmse")); + assert!(!json.contains("evidence_span_ids")); + assert!(!json.contains("tepp.scientific_acceptance.v1")); + InterpretationRunCollection::from_json(&json).expect("roundtrip"); + } + + #[test] + fn collection_payloads_and_origins_fail_closed() { + assert_eq!( + refuse_metrics_on_interpretation_run_collection_payload(""), + Ok(()) + ); + assert_eq!( + refuse_metrics_on_interpretation_run_collection_payload(r#"{"rmse":1.0}"#), + Err(OrchestratorLiveError::InvalidWirePayload) + ); + assert_eq!( + refuse_metrics_on_interpretation_run_collection_payload(r#"{"causal_score":1}"#), + Err(OrchestratorLiveError::InvalidWirePayload) + ); + assert_eq!( + refuse_metrics_on_interpretation_run_collection_payload( + r#"{"schema_version":"tepp.scientific_acceptance.v1"}"# + ), + Err(OrchestratorLiveError::InvalidWirePayload) + ); + assert_eq!( + refuse_metrics_on_interpretation_run_collection_payload("[1]"), + Err(OrchestratorLiveError::InvalidWirePayload) + ); + assert_eq!( + contextual_orchestrator_interpretation_run_collection_exchange( + "http://insecure.example", + None, + None + ), + Err(OrchestratorLiveError::InvalidWirePayload) + ); + assert_eq!( + contextual_orchestrator_interpretation_run_collection_exchange( + "https://user:pass@tepp.example.test", + None, + None + ), + Err(OrchestratorLiveError::InvalidWirePayload) + ); + assert_eq!( + contextual_orchestrator_interpretation_run_collection_exchange( + "https://postgres.example.test", + None, + None + ), + Err(OrchestratorLiveError::InvalidWirePayload) + ); + } + + #[test] + fn collection_pagination_and_claim_boundary_fail_closed() { + assert_eq!( + parse_interpretation_run_collection_page_limit(Some("0")), + Err(OrchestratorLiveError::InvalidWirePayload) + ); + assert_eq!( + parse_interpretation_run_collection_page_limit(Some("nope")), + Err(OrchestratorLiveError::InvalidWirePayload) + ); + assert_eq!( + parse_interpretation_run_collection_page_limit(Some( + &(INTERPRETATION_RUN_COLLECTION_MAX_LIMIT + 1).to_string() + )), + Err(OrchestratorLiveError::LimitExceeded) + ); + assert_eq!( + parse_interpretation_run_collection_page_cursor(Some("idem/slash")), + Err(OrchestratorLiveError::InvalidWirePayload) + ); + assert_eq!( + parse_interpretation_run_collection_page_cursor(Some("idem\0nul")), + Err(OrchestratorLiveError::InvalidWirePayload) + ); + assert_eq!( + parse_interpretation_run_collection_page_cursor(Some( + &"k".repeat(INTERPRETATION_RUN_COLLECTION_CURSOR_MAX_LEN + 1) + )), + Err(OrchestratorLiveError::LimitExceeded) + ); + assert_eq!( + InterpretationRunCollectionItem::new( + " ", + "idem-a", + OrchestrationMode::Direct, + "hypothetical", + false, + ) + .expect_err("empty id"), + OrchestratorLiveError::InvalidWirePayload + ); + assert_eq!( + InterpretationRunCollectionItem::new( + "orch-run-1", + "idem-a", + OrchestrationMode::Direct, + "accepted", + false, + ) + .expect_err("claim"), + OrchestratorLiveError::ScientificAuthorityRefused + ); + assert_eq!( + InterpretationRunCollectionItem::new( + "orch-run-1", + "idem-a", + OrchestrationMode::Direct, + "hypothetical", + true, + ) + .expect_err("authority"), + OrchestratorLiveError::ScientificAuthorityRefused + ); + let first = sample_item("orch-run-1", "idem-a"); + let second = sample_item("orch-run-2", "idem-b"); + let (page, next) = + page_interpretation_run_collection_items(vec![second.clone(), first.clone()], None, 1); + assert_eq!(page, vec![first.clone()]); + assert_eq!(next.as_deref(), Some("idem-a")); + let (rest, done) = page_interpretation_run_collection_items( + vec![first.clone(), second.clone()], + Some("idem-a"), + 1, + ); + assert_eq!(rest, vec![second.clone()]); + assert_eq!(done, None); + InterpretationRunCollection::new(vec![first], Some("idem-a".into())).expect("page"); + assert_eq!( + InterpretationRunCollection::from_json(r#"{"contract_version":9,"items":[]}"#) + .expect_err("version"), + OrchestratorLiveError::UnsupportedContractVersion + ); + } +} diff --git a/crates/orchestrator_live/src/lib.rs b/crates/orchestrator_live/src/lib.rs index c56585d46..d555f1025 100644 --- a/crates/orchestrator_live/src/lib.rs +++ b/crates/orchestrator_live/src/lib.rs @@ -2,8 +2,10 @@ #![deny(missing_docs)] //! Loopback live HTTP/1.1 listener for contextual-orchestrator interpretation. //! -//! The listener accepts `POST /v1/interpretation-runs` on loopback only. -//! Accepted output is always hypothetical and never scientific authority. +//! The listener accepts `POST /v1/interpretation-runs` and +//! `GET /v1/interpretation-runs` on loopback only. Accepted output is always +//! hypothetical and never scientific authority. Collection GET enumerates +//! metric-free identities so operators do not guess idempotency keys. //! Table-access hosts, review/Copilot/GitHub credentials, and //! `COPILOT_GITHUB_TOKEN` fail closed. This crate does not implement TLS //! termination or call a model provider (ADR 0010; ADR 0011). The published @@ -14,6 +16,7 @@ mod error; mod http; mod interpretation_run_cli; +mod interpretation_run_collection_http; mod mode; mod request; mod service; @@ -50,6 +53,30 @@ pub use interpretation_run_cli::read_interpretation_run_cli_stdin; pub use interpretation_run_cli::refuse_metrics_on_interpretation_run_cli_payload; /// Filter interpretation-run CLI stdout so the accepted run stays hypothetical. pub use interpretation_run_cli::render_interpretation_run_cli_stdout; +/// Maximum opaque cursor length on interpretation-run collection GET. +pub use interpretation_run_collection_http::INTERPRETATION_RUN_COLLECTION_CURSOR_MAX_LEN; +/// Default page size for interpretation-run collection GET. +pub use interpretation_run_collection_http::INTERPRETATION_RUN_COLLECTION_DEFAULT_LIMIT; +/// Maximum page size for interpretation-run collection GET. +pub use interpretation_run_collection_http::INTERPRETATION_RUN_COLLECTION_MAX_LIMIT; +/// Metric-free interpretation-run collection page. +pub use interpretation_run_collection_http::InterpretationRunCollection; +/// Typed GET exchange for interpretation-run collection. +pub use interpretation_run_collection_http::InterpretationRunCollectionHttpExchange; +/// One metric-free interpretation-run collection row. +pub use interpretation_run_collection_http::InterpretationRunCollectionItem; +/// Build a credential-free contextual-orchestrator collection GET exchange. +pub use interpretation_run_collection_http::contextual_orchestrator_interpretation_run_collection_exchange; +/// Whether a path is the interpretation-run collection resource. +pub use interpretation_run_collection_http::is_interpretation_run_collection_path; +/// Page stored collection rows with an exclusive idempotency-key cursor. +pub use interpretation_run_collection_http::page_interpretation_run_collection_items; +/// Parse the optional exclusive `tepp-page-cursor` header. +pub use interpretation_run_collection_http::parse_interpretation_run_collection_page_cursor; +/// Parse the optional `tepp-page-limit` header. +pub use interpretation_run_collection_http::parse_interpretation_run_collection_page_limit; +/// Refuse metric, evidence, and causal-score keys on collection JSON. +pub use interpretation_run_collection_http::refuse_metrics_on_interpretation_run_collection_payload; /// Closed ADR 0010 orchestration-mode vocabulary. pub use mode::OrchestrationMode; /// Default maximum interpretation-run JSON payload size in bytes. @@ -58,7 +85,7 @@ pub use request::DEFAULT_INTERPRETATION_BYTE_LIMIT; pub use request::HYPOTHETICAL_CLAIM_STATUS; /// Supported interpretation-run contract version. pub use request::INTERPRETATION_RUN_CONTRACT_VERSION; -/// Versioned path contextual-orchestrator may POST. +/// Versioned path contextual-orchestrator may POST or GET. pub use request::INTERPRETATION_RUN_PATH; /// Accepted hypothetical interpretation-run response. pub use request::InterpretationRunAccepted; diff --git a/crates/orchestrator_live/src/request.rs b/crates/orchestrator_live/src/request.rs index 4d6d9d715..a588d974d 100644 --- a/crates/orchestrator_live/src/request.rs +++ b/crates/orchestrator_live/src/request.rs @@ -8,7 +8,7 @@ use crate::mode::OrchestrationMode; /// Supported interpretation-run contract version. pub const INTERPRETATION_RUN_CONTRACT_VERSION: u16 = 1; -/// Versioned path contextual-orchestrator may POST. +/// Versioned path contextual-orchestrator may POST or GET. pub const INTERPRETATION_RUN_PATH: &str = "/v1/interpretation-runs"; /// Default maximum interpretation-run JSON payload size in bytes. diff --git a/crates/orchestrator_live/src/service.rs b/crates/orchestrator_live/src/service.rs index 06f4c5416..db39dcfd1 100644 --- a/crates/orchestrator_live/src/service.rs +++ b/crates/orchestrator_live/src/service.rs @@ -6,7 +6,14 @@ use std::net::{SocketAddr, TcpListener, TcpStream}; use crate::error::OrchestratorLiveError; use crate::http::{ OrchestratorLiveResponse, header_value, map_io_error, parse_headers, parse_request_line, - read_http_request, refuse_live_headers, split_request, status_for, write_response, + read_http_request, refuse_collection_get_headers, refuse_live_headers, split_request, + status_for, write_response, +}; +use crate::interpretation_run_collection_http::{ + InterpretationRunCollection, InterpretationRunCollectionItem, + is_interpretation_run_collection_path, page_interpretation_run_collection_items, + parse_interpretation_run_collection_page_cursor, + parse_interpretation_run_collection_page_limit, }; use crate::request::{ INTERPRETATION_RUN_PATH, InterpretationRunAccepted, InterpretationRunRequest, to_json, @@ -17,6 +24,8 @@ use crate::request::{ /// Production interchange remains optional and versioned. This listener binds /// loopback TCP so tests and standalone operation can prove request handling /// without TLS termination, table access, or scientific-authority promotion. +/// `GET /v1/interpretation-runs` enumerates accepted hypothetical runs as +/// metric-free identities. #[derive(Debug)] pub struct OrchestratorLiveService { listener: Option, @@ -162,14 +171,59 @@ impl OrchestratorLiveService { let mut lines = header_block.split("\r\n"); let request_line = lines.next().unwrap_or(""); let (method, path) = parse_request_line(request_line)?; + let headers = parse_headers(lines)?; + if method == "GET" { + return self.list_interpretation_runs(path, &headers, body); + } if method != "POST" || path != INTERPRETATION_RUN_PATH { return Err(OrchestratorLiveError::InvalidWirePayload); } - let headers = parse_headers(lines)?; refuse_live_headers(&headers)?; self.accept_interpretation_run(&headers, body) } + fn list_interpretation_runs( + &self, + path: &str, + headers: &HashMap, + body: &str, + ) -> Result { + if !is_interpretation_run_collection_path(path) { + return Err(OrchestratorLiveError::InvalidWirePayload); + } + if !body.is_empty() { + return Err(OrchestratorLiveError::InvalidWirePayload); + } + refuse_collection_get_headers(headers)?; + let limit = parse_interpretation_run_collection_page_limit( + headers.get("tepp-page-limit").map(String::as_str), + )?; + let cursor = parse_interpretation_run_collection_page_cursor( + headers.get("tepp-page-cursor").map(String::as_str), + )?; + let items = self + .accepted_runs + .values() + .map(|(_, accepted)| { + InterpretationRunCollectionItem::new( + accepted.interpretation_run_id(), + accepted.idempotency_key(), + accepted.orchestration_mode(), + accepted.claim_status(), + accepted.scientific_authority(), + ) + }) + .collect::, _>>()?; + let (page, next_cursor) = + page_interpretation_run_collection_items(items, cursor.as_deref(), limit); + let collection = InterpretationRunCollection::new(page, next_cursor)?; + Ok(OrchestratorLiveResponse::json( + 200, + "OK", + collection.to_json()?, + )) + } + fn accept_interpretation_run( &mut self, headers: &HashMap, diff --git a/crates/orchestrator_live/tests/interpretation_run_collection_http_contract.rs b/crates/orchestrator_live/tests/interpretation_run_collection_http_contract.rs new file mode 100644 index 000000000..e63c4c4a4 --- /dev/null +++ b/crates/orchestrator_live/tests/interpretation_run_collection_http_contract.rs @@ -0,0 +1,80 @@ +//! Contract tests for loopback `GET /v1/interpretation-runs`. + +use orchestrator_live::{ + INTERPRETATION_RUN_PATH, InterpretationRunCollection, InterpretationRunCollectionItem, + OrchestrationMode, OrchestratorLiveError, + contextual_orchestrator_interpretation_run_collection_exchange, + is_interpretation_run_collection_path, refuse_metrics_on_interpretation_run_collection_payload, +}; + +#[test] +fn interpretation_run_collection_is_metric_free_get_without_credentials() { + assert!(is_interpretation_run_collection_path( + INTERPRETATION_RUN_PATH + )); + assert!(!is_interpretation_run_collection_path( + "/v1/interpretation-runs/extra" + )); + let item = InterpretationRunCollectionItem::new( + "orch-run-1", + "idem-1", + OrchestrationMode::Direct, + "hypothetical", + false, + ) + .expect("item"); + let page = InterpretationRunCollection::new(vec![item], None).expect("page"); + let json = page.to_json().expect("json"); + assert!(!json.contains("rmse")); + assert!(!json.contains("tepp.scientific_acceptance.v1")); + assert!(!json.contains("evidence_span_ids")); + assert!(!json.contains("tenant_workspace_id")); + assert!(!json.contains("compute_budget_tokens")); + assert!(!json.contains("causal_score")); + assert!(json.contains("\"claim_status\":\"hypothetical\"")); + assert!(json.contains("\"scientific_authority\":false")); + let exchange = contextual_orchestrator_interpretation_run_collection_exchange( + "https://tepp.example.test", + None, + None, + ) + .expect("exchange"); + assert_eq!(exchange.method, "GET"); + assert!(exchange.target_url.ends_with("/v1/interpretation-runs")); + assert!(exchange.body.is_empty()); + assert!( + !exchange + .headers + .iter() + .any(|(name, _)| name.eq_ignore_ascii_case("authorization") + || name.eq_ignore_ascii_case("idempotency-key")) + ); +} + +#[test] +fn interpretation_run_collection_refuses_metrics_evidence_and_insecure_origins() { + assert_eq!( + refuse_metrics_on_interpretation_run_collection_payload(r#"{"rmse":1.0}"#), + Err(OrchestratorLiveError::InvalidWirePayload) + ); + assert_eq!( + refuse_metrics_on_interpretation_run_collection_payload(r#"{"evidence_text":"x"}"#), + Err(OrchestratorLiveError::InvalidWirePayload) + ); + assert_eq!( + refuse_metrics_on_interpretation_run_collection_payload(r#"{"findings":[]}"#), + Err(OrchestratorLiveError::InvalidWirePayload) + ); + assert_eq!( + contextual_orchestrator_interpretation_run_collection_exchange( + "http://insecure.example", + None, + None + ), + Err(OrchestratorLiveError::InvalidWirePayload) + ); + assert!(!is_interpretation_run_collection_path("/v1/analysis-runs")); + assert!(!is_interpretation_run_collection_path( + "/v1/project-histories" + )); +} diff --git a/crates/orchestrator_live/tests/live_http_contract.rs b/crates/orchestrator_live/tests/live_http_contract.rs index d16f081fd..5a60de060 100644 --- a/crates/orchestrator_live/tests/live_http_contract.rs +++ b/crates/orchestrator_live/tests/live_http_contract.rs @@ -8,9 +8,9 @@ use std::time::Duration; use orchestrator_live::{ DEFAULT_INTERPRETATION_BYTE_LIMIT, INTERPRETATION_RUN_CONTRACT_VERSION, - INTERPRETATION_RUN_PATH, InterpretationRunAccepted, InterpretationRunRequest, - LIVE_HEADER_BYTE_LIMIT, LIVE_HEADER_COUNT_LIMIT, OrchestrationMode, OrchestratorLiveError, - OrchestratorLiveService, + INTERPRETATION_RUN_PATH, InterpretationRunAccepted, InterpretationRunCollection, + InterpretationRunRequest, LIVE_HEADER_BYTE_LIMIT, LIVE_HEADER_COUNT_LIMIT, OrchestrationMode, + OrchestratorLiveError, OrchestratorLiveService, }; fn sample_request() -> InterpretationRunRequest { @@ -38,6 +38,15 @@ fn orchestrator_headers(idempotency_key: &str) -> Vec<(String, String)> { ] } +fn collection_headers() -> Vec<(String, String)> { + vec![ + ("Host".into(), "127.0.0.1".into()), + ("content-type".into(), "application/json".into()), + ("tepp-consumer".into(), "contextual-orchestrator".into()), + ("tepp-contract-version".into(), "1".into()), + ] +} + fn http_request(method: &str, path: &str, headers: &[(String, String)], body: &str) -> String { let mut request = format!("{method} {path} HTTP/1.1\r\n"); for (name, value) in headers { @@ -295,6 +304,174 @@ fn handle_http_refuses_methods_paths_and_table_hosts() { assert_eq!(service.handle_http_request(&http10).status_code, 400); } +#[test] +fn handle_http_enumerates_interpretation_runs_on_collection_get() { + let mut service = OrchestratorLiveService::new(); + let empty = service.handle_http_request(&http_request( + "GET", + INTERPRETATION_RUN_PATH, + &collection_headers(), + "", + )); + assert_eq!(empty.status_code, 200); + let empty_page = InterpretationRunCollection::from_json(&empty.body).expect("empty"); + assert!(empty_page.items.is_empty()); + assert_eq!(empty_page.next_cursor, None); + + let first = sample_request(); + assert_eq!( + service + .handle_http_request(&interpretation_http(&first)) + .status_code, + 202 + ); + let second = InterpretationRunRequest::new( + INTERPRETATION_RUN_CONTRACT_VERSION, + "orch-live-idem-002", + "orch-tenant-workspace-demo", + "tepp-snapshot-demo-001", + "2026-08-01T00:00:00Z", + OrchestrationMode::Verify, + 2048, + vec!["span-001".into()], + false, + ) + .expect("second"); + assert_eq!( + service + .handle_http_request(&interpretation_http(&second)) + .status_code, + 202 + ); + + let listed = service.handle_http_request(&http_request( + "GET", + INTERPRETATION_RUN_PATH, + &collection_headers(), + "", + )); + assert_eq!(listed.status_code, 200); + let page = InterpretationRunCollection::from_json(&listed.body).expect("page"); + assert_eq!(page.items.len(), 2); + assert_eq!(page.items[0].idempotency_key, "orch-live-idem-001"); + assert_eq!(page.items[1].idempotency_key, "orch-live-idem-002"); + assert!( + page.items + .iter() + .all(|item| item.claim_status == "hypothetical") + ); + assert!(page.items.iter().all(|item| !item.scientific_authority)); + assert!(!listed.body.contains("rmse")); + assert!(!listed.body.contains("evidence_span_ids")); + assert!(!listed.body.contains("tepp.scientific_acceptance.v1")); + + let mut limited_headers = collection_headers(); + limited_headers.push(("tepp-page-limit".into(), "1".into())); + let limited = service.handle_http_request(&http_request( + "GET", + INTERPRETATION_RUN_PATH, + &limited_headers, + "", + )); + assert_eq!(limited.status_code, 200); + let limited_page = InterpretationRunCollection::from_json(&limited.body).expect("limited"); + assert_eq!(limited_page.items.len(), 1); + assert_eq!( + limited_page.next_cursor.as_deref(), + Some("orch-live-idem-001") + ); + + let mut cursor_headers = collection_headers(); + cursor_headers.push(("tepp-page-cursor".into(), "orch-live-idem-001".into())); + cursor_headers.push(("tepp-page-limit".into(), "1".into())); + let rest = service.handle_http_request(&http_request( + "GET", + INTERPRETATION_RUN_PATH, + &cursor_headers, + "", + )); + assert_eq!(rest.status_code, 200); + let rest_page = InterpretationRunCollection::from_json(&rest.body).expect("rest"); + assert_eq!(rest_page.items.len(), 1); + assert_eq!(rest_page.items[0].idempotency_key, "orch-live-idem-002"); + assert_eq!(rest_page.next_cursor, None); +} + +#[test] +fn handle_http_collection_get_refuses_foreign_consumers_and_hostile_headers() { + let mut service = OrchestratorLiveService::new(); + assert_eq!( + service + .handle_http_request(&http_request( + "GET", + "/v1/interpretation-runs/extra", + &collection_headers(), + "", + )) + .status_code, + 400 + ); + assert_eq!( + service + .handle_http_request(&http_request( + "GET", + INTERPRETATION_RUN_PATH, + &collection_headers(), + "{}", + )) + .status_code, + 400 + ); + let mut with_idem = collection_headers(); + with_idem.push(("idempotency-key".into(), "orch-live-idem-001".into())); + assert_eq!( + service + .handle_http_request(&http_request( + "GET", + INTERPRETATION_RUN_PATH, + &with_idem, + "", + )) + .status_code, + 400 + ); + for consumer in ["naruon", "lineageweave"] { + let mut foreign = collection_headers(); + foreign.retain(|(name, _)| !name.eq_ignore_ascii_case("tepp-consumer")); + foreign.push(("tepp-consumer".into(), consumer.into())); + assert_eq!( + service + .handle_http_request(&http_request("GET", INTERPRETATION_RUN_PATH, &foreign, "",)) + .status_code, + 400, + "consumer={consumer}" + ); + } + let mut slash_cursor = collection_headers(); + slash_cursor.push(("tepp-page-cursor".into(), "idem/slash".into())); + assert_eq!( + service + .handle_http_request(&http_request( + "GET", + INTERPRETATION_RUN_PATH, + &slash_cursor, + "", + )) + .status_code, + 400 + ); + let mut credential = collection_headers(); + credential.push(("Authorization".into(), "Bearer review-agent".into())); + let denied = service.handle_http_request(&http_request( + "GET", + INTERPRETATION_RUN_PATH, + &credential, + "", + )); + assert_eq!(denied.status_code, 403); + assert_eq!(error_code(&denied.body), "authorization_denied"); +} + #[test] fn handle_http_refuses_credential_headers_and_reserved_overrides() { let mut service = OrchestratorLiveService::new(); diff --git a/docs/API_CONTRACT.md b/docs/API_CONTRACT.md index b1f3b052f..6fa77f135 100644 --- a/docs/API_CONTRACT.md +++ b/docs/API_CONTRACT.md @@ -8,7 +8,7 @@ TEPP must work both as a standalone product and as a modular CWL component. Integrations with `naruon`, `contextual-orchestrator`, `.github`, or other repositories use explicit versioned API/artifact contracts. Cross-service direct table access is prohibited. -Current protected main exposes Rust library/domain contracts. The active stack adds a loopback HTTP/1.1 listener for naruon analysis-run, LineageWeave temporal-context, and export POSTs, including `POST /v1/project-histories` on the `AnalysisRunLiveService` contract boundary. `tepp-loopback` runs the shared consumer listener on `127.0.0.1:18081` by default; a caller may pass another loopback socket address and an optional maximum request count as its two arguments. The container is intended for a trusted same-host or shared-network-namespace sidecar, checks readiness through a synthetic bounded temporal-context request, and deliberately cannot bind a public or bridge address. It is not a production TLS/`$PORT` service. Endpoint examples below that are not covered by `NaruonLiveService` or `AnalysisRunLiveService` remain target interface shapes; export retrieval stays a target shape until an executable export route ships. Loopback `tepp-interpretation-runs create` is the operator-visible client for `POST /v1/interpretation-runs` on `tepp-orchestrator-loopback` (ADR 0064); stdout stays metric-free with `claim_status` `hypothetical` and `scientific_authority` false. +Current protected main exposes Rust library/domain contracts. The active stack adds a loopback HTTP/1.1 listener for naruon analysis-run, LineageWeave temporal-context, and export POSTs, including `POST /v1/project-histories` on the `AnalysisRunLiveService` contract boundary. `tepp-loopback` runs the shared consumer listener on `127.0.0.1:18081` by default; a caller may pass another loopback socket address and an optional maximum request count as its two arguments. The container is intended for a trusted same-host or shared-network-namespace sidecar, checks readiness through a synthetic bounded temporal-context request, and deliberately cannot bind a public or bridge address. It is not a production TLS/`$PORT` service. Endpoint examples below that are not covered by `NaruonLiveService` or `AnalysisRunLiveService` remain target interface shapes; export retrieval stays a target shape until an executable export route ships. Loopback `tepp-interpretation-runs create` is the operator-visible client for `POST /v1/interpretation-runs` on `tepp-orchestrator-loopback` (ADR 0064); stdout stays metric-free with `claim_status` `hypothetical` and `scientific_authority` false. Loopback `GET /v1/interpretation-runs` enumerates those accepted hypothetical runs as metric-free identities (ADR 0069); naruon and LineageWeave stay refused. ## 2. Contract families @@ -20,7 +20,7 @@ Current protected main exposes Rust library/domain contracts. The active stack a | event/relation/membership API | future TEPP crates/services | naruon, analytics, UI | accepted-target | | semantic/topic measurement API | future TEPP measurement service | naruon, batch jobs, visual analytics | accepted-target | | topic-context posterior plausible values | `analysis_engine` `tepp.topic_context_posterior.v1` | fast-mlsirm, LineageWeave | contract-only active-PR | -| LLM interpretation provider port | `orchestrator_live` loopback `POST /v1/interpretation-runs` | contextual-orchestrator | partial | +| LLM interpretation provider port | `orchestrator_live` loopback `POST`/`GET /v1/interpretation-runs` | contextual-orchestrator | partial | | LLM interpretation provider port | `tepp_api` orchestration router + future HTTP gateway | contextual-orchestrator | partial | | model/artifact/export API | `tepp_api` export envelopes + future HTTP service | standalone UI/CWL consumers | partial | | analysis-run request/accepted/status/terminal-result contracts | `tepp_api` v1 wire DTOs | naruon, orchestrator, UI | active product branch | @@ -63,6 +63,7 @@ When the service layer is introduced, use resources such as: POST /v1/evidence-imports GET /v1/evidence-imports/{import_id} POST /v1/interpretation-runs +GET /v1/interpretation-runs POST /v1/analysis-runs POST /v1/temporal-context GET /v1/analysis-runs/{run_id} @@ -204,7 +205,7 @@ Before any naruon, contextual-orchestrator, or NVIDIA NIM submission, callers mu ### contextual-orchestrator -TEPP may call a provider-neutral interpretation/orchestration port for semantic unitization, blinded model review, and evidence-bounded interpretation. Callers first obtain a plan from `tepp_api::route_orchestration` and may bind it with `tepp_api::bind_contextual_orchestrator` using an evidence-manifest digest. The standalone `orchestrator_live::OrchestratorLiveService` also serves a loopback-only `POST /v1/interpretation-runs` proof listener; the listener is not TLS termination. A production live port must pass `service_tls::authorize_orchestrator_live_port` (valid rustls PEM on an `https` bind); loopback plaintext is refused and loopback `https` with valid PEM is authorized as production TLS. The orchestrator does not own TEPP's statistical truth, source evidence, model registry, merge/release authority, or scientific acceptance. Detailed port boundary and credential separation are recorded in [`docs/connectors/contextual-orchestrator-interpretation-port.md`](connectors/contextual-orchestrator-interpretation-port.md). +TEPP may call a provider-neutral interpretation/orchestration port for semantic unitization, blinded model review, and evidence-bounded interpretation. Callers first obtain a plan from `tepp_api::route_orchestration` and may bind it with `tepp_api::bind_contextual_orchestrator` using an evidence-manifest digest. The standalone `orchestrator_live::OrchestratorLiveService` also serves a loopback-only `POST /v1/interpretation-runs` proof listener and `GET /v1/interpretation-runs` collection of accepted hypothetical identities; the listener is not TLS termination. A production live port must pass `service_tls::authorize_orchestrator_live_port` (valid rustls PEM on an `https` bind); loopback plaintext is refused and loopback `https` with valid PEM is authorized as production TLS. The orchestrator does not own TEPP's statistical truth, source evidence, model registry, merge/release authority, or scientific acceptance. Detailed port boundary and credential separation are recorded in [`docs/connectors/contextual-orchestrator-interpretation-port.md`](connectors/contextual-orchestrator-interpretation-port.md). ### organization `.github` diff --git a/docs/TRACEABILITY.md b/docs/TRACEABILITY.md index a298032ca..caa3ad5f2 100644 --- a/docs/TRACEABILITY.md +++ b/docs/TRACEABILITY.md @@ -107,6 +107,7 @@ The full APA 7th standards/literature register remains `docs/research/standards- | contextual-orchestrator execution boundary | ADR 0010/0011 | credential-free `bind_contextual_orchestrator` on the active PR; live HTTP remaining | partial | | contextual-orchestrator live execution boundary | ADR 0010/0011 | loopback listener records mode/budget and refuses scientific authority; provider execution remains accepted-target | partial | | loopback contextual-orchestrator interpretation-run CLI | ADR 0064; ADR 0010/0011; API contract; RFC 9110 | `orchestrator_live` `tepp-interpretation-runs create` CLI against `tepp-orchestrator-loopback` (`POST /v1/interpretation-runs`); metric-free hypothetical JSON; `tepp.scientific_acceptance.v1` never appears; does not infer causality; naruon and LineageWeave refused | active-PR | +| loopback contextual-orchestrator interpretation-run collection GET | ADR 0069; ADR 0010/0011; API contract; RFC 9110 | `orchestrator_live` `GET /v1/interpretation-runs` on `tepp-orchestrator-loopback`; metric-free hypothetical identities; empty body; no `idempotency-key`; `tepp.scientific_acceptance.v1` never appears; does not infer causality; naruon and LineageWeave refused | active-PR | | foundation validation / release-readiness ledger | ADR 0014; Test Strategy | PR #24 `docs/validation/temporal-event-foundation.md` on protected main | implemented-main | | scientific claim promotion separated from design/implementation/release | ADR 0014; ADR policy | `validation_core` exact-head promotion gates on this PR; documentation/CI/domain validation remain; full package/image release bundle remaining | partial | | CSAP/SOC 2/ISO/NIST assurance readiness | `docs/COMPLIANCE_READINESS.md`; research register | repository controls + future deployment evidence | accepted-target / deployment-owned | diff --git a/docs/adr/0069-interpretation-run-collection-get.md b/docs/adr/0069-interpretation-run-collection-get.md new file mode 100644 index 000000000..d2c4d1ed5 --- /dev/null +++ b/docs/adr/0069-interpretation-run-collection-get.md @@ -0,0 +1,107 @@ +# ADR 0069 — Contextual-orchestrator interpretation-run collection GET + +**Decision status:** Accepted +**Implementation maturity:** active-PR +**Date:** 2026-09-01 +**Supersedes:** None; complements ADR 0010, ADR 0011, and ADR 0064 for the operator-visible interpretation-run collection. Does not supersede ADR 0014 claim-promotion authority. This ADR number is unique on this stack versus protected main; live vs-main and sibling GAP-003A PRs already occupy 0026–0068. + +## Context + +Protected main already serves `POST /v1/interpretation-runs` on +`OrchestratorLiveService`, and #425 publishes `tepp-interpretation-runs create`. +Operators still cannot enumerate accepted hypothetical runs without guessing +idempotency keys. Duplicating interpretation-run CLI (#425), project-history +collection GET (#424), collection CLI (#428), GET-by-id (#429), retrieval CLI +(#431), analysis-run collection GET (#368), Leiden, Driver p.16, or GAP-010 +Figma/export would collide with live PRs. Naruon and `LineageWeave` are refused +on this orchestrator-owned adapter; `NaruonLiveService` stays POST-only. + +## Decision + +`orchestrator_live` publishes loopback-only `GET /v1/interpretation-runs` on +`tepp-orchestrator-loopback`: + +- Consumer is `contextual-orchestrator` only. Empty body. Pagination uses + `tepp-page-limit` and exclusive `tepp-page-cursor` headers because the + request-line parser fails closed on query strings. +- `idempotency-key` is refused on collection GET. Extra path segments + (GET-by-id) fail closed on this slice. +- Collection rows are metric-free identities: `interpretation_run_id`, + `idempotency_key`, `orchestration_mode`, `claim_status=hypothetical`, + `scientific_authority=false`. +- `tepp.scientific_acceptance.v1`, RMSE, bias, coverage, SE-gate, + `evidence_span_ids`, `tenant_workspace_id`, `compute_budget_tokens`, + `evidence_text`, `findings`, and `causal_score` never appear. +- The collection does not infer causality, call a model provider, mutate TEPP + state, or return a completed psychometric result. +- This slice does not implement interpretation-run collection CLI, GET-by-id, + or persistence. + +## Alternatives considered + +1. **Keep POST replay as the only retrieval path** — rejected because + operators still guess idempotency keys. +2. **Reuse analysis-run or project-history collection GET** — rejected; those + slices are different live PRs and different resources. +3. **Return evidence spans, tenant, or budget on the list** — rejected because + collection bodies must stay metric-free identities. +4. **Open naruon or LineageWeave on this adapter** — rejected; the listener + admits `contextual-orchestrator` only. +5. **Loopback `GET /v1/interpretation-runs`** — accepted. + +## Consequences + +- Operators can enumerate accepted hypothetical interpretation runs without + writing a second POST. +- Collection JSON cannot be mistaken for a succeeded scientific-acceptance + result or a causal score. +- Collection success is not release evidence and is not an ADR 0014 claim. + +## Failure and recovery + +Non-`contextual-orchestrator` consumers, nonempty GET bodies, present +`idempotency-key`, extra path segments, zero/oversized page limits, empty or +slash/NUL cursors, credential flags, and metric keys fail closed. The +in-memory listener is not durable. + +## Security, privacy, scientific-integrity, and governance impact + +- No credential headers cross the consumer boundary. +- Evidence spans, tenant, and budget stay off the collection page. +- HTTP 200 on collection GET is not measurement evidence and is not a causal + claim. + +## Compatibility and migration + +`POST /v1/interpretation-runs` and `tepp-interpretation-runs create` remain +unchanged. Interpretation-run collection CLI remains a later slice. + +## Verification + +Falsifiable evidence: + +- GET of two accepted runs returns a metric-free page sorted by idempotency + key with `claim_status=hypothetical`, `scientific_authority=false`, and no + RMSE/bias/coverage/SE-gate/`tepp.scientific_acceptance.v1`/`evidence_span_ids`/ + `causal_score` keys; +- GET extra segments, naruon or LineageWeave consumer, nonempty body, present + `idempotency-key`, and metric keys fail closed; +- Clippy `-D warnings`, `orchestrator_live` tests, rustdoc, and exact-head + review remain required. + +## Rollback and supersession + +Rollback removes collection GET; `POST /v1/interpretation-runs` remains valid. +A superseding ADR is required to persist the registry, bind a public address, +emit scientific-acceptance on the list, infer causality, open naruon or +`LineageWeave`, or treat collection success as an ADR 0014 claim. + +## Related authority + +- ADR 0010 owns adaptive LLM orchestration and scientific-authority + separation. +- ADR 0011 owns standalone/modular HTTP boundaries. +- ADR 0064 owns the interpretation-run create CLI. +- ADR 0014 owns scientific claim promotion. +- RFC 9110 owns GET semantics (Fielding, Nottingham, & Reschke, 2022). It does + not authorize scientific claims. diff --git a/docs/adr/README.md b/docs/adr/README.md index 3637d0f73..a5aaa4627 100644 --- a/docs/adr/README.md +++ b/docs/adr/README.md @@ -31,6 +31,7 @@ Read [`ADR_POLICY.md`](ADR_POLICY.md) first. **Decision status and implementatio | [0024](0024-lineage-pair-criterion-and-project-journey-posterior.md) | Independent Event Lineage pair criterion and posterior Project Journey | Proposed | active-PR | Strict artifacts preserve criterion/event-time draws, branches, ties, and CPU/GPU receipts without claiming the scientific estimator is complete. | | [0025](0025-macos-native-rust-mlx-metal-boundary.md) | macOS-native Rust-owned MLX Metal execution | Accepted | accepted-target | Compose authenticates to a native host service; Linux never claims Metal, and actual backend/parity receipts fail closed. | | [0064](0064-interpretation-run-cli.md) | Loopback `tepp-interpretation-runs create` is contextual-orchestrator POST /v1/interpretation-runs client | Accepted | active-PR | Complements ADR 0010/0011; does not supersede ADR 0014. Unique on protected main. Does not infer causality. | +| [0069](0069-interpretation-run-collection-get.md) | Loopback `GET /v1/interpretation-runs` enumerates accepted hypothetical interpretation runs | Accepted | active-PR | Complements ADR 0010/0011/0064; does not supersede ADR 0014. Unique on this stack versus protected main (0026–0068 occupied). Does not infer causality. | | [0023](0023-lineage-criterion-anchor-contract.md) | TEPP-owned Event Lineage criterion anchor | Accepted | active-PR | PR #237 publishes the strict accepted/rejected artifact and identities; estimator execution remains fail-closed future work. | | [0024](0024-independent-topic-importance-anchor.md) | Posterior topic-context producer contract | Accepted | contract-only active-PR | Strict DTO/schema only; the current estimator does not emit it. fast-mlsirm owns case-deletion influence. | | [0001](0001-rust-first-modular-msa.md) | Rust-first numerical core and CPU `f64` reference | Accepted | partial | ADR 0011 owns cross-service/MSA authority; 0001 retains numerical/backend authority. | @@ -142,6 +143,7 @@ Use the narrowest owning ADR when decisions overlap: - **independent lineage criterion and posterior Project Journey:** ADR 0023. - **macOS-native Rust-owned MLX Metal execution:** ADR 0024. - **contextual-orchestrator interpretation-run CLI:** ADR 0064. +- **contextual-orchestrator interpretation-run collection GET:** ADR 0069. ## Change and supersession rule diff --git a/docs/connectors/contextual-orchestrator-interpretation-port.md b/docs/connectors/contextual-orchestrator-interpretation-port.md index ce2ce23e9..529676797 100644 --- a/docs/connectors/contextual-orchestrator-interpretation-port.md +++ b/docs/connectors/contextual-orchestrator-interpretation-port.md @@ -15,8 +15,9 @@ TEPP may call a provider-neutral interpretation/orchestration port for semantic LLM/provider settings are execution policy only. Deterministic scientific gates remain authoritative (AGENTS.md §11). A production live bind uses `service_tls::authorize_orchestrator_live_port` and cannot be loopback plaintext. This document does not claim a deployed TLS listener. `orchestrator_live::OrchestratorLiveService` binds loopback TCP and serves -`POST /v1/interpretation-runs`. Accepted output is always hypothetical and -never scientific authority. Non-loopback binds, table-access hosts, and +`POST /v1/interpretation-runs` plus `GET /v1/interpretation-runs`. Accepted +output is always hypothetical and never scientific authority. Collection GET +returns metric-free identities only. Non-loopback binds, table-access hosts, and review/Copilot/GitHub credential headers fail closed. The listener does not call a model provider. diff --git a/docs/research/interpretation-run-collection-http.md b/docs/research/interpretation-run-collection-http.md new file mode 100644 index 000000000..7b238ad3d --- /dev/null +++ b/docs/research/interpretation-run-collection-http.md @@ -0,0 +1,59 @@ +# Interpretation-run collection GET (doctoring) + +## Scope + +`GET /v1/interpretation-runs` is the operator-visible collection of accepted +hypothetical interpretation runs on `OrchestratorLiveService` / +`tepp-orchestrator-loopback`. HTTP method, path, and header semantics follow +current HTTP semantics (Fielding, Nottingham, & Reschke, 2022). Fail-closed +refusal of unpublished consumers, nonempty GET bodies, present +`idempotency-key`, extra path segments, review/Copilot/GitHub credential +flags, and scientific-authority promotion is repository contract authority +(ADR 0069; ADR 0010; ADR 0011; ADR 0014), not an RFC inference rule. + +Collection JSON is metric-free. `claim_status` remains `hypothetical`. +`scientific_authority` remains false. `tepp.scientific_acceptance.v1` never +appears. A 200 collection page is not a completed psychometric result, +calibrated score, theta estimate, uncertainty statement, causal inference, or +scientific claim. + +## Authority + +### External standards (HTTP only) + +Fielding, R., Nottingham, M., & Reschke, J. (Eds.). (2022). *HTTP semantics* +(RFC 9110). IETF. https://doi.org/10.17487/RFC9110 + +RFC 9110 §9.3.1 describes GET as a method for retrieving the target resource. +TEPP maps that retrieval onto a bounded, hypothetical interpretation-run +collection. The RFC does not define psychometric acceptance, RMSE, causality, +or claim promotion. + +### Internal contract evidence + +- `docs/adr/0069-interpretation-run-collection-get.md` — this collection +- `docs/adr/0064-interpretation-run-cli.md` — create CLI +- `docs/adr/0010-adaptive-llm-orchestration.md` — mode vocabulary and + scientific-authority separation +- `docs/adr/0011-standalone-modular-msa-boundary.md` — modular HTTP boundary +- `docs/adr/0014-scientific-claim-promotion-and-release-evidence.md` — HTTP + 200 is not a scientific claim +- `crates/orchestrator_live/tests/interpretation_run_collection_http_contract.rs` + — fail-closed collection proofs +- `crates/orchestrator_live/tests/live_http_contract.rs` — loopback GET proofs + +## Verification + +- `GET /v1/interpretation-runs` of accepted contextual-orchestrator runs + returns `hypothetical` rows without RMSE/bias/coverage/SE-gate keys, + `evidence_span_ids`, `causal_score`, or `tepp.scientific_acceptance.v1`; +- GET extra segments, naruon or LineageWeave consumer, nonempty body, present + `idempotency-key`, and unknown verbs fail closed. + +## Non-claims + +This slice does not implement interpretation-run collection CLI, GET-by-id, +export CLI, analysis-run collection GET, project-history collection GET, wait +CLI, lookup CLI, persistence, production TLS, Leiden consensus, GAP-010 +Figma/export, causal inference, or an ADR 0014 scientific claim-promotion +package.