Files
oh-my-pi/packages/coding-agent
ReqX 838e37417f fix(rpc): await background model discovery in get_available_models, set_model, and deferred --model resolution
Three read paths raced background model discovery on cold start:

1. `get_available_models` RPC (rpc-mode.ts) read the registry
   synchronously and returned a partial catalog containing only
   statically-bundled models.
2. `set_model` RPC (rpc-mode.ts) read the registry synchronously and
   rejected discovery-backed selectors with "Model not found".
3. `--model <provider>/<pattern>` CLI flag deferred retry (sdk.ts:2078)
   resolved synchronously after extension registration, before
   discovery-backed providers had populated `#models`.

Paths 1 and 2 are fixed by exposing the existing in-flight background
refresh promise (`#backgroundRefresh`, already tracked and cleared by
`refreshInBackground`) via a new public
`ModelRegistry.awaitBackgroundRefresh()` method, and awaiting it at each
RPC read site. No-op when no refresh is in flight (warm sessions
unaffected).

Path 3 mirrors the cold-cache race fix already applied to the
default-role fallback on this branch (issues #6114, #6162, sdk.ts:2343):
when a deferred pattern is unresolved and any discoverable provider is
registered, run a cache-aware `refresh("online-if-uncached")` pass
before the retry. Reuses the existing discovery machinery rather than
introducing a new ordering dependency.

The `omp models` CLI never had this bug because it awaits
`modelRegistry.refresh()` directly before listing.

Behavioral characteristics:
- **Warm-session fast path preserved**: when no refresh is in flight
  (`#backgroundRefresh === undefined`), `await undefined` resolves in a
  microtask. No regression for sessions that don't need discovery or
  have already settled.
- **Failure isolation preserved**: `refreshInBackground()` already
  swallows discovery errors via `.catch(...)`, so `awaitBackgroundRefresh()`
  resolves even when discovery fails — callers then read whatever models
  made it into `#models` (built-in + cached). No new failure modes.
- **Scoped**: doesn't change `refreshInBackground()` semantics. Adds a
  new read-only awaiter with minimal API surface. Reuses the
  well-established `refresh("online-if-uncached")` pattern for the
  deferred retry path.

Reproduction (get_available_models RPC, with any discovery-backed
provider configured in `~/.omp/agent/models.yaml`):

  cd ~
  {
    sleep 1
    printf '%s\n' '{"id":"m1","type":"get_available_models"}'
    sleep 5
  } | timeout 15 omp --mode rpc-ui --approval-mode yolo 2>/dev/null \
    | grep '"id":"m1"' | jq '.data.models | {count: length, providers: ([.[].provider]|unique)}'

Before: discovery-backed provider absent from the response on cold start.
After:  discovery-backed provider present.

Reproduction (--model CLI flag, same config):

  omp --mode rpc-ui --model <discovery-provider>/<model-id> --approval-mode yolo

Before: exits 1 with "Model \"<discovery-provider>/<model-id>\" not found".
After:  starts rpc-ui session with the requested model selected.
2026-07-23 08:46:31 +00:00
..
…

@oh-my-pi/pi-coding-agent

Core implementation package for the omp coding agent in the oh-my-pi monorepo.

For installation, setup, provider configuration, model roles, slash commands, and full CLI reference, see:

Package-specific references:

Memory backends

The agent supports three mutually-exclusive memory backends, selected via the memory.backend setting (Settings → Memory tab, or ~/.omp/config.yml):

  • off (default) — no memory subsystem runs.
  • local — existing rollout-summarisation pipeline; writes memory_summary.md and consolidated artifacts under the agent dir.
  • hindsight — talks to a Hindsight server (Cloud or self-hosted Docker), retains transcripts every Nth user turn, recalls memories on the first turn of a session, and exposes retain, recall, and reflect.

Hindsight quickstart

  1. Run a Hindsight server (Cloud or docker run -p 8888:8888 ghcr.io/vectorize-io/hindsight:latest).
  2. Set memory.backend = "hindsight" and hindsight.apiUrl = "http://localhost:8888" (or your Cloud URL).
  3. Optional environment overrides (env wins over settings):
    • HINDSIGHT_API_URL, HINDSIGHT_API_TOKEN — connection
    • HINDSIGHT_BANK_ID, HINDSIGHT_DYNAMIC_BANK_ID, HINDSIGHT_AGENT_NAME — bank addressing
    • HINDSIGHT_AUTO_RECALL, HINDSIGHT_AUTO_RETAIN, HINDSIGHT_RETAIN_MODE — lifecycle
    • HINDSIGHT_RECALL_BUDGET, HINDSIGHT_RECALL_MAX_TOKENS — recall sizing
    • HINDSIGHT_BANK_MISSION, HINDSIGHT_DEBUG

Switching backends mid-session is honoured on the next system-prompt rebuild and the next /memory slash command. Existing users with memories.enabled = true|false are migrated to memory.backend = "local"|"off" exactly once on first launch.