{"record":{"id":"63037d1a4d74f84a","repo":"abhigyanpatwari/GitNexus","slug":"branch-branch-is-not-indexed-for-handle-na","errorCode":null,"errorMessage":"Branch \"${branch}\" is not indexed for \"${handle.name}\". Indexed branches: ${available}. The workspace index follows the checked-out branch — check out \"${branch}\" and re-run: gitnexus analyze (add --branch ${branch} while it is checked out to pin a separate sub-index).","messagePattern":"Branch \"(.+?)\" is not indexed for \"(.+?)\"\\. Indexed branches: (.+?)\\. The workspace index follows the checked-out branch — check out \"(.+?)\" and re-run: gitnexus analyze \\(add --branch (.+?) while it is checked out to pin a separate sub-index\\)\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gitnexus/src/mcp/local/local-backend.ts","lineNumber":1953,"sourceCode":"\n    // Every miss refreshes once before erroring: newly-pinned branches and\n    // restamped labels the cached handle predates become resolvable on the\n    // caller's next attempt (the cache otherwise only refreshes on repo-\n    // resolution misses and list_repos).\n    await refreshOnce();\n\n    // The flat slot's label comes from the authoritative meta when readable —\n    // never echo a cached label the meta just contradicted (a \"not indexed:\n    // main / indexed: main\" self-contradiction). Cached summaries may still\n    // lag; they are a hint, not a promise.\n    const flatLabel = flatMeta?.branch ?? handle.branch;\n    const indexed = [flatLabel, ...(handle.branches?.map((b) => b.branch) ?? [])].filter(\n      (b) => Boolean(b) && b !== branch,\n    );\n    const available = indexed.length > 0 ? indexed.join(', ') : '(workspace only)';\n    // Post-#2354 a bare `analyze --branch <X>` refuses to run unless X is\n    // checked out, so the guidance must lead with the checkout (#2364 F6).\n    throw new Error(\n      `Branch \"${branch}\" is not indexed for \"${handle.name}\". ` +\n        `Indexed branches: ${available}. The workspace index follows the ` +\n        `checked-out branch — check out \"${branch}\" and re-run: gitnexus analyze ` +\n        `(add --branch ${branch} while it is checked out to pin a separate sub-index).`,\n    );\n  }\n\n  /**\n   * Try to resolve a repo from the in-memory cache. Returns null on miss.\n   * Throws {@link RegistryAmbiguousTargetError} when `repoParam` matches\n   * multiple handles by name and cwd cannot disambiguate (#1658).\n   */\n  private resolveRepoFromCache(repoParam?: string, allowCwdDefault = false): RepoHandle | null {\n    if (this.repos.size === 0) return null;\n\n    if (repoParam) {\n      const paramLower = repoParam.toLowerCase();\n      const looksLikePath =","sourceCodeStart":1935,"sourceCodeEnd":1971,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/0d1aed942f0e8b5d3bac27519fff441aceea722d/gitnexus/src/mcp/local/local-backend.ts#L1935-L1971","documentation":"applyBranchScope could not point the resolved handle at the requested branch: no sub-index exists for it and it is not the flat workspace slot's recorded branch. The flat slot's label is read from authoritative on-disk meta (never a stale cached label, #2364), the error lists the branches that ARE indexed, and — because post-#2354 `analyze --branch <X>` refuses to run unless X is checked out — the guidance leads with checking out the branch.","triggerScenarios":"Calling a repo-scoped tool with branch: \"feature-x\" when only main is indexed (the workspace index follows the checked-out branch); passing a branch name whose sub-index was deleted; querying a branch that exists remotely but was never checked out and analyzed locally.","commonSituations":"Agents diffing review branches by name without a local checkout; worktrees where the flat slot follows a different branch than requested; users assuming remote branches are indexed automatically; sub-indexes cleaned up by registry maintenance.","solutions":["Check out the branch and re-index: `git checkout feature-x && gitnexus analyze` — the workspace index follows the checked-out branch.","To keep a separate pinned sub-index, check the branch out first, then run `gitnexus analyze --branch feature-x` while it is checked out.","Or drop the branch parameter to query the current workspace index.","Verify what is indexed via the error's 'Indexed branches:' list or gitnexus status before retrying."],"exampleFix":"# before: branch never indexed\n{\"tool\": \"impact\", \"args\": {\"target\": \"login\", \"repo\": \"myrepo\", \"branch\": \"feature-x\"}}\n# → Branch \"feature-x\" is not indexed ...\n\n# after: check out, re-analyze, then query\n$ git checkout feature-x && gitnexus analyze\n{\"tool\": \"impact\", \"args\": {\"target\": \"login\", \"repo\": \"myrepo\", \"branch\": \"feature-x\"}}\n# or pin a separate sub-index while checked out:\n$ gitnexus analyze --branch feature-x","handlingStrategy":"validation","validationCode":"// Before passing branch, confirm it is among the repo's indexed branches\nconst status = await client.callTool({ name: 'status', arguments: { repo } });\nconst indexedBranches = [\n  status.branch,                          // flat workspace slot (checked-out branch)\n  ...(status.branches ?? []).map((b: any) => b.branch),\n].filter(Boolean);\n\nfunction assertIndexedBranch(branch?: string): void {\n  if (branch && !indexedBranches.includes(branch)) {\n    throw new Error(`branch \"${branch}\" not indexed for \"${repo}\". Indexed: ${indexedBranches.join(', ')}`);\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  return await client.callTool({ name: 'impact', arguments: { ...args, repo, branch } });\n} catch (err) {\n  if (err instanceof Error && err.message.includes('is not indexed for')) {\n    // parse 'Indexed branches:' and either re-target an indexed branch or drop the param\n    const indexed = err.message.match(/Indexed branches: ([^.]+)/)?.[1];\n    logger.warn(`branch ${branch} missing; indexed: ${indexed} — querying workspace index instead`);\n    return client.callTool({ name: 'impact', arguments: { ...args, repo } });\n  }\n  throw err;\n}","preventionTips":["Query status (or the error's Indexed branches list) before passing a branch parameter.","Remember the flat index follows the checked-out branch: checkout + analyze is the refresh path.","Use `gitnexus analyze --branch <X>` only while X is checked out, to pin sub-indexes.","In CI, index the exact branch under review before running branch-scoped graph tools."],"tags":["mcp","branch","index","git","apply-branch-scope"],"backgroundTag":"branch-not-indexed","analyzedSha":"0d1aed942f0e8b5d3bac27519fff441aceea722d","analyzedAt":"2026-08-20T23:29:22.980Z","contentChangedAt":"2026-08-20T23:29:22.980Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}