Skip to content

fix: find config without HOME and match variant models in the fallback chain - #42

Open
madsiberian wants to merge 1 commit into
azumag:mainfrom
madsiberian:fix/windows-homedir-variant-fallback
Open

madsiberian wants to merge 1 commit into
azumag:mainfrom
madsiberian:fix/windows-homedir-variant-fallback

Conversation

@madsiberian

Copy link
Copy Markdown

Problem

Two independent bugs kept the v2 fallback from working for Z.AI coding-plan users on Windows:

  1. Config never found on Windows. loadConfig used process.env.HOME || "". On Windows HOME is normally unset, so the home-based search paths resolved against the process cwd instead of the user profile. The plugin silently found no config, fallbackModels stayed empty, and setup registered nothing.

  2. Variant models never matched the chain. sameModel compared the reasoning-effort variant, so a session on glm-5.3#high (configured via reasoningEffort: "high") never matched a variant-less chain entry. The retry hook fired and detection passed (HTTP 429), but handles(model) returned false, so no fallback ever engaged.

Changes

  • src/utils/config.ts: fall back to os.homedir() when HOME is unset.
  • v2.ts: ignore the variant when matching (sameModel), and carry the failed model's variant onto same-model fallbacks (chainFor) so glm-5.3#high -> zai/glm-5.3#high preserves effort; different-model tiers (e.g. a flash model) keep their default effort.

Testing

  • Added a config test asserting loadConfig falls back to os.homedir() when HOME/XDG_CONFIG_HOME are unset.
  • Added two v2 tests: the variant is carried onto the same-model fallback, and not carried onto a different-model fallback.
  • vitest run: 734 passed (the 2 failures are pre-existing symlinkSync EPERM tests that need admin/Developer Mode on Windows — unrelated).
  • npm run typecheck and npm run build pass.
  • Version bumped 2.1.0 -> 2.1.1 per AGENTS.md.

Note

errorPatterns.custom is parsed by validateConfig but never wired into the v2 detection path (the v2 entrypoint matches against a fixed pattern list). That's a separate gap left untouched here; flagging it in case you want a follow-up.

…k chain

Two fixes that together make the v2 fallback work for Z.AI coding-plan
users on Windows.

- loadConfig used process.env.HOME || "", which on Windows (where HOME
  is usually unset) resolves the home-based config paths against the
  process cwd instead of the user profile, so the plugin silently finds
  no config and registers nothing. Fall back to os.homedir().

- sameModel compared the reasoning-effort variant, so a session on
  glm-5.3#high never matched a variant-less chain entry and the fallback
  never engaged. Ignore the variant when matching, and carry it onto
  same-model fallbacks (glm-5.3#high -> zai/glm-5.3#high) so effort is
  preserved across providers; different-model tiers (e.g. a flash model)
  keep their default effort.
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