Skip to content

fix(research): accept object-shaped exploration queries (#515) - #532

Merged
HananKavitzAmat merged 2 commits into
chunkhound:mainfrom
munjikesh:fix/515-object-exploration-queries
Nov 18, 2026
Merged

HananKavitzAmat merged 2 commits into
chunkhound:mainfrom
munjikesh:fix/515-object-exploration-queries

Conversation

@munjikesh

Copy link
Copy Markdown
Contributor

Closes #515.

Note: #531 also targets this issue. It was opened after my claim on the issue, and the two are close. This one also rejects unknown keys in the object form (additionalProperties: false, plus a key check for Anthropic and Gemini, which don't validate the response), per the issue's "Never: accept a payload silently by dropping unknown keys". Either is fine with me. Close whichever you don't want.

What

Exploration query generation now accepts the {query, aspect} objects some models return, instead of dropping the whole expansion. A failed call is no longer a silent []: it shows up in the stats.

  • Schema (_generate_exploration_queries): queries.items is anyOf a string or an object with a required query string and an optional aspect string, with additionalProperties: false. Only queries is relaxed.
  • Normalization: both shapes become the query strings the stage already uses. Each object-shaped item logs one debug line naming the source file, for example Coerced object-shaped exploration query 0 for AGENTS.md (aspect='Component architecture').
  • Still rejected: an item with no query string, unknown keys, or a non-string aspect. Schema validation rejects these for the providers that validate. The normalization loop rejects them too, because Anthropic and Gemini only json.loads the response.
  • Failures are visible: the try/except that returned [] is gone. The error goes to _generate_all_exploration_queries, which already logs a warning with the file and the reason and records it in FailureMetrics. The early return for "no queries generated" now includes query_generation_failures as well. Without it, the case this issue describes, where every file fails, still had no failure entry in the stats.
  • Budget: unchanged. The call still passes depth_exploration_max_completion_tokens.

Why test_returns_empty_on_llm_failure changed

It asserted that a failed LLM call returns [], which is the silent behaviour this issue removes. It is now test_llm_failure_is_raised_not_returned_as_empty. Two other tests check where the failure goes now: test_failed_generation_is_counted_and_logged checks the warning and FailureMetrics, and test_stats_count_failures_when_every_file_fails checks explore_coverage_depth's stats.

Tests

In tests/unit/research/shared/test_depth_exploration.py:

  • [{query, aspect}, "plain string"] yields both queries. The payload goes through parse_and_validate_structured_json with the schema the service sends, as a structured completion would. One coercion debug line names the file.
  • A payload with no query, a non-string query, or an extra key fails validation and raises. A payload from a provider that doesn't validate (no query, an extra key, a non-string aspect) raises too.
  • A failed call raises, is logged with its file, and is counted. When all 3 files fail, stats["query_generation_failures"] has a count of 3.

With main's depth_exploration.py, 10 of these fail. With this change, the file has 43 passed. The cases that reject bad items guard requirement 3 under the new schema. The schema change itself is covered by the object-shaped test.

Checks run (Windows 11, Python 3.12)

  • uv run pytest tests/unit/research/shared/test_depth_exploration.py -q: 43 passed.
  • tests/unit/research: 265 passed.
  • uv run pytest tests/test_smoke.py -v -n auto: 14 passed. One earlier cold run had 5 CLI-help failures that didn't come back in later runs.
  • uv run pytest tests/ -n auto: the failures are the same as main's on this machine. These include tests/site (needs the site build), some realtime and MCP tests, and a flaky tests/mcp/test_smoke.py::TestMCPStartupImports::test_mcp_stdio_server_starts, which passed 1 run in 3 on both main and this branch.
  • On the two changed files, ruff reports the same findings as main, and ruff format only touches lines that were already there. mypy on the module is clean.

Note for strict-mode providers

OpenAI's strict structured outputs want every property in required and additionalProperties: false on every object. This schema's root object didn't meet that on main either, so the optional aspect doesn't make an already non-strict schema worse. I kept aspect optional as the issue asks. A required, nullable aspect would fail models that return {query} alone on endpoints that don't enforce the schema, which is where this drift comes from.

AI disclosure: Claude Code (an AI coding agent) wrote this change and its tests and ran the checks above, operating my account, in line with CONTRIBUTING's AI-generated workflow. A separate AI review pass checked it, and its findings were applied. I haven't reviewed the diff line by line myself.

🤖 Generated with Claude Code

Some models return each exploration query as {query, aspect} instead of
a string; the schema rejected the payload and the swallowed exception
dropped every query for the file. Accept a string or a {query, aspect}
object, normalize to strings with one debug line per coerced item, and
keep rejecting items with no query string, unknown keys or a non-string
aspect (also for providers that don't validate the response).

A failed call now propagates to _generate_all_exploration_queries, which
logs it with the file and counts it in query_generation_failures; the
"no queries generated" early return now includes that counter too.
test_returns_empty_on_llm_failure codified the silent [] and is replaced.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@HananKavitzAmat

Copy link
Copy Markdown
Collaborator

@munjikesh The rust-checks issue is resolved in main. Please pull the fix.

Picks up the rust-checks fix (chunkhound#534).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@munjikesh

Copy link
Copy Markdown
Contributor Author

Thanks, merged main in (16905a8). tests/unit/research and the smoke tests pass locally.

@HananKavitzAmat
HananKavitzAmat added this pull request to the merge queue Nov 18, 2026
Merged via the queue into chunkhound:main with commit 09119a2 Nov 18, 2026
25 checks passed
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.

fix(research): accept object-shaped exploration queries

2 participants