From c1903709b995f1b5c670b7774e904aafb263428b Mon Sep 17 00:00:00 2001 From: Gergo Magyar Date: Wed, 23 Sep 2026 17:56:58 +0000 Subject: [PATCH] fix(query): send hub content once across process_symbols rows With include_content, a symbol in several execution flows carried its full source text on every (id, process_id) row. Keep content on the first row for each symbol id and omit it from later rows. Membership fields, is_entry_point, and symbol_count are unchanged. Co-Authored-By: Claude Opus 5.5 (1M context) --- gitnexus/src/mcp/local/query-process-attaches.ts | 15 +++++++++++++-- gitnexus/src/mcp/tools.ts | 2 +- .../test/unit/mcp/query-process-attaches.test.ts | 9 ++++----- gitnexus/test/unit/tools.test.ts | 3 +++ 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/gitnexus/src/mcp/local/query-process-attaches.ts b/gitnexus/src/mcp/local/query-process-attaches.ts index 963978118..bb81531c7 100644 --- a/gitnexus/src/mcp/local/query-process-attaches.ts +++ b/gitnexus/src/mcp/local/query-process-attaches.ts @@ -5,6 +5,8 @@ * Aggregation already pushes a hub onto every owning process. This helper * is the last shaping step: slice each process to `max_symbols`, keep one * row per `(id, process_id)`, then set `symbol_count` from those rows. + * `content` stays only on the first row for each symbol id so a hub in + * many flows does not repeat its source text. */ export type QueryProcessAttach = { @@ -55,6 +57,7 @@ export function shapeQueryProcessAttaches( ): { processes: QueryProcessCard[]; process_symbols: S[] } { const { maxSymbolsPerProcess, chainByProcessId } = options; const seen = new Set(); + const contentSeen = new Set(); const process_symbols: S[] = []; const countByProcess = new Map(); @@ -63,8 +66,16 @@ export function shapeQueryProcessAttaches( const key = attachPairKey(s.id, s.process_id); if (seen.has(key)) continue; seen.add(key); - const row = - p.entryPointId && s.id === p.entryPointId ? ({ ...s, is_entry_point: true } as S) : s; + let row: S = s; + if (s.content !== undefined) { + if (contentSeen.has(s.id)) { + const { content: _content, ...rest } = s; + row = rest as S; + } else { + contentSeen.add(s.id); + } + } + if (p.entryPointId && s.id === p.entryPointId) row = { ...row, is_entry_point: true }; process_symbols.push(row); countByProcess.set(s.process_id, (countByProcess.get(s.process_id) ?? 0) + 1); } diff --git a/gitnexus/src/mcp/tools.ts b/gitnexus/src/mcp/tools.ts index 4daaf27d4..394eed086 100644 --- a/gitnexus/src/mcp/tools.ts +++ b/gitnexus/src/mcp/tools.ts @@ -148,7 +148,7 @@ AFTER THIS: Use context() on a specific symbol for 360-degree view (callers, cal Returns results grouped by process (execution flow): - processes: ranked execution flows with relevance priority. When a process has an HTTP endpoint, each item includes route and method string aliases plus routes: [{ url, method? }] (same shape as context). When chain_depth > 0, each item also includes chain — layered upstream callers + downstream callees from the process entry symbol (same BFS as context({chain_depth})). -- process_symbols: search-hit symbols in those flows with file locations and module (functional area). On the single-repo envelope { processes, process_symbols, definitions }: One row per (id, process_id) — the same symbol id may appear under more than one process. Join a process to its rows by process_id; symbol_count is the number of those rows. When the process entry is among those hits, it is marked is_entry_point: true. A repo of "@" returns { group, query, results, per_repo } and does not include process_symbols. results[].symbol_count is the member's post-slice attach count; when service is set, it counts only attaches under that prefix. To get process_symbols for one member, query again with repo "@/" (member path from group.yaml, or results[]._repo). +- process_symbols: search-hit symbols in those flows with file locations and module (functional area). On the single-repo envelope { processes, process_symbols, definitions }: One row per (id, process_id) — the same symbol id may appear under more than one process. Join a process to its rows by process_id; symbol_count is the number of those rows. When the process entry is among those hits, it is marked is_entry_point: true. With include_content, content appears only on the first row for each symbol id; later rows for that id omit it. A repo of "@" returns { group, query, results, per_repo } and does not include process_symbols. results[].symbol_count is the member's post-slice attach count; when service is set, it counts only attaches under that prefix. To get process_symbols for one member, query again with repo "@/" (member path from group.yaml, or results[]._repo). - definitions: standalone types/interfaces not in any process. Keyword hits on Route URLs (route_fts) are bridged to their handler via HANDLES_ROUTE (handlerSymbolId, routes) when the edge exists; use route_map({route}) for the full HTTP surface. Hybrid ranking: BM25 keyword + semantic vector search, ranked by Reciprocal Rank Fusion. diff --git a/gitnexus/test/unit/mcp/query-process-attaches.test.ts b/gitnexus/test/unit/mcp/query-process-attaches.test.ts index 23e368303..bdea8868e 100644 --- a/gitnexus/test/unit/mcp/query-process-attaches.test.ts +++ b/gitnexus/test/unit/mcp/query-process-attaches.test.ts @@ -102,7 +102,7 @@ describe('shapeQueryProcessAttaches', () => { expect(processes[0]?.symbol_count).toBe(1); }); - it('keeps include_content on every emitted hub attach (KTD5)', () => { + it('keeps include_content only on the first row for a hub id', () => { const { process_symbols } = shapeQueryProcessAttaches( [ ranked('proc:login-flow', [ @@ -115,10 +115,9 @@ describe('shapeQueryProcessAttaches', () => { { maxSymbolsPerProcess: 25 }, ); - expect(process_symbols.map((s) => s.content)).toEqual([ - 'function validate() {}', - 'function validate() {}', - ]); + expect(process_symbols.map((s) => s.process_id)).toEqual(['proc:login-flow', 'proc:beta-flow']); + expect(process_symbols[0]?.content).toBe('function validate() {}'); + expect(process_symbols[1]).not.toHaveProperty('content'); }); it('marks the entry-point hit and preserves process card extras', () => { diff --git a/gitnexus/test/unit/tools.test.ts b/gitnexus/test/unit/tools.test.ts index aba1c7fd8..97cb1ee42 100644 --- a/gitnexus/test/unit/tools.test.ts +++ b/gitnexus/test/unit/tools.test.ts @@ -136,6 +136,9 @@ describe('GITNEXUS_TOOLS', () => { 'when service is set, it counts only attaches under that prefix', ); expect(queryTool.description).toContain('query again with repo "@/"'); + expect(queryTool.description).toContain( + 'content appears only on the first row for each symbol id', + ); }); it('query tool requires "search_query" parameter (renamed from "query" for #2175)', () => {