Skip to content

fix(cli): stop KeyError('rank') in transcript view after keyword find - #3178

Merged
Sinity merged 1 commit into
masterfrom
fix/cli/transcript-rank-keyerror
Jul 19, 2026
Merged

Sinity merged 1 commit into
masterfrom
fix/cli/transcript-rank-keyerror

Conversation

@Sinity

@Sinity Sinity commented Jul 19, 2026

Copy link
Copy Markdown
Owner

Summary

find QUERY then read --view transcript crashed with KeyError: '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.json into a scratch archive, then run:

polylogue --origin hermes-session find "hermes" then read --view transcript

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 + match evidence), 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 typed SessionSearchHitPayload/SessionSearchMatchPayload contract, which declares rank: int as a required field of match. The daemon's hand-built HTTP payload (daemon/http.py::_archive_search_hit_payload) instead put rank as a top-level sibling of session/match.

Both consumers of the rendered dict already expect rank inside match: the CLI's plain-text renderer _hit_line (cli/archive_query.py, match['rank'], no .get fallback — 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 places rank under match.

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-session fixture and a chatgpt-export fixture.

Surface scope: read --view messages/raw never resolve through the search-hit renderer at all (accepts_query_set=False for those views forces an upfront single-session resolution before any rendering happens), so they were never exposed to this shape. summary, transcript, and dialogue share the same query-set renderer (run_read_summary_or_transcript) and were all affected — including plain read with no --view flag at all, since summary is the default view.

Solution

Moved rank from the top level into the nested match dict in polylogue/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 clean origin/master worktree with none of this change's files present (a real-daemon index.db deletion mid-test surfaces an unhandled sqlite3.OperationalError as an HTTP 500, unrelated to search-hit shape).
  • Anti-vacuity: reverting the http.py hunk 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 on git push via the pre-push hook.

Ref polylogue-ajmu

Co-Authored-By: Claude [email protected]

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]>
@coderabbitai

coderabbitai Bot commented Jul 19, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@Sinity, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 53 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: e14fd801-5686-4677-b885-581c30198ed3

📥 Commits

Reviewing files that changed from the base of the PR and between 1c0f4ec and 47716e7.

📒 Files selected for processing (3)
  • polylogue/daemon/http.py
  • tests/unit/cli/test_daemon_golden_parity.py
  • tests/unit/daemon/test_web_reader.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/cli/transcript-rank-keyerror

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Sinity
Sinity merged commit 46df563 into master Jul 19, 2026
3 checks passed
@Sinity
Sinity deleted the fix/cli/transcript-rank-keyerror branch July 19, 2026 23:31
Sinity added a commit that referenced this pull request Jul 20, 2026
)

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]>
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.

1 participant