feat(runtime): consume governed Activity Core closes

Assistant: codex
Assistant-Model: gpt-5.6-sol
Assistant-Session: 01a06ba0-10aa-7ea0-b20a-4f3fac39efe9
This commit is contained in:
tegwick 2026-09-04 19:54:07 +02:00
parent 0e6d795aa4
commit d00ffcb402
22 changed files with 1218 additions and 148 deletions

View file

@ -8,6 +8,7 @@ with an actionable error if the governed runtime is not installed.
from __future__ import annotations
import math
from collections.abc import Callable
from typing import Any
@ -24,12 +25,86 @@ _SCALAR_REFS = (
"duty_ref",
)
_LIST_REFS = ("goal_refs", "resource_envelope_refs")
_EVIDENCE_STRING_FIELDS = (
"request_id",
"correlation_id",
"actor",
"project",
"target_repo",
"contract_version",
"profile_ref",
"rein_id",
"rein_version",
"model_route",
"resolved_model",
"sandbox_profile",
"sandbox_id",
"tool_profile",
"outcome",
"failure_stage",
"error",
"started_at",
"finished_at",
"commit_sha",
"tool_events_completeness",
)
_EVIDENCE_NUMBER_FIELDS = (
"duration_s",
"tokens_spent",
"token_budget",
"tool_events_count",
)
class GlasExecutionError(RuntimeError):
"""The authoritative Glas invocation could not produce a GatewayResult."""
def normalise_execution_evidence_for_close(raw: Any) -> dict[str, Any]:
"""Retain only bounded Glas evidence fields safe for durable close state."""
if not isinstance(raw, dict):
return {}
result: dict[str, Any] = {}
for key in _EVIDENCE_STRING_FIELDS:
value = raw.get(key)
if isinstance(value, str):
result[key] = value[:2000] if key == "error" else value[:500]
for key in _EVIDENCE_NUMBER_FIELDS:
value = raw.get(key)
if (
isinstance(value, (int, float))
and not isinstance(value, bool)
and math.isfinite(value)
and value >= 0
):
result[key] = value
artifacts = raw.get("artifacts")
if isinstance(artifacts, list):
result["artifacts"] = [
item[:1000]
for item in artifacts[:20]
if isinstance(item, str) and item
]
refs: dict[str, Any] = {}
raw_refs = raw.get("refs")
if isinstance(raw_refs, dict):
for key in _SCALAR_REFS:
value = raw_refs.get(key)
if isinstance(value, str) and value:
refs[key] = value[:500]
for key in _LIST_REFS:
value = raw_refs.get(key)
if isinstance(value, list):
refs[key] = [
item[:500]
for item in value[:50]
if isinstance(item, str) and item
]
if refs:
result["refs"] = refs
return result
def _request_kwargs(run: OpsRun, config: OpsRunConfig, report_to_hub: bool) -> dict[str, Any]:
if not run.harness_profile_ref:
raise GlasExecutionError(f"ops_run {run.id} has no harness_profile_ref")