idle-draft: clear attempts on success so forced redos start fresh

Claude-Session: https://claude.ai/code/session_01YQDoWNM7XPPii28khFWoMc
This commit is contained in:
Paul O'Reilly
2026-08-02 21:54:53 +12:00
parent 1f008eebcb
commit ec25f02f01
3 changed files with 67 additions and 6 deletions

View File

@@ -670,6 +670,40 @@ check("signal handling: install_signal_handlers installs a non-default SIGINT ha
_signal.signal(_signal.SIGTERM, _signal.SIG_DFL)
_signal.signal(_signal.SIGINT, _signal.SIG_DFL)
# --- apply_success_state: clears attempts for the succeeded work type only ---
success_state = {"items": {"ai/01-topic-one": {"human_edit_done": True, "attempts": {"draft": 1, "research": 2}}}}
success_candidate = {"kind": "item", "item_key": "ai/01-topic-one", "work_type": "draft"}
m.apply_success_state(success_state, success_candidate)
entry_after = success_state["items"]["ai/01-topic-one"]
check("apply_success_state: clears the succeeded work type's attempts key",
"draft" not in entry_after.get("attempts", {}), entry_after)
check("apply_success_state: leaves an unrelated work type's attempts counter untouched",
entry_after.get("attempts", {}).get("research") == 2, entry_after)
check("apply_success_state: leaves other item fields (e.g. human_edit_done) untouched",
entry_after.get("human_edit_done") is True, entry_after)
# When the succeeded work type was the item's only attempts entry, the whole
# `attempts` key is dropped (not left behind as an empty {}).
success_state2 = {"items": {"ai/01-topic-one": {"attempts": {"draft": 1}}}}
m.apply_success_state(success_state2, success_candidate)
entry_after2 = success_state2["items"]["ai/01-topic-one"]
check("apply_success_state: drops the attempts key entirely once it's empty",
"attempts" not in entry_after2, entry_after2)
# No prior attempts entry at all -> no-op, no KeyError, no spurious key created.
success_state3 = {"items": {"ai/01-topic-one": {}}}
m.apply_success_state(success_state3, success_candidate)
check("apply_success_state: no-op when the item has no attempts history",
success_state3["items"]["ai/01-topic-one"] == {}, success_state3)
# Result is well-formed state per validate_state (schema still satisfied post-clear).
try:
m.validate_state(success_state, repo)
validate_ok = True
except m.StateValidationError:
validate_ok = False
check("apply_success_state: resulting state still passes validate_state", validate_ok, success_state)
for status, name, detail in results:
print(f"{status}: {name}", detail if detail else "")