Skip to content

fix(cli): route read --to browser through existing delivery contract - #3504

Merged
Sinity merged 2 commits into
masterfrom
fix/cli/read-view-browser-destination
Aug 1, 2026
Merged

Sinity merged 2 commits into
masterfrom
fix/cli/read-view-browser-destination

Conversation

@Sinity

@Sinity Sinity commented Aug 1, 2026 •

Copy link
Copy Markdown
Owner

Summary

polylogue find QUERY read --to browser silently printed rows to the terminal instead of opening a browser. Fixed by routing both affected dispatch sites through the existing browser-delivery mechanism (query_output.py's destination.kind == "browser" path) instead of building a second implementation, and by making the previously-silent else fallthrough raise on a genuinely unrecognized destination.

Problem

_READ_DESTINATIONS (polylogue/cli/query_verbs.py:215) accepts "browser" as a valid --to value, and browser delivery IS implemented -- but on a path (query_output.py:291, deliver_query_output's destination.kind == "browser" branch) that two other dispatch sites never adopted:

  • run_read_summary_or_transcript (polylogue/cli/read_views/standard.py) -- the handler for the default summary/transcript views, which read_verb force-routes every --to browser invocation through (query_verbs.py:1282-1296).
  • deliver_content (polylogue/cli/read_views/base.py) -- used by the dialogue/temporal/context/neighbors/messages/events/file-edits/chronicle read views.

Both had a string-comparison if/elif chain with a silent else that fell through to plain stdout echo for any destination the chain didn't explicitly handle -- including the valid-but-unwired "browser".

Reproduced against a demo archive before fixing:

$ POLYLOGUE_ARCHIVE_ROOT=/realm/tmp/pl-bvnz-repro polylogue demo seed --root /realm/tmp/pl-bvnz-repro
$ POLYLOGUE_ARCHIVE_ROOT=/realm/tmp/pl-bvnz-repro polylogue find "demo" read --first --to browser
1. codex-session  Map the demo lineage base context. ...
2. gemini-cli-session  demo-gemini-cli · demo/gemini_cli_fixture.py · 2 msgs ...
... (11 rows printed to terminal, no browser opened, no warning, exit 0)

Solution

  • run_read_summary_or_transcript (standard.py): added an elif invocation.destination == "browser": branch that sets output="browser" on the query request before delegating to execute_query_request -- the same param QueryOutputSpec.from_params/deliver_query_output (query_output.py) already resolve to open_in_browser, i.e. the identical contract find QUERY --to browser (without read) already uses. No second implementation.
  • deliver_content (base.py): added an elif destination == "browser": branch calling query_output.open_in_browser directly. Added optional output_format: str = "markdown" and session: Session | None = None params (backward compatible for the other 8 existing call sites) so callers holding a Session (dialogue) can render richer HTML.
  • Both functions' former silent else (click.echo(content, nl=False) / execute_query_request(env, updated)) now raise click.UsageError(...) for a genuinely unrecognized destination. _READ_DESTINATIONS's valid set (terminal/stdout/browser/clipboard/file) is unchanged -- this branch is defensive since Click's Choice already constrains the CLI-facing value, but it closes the exact hole that let "browser" degrade silently for months.

Verification

  • Reproduced pre-fix (see Problem section) and confirmed post-fix: same invocation now prints Opened in browser: /realm/tmp/tmpXXXXXX.html, exit 0.
  • Spot-checked --to stdout/clipboard/file against the same demo archive: unchanged behavior.
  • python -m devtools test tests/unit/cli/test_query_verbs_runtime.py -- 62 passed, including 4 new tests:
    • test_read_verb_summary_browser_destination_routes_through_query_output_delivery -- asserts read_verb with destination="browser" calls execute_query_request with output="browser" in the request params.
    • test_read_verb_summary_unrecognized_destination_raises -- asserts run_read_summary_or_transcript raises click.UsageError for a bogus destination.
    • test_deliver_content_browser_destination_opens_browser -- asserts deliver_content calls query_output.open_in_browser(env, content, output_format, session) for destination="browser".
    • test_deliver_content_unrecognized_destination_raises -- asserts deliver_content raises click.UsageError for a bogus destination.
  • python -m devtools verify --quick -- exit 0 (ran twice: once manually, once via the pre-push hook).

AC matrix (polylogue-bvnz)

Criterion Status
Reproduce the bug against a demo archive before fixing Satisfied -- see Problem section
Fix both dispatch sites (base.py deliver_content, standard.py run_read_summary_or_transcript) Satisfied
Route through the EXISTING browser-delivery mechanism, not a second implementation Satisfied -- both branches call into query_output.open_in_browser/deliver_query_output, no new browser-opening code was written
Make the fallthrough else raise on unrecognized destination Satisfied -- both functions now raise click.UsageError
Do not change _READ_DESTINATIONS's valid set Satisfied -- query_verbs.py:215 untouched

Anti-vacuity

Production callers exercised: read_verb (query_verbs.py) dispatching into run_read_summary_or_transcript (read_views/standard.py), and deliver_content (read_views/base.py) directly. Removing either function's elif destination == "browser": branch (or its output="browser" param update in standard.py) makes the corresponding new test fail, since execute_query_request/open_in_browser would then not be called with the browser-routing arguments -- reverting to the silent-echo fallthrough this PR fixes.

Ref polylogue-bvnz

Summary by CodeRabbit

  • New Features

    • Added browser delivery for standard, dialogue, temporal, and summary reads.
    • Output formatting and session context are now preserved when delivering content.
  • Bug Fixes

    • Unsupported output destinations now show a clear usage error instead of defaulting to terminal output.
  • Tests

    • Added coverage for browser delivery and invalid destination handling.

Problem: `polylogue find "demo" read --first --to browser` silently
printed session rows to the terminal instead of opening a browser, with
no warning at all. `_READ_DESTINATIONS` (query_verbs.py) accepts
"browser" as a valid --to value, and browser delivery IS implemented --
but on a separate path (query_output.py's
`destination.kind == "browser"` branch in `deliver_query_output`) that
two other dispatch sites never adopted:

  - `run_read_summary_or_transcript` (read_views/standard.py), the
    handler for the default "summary"/"transcript" views, which
    query_verbs.py's read_verb force-routes every `--to browser`
    invocation through (query_verbs.py:1282-1296).
  - `deliver_content` (read_views/base.py), used by dialogue/temporal/
    context/neighbors/messages/events/file-edits/chronicle views.

Both had a string-comparison if/elif chain with a silent `else` that
fell through to plain stdout echo for any unhandled destination,
including the valid-but-unwired "browser" -- exactly the kind of gap a
loud failure would have caught immediately.

Solution: add a "browser" branch to both dispatch sites, routing
through the existing browser-delivery mechanism rather than building a
second implementation:

  - `run_read_summary_or_transcript` now sets `output="browser"` on the
    query request, which `QueryOutputSpec`/`deliver_query_output`
    (query_output.py) already resolve to `open_in_browser` -- the same
    contract `find QUERY --to browser` (without `read`) uses.
  - `deliver_content` now calls `query_output.open_in_browser` directly,
    with new optional `output_format`/`session` params (default
    "markdown"/None) so callers that have a `Session` (e.g. dialogue)
    can render richer HTML.

The former silent `else` in both functions now raises
`click.UsageError` on a genuinely unrecognized destination instead of
degrading to terminal output -- the silent fallthrough is what let this
bug hide. `_READ_DESTINATIONS`' valid set is unchanged.

Verification:
  - Reproduced pre-fix: `POLYLOGUE_ARCHIVE_ROOT=/realm/tmp/pl-bvnz-repro
    polylogue demo seed --root ...` then
    `polylogue find "demo" read --first --to browser` printed 11 result
    rows to the terminal, no browser opened, no warning, exit 0.
  - Confirmed post-fix: same invocation prints
    "Opened in browser: /realm/tmp/tmpXXXXXX.html", exit 0. `--to
    stdout`/`clipboard`/`file` behavior unchanged (spot-checked all
    three against the demo archive).
  - `python -m devtools test tests/unit/cli/test_query_verbs_runtime.py`
    -- 62 passed (4 new: browser-destination routing +
    unrecognized-destination raise, at both the read_verb level and the
    deliver_content unit level).
  - `python -m devtools verify --quick` -- exit 0.

Anti-vacuity: the production callers exercised are `read_verb`
(query_verbs.py) dispatching into `run_read_summary_or_transcript`
(read_views/standard.py), and `deliver_content` (read_views/base.py)
directly. Removing either function's `elif destination == "browser":`
branch (or its `output="browser"` param update) makes the corresponding
new test fail, since `execute_query_request`/`open_in_browser` would
then not be called with the browser-routing arguments.

Ref polylogue-bvnz

Co-Authored-By: Claude <[email protected]>
@coderabbitai

coderabbitai Bot commented Aug 1, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

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

Next review available in: 48 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 Plus

Run ID: 43c1a9f2-0f7d-4194-ba65-7ee72b5abfe8

📥 Commits

Reviewing files that changed from the base of the PR and between 5254853 and fa2fc0e.

📒 Files selected for processing (2)
  • polylogue/cli/read_views/standard.py
  • tests/unit/cli/test_query_verbs_runtime.py
📝 Walkthrough

Walkthrough

Read output delivery now supports browser targets, propagates output format and session data, and rejects unsupported destinations. Standard and summary reads route browser requests explicitly. Runtime tests cover these paths.

Changes

Read output routing

Layer / File(s) Summary
Shared delivery contract
polylogue/cli/read_views/base.py
deliver_content accepts output format and session data. Browser destinations use open_in_browser; unsupported destinations raise click.UsageError.
Standard read routing and validation
polylogue/cli/read_views/standard.py, tests/unit/cli/test_query_verbs_runtime.py
Standard, dialogue, temporal, and summary reads pass browser and rendering metadata through the output path. Tests cover browser routing and invalid destinations.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant StandardRead
  participant execute_query_request
  participant query_output.open_in_browser
  StandardRead->>execute_query_request: request output="browser"
  execute_query_request->>query_output.open_in_browser: deliver rendered content
  query_output.open_in_browser-->>StandardRead: browser delivery result
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers the summary, problem, solution, verification, and risks, but omits the required changelog entry for this user-visible output change. Add a Changelog section with a one-line entry under the Unreleased section of CHANGELOG.md.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the CLI browser-routing fix for read output.
Docstring Coverage ✅ Passed Docstring coverage is 87.50% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/cli/read-view-browser-destination

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@polylogue/cli/read_views/standard.py`:
- Around line 152-159: Update the browser delivery path in the call to
deliver_content so dialogue sessions are first transformed with
_window_dialogue_session using the requested projection before being passed for
HTML rendering, ensuring read --to browser honors projection_spec. Add a
regression test covering a browser dialogue read with projection_spec.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 0a67eea2-6b20-4857-ad3c-c8402d82bd17

📥 Commits

Reviewing files that changed from the base of the PR and between 753fd9e and 5254853.

📒 Files selected for processing (3)
  • polylogue/cli/read_views/base.py
  • polylogue/cli/read_views/standard.py
  • tests/unit/cli/test_query_verbs_runtime.py

Comment thread polylogue/cli/read_views/standard.py Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 52548535ae

ℹ️ 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".

# missing and fell through to the plain-stdout `else`, so
# `read --to browser` silently printed to the terminal
# (polylogue-bvnz).
execute_query_request(env, updated.with_param_updates(output="browser"))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve the resolved first match for browser reads

When a broad query uses read --first --to browser, read_verb has already resolved the first match and placed its ID in invocation.session_id, but this branch executes the original multi-match request unchanged because _request_for_standard_read() only applies conv_id for exact-reference queries. Consequently, the browser contains the whole result list—the reproduced find "demo" read --first --to browser case still renders all 11 matches rather than the selected first session. Apply the resolved session ID (or otherwise constrain the request) when --first produced it before browser delivery.

Useful? React with 👍 / 👎.

…reads

Problem: CodeRabbit review on #3504 found that open_in_browser()
re-derives HTML from the raw session for non-html output formats
(the common markdown case) instead of using the already-rendered
content string. run_read_dialogue passed the un-windowed session
through, so `read --view dialogue --to browser` combined with a
projection/window (--max-tokens, a body_limit/offset) silently
showed the FULL dialogue in the browser, ignoring the requested
window.

What changed: run_read_dialogue now computes windowed_session via
the same _window_dialogue_session(session, projection) call
_format_dialogue_session already uses internally, and passes that
to deliver_content instead of the raw session.

Verification: new regression test
test_dialogue_read_view_browser_destination_honors_projection_window
asserts the delivered session has exactly 1 message under a
body_limit=1 projection (was 4). Anti-vacuity: reverted the fix,
confirmed the new test fails (delivered session had 4 messages, not
1); restored, confirmed 63 passed (was 62). devtools verify --quick
exit 0.

Co-Authored-By: Claude <[email protected]>
@Sinity
Sinity merged commit a7001a1 into master Aug 1, 2026
3 checks passed
@Sinity
Sinity deleted the fix/cli/read-view-browser-destination branch August 1, 2026 14:39
Sinity added a commit that referenced this pull request Aug 1, 2026
…jtc, bvnz, 5vbs)

Reconciliation pass driven by devtools lab probe bead-pr-reconciliation:
verified each bead's own acceptance criteria against the actual diff/AC
matrix of its referencing merged PR(s), not just the PR's self-description.

Closed (AC fully satisfied):
- polylogue-bvnz: PR #3504, all 5 AC items satisfied.
- polylogue-5vbs: PR #3439, AC's detection/repair branch satisfied via new
  daemon/fts_orphan_audit.py sweep.

Left open with progress notes (partial, residual scope named):
- polylogue-layg.1: PR #3486 satisfies 6/8 AC items; scale fixture + coverage
  manifest update still missing.
- polylogue-hjpx: PR #3485 confirms AC1-5 satisfied (mostly by pre-existing
  landed work whose ancestry the bead's own stale note had missed), but
  bd close refuses on open child polylogue-yla8 (the live closure-gate audit
  AC1-5 doesn't substitute for).
- polylogue-6j9c, polylogue-9kjtc: PR #3511 satisfies 2/3 AC items each;
  live-archive reprice pass over existing session_profiles rows still
  outstanding for both.

Ref polylogue-93xe

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