Merge branch 'feature/agent-feedback-channel' into unify/skills-20261112-night
This commit is contained in:
commit
018de9a7ff
14 files changed
+833
-95
No files matched your search
@@ -14,6 +14,7 @@ CONSOLE = ("id", "status", "code", "output", "created_ts", "started", "finished"
|
||||
TASK_JOB = "task"
|
||||
GATE_JOB = "gate"
|
||||
CHANGES = (TASK_JOB, GATE_JOB)
|
||||
USAGE = 2
|
||||
|
||||
|
||||
def runner_job(job: dict) -> dict:
|
||||
@@ -92,9 +93,27 @@ class Jobs:
|
||||
job, changed = self.jobs.transition(job_id, "running", {"status": status, "code": code, "output": output, "finished": time.time()})
|
||||
if not changed:
|
||||
raise Conflict({"id": job_id, "status": job["status"]})
|
||||
command_done = status == "done" and job.get("kind") not in CHANGES
|
||||
runs = [self.scripts.run(OPERATOR_SCRIPT, ["done", job["task"].removeprefix(OPERATOR)])] if command_done else []
|
||||
runs = self.close_row(job, status, code)
|
||||
tail = "\n".join(output.splitlines()[-20:])
|
||||
self.log.add({"kind": "run", "title": f"{status}: {job['command'][:200]}", "text": tail, "ref": {"job": job_id, "task": job["task"], "code": code, "status": status}})
|
||||
told = self.tell_applied(job) if job.get("kind") == TASK_JOB else []
|
||||
return {"id": job_id, "status": status, "code": code, "runs": runs, "told": told}
|
||||
|
||||
def close_row(self, job: dict, status: str, code: int | None) -> list[dict]:
|
||||
"""Returns:
|
||||
The operator.py runs that report the end of an operator command
|
||||
job on its row: `ran` on exit 0, then an older operator.py's
|
||||
`done` when `ran` is its usage error; `failed` on any other exit;
|
||||
none for a refused job or a task or gate change.
|
||||
"""
|
||||
if job.get("kind") in CHANGES or status not in ("done", "failed"):
|
||||
return []
|
||||
slug = job["task"].removeprefix(OPERATOR)
|
||||
shown = [slug, f"--command={job['command']}", f"--dir={job['directory']}"]
|
||||
if status == "failed":
|
||||
why = f"killed by signal {-code}" if code < 0 else f"exit {code}"
|
||||
return [self.scripts.run(OPERATOR_SCRIPT, ["failed", *shown, "--why", why])]
|
||||
runs = [self.scripts.run(OPERATOR_SCRIPT, ["ran", *shown])]
|
||||
if runs[0]["code"] == USAGE:
|
||||
runs.append(self.scripts.run(OPERATOR_SCRIPT, ["done", slug]))
|
||||
return runs
|
||||
@@ -33,15 +33,21 @@ def read_snapshot(path: Path, now: float) -> dict[str, dict]:
|
||||
|
||||
def unanswered(news: list[dict], now: float) -> list[tuple[str, float]]:
|
||||
"""Returns:
|
||||
(callee name, call time) of every call older than UNANSWERED that its
|
||||
callee never receipted.
|
||||
(callee, call time) of every call older than UNANSWERED without a
|
||||
receipt: one per session id in `to_sessions`, answered by any
|
||||
receipt of that call; else one per name in `to`.
|
||||
"""
|
||||
receipts = {(agent(row.get("from")), round(epoch(row.get("call")) or 0, 3)) for row in news if row.get("class") == "receipt"}
|
||||
answered = {call for _, call in receipts}
|
||||
late = []
|
||||
for row in news:
|
||||
ts = epoch(row.get("ts"))
|
||||
if row.get("class") != "call" or ts is None or now - ts < UNANSWERED or not isinstance(row.get("to"), list):
|
||||
continue
|
||||
sessions = [sid for sid in row["to_sessions"] if isinstance(sid, str)] if isinstance(row.get("to_sessions"), list) else []
|
||||
if sessions:
|
||||
late += [(sid, ts) for sid in sessions if round(ts, 3) not in answered]
|
||||
continue
|
||||
late += [(name, ts) for name in map(agent, row["to"]) if name and (name, round(ts, 3)) not in receipts]
|
||||
return late
|
||||
|
||||
@@ -75,7 +81,7 @@ def presence(sessions: dict[str, dict], parts: dict[str, str], mode: str, claims
|
||||
busy = record.get("status") == "busy"
|
||||
stamp = record.get("statusUpdatedAt")
|
||||
updated = (epoch(stamp / 1000) if isinstance(stamp, int | float) and not isinstance(stamp, bool) else None) or 0
|
||||
called = names.get(sid, set()) | {agent(record.get("name"))}
|
||||
called = names.get(sid, set()) | {agent(record.get("name")), sid}
|
||||
if (busy and now - updated > STALE) or any(name in called and ts > updated for name, ts in late):
|
||||
states[sid] = "unreachable"
|
||||
continue
|
||||
|
||||
Reference in new issue
Block a user