Bound pilot inference with ongoing heartbeat and process-group cancellation

This commit is contained in:
devops committed 2026-10-23 16:57:33 +00:00
1 parent c66bc58f73
commit 8cfd44cd09
7 files changed
+294 -14

No files matched your search

+20 -3
View File
@@ -14,7 +14,7 @@ def validate_lease(lease):
if not 5 < expiry-time.time() <= 31: raise ValueError('Fresh 30-second lease required')
return lease
def execute(lease, artifact_root, infer, heartbeat):
def _execute(lease, artifact_root, infer, heartbeat):
"""No claim/approval generation. heartbeat must call trusted server; errors abort.
infer is the pinned runner, not a browser-supplied command or prompt.
Completion is deliberately NOT sent: existing transport accepts tracer JSON only.
@@ -23,12 +23,12 @@ def execute(lease, artifact_root, infer, heartbeat):
heartbeat(lease)
root=pathlib.Path(tempfile.mkdtemp(prefix='real-pilot-',dir=artifact_root))
def git(*args):
return subprocess.check_output(['git','-C',str(root),*args],stderr=subprocess.DEVNULL,text=True).strip()
return subprocess.check_output(['git','-C',str(root),*args],stderr=subprocess.DEVNULL,text=True,timeout=1).strip()
git('init','-q'); git('config','user.email','pilot@invalid'); git('config','user.name','Bounded Hermes Pilot')
(root/'README').write_text('Disposable fixture; PREPARE source '+lease['commitSha']+'\n')
git('add','README'); git('commit','-qm','Seed isolated pilot fixture')
base=git('rev-parse','HEAD')
# One inference, no tools, 18s hard outer cap in supplied pinned runner.
# One cancellable inference, no tools; ongoing authenticated guard.
source=infer()
heartbeat(lease)
if not isinstance(source,str) or len(source.encode())>2048: raise ValueError('Invalid generated artifact')
@@ -45,3 +45,20 @@ def execute(lease, artifact_root, infer, heartbeat):
'gate1':'EXTERNAL_LEASE_REQUIRED','published':False,'deploymentExecuted':False}
(root/'evidence.json').write_text(json.dumps(report,indent=2)+'\n')
return root,report
from runtime import LeaseGuard, ProcessInference, pinned_inference
def execute(lease, artifact_root, infer, heartbeat):
validate_lease(lease)
with LeaseGuard(lease, heartbeat) as guard:
guard.check()
if not isinstance(infer, ProcessInference):
raise TypeError("Cancellable ProcessInference required")
def generate():
response = json.loads(infer.run(guard))
if not isinstance(response,dict) or response.get("tools") != 0 or response.get("model") != "Free":
raise ValueError("Pinned tool-less model required")
return response["source"]
result = _execute(lease, artifact_root, generate, lambda _: guard.check())
guard.check()
return result