The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(update): verify SQLite runtime remediation
fangliquanflq7e22725bb437
diff --git a/hermes_cli/update_cmd.py b/hermes_cli/update_cmd.pyindex 4421afdd228..d710f560b63 100644--- a/hermes_cli/update_cmd.py+++ b/hermes_cli/update_cmd.py@@ -1789,8 +1789,48 @@ def _update_complete_message(pre_version: str | None) -> str:if post_version:return f"✓ Update complete! (v{post_version})"return "✓ Update complete!"--+++def _post_update_sqlite_runtime_status():+ """Return whether the interpreter used after update has safe SQLite."""+ from hermes_constants import project_venv_dir+ from hermes_cli.sqlite_runtime import probe_sqlite_runtime++ venv_dir = project_venv_dir(_m().PROJECT_ROOT)+ python = (+ venv_python_path(venv_dir, windows=_m()._is_windows())+ if venv_dir is not None+ else Path(sys.executable)+ )+ info = probe_sqlite_runtime(python)+ return info is not None and not info.wal_reset_vulnerable, info+++def _print_verified_update_completion(message: str) -> bool:+ """Print a success completion only after probing the next Hermes runtime."""+ if not message.startswith("✓"):+ _print_update_completion(message)+ return False+ sqlite_runtime_ok, sqlite_info = _post_update_sqlite_runtime_status()+ if sqlite_runtime_ok:+ _print_update_completion(message)+ return True+ print()+ if sqlite_info is None:+ detail = "the post-update SQLite runtime could not be verified"+ else:+ detail = (+ f"SQLite {sqlite_info.sqlite_version_string} still has the "+ "WAL-reset corruption bug"+ )+ print(f"⚠ Update partially complete — {detail}.")+ print(+ " Rebuild the Hermes venv with a uv-managed Python, restart Hermes, "+ "then verify with `hermes doctor`."+ )+ return False++def _clear_stale_sqlite_sidecars(db_path: Path) -> None:"""Delete the WAL / shared-memory / rollback-journal files next to *db_path*.@@ -1817,11 +1857,12 @@ def _print_update_summary(node_failures: list,desktop_build_ok: bool,pre_update_version: str | None,-) -> None:+) -> bool:"""Final update banner. A failed Desktop rebuild is non-fatal for thePython side, but must not print ``✓ Update complete!`` (#88251)."""+ sqlite_runtime_ok, sqlite_info = _post_update_sqlite_runtime_status()print()- if node_failures or not desktop_build_ok:+ if node_failures or not desktop_build_ok or not sqlite_runtime_ok:parts = []if node_failures:parts.append(@@ -1831,14 +1872,30 @@ def _print_update_summary(parts.append("the desktop app was not rebuilt and is still on the previous build")+ if not sqlite_runtime_ok:+ if sqlite_info is None:+ parts.append("the post-update SQLite runtime could not be verified")+ else:+ parts.append(+ f"SQLite {sqlite_info.sqlite_version_string} still has the "+ "WAL-reset corruption bug"+ )print("⚠ Update partially complete — " + "; ".join(parts) + ".")if node_failures:print(" Code and Python deps are updated, but the dashboard/TUI may")print(" be in a mixed state until the Node deps are rebuilt.")if not desktop_build_ok:print(" Run `hermes desktop` to retry the desktop rebuild.")+ if not sqlite_runtime_ok:+ print(+ " The Python runtime remediation did not complete. Run `hermes "+ "update` again; if SQLite is unchanged, rebuild the Hermes venv "+ "with a uv-managed Python, restart Hermes, then verify with "+ "`hermes doctor`."+ )else:_print_update_completion(_update_complete_message(pre_update_version))+ return desktop_build_ok and sqlite_runtime_okdef _write_gateway_update_exit_code(ok: bool) -> None:@@ -2290,7 +2347,7 @@ def _update_via_zip(args, *, had_desktop_app_before_update: bool = False) -> boo"Post-update state.db integrity check (zip path) failed: %s", exc)- _print_update_summary(+ update_complete = _print_update_summary(node_failures=node_failures,desktop_build_ok=desktop_build_ok,pre_update_version=pre_update_version,@@ -2310,11 +2367,11 @@ def _update_via_zip(args, *, had_desktop_app_before_update: bool = False) -> boofrom hermes_cli.update_receipt import finalize_update_receiptfinalize_update_receipt(- "success" if (desktop_build_ok and not node_failures) else "partial"+ "success" if update_complete and not node_failures else "partial")except Exception as _receipt_exc:logger.debug("Update receipt finalize (zip path) failed: %s", _receipt_exc)- return desktop_build_ok+ return update_completedef _stash_local_changes_if_needed(git_cmd: list[str], cwd: Path) -> Optional[str]:status = subprocess.run(@@ -8631,7 +8688,7 @@ def _cmd_update_impl(args, gateway_mode: bool):print(" Close all Hermes windows/gateways and re-run: hermes update")else:_repair_node_deps_on_current_checkout(- _print_update_completion,+ _print_verified_update_completion,assume_yes=assume_yes,gateway_mode=gateway_mode,pre_update_snapshot_id=pre_update_snapshot_id,@@ -9321,7 +9378,7 @@ def _cmd_update_impl(args, gateway_mode: bool):pre_update_snapshot_id=pre_update_snapshot_id,)- _print_update_summary(+ update_complete = _print_update_summary(node_failures=node_failures,desktop_build_ok=desktop_build_ok,pre_update_version=pre_update_version,@@ -9452,11 +9509,11 @@ def _cmd_update_impl(args, gateway_mode: bool):## Writing the marker here — after git pull + pip install succeed but# before we attempt the restart — ensures the new gateway sees it- # regardless of how we die. Gated on desktop_build_ok (#88251): a- # Desktop rebuild failure must not be reported as "0" — the gateway's- # /update watcher (gateway/run.py) polls this file.+ # regardless of how we die. The verified summary includes Desktop and+ # SQLite-runtime health, so neither failure is reported as "0" to the+ # gateway watcher (gateway/run.py).if gateway_mode:- _write_gateway_update_exit_code(desktop_build_ok)+ _write_gateway_update_exit_code(update_complete)gateway_fleet_restart_incomplete = Falsegateway_restart_phase_errors: list[str] = []@@ -10575,7 +10632,11 @@ def _cmd_update_impl(args, gateway_mode: bool):from hermes_cli.update_receipt import finalize_update_receipt_receipt_path = finalize_update_receipt(- "partial" if gateway_fleet_restart_incomplete else "success",+ (+ "partial"+ if gateway_fleet_restart_incomplete or not update_complete+ else "success"+ ),fleet=_fleet_snapshot,)if _receipt_path is not None:diff --git a/tests/hermes_cli/test_cmd_update.py b/tests/hermes_cli/test_cmd_update.pyindex 117b39b3710..b889832a5fe 100644--- a/tests/hermes_cli/test_cmd_update.py+++ b/tests/hermes_cli/test_cmd_update.py@@ -67,7 +67,11 @@ def _patch_managed_uv(request):with patch("hermes_cli.managed_uv.resolve_uv", side_effect=_fake_resolve_uv), \patch("hermes_cli.managed_uv.ensure_uv", side_effect=_fake_ensure_uv), \- patch("hermes_cli.managed_uv.update_managed_uv", side_effect=_fake_update_managed_uv):+ patch("hermes_cli.managed_uv.update_managed_uv", side_effect=_fake_update_managed_uv), \+ patch(+ "hermes_cli.update_cmd._post_update_sqlite_runtime_status",+ return_value=(True, None),+ ):yielddiff --git a/tests/hermes_cli/test_update_desktop_stale_warning.py b/tests/hermes_cli/test_update_desktop_stale_warning.pyindex 294c9ca17de..3596029bfee 100644--- a/tests/hermes_cli/test_update_desktop_stale_warning.py+++ b/tests/hermes_cli/test_update_desktop_stale_warning.py@@ -138,6 +138,9 @@ def test_summary_keeps_success_banner_when_desktop_ok(capsys, monkeypatch):update_cmd, "_update_complete_message", lambda _v: "✓ Update complete! (v0.20.2)")monkeypatch.setattr(update_cmd, "_branch_head_suffix", lambda *a, **k: "")+ monkeypatch.setattr(+ update_cmd, "_post_update_sqlite_runtime_status", lambda: (True, None)+ )_print_update_summary(node_failures=[],desktop_build_ok=True,diff --git a/tests/hermes_cli/test_update_sqlite_remediation.py b/tests/hermes_cli/test_update_sqlite_remediation.pynew file mode 100644index 00000000000..ac020aeec57--- /dev/null+++ b/tests/hermes_cli/test_update_sqlite_remediation.py@@ -0,0 +1,67 @@+"""Post-update reporting for unresolved SQLite WAL-reset risk."""++from pathlib import Path+from types import SimpleNamespace++from hermes_cli import update_cmd+++def test_runtime_status_probes_running_venv_outside_checkout(tmp_path, monkeypatch):+ running_python = tmp_path / "venv312" / "bin" / "python"+ observed = []+ vulnerable = SimpleNamespace(wal_reset_vulnerable=True)+ monkeypatch.setattr("hermes_constants.project_venv_dir", lambda _root: None)+ monkeypatch.setattr(update_cmd.sys, "executable", str(running_python))+ monkeypatch.setattr(+ "hermes_cli.sqlite_runtime.probe_sqlite_runtime",+ lambda python: observed.append(Path(python)) or vulnerable,+ )++ safe, info = update_cmd._post_update_sqlite_runtime_status()++ assert observed == [running_python]+ assert safe is False+ assert info is vulnerable+++def test_summary_withholds_success_when_sqlite_remediation_failed(capsys, monkeypatch):+ monkeypatch.setattr(+ update_cmd,+ "_post_update_sqlite_runtime_status",+ lambda: (False, SimpleNamespace(sqlite_version_string="3.46.1")),+ raising=False,+ )+ monkeypatch.setattr(+ update_cmd,+ "_update_complete_message",+ lambda _version: "✓ Update complete! (v0.20.5)",+ )++ complete = update_cmd._print_update_summary(+ node_failures=[],+ desktop_build_ok=True,+ pre_update_version="0.20.4",+ )++ out = capsys.readouterr().out+ assert complete is False+ assert "Update complete" not in out+ assert "SQLite 3.46.1" in out+ assert "WAL-reset" in out+ assert "uv-managed Python" in out+ assert "hermes doctor" in out+++def test_current_checkout_completion_is_verified_before_success(capsys, monkeypatch):+ monkeypatch.setattr(+ update_cmd,+ "_post_update_sqlite_runtime_status",+ lambda: (False, SimpleNamespace(sqlite_version_string="3.46.1")),+ )++ complete = update_cmd._print_verified_update_completion("✓ Already up to date!")++ out = capsys.readouterr().out+ assert complete is False+ assert "Already up to date" not in out+ assert "SQLite 3.46.1" in out