Skip to content

Wizard step audit: _step_memory_dir and _step_settings crash on filesystem failure (refs #626) #664

@memtomem

Description

@memtomem

Summary

Follow-up to #626. The Ollama branch of _step_embedding was migrated to the new fail_step() mechanism in #661, but two other interactive steps still perform filesystem side effects without any try/except. They don't silently advance (the original #626 bug pattern) — they crash with an uncaught stack trace, which is the symmetric failure mode and equally surprising for the user.

Sites

1. _step_memory_dir (packages/memtomem/src/memtomem/cli/init_cmd.py:638)

if not memory_path.exists():
    create = nav_confirm(f"  '{memory_dir}' doesn't exist. Create it?", default=True)
    if create:
        memory_path.mkdir(parents=True, exist_ok=True)   # <-- uncaught
        click.secho(f"  Created {memory_path}", fg="green")

If mkdir fails (PermissionError, OSError, ENOSPC), the wizard exits with a Python stack trace. The user has to read the trace, fix the underlying issue, then re-run mm init from the top.

Suggested fix: wrap the mkdir in a while True: try / except (PermissionError, OSError) as exc: fail_step(f"Could not create '{memory_path}': {exc}", retryable=True) block so the user can fix permissions / pick a different path / quit.

2. _step_settings (packages/memtomem/src/memtomem/cli/init_cmd.py:889-894)

canonical = project_root / CANONICAL_SETTINGS_FILE
canonical.parent.mkdir(parents=True, exist_ok=True)   # <-- uncaught
if not canonical.exists():
    canonical.write_text(                              # <-- uncaught
        json.dumps({"hooks": {}}, indent=2) + "\n",
        encoding="utf-8",
    )

Same pattern: mkdir and write_text can both raise. Crashes on read-only project root, full disk, etc.

Suggested fix: same shape as above — try/except + fail_step with retryable=True.

Out of scope (intentionally)

The "warn-and-save" patterns in _step_embedding (ONNX/Ollama/OpenAI client missing, kiwipiepy missing in _step_language) are documented UX — the wizard saves the config so the user can install the extra later. Those are not bugs.

Why a separate PR

Per the project's "one focused PR per change" convention, the Ollama branch fix in #661 deliberately did not touch other steps. Once this PR lands, the fail_step adoption is consistent across every step that performs a side effect.

Acceptance

  • mkdir / write_text failures in _step_memory_dir and _step_settings surface a fail_step prompt instead of a stack trace.
  • Tests pin: simulate mkdir raising PermissionError → assert the prompt appears, r retries the action, b returns to the previous step, q cancels via WizardCancel (exit 0).

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions