Skip to content

fix(ai): context extraction only on the user's own key; vendors by id (main green again) - #205

Merged
catomean merged 2 commits into
mainfrom
fix/no-background-ai
Sep 25, 2026
Merged

catomean merged 2 commits into
mainfrom
fix/no-background-ai

Conversation

@catomean

Copy link
Copy Markdown
Collaborator

There are two commits here. The first one gets main green again so the second one can deploy.

1. fix(ai): context extraction runs only on the user's own key

After every professional-chat turn, extractAndSaveContext fired a second model call (fire-and-forget, after the answer) on the shared free-tier Groq key. Nobody asked for that call. Standing rule (2026-09-25): free-tier keys are spent only when a person deliberately asks. Extraction now needs the user's own key and uses their provider. Without one it returns before making any call.

New test tests/__tests__/no-free-background-ai.test.ts walks the import graph from:

  • /api/rebuild, which the box timer appcron-botsmann-rebuild calls daily
  • /api/warmup
  • /api/health

It fails if any of them reaches a model client. The walker gets checked against a synthetic graph first, so a walker that finds nothing can't pass.

I checked both guards by mutation. Each change below failed the tests (4 red):

  • importing @/lib/nlp into /api/rebuild fails the graph test
  • removing if (!own.apiKey) return 0; fails the 3 new extractor cases

Findings so far: /api/rebuild only revalidates /blog, and /api/warmup runs local Transformers.js embeddings. Neither spends a free-tier key.

2. fix(ai): pick chain vendors by id, and make main green again

main has been red since #203. That PR bumped ai-kit to 1.10, which put Gemini second in freeChain('BOTSMANN'). vendorChain(1, …) was meant to pick OpenRouter, so a BYOK OpenRouter key would have gone down the Gemini link. Vendors are now looked up by id, in the code and in both tests. The same bump broke two other things, fixed here: a prettier reformat and the new next lint rule against relative window.location.href.

pnpm run verify is green locally: format, lint, typecheck, selfhost check, 306 tests, build.

🤖 Generated with Claude Code

catomean and others added 2 commits September 25, 2026 09:33
main has been red since #203 bumped @bitbaum/ai-kit to 1.10, which put
Gemini second in freeChain('BOTSMANN'). vendorChain() indexed [1] for
OpenRouter, so a BYOK OpenRouter user's key would have been sent down the
Gemini link. Look vendors up by id instead (code and both tests).

Also clears the rest of the red verify from the same bump: prettier 3.x
reformat of six files and the new next lint rule on relative
window.location.href assignments (sign-out keeps its full reload).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Signed-off-by: Cato <41178744+catomean@users.noreply.github.com>
Every professional-chat turn fired a second, unasked model call
(extractAndSaveContext, fire-and-forget after the answer) on the shared
free-tier Groq key. Standing rule (2026-09-25): free-tier keys are spent
only when a person deliberately asks. Extraction now requires the user's
own key and uses their provider; without one it returns before any call.

Adds tests/__tests__/no-free-background-ai.test.ts: walks the import graph
from the timer route (/api/rebuild, appcron-botsmann-rebuild), /api/warmup
and /api/health and fails if any reaches a model client. Proven by
mutation: importing lib/nlp into /api/rebuild fails it, and dropping the
own-key guard fails the three new extractor cases.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Signed-off-by: Cato <41178744+catomean@users.noreply.github.com>
@catomean
catomean merged commit ce98b0c into main Sep 25, 2026
1 check passed
@catomean
catomean deleted the fix/no-background-ai branch September 25, 2026 07:44
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