{"record":{"id":"18a3213bd34c397b","repo":"can1357/oh-my-pi","slug":"security-scan-preflight-requires-an-active-model","errorCode":null,"errorMessage":"Security scan preflight requires an active model","messagePattern":"Security scan preflight requires an active model","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/security/coordinator.ts","lineNumber":428,"sourceCode":"\t\t\t\toperationId,\n\t\t\t\tplanId: bundle.scan.plan?.id ?? \"\",\n\t\t\t\tscanId: bundle.scan.id,\n\t\t\t\tphase: operationPhaseFromStatus(bundle.scan.status),\n\t\t\t\tcreatedAt: bundle.scan.createdAt,\n\t\t\t\tupdatedAt: bundle.scan.completedAt ?? bundle.scan.startedAt ?? bundle.scan.createdAt,\n\t\t\t\tfindingCount: bundle.findings.length,\n\t\t\t};\n\t\t\tif (bundle.scan.error !== undefined) snapshot.error = bundle.scan.error;\n\t\t\tthis.#operations.set(operationId, { snapshot, promise: Promise.resolve() });\n\t\t}\n\t}\n\n\tasync preflight(input: SecurityPreflightInput = {}): Promise<SecurityScanPlan> {\n\t\tif (!this.#host.settings.get(\"security.enabled\")) {\n\t\t\tthrow new Error(\"Security is disabled; enable security.enabled before planning a scan\");\n\t\t}\n\t\tconst model = input.model ?? this.#host.activeModel;\n\t\tif (!model) throw new Error(\"Security scan preflight requires an active model\");\n\t\tconst account = selectSecurityAccount(\n\t\t\tthis.#host.authStorage,\n\t\t\tmodel.provider,\n\t\t\tinput.credentialId,\n\t\t\tthis.#host.sessionId,\n\t\t);\n\t\tconst store = await this.#openStore(this.#host.cwd);\n\t\tconst workRoot = path.join(store.projectDirectory, \"work\");\n\t\tawait fs.mkdir(workRoot, { recursive: true, mode: 0o700 });\n\t\tif (process.platform !== \"win32\") await fs.chmod(workRoot, 0o700);\n\t\tconst modelRef: SecurityModelRef = { provider: model.provider, modelId: model.id };\n\t\tif (input.thinkingLevel !== undefined) modelRef.thinkingLevel = input.thinkingLevel;\n\t\tconst plan = await createSecurityScanPlan(\n\t\t\t{\n\t\t\t\tcwd: this.#host.cwd,\n\t\t\t\ttarget: input.target ?? { kind: \"repository\" },\n\t\t\t\tknowledgeBasePaths: input.knowledgeBasePaths,\n\t\t\t\toutputRoot: input.outputRoot ?? path.join(workRoot, Bun.randomUUIDv7()),","sourceCodeStart":410,"sourceCodeEnd":446,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/security/coordinator.ts#L410-L446","documentation":"preflight() needs an LLM model to plan and drive the security scan: it uses input.model if given, otherwise the host's currently active model. When neither exists it throws, because scan planning cannot proceed without selecting a model and account.","triggerScenarios":"Calling preflight() with no input.model while no model is active in the host session — e.g. running a security scan before any model is selected, or in a headless/SDK context where activeModel is never set.","commonSituations":"Scripted/SDK use of SecurityCoordinator outside an interactive TUI session; a session whose model failed to load (missing auth/provider config); invoking the security command in a fresh session before choosing a model.","solutions":["Pass an explicit model in the preflight input: preflight({ model }).","Set/activate a model in the session before planning (log in / configure the provider so activeModel is populated).","Verify provider credentials exist for the intended provider so the default model can be resolved.","Catch the error in automation and prompt the user to select a model before proceeding."],"exampleFix":"// before\nawait coordinator.preflight({});\n// after\nawait coordinator.preflight({ model: await host.resolveDefaultModel() });","handlingStrategy":"validation","validationCode":"const model = input.model ?? host.activeModel;\nif (!model) throw new Error(\"select or pass a model before planning a security scan\");","typeGuard":"function hasModel(input: SecurityPreflightInput, activeModel: unknown): boolean {\n  return Boolean(input.model ?? activeModel);\n}","tryCatchPattern":"try {\n  await coordinator.preflight(input);\n} catch (err) {\n  if (err instanceof Error && err.message.includes(\"requires an active model\")) {\n    // prompt for model selection or configure provider auth, then retry\n  } else throw err;\n}","preventionTips":["In SDK/headless use, always pass an explicit model in preflight input.","Verify provider authentication is configured before scan automation runs.","Gate scan workflows on a model being resolvable (e.g. host.activeModel) before starting."],"tags":["configuration","model-selection","security-scan"],"backgroundTag":"no-active-model","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}