Skip to content

fix(providers): keep a Fireworks/AMD key across TUI instances and restarts - #4485

Merged
kovtcharov-amd merged 1 commit into
amd:mainfrom
kovtcharov:kalin/fireworks-key-persist
Sep 29, 2026
Merged

kovtcharov-amd merged 1 commit into
amd:mainfrom
kovtcharov:kalin/fireworks-key-persist

Conversation

@kovtcharov

Copy link
Copy Markdown
Contributor

A Fireworks key pasted into the TUI's /provider panel worked only until that Lemonade stopped. Every later TUI, and every embedded-Lemonade restart, came back with no key, so users re-pasted it. Now a key that connects is kept in the OS credential store and handed back to any Lemonade that lacks it: when a chat starts on a cloud model, or when /provider opens. The same applies to an AMD gateway key set from /provider. Pairs with #4469, which keeps the provider registration across embedded restarts; this keeps the key.

  • Never overwrites a live key. A key Lemonade already has, from LEMONADE_FIREWORKS_API_KEY or a paste, wins. A key that discovers no models is not kept, so a typo isn't replayed forever.
  • Ctrl+D forgets the kept copy too. Where no credential store exists (headless Linux), the panel says "this session only" and names LEMONADE_<PROVIDER>_API_KEY.

Test plan

  • python -m pytest tests/unit/test_cloud_keys.py tests/unit/test_daemon_gateway_routes.py tests/unit/test_gateway.py
  • cd tui && go test ./internal/ui/providers/ ./internal/ui/gateway/ ./internal/daemon/
  • Paste a Fireworks key in /provider and pick a model; quit; gaia lemonade embedded stop && gaia lemonade embedded start (with fix(lemonade): keep cloud providers across embedded restarts #4469); relaunch gaia tui and chat on fireworks.* without re-entering the key
  • Ctrl+D in /provider → relaunch → the key is asked for again
🔍 Technical details
  • gaia.llm.cloud_keys keeps, recalls, forgets and replays per provider. Fireworks uses slot fireworks_api_key, the one resolve_fireworks_api_key already reads. AMD reuses gateway:amd and GatewayManager.ensure_authenticated. Writes are read back, so a null keyring backend fails loudly instead of "saving" nothing.
  • New daemon routes: /daemon/v1/providers/{fireworks|amd}/{key,authenticate}, guarded by the daemon client token. The key is never logged or echoed back, and an unusable store returns 503 with the remedy.
  • readiness._replay_gateway_token becomes _replay_cloud_key, covering every provider in cloud_keys.PROVIDERS.
  • The gateway panel's private daemonCall moves to daemon.Call, so both panels share one implementation.
  • Live check against a separate lemond on its own port and config, with a fake key in the real Windows credential store:
fresh lemond:          runtime_key_set False
kept in OS store:      True
after replay:          runtime_key_set True   (usable False — fake key discovers nothing)
after lemond restart:  runtime_key_set False
after second replay:   runtime_key_set True
forgot kept key:       True | still stored: False

The last unchecked item needs a real Fireworks key, which I didn't handle.

…onade restarts

A key pasted into the TUI's /provider panel lived only in Lemonade's memory, so
the next TUI, or the next embedded-Lemonade start, had no Fireworks key and the
user had to paste it again.

- A key that connects and discovers models is kept in the OS credential store
  via the daemon (go-keyring cannot read what python-keyring writes). The
  Fireworks slot is the one GAIA's own Fireworks client already reads.
- It is replayed into any Lemonade that has the provider but no key: by the
  agent readiness check when a cloud model is missing (every front-end), and
  when the /provider panel opens. A key Lemonade already has, from its
  environment or a paste, is never overwritten.
- Ctrl+D forgets the kept copy too, and a store that cannot keep the key says
  "this session only" with the LEMONADE_<PROVIDER>_API_KEY remedy.
- The gateway panel's daemon helper moves to daemon.Call so both panels share it.
@github-actions github-actions Bot added documentation Documentation changes llm LLM backend changes tests Test changes performance Performance-critical changes agents tui Go terminal UI (gaia-tui) daemon Daemon supervisor / sidecar control plane labels Sep 29, 2026
@kovtcharov

Copy link
Copy Markdown
Contributor Author

One related gap this PR is well placed to close. With LEMONADE_FIREWORKS_API_KEY set in the Lemonade process, a fresh-install TUI's Fireworks panel still shows only › API key — Paste API key. Pressing Enter on the empty field does connect (25 models discovered), but nothing tells the user that. docs/guides/ai-providers.mdx promises "If a credential is already active for a provider, the setup screen says so before you type anything". With this PR also keeping pasted keys, the panel should show which one is active: "Using the key from LEMONADE_FIREWORKS_API_KEY" or "Using your saved key". Seen on a combined build of #4457/#4459/#4461 on 2026-09-29.

@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Sep 29, 2026
Merged via the queue into amd:main with commit f295bdc Sep 29, 2026
64 of 67 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the kalin/fireworks-key-persist branch September 29, 2026 18:08
kovtcharov added a commit to kovtcharov/gaia that referenced this pull request Sep 29, 2026
…amd#4497)

Before: a model picked in the TUI (Fireworks → DeepSeek V4.1 Flash, say)
was forgotten on quit. The next launch ran local Gemma with no notice,
and the header didn't name the model. After: the last provider + model
the agent confirmed is saved in `~/.gaia/config.json` and restored on
launch, and the header names the model from the moment the chat opens,
local included. If a restore doesn't take (key gone, model not listed,
agent down, or you stop it), GAIA says so in one line and opens the
provider picker. It never quietly runs another model. This is the third
piece after amd#4469 (provider registration kept) and amd#4485 (key kept): the
*selection*.

Closes amd#4490

## Test plan
- [ ] `cd tui && go vet ./... && go test ./...`
- [ ] `python -m pytest hub/agents/gaia/python/tests/test_stdio.py
tests/unit/test_cli_config.py`
- [ ] Fresh `GAIA_HOME` + `GAIA_CONFIG_DIR`: launch `gaia-tui`. The
header names the local model before any message. `/provider` → Fireworks
→ `deepseek-v4p1-flash`, chat once, quit, relaunch. Expect "Restored
your last model." `/model` should say `Currently running:
fireworks.deepseek-v4p1-flash`, and the gate should skip the local chat
load.
- [ ] Set `last_model` to a bogus `fireworks.*` id or an undownloaded
local id and relaunch. Expect one `Couldn't restore your last model, …`
line, the picker opens, and the saved value is untouched.

<details>
<summary>🔍 Technical details</summary>

- **Storage:** `last_provider` / `last_model` are declared on
`GaiaConfig`, because `save()` writes declared fields only and a Python
`gaia config set` would otherwise drop them. Go writes them with the
same read-modify-write as `full_access` (the shared helper is
`writeConfigKeys`). A value is saved only when the agent's `/model` ping
matches the requested id and the turn ends in a `final`.
- **Restore:** one `/model <id>` turn sent as the chat opens, before
amd#4488's warm-up. The warm-up then runs on the restored model, and is
skipped if the restore fails. Anything typed before it, and a `--query`,
waits behind it. Every non-confirmed ending sets `startup.unresolved`,
which `ChatModel.Update` turns into the line + picker: an agent refusal,
a crash before the model ping, a transport error, a cancel, or a
double-Esc abort.
- **Which choices become the launch model:** a saved cloud model does,
so the gate skips the local chat load. Local and Claude choices are
switched to after launch, so a deleted model or missing
`ANTHROPIC_API_KEY` reaches the one-line path instead of halting at the
gate. Explicit `--model` / `--use-claude` win for that launch.
- **Scope:** the remembered choice lives in a shared box in `root` and
is only ever applied to the flagship. `/agents` switches to other agents
never receive it, and switching back restores the latest confirmed
choice. A gate pick is cleared from `m.model` once the flagship has
launched on it.
- **Header before the first ping:** shows the chat model the readiness
gate loaded (new `Report.ChatModel`), display-only, so the agent's first
ping replaces it without tripping the revert warning.
- **Agent:** `/model` on a cloud id Lemonade doesn't list now asks
`readiness.probe_model_present`, which replays the key amd#4485 keeps
(Fireworks or AMD), then re-lists. So a restore survives a Lemonade
restart.
- **Live drive** (Windows Terminal, control API, isolated
`GAIA_HOME`/config/memory/daemon, `PYTHONPATH` pinned to this checkout,
existing embedded Lemonade that already held a Fireworks key):

```
fresh launch:   GAIA │ agent gaia │ Gemma-4-E4B-it-GGUF        (no config.json yet)
after pick:     {"last_model": "fireworks.deepseek-v4p1-flash", "last_provider": "fireworks"}
relaunch gate:  Starting GAIA — chat runs on fireworks.deepseek-v4p1-flash (in the cloud)…
relaunch:       GAIA │ agent gaia │ Fireworks AI · deepseek-v4p1-flash (remote)
                Restored your last model.
/model:         Currently running: fireworks.deepseek-v4p1-flash.
bogus cloud id: Couldn't restore your last model, Fireworks AI · not-a-real-model: Fireworks AI does not list it — the key may be missing or the provider is not connected. Pick a model to continue, now or later with /provider.
missing local:  Couldn't restore your last model, Qwen3-0.6B-GGUF: it is not downloaded. Pick a model to continue, now or later with /provider.
```

- **Pre-existing failures, not from this PR:** three `hub/agents/gaia`
browser-tool registry tests fail without `playwright` installed, and
pylint flags `os.getuid` / `signal.SIGKILL` on Windows. Both reproduce
on `main`.
- **Agent eval:** not run. No prompt, tool schema or error
classification changed; the agent change only adds a re-list in the
`/model` handler.
</details>
grtninja pushed a commit to grtninja/gaia that referenced this pull request Oct 2, 2026
…ere (amd#4505)

Three things on the AI provider screen told users something untrue. On a
new machine, pressing **p** before setup installed Lemonade showed
"Lemonade did not respond… Start it", a fault for a step they hadn't
reached. A Fireworks key Lemonade already held
(`LEMONADE_FIREWORKS_API_KEY`) still showed "Paste API key", though
Enter connected. And the setup text said keys are lost when Lemonade
restarts, which stopped being true with amd#4485. Now the picker names the
setup step that installs Lemonade and waits for it, the key field says
"A key is already set — Enter connects", and the text says the key is
kept in the OS credential store.

Past setup, an unreachable Lemonade still reports the fault as before.

Closes amd#4503

<details>
<summary>🔍 Technical details</summary>

- Lemonade lists a provider in `/system-info`, and so reports
`env_var_set`, only after `POST /install` registers it. That's why the
env key was invisible. Opening Fireworks setup now registers it with the
same fixed settings Connect sends (no key), re-runs the kept-key
restore, then re-reads providers. I confirmed this against a real
`lemond` 2026.39.1: `providers: []` before, `env_var_set: true` after.
- `lemonade.ErrUnreachable` is now a sentinel. Root passes
`Report.LemonadeStep()` into the panel via `WithSetupStep`, so the
wording follows the real step number.
- A failed provider read no longer wipes the known key states. This came
out of review.
- `tui/README.md` and `docs/guides/ai-providers.mdx` are updated to
match.
</details>

## Test plan
- [x] `cd tui && go build ./... && go vet ./... && go test ./...` — all
pass; `gofmt -l` clean after CRLF strip
- [x] New frame tests in
`tui/internal/ui/providers/setup_state_test.go`: step message before
setup, fault after setup, "A key is already set" against a fake Lemonade
that lists Fireworks only once registered, credential-store wording at
both panel heights
- [x] Fresh `GAIA_HOME` first run, driven over the control API, **p** on
the setup gate: before shows "Lemonade did not respond"; after shows
"Lemonade isn't installed yet — setup step 1 installs it" and Enter does
nothing
- [x] Real `lemond` started with `LEMONADE_FIREWORKS_API_KEY`,
`/provider` → Fireworks: before shows "Paste API key" plus "Keys stay in
Lemonade memory until it restarts"; after shows "A key is already set —
Enter connects" plus the credential-store line
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents daemon Daemon supervisor / sidecar control plane documentation Documentation changes llm LLM backend changes performance Performance-critical changes tests Test changes tui Go terminal UI (gaia-tui)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants