Support Chat Gemini Model Repair Implementation Plan¶
For agentic workers: REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (
- [ ]) syntax for tracking.
Goal: Make the support-chat API use the valid Gemini 3.1 Flash-Lite Vertex model ID by default and prevent the invalid ID from returning.
Architecture: Keep the existing environment-driven model selection and Vertex REST client. Correct only the default and documented model ID, then lock the endpoint behavior with focused unit tests.
Tech Stack: TypeScript, Vitest, Vertex AI REST, Vercel Functions, Markdown
Global Constraints¶
- Use
gemini-3.1-flash-liteas the supported model ID. - Keep
GEMINI_LOCATION=globaland preserve customGEMINI_MODELoverrides. - Do not add retries, aliases, or fallback models.
- Do not run browser tests, server tests, or the full test suite.
- Do not create git commits.
- Do not use em dashes.
Task 1: Correct the Runtime Model Default and Regression Tests¶
Files: - Modify: api/__tests__/env.test.ts - Modify: api/__tests__/gemini.test.ts - Modify: api/__tests__/support-chat-fallback.test.ts - Modify: api/__tests__/support-chat-logging.test.ts - Modify: api/_lib/env.ts
Interfaces: - Consumes: loadEnv(): AppEnv and streamGemini(accessToken, input, signal?). - Produces: AppEnv.geminiModel defaulting to gemini-3.1-flash-lite while retaining environment overrides.
- [ ] Step 1: Write failing default-model expectations
In api/__tests__/env.test.ts, change the default assertion to:
In api/__tests__/gemini.test.ts, make the endpoint test exercise the runtime default:
process.env.GEMINI_LOCATION = "global";
delete process.env.GEMINI_MODEL;
process.env.GEMINI_TEMPERATURE = "0.35";
_resetEnvCache();
and expect:
"https://aiplatform.googleapis.com/v1/projects/loupe-factory/locations/global/publishers/google/models/gemini-3.1-flash-lite:streamGenerateContent?alt=sse"
- [ ] Step 2: Run focused tests and confirm RED
Run:
Expected: the model-default and endpoint assertions fail because api/_lib/env.ts still defaults to gemini-3.1-flash-lite-preview.
- [ ] Step 3: Correct the runtime default
In api/_lib/env.ts, set:
Update the mocked geminiModel values in api/__tests__/support-chat-fallback.test.ts and api/__tests__/support-chat-logging.test.ts to gemini-3.1-flash-lite so fixtures reflect production configuration.
- [ ] Step 4: Run focused tests and confirm GREEN
Run:
npx vitest run api/__tests__/env.test.ts api/__tests__/gemini.test.ts api/__tests__/support-chat-fallback.test.ts api/__tests__/support-chat-logging.test.ts
Expected: all focused test files pass.
Task 2: Correct Setup and Troubleshooting Documentation¶
Files: - Modify: README_SUPPORT_CHAT.md
Interfaces: - Consumes: the runtime defaults established in Task 1. - Produces: deployment instructions that use the same supported model ID and location as the API.
- [ ] Step 1: Correct the environment table
Set the documented value to:
Keep:
- [ ] Step 2: Correct the regional guidance
Replace the stale regional guidance with:
Your **GCS bucket** can stay multi-region. The **Vertex RAG corpus and `GCP_LOCATION`** must use `us-central1` so `retrieveContexts` reaches the corpus region. Gemini generation uses the separate `GEMINI_LOCATION`; this project uses `global`.
- [ ] Step 3: Document the observed 404
Add this troubleshooting row:
| `Gemini streamGenerateContent failed (404)`: *Publisher model ... was not found* | `GEMINI_MODEL` is not a valid Vertex model ID or is unavailable at `GEMINI_LOCATION` | Set `GEMINI_MODEL=gemini-3.1-flash-lite` and `GEMINI_LOCATION=global` for Production + Preview, then redeploy. |
- [ ] Step 4: Run static and focused verification
Run:
rg -n "gemini-3\.1-flash-lite-preview|gemini-3\.1-flash-lite" README_SUPPORT_CHAT.md api
npm run typecheck
Expected: the invalid ID is absent from README_SUPPORT_CHAT.md and api, all active configuration and test fixtures use gemini-3.1-flash-lite, and type checking passes.