# omp-commandcode-provider — Session Hang Diagnosis ## Summary The `omp-commandcode-provider` extension hangs the OMP session at startup. Bisection isolated the hang to this plugin; the other 5 plugins load fine. ## Test method Each plugin was enabled/disabled via `omp-plugins.lock.json` and tested with: ``` timeout 30 omp --print "say hi" 2>&1; echo "EXIT: $?" ``` EXIT 124 = hang. The plugin was also progressively stripped to isolate causes. ## Findings ### 1. Deep subpath import hangs session (BLOCKING) **File:** `extensions/index.ts` line 8 **Original:** ```ts import type { ExtensionAPI } from "@oh-my-pi/pi-coding-agent/extensibility/extensions/types.js"; ``` **Effect:** Session hangs indefinitely. The module is never evaluated (no `console.error` output at module top level). The OMP extension loader's scoped Bun `onLoad` hook (`legacy-pi-compat.ts`) rewrites legacy pi-package specifiers before evaluation. The deep subpath `.js` extension maps to a `.ts` source file via the package `exports` map, and the `onLoad` rewriting cycle on this deep path causes the module import to hang. **Fix:** Import from the package root, per the OMP extension authoring docs (`extensions.md`): ```ts import type { ExtensionAPI } from "@oh-my-pi/pi-coding-agent"; ``` **Verification:** Package-root `import type` alone loads in ~5s. Deep subpath `import type` alone hangs. ### 2. `export *` re-exports hang session (BLOCKING) **File:** `extensions/index.ts` lines 13-17 **Original:** ```ts export * from "./discovery.js"; export * from "./usage.js"; export * from "./transport.js"; export * from "./auth.js"; export * from "./config.js"; ``` **Effect:** `export *` from `./transport.js` or `./discovery.js` causes the session to hang. Named `import { ... }` from the same modules works fine. `export *` from `./usage.js` does not hang. `transport.js` and `discovery.js` transitively import each other (`discovery.ts` imports `isZdrEnabled` from `./transport.js`). The `export *` pattern forces the `onLoad` hook to walk the full re-export map, which interacts with the scoped Bun rewriting to produce the hang. **Fix:** Remove all `export *` re-exports from the extension entry point. Named imports are the canonical pattern from `extensions.md`. Sibling modules remain independently importable for tests and external consumers. **Verification:** - `import { PROVIDER_ID } from "./discovery.js"` + `import { streamCommandCode } from "./stream.js"` → works - `export * from "./transport.js"` alone → hangs - `export * from "./usage.js"` alone → works ### 3. `fetchDynamicModels` + `models` mutual exclusivity violation (CONTRACT) **File:** `extensions/index.ts` lines 126-141 **Original:** Passes both `models: MODEL_CATALOG.map(...)` (56 entries) and `fetchDynamicModels: async (apiKey) => { ... }`. **Contract:** `ProviderConfig` type docs (`types.ts` line 1521): > fetchDynamicModels — "Mutually exclusive with `models`." **Effect:** Not the hang cause (removing `fetchDynamicModels` alone did not fix the hang), but it violates the `ProviderConfig` contract and may cause undefined behavior in model registry initialization. **Fix:** Remove `fetchDynamicModels` from `registerProvider` config when `models` is provided. The static `MODEL_CATALOG` is authoritative. ### 4. `models: []` (empty array) + `apiKey` causes model discovery hang (BLOCKING) **Effect:** Passing `models: []` (empty array) alongside `apiKey` causes the runtime to create a model manager with 0 models and attempt network model discovery at `baseUrl`, which hangs. **Verification:** - `registerProvider("commandcode", { baseUrl, apiKey, api: "openai-completions", models: [] })` → hangs - `registerProvider("commandcode", { baseUrl, apiKey, api: "openai-completions" })` (no `models`) → works - `registerProvider("commandcode", { baseUrl, apiKey, api: "openai-completions", models: [1 model] })` → works **Note:** The original extension passes non-empty `models` (56 entries), so this is not the direct cause, but it's a latent trap if the catalog is ever empty. ### 5. Custom API type + models + apiKey + streamSimple causes hang (BLOCKING — UNRESOLVED) **Effect:** The combination of `api: "commandcode-custom"` (a custom API id not in the built-in API registry) + non-empty `models` + `apiKey` + `streamSimple: streamCommandCode` causes the session to hang. **Verification (minimal repro):** ```ts pi.registerProvider(PROVIDER_ID, { baseUrl: BASE_URL, apiKey: "COMMANDCODE_API_KEY", api: "commandcode-custom" as never, streamSimple: streamCommandCode, models: [{ id: "zai-org/GLM-5.2", name: "GLM-5.2", provider: PROVIDER_ID, api: "commandcode-custom" as never, contextWindow: 131000, maxTokens: 16384, input: ["text"] as const, nativeTools: true, reasoning: false, cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 } }], }); ``` → hangs (30s timeout). **Working variants:** - `api: "openai-completions"` + 1 model + apiKey (no streamSimple) → works (5.98s) - `api: "openai-completions"` + no models + apiKey → works (11.66s) - `api: "commandcode-custom"` + no models + no apiKey → works (5.96s) **Isolation incomplete:** Did not test `api: "openai-completions"` + 1 model + apiKey + streamSimple, nor `api: "commandcode-custom"` + 1 model + apiKey without streamSimple. The hang could be caused by: - (a) the custom API type `"commandcode-custom"` requiring stream handler registration that hangs at init, or - (b) `streamSimple: streamCommandCode` itself, which imports `@oh-my-pi/pi-ai` and `@oh-my-pi/pi-ai/utils/event-stream` and may trigger a transitive module graph issue under the `onLoad` hook, or - (c) the `streamCommandCode` function's closure over `convertMessages` / `convertTools` which reference `@oh-my-pi/pi-ai` types. **Next step to resolve:** Test `api: "commandcode-custom"` + 1 model + apiKey without `streamSimple`. If it works, the hang is in `streamSimple` registration/evaluation. If it still hangs, the custom API type itself is the issue and the extension needs to use a built-in API id or register the custom API handler before `registerProvider`. ### 6. Broken symlink loop in omp-lean-ctx node_modules (FIXED) **File:** `~/.omp/omp-lean-ctx/node_modules/@oh-my-pi/omptype/package.json` **Effect:** Self-referential symlinks (`package.json -> package.json`, `CHANGELOG.md -> CHANGELOG.md`, `src/*.ts -> *.ts`) created an infinite loop. `cat package.json` → "Too many levels of symbolic links". This broke `@oh-my-pi/omptype/typebox` resolution for the lean-ctx extension. **Cause:** Botched `bun install` in the plugin source directory. **Fix applied:** `rm -rf node_modules && bun install` in `~/.omp/omp-lean-ctx/`. Reinstalled `@oh-my-pi/omptype@17.3.7` with real files. ### 7. Plugin install method was broken (FIXED) **Original state:** 6 plugin source directories at `~/.omp/omp-*` were registered in `omp-plugins.lock.json` as enabled but had no symlinks in `~/.omp/plugins/node_modules/`. The runtime's `getEnabledPlugins()` skips packages not resolvable from `node_modules/`. **Fix applied:** `omp plugin link ` for each of the 6 plugins, creating symlinks and lockfile entries. Also removed orphaned `omp-plugins` lockfile entry (root container package name leaking into plugins map). ## Fixes applied so far 1. **Plugin linking:** All 6 plugins linked via `omp plugin link`. 2. **omp-lean-ctx node_modules:** Reinstalled to fix symlink loops. 3. **omp-commandcode-provider import path:** Changed from deep subpath `@oh-my-pi/pi-coding-agent/extensibility/extensions/types.js` to package root `@oh-my-pi/pi-coding-agent`. 4. **omp-commandcode-provider `export *`:** Removed all 5 `export *` re-exports. 5. **omp-commandcode-provider `fetchDynamicModels`:** Removed from `registerProvider` config (mutually exclusive with `models`). ## Remaining issue Finding #5 (custom API + models + apiKey + streamSimple hang) is **unresolved**. The three fixes above (import path, export *, fetchDynamicModels) were not sufficient to eliminate the hang. The session still times out with all 6 plugins enabled. Further isolation is needed to determine whether the hang is caused by the custom API type, the `streamSimple` function, or their interaction with the model registry. ## Environment - omp: 17.2.15 - lean-ctx: 3.9.19 - Platform: Linux 7.1.6-1-cachyos x86_64 - Bun: (bundled with omp) - Plugin node_modules: `@oh-my-pi/omptype@17.3.7`, `@oh-my-pi/pi-coding-agent@17.3.7`