Skip to content

Expose live-probing model fallback resolution over RPC #252

Description

@m-aebrer

Summary

Expose dreb's existing model fallback resolution with live availability probing over the RPC interface, so RPC clients can resolve "the first actually-available model from an ordered list" — the same way subagent fallback lists already work internally.

Motivation

dreb already has battle-tested logic for this in src/core/tools/subagent.ts:

  • resolveModelForSubagentSpawn() — walks an ordered fallback list, returns the first model that resolves and passes a live probe.
  • probeModelAvailability() — sends a minimal "hi""OK" completion via completeSimple and treats runtime-unavailable errors (isRuntimeUnavailableError, e.g. LanguageModelNotAvailable / ProxyModelNotFound) as a skip-to-next signal, with a timeout.

This is currently only reachable from inside the agent process for subagent spawns. RPC clients have no way to get it.

The existing RPC resolve_model command (src/modes/rpc/rpc-mode.ts) only resolves a single pattern against the configured registry — it does not perform a live availability check. On proxies with no /models list endpoint, the registry keeps listing a model after it has actually been decommissioned, so resolve_model returns a model that then fails at spawn time.

Concrete use case

An RPC consumer app needs a model dropdown with an automatic fallback chain (e.g. opus → sonnet → gpt-5.5) because access to a preferred model may be removed at any time. The app needs to detect live availability and settle on the first working model before spawning the agent. Today it has no choice but to hand-roll a proxy-specific HTTP probe (duplicating the endpoint/quirk/error-code handling dreb already owns). Once this primitive exists, that hand-rolled probe can be replaced with a single RPC call.

Proposed Behavior

Add an RPC command that resolves an ordered fallback list against live availability and returns the first model that passes the probe. Two shape options (pick whichever fits the RPC conventions best):

  • Extend resolve_model to accept an ordered list of patterns plus an opt-in probe: true flag, or
  • Add a dedicated command (e.g. resolve_model_fallback) taking patterns: string[] and returning { model, skippedModels?, warning? }.

Wire it in src/modes/rpc/rpc-mode.ts to reuse resolveModelForSubagentSpawn / probeModelAvailability against the session's modelRegistry (so API keys never leave the process). Add a corresponding RpcClient method in src/modes/rpc/rpc-client.ts mirroring the existing resolveModel().

Acceptance Criteria

  • RPC command resolves an ordered list and returns the first model that resolves and passes a live probe.
  • Probing reuses the existing probeModelAvailability path (no duplicated probe logic).
  • Skipped/unavailable models are reported back (mirroring SkippedFallbackModel) so clients can surface "X unavailable, using Y".
  • Single-pattern / non-probing behavior of the existing resolve_model is unchanged (backward compatible).
  • RpcClient exposes a typed method for the new capability.
  • Probe runs server-side with the session's registry/credentials; API keys never cross the RPC boundary.
  • Tests cover: first-available selection, all-unavailable error, skipped-model reporting, timeout/abort handling.

Technical Notes

  • Core logic: src/core/tools/subagent.tsresolveModelForSubagentSpawn, probeModelAvailability, SkippedFallbackModel, isRuntimeUnavailableError.
  • RPC wiring: src/modes/rpc/rpc-mode.ts (resolve_model / get_available_models cases), src/modes/rpc/rpc-types.ts, src/modes/rpc/rpc-client.ts (resolveModel).
  • Respect abort signals and a sane probe timeout (the subagent path already does).

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions