From 4447f9b5209f79177e29421117b04e19fcb341aa Mon Sep 17 00:00:00 2001 From: Gergo Magyar Date: Mon, 21 Sep 2026 07:51:03 +0000 Subject: [PATCH] Address PR review feedback (#3339) Memoize live tRPC mount paths so the depth-N chain bench stays linear, and render invalid group/MCP bounds without throwing. Co-authored-by: Cursor --- gitnexus/src/core/group/service.ts | 4 +- .../core/ingestion/route-extractors/trpc.ts | 9 +++-- gitnexus/src/mcp/local/local-backend.ts | 12 +++++- gitnexus/test/unit/group/service.test.ts | 37 +++++++++++++++---- 4 files changed, 47 insertions(+), 15 deletions(-) diff --git a/gitnexus/src/core/group/service.ts b/gitnexus/src/core/group/service.ts index 15441f625..2ab72bffc 100644 --- a/gitnexus/src/core/group/service.ts +++ b/gitnexus/src/core/group/service.ts @@ -463,7 +463,7 @@ function parseGroupQueryBound( if (typeof value !== 'number' || !Number.isInteger(value) || value < 1 || value > max) { return { ok: false, - error: `Invalid "${field}": expected an integer in [1, ${max}], got ${JSON.stringify(value)}.`, + error: `Invalid "${field}": expected an integer in [1, ${max}], got ${describeValue(value)}.`, }; } return { ok: true, value }; @@ -481,7 +481,7 @@ function parseGroupChainDepth( ) { return { ok: false, - error: `Invalid "chain_depth": expected an integer in [0, ${GROUP_CHAIN_MAX_DEPTH}], got ${JSON.stringify(value)}.`, + error: `Invalid "chain_depth": expected an integer in [0, ${GROUP_CHAIN_MAX_DEPTH}], got ${describeValue(value)}.`, }; } return { ok: true, value }; diff --git a/gitnexus/src/core/ingestion/route-extractors/trpc.ts b/gitnexus/src/core/ingestion/route-extractors/trpc.ts index 17b4958a2..4734560cb 100644 --- a/gitnexus/src/core/ingestion/route-extractors/trpc.ts +++ b/gitnexus/src/core/ingestion/route-extractors/trpc.ts @@ -496,9 +496,12 @@ function buildMountPathLookup( if (out.length > 0) result = out; } visiting.delete(binding); - // Nested cycle cuts return [] for this hop only. Memoizing that empty - // walk would drop a later live path (`a.b.list` after `a` ↔ `b`). - if (visiting.size === 0) memo.set(binding, result); + // Memoize live paths immediately so a depth-N chain is one walk, not one + // remount per procedure. Leave nested empty results uncached: a cycle cut + // returns [] for this hop only, and memoizing that would drop a later live + // path (`a.b.list` after `a` ↔ `b`). A finished top-level [] is real + // (unmounted / no root path) and is safe to cache. + if (result.length > 0 || visiting.size === 0) memo.set(binding, result); return result; }; } diff --git a/gitnexus/src/mcp/local/local-backend.ts b/gitnexus/src/mcp/local/local-backend.ts index 63cd84a4d..34616a734 100644 --- a/gitnexus/src/mcp/local/local-backend.ts +++ b/gitnexus/src/mcp/local/local-backend.ts @@ -1467,6 +1467,14 @@ export function parseListReposPagination( * inputSchema — so the backend rejects out-of-range values the same way * parseListReposPagination / pdg_query do (reject, not clamp). */ +function describeBoundValue(raw: unknown): string { + try { + return JSON.stringify(raw) ?? String(raw); + } catch { + return typeof raw === 'bigint' ? `${raw}n` : Object.prototype.toString.call(raw); + } +} + function parseQueryPageBound( value: unknown, field: 'limit' | 'max_symbols', @@ -1477,7 +1485,7 @@ function parseQueryPageBound( if (typeof value !== 'number' || !Number.isInteger(value) || value < 1 || value > max) { return { ok: false, - error: `Invalid "${field}": expected an integer in [1, ${max}], got ${JSON.stringify(value)}.`, + error: `Invalid "${field}": expected an integer in [1, ${max}], got ${describeBoundValue(value)}.`, }; } return { ok: true, value }; @@ -1495,7 +1503,7 @@ function parseChainDepth( ) { return { ok: false, - error: `Invalid "chain_depth": expected an integer in [0, ${CONTEXT_CHAIN_MAX_DEPTH}], got ${JSON.stringify(value)}.`, + error: `Invalid "chain_depth": expected an integer in [0, ${CONTEXT_CHAIN_MAX_DEPTH}], got ${describeBoundValue(value)}.`, }; } return { ok: true, value }; diff --git a/gitnexus/test/unit/group/service.test.ts b/gitnexus/test/unit/group/service.test.ts index 48d48ceaa..f56522ef9 100644 --- a/gitnexus/test/unit/group/service.test.ts +++ b/gitnexus/test/unit/group/service.test.ts @@ -341,25 +341,46 @@ describe('GroupService', () => { const query = vi.fn(async () => ({ processes: [] })); const svc = new GroupService(makePort({ query })); - const overLimit = await svc.groupQuery({ + const infiniteLimit = await svc.groupQuery({ name: 'test-group', query: 'auth flow', limit: Infinity, - max_symbols: 9999, }); - expect(overLimit).toMatchObject({ error: expect.stringMatching(/Invalid "limit"/) }); - expect(query).not.toHaveBeenCalled(); + expect(infiniteLimit).toMatchObject({ error: expect.stringMatching(/Invalid "limit"/) }); - const overSymbols = await svc.groupQuery({ + const oversizedLimit = await svc.groupQuery({ + name: 'test-group', + query: 'auth flow', + limit: 101, + }); + expect(oversizedLimit).toMatchObject({ error: expect.stringMatching(/Invalid "limit"/) }); + + const infiniteSymbols = await svc.groupQuery({ name: 'test-group', query: 'auth flow', - limit: 3, max_symbols: Infinity, }); - expect(overSymbols).toMatchObject({ + expect(infiniteSymbols).toMatchObject({ error: expect.stringMatching(/Invalid "max_symbols"/), }); - expect(query).not.toHaveBeenCalled(); + + const oversizedSymbols = await svc.groupQuery({ + name: 'test-group', + query: 'auth flow', + max_symbols: 201, + }); + expect(oversizedSymbols).toMatchObject({ + error: expect.stringMatching(/Invalid "max_symbols"/), + }); + + const cyclic = { self: null as unknown }; + cyclic.self = cyclic; + const cyclicLimit = await svc.groupQuery({ + name: 'test-group', + query: 'auth flow', + limit: cyclic, + }); + expect(cyclicLimit).toMatchObject({ error: expect.stringMatching(/Invalid "limit"/) }); const badDepth = await svc.groupQuery({ name: 'test-group',