{"record":{"id":"edae3cb0007f3e17","repo":"ruvnet/ruflo","slug":"no-policy-bundle-loaded-call-loadbundle-first","errorCode":null,"errorMessage":"No policy bundle loaded. Call loadBundle() first.","messagePattern":"No policy bundle loaded\\. Call loadBundle\\(\\) first\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/guidance/src/retriever.ts","lineNumber":352,"sourceCode":"    const confidence = Math.min(bestScore / 3, 1);\n\n    return { intent: bestIntent, confidence };\n  }\n\n  /**\n   * Retrieve relevant shards for a task\n   *\n   * Contract:\n   * 1. Always include the constitution\n   * 2. Up to maxShards by semantic similarity\n   * 3. Hard filters by risk class and repo scope\n   * 4. Contradiction check: prefer higher priority\n   */\n  async retrieve(request: RetrievalRequest): Promise<RetrievalResult> {\n    const startTime = performance.now();\n\n    if (!this.constitution) {\n      throw new Error('No policy bundle loaded. Call loadBundle() first.');\n    }\n\n    // Step 1: Classify intent\n    const { intent: detectedIntent } = this.classifyIntent(request.taskDescription);\n    const intent = request.intent ?? detectedIntent;\n\n    // Step 2: Generate query embedding\n    const queryEmbedding = await this.embeddingProvider.embed(request.taskDescription);\n\n    // Step 3: Score all shards\n    const maxShards = request.maxShards ?? 5;\n    const scored = this.scoreShards(queryEmbedding, intent, request.riskFilter, request.repoScope);\n\n    // Step 4: Select top N with contradiction resolution\n    const selected = this.selectWithContradictionCheck(scored, maxShards);\n\n    // Step 5: Build combined policy text\n    const policyText = this.buildPolicyText(this.constitution, selected);","sourceCodeStart":334,"sourceCodeEnd":370,"githubUrl":"https://github.com/ruvnet/ruflo/blob/fa13ee4ad60ac2090b1480656eb233521790d640/v3/@claude-flow/guidance/src/retriever.ts#L334-L370","documentation":"PolicyRetriever.retrieve() requires a compiled PolicyBundle to have been loaded via loadBundle() — it throws while this.constitution is still unset. The same state is observable via the public getConstitution() accessor (null when unloaded). When the retriever is used inside GuidanceControlPlane, initialize() performs the load, so standalone usage that skips loadBundle() is the usual cause.","triggerScenarios":"Constructing new PolicyRetriever(provider) and calling retrieve() without awaiting loadBundle(); a loadBundle() call that failed earlier; using the retriever standalone (outside the control plane) in scripts or tests.","commonSituations":"Ad-hoc retrieval scripts; unit tests that instantiate the retriever directly; refactors that bypass the control plane and forget the load step.","solutions":["Await retriever.loadBundle(bundle) before the first retrieve() call","Or use GuidanceControlPlane and await plane.initialize(), which loads the bundle for you","Guard with retriever.getConstitution() !== null before dispatching retrieval requests","Order startup so bundle compilation/loading completes before request handling begins"],"exampleFix":"// before\nconst retriever = new PolicyRetriever(embedder);\nawait retriever.retrieve({ taskDescription: 'refactor db' }); // throws\n// after\nconst retriever = new PolicyRetriever(embedder);\nawait retriever.loadBundle(compiledBundle);\nawait retriever.indexShards();\nawait retriever.retrieve({ taskDescription: 'refactor db' });","handlingStrategy":"validation","validationCode":"if (retriever.getConstitution() === null) {\n  const bundle = await compileGuidance(rootContent, localContent); // or plane.getBundle()\n  await retriever.loadBundle(bundle);\n  await retriever.indexShards();\n}\nawait retriever.retrieve(request);","typeGuard":"function isRetrieverLoaded(retriever: PolicyRetriever): boolean {\n  return retriever.getConstitution() !== null;\n}","tryCatchPattern":null,"preventionTips":["Await loadBundle() (and indexShards()) before the first retrieve() in standalone usage","Prefer GuidanceControlPlane.initialize() which performs the load for you","Guard every retrieval entry point with getConstitution() !== null"],"tags":["guidance","retriever","lifecycle","initialization","policy-bundle"],"backgroundTag":"component-not-initialized","analyzedSha":"fa13ee4ad60ac2090b1480656eb233521790d640","analyzedAt":"2026-08-18T21:34:22.708Z","schemaVersion":2},"datasetVersion":"2026-08-22T04:17:13.399Z"}