Skip to content

fix(put): lowercase caller-supplied slug in importFromContent (#200)#207

Open
sharziki wants to merge 1 commit intogarrytan:masterfrom
sharziki:fix/put-uppercase-slug
Open

fix(put): lowercase caller-supplied slug in importFromContent (#200)#207
sharziki wants to merge 1 commit intogarrytan:masterfrom
sharziki:fix/put-uppercase-slug

Conversation

@sharziki
Copy link
Copy Markdown
Contributor

Summary

Fixes #200gbrain put <slug> with uppercase letters failed with the misleading error Page not found: <slug>, identical to the gbrain get error for a genuinely missing page.

Root cause

putPage runs validateSlug internally and stores the page at the lowercased slug. However, the same-transaction calls that follow (tx.upsertChunks, tx.getTags, tx.addTag, tx.removeTag) use whatever slug the caller handed to importFromContent. With claude-memory/TestUpper/test the upsertChunks lookup hits SELECT id FROM pages WHERE slug = 'claude-memory/TestUpper/test', finds nothing, and throws Page not found: claude-memory/TestUpper/test — the exact message get_page emits for a genuine miss.

The bug reporter's 236-file bulk migration silently dropped 30 writes under claude-memory/DogskinMap/* and claude-memory/SolarPower/* until they A/B-tested TestUpper vs testlower.

Fix

Lowercase the slug once at the top of importFromContent so putPage, getTags, addTag, removeTag, and upsertChunks all operate on the same normalized slug.

Test plan

  • Added a regression test in test/import-file.test.ts that feeds an uppercase slug through importFromContent and asserts both putPage and upsertChunks are called with the lowercased slug.
  • bun test test/import-file.test.ts — 17 pass, 0 fail.

🤖 Generated with Claude Code

putPage runs validateSlug internally and stores the page at the
lowercased slug, but the same-transaction tx.upsertChunks/getTags/addTag
lookups use whatever slug the caller passed in. When a user ran
`gbrain put claude-memory/TestUpper/test ...` the put_page handler
forwarded the uppercase slug straight through and upsertChunks failed
with "Page not found: claude-memory/TestUpper/test" — the same message
`get_page` emits for a genuinely missing page, so users debugging a
failing bulk put chased phantom "did the page get deleted?" paths
instead of the real cause (issue garrytan#200).

Normalize once at the top of importFromContent so putPage, getTags,
addTag, removeTag, and upsertChunks all operate on the same lowercased
slug. Added a regression test covering the mock-engine call arguments.

Fixes garrytan#200
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Misleading error: "Page not found" when gbrain put receives a slug with uppercase letters

1 participant