Skip to content

AI prompt pipeline: key save, live model, honest outcomes (6/7) - #47

Merged
bring42 merged 3 commits into
mainfrom
claude/pr6-ai-pipeline
Sep 12, 2026
Merged

bring42 merged 3 commits into
mainfrom
claude/pr6-ai-pipeline

Conversation

@bring42

@bring42 bring42 commented Sep 12, 2026 •

Copy link
Copy Markdown
Owner

Stacked PR — part 6 of 7. Merge in order (1 → 7) using a merge commit, not squash: the per-commit messages are the documentation, and squashing would also break the PRs stacked on top. Split from claude/next-goal-notes-merge-prep-6bb680; the top of the stack is byte-identical to that branch.

What

The AI prompt feature was dead three independent ways; this fixes all three.

  1. The API key could not be saved: the settings field had no save handler. Now fixed.
  2. The default model was retired and returned 404. It is now claude-haiku-4-5, with a load-time migration for retired IDs already stored on a device. The default is also a single AI_MODEL_DEFAULT constant: it used to live in two places that drifted apart, and fresh boards booted the retired model.
  3. Every failure was reported as success. New GET /api/prompt/status reports the worker's real outcome, and the UI shows the device's actual error text instead of "Applied".

Review follow-up: empty or retired model IDs are normalized on every path a model enters the config: NVS load, POST /api/config, and the dev-secrets override. The override could previously re-introduce a retired ID from an old secrets.h, and an empty value could be stored with no fallback.

Review notes

  • Model IDs were checked against the Claude API reference: claude-haiku-4-5 is active, and claude-3-5-haiku-20241022 / claude-3-5-sonnet-20241022 are retired.
  • The firmware reads content[0].text. That is fine for Haiku 4.5 (no thinking by default), but a model with thinking on by default would need the parser to find the first text block.

Verification

Built and tested on this branch alone. This stacked state is new, so it was verified independently rather than assumed: 81/81 native tests pass, the firmware builds for seeed_xiao_esp32c3 (65.3% of the app partition, the new 1.75 MB slot), and the web UI JS passes node --check.

On hardware: a fresh board now reports claude-haiku-4-5, and the status endpoint responds. Not tested end-to-end against the API (no key).

🤖 Generated with Claude Code


The stack (merge top to bottom):

  1. Premium render substrate + 13 premium modes (1/7) #42 — Premium render substrate + 13 premium modes (1/7)
  2. Web UI: data/ as the single source of truth (2/7) #43 — Web UI: data/ as the single source of truth (2/7)
  3. Live viz: the channel visualizer mirrors the real strip (3/7) #44 — Live viz: the channel visualizer mirrors the real strip (3/7)
  4. WiFi observability: stop failing silently (4/7) #45 — WiFi observability: stop failing silently (4/7)
  5. 4 MB partition table: 1.75 MB A/B app slots (5/7) #46 — 4 MB partition table: 1.75 MB A/B app slots (5/7)
  6. AI prompt pipeline: key save, live model, honest outcomes (6/7) #47 — AI prompt pipeline: key save, live model, honest outcomes (6/7)
  7. Core hardening from the external review (7/7) #48 — Core hardening from the external review (7/7)

benno6 and others added 3 commits September 12, 2026 18:08
… outcomes

The feature was dead three independent ways (forensic audit on-branch):
the settings key field had NO save handler (typed keys went nowhere); the
default model claude-3-5-haiku-20241022 was retired 2026-02 and 404s (the
second death-by-model-retirement — the previous default was also retired);
and every failure reported as success — the 202-accept pattern meant the UI
printed "Applied to the console" while "no key"/"bad key"/"404 model"
died in the serial log.

- UI: #aiKey saves on change via /api/config (masked "****" echo and empty
  values are never sent back); placeholder now sk-ant-…; Enter commits.
- Model: default -> claude-haiku-4-5, plus an NVS migration in loadConfig —
  any config save pins the then-default model, so existing devices carry the
  retired id and a new default alone can never heal them. secrets.h.example
  updated too.
- Honest outcomes: the worker records each job's result; new
  GET /api/prompt/status {busy, jobs, lastOk, lastError} (seq-guarded torn-
  read-safe cross-task copy); engine.sendPrompt polls it after the 202 and
  resolves with the REAL outcome; the UI shows the device's own error text
  verbatim instead of unconditional success. dev_server.js mocks the
  endpoint so the mock stays faithful.

Verified: browser run against the mock (chip click holds "Interpreting…"
until the worker finishes, key save toasts); flashed to the C3 — status
endpoint live, NVS model migrated to claude-haiku-4-5 on first boot;
native tests pass.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
… a retired one

Found on hardware: a freshly flashed C3 reported aiModel
"claude-3-5-haiku-20241022" (retired 2026-02-19, 404s at the API) even
though the prompt-pipeline commit had moved the default to claude-haiku-4-5.

Root cause: the default lived in two separate literals. The prompt-pipeline commit updated
the loadConfig() getString fallback and added a retired-id migration
there, but on a factory-fresh board the NVS namespace doesn't exist, so
loadConfig() returns at prefs.begin() before either runs — and the Config
struct initializer in storage.h still held the retired id. The first
config save (provisioning WiFi) then persisted it to NVS. The prompt-pipeline commit's
"migration confirmed on hardware" was checked on a board that already had
NVS, so the fresh-board path was never exercised.

- AI_MODEL_DEFAULT in constants.h is now the single source: the struct
  initializer, the loadConfig() fallback, and the migration target all use
  it, so they cannot drift apart again (the same pattern storage.h already
  uses to seed the gamma default from LED_GAMMA).
- dev_server.js and two API_V2.md examples no longer show the retired
  claude-3-5-sonnet-20241022.

Model IDs checked against the Claude API reference: claude-haiku-4-5 is
Active; claude-3-5-haiku-20241022 (retired Feb 19 2026) and
claude-3-5-sonnet-20241022 (retired Oct 28 2025) are retired. The
firmware's raw request shape (x-api-key, anthropic-version 2023-06-01,
model / max_tokens / messages, reading content[0].text) matches the
documented one.

Verified: 82/82 native tests; flashed to the C3, which reports aiModel
"claude-haiku-4-5" after reboot (the persisted retired id is migrated on
load). Not verified end-to-end against the API: no key was used.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Follow-up from review of the default-model fix, which left two ways to
end up with a retired or empty model:

- The dev-secrets override in main.cpp assigned DEV_AI_MODEL
  unconditionally, after loadConfig() and so after its migration. A
  secrets.h copied from the old example (which shipped
  claude-3-5-sonnet-20241022) kept running a retired id, and any settings
  save persisted it. An empty DEV_AI_MODEL blanked the model, unlike the
  length-guarded SSID/key overrides next to it.
- POST /api/config stored any string: a retired id lived until the next
  reboot's migration, and an empty string was stored and never fell back
  to the default, because the key now existed.

The migration is now a normalizeAiModel() helper (empty or retired ->
AI_MODEL_DEFAULT) applied on all three paths: NVS load, the /api/config
update and the dev override, which is now length-guarded like its
siblings.

Verified: firmware builds, including a build with src/secrets.h present
to compile the otherwise-dormant override path; 82/82 native tests.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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