Learning loop hardening: docs, approval wording, rollback only restores the cycle's own files, due notice no longer hides errors
This commit is contained in:
1 parent
4821a1b6a4
commit
2ca45f8103
9 files changed
+152
-90
No files matched your search
+24
-20
@@ -199,20 +199,18 @@ def proposed(rows=None):
|
||||
|
||||
|
||||
def due_notice(session=None):
|
||||
"""Session-start lines: a cycle is due, and/or a decision waits for the owner."""
|
||||
try:
|
||||
n = len(proposed())
|
||||
fl = len(L.flagged())
|
||||
lines = []
|
||||
if n >= DUE_AFTER or fl:
|
||||
lines.append("sisi: a learning cycle is due (%d proposed learning(s)%s; `sisi cycle` prints the brief)"
|
||||
% (n, ", %d flagged not working" % fl if fl else ""))
|
||||
pend = L.pending_notice()
|
||||
if pend:
|
||||
lines.append(pend)
|
||||
return "\n".join(lines)
|
||||
except Exception:
|
||||
return ""
|
||||
"""Session-start lines: a cycle is due, and/or a decision waits for the owner. The callers
|
||||
(tick, the gate) catch and log a failure; it is not hidden here."""
|
||||
n = len(proposed())
|
||||
fl = len(L.flagged())
|
||||
lines = []
|
||||
if n >= DUE_AFTER or fl:
|
||||
lines.append("sisi: a learning cycle is due (%d proposed learning(s)%s; `sisi cycle` prints the brief)"
|
||||
% (n, ", %d flagged not working" % fl if fl else ""))
|
||||
pend = L.pending_notice()
|
||||
if pend:
|
||||
lines.append(pend)
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
def brief_text():
|
||||
@@ -586,9 +584,14 @@ def _transact(label, fn):
|
||||
lines, touched, added = fn()
|
||||
except BaseException:
|
||||
if before:
|
||||
changed = _changed(before, "HEAD")
|
||||
_restore_files(before, changed)
|
||||
pdata.commit("cycle aborted: store restored", changed or None)
|
||||
changed = set(_changed(before, "HEAD"))
|
||||
changed |= {x for x in pdata.git("diff", "--name-only", "HEAD", check=False).stdout.splitlines() if x}
|
||||
changed |= {x for x in pdata.git("ls-files", "--others", "--exclude-standard", "--", "overlay",
|
||||
check=False).stdout.splitlines() if x}
|
||||
changed = sorted(changed)
|
||||
if changed:
|
||||
_restore_files(before, changed)
|
||||
pdata.commit("cycle aborted: store restored", changed)
|
||||
try:
|
||||
overlay.build_canon()
|
||||
except Exception:
|
||||
@@ -692,7 +695,8 @@ def revert_cycle(cid=None):
|
||||
gone = set(rec.get("pending_added") or [])
|
||||
if gone:
|
||||
L.save_pending([i for i in L.load_pending() if i.get("id") not in gone], "revert %s: parked changes dropped" % rec["id"])
|
||||
pdata.commit("revert %s" % rec["id"], files or None)
|
||||
if files:
|
||||
pdata.commit("revert %s" % rec["id"], files)
|
||||
rec["reverted"] = L.now()
|
||||
pdata.write_text("cycles/%s.json" % rec["id"], json.dumps(rec, indent=2, sort_keys=True) + "\n")
|
||||
pdata.commit("revert %s recorded" % rec["id"], ["cycles/%s.json" % rec["id"]])
|
||||
@@ -722,7 +726,7 @@ def relay_allowed():
|
||||
|
||||
|
||||
def describe_pending(item):
|
||||
"""The full action, in words and text, so the owner can see exactly what he approves."""
|
||||
"""The full action, in words and text, so the owner can see exactly what is approved."""
|
||||
a = item.get("action") or {}
|
||||
rec = L.get(L.load_learnings(), item.get("learning") or "")
|
||||
out = ["%s: %s" % (item["id"], (a.get("action") if a.get("action") != "promote" else
|
||||
@@ -858,7 +862,7 @@ def cmd_approve(argv):
|
||||
print("\n".join(describe_pending(item)), file=sys.stderr)
|
||||
print("sisi approve: refused. A decision must be made by the owner in a terminal: this was run "
|
||||
"without one (an agent, a script, a pipe). Show the owner what it does (the listing above) "
|
||||
"and give him the command to type himself. To allow an agent to relay a decision, set "
|
||||
"and give the owner the command to type. To allow an agent to relay a decision, set "
|
||||
"learning.agent_relayed_approval in the user config (off by default).", file=sys.stderr)
|
||||
return 2
|
||||
relayed = True
|
||||
|
||||
+5
-5
@@ -110,7 +110,7 @@ def is_subagent_session():
|
||||
if sess.get("subagent"):
|
||||
return True
|
||||
for sh in reversed(sess.get("shells") or []):
|
||||
if isinstance(sh, dict) and "retro" in str(sh.get("cmd") or ""):
|
||||
if isinstance(sh, dict) and sh.get("retro"):
|
||||
return bool(sh.get("subagent"))
|
||||
return False
|
||||
|
||||
@@ -474,7 +474,7 @@ def new_record(finding, cause, impact, disposition, project, unit,
|
||||
"provenance": [{"unit": unit, "project": pk, "ts": now(), "kind": "origin"}],
|
||||
"terms": derive_terms(finding, cause, change or ""),
|
||||
"owner_statement": bool(owner_statement), "candidate": bool(subagent),
|
||||
"entered_via": entered_via, "recurrences_after_promotion": 0,
|
||||
"recurrences_after_promotion": 0,
|
||||
"flagged_not_working": False, "promoted_at": now() if owner_statement else None,
|
||||
"mechanism_ref": None, "replay": replay, "created": now(),
|
||||
}
|
||||
@@ -741,9 +741,9 @@ def pending_notice():
|
||||
if not n:
|
||||
return ""
|
||||
return ("sisi: %d learning change(s) wait for the owner's decision. Ask the owner through the host's "
|
||||
"question dialog (`sisi approve` lists each change in full; show him what it would do) and give "
|
||||
"him the command to run himself in a terminal: `sisi approve ID --yes` or `--no`. "
|
||||
"Do not run it for him." % n)
|
||||
"question dialog (`sisi approve` lists each change in full; show the owner what it would do) and give "
|
||||
"the owner the command to run in a terminal: `sisi approve ID --yes` or `--no`. "
|
||||
"Do not run it for the owner." % n)
|
||||
|
||||
|
||||
# ---- owner statements (one path: learn writes, oracle prints) ---------------------
|
||||
|
||||
+2
-2
@@ -355,7 +355,7 @@ def migrate_learnings():
|
||||
"detail": "migrated from the old lesson store; never replay-validated"},
|
||||
"status": status, "version": 1, "confidence": "low", "provenance": prov,
|
||||
"terms": L.derive_terms(old.get("moment") or "", old.get("cause") or "", old.get("change") or ""),
|
||||
"owner_statement": False, "candidate": False, "entered_via": "migration",
|
||||
"owner_statement": False, "candidate": False,
|
||||
"recurrences_after_promotion": 0, "flagged_not_working": False,
|
||||
"promoted_at": None, "mechanism_ref": old.get("folded_into"),
|
||||
"replay": None, "created": old.get("created") or L.now()}
|
||||
@@ -391,7 +391,7 @@ def migrate_learnings():
|
||||
"provenance": [{"unit": "owner", "project": proj, "ts": r.get("ts") or "", "kind": "origin"}],
|
||||
"terms": L.derive_terms(text), "owner_statement": True, "candidate": False,
|
||||
"statement_origin": "migrated from the old statement file",
|
||||
"entered_via": "migration", "recurrences_after_promotion": 0,
|
||||
"recurrences_after_promotion": 0,
|
||||
"flagged_not_working": False, "promoted_at": r.get("ts") or L.now(),
|
||||
"mechanism_ref": None, "replay": None, "created": r.get("ts") or L.now()}
|
||||
rows.append(rec)
|
||||
|
||||
+1
-1
@@ -521,7 +521,7 @@ def _export_core(path=None):
|
||||
pr = r.get("proposed") or {}
|
||||
lines += ["## Learning %s (%s%s)" % (r["id"], pr.get("mechanism") or "policy",
|
||||
", target " + pr["target"] if pr.get("target") else ""), ""]
|
||||
if r.get("title"):
|
||||
if r.get("title") and r["title"] != pr.get("description"):
|
||||
lines += [str(r["title"]), ""]
|
||||
lines += [str(pr.get("description") or ""), ""]
|
||||
if r.get("expected_effect"):
|
||||
|
||||
+4
-7
@@ -394,13 +394,10 @@ def _print_lessons(query, extra="", targets=()):
|
||||
|
||||
|
||||
def _print_cycle_notice():
|
||||
try:
|
||||
from . import cycle
|
||||
line = cycle.due_notice()
|
||||
if line:
|
||||
print(line)
|
||||
except Exception:
|
||||
pass
|
||||
from . import cycle
|
||||
line = cycle.due_notice()
|
||||
if line:
|
||||
print(line)
|
||||
|
||||
|
||||
def cmd_show(args):
|
||||
|
||||
+5
-4
@@ -109,12 +109,13 @@ def _session(sid, d, cwd):
|
||||
|
||||
|
||||
def note_shell(sess, cmd, payload):
|
||||
"""Record, for the learning loop, who ran this shell command: whether its hook payload came
|
||||
from a subagent (an agent id or a subagent transcript path). `sisi retro` reads this from the
|
||||
session record to quarantine what a subagent records; it never trusts the caller's environment."""
|
||||
"""Record, for the learning loop, who ran this shell command: whether it names a retro, and whether
|
||||
its hook payload came from a subagent (an agent id or a subagent transcript path). `sisi retro`
|
||||
reads this from the session record to quarantine what a subagent records; it never trusts the
|
||||
caller's environment. The command text itself is not kept."""
|
||||
from . import workers
|
||||
shells = sess.setdefault("shells", [])
|
||||
shells.append({"cmd": (cmd or "")[:200], "subagent": bool(workers.is_subagent_payload(payload)),
|
||||
shells.append({"retro": "retro" in (cmd or ""), "subagent": bool(workers.is_subagent_payload(payload)),
|
||||
"ts": time.time()})
|
||||
del shells[:-8]
|
||||
|
||||
|
||||
Reference in new issue
Block a user