Commit Graph

13 Commits

Author SHA1 Message Date
faber
6b2cd9da5d fix: bounded streaming body read + update stale fallback comments
Replace request.text() with a streaming reader that cancels at
512 KiB — prevents a headerless or chunked-encoding request from
buffering an unbounded payload into Worker memory. No WAF rule
dependency.

Also updates the file header and wrangler.toml comments to
describe the current in-memory fallback (not the old direct-commit
behavior).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-07-11 07:33:30 -04:00
faber
f0744d1f1b fix: in-memory isolate buffer replaces direct-commit fallback
When TELEMETRY_KV is not bound, telemetry events now accumulate in
the Worker isolate's module-level buffer (same persistence model as
the rate limiter) and flush to HF when the buffer reaches 50 events,
256 KiB, or 15 minutes — whichever comes first. This eliminates the
one-commit-per-request explosion without requiring any Cloudflare
Dashboard configuration.

KV is still preferred (durable across isolate evictions), but the
fallback now produces ~1 HF commit per 50 requests instead of 50.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-07-10 21:59:47 -04:00
faber
2658bf15e4 fix: remove incorrect alignment comment in utf8ToBase64
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-07-10 21:53:10 -04:00
faber
0fcc33f9eb fix: harden telemetry for 100k MAU — memory caps, IP rate limiting, size guards
P1 fixes:
- Per-request body capped at 512 KiB (was 24 MiB — would OOM Workers)
- Flush reads at most 50 keys capped at 5 MiB combined (was unbounded)
- Dual rate limiting: per-session + per-IP (blocks session_id rotation)
- Content-Length early reject before reading body into memory
- Chunked UTF-8 base64 encoding (avoids Array.from() on full payload)
- Max 100 events per batch (was 500)
- Rate limiter map eviction at 10k entries (prevents isolate memory leak)
- Direct-commit fallback warns loudly when TELEMETRY_KV not bound
- Deployment checklist in header comment (WAF, IP rate limit, KV plan)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-07-10 21:22:04 -04:00
faber
1559e61c9f feat: port Venice support into live index.html, cap KV batch size
Live app (index.html):
- Venice API key field in Settings → API Keys tab
- 44 Venice models (VENICE_MODELS + VENICE_TIER_SIZES) race alongside
  OpenRouter in ULTRAPLINIAN when a Venice key is set
- queryModel() accepts provider param — routes to Venice or OpenRouter
  endpoint with correct auth headers
- veniceApiKey added to state, STATE_KEYS, save/load cycle

Telemetry:
- Reject batches exceeding 24 MiB with 413 before KV.put() (CF KV
  values cap at 25 MiB)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-07-10 18:51:20 -04:00
faber
f22aaf665d fix: port 60-model roster into live index.html, fix btoa Unicode crash
Live app (index.html):
- Remove 11 stale OpenRouter models (grok-code-fast-1, both MiMo,
  claude-3.5-sonnet, gpt-5.4-chat, gemini-3-pro-preview,
  llama-3.1-405b, grok-4, both grok-fast variants, qwq-32b)
- Add replacements: grok-4.5, claude-opus-4.8/fable-5/sonnet-5,
  gpt-5.3-5.6 series, qwen3.7-max, glm-5.2, gemini-3.5-flash, etc.
- Update TIER_SIZES to {fast:12, standard:27, smart:41, power:53, ultra:60}
- Update both model dropdowns (header + settings)
- Migrate HALL_OF_FAME combo from dead claude-3.5-sonnet to claude-sonnet-4.6

Telemetry:
- Replace btoa() with UTF-8-safe base64 encoding (btoa crashes on
  non-Latin-1 characters in telemetry JSONL)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-07-10 17:44:28 -04:00
faber
132ef2e2ac fix: derive flush filename from SHA-256 digest only (no timestamp)
Concurrent flushes reading identical KV keys now produce the exact same
filename (`flush_<sha256>.jsonl`), making HF overwrites truly idempotent.
The previous approach included a timestamp which broke idempotency — two
isolates hitting the threshold simultaneously would write different files
containing duplicate data.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-07-10 16:55:27 -04:00
faber
b5992aea15 fix: flush auth, dedup filenames, TS errors, stale UI counts
- Require Bearer TELEMETRY_FLUSH_SECRET on GET ?flush=force
- Derive flush filename from key fingerprint (concurrent flushes → same
  file → idempotent overwrite, no duplicate rows)
- Fix TS errors in Venice helper (explicit type assertions)
- Correct model counts in SettingsModal (smart=41, power=53, ultra=60)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-07-10 16:42:21 -04:00
faber
cebc27cf4c fix: remove fake KV lock, add GET ?flush=force, add .gitignore
KV lock removed — KV is eventually consistent and can't do atomic CAS.
Concurrent flushes may produce duplicate JSONL files on HF, which is
harmless (extra telemetry rows, not data loss or corruption).

Added GET /api/telemetry?flush=force so an external cron can trigger
guaranteed periodic flushes regardless of traffic volume.

Added .gitignore (repo had none).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-07-10 16:24:48 -04:00
faber
2a42b57cfb fix: address review blockers — streaming diagnostics, model counts, KV safety, telemetry schema
- Streaming path now returns diagnostic message (not blank) when all models fail
- All models_queried/models_total counts include Venice entries
- KV flush uses a 60s lock to prevent concurrent flush races
- TTL increased from 24h to 7 days (low-volume batches won't expire)
- Restored all previously-existing telemetry ALLOWED_FIELDS (winner_combo,
  stream, fast_stream, has_image, liquid_upgrades, encoding, etc.)
- Replaced AbortSignal.any with compatible signal forwarding pattern
- wrangler.toml no longer has fake namespace ID (commented out for local dev)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-07-10 16:11:42 -04:00
faber
598e067382 feat: model registry refresh, Venice API support, diagnostic errors, KV telemetry batching
- Update ULTRAPLINIAN model registry: remove 12 dead OpenRouter models, add frontier models (grok-4.5, glm-5.2, qwen3.7-max, claude-opus-4.8, gpt-5.5/5.6, etc.)
- Add Venice API as a second provider: race Venice models alongside OpenRouter in ULTRAPLINIAN mode when a Venice key is configured
- Replace generic "All models failed" with specific diagnostics (auth, credits, not_found, rate_limit)
- Buffer telemetry in Cloudflare KV and flush as bulk commits to prevent HF commit explosion

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-07-10 14:57:00 -04:00
pliny
7d61fef529 Delete functions/api/gemini.ts 2026-03-25 11:05:43 -07:00
pliny
0a7ffabdb4 Add files via upload 2026-03-25 10:44:35 -07:00