feat: route profiled ops runs through Glas
Assistant: codex Assistant-Model: gpt-5.6-sol Assistant-Session: 01a02b6f-7db1-7222-918b-e813a6bda38d
This commit is contained in:
parent
68ab94581a
commit
0f01c3e421
17 changed files with 895 additions and 11 deletions
|
|
@ -23,6 +23,11 @@ from rein_aharness.approaches import (
|
|||
execute_approach,
|
||||
select_approach,
|
||||
)
|
||||
from rein_aharness.glas_execution import (
|
||||
GLAS_APPROACH,
|
||||
GlasExecutionError,
|
||||
execute_profiled_run,
|
||||
)
|
||||
from rein_aharness.ops_run_client import (
|
||||
ActivityCoreOpsClient,
|
||||
OpsRun,
|
||||
|
|
@ -105,7 +110,7 @@ def process_one(
|
|||
return ProcessResult(claimed=False, empty=True, reason="queue empty")
|
||||
|
||||
run = claimed[0]
|
||||
approach = select_approach(run)
|
||||
approach = GLAS_APPROACH if run.harness_profile_ref else select_approach(run)
|
||||
logger.info(
|
||||
"claimed run_id=%s approach=%s title=%r labels=%s",
|
||||
run.id,
|
||||
|
|
@ -140,6 +145,13 @@ def process_one(
|
|||
detail={"dry_run": True},
|
||||
)
|
||||
|
||||
if run.harness_profile_ref:
|
||||
return _process_profiled_run(
|
||||
client,
|
||||
run,
|
||||
report_to_hub=report_to_hub,
|
||||
)
|
||||
|
||||
hb = _Heartbeat(client, run.id, cfg.lease_seconds)
|
||||
hb.start()
|
||||
try:
|
||||
|
|
@ -207,6 +219,84 @@ def process_one(
|
|||
)
|
||||
|
||||
|
||||
def _process_profiled_run(
|
||||
client: ActivityCoreOpsClient,
|
||||
run: OpsRun,
|
||||
*,
|
||||
report_to_hub: bool,
|
||||
) -> ProcessResult:
|
||||
"""Execute a profiled row without consulting or falling back to legacy routing."""
|
||||
hb = _Heartbeat(client, run.id, client.config.lease_seconds)
|
||||
hb.start()
|
||||
try:
|
||||
try:
|
||||
gateway_result = execute_profiled_run(
|
||||
run,
|
||||
client.config,
|
||||
report_to_hub=report_to_hub,
|
||||
)
|
||||
except GlasExecutionError as exc:
|
||||
reason = str(exc)
|
||||
try:
|
||||
out = client.fail(
|
||||
run.id,
|
||||
error=reason,
|
||||
reopen=False,
|
||||
result={"ok": False, "approach": GLAS_APPROACH, "reason": reason},
|
||||
)
|
||||
except OpsRunError as close_exc:
|
||||
return ProcessResult(
|
||||
claimed=True,
|
||||
run_id=run.id,
|
||||
approach=GLAS_APPROACH,
|
||||
ok=False,
|
||||
reason=f"close ops_run failed: {close_exc}; {reason}",
|
||||
)
|
||||
return ProcessResult(
|
||||
claimed=True,
|
||||
run_id=run.id,
|
||||
approach=GLAS_APPROACH,
|
||||
ok=False,
|
||||
reason=reason,
|
||||
ops_state=out.state,
|
||||
)
|
||||
finally:
|
||||
hb.stop()
|
||||
|
||||
evidence = gateway_result["evidence"]
|
||||
ok = gateway_result["ok"]
|
||||
reason = str(evidence.get("error") or evidence.get("outcome") or "Glas execution failed")
|
||||
try:
|
||||
if ok:
|
||||
out = client.complete(run.id, result=gateway_result)
|
||||
else:
|
||||
out = client.fail(
|
||||
run.id,
|
||||
error=reason,
|
||||
reopen=False,
|
||||
result=gateway_result,
|
||||
)
|
||||
except OpsRunError as exc:
|
||||
return ProcessResult(
|
||||
claimed=True,
|
||||
run_id=run.id,
|
||||
approach=GLAS_APPROACH,
|
||||
ok=False,
|
||||
reason=f"close ops_run failed: {exc}; gateway_ok={ok} {reason}",
|
||||
detail={"execution_evidence": evidence},
|
||||
)
|
||||
|
||||
return ProcessResult(
|
||||
claimed=True,
|
||||
run_id=run.id,
|
||||
approach=GLAS_APPROACH,
|
||||
ok=ok,
|
||||
reason="" if ok else reason,
|
||||
ops_state=out.state,
|
||||
detail={"execution_evidence": evidence},
|
||||
)
|
||||
|
||||
|
||||
def poll_peek(client: ActivityCoreOpsClient | None = None) -> list[dict[str, Any]]:
|
||||
"""List open ops_runs with selected approach (no claim)."""
|
||||
client = client or ActivityCoreOpsClient()
|
||||
|
|
@ -220,7 +310,10 @@ def poll_peek(client: ActivityCoreOpsClient | None = None) -> list[dict[str, Any
|
|||
"state": run.state,
|
||||
"labels": run.labels,
|
||||
"target_repo": run.target_repo,
|
||||
"approach": select_approach(run),
|
||||
"approach": (
|
||||
GLAS_APPROACH if run.harness_profile_ref else select_approach(run)
|
||||
),
|
||||
"harness_profile_ref": run.harness_profile_ref,
|
||||
"created_at": run.raw.get("created_at"),
|
||||
}
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue