diff --git a/memory-update.md b/memory-update.md index ea616b36..8ec804ee 100644 --- a/memory-update.md +++ b/memory-update.md @@ -109,3 +109,8 @@ - CI `test (ubuntu-latest, 3.10)` failed during test collection because `datetime.UTC` is unavailable on Python 3.10. - Replaced `datetime.UTC` usage with `timezone.utc` in `src/seedpass/cli/agent.py` and `scripts/ai_tui_agent_test.py`. - Verified with targeted tests: `src/tests/test_cli_agent_mode.py` and `src/tests/test_ai_tui_agent_harness.py`. + +## Settings Unlock Cancellation Robustness (2026-02-26) +- CI showed `test_settings_lock_unlock_cancelled_is_graceful` intermittently receiving a generic exception path instead of `PasswordPromptError` during Settings -> Lock Vault unlock. +- Hardened `handle_settings()` lock flow to treat any exception containing "cancelled by user" as cancellation, printing `Unlock cancelled: ...` instead of a hard failure message. +- Verified with targeted pytest for the failing test. diff --git a/src/main.py b/src/main.py index 11fcb561..f85a88e3 100644 --- a/src/main.py +++ b/src/main.py @@ -1102,12 +1102,20 @@ def handle_settings(password_manager: PasswordManager) -> None: except PasswordPromptError as exc: print(colored(f"Unlock cancelled: {exc}", "yellow")) except Exception as exc: - logging.error( - "Failed to unlock vault from settings: %s", - exc, - exc_info=True, - ) - print(colored(f"Failed to unlock vault: {exc}", "red")) + # Some environments can surface cancellation through a + # different exception class; treat the message as cancel. + if "cancelled by user" in str(exc).lower(): + logging.warning( + "Unlock cancelled during settings lock flow: %s", exc + ) + print(colored(f"Unlock cancelled: {exc}", "yellow")) + else: + logging.error( + "Failed to unlock vault from settings: %s", + exc, + exc_info=True, + ) + print(colored(f"Failed to unlock vault: {exc}", "red")) else: password_manager.start_background_sync() getattr(