1.4.3 regression: `memorix memory store --text` fails with "Error: named?.trim is not a function" for long text input
Description
Upgrading from 1.4.2 to 1.4.3 causes memorix memory store --text to fail with Error: named?.trim is not a function when the input text exceeds a certain length (around ~100 chars or so, seems content-dependent). Short text still works.
Environment
- memorix version: 1.4.3 (regression from 1.4.2 which works fine)
- OS: Windows 11 (also reproduced likely on any OS — error comes from JS not from OS shell)
- Node.js: v22.22.2
- Install:
npm install -g memorix@latest - Embedding provider:
MEMORIX_EMBEDDING_BASE_URL=http://localhost:3114/v1(local proxy, working correctly)
Steps to reproduce
# Short text — works
memorix memory store --text "short hello"
# → Stored observation #XXXX: short hello
# Long text (1750 chars, multi-line, Chinese + @ + English + special symbols) — fails
memorix memory store --text "$(Get-Content long_file.txt -Raw)"
# → Error: named?.trim is not a function
Expected
Long text should be stored successfully, same as short text.
Actual
[memorix] API embedding: default @ http://localhost:3114/v1 (1024d) [dims-cache]
Error: named?.trim is not a function
[memorix] Loaded 2778 cached API embeddings from disk
The observation is not stored. No exit code error shown (PowerShell exit 0 because node exit was caught by the wrapper).
Workaround
Stay on 1.4.2 (npm install -g [email protected]). Confirmed working for the same long-text input.
Additional context
I bisected locally. The error appears content-dependent — the same 1750-char text with line breaks stripped (text.Replace("\r", "").Replace("\n", " ")) still fails. But short strings (under ~100 chars) with the same characters (Chinese, @, <>, etc.) work fine.
Looks like a regression in how the --text argument is parsed/normalized when it has more than a small amount of content. Possibly the named variable (probably a destructure from a citty command definition) is being assigned a non-string value (array? object?) for long input, and .trim() is being called on it without a guard.
Test artifacts
I left several test observations in my local store:
#3654— short text with\nliterals + 100xchars + special symbols → stored OK, 71 tokens#3651— 1750 chars read from UTF-8 file with same content profile → FAILED with named?.trim error, but output said "Stored observation #3651: opencode-mem 2.14.3 到 2.24.3" before the error (inconsistent state — title-only?)- The failing text was UTF-8 (1750 chars), with content like:
opencode-mem 2.14.3 到 2.24.3 升级完成,踩坑合集: 【升级路径】...plus technical references with single quotes, backticks, parentheses, and Chinese punctuation.
Update: 1.4.2 has the same bug
I downgraded to 1.4.2 to test the workaround. The same 1750-char text also fails on 1.4.2 with the same Error: named?.trim is not a function. So this is not a 1.4.3 regression — it was already present in 1.4.2 but with a higher trigger threshold (1.4.3 just lowered it).
1.4.2 reproduction (latest test, ExitCode=1)
PS> & "F:\npm-global\node.exe" "F:\npm-global\node_modules\memorix\dist\cli\index.js" memory store --text (1750-char UTF-8 string)
[memorix] API embedding: default @ http://localhost:3114/v1 (1024d) [dims-cache]
Error: named?.trim is not a function
[memorix] Loaded 2779 cached API embeddings from disk
EXIT=1
What still works on 1.4.2
- Text < ~500 chars with same character profile: stores OK
- Short ASCII (under ~100 chars): stores OK
- Multi-line short: stores OK
.cmdwrapper path also fails the same way (cmd.exe argument length is not the issue, sincenodedirect invocation also fails)
Updated test observations
#3654— short text with\nliterals + 100xchars + special symbols → stored OK, 71 tokens (re-confirmed on 1.4.2)#3657— short cmd-line text (inline) → stored with\\only (cmd.exe arg truncation, separate issue)- New failed attempts (ExitCode=1, not stored):
- 1.4.3 with 1750-char file:
named?.trim - 1.4.2 with 1750-char file:
named?.trim
- 1.4.3 with 1750-char file:
Updated workaround
There is no clean workaround for long text. Options:
- Split into multiple short observations (lossy)
- Pre-summary the text (lossy)
- Use a different MCP path (the issue is in the CLI, MCP server may have the same problem)
I will likely keep 1.4.2 since 1.4.3 made it worse, but this bug blocks any non-trivial memory write.
Suspected location in source
The named variable name suggests it comes from a citty command argument destructure (citty uses named for non-positional args). Probably dist/cli/index.js or a service in dist/services/. The fact that .trim() is called without optional chaining (named?.trim() is the error message — wait, it IS optional chaining but the right side still throws) suggests the variable exists but is not a string at that point — likely the argument is sometimes an array (e.g., when the user passes --text "a" "b" "c") and .trim() gets called on the array.
Could the long-text case cause citty to split the value into an array of arguments somehow? Or could a shell layer (the .cmd / bash wrapper, or fnm shimming) be involved?
Either way, I think the fix is in memorix's code: coerce named to a string before .trim(), or just use String(named).trim().
Thanks for the detailed report — and especially for bisecting 1.4.2 yourself. That saved a lot of time.
Your instinct about named was right, just one layer up. The crash is in the CLI's argument handling, not anything 1.4.3-specific. getStringArg in src/cli/commands/memory.ts calls .trim() on the citty-parsed --text value, and citty turns a repeated flag into an array (--text a --text b → ["a", "b"]), so .trim() blows up with exactly this error.
The reason it only bites on long text is Windows PowerShell 5.1's native argument passing: it doesn't escape embedded double quotes, so a single quoted argument gets re-split at each ". When the text itself mentions --text (like a note documenting this very command), the split fragments re-introduce the flag and citty sees it twice. Quick repro on PS 5.1:
$t = 'opencode upgrade: run "memorix memory store --text "upgrade note"" after.'
node -e "console.log(JSON.stringify(process.argv.slice(1)))" memory store --text $t
# ["memory","store","--text","opencode upgrade: run memorix","memory","store","--text","upgrade note\" after."]
That also explains both symptoms you saw:
- the
#3651"stored, but title-only" run: that text had no second--text, so the store succeeded — but only the first argv fragment survived as the narrative (silent truncation, same PS 5.1 splitting); - and the "not a clean 1.4.3 regression" part:
memory.tsdidn't change between 1.4.2 and 1.4.3, so the differing thresholds are just content-dependent, as you concluded.
Fix is up in #195: the CLI now coerces repeated flags instead of assuming strings — free-text args join their fragments, scalar/enum flags take the last value — with regression tests covering repeated --text. The crash is gone and the recoverable fragments are preserved. A few words around the embedded quotes can still be lost because the shell already destroyed them before the process saw them, but that part isn't recoverable from inside the app.
Until it ships, the practical workarounds are: use PowerShell 7.3+ or bash for these commands, or avoid embedded ASCII double quotes in the text (single quotes and Chinese quotes don't split).
Thanks again for the solid repro — the argv-level detail was the key to pinning this down.
The fix from #195 is now merged and will ship in the next release.
To recap: the crash came from citty accumulating a repeated --text flag into an array, and Windows PowerShell 5.1's native argument passing splitting your long quoted argument at embedded double quotes — which re-introduced the --text token from the text itself as a second flag. The CLI now joins repeated free-text arguments and takes the last value for scalar flags, so the crash is gone; the recoverable text fragments are preserved.
The PS 5.1 splitting itself is a shell behavior Memorix can't fully undo — a few words around embedded quotes can still be lost before the process ever sees them — so until the release is out, PowerShell 7.3+ (or bash) or avoiding embedded ASCII double quotes in the text remain the practical workarounds.
Thanks again for the report — the argv-level detail made this straightforward to pin down.
Shipped in 1.4.4 — published to npm (with provenance), the official MCP Registry, and GitHub Releases today.
npm install -g memorix@latest gets the fix. If you can, please confirm the long-text store works for you on 1.4.4; if anything still looks off on Windows PowerShell 5.1, reopen or comment here and I'll dig back in.
Thanks again for the report.