Skip to content

feat(rlm): env-default model with 429 fallback list - #244

Merged
AdarGit008 merged 3 commits into
mainfrom
feat/rlm-default-free-fallback
Oct 17, 2026
Merged

AdarGit008 merged 3 commits into
mainfrom
feat/rlm-default-free-fallback

Conversation

@AdarGit008

Copy link
Copy Markdown
Owner

What

Adds a third model-routing tier to createLlmClient so an RLM loop can default to a free/cheap model (instead of the session's paid main model) and fail over to a fallback list when a provider rate-limits (HTTP 429).

New env vars

Var Meaning
REPL_RLM_DEFAULT_MODEL model id/name resolved through the host registry
REPL_RLM_DEFAULT_PROVIDER optional provider for that model
REPL_RLM_FALLBACK_MODELS comma list of provider/model-id (or bare model-id), tried in order on a 429

Resolution order

injected model/provider → REPL_RLM_BASE_URL endpoint → env-default (+ fallbacks) → session main model.

  • A non-429 error still rethrows immediately (not a quota problem another model can fix).
  • An exhausted fallback list rethrows the last 429.
  • Backwards-compatible: without the new vars, behavior is unchanged.

Tests

8 new cases in test/rlm_client.test.ts (default routing, not-found, 429 fallback, non-429 no-fallback, exhausted-list rethrow, injected-wins, endpoint-wins, bare-id fallback). Full file: 24/24 pass; tsc --noEmit, npm run build, and npm run lint all green.

Add a third model-routing tier to createLlmClient so an RLM loop can default
to a free/cheap model (instead of the session's paid main model) and fail over
to a list of fallbacks when a provider rate-limits (HTTP 429).

New env vars:
- REPL_RLM_DEFAULT_MODEL     — model id/name resolved through the host registry
- REPL_RLM_DEFAULT_PROVIDER  — optional provider for that model
- REPL_RLM_FALLBACK_MODELS   — comma list of `provider/model-id` (or bare
  `model-id`), tried in order when the previous model returns a 429

Resolution order is now: injected model/provider → REPL_RLM_BASE_URL endpoint →
env-default (+ fallbacks) → session main model. A non-429 error still rethrows
immediately; an exhausted fallback list rethrows the last 429.
Add a one-shot `/rlm-setup` command so a fresh install can configure the rlm
model routing without hand-editing a shell profile.

- Defaults to the session model (ctx.model id + provider), no fallback.
- Asks to opt in to a custom model/provider and to a 429 fallback chain
  (X fallback models -> the chain is the default + X).
- Writes an idempotent managed block to the detected shell profile
  (~/.zshrc / ~/.bashrc / ~/.config/fish/config.fish / ~/.profile), using
  `export` (or fish `set -gx`), and applies the same values to the current
  process so rlm picks them up immediately.

Pure helpers live in src/rlm_setup.ts (profile detection, block render,
idempotent rewrite, env apply) with unit tests in test/rlm_setup.test.ts.
Extends the registered-command pin (#198) to cover /rlm-setup.
@AdarGit008
AdarGit008 force-pushed the feat/rlm-default-free-fallback branch from a77f1fe to 04e72c6 Compare October 17, 2026 03:13
CI "coverage floors" was red: the new /rlm-setup handler pushed
extensions/repl-extension.ts below its floor, and src/rlm_setup.ts had no floor.

- Add 7 extension tests driving the /rlm-setup dialogs: session-model default,
  custom model/provider, fallback chain, cancel, no-session, and idempotent
  profile rewrite.
- Remove the unreachable "no model resolved" guard the tests could not reach.
- Baseline: add src/rlm_setup.ts floor (94.5) and raise src/rlm_client.ts to
  its now-covered 93.27.
@AdarGit008
AdarGit008 merged commit bc8bc8e into main Oct 17, 2026
12 checks passed
@AdarGit008
AdarGit008 deleted the feat/rlm-default-free-fallback branch October 17, 2026 05:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant