feat(api): extend Gary header parsing to embeddings, search, and rerank#4
Merged
OriginalGary merged 1 commit intomainfrom May 5, 2026
Merged
feat(api): extend Gary header parsing to embeddings, search, and rerank#4OriginalGary merged 1 commit intomainfrom
OriginalGary merged 1 commit intomainfrom
Conversation
…nk handlers parseGaryContext() is now called at the entry point of POST /v1/embeddings, POST /v1/search, and POST /v1/rerank — matching the existing coverage in handleChat(). Audit ring buffer entries from all four surfaces are identical in shape. Architecture note recorded in GRAZE.md: per-handler injection is the only viable pattern because Next.js middleware runs on Edge Runtime, which is incompatible with the SQLite audit log and the in-process ring buffer. 8 new tests in gary-coverage-extension.test.ts verify that each handler captures all four Gary fields, that null fields are correctly represented when no headers are sent, that the ring buffer entry shape matches the chat handler's shape, and that entries from all three new handlers accumulate in the shared ring buffer in newest-first order. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
CI Coverage Report
Coverage artifact was not available for this run. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
parseGaryContext()wired intoPOST /v1/embeddings,POST /v1/search, andPOST /v1/rerank— closing the coverage gap from PR feat(api): Gary header contract — read-only parsing of X-Gary-* headers #3 which only coveredhandleChat()routesgary-coverage-extension.test.tsverifying ring buffer capture, null-field handling, entry shape parity, and multi-handler accumulationdocs/GRAZE.md§header-contract updated: coverage surface table, architecture rationale for per-handler approach, health endpoint noteOption selected: per-handler injection (Option B)
Investigation findings: No
middleware.tsexists in this repo. Next.js middleware runs on Edge Runtime — incompatible withbetter-sqlite3(SQLite) used bylogAuditEventand with the Node.js in-process ring buffer (recentGaryContexts). CLAUDE.md explicitly documents "No global Next.js middleware — interception is route-specific." Per-handler is the only viable pattern.Routes not covered (intentionally):
GET /v1/embeddings(model list — read-only, no agent payload),GET /v1/search(provider list),GET /v1/models,/v1/registered-keys(admin),/v1/batches,ws://WebSocket handshake.Test coverage
curl examples
Surprises
The route handlers fail fast (400) on invalid JSON before reaching any DB or credential code, which made testing straightforward: send Gary headers with an unparseable body, verify the ring buffer entry, done. No mocking required.
🤖 Generated with Claude Code