Skip to content

Model picker: re-use existing key on re-onboard + inline preview in model show - #172

Merged
FMXExpress merged 2 commits into
mainfrom
claude/model-picker-cache-fallback
Jun 7, 2026
Merged

FMXExpress merged 2 commits into
mainfrom
claude/model-picker-cache-fallback

Conversation

@FMXExpress

Copy link
Copy Markdown
Owner

Summary

You reported that pasclaw onboard didn't show the model picker — only the old "Default model [gemini-3.5-flash]:" prompt — even though PR #171 was supposed to add live discovery. You confirmed: re-onboarding with an existing API key in config. That's the most common flow, and PR #171 silently broke it.

Two root causes, both fixed:

Cause 1 — Re-onboard with an existing key

The API key prompt says "leave blank to skip" so a re-onboarding user hits Enter to preserve their existing key. PR #171's PickModelInteractive saw an empty APIKey argument, treated the auth-required provider as unreachable, and silently fell through to the text-input prompt without ever attempting discovery.

Fix in Cmd.Onboard.RunOnboard: when the operator's key entry is blank, walk Cfg.Providers for an existing row matching Spec.Kind and reuse its APIKey as the effective key for discovery. UpsertProvider already treats Key='' as "preserve existing" so the saved config is untouched — this only affects the discovery path. Prompt copy also flipped from "leave blank to skip" to "leave blank to keep existing" so the existing-key path reads correctly.

Cause 2 — Silent skip when no key available

Even when the user had no existing key, PR #171's picker fell straight to the text prompt with zero explanation. You rightly read that as "the picker is broken."

Refactored PickModelInteractive into a four-step pipeline:

  1. Load any cached roster up-front.
  2. If a key is available (entered OR existing), attempt the live fetch; on success refresh the cache.
  3. Pick the data source: live > cache > nothing. SourceLabel explains where the list came from:
    • Fetched live from Anthropic.
    • Showing the cached roster (refreshed 3 days ago).
    • API key not entered — showing the cached roster (refreshed 3 days ago). Re-run with a key to refresh.
  4. Only when there's no live and no cache do we drop to the text-input prompt, and we print an explicit one-liner — API key not entered — using the catalog default. Run pasclaw model refresh later to populate the picker for next time. — so you know why the picker isn't there.

The cache is never overwritten by a failed live fetch.

pasclaw model show also got the inline preview

You also ran pasclaw model looking for a list and only saw the cache count. show now inlines a top-10 preview directly under the freshness line:

default provider: anthropic
default model:    claude-opus-4-7
models cached:    47 (refreshed 3 days ago)

  · claude-opus-4-8   (Claude Opus 4.8)
  · claude-opus-4-7   (Claude Opus 4.7)
  · claude-sonnet-4-6 (Claude Sonnet 4.6)
  ...
  (+ 37 more — run `pasclaw model list anthropic` for the full roster)

Test plan

  • FPC build clean on Linux.
  • Synthesised cache → pasclaw model show renders the inline preview correctly.
  • Full test suite green: smoke + hashline + toolview + anthropic-server-tools + openai-server-tools + println-helper + utf8-codepage-tag + gemini-schema-strip + markdown-render + json-utf8-roundtrip + model-discovery.
  • Live re-onboard with an existing Gemini / Anthropic / OpenAI key in config.json, hitting Enter at the API key prompt — should now show the live picker with the fresh roster.

Generated by Claude Code

…w in `model show`

First-user feedback: `pasclaw onboard` was supposed to show a numbered
picker of available models, but only the old "Default model
[gemini-3.5-flash]:" prompt appeared. Two root causes; both fixed.

Cause 1 — re-onboard with existing key.
  The most common onboard flow is the SECOND run, when the user
  already has an API key saved in config.json and just wants to
  tweak something else. The API key prompt says "leave blank to
  skip" so they hit Enter — and PickModelInteractive saw an empty
  key, treated the auth-required provider as unreachable, and
  silently fell through to the text-input prompt without ever
  attempting discovery.

  Fix in Cmd.Onboard.RunOnboard: when the operator's key entry is
  blank, look up the existing key from Cfg.Providers[<Spec.Kind>]
  and pass it to PickModelInteractive as the effective key.
  UpsertProvider already treats Key='' as "preserve existing key"
  so this only affects the discovery path — the saved config is
  unchanged. Prompt copy also flipped from "leave blank to skip"
  to "leave blank to keep existing" so the existing-key path
  reads correctly.

Cause 2 — silent skip when no key available.
  Even when no existing key was present, the picker fell through
  to the text prompt with zero explanation. User saw the bare
  "Default model [...]" line and rightly assumed the picker was
  broken.

  Refactored PickModelInteractive into a four-step pipeline:
    1. Load any cached roster up-front.
    2. If a key is available (entered OR existing), attempt the
       live fetch; on success refresh the cache.
    3. Pick the data source: live > cache > nothing. Live wins;
       cache used when live fails. SourceLabel explains where
       the list came from ("Fetched live", "Showing the cached
       roster (refreshed 3 days ago)", "API key not entered —
       showing the cached roster…").
    4. Only when there's NO live and NO cache do we drop to the
       text-input prompt, and we print an explicit one-liner
       ("API key not entered — using the catalog default. Run
       `pasclaw model refresh <provider>` later …") so the
       operator knows why the picker isn't there.

  Extracted ShowPicker as a helper so the live-vs-cache paths
  share rendering. The cache file is never overwritten by a
  failed live fetch.

Also: `pasclaw model show` enhancement.

  The user had also been running `pasclaw model` looking for a
  list and only saw the cache COUNT, not the contents. Show now
  inlines a top-10 preview directly under the cache-freshness line:

    default provider: anthropic
    default model:    claude-opus-4-7
    models cached:    47 (refreshed 3 days ago)

      · claude-opus-4-8   (Claude Opus 4.8)
      · claude-opus-4-7   (Claude Opus 4.7)
      ...
      (+ 37 more — run `pasclaw model list anthropic` for the full roster)

  Same code path the picker uses; same Provider-Name keying from
  PR #171 Codex P2.

Verified on Linux/FPC:
  - Synthesised cache → `pasclaw model show` renders the inline
    preview (5 models, ordered by created_at desc).
  - Full test suite green: smoke + hashline + toolview +
    anthropic-server-tools + openai-server-tools + println-helper +
    utf8-codepage-tag + gemini-schema-strip + markdown-render +
    json-utf8-roundtrip + model-discovery.
  - Live-key re-onboard path not exercised here (no real Gemini
    key in CI), but the logic is bounded: existing-key lookup is
    a Cfg.Providers walk + APIKey check; failure modes (key absent,
    key empty) cleanly degrade through cache → text-input.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e81e8306dd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/cmd/PasClaw.Cmd.Onboard.pas Outdated
Pick := StrToIntDef(Input, 0);
if (Pick >= 1) and (Pick <= N) then
Exit(R.Models[Pick - 1].Id);
if (Pick >= 1) and (Pick <= Length(Models)) then

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Limit numeric picks to displayed models

When a provider/cache has more than 12 models, ShowPicker only prints entries 1–12, but this condition accepts any number up to the full roster length. In that scenario, typing 13 or higher silently saves an undisplayed model, unlike the previous <= N check that limited picks to visible choices; either keep the visible count for validation or display all selectable numbers.

Useful? React with 👍 / 👎.

ShowPicker only printed the top 12 of the roster (VISIBLE_TOP_N), but
the caller validated typed numbers against Length(Models). With 47
cached models the picker displayed rows 1..12 and the operator could
still type "47" and silently land on a model they never saw — exactly
the case Codex flagged.

Fix: turn ShowPicker into a function returning the visible row count,
and validate `Pick <= VisibleN` in the caller. Numbers outside the
visible range fall through to the free-form-id branch (operator may
know about a model the cache doesn't show), matching how non-numeric
input is already handled.

The Codex comment listed two acceptable fixes — "keep the visible
count for validation" OR "display all selectable numbers". Picked
the former since 47-row interactive lists are worse UX than a 12-row
window plus the `pasclaw model list <provider>` escape hatch (already
mentioned in the picker's "(+ N more — see ...)" footer).

Full test suite green: smoke + hashline + toolview +
anthropic-server-tools + openai-server-tools + println-helper +
utf8-codepage-tag + gemini-schema-strip + markdown-render +
json-utf8-roundtrip + model-discovery.
@FMXExpress
FMXExpress merged commit 0f0286b into main Jun 7, 2026
FMXExpress pushed a commit that referenced this pull request Jun 7, 2026
Down-key bound was capped at FModelMenuVisibleN - 1 (the visible
window count), so on a roster with more than ~20 cached models —
or fewer on a short terminal — the user couldn't reach anything
past the first page even though DrawModelMenu was already
windowing the printed rows around FModelMenuSelIdx.

Pattern was lifted from the PR #172 onboard-picker fix, but that
picker is line-based and never scrolls — the validation cap there
matches what was printed once. The TUI overlay re-paints every
frame and scrolls, so the bound must be the full roster length.

Drop FModelMenuVisibleN (no remaining users) and bound KEY_DOWN
on Length(FModelMenuModels) - 1.
khongten001 pushed a commit to khongten001/PasClaw that referenced this pull request Jul 13, 2026
Type `/model` inside `pasclaw tui` to pick from the cached /v1/models
roster for the active session's provider (falls back to
Cfg.DefaultProvider). Delphi build paints a modal overlay with
Up/Dn navigation, Enter to apply, Esc to cancel — same shape as the
existing /theme picker. FPC build exposes /model as a line-based
command: bare prints the cached list and current selection, `/model
<id>` switches the active model for the running TUI.

Cache lookup reads $PASCLAW_HOME/cache/models/<provider>.json
populated by `pasclaw model refresh` / `pasclaw onboard` — no live
HTTP from the UI thread. Modal subtitle shows cache freshness so
the operator knows whether to drop out and refresh. Picking a
model updates FSession.Meta.Model (persisted on next turn) but
does not touch config.json — use `pasclaw model set` for that.

Validation cap (FModelMenuVisibleN) follows the PR FMXExpress#172 Codex P2
pattern: arrow-key bounds and Enter validation check rows actually
printed, not full roster length.
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.

2 participants