Skip to content

fix: replace deprecated Workers AI model + repair hosted recall/query/crawl#34

Merged
harrymove-ctrl merged 1 commit into
mainfrom
fix/ai-model-and-crawl
Jun 21, 2026
Merged

fix: replace deprecated Workers AI model + repair hosted recall/query/crawl#34
harrymove-ctrl merged 1 commit into
mainfrom
fix/ai-model-and-crawl

Conversation

@harrymove-ctrl

Copy link
Copy Markdown
Owner

Why

Live prod showed five bugs after building a context package:

  • AI Query → "error 5028: model deprecated 2026-05-30"aiQueryRun hardcoded @cf/meta/llama-3.1-8b-instruct, which Cloudflare deprecated, and never used the OpenRouter key.
  • Memory chat → "Not found" — the per-run memory routes did not exist on the deployed worker.
  • Crawl = flattened nav/llms.txt boilerplatehtmlToText grabbed the whole document.
  • Build timer frozen at "0s" — nothing re-rendered elapsed time.
  • "Remember" button dead — gated on a delegate hosted runs never have.

What

  • Extract one aiChatComplete() helper: prefers OpenAI-compatible endpoint when OPENAI_API_KEY is set, else Workers AI on @cf/meta/llama-3.1-8b-instruct-fast (overridable via WORKERS_AI_MODEL). Routes aiQueryRun, the facts extractor, and memwalChat through it. Facts model keeps null-on-failure → still degrades to deterministic heuristics.
  • Add POST /api/runs/:id/memwal/{recall,query} and load namespace facts (context/facts.json / manifest) for grounded recall + chat.
  • Rewrite htmlToText to scope to <main>/<article>, drop nav/header/footer/script/style/svg/form, preserve headings + lists.
  • Live ticking elapsed timer on the build console.
  • Honest, clickable hosted "Remember" button (no silent no-op).

Verification

  • tsc --noEmit clean (api + web)
  • vitest run apps/api/src/worker.test.ts → 22/22 pass (incl. Firecrawl)
  • wrangler deploy --dry-run clean, no jsdom in runtime bundle

Follow-up (infra, not in this PR)

  • Set FIRECRAWL_API_KEY as a worker secret to activate clean JS-rendered crawling (code path already wired).

…ll/query/crawl

Cloudflare deprecated @cf/meta/llama-3.1-8b-instruct on 2026-05-30 (error
5028), which broke the AI Query endpoint (it hardcoded that model and never
used the OpenRouter key). Extract a single aiChatComplete() helper that prefers
the OpenAI-compatible endpoint when OPENAI_API_KEY is set, else Workers AI on
@cf/meta/llama-3.1-8b-instruct-fast (overridable via WORKERS_AI_MODEL). Route
aiQueryRun, the facts extractor, and memwalChat through it. The facts model
keeps null-on-failure so extraction still degrades to deterministic heuristics.

Also in this change set:
- Add per-run memory routes POST /api/runs/:id/memwal/{recall,query} so the
  Memory page stops returning "Not found" on hosted runs; resolve the run's
  namespace and proxy to the global recall/chat handlers.
- Load namespace facts (context/facts.json / manifest) for grounded recall and
  chat instead of an in-memory seed table.
- Rewrite htmlToText to scope to <main>/<article>, drop nav/header/footer/
  script/style/svg/form blocks, and preserve headings and list structure, so
  the fetch fallback no longer flattens nav/llms.txt boilerplate.
- Add a live ticking elapsed timer to the build console (no longer frozen 0s).
- Make the hosted "Remember" button honest and clickable instead of silently
  no-opping behind a delegate gate it can never satisfy.
@harrymove-ctrl harrymove-ctrl merged commit 6bcf3c8 into main Jun 21, 2026
2 checks passed
@harrymove-ctrl harrymove-ctrl deleted the fix/ai-model-and-crawl branch June 21, 2026 07:45
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