feat(search): require versioned index envs, derive template + read patterns#174
Conversation
📝 WalkthroughWalkthroughThis PR adds a new ChangesSearch Index Environment-Variable Contract & Version Handling
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
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)
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 |
f63dce6 to
bd7008c
Compare
…tterns - New pkg/searchindex.StripVersion helper splits "<base>-v<N>" inputs. - search-sync-worker: make MSG_INDEX_PREFIX, SPOTLIGHT_INDEX, USER_ROOM_INDEX all required. Validate "-v<N>$" on messages/spotlight at startup. USER_ROOM_INDEX is intentionally unversioned (ES terms_lookup rejects wildcards and the index is rebuildable from Mongo). - messages and spotlight: derive template name + index_patterns from the stripped base so future v2/v3 indices inherit the same template; write target stays the full versioned name. - user-room: derive template name from env value; index_patterns is the exact single index, matching the terms_lookup constraint. - search-service: validate SEARCH_SPOTLIGHT_INDEX "-v<N>" suffix and derive a "<base>-*" read pattern so queries span versions during reindex windows. SEARCH_USER_ROOM_INDEX flows through unchanged for use in terms_lookup. Drop dead UserRoomIndex constant and resolveUserRoomIndex empty-string fallback now that the env is required. - docker-compose: set the new env values for both services. https://claude.ai/code/session_01E2Cc6bj5Qo8GsYwZV8YEC2
bd7008c to
673436a
Compare
…Pattern rename, address coderabbit nitpicks - Update setupAppsFixture to use SpotlightReadPattern (handlerConfig field was renamed in #174, which landed in main after this branch forked — CI's merge-of-PR-and-base surfaced the mismatch). - Add natsrouter.RequestID() middleware to the apps fixture's router so request-ID propagation matches the rest of the file (coderabbit nit). - Switch assert.Len → require.Len before indexing resp.Apps to avoid a panic on length mismatch (coderabbit nit). https://claude.ai/code/session_011cH1YdP4Tf88cidbSy6idf
Summary
pkg/searchindexpackage withStripVersion(name) → (base, version, ok)andStripVersionBase(name) → basehelpers (single source of truth for the-v<N>$parsing rule).search-sync-worker:MSG_INDEX_PREFIX,SPOTLIGHT_INDEX,USER_ROOM_INDEXare all now,required(no silent empty defaults). Messages and spotlight values must end in-v<N>— validated at startup, fails fast with a clear error. User-room is intentionally unversioned (ESterms_lookuprejects wildcards, and the index is rebuildable from Mongo).index_patternsare now derived from the stripped base (e.g.messages-site-a_template+messages-site-a-*) so future v2/v3 indices auto-inherit the template. The actual write target (monthly index for messages, concrete versioned index for spotlight) stays unchanged.user_room_template, so each deployment gets a uniquely-named template.index_patternsis the single concrete name (matching theterms_lookupconstraint).search-service: validatesSEARCH_SPOTLIGHT_INDEXends in-v<N>and derives a<base>-*read pattern at startup so message-search and room-search span all versions during reindex windows. Handler field renamedSpotlightIndex→SpotlightReadPatternto reflect the new semantics.SEARCH_USER_ROOM_INDEXflows through unchanged (concrete name required forterms_lookup).const UserRoomIndex = "user-room"andresolveUserRoomIndexempty-string fallback insearch-servicenow that the env is required.docker-composefiles for both services updated with values that match the new contract (spotlight-site-local-v1,user-room-mv-site-local).docs/superpowers/plans/2026-05-13-search-index-env-vars.mdcaptures the design and reindex playbook.Reindex flow this unlocks
-v1. search-service queries<base>-*(matches v1).<base>-v2indices manually or via ES template auto-create._reindexv1 → v2 out of band.-v2, redeploy. Writes go to v2; reads via<base>-*see both.User-room doesn't get this flow by design — rebuild from Mongo subscriptions if its schema ever needs a breaking change.
Test plan
make test— all packages green.make lint— 0 issues.go vet -tags integration ./search-service/... ./search-sync-worker/...— clean.make test-integration SERVICE=search-sync-workerandmake test-integration SERVICE=search-service(require Docker — to run in CI).docker compose upfor both services brings them up with the new env values; ES shows three templates (messages-site-local_template,spotlight-site-local_template,user-room-mv-site-local_template).Out of scope
spotlight-{site}-v1-chatvalue needs a coordinated rename (this PR only touches local-dev compose).*:patterns today.make reindextarget if needed.https://claude.ai/code/session_01E2Cc6bj5Qo8GsYwZV8YEC2
Generated by Claude Code
Summary by CodeRabbit
Documentation
Refactor
-v<N>suffix; user-room index remains unversioned for terms_lookup compatibility.Tests