fix(sqlite): hydrate merged_into_project records on semantic-search ID lookups (closes #3331)#3342
Open
rodboev wants to merge 6 commits into
Open
fix(sqlite): hydrate merged_into_project records on semantic-search ID lookups (closes #3331)#3342rodboev wants to merge 6 commits into
merged_into_project records on semantic-search ID lookups (closes #3331)#3342rodboev wants to merge 6 commits into
Conversation
Contributor
Greptile SummaryThis PR fixes merged-worktree semantic-search hydration. The main changes are:
Confidence Score: 5/5Safe to merge with low risk. The production changes are narrowly scoped to project filtering and Chroma metadata updates. The typed Chroma lookup avoids the documented sqlite_id collision path. Focused tests cover the changed hydration, timeline, and adoption flows. No blocking correctness or security issues were found. No files require special attention.
What T-Rex did
Important Files Changed
Sequence Diagram%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
participant SM as SearchManager
participant CS as Chroma
participant SS as SessionStore
participant WA as WorktreeAdoption
SM->>CS: Search with project or merged_into_project filter
CS-->>SM: Return typed sqlite_id metadata
SM->>SS: Hydrate observations and summaries by IDs
SS-->>SM: Return rows scoped by project or merged_into_project
SM->>SS: Request redirected observation timeline
SS-->>SM: Return merged-parent observations and summaries
WA->>SS: Adopt merged worktree rows
SS-->>WA: Return observation and summary sqlite IDs
WA->>CS: Patch merged_into_project by doc_type and sqlite_id
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
participant SM as SearchManager
participant CS as Chroma
participant SS as SessionStore
participant WA as WorktreeAdoption
SM->>CS: Search with project or merged_into_project filter
CS-->>SM: Return typed sqlite_id metadata
SM->>SS: Hydrate observations and summaries by IDs
SS-->>SM: Return rows scoped by project or merged_into_project
SM->>SS: Request redirected observation timeline
SS-->>SM: Return merged-parent observations and summaries
WA->>SS: Adopt merged worktree rows
SS-->>WA: Return observation and summary sqlite IDs
WA->>CS: Patch merged_into_project by doc_type and sqlite_id
Reviews (3): Last reviewed commit: "test(sync): restore process-global Chrom..." | Re-trigger Greptile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Project-scoped semantic search already matches redirected observation and summary records in Chroma, but the follow-up SQLite consumers still filter those rows with exact
project = ?. This change unionsmerged_into_projectinto the two schema-backed ID hydrators, keeps redirected observation timelines on the same merged-parent scope, and carries adopted observation and session-summary IDs with explicit Chroma document types so summary-only worktrees hydrate their Chroma metadata without selecting colliding user prompts.Closes #3331
Why
SearchManageralready builds a semantic-search where-filter that matches eitherprojectormerged_into_project. The loss happens later, whengetObservationsByIds(...),getSessionSummariesByIds(...), and the downstream observation timeline scope narrow those matched IDs back to exact project equality. The fix belongs in those schema-backed consumers, because the redirect discriminator already exists there.Scope
This PR changes observation and session-summary ID hydration, redirected observation timeline scope, and the existing worktree-adoption-to-Chroma patch seam. Adoption writes still use the existing
merged_into_projectfields. Chroma lookups now constrain each batch bydoc_type; user-prompt documents remain outside this patch path.Risk
Low. The widened predicates key on the schema's existing redirect discriminator and only affect project scoping inside the two ID hydrators plus redirected observation timeline expansion. Native rows, foreign-project exclusion, prompt behavior, and platform-source filtering stay intact.
Verification
bun test tests/services/sqlite/merged-project-id-hydration.test.ts— 5 passing, 0 failing, 8 assertionsbun test tests/services/sqlite/search-platform-source-scoping.test.ts— 11 passing, 0 failing, 23 assertionsbun test tests/worker/SearchManager.timeline-anchor.test.ts— 8 passing, 0 failing, 32 assertionsnpm run typecheck— passednpm run build— passed, all build targets compiled successfullynpm run lint:hook-io—hook-io discipline: OK (handlers + adapters are pure)npm run lint:spawn-env—spawn-env discipline: OK (all env-bearing spawns sanitize process.env)npm run strip-comments:check— exits 1 withChanged: 316 (check mode, no writes)bun test tests/services/infrastructure/worktree-adoption-chroma.test.ts— 1 passing, 0 failingbun test tests/services/sync/chroma-merged-project-typed-lookup.test.ts— 3 passing, 0 failingCloses #3331