Repository navigation
feat(search): typed ranked-result envelope + OpenAPI schema emission (#1266) - #1370
Conversation
…1266) Foundation slice (#873 slice A) for the shared ranked-result envelope. * polylogue/surfaces/payloads.py: SearchEnvelope, build_search_envelope, build_search_cursor, RANKING_POLICY_MIXED / RANKING_POLICY_VERSION. * polylogue/mcp/payloads.py: MCPPaginatedSearchResultPayload now aliases SearchEnvelope; conversation_search_result_payload routes through the shared builder and threads query/lane/sort. * polylogue/daemon/http.py: _do_search_list returns the typed envelope. * polylogue/cli/query_output.py: --format json wraps hits in the canonical envelope (ndjson/yaml/csv keep streaming per-row). * polylogue/api/archive.py + polylogue/api/search_envelope_builder.py: Polylogue.search_envelope() returns the same shape. * devtools/render_openapi.py: emit docs/openapi/search.yaml from the Pydantic models; registered in command_catalog + generated_surfaces. * devtools/render_cli_output_schemas.py: publish search-envelope schema. * tests/unit/surfaces/test_search_envelope_contract.py: cross-surface semantic equivalence + envelope field-set pin + OpenAPI sanity check. Closes #1266. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (20)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6b345fc889
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| query_text = getattr(output, "search_query", "") or "" | ||
| retrieval_lane = getattr(output, "retrieval_lane", "") or "auto" | ||
| limit_value = getattr(output, "limit", None) or len(hits) | ||
| offset_value = getattr(output, "offset", 0) or 0 | ||
| sort_value = getattr(output, "sort", None) |
There was a problem hiding this comment.
Populate CLI envelopes from the query plan
In the actual CLI path, output_search_hits receives a QueryOutputSpec, which only carries formatting/destination settings and does not define search_query, retrieval_lane, limit, offset, or sort. As a result, polylogue --format json <query> always falls through these defaults and emits query: "", retrieval_lane: "auto", limit: len(hits), offset: 0, and no sort even when the user supplied a query or pagination flags, breaking the canonical envelope metadata and pagination contract. Thread the selection/page values from the execution plan instead of reading missing attributes from QueryOutputSpec.
Useful? React with 👍 / 👎.
PR #1370 changed `polylogue list --format json` for search-mode queries to emit a typed ranked-result envelope (`{"hits": [...], "limit": N, "next_cursor": ...}`) rather than a bare JSON array. The parity adapter at tests/infra/surfaces.py:307 still expected the bare array shape, causing `test_search_unique_token_parity` and `test_search_shared_token_parity` to fail on every search-mode case. Fix: when the parsed CLI output is a dict carrying a `hits` array, peel it and continue with the existing per-row id extraction. The list-mode and search-hit-mode shapes still work unchanged (both go through the same row loop). Updates the docstring to enumerate all three shapes the adapter now handles. Verification: - `nix develop --command pytest tests/unit/storage/test_surface_parity_adapters.py -q` → 10 passed (previously 2 failed). - No production code touched; test-infra only. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…#1384) ## Summary PR #1370 (typed ranked-result envelope) changed `polylogue list --format json` for search-mode queries to emit `{"hits": [...], "limit": N, "next_cursor": ...}` rather than a bare JSON array. The CLI parity adapter at `tests/infra/surfaces.py:307` still expected a bare array and asserted `not isinstance(parsed, list)`, causing both `test_search_unique_token_parity` and `test_search_shared_token_parity` to fail on every search-mode case on master. ## Solution When the parsed CLI output is a dict carrying a `hits` array (the typed envelope shape), peel the `hits` and continue with the existing per-row id extraction. The list-mode and search-hit-mode shapes still work unchanged — they hit the same row loop directly. Updated the inline doc to enumerate all three shapes the adapter now handles. ## Verification - `nix develop --command pytest tests/unit/storage/test_surface_parity_adapters.py -q` → **10 passed** (was 2 failures on master). - No production code touched; test-infra only. ## Scope Single-file, test-infra-only change. Should land before #1379 / #1380 / #1382 (or alongside) so those PRs' CI runs are unmasked by this pre-existing failure. Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
|
Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.
Only the rows listed above are dispositioned. Held findings remain open. |
Summary
Foundation slice (#873 slice A) for the shared ranked-result envelope. Introduces
SearchEnvelope— a typed Pydantic model carrying hits + total + limit/offset + next_offset/next_cursor + query + sort + retrieval_lane + ranking_policy/version + diagnostics — and routes CLI JSON, MCP, the Python API, and daemon HTTP through one shared builder so all four surfaces emit semantically-equivalent envelopes. Also emits an OpenAPI 3.1 schema (docs/openapi/search.yaml) generated from the Pydantic models so external tooling can auto-discover the daemon's ranked-search contract.Closes #1266.
Problem
Before this PR each surface emitted its own ad-hoc search shape. MCP exposed
MCPPaginatedSearchResultPayloadwith{hits, total, limit, offset, next_offset, next_cursor, diagnostics}. Daemon HTTP_do_search_listbuilt a hand-shaped dict with flat-row hits and a parallelmatchsub-object. CLI--format jsonemitted a bare list ofConversationSearchHitPayload. The Python API only returned the legacySearchResult(alist[ConversationSearchHit]wrapper). None of these surfaces declared the ranking policy, version, or carried the query / retrieval_lane / sort metadata required by #873. Reader/MCP clients had no way to discover the daemon HTTP shape mechanically — there was no OpenAPI document.Solution
polylogue/surfaces/payloads.py:SearchEnvelopemodel with all the required fields, plusRANKING_POLICY_MIXED/RANKING_POLICY_VERSIONconstants.build_search_envelope()(canonical builder with cursor/next_offset logic) andbuild_search_cursor().polylogue/mcp/payloads.py:MCPPaginatedSearchResultPayloadnow aliasesSearchEnvelope.conversation_search_result_payload()delegates tobuild_search_envelopeand threadsquery/retrieval_lane/sortfromMCPConversationQueryRequest.polylogue/mcp/server_tools.py: search tool passes query/lane/sort into the envelope builder.polylogue/daemon/http.py:_do_search_listbuilds the typed envelope andmodel_dumps it. The HTTPhitspayload now uses the canonicalConversationSearchHitPayloadshape ({conversation: {...}, match: {...}}) — the existing reader test was updated; no public clients besides the web reader consume this endpoint yet.polylogue/cli/query_output.py:output_search_hits()emits the envelope for--format json(the format that feat(search): one typed ranked-result envelope across CLI/MCP/API/HTTP (#873 slice A) #1266 calls out);ndjson/yaml/csvkeep streaming per-row payloads. Newformat_search_envelope()helper.polylogue/api/archive.py+polylogue/api/search_envelope_builder.py:Polylogue.search_envelope()typed API method; build logic extracted topolylogue/api/search_envelope_builder.py(keepsarchive.pyunder the per-file LOC budget).devtools/render_openapi.py+docs/openapi/search.yaml: generated OpenAPI 3.1 description of the daemon HTTP search endpoint, derived from the Pydantic models with$defshoisted intocomponents/schemas. Wired intocommand_catalog,generated_surfaces, and thereforedevtools render-all/--check.devtools/render_cli_output_schemas.py:SearchEnvelopepublished asdocs/schemas/cli-output/search-envelope.schema.jsonalongside the existing per-hit schema (reuses the feat(cli): output-assurance contract — stable JSON schemas + snapshot gate per command family (#958 slice B) #1272 pattern from PR feat(cli): output assurance contract + JSON schemas + NDJSON streaming (#1272) #1340).tests/unit/surfaces/test_search_envelope_contract.py: cross-surface contract test that runs the same query through the Python helper, the MCP helper, and the CLI formatter and asserts the envelope-level metadata (limit, offset, query, retrieval_lane, ranking_policy, ranking_policy_version, hit ranks, hit lanes, hit conversation IDs) matches across all three. Also pins theSearchEnvelopefield set and verifies the OpenAPI schema is committed.The legacy
MCPPaginatedSearchResultPayloadexport is retained as an alias so external imports keep working through the transition.Verification
Cross-surface equivalence is verified by
tests/unit/surfaces/test_search_envelope_contract.py::test_all_surfaces_emit_semantically_equivalent_envelope. The OpenAPI schema renders cleanly andtests/unit/surfaces/test_search_envelope_contract.py::test_openapi_schema_is_present_and_well_formedensures it stays committed and referencesSearchEnvelope.Follow-ups
This is the slice-A foundation. Slices B–E under #873 (lane-rank contribution preservation in hybrid RRF, cursor-based stable pagination wiring at the query plan level, scoped facets, surface convergence of the two
ConversationSearchHitmodels) build on this envelope.