Python
fix(memhub): name a blocked cutover without its counts
kristinhee82c4c939e3a
diff --git a/memhub/apps/core/src/one_memory/cli.py b/memhub/apps/core/src/one_memory/cli.pyindex 67cae2d..e4a764a 100644--- a/memhub/apps/core/src/one_memory/cli.py+++ b/memhub/apps/core/src/one_memory/cli.py@@ -415,6 +415,21 @@ def migration_bundle(options: Sequence[str], stream: TextIO) -> int:return 0+def cutover_failure_code(error: BaseException) -> str:+ """The cutover's own codes, minus the counts it appends to one of them.++ `sdk_data_plane_cutover_work_pending` carries a JSON body of table names and+ counts. That belongs in the diagnostic event, not in the single string the+ startup dialog reads, so it collapses to one name here.+ """+ code = getattr(error, "code", "")+ if isinstance(code, str) and code.startswith("sdk_data_plane_cutover_work_pending"):+ return "sdk_migration_work_pending"+ if isinstance(code, str) and _SAFE_MIGRATION_CODE.match(code):+ return code+ return "sdk_migration_cutover_failed"++def sdk_migrate(options: Sequence[str], stream: TextIO) -> int:"""Backfill legacy memory/raw into SDK while keeping legacy authority."""migration_id: str | None = None@@ -696,7 +711,7 @@ def sdk_cutover(options: Sequence[str], stream: TextIO) -> int:database_path=database_path,)except (DataPlaneMigrationError, MigrationBundleRejected, OSError) as error:- code = getattr(error, "code", str(error))+ code = cutover_failure_code(error)document = {"schema_version": 1,"state": "blocked",diff --git a/memhub/apps/core/tests/test_cli_migration_error_codes.py b/memhub/apps/core/tests/test_cli_migration_error_codes.pyindex f7a6874..8252f75 100644--- a/memhub/apps/core/tests/test_cli_migration_error_codes.py+++ b/memhub/apps/core/tests/test_cli_migration_error_codes.py@@ -12,7 +12,7 @@ from pathlib import Pathimport pytest-from one_memory.cli import migration_failure_code+from one_memory.cli import cutover_failure_code, migration_failure_codeclass _Coded(RuntimeError):@@ -106,6 +106,7 @@ def test_the_chain_survives_a_cycle() -> None:"sdk_migration_disk_space_insufficient","sdk_migration_working_fact_conflict","sdk_migration_coding_inventory_failed",+ "sdk_migration_work_pending",],)def test_the_codes_the_desktop_translates_stay_in_sync(code: str) -> None:@@ -113,3 +114,18 @@ def test_the_codes_the_desktop_translates_stay_in_sync(code: str) -> None:desktop = Path(__file__).resolve().parents[2] / "desktop" / "src" / "stable-runtime.ts"assert desktop.is_file(), desktopassert f'"{code}"' in desktop.read_text(encoding="utf-8")+++def test_cutover_work_counts_do_not_become_the_dialog_text() -> None:+ """The blocker code carries a JSON body; the person gets one name."""+ blocked = _Coded('sdk_data_plane_cutover_work_pending:{"memory_tasks":591}')++ assert cutover_failure_code(blocked) == "sdk_migration_work_pending"+ assert (+ cutover_failure_code(_Coded("sdk_data_plane_cutover_missing"))+ == "sdk_data_plane_cutover_missing"+ )+ assert (+ cutover_failure_code(RuntimeError("/Users/someone/private"))+ == "sdk_migration_cutover_failed"+ )diff --git a/memhub/apps/desktop/src/stable-runtime.ts b/memhub/apps/desktop/src/stable-runtime.tsindex 89db81a..8e56454 100644--- a/memhub/apps/desktop/src/stable-runtime.ts+++ b/memhub/apps/desktop/src/stable-runtime.ts@@ -137,6 +137,8 @@ const SAFE_STABLE_RUNTIME_ERROR_CODES = new Set(["sdk_migration_backfill_failed","sdk_migration_working_fact_conflict","sdk_migration_coding_inventory_failed",+ "sdk_migration_work_pending",+ "sdk_migration_cutover_failed","sdk_migration_bundle_copy_failed","sdk_migration_response_invalid","sdk_migration_status_unavailable",@@ -222,6 +224,10 @@ export const STABLE_RUNTIME_USER_MESSAGES: Record<string, string> = {"读取旧版 Coding 记忆时发现无法识别的结构,升级已停止。请把这个提示反馈给我们;原有记忆数据不会丢失。",sdk_migration_backfill_failed:"升级记忆数据格式时失败,已停止且没有切换数据源。请重新启动重试;如果仍然失败,请把这个提示反馈给我们,原有记忆数据不会丢失。",+ sdk_migration_work_pending:+ "记忆数据已经升级完成,但还有之前没处理完的记忆任务,所以暂时不能切换数据源。请保持 MemHub 打开几分钟,等这些任务处理完再重新启动;原有记忆数据不会丢失。",+ sdk_migration_cutover_failed:+ "切换数据源时失败,原有记忆数据仍然完整可用。请重新启动重试;如果仍然失败,请把这个提示反馈给我们。",sdk_migration_preflight_failed:"升级前的检查没有通过,升级已停止。请重新启动重试;如果仍然失败,请把这个提示反馈给我们,原有记忆数据不会丢失。",sdk_migration_status_unavailable: