{"record":{"id":"05d0cac308f48f4a","repo":"can1357/oh-my-pi","slug":"model-registry-unavailable-in-current-session","errorCode":null,"errorMessage":"Model registry unavailable in current session.","messagePattern":"Model registry unavailable in current session\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/modes/components/agents-hub.ts","lineNumber":750,"sourceCode":"\t\tthis.#createSpec = null;\n\t\tthis.#createStreamingText = \"\";\n\t\tthis.#tui.requestRender();\n\t\ttry {\n\t\t\tconst spec = await this.#runAgentCreationArchitect(description);\n\t\t\tthis.#createSpec = spec;\n\t\t\tthis.#notice = null;\n\t\t} catch (error) {\n\t\t\tthis.#createError = error instanceof Error ? error.message : String(error);\n\t\t} finally {\n\t\t\tthis.#createGenerating = false;\n\t\t\tthis.#tui.requestRender();\n\t\t}\n\t}\n\n\tasync #runAgentCreationArchitect(description: string): Promise<GeneratedAgentSpec> {\n\t\tconst modelRegistry = this.#modelContext.modelRegistry;\n\t\tif (!modelRegistry) {\n\t\t\tthrow new Error(\"Model registry unavailable in current session.\");\n\t\t}\n\t\tawait modelRegistry.refresh();\n\t\tconst modelPatterns = resolveConfiguredModelPatterns(\n\t\t\tthis.#modelContext.activeModelPattern ??\n\t\t\t\tthis.#modelContext.defaultModelPattern ??\n\t\t\t\tthis.#settings.getModelRole(\"default\"),\n\t\t\tthis.#settings,\n\t\t);\n\t\tconst { model } = resolveModelOverride(modelPatterns, modelRegistry, this.#settings);\n\t\tconst selectedModel = model ?? modelRegistry.getAvailable()[0];\n\t\tif (!selectedModel) {\n\t\t\tthrow new Error(\"No available model to generate agent specification.\");\n\t\t}\n\t\tconst systemPrompt = prompt.render(agentCreationArchitectPrompt, {});\n\t\tconst userPrompt = prompt.render(agentCreationUserPrompt, { request: description });\n\t\tconst { session } = await createAgentSession({\n\t\t\tcwd: this.#cwd,\n\t\t\tauthStorage: modelRegistry.authStorage,","sourceCodeStart":732,"sourceCodeEnd":768,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/modes/components/agents-hub.ts#L732-L768","documentation":"#runAgentCreationArchitect needs the session's model registry to list and refresh available models before spawning the architect sub-session. If this.#modelContext.modelRegistry is unset (e.g. the hub is rendered in a context without model registry wiring), it throws this error instead of proceeding.","triggerScenarios":"Invoking the agent creation flow while this.#modelContext.modelRegistry is null/undefined — typically when the AgentsHubComponent was constructed without a model context or in a session type that does not supply one.","commonSituations":"Running the hub before the session fully initializes model context; embedding the component in tests or SDK usage without providing modelContext; session started in an offline/degraded mode where the registry was never attached.","solutions":["Start a normal interactive session so the model registry is populated before opening the agents hub","Ensure the component is constructed with a valid modelContext containing modelRegistry","Initialize/await model context setup before triggering agent creation","Retry after session initialization completes"],"exampleFix":"// before\nawait hub.runAgentCreationArchitect(desc) // modelContext.modelRegistry === null\n// after\nif (!hub.modelContext?.modelRegistry) await session.initializeModelContext()\nawait hub.runAgentCreationArchitect(desc)","handlingStrategy":"type-guard","validationCode":"if (!session.modelContext?.modelRegistry) {\n  await session.initialize(); // or surface a clear setup error\n}","typeGuard":"function hasModelRegistry(ctx: unknown): ctx is { modelRegistry: NonNullable<typeof ctx extends { modelRegistry: infer R } ? R : never> } {\n  return typeof ctx === \"object\" && ctx !== null && \"modelRegistry\" in ctx && (ctx as any).modelRegistry != null;\n}","tryCatchPattern":"try {\n  await hub.runAgentCreationArchitect(desc);\n} catch (err) {\n  if (err instanceof Error && err.message.includes(\"Model registry unavailable\")) {\n    // re-open hub after session model context is ready\n  } else throw err;\n}","preventionTips":["Only open the agents hub after the session is fully initialized","In SDK/test embeddings, construct the component with a complete modelContext","Await model context setup before exposing creation UI","Guard integrations with a registry-existence check"],"tags":["session-state","model-registry","agents"],"backgroundTag":"missing-session-dependency","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}