Unit record, telemetry and status tests; close under the original id

This commit is contained in:
swaits committed 2026-11-23 11:47:00 -07:00
1 parent c4366b1f42
commit 770fbddde6
3 files changed
+596 -9

No files matched your search

+9 -5
View File
@@ -256,9 +256,10 @@ def transcript_stats(path, t0=None, t1=None):
if not isinstance(d, dict):
continue
ts = epoch(d["timestamp"]) if isinstance(d.get("timestamp"), str) else None
if ts is not None and ((t0 is not None and ts < t0) or (t1 is not None and ts > t1)):
continue
outside = ts is not None and ((t0 is not None and ts < t0) or (t1 is not None and ts > t1))
typ = d.get("type")
if outside and typ != "user":
continue
if typ == "assistant":
m = d.get("message") or {}
u = m.get("usage") if isinstance(m, dict) else None
@@ -284,10 +285,13 @@ def transcript_stats(path, t0=None, t1=None):
elif typ == "user":
text = typed_text(d)[0]
if text is not None:
if not first and is_correction(text):
corrections += 1
# the transcript's first typed message is a request, never a correction,
# whether or not it falls inside the window
if not outside:
if not first and is_correction(text):
corrections += 1
human += 1
first = False
human += 1
elif typ == "attachment":
a = d.get("attachment") or {}
if a.get("type") == "queued_command" and a.get("commandMode") == "prompt" and not a.get("isMeta"):
+4 -4
View File
@@ -466,9 +466,9 @@ def decide_status(c, rows, abandon=None):
return "delivered", block, unrun
def build_record(c, project, delivery_status, ended_epoch, abandon_reason=None):
def build_record(c, project, delivery_status, ended_epoch, abandon_reason=None, rows=None):
t0 = harvest.epoch(c["started"]) if isinstance(c.get("started"), str) else None
rows = _unit_results(c, project, c.get("started"))
rows = _unit_results(c, project, c.get("started")) if rows is None else rows
tel = build_telemetry(c, project, rows, t0, ended_epoch)
models = tel.pop("_models")
delegation_rows = tel.pop("_delegation_rows")
@@ -581,6 +581,7 @@ def close_unit(c, contract_path, project, abandon=None, now=None):
abandonment accounts for it. Safe to repeat after a crash at any step: an archive that
exists is kept as it stands and the remaining steps are completed."""
ended_epoch = time.time() if now is None else now
rows = _unit_results(c, project, c.get("started")) # under the id the results were recorded with
path = archive_path(project, c["id"])
if os.path.exists(path):
try:
@@ -599,7 +600,6 @@ def close_unit(c, contract_path, project, abandon=None, now=None):
else:
rec = None
if rec is None:
rows = _unit_results(c, project, c.get("started"))
status, block, _ = decide_status(c, rows, abandon)
if status is None:
bad = ", ".join("%s (%s%s)" % (r["id"], r["status"], ": " + r["reason"] if r.get("reason") else "")
@@ -607,7 +607,7 @@ def close_unit(c, contract_path, project, abandon=None, now=None):
return None, ("sisi: unit %s cannot close as delivered: %s. Fix and re-run `sisi verify`, "
"record a deviation with `sisi contract waive \"<reason>\"`, or close it with "
"`sisi unit close --abandon \"<reason>\"`." % (c["id"], bad)), False
rec = build_record(c, project, status, ended_epoch, abandon_reason=abandon)
rec = build_record(c, project, status, ended_epoch, abandon_reason=abandon, rows=rows)
_, created = archive_record(rec, project)
if created:
_capture_case(rec)