Skip to content

The agent that grows with you

refactor(hermes_cli): lost_and_found lane literal compaction

Tekniuma0358185ddeb
diff --git a/hermes_cli/session_lost_and_found.py b/hermes_cli/session_lost_and_found.py
index 703aa5c4f0f..121b9d22121 100644
--- a/hermes_cli/session_lost_and_found.py
+++ b/hermes_cli/session_lost_and_found.py
@@ -112,15 +112,12 @@ def run_cli_lost_and_found_recover(
attempt["usable"] = _lost_and_found_db_usable(lf_path)
if attempt["usable"]:
return {"binary": sqlite3_bin, "attempts": attempts}
- raise LostAndFoundError(
- "sqlite3 .recover did not produce a usable lost_and_found database: "
- + "; ".join(
- f"[{a['command']}] dump rc={a['dump_returncode']} "
- f"load rc={a['load_returncode']} "
- f"{a['dump_stderr_tail'] or a['load_stderr_tail']}".strip()
- for a in attempts
- )
+ details = "; ".join(
+ f"[{a['command']}] dump rc={a['dump_returncode']} load rc={a['load_returncode']} "
+ f"{a['dump_stderr_tail'] or a['load_stderr_tail']}".strip()
+ for a in attempts
)
+ raise LostAndFoundError(f"sqlite3 .recover did not produce a usable lost_and_found database: {details}")
def _lost_and_found_db_usable(lf_path: Path) -> bool:
@@ -286,18 +283,14 @@ def map_lost_and_found_rows(lf_conn: sqlite3.Connection, dest: sqlite3.Connectio
try:
if kind == "sessions" and nfield == SESSIONS_LEGACY_MINIMAL_NFIELD:
# Pre-modern layout with unknown column order: salvage identity + timing only.
- inserted = (
- dest.execute(
- "INSERT OR IGNORE INTO sessions (id, source, started_at, title) VALUES (?, ?, ?, ?)",
- (
- cells[0],
- cells[1] if _looks_like_source(cells[1]) else "recovered",
- _heuristic_started_at(cells),
- "[best-effort recovered] legacy session row (layout unknown)",
- ),
- ).rowcount
- == 1
+ row_values = (
+ cells[0], cells[1] if _looks_like_source(cells[1]) else "recovered",
+ _heuristic_started_at(cells), "[best-effort recovered] legacy session row (layout unknown)",
)
+ inserted = dest.execute(
+ "INSERT OR IGNORE INTO sessions (id, source, started_at, title) VALUES (?, ?, ?, ?)",
+ row_values,
+ ).rowcount == 1
report["legacy_minimal_sessions"] += int(inserted)
else:
# messages: the rowid-alias PK is NULL in the record; use the lost_and_found rowid.
diff --git a/hermes_cli/session_recovery.py b/hermes_cli/session_recovery.py
index 3fd4c9a0116..036414d49ee 100644
--- a/hermes_cli/session_recovery.py
+++ b/hermes_cli/session_recovery.py
@@ -956,8 +956,7 @@ def _recover_via_lost_and_found(
destination_conn.close()
copy_report: dict[str, dict[str, Any]] = {
table: {
- "mode": "lost_and_found_salvage",
- "status": "partial",
+ "mode": "lost_and_found_salvage", "status": "partial",
"copied_rows": int(mapping["direct_table_rows"].get(table) or 0) + int(mapping["mapped"].get(table) or 0),
"error": "recovered via page-level lost_and_found salvage; "
"row completeness cannot be verified against the source",
@@ -972,12 +971,11 @@ def _recover_via_lost_and_found(
output, expected_counts={"sessions": None, "messages": None}, copy_report=copy_report, allow_partial=True,
orphan_cleanup=orphan_cleanup,
)
- verification["loss_detected"] = True
verification["warnings"].append(
"BEST-EFFORT page-level salvage: the source table schemas were unreadable, so rows were rebuilt from raw "
"pages and mapped heuristically. Review every count before trusting this output."
)
- verification["complete"] = False
+ verification.update(loss_detected=True, complete=False)
return _recovery_report(
source, output, inspection, disk_space, verification, on_source_change="healthy",
allow_partial=True, mode="lost_and_found_salvage", best_effort=True, unreadable_schemas=missing_required,