Skip to content

fix(sqlite): hydrate merged_into_project records on semantic-search ID lookups (closes #3331)#3342

Open
rodboev wants to merge 6 commits into
thedotmack:mainfrom
rodboev:pr/3331-merged-project-id-hydration
Open

fix(sqlite): hydrate merged_into_project records on semantic-search ID lookups (closes #3331)#3342
rodboev wants to merge 6 commits into
thedotmack:mainfrom
rodboev:pr/3331-merged-project-id-hydration

Conversation

@rodboev

@rodboev rodboev commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

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 unions merged_into_project into 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

SearchManager already builds a semantic-search where-filter that matches either project or merged_into_project. The loss happens later, when getObservationsByIds(...), 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_project fields. Chroma lookups now constrain each batch by doc_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 assertions
  • bun test tests/services/sqlite/search-platform-source-scoping.test.ts — 11 passing, 0 failing, 23 assertions
  • bun test tests/worker/SearchManager.timeline-anchor.test.ts — 8 passing, 0 failing, 32 assertions
  • npm run typecheck — passed
  • npm run build — passed, all build targets compiled successfully
  • npm run lint:hook-iohook-io discipline: OK (handlers + adapters are pure)
  • npm run lint:spawn-envspawn-env discipline: OK (all env-bearing spawns sanitize process.env)
  • npm run strip-comments:check — exits 1 with Changed: 316 (check mode, no writes)
  • Runtime base/head reproduction — base drops redirected observation and summary IDs; head hydrates both under the merged parent project
  • Redirected timeline regression — base drops redirected timeline context under the merged parent project; head keeps the redirected observation and summary context
  • Summary-only adoption regression — bun test tests/services/infrastructure/worktree-adoption-chroma.test.ts — 1 passing, 0 failing
  • Typed Chroma lookup regression — bun test tests/services/sync/chroma-merged-project-typed-lookup.test.ts — 3 passing, 0 failing

Closes #3331

@greptile-apps

greptile-apps Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes merged-worktree semantic-search hydration. The main changes are:

  • SQLite observation and session-summary ID lookups now include rows redirected with merged_into_project.
  • Observation timeline scope now keeps redirected observations and summaries under the merged parent project.
  • Worktree adoption now sends typed observation and session-summary Chroma targets for merged_into_project metadata updates.
  • Chroma metadata patching now constrains lookups by doc_type to avoid sqlite_id collisions with prompt documents.
  • Tests cover merged-project hydration, redirected timelines, typed Chroma lookups, summary-only adoption, and mock cleanup.

Confidence Score: 5/5

Safe 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.

T-Rex T-Rex Logs

What T-Rex did

  • The primary hydration regression command was executed and completed with exit code 0, with Bun output and timestamps recorded in the log.
  • The remaining focused hydration regression command was executed and completed with exit code 0, with Bun output and timestamps recorded in the log.
  • Logs for both hydration regression runs were collected to support contract validation and review.

View all artifacts

T-Rex Ran code and verified through T-Rex

Important Files Changed

Filename Overview
src/services/sqlite/SessionStore.ts Widens project-scoped observation and session-summary ID hydration plus timeline scoping to include rows redirected via merged_into_project while leaving prompt scope unchanged.
src/services/sync/ChromaSync.ts Updates merged-project Chroma metadata by typed document batches to avoid sqlite_id collisions across document categories.
src/services/infrastructure/WorktreeAdoption.ts Collects adopted observation and session-summary targets with explicit Chroma document types before patching merged-project metadata.
tests/services/sqlite/merged-project-id-hydration.test.ts Adds tests for merged-project observation and summary hydration, timeline context, and native prompt scoping.
tests/services/sync/chroma-merged-project-typed-lookup.test.ts Adds tests for typed Chroma lookups that patch observations and session summaries without prompt collisions.
tests/services/infrastructure/worktree-adoption-chroma.test.ts Adds coverage for summary-only worktree adoption patching session-summary Chroma documents.

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
Loading
%%{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
Loading

Reviews (3): Last reviewed commit: "test(sync): restore process-global Chrom..." | Re-trigger Greptile

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.

merged_into_project is half-wired: semantic search drops merged/redirected records at SQLite hydration

1 participant