mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-11-17 04:11:35 +00:00
Review findings on the assignee-login gate (#122689): - MAJOR: served_profile_child_env(inherit_credentials=True) overlays only the assignee's own GH_TOKEN/GH_CONFIG_DIR but HOME/XDG_CONFIG_HOME stay the launch process's, so a profile with no login of its own fell through to ~/.config/gh/hosts.yml - the ambient login the gate promises never to use. For a routed assignee home with neither token nor config dir, pin GH_CONFIG_DIR to <profile_home>/gh; gh then exits 4 (authentication required), which _api classifies as auth naming the profile. - MINOR (a): an ASSIGNED card whose profile cannot be resolved was fail-open (env=None -> completing process's full ambient login). Resolution now happens inside collect_acceptance and raises _GateAuthError naming the profile; only genuinely unassigned cards keep the ambient path. - MINOR (c): Codex refresh 200/non-JSON body no longer sets relogin_required, so the new exit-78 startup gate cannot turn an edge misfire into a sticky terminal block (invalid_json_relogin=False, as xAI already does). - MINOR (b)+(d) docs: GH_TOKEN must live in the profile's .env/secret source (a shell/systemd export is scrubbed); skipped_nonspawnable {assignee} row in the worker telemetry table; startup relogin-required failure exits 78.
48 lines
2.3 KiB
Python
48 lines
2.3 KiB
Python
"""Persist acceptance with the same ownership snapshot as the terminal write."""
|
|
from __future__ import annotations
|
|
|
|
from hermes_cli.kanban_db_connect import write_txn
|
|
from hermes_cli.kanban_pr_acceptance import _PR, collect_acceptance
|
|
|
|
|
|
def _snapshot(conn, task_id):
|
|
row = conn.execute("SELECT current_run_id, status, completion_contract FROM tasks WHERE id=?", (task_id,)).fetchone()
|
|
return tuple(row) if row else None
|
|
|
|
|
|
def prepare_acceptance(conn, task_id, expected_run_id, metadata):
|
|
snapshot = _snapshot(conn, task_id)
|
|
if snapshot is None:
|
|
return False
|
|
run_id, status, contract = snapshot
|
|
if not contract or contract == "local-only":
|
|
return None
|
|
if status not in {"running", "ready", "blocked", "review"} or (expected_run_id is not None and run_id != expected_run_id):
|
|
return False
|
|
published_pr = metadata.get("published_pr") if isinstance(metadata, dict) else None
|
|
match = _PR.fullmatch(published_pr) if isinstance(published_pr, str) else None
|
|
# Publication binds once. Retrying cannot replace the task's PR with a green sibling.
|
|
if match and contract == match[1]:
|
|
with write_txn(conn):
|
|
if _snapshot(conn, task_id) != snapshot:
|
|
return False
|
|
conn.execute("UPDATE tasks SET completion_contract=? WHERE id=?", (published_pr, task_id))
|
|
snapshot = (run_id, status, published_pr)
|
|
contract = published_pr
|
|
# The assignee profile's gh login owns the repo: acceptance must not run as
|
|
# the ambient login of whichever process completes the card (#122689).
|
|
assignee = conn.execute("SELECT assignee FROM tasks WHERE id=?", (task_id,)).fetchone()["assignee"]
|
|
return snapshot, collect_acceptance(contract, published_pr, assignee=assignee)
|
|
|
|
|
|
def record_acceptance(conn, task_id, acceptance):
|
|
"""Called under complete_task's write_txn, before its terminal UPDATE."""
|
|
from hermes_cli.kanban_db import _append_event
|
|
snapshot, receipt = acceptance
|
|
if _snapshot(conn, task_id) != snapshot:
|
|
return False
|
|
_append_event(conn, task_id, "pr_acceptance", receipt, run_id=snapshot[0])
|
|
if not receipt["ok"]:
|
|
detail = f"PR acceptance {receipt['classification']}: {receipt.get('detail', '')} {receipt['recovery']}"
|
|
conn.execute("UPDATE tasks SET last_failure_error=? WHERE id=?", (detail, task_id))
|
|
return receipt["ok"]
|