Repository navigation
fix(cli): stop KeyError('rank') in transcript view after keyword find - #3178
Conversation
Problem: `find QUERY then read --view transcript` (and the shared
summary/transcript/dialogue query-set renderer generally) crashed with
`KeyError: 'rank'` whenever a daemon was reachable and the query was a
keyword FTS search rather than an exact session ref -- reproducible with
exactly one matching session, no disambiguation involved (polylogue-ajmu).
Solution: the daemon's `_archive_search_hit_payload` (daemon/http.py) put
`rank` as a top-level sibling of `session`/`match` in its search-hit JSON.
Every other producer of this shape -- the direct in-process CLI path
(`archive_query.py::_hit_payload`) and the MCP surface
(`mcp/archive_support.py::archive_search_hit_payload`) -- builds the typed
`SessionSearchHitPayload`/`SessionSearchMatchPayload` contract, which
declares `rank` as a required field of `match`, not of the top-level hit.
Both consumers of the rendered dict already expect it there: the CLI's
text renderer `_hit_line` (`match['rank']`, no `.get` fallback -- the
crash site) and the webui's `_render_search_hit` (`match.get("rank")`,
which silently swallowed the same divergence instead of crashing). The
fix moves `rank` into `match` in the daemon's hand-built payload so all
four producers/consumers agree on one shape, rather than adding a
defensive `.get()` at the CLI crash site.
Origin-independence: the divergence lives entirely in the daemon's wire
payload construction, unrelated to any provider/origin parsing, so it
reproduces for every origin whose keyword search goes through the daemon
(verified against both a hermes-session fixture and a chatgpt-export
fixture). Surface scope: `read --view messages`/`raw` never resolve
through the search-hit renderer (`accepts_query_set=False` forces an
upfront single-session resolution before rendering), so they were never
exposed to this shape; `summary`/`transcript`/`dialogue` share the same
query-set renderer and were all affected.
Verification:
- `devtools test polylogue/daemon/http.py tests/unit/cli/test_daemon_golden_parity.py tests/unit/daemon/test_web_reader.py tests/unit/cli/test_archive_query.py`
-> 280 passed, 1 failed (`test_operational_web_payloads_redact_configured_archive_paths`,
confirmed pre-existing/unrelated: reproduces identically on a clean
`origin/master` worktree with none of this change's files touched).
- Anti-vacuity: reverting the `http.py` hunk reproduces
`<Result KeyError('rank')>` in the new CLI e2e test and the top-level
`"rank"` assertion failure in the new daemon-payload test.
- `devtools verify --quick` -> exit_code 0 (16/16 checks green).
Ref polylogue-ajmu
Co-Authored-By: Claude <[email protected]>
|
Warning Review limit reached
Next review available in: 53 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (3)
✨ 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 |
) Ref polylogue-93cp demo program (runbook category A). ## Summary Refreshes the deterministic basic-usage walkthrough artifacts against current master — first refresh since #3178 (transcript crash fix), #3179 (import parity), #3182 (all-origins seeding) landed. ## Problem Committed walkthrough outputs predated three merged changes that alter demo-visible behavior: corpus grew 16→19 sessions / 62→71 messages across 8 origins, index schema v40→v42, embeddings v3→v4, and the MCP surface consolidation (#3056) renamed the tools the MCP walkthrough exercises. ## Solution Re-ran every walkthrough recorded command against a fresh scratch seed: 1-4 (find/read/search/resume) byte-identical — surface stability demonstrated; 5/8 (cost, status/debt) refreshed with expected corpus-growth deltas; 7 (MCP round-trip) refactored onto the query/read dispatchers preserving the search→summary pattern; README stamp + schema refs updated. Cold-reader gate re-answered from directory contents alone. Produced by a Haiku lane; branch harvested by coordinator. ## Verification Each walkthrough re-executed against a fresh `polylogue demo seed` in a scratch root; diffs classified per-artifact (table in lane report); `devtools verify --quick` 16/16 green. Co-authored-by: Claude <[email protected]>
Summary
find QUERY then read --view transcriptcrashed withKeyError: 'rank'whenever a daemon was reachable and the query was a keyword FTS search rather than an exact session ref, even with exactly one matching session. Fixed the underlying wire-shape divergence in the daemon's search-hit payload.Problem
Repro (per polylogue-ajmu): import
tests/fixtures/hermes/atif/nemo_relay_atif_v1.7_real_redacted.jsoninto a scratch archive, then run:This raised
Error: unexpected error: KeyError: 'rank'. The same session read fine via an exact ref (find id:hermes-session:...) instead of a keyword query.Root cause: three producers build the same "search hit" wire shape (
session+matchevidence), but only two of them agree. The direct in-process CLI path (archive_query.py::_hit_payload) and the MCP surface (mcp/archive_support.py::archive_search_hit_payload) both build the typedSessionSearchHitPayload/SessionSearchMatchPayloadcontract, which declaresrank: intas a required field ofmatch. The daemon's hand-built HTTP payload (daemon/http.py::_archive_search_hit_payload) instead putrankas a top-level sibling ofsession/match.Both consumers of the rendered dict already expect
rankinsidematch: the CLI's plain-text renderer_hit_line(cli/archive_query.py,match['rank'], no.getfallback — the crash site) and the daemon webui's_render_search_hit(daemon/webui.py,match.get("rank"), which silently swallowed the same divergence instead of crashing — a masked instance of the same bug).docs/search.md's documented hit-evidence contract also placesrankundermatch.This is entirely origin-independent — the divergence lives purely in the daemon's wire payload construction, unrelated to any provider/origin parsing. Verified with both a
hermes-sessionfixture and achatgpt-exportfixture.Surface scope:
read --view messages/rawnever resolve through the search-hit renderer at all (accepts_query_set=Falsefor those views forces an upfront single-session resolution before any rendering happens), so they were never exposed to this shape.summary,transcript, anddialogueshare the same query-set renderer (run_read_summary_or_transcript) and were all affected — including plainreadwith no--viewflag at all, sincesummaryis the default view.Solution
Moved
rankfrom the top level into the nestedmatchdict inpolylogue/daemon/http.py::DaemonAPIHandler._archive_search_hit_payload, so all four producers/consumers of this shape agree, rather than adding a defensive.get()at the CLI crash site.Verification
devtools test polylogue/daemon/http.py tests/unit/cli/test_daemon_golden_parity.py tests/unit/daemon/test_web_reader.py tests/unit/cli/test_archive_query.py→ 280 passed, 1 failed. The 1 failure (test_operational_web_payloads_redact_configured_archive_paths) is confirmed pre-existing and unrelated — it reproduces identically on a cleanorigin/masterworktree with none of this change's files present (a real-daemonindex.dbdeletion mid-test surfaces an unhandledsqlite3.OperationalErroras an HTTP 500, unrelated to search-hit shape).http.pyhunk reproduces<Result KeyError('rank')>in the new CLI end-to-end test (test_find_then_read_transcript_survives_daemon_proxied_keyword_search) and the top-level"rank"assertion failure in the new daemon-payload test (test_search_hit_rank_lives_under_match_not_top_level).devtools verify --quick→ exit_code 0 (16/16 checks green), and again ongit pushvia the pre-push hook.Ref polylogue-ajmu
Co-Authored-By: Claude [email protected]