fix(boot): self-explanatory + one-shot recovery for vector-dim mismatch (closes #469, #455)#575
fix(boot): self-explanatory + one-shot recovery for vector-dim mismatch (closes #469, #455)#575rohitg00 wants to merge 1 commit into
Conversation
…sistent
Recovery from a persisted vector-index dimension mismatch (after the user
changes EMBEDDING_PROVIDER) was unnecessarily hard:
1. The error pointed users at `AGENTMEMORY_DROP_STALE_INDEX=true` but
never told them which `.env` file the running process actually reads,
which matters under LaunchAgent / systemd / Docker contexts where
HOME can differ from the expected user directory.
2. Even after setting the flag, the dropStale branch only skipped
restoring the bad vectors in memory — the stale payload stayed in KV.
Removing the flag on the next boot would crash-loop the server again
because the persisted index was still bad.
Two minimal changes:
- Export the resolved data dir + env-file paths from config and surface
them in the error message, with a ready-to-paste `echo … >> $envFile`
recovery line and an explicit HOME-resolution note for service-managed
deployments.
- In the dropStale branch, persist the now-cleared index back via
indexPersistence.save() so the recovery is one-shot: the flag drops
the stale payload AND clears the on-disk KV, so the next boot is
clean even after the flag is removed.
Tests (1081) + build pass.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughThis PR improves recovery from persisted vector index dimension mismatches during startup. It centralizes filesystem paths in a ChangesVector Index Dimension Mismatch Handling
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/index.ts`:
- Around line 416-418: The printed recovery command inserts
RESOLVED_PATHS.envFile raw into the shell snippet which breaks if the path
contains spaces or shell metacharacters; update the template in src/index.ts to
shell-quote or escape RESOLVED_PATHS.envFile before interpolation (e.g., call an
escape helper like escapeShellArg or wrap the path in single quotes while
escaping any embedded single quotes) so the printed command is safe to
copy-paste; ensure you replace the direct interpolation of
RESOLVED_PATHS.envFile in the multiline string with the escaped/quoted value.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: e5fea2ac-ea27-45a2-ada7-412e894c4175
📒 Files selected for processing (2)
src/config.tssrc/index.ts
| ` 1. One-shot drop + rebuild (recommended):\n` + | ||
| ` echo 'AGENTMEMORY_DROP_STALE_INDEX=true' >> ${RESOLVED_PATHS.envFile}\n` + | ||
| ` # restart agentmemory; the flag can be removed after the next clean boot.\n` + |
There was a problem hiding this comment.
Quote the env-file path in the recovery command.
Line 417 inserts the raw path into shell syntax. If the resolved HOME path contains spaces or shell metacharacters, the suggested copy-paste recovery step breaks, which undercuts the main operator guidance in this error path. Please shell-quote or escape RESOLVED_PATHS.envFile before printing it.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/index.ts` around lines 416 - 418, The printed recovery command inserts
RESOLVED_PATHS.envFile raw into the shell snippet which breaks if the path
contains spaces or shell metacharacters; update the template in src/index.ts to
shell-quote or escape RESOLVED_PATHS.envFile before interpolation (e.g., call an
escape helper like escapeShellArg or wrap the path in single quotes while
escaping any embedded single quotes) so the printed command is safe to
copy-paste; ensure you replace the direct interpolation of
RESOLVED_PATHS.envFile in the multiline string with the escaped/quoted value.
Summary
Closes #469. Closes #455.
Recovery from a persisted vector-index dimension mismatch (after the user changes
EMBEDDING_PROVIDERand the new provider declares a different vector dimension) was unnecessarily hard. Two real problems behind the report:1. Users couldn't discover the right
.envfileThe error pointed at
AGENTMEMORY_DROP_STALE_INDEX=truebut never said where that flag belongs. Under LaunchAgent / systemd / Docker the running process'sHOMEcan differ from the user's interactive shell, so editing the shell's~/.agentmemory/.envdoesn't reach the process.Fix: export the resolved paths from
config.tsand embed them in the error message, including a ready-to-pasteecho … >> $envFilerecovery line and an explicit HOME-resolution note.2. Dropping was not one-shot
The
dropStalebranch only skipped restoring the bad vectors in memory — the stale payload stayed in KV. Removing the flag on the next boot would re-trip the guard.Fix: in the
dropStalebranch, persist the cleared vector index back viaindexPersistence.save(). The recovery is now one-shot: the flag drops the stale payload AND clears the on-disk KV, so the next boot is clean even after the flag is removed.Diff
src/config.ts—+12exportsRESOLVED_PATHSfor callers that need the actually-read pathssrc/index.ts—+33/-5better error message + post-drop persist40 insertions, 5 deletions across 2 files.
What it does NOT do
--drop-staleflow is already the documented escape hatch)dotenv-style global env injection (the runtime reads.envper call already; the issue was discoverability not load order)Validation
npm test→ 97/97 test files, 1081/1081 tests passnpm run build→ bundle cleantsc --noEmitclean on touched filesExample error after the fix
Summary by CodeRabbit