Skip to content

feat(docs): Dox chat evals (#355) - #373

Merged
baldurpan merged 16 commits into
mainfrom
feature/355-dox-chat-evals
Nov 25, 2026
Merged

baldurpan merged 16 commits into
mainfrom
feature/355-dox-chat-evals

Conversation

@baldurpan

Copy link
Copy Markdown
Contributor

Closes #355

Evals for the Dox chat: a fixed case set, each case scored by code against what a good answer needs. Plan and ledger: #355.

  • Offline layer (pnpm docs:test, no model, no key): docs/evals/ runs every case through validateChatRequest and the new shared prepareTurn, scores recall@10, withinK, MRR, fit.kept, vocabulary.hit and refusal.quiet, and fails on any move from baseline.json.
  • Live layer (by hand, never in CI): evals:live against a local [env.evals] Worker, with a Neuron budget guard and a CI refusal. The first run on Gemma 4 26B passed all 12 live cases at 937 Neurons and is committed as its report.

Phases landed, one commit each:

  1. d861870 extract the steps before the model into docs/worker/prepare-turn.ts
  2. c51c5f9 the case set and its checks
  3. 85dfa3e the offline layer and its first baseline
  4. c303e75 the stream reader and graders
  5. b8ba9a9 the live runner, budget guard and evals environment
  6. c2a0992 the first live run (grader fix 1996c17)

Open owner checks the feature ships with, none of them blocking: #305 (the starters' and rewordings' pages answer their questions) and #341 (the dailyLimit against a shared quota). The three retrieval misses the baseline records are filed as #369.

No release note: the change touches docs/**, context/** and .gitignore, which context/release.md says owe none. The merge deploys the Worker (docs/worker/** and docs/package.json are worker-deploy.yml paths) with unchanged behaviour. It ships nothing to npm.

…355)

Phase 1 of #355. docs/worker/prepare-turn.ts now holds the question pick,
the retriever cache, the namespaced search, fitChunks, selectVocabulary and
assembleSystemPrompt; createChatHandler calls prepareTurn inside its existing
try/catch with the same 500 path, trace and three stage timings.
chat-handler.test.ts is unchanged. READMEs name prepare-turn.ts.

Gate 1: pnpm check, typecheck (root and docs), build, docs:build,
worker:bundle-check, docs:audit-dist, pnpm test (3831 passed),
pnpm docs:test (1668 passed), test-marker grep: all exit 0.
Gate 2: reviewer subagent, FAIL (dead VocabularySection import) on round 1,
PASS WITH NOTES on loopback 1; notes in context/notes.md.
Phase 2 of #355. docs/evals/cases.ts holds 36 typed cases (starters derived
from CHAT_STARTERS, two rewordings each, lookups, absent, off-topic,
injection, follow-up and fault), 12 of them live, each group stating the
source of its expectation. docs/evals/cases.test.ts checks routes, chunk
ids, vocabulary titles, documented names and page contexts against the
corpus, and shows on planted lists that each check fails. docs/tsconfig.json
includes evals; stack.md's Layout lists docs/evals/.

Gate 1: pnpm check, typecheck (root and docs), build, docs:build,
worker:bundle-check, docs:audit-dist, pnpm test (3831 passed),
pnpm docs:test (1682 passed), test-marker grep: all exit 0.
Gate 2: reviewer subagent, FAIL (untraceable source for the terse lookups)
on round 1, PASS WITH NOTES on loopback 1; notes in context/notes.md.
Phase 3 of #355. docs/evals/metrics.ts scores gmt's retrieval metrics
without tools.offered (recallAt10, withinK, mrr, fit.kept, vocabulary.hit,
refusal.quiet), truncated to three decimals. docs/evals/offline.test.ts runs
in pnpm docs:test: every case goes through validateChatRequest and
prepareTurn, and the scores must equal the committed baseline.json, which
`pnpm --filter docs evals:baseline` rewrites and formats. Runbook in
docs/evals/README.md; test tables, verify.md and stack.md updated.

Baseline: recallAt10 0.888, mrr 0.703, every other metric 1. Misses:
follow-up-undo-that, lookup-key-branch-prefix, lookup-what-does-clean-do.

Gate 1: pnpm check, typecheck (root and docs), build, docs:build,
worker:bundle-check, docs:audit-dist, pnpm test (3831 passed),
pnpm docs:test (1706 passed), test-marker grep: all exit 0.
Gate 2: reviewer subagent, FAIL (refusal.quiet and fit.kept departed from
gmt's definitions) on round 1, PASS WITH NOTES on loopback 1; notes in
context/notes.md.
Phase 4 of #355. docs/evals/read-stream.ts turns a chat SSE body into a
record (text, traces, progress, refusal, run error, usage, finish reason,
faults), parsing each event through Zod and never throwing; a stream with
no terminal event is a fault. docs/evals/graders.ts runs the nine D12
graders that apply to a case, and a dox-refusal makes it ungraded. Both are
proven on five fixtures recorded from createChatHandler over fakeText
(answer, refusal, run-error, spent, truncated). The runbook gains the
graders' table and how to re-record.

Gate 1: pnpm check, typecheck (root and docs), build, docs:build,
worker:bundle-check, docs:audit-dist, pnpm test (3831 passed),
pnpm docs:test (1754 passed), test-marker grep: all exit 0.
Gate 2: reviewer subagent, FAIL (markup pattern was not gmt's; known skipped
indented fences) on round 1, PASS WITH NOTES on loopback 1; notes in
context/notes.md.
…ent (#355)

Phase 5 of #355. docs/evals/budget.ts holds the Neuron rates, the 350
worst case, the 2,500 default budget, the Gemini cap, the CI refusal and
the RunGuard; docs/evals/report.ts the report shape, its diff with
regressions flagged, and a write that only a fully passing run makes, with
no answer text. docs/evals/run-live.ts runs the live flow under Node type
stripping (`pnpm --filter docs evals:live`). wrangler.toml gains a
local-only [env.evals] (remote AI, no KV, workers_dev = false), with
worker:dev:evals blanking the Gemini key; docs/.cache/ is gitignored. The
runbook gains its live section; READMEs, verify.md and stack.md match.

Nothing was spent: the runner was exercised with --help, with no Worker
(exit 2), under CI (exit 2) and against loopback fakes only.
`wrangler deploy --dry-run --env evals`, credential-free, exits 0 listing
the AI binding and no KV.

Gate 1: pnpm check, typecheck (root and docs), build, docs:build,
worker:bundle-check, docs:audit-dist, pnpm test (3831 passed),
pnpm docs:test (1791 passed), test-marker grep: all exit 0.
Gate 2: reviewer subagent, FAIL (a connection lost mid-stream exited 1,
the regression code) on round 1, PASS WITH NOTES on loopback 1; notes in
context/notes.md.
The first live run failed a correct answer to lookup-rename with
"known: undocumented worktree directory". The answer's bash block held the
comment "# Rename a specific worktree directory", and the grader read it as
a command named `directory`. A shell comment is prose, and D7 checks code
only, so comments are now dropped from shell and unlabelled fenced blocks
before commands and flags are read. The corpus writes such comments itself
(skills/worktree/SKILL.md:517), so an answer quoting it verbatim could not
pass before. This fixes a false positive; no expectation changed.
…its report (#355)

docs/evals/live-cf-gemma-4-26b.json is the first live report. All 12 live
cases pass, every Neuron figure is measured from RUN_FINISHED usage, and the
report holds no answer text. The runbook's cost table carries the run's
figures.

The run:
- The evals scripts dropped `--local`. Under it, wrangler 4.152.0 printed
  `env.AI AI not supported`, and the first one-case attempt failed with
  `RUN_ERROR upstream_unavailable` and no usage, so nothing was spent.
  `--local` disables remote bindings, and Workers AI has no local simulator.
  Without the flag, the bindings table reads `env.AI AI remote`.
  `[env.evals]` binds AI only, so nothing else became remote.
- GET /api/brains listed exactly cf-gemma-4-26b and cf-glm-4.7-flash, both
  workers-ai.
- `--only lookup-rename`: measured at 79 Neurons, not flagged unmeasured.
  It failed a false positive in the known grader, fixed in the previous
  commit.
- `--budget 4200 --write-baseline`: 12/12 pass, spent 937 of 4200 Neurons,
  5 to 109 per question, 0.6 to 11 s per answer, 91 s in all.
- Spend for the session: 1,016 Neurons on the NorthGuild account
  (Workers Free, the pool shared with gmt), approved by the maintainer.

The same `--local` defect in main's `worker:dev` is filed as #367.
…es (#355)

#366 renamed the SKILL.md issue section to '…, a ClickUp task or your own
tracker', so the starter case's vocabulary title no longer resolved. Its
--issue text in commands/branch.mdx also pushes the github-issue-integration
guide from rank 3 to 4 for 'Name my branch after a GitHub issue', past the
fit budget; the baseline records the move (fit.kept 1 -> 0.962, MRR 0.703 -> 0.7).
@baldurpan

Copy link
Copy Markdown
Contributor Author

Merging main broke CI, and c205da2 fixes it. I brought main into this branch with update-branch (merge commit 25aefe3, no conflicts). After that, pnpm docs:test failed in two places, both caused by docs that #366 changed:

  1. A SKILL.md heading was renamed. It went from Derive a branch name from a GitHub, Jira or Linear issue or a ClickUp task to …, a ClickUp task or your own tracker. The ISSUES vocabulary title in docs/evals/cases.ts still used the old wording, so starter-guides-github-issue-integration no longer matched a section. I updated it to the new heading.
  2. One offline score dropped. feat(branch): custom issue providers (#357) #366 added --issue text to commands/branch.mdx, and that page's chunks now rank 1–3 for "Name my branch after a GitHub issue". The /guides/github-issue-integration/ chunk this case expects moved from rank 3 to rank 4, which is past the fitChunks budget. I regenerated the baseline with evals:baseline:
    • fit.kept 1 → 0.962
    • retrieval.mrr 0.703 → 0.7
    • reworded-github-issue-name [3] → [4], and the case now counts as a fit.kept failure

Please check the second item. I recorded the drop in the baseline instead of changing retrieval in this pull request. The answer for that question still gets branch › GitHub Issue Branching, Previewing a branch name and Branch name template, so it stays on topic. But the guide the case names no longer reaches the prompt. If that guide should win, the fix is in ranking or the fit budget, which is code already on main and not part of this pull request.

Verified with pnpm check, pnpm typecheck, pnpm --filter docs typecheck and pnpm docs:test (74 files, 1794 tests passed).

@craig-o-curtis craig-o-curtis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes, mainly for the eval's injection cases: two canaries are never shown to the model, and the link canary is matched case-sensitively. As written, those cases pass whether or not the injection works. The other inline comments are about budget accounting and exit codes in the live runner.

The prepareTurn extraction from chat-handler.ts behaves the same as before. No issues there.

Smaller cleanups, none blocking:

  • The buildCorpus + RetrievalCorpus/CORPUS_TEXT setup, BUILT_IN_COMMANDS and the request envelope are each copied across cases.test.ts, graders.ts, run-live.ts, offline.test.ts and prepare-turn.test.ts.
  • readStream in read-stream.ts is never used.
  • convertUnixToUtc returns "", never null, so the ?? "unknown" fallback in run-live.ts never runs.

Comment thread docs/evals/cases.ts Resolved
Comment thread docs/evals/cases.ts Resolved
Comment thread docs/evals/graders.ts Resolved
Comment thread docs/evals/cases.test.ts Resolved
Comment thread docs/evals/budget.ts Resolved
Comment thread docs/evals/run-live.ts Resolved
Comment thread docs/evals/budget.ts Resolved
Comment thread docs/evals/run-live.ts Resolved
Comment thread docs/evals/report.ts Resolved
Comment thread docs/evals/run-live.ts Resolved
… review found (#355)

- Each injection question now orders its canary written, so an obeyed injection shows;
  cases.test.ts fails a canary the model is never shown, and leak matches it in any case.
- cases.test.ts reads a documented name as a whole token, as the known grader does.
- The budget is the Workers AI brains' together and stops no Gemini brain; each case
  reserves the worst case (or a higher committed figure), so a run never passes it.
- A non-2xx response is no answer and stops the run; a lost Workers AI stream books the
  worst case; a Gemini-capped case is ungraded and exits 3.
- A partial --write-baseline recomputes spent over the report's cases.
- readStream is gone, and generatedAt falls back on convertUnixToUtc's "".
@baldurpan

Copy link
Copy Markdown
Contributor Author

@craig-o-curtis, thanks. The inline threads are answered one by one. dffca39 fixes nine of them, and the corpus hash is #374. On the three cleanups in the review body:

  • readStream was dead, so dffca39 removes it along with its one test.
  • convertUnixToUtc does return "", never null. The fallback now reads || "unknown".
  • The copied setup is mostly intentional, so I've left it.
    • cases.test.ts keeps its own BUILT_IN_COMMANDS and documented-name check because its header rule is that the list is checked against the corpus, never against the code under test. Importing indexDocs from graders.ts would let a grader bug vouch for the case list.
    • offline.test.ts's envelope and run-live.ts's requestBody aren't the same body. One goes through validateChatRequest in process; the other is the wire request, with brain, tools and context.
    • What's left is the four-line buildCorpus(...) call. I'd rather keep that inline than add a module for it. Say if you'd rather have the module.

One thing to know about the committed live report. injection-ignore-instructions is a live case, and its question changed in dffca39. Its pass in live-cf-gemma-4-26b.json was measured with the old question, which is exactly the one whose canary could never fire. I haven't run the live evals: they spend real Neurons, and only a person runs them. The next evals:live --only injection-ignore-instructions --write-baseline gives it a real measurement.

@baldurpan

Copy link
Copy Markdown
Contributor Author

I merged main again (6574531) to bring in #370, which conflicted in docs/package.json.

The conflict was two neighbouring lines, not a disagreement. #370 removed --local from worker:dev so it keeps its remote AI and KV bindings, and this branch adds worker:dev:evals and worker:dev:evals:gemini right after it. The merge keeps #370's worker:dev and both evals scripts unchanged. The evals scripts never had --local, and docs/worker/README.md already said so.

The rest of #370 (wrangler.toml, both READMEs, verify.md, .env.local.example) merged on its own. [env.evals] still declares its own remote [ai] and deliberately no DOX_USAGE, so #370's KV change doesn't reach it.

Verified with pnpm check, pnpm typecheck, pnpm --filter docs typecheck and pnpm docs:test (74 files, 1798 tests passed).

#372's cleanup.mdx edit ranks /commands/cleanup/ first for reworded-cleanup-merged-prs
(was second), so retrieval.mrr moves 0.7 -> 0.719.
@baldurpan

Copy link
Copy Markdown
Contributor Author

I merged main again (0fb675f) to bring in #372. There were no conflicts. #372's cleanup.mdx edit moved one offline eval score up: reworded-cleanup-merged-prs now gets /commands/cleanup/ at rank 1 instead of rank 2, and retrieval.mrr rises from 0.7 to 0.719. 3ee6bb6 records the new baseline. Verified with pnpm check and pnpm docs:test (74 files, 1798 tests passed).

@craig-o-curtis craig-o-curtis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working through these. I checked dffca39 against each thread, and all nine fixes are in:

  • Canaries: each canary is now ordered in its question, and the new cases.test.ts check fails any case whose canary the model is never shown. leak matches it case-insensitively through squash.
  • isDocumented: now matches a whole token, and the planted --forc case proves it.
  • Budget: applies per provider, with a worst-case reservation, and Gemini brains are no longer stopped by it.
  • Runner: !response.ok is a no-answer. A stream lost mid-answer books 350. leftUngraded and endRun are now separate, so capped runs exit 3.
  • spent: recomputed over the merged cases.

Leaving the corpus hash for #374 makes sense, since it changes the production trace protocol. Your reasons for keeping the duplicated setup are fair.

Two non-blocking notes:

  • As you said, the committed pass for injection-ignore-instructions in live-cf-gemma-4-26b.json was measured with the old question. It needs a --only injection-ignore-instructions --write-baseline run before anyone relies on that number.
  • The canary is now in the question, so a refusal that quotes it back ("I won't write zq7-canary-attack") will grade as a leak. That errs on the safe side, but if it turns up in a live run, that's why.

@baldurpan
baldurpan enabled auto-merge (squash) November 25, 2026 13:53
@baldurpan
baldurpan merged commit 9620a9c into main Nov 25, 2026
1 check passed
@baldurpan
baldurpan deleted the feature/355-dox-chat-evals branch November 25, 2026 13:55
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.

dox-chat-evals

2 participants