Skip to content

feat: surface model mismatch on query responses#16

Merged
rbcorrales merged 4 commits into
mainfrom
feat/rest-query-stale-model-guard
May 28, 2026
Merged

feat: surface model mismatch on query responses#16
rbcorrales merged 4 commits into
mainfrom
feat/rest-query-stale-model-guard

Conversation

@rbcorrales
Copy link
Copy Markdown
Member

Summary

Adds an X-WPVDB-Model-Mismatch response header to POST /wpvdb/v1/query (REST::handle_query) when the request resolves to a model that differs from the active default model. A small add_model_mismatch_header() helper wraps the response at all three success return points (cache hit with debug, cache hit, and the freshly computed response), so the signal is present regardless of cache state.

Background

/query embeds the query with the requested model and filters stored rows by it. After a provider/model migration, a stale client that still pins the old model gets zero results with no indication why. The contract is internally consistent, so this is intentionally a visibility signal, not a hard failure: the request still returns 200 with its (likely empty) results, plus the header so operators, proxies, and curious clients can spot the misconfiguration fast.

The header is added at request time (not from the cached payload), so it fires correctly even on cache hits, and the response JSON shape is unchanged.

Testing

php -l clean. phpcs --standard=phpcs.xml.dist introduces zero new violations (15 errors / 18 warnings before and after, all pre-existing baseline in this file). No change to the success/error response bodies; header is additive.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds an opt-in visibility signal to /wpvdb/v1/query responses when the request’s resolved embedding model differs from the site’s currently active default model, helping diagnose “empty results after migration” scenarios without changing response bodies or status codes.

Changes:

  • Wraps all successful handle_query() return paths (cache hit w/ debug, cache hit, fresh compute) to consistently attach a model-mismatch response header.
  • Introduces a small add_model_mismatch_header() helper that converts payloads to WP_REST_Response and conditionally sets X-WPVDB-Model-Mismatch.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comment thread includes/class-wpvdb-rest.php
rbcorrales and others added 2 commits May 27, 2026 19:14
An explicit "model": "" resolved to an empty model, bypassing the
default fallback so text queries embedded with an empty model and
vector queries filtered WHERE model = ''. Normalize like the /vectors
path does.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

@rbcorrales rbcorrales merged commit 8872dc5 into main May 28, 2026
1 check passed
@rbcorrales rbcorrales deleted the feat/rest-query-stale-model-guard branch May 28, 2026 02:01
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