โ† Back to PRs

#6060: feat(onboarding): add Memory Optimization step to onboarding wizard

by GodsBoy open 2026-02-01 07:13 View on GitHub โ†’
commands
## Summary This PR adds a **Memory Optimization** step to the OpenClaw onboarding wizard, giving users the ability to enable powerful memory features during initial setup rather than having to manually edit config later. Resolves discussion #6038. ## Problem OpenClaw has excellent memory infrastructure, but these features are **off or minimal by default** and require users to know they exist and manually configure them. Most users never discover these capabilities, leading to: - **Context amnesia** after compaction (no memory flush) - **Poor recall** of exact names, IDs, and code symbols (no hybrid search) - **Slow reindexing** on startup (no embedding cache) - **Lost conversation history** (no session transcript search) ## Solution ### Interactive Mode Adds a `setupMemoryOptimization()` step after hooks setup with a multiselect prompt offering four options: - ๐Ÿ” **Hybrid search (BM25 + vector)** โ€” 70/30 vector/text blend with 4x candidate pool. Dramatically improves recall for exact terms, names, error strings, and code symbols. - ๐Ÿ’พ **Embedding cache** โ€” Caches chunk embeddings in SQLite so reindexing does not re-embed unchanged text. Saves API calls and makes search faster on startup. - ๐Ÿง  **Pre-compaction memory flush** โ€” Auto-triggers a silent agentic turn before context compaction, giving the agent a chance to write durable notes to disk. Prevents the "woke up with amnesia" problem. - ๐Ÿ“œ **Session transcript search** โ€” Indexes past session transcripts via memory_search with lower delta thresholds (50KB/25 messages) for faster indexing. ### Non-Interactive Mode Applies sensible defaults automatically: hybrid search, embedding cache, and memory flush are enabled. Session transcript search is opt-in only (it is experimental). ## Implementation - **New file:** `src/commands/onboard-memory.ts` โ€” The memory optimization wizard step + `applyNonInteractiveMemoryDefaults()` export - **New file:** `src/commands/onboard-memory.test.ts` โ€” 19 tests covering all options individually, all together, skip, nullish coalescing (no overwrite), immutability, and non-interactive defaults - **Modified:** `src/wizard/onboarding.ts` โ€” Integrates the step after hooks setup - **Modified:** `src/commands/onboard-non-interactive/local.ts` โ€” Adds non-interactive memory defaults ### Key Design Decisions - Uses `structuredClone()` for immutability (original config never mutated) - All nested config uses `??=` (nullish coalescing assignment) โ€” never overwrites existing user-set values - Follows the existing `onboard-hooks.ts` pattern exactly for function signature and test structure ## Testing - โœ… TypeScript compiles cleanly (`tsc --noEmit`) - โœ… 19/19 tests pass (`vitest run src/commands/onboard-memory.test.ts`) - โœ… Lint passes (`oxlint` โ€” 0 warnings, 0 errors in new files) - โœ… Format passes (`oxfmt`) - โœ… Tested on a live OpenClaw instance (Hetzner VPS, Ubuntu) running all four memory optimizations ## Why This Matters The compaction problem that frustrates most long-running OpenClaw users has built-in solutions that almost nobody knows about. This PR makes them discoverable at first setup rather than requiring users to manually edit config JSON. ## AI-Assisted ๐Ÿค– Built with Claude (Opus 4.5) via OpenClaw sub-agent. The irony is not lost on us: this PR improves the memory of the very system that wrote it. cc @steipete <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR adds a new onboarding step (`setupMemoryOptimization`) that lets users enable memory-related defaults (hybrid search, embedding cache, pre-compaction flush, session transcript search) and wires it into both interactive onboarding (`src/wizard/onboarding.ts`) and non-interactive local onboarding (`applyNonInteractiveMemoryDefaults`). It also introduces a focused test suite validating that the step sets defaults via nullish coalescing and does not mutate or overwrite existing config. <h3>Confidence Score: 4/5</h3> - This PR is mostly safe to merge; the main concern is handling prompt cancellation/undefined values robustly. - Changes are additive, well-tested, and scoped to onboarding config writing. The only notable risk is an unhandled cancel/null return from `multiselect` causing a runtime crash during onboarding, plus a minor semantic question around whether `null` should be treated as โ€œunsetโ€. - src/commands/onboard-memory.ts <!-- greptile_other_comments_section --> **Context used:** - Context from `dashboard` - CLAUDE.md ([source](https://app.greptile.com/review/custom-context?memory=fd949e91-5c3a-4ab5-90a1-cbe184fd6ce8)) - Context from `dashboard` - AGENTS.md ([source](https://app.greptile.com/review/custom-context?memory=0d0c8278-ef8e-4d6c-ab21-f5527e322f13)) <!-- /greptile_comment -->

Most Similar PRs