Handle lease loss during adapter errors

Assistant: codex
Assistant-Model: gpt-5.6-sol
Assistant-Session: 01a02b6f-7db1-7222-918b-e813a6bda38d
This commit is contained in:
tegwick 2026-08-23 14:40:29 +02:00
parent 75f4914777
commit ad4074c20a
3 changed files with 98 additions and 32 deletions

View file

@ -168,14 +168,18 @@ def process_one(
hb = _Heartbeat(client, run.id, cfg.lease_seconds)
hb.start()
execution_error: str | None = None
try:
ar: ApproachResult = execute_approach(
run,
approach=approach,
config=cfg,
report_to_hub=report_to_hub,
commit=commit,
)
try:
ar: ApproachResult = execute_approach(
run,
approach=approach,
config=cfg,
report_to_hub=report_to_hub,
commit=commit,
)
except Exception as exc:
execution_error = type(exc).__name__
finally:
hb.stop()
@ -196,6 +200,16 @@ def process_one(
},
)
if execution_error is not None:
return ProcessResult(
claimed=True,
run_id=run.id,
approach=approach,
ok=False,
reason=f"approach failed ({execution_error})",
detail={"execution_error_type": execution_error},
)
payload = {
"approach": ar.approach,
"ok": ar.ok,
@ -259,6 +273,9 @@ def _process_profiled_run(
"""Execute a profiled row without consulting or falling back to legacy routing."""
hb = _Heartbeat(client, run.id, client.config.lease_seconds)
hb.start()
execution_error: str | None = None
execution_reason = ""
gateway_result: dict[str, Any] | None = None
try:
try:
gateway_result = execute_profiled_run(
@ -267,30 +284,8 @@ def _process_profiled_run(
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,
)
execution_error = type(exc).__name__
execution_reason = str(exc)
finally:
hb.stop()
@ -311,6 +306,33 @@ def _process_profiled_run(
},
)
if execution_error is not None:
reason = execution_reason or f"profiled execution failed ({execution_error})"
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,
)
assert gateway_result is not None
evidence = gateway_result["evidence"]
ok = gateway_result["ok"]
reason = str(evidence.get("error") or evidence.get("outcome") or "Glas execution failed")