Skip to content

Render every CLI query row through one operation-shaped seam - #5156

Merged
Sinity merged 1 commit into
masterfrom
cli-s4-render-seam
Sep 14, 2026
Merged

Sinity merged 1 commit into
masterfrom
cli-s4-render-seam

Conversation

@Sinity

@Sinity Sinity commented Sep 14, 2026

Copy link
Copy Markdown
Owner

Summary

Lands Seam B of the CLI unification design (cli-unification-design.md §2.1, step S4) as polylogue/cli/render/: one row renderer over declared operation results, one owner of the terminal exit code, and the deletion of the client-side row translation layer S3 left standing.

Problem

After S3 (#5152) every root read is a declared operation, but the CLI still carried a second idea of what a session row is:

  • archive_query._normalize_daemon_list_item + _DAEMON_LIST_ITEM_KEEP_KEYS reshaped every operation row into a CLI row. Its word_count → words fallback was already dead (both sides build SessionListEnvelope), leaving a keep-key table as the only remaining difference — a second declaration of the row vocabulary, on the wrong side of the boundary.
  • _emit_daemon_list_payload / _emit_daemon_search_payload re-derived total, limit, next_offset and, when absent, the terminal outcome, duplicating facts the operation had already reported.
  • _emit_degraded_daemon_search_payload ended with raise SystemExit(OUTCOME_EXIT_CODES["degraded"]), and _emit_open_no_results with emit(exit_code=OUTCOME_EXIT_CODES["empty"]) — two surfaces choosing an exit status by name instead of from the outcome, which is exactly how a degraded zero-row page can be reported as empty.
  • No-results feedback had three owners: archive_query._emit_no_results (envelope-driven), cli/query_feedback.py (spec-driven) and cli/convergence_feedback.py (the warning both printed).
  • query_output.py carried six functions with zero production consumers, and they were the only thing keeping cli/query_stats.py and cli/query_semantic.py reachable.

Solution

polylogue/cli/render/rows.py — one row renderer. emit_session_list_page and emit_session_search_page (which absorbs the degraded and empty forms) render the operation's page verbatim: total, limit, total_unit, next_cursor and outcome are read, never re-derived. emit_rows, project_payload, selected_fields, csv_text, summary_line_renderer, hit_line and stats_by_line relocate here, along with the render-phase timing ContextVar.

The operation row is the CLI row. The row vocabulary is declared once, in operations/daemon_reads._SESSION_LIST_ROW_FIELDS, at the boundary that builds the row. SessionListEnvelope's remaining three fields (title_source, title_ref, cost_provenance) describe how a title or cost was derived — reader-surface provenance affordances that no CLI format has ever printed — so they are projected out where the row is made rather than filtered out where it is rendered. daemon_reads.py is OUT of the derived-schema closure, so this does not move the identity.

polylogue/cli/render/outcome.py — one exit-code authority. Absorbs _emit_no_results (as emit_empty_page) and all of cli/query_feedback.py. exit_for(outcome) is the only exit path, EMPTY_EXIT_CODE is derived from outcome_exit_code(decide_outcome(matched=0)) rather than named, and both previous by-name lookups are gone. A daemon-supplied outcome is still preserved verbatim.

cli/convergence_feedback.py is not folded in, deliberately: the probe imports storage.archive_readiness, which is precisely the substrate import the Seam B rule (design §2.2) forbids a renderer. Moving it made gate layering go red on a new unbaselined edge — the gate correctly refusing the shortcut. render/outcome.py renders the warning; the probe keeps producing it. Its real home is behind the status operation, which already reports component_readiness.raw_materialization (residual below).

Deletions. The four _emit_daemon_* functions, _normalize_daemon_list_item, _DAEMON_LIST_ITEM_KEEP_KEYS, cli/query_feedback.py, cli/query_stats.py, cli/query_semantic.py, and the query_output.py functions the design named. Five of the six had zero consumers anywhere. The sixth, summary_to_dict, has an in-module caller (format_summary_list) the design's grep missed, so its export is deleted and it becomes _summary_to_dict. tests/unit/cli/test_query_stats.py goes with the module it certified; test_query_fmt.py loses the _format_list/_write_message_streaming cases; test_query_exec_laws.py's semantic-parity test is rewritten to assert the surviving substrate law (matches_referenced_path across a session's actions) now that the Python re-derivation it was paired against is gone.

Golden bytes

scripts/golden_find_bytes.py — 37 documented find invocations, 0 differing.

S3's warning is that the documented aggregate examples land on empty selections, so a companion harness over the same immutable cli-mixed workload and frozen clock exercises 22 hand-picked non-empty cases (list in all five formats, --limit/--offset pages, --fields projection, analyze count, analyze by origin, analyze by day, ranked search in text/json/csv, --origin filter, --sort/--reverse, a messages where unit query, --sample, with messages projection; 17 exit 0 with rows). 22 cases, 0 differing once run_id/generation_id/archive_epoch — which vary per harness run on master too — are normalized.

Layering

devtools gate layering: 273 baseline entries before, 273 after (230 matched, 43 stale), 0 violations. S4 removes no baseline entry: query_output.py -> storage.runtime survives on the still-live render_stream_* signatures, and the deleted modules had no entries. The one edge S4 would have added (render/outcome.py -> storage.archive_readiness) was resolved by not moving the probe, not by baselining it.

Verification

devtools test tests/unit/cli/test_json_envelope_contract.py tests/unit/cli/test_query_fmt.py \
              tests/unit/cli/test_plain_cli_snapshots.py tests/unit/cli/test_machine_contract.py
  devtools test: FAILED exit=1 diagnosis=pytest_failed

Four failures, all inherited, all in test_plain_cli_snapshots.py: test_json_read_all_snapshot, test_json_analyze_snapshot, test_json_status_snapshot, test_facets_command_json_matches_analyze_facets. The identical four fail on master at this worktree's base (devtools test tests/unit/cli/test_plain_cli_snapshots.py, receipt 20260914T201951Z). Every other test in the selection passes, and no test moves between the two runs.

S4 does not re-record those snapshots. The renderer work produces byte-identical output on 59 verified invocations, so these snapshots are stale for reasons outside this change (three long-standing, one from #5146 adding to_dict() fields); re-recording them here would fold an unrelated fix into a refactor whose whole claim is that nothing changed.

devtools verify --quick   → exit 0, all 17 gates ok
devtools gate layering    → exit 0, 0 violations, 273 baseline entries
devtools render all --check → exit 0, grep "out of sync": 0 hits
devtools gate mypy        → Success: no issues found in 2866 source files

Closure

devtools schema closure ...
  out  polylogue/cli/archive_query.py
  out  polylogue/cli/query_output.py
  out  polylogue/cli/render/__init__.py
  out  polylogue/cli/render/outcome.py
  out  polylogue/cli/render/rows.py
  out  polylogue/cli/convergence_feedback.py
  out  polylogue/operations/daemon_reads.py

Every touched file is OUT. This PR does not move the derived schema identity and does not gate a rebuild.

That is a deliberate choice about the two fixes S1 applied at the operation boundary rather than at their natural homes, which S3 recorded as S4 work:

  1. daemon_reads._session_list_row re-spells the archive's ...Z timestamps over the ...+00:00 that session_list_envelope_from_summary produces. Natural home: surfaces/payloads.py (IN).
  2. cli/lowering._selection_params imports _RECOGNIZED_PARAMS under its private name because a public alias would move the identity. Natural home: archive/query/spec.py (IN).

Neither is moved. Both are cosmetic — a timestamp spelling and an underscore — and moving either forces a full archive reconvergence for a CLI-only refactor. The comments at both sites still name the correct home, so whichever closure-moving change lands next can carry them for free.

Residuals

  • cli/convergence_feedback.py remains a substrate read reachable from a render path. The status operation already reports the same readiness; a CLI read consuming it would retire the probe.
  • Most of the rest of query_output.py (format_summary_list, output_summary_list, output_search_hits, format_search_envelope, render_stream_*, no_results, open_result) also has no production consumer, only tests. That is S12's census, not S4's: several carry real format laws whose surviving owner has to be named first.
  • archive_query.py's remaining renderers (_session_text, _emit_session_result, _emit_stream, the _*_query_line family) have not moved into render/; they go with S5's deletion of the module.
  • The design's D4 claim that the operation row uses word_count is stale at this head — both sides build SessionListEnvelope, which spells it words. The only real divergence was the keep-key table, which this PR resolves in the operation's favour.

🤖 Generated with Claude Code

https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK

The root query surface carried two session-row shapes for one query. The
`cli.query` operation returned a `SessionListRowPayload` document and the CLI
carried its own idea of a row, bridged by `_normalize_daemon_list_item` plus a
hand-maintained keep-key table; `_emit_daemon_list_payload`,
`_emit_daemon_search_payload` and `_emit_degraded_daemon_search_payload`
re-derived envelope fields the operation had already decided, and the degraded
page picked its exit status straight out of `OUTCOME_EXIT_CODES` rather than
from the outcome the operation reported.

Seam B lands as `polylogue/cli/render/`. `rows.py` owns one row renderer over
operation rows: `emit_session_list_page` and `emit_session_search_page` render
what they are handed, and the row vocabulary is now declared once where the row
is built (`daemon_reads._SESSION_LIST_ROW_FIELDS`), so the operation row is the
CLI row and the client-side translation is gone. `outcome.py` absorbs
`_emit_no_results` and `cli/query_feedback.py`, and every terminal exit is
computed only by `outcome_exit_code` — including the degraded search page and
the open-no-results refusal, which each named a status directly before.

`cli/convergence_feedback.py` deliberately stays outside `render/`: the probe
reads `storage.archive_readiness`, which is exactly the substrate import the
Seam B rule forbids a renderer. `render/outcome.py` renders its warning; the
probe keeps producing it until a CLI read consumes the `status` operation's
`component_readiness.raw_materialization` instead.

Deletes the six `query_output.py` functions with no production consumer
(`format_list`, `render_session_rich`, `sessions_to_csv`, `output_results`,
`write_message_streaming`, and the public export of `summary_to_dict`, whose
sole caller is in-module and is now private), and with them the last consumers
of `cli/query_stats.py` and `cli/query_semantic.py`, which were reachable only
through those re-exports and their own tests.

Golden bytes: the 37 documented `find` invocations and 22 hand-picked
non-empty list/search/aggregate/projection invocations are byte-identical
before and after.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented Sep 14, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 59 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: fa1c851e-c9e9-46ba-bd85-b2f44aaca74e

📥 Commits

Reviewing files that changed from the base of the PR and between 890a292 and c9847d9.

📒 Files selected for processing (14)
  • polylogue/cli/archive_query.py
  • polylogue/cli/query_feedback.py
  • polylogue/cli/query_output.py
  • polylogue/cli/query_semantic.py
  • polylogue/cli/query_stats.py
  • polylogue/cli/render/__init__.py
  • polylogue/cli/render/outcome.py
  • polylogue/cli/render/rows.py
  • polylogue/operations/daemon_reads.py
  • tests/unit/cli/test_archive_query.py
  • tests/unit/cli/test_query_exec_laws.py
  • tests/unit/cli/test_query_fmt.py
  • tests/unit/cli/test_query_stats.py
  • tests/unit/surfaces/test_terminal_outcomes.py

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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 14, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
🔒 Security Review ✅ Completed 2026-09-14T20:31:14.725035Z c9847d9 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Sinity
Sinity merged commit 10cbf12 into master Sep 14, 2026
3 checks passed
@Sinity
Sinity deleted the cli-s4-render-seam branch September 14, 2026 23:10
Sinity added a commit that referenced this pull request Sep 14, 2026
## Summary

S8 of the CLI unification begins with a judgment call, not a migration:
the
design (§2.3) left the read-view classification open and asked for it to
be
decided "against `structural_query_units()` at S8". This lands that
decision
(D3) as a declaration every view must satisfy, plus the test that keeps
the
table total.

## Problem

`READ_VIEW_HANDLER_METADATA` described *what options a view accepts* but
not
*how the view reaches durable evidence*. Each S8 family would otherwise
have
re-derived that per PR, and the design's own hypothesis was wrong in a
way
that is easy to repeat.

The design guessed that the per-session evidence views whose names
resemble
query units would lower to `query.units` with a `session:` filter.
Checked
against the relations:

- the `observed-event` unit reads the materialized
`query_observed_events`
projection (`archive/query/metadata.py`,
`sql_query_method="query_observed_events"`);
  the `events` view renders `Session.session_events`, the parsed
session-timeline evidence (`api/archive.py:get_session_events`).
Different
  relation, different grain.
- the `file` unit reads affected file *paths* via `query_files`; the
  `file-edits` view renders the structured `file_edits` diffs
  (`api/archive.py:get_file_edits`).
- `hooks` (`hook_events`), `agent-policies` (`session_agent_policies`),
  `web-content` (`web_content_constructs`) and `effective_context` (the
  compaction-aware replay) have no unit descriptor at all —
`structural_query_units()` is `action, assertion, block,
context-snapshot,
  delegation, file, message, observed-event, run`.

## Solution

`ReadViewHandlerMetadata` gains a keyword-only `execution_kind` and the
`operations` it executes through. The decided partition:

| kind | views |
| --- | --- |
| `session-read-projection` | `agent-policies`, `dialogue`,
`effective_context`, `events`, `file-edits`, `hooks`, `messages`, `raw`,
`summary`, `transcript`, `web-content` |
| `query-units-projection` | *(none — declared, unpopulated; see
Problem)* |
| `distinct-operation` | `context`, `context-image`, `lineage`,
`topology` (`context.compile` / `session.lineage` land with S9) |
| `renderer` | `chronicle`, `correlation`, `neighbors`, `temporal` |

`_validate_read_view_classification` runs at import, so a view cannot be
added
with an execution kind that contradicts the operations it names. The
module
stays metadata-only: operation *names* are checked against
`DAEMON_OPERATION_SPECS` in the test, not the module.

No execution path changes in this PR; the eleven `session.read` families
migrate one per candidate on top of this table.

## Golden bytes

`scripts/golden_find_bytes.py` run at `890a2921e` (master) and at this
head:
**37 goldens (13 skipped), byte-identical** (`cmp` clean). Expected —
this is a
declaration-only change.

The non-empty companion cases the brief attributes to S4/S6/S7's author
are
not present on master and not in #5156/#5157/#5158's file lists, so the
documented aggregates are all the harness currently offers. Listed as a
residual.

## Layering

`docs/plans/layering-surface-baseline.json`: **273 entries before, 273
after**
(unchanged — no import added or removed). `devtools gate layering`
passed with
`count=0`, `baselined_count=230`.

## Verification

```
devtools test tests/unit/cli/test_read_view_classification.py \
  tests/unit/cli/test_query_verbs_runtime.py \
  tests/unit/cli/test_query_set_read.py \
  tests/unit/cli/test_messages.py \
  tests/unit/surfaces/test_projection_spec.py
devtools test: PASSED exit=0 diagnosis=pytest_passed

devtools verify --quick        # 15 gates ok
devtools gate layering         # count=0
devtools render all --check    # exit 0, zero "out of sync"
```

Anti-vacuity: the three new tests go red if a read-view profile is added
without a classification, if a row names an operation the protocol does
not
declare, if a `session.read` projection reaches for another operation,
if a
renderer composes nothing, or if any view is moved between kinds —
including
reclassifying one of the per-session evidence views onto `query.units`,
the
hypothesis the relation evidence above refutes.

## Closure

`devtools schema closure` — both touched files report `out`:

- `polylogue/cli/read_view_registry.py` → out
- `tests/unit/cli/test_read_view_classification.py` → out

No rebuild-boundary constraint.

## Residuals

- `query-units-projection` is a declared kind with no members. It is
kept
rather than dropped because the S8 per-family PRs must be able to move a
  view into it if a relation turns out to be unit-expressible; the test
  enforces that such a move names a real grammar unit.
- The four `distinct-operation` rows carry no operation name because
  `session.lineage` and `context.compile` are not declared until S9. The
import-time validator enforces the empty tuple so the rows cannot
quietly
  claim a route they do not have.
- The read parity the design names for S8 (`session.read` across daemon,
direct and the API's `get_session` on the lineage corpus) belongs to the
  first family migration, not to this declaration-only change.
- `correlation` is classified `renderer` over `session.read` per D7; its
local
  `git`/`gh` evidence step is not an operation and is not modelled here.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Sinity added a commit that referenced this pull request Sep 14, 2026
> Stacked on #5160 (the D3 classification). Review that one first; this
PR's
> base will be retargeted to `master` once it merges.

## Summary

The first S8 family migration. The `hooks` read view stops opening an
archive
through the API facade and instead lowers onto `session.read` and
renders what
the operation returns.

## Problem

`read --view hooks` reached durable evidence by opening the `Polylogue`
facade
in-process (`cli/messages.py::run_hooks` →
`api.get_hook_event_summary_for_session`).
That is a second read authority inside a surface, and it is the shape S8
exists
to remove.

Two further consequences at head:

- The view decided its own execution route. Nothing about whether a
daemon was
  resident reached the decision, because there was no dispatch at all.
- A missing session printed `Session not found: <ref>` through
`env.ui.error`
and returned normally. An operator scripting `read --view hooks` could
not
distinguish "this session recorded no hook events" from "this reference
does
  not resolve", because both produced a zero exit and no evidence.

## Solution

`session.read` grows a `kind` discriminator
(`polylogue/operations/read_contracts.py`):

- `transcript` — the message window it already served; unchanged.
- `hooks` — the first per-session evidence relation, read through the
pinned
  reader's `hook_event_summary_for_session` rather than the facade.

Evidence kinds are bounded read models answered whole, so the request
model
refuses a continuation on one and the result model refuses three states
that
would otherwise be expressible: an evidence body on a transcript window,
a
transcript kind with no body, and a `hooks` result that reports itself
partial.
`_WHOLE_EVIDENCE_KINDS` names which kinds that last rule binds, so a
kind that
later genuinely needs paging graduates to the windowed contract instead
of
silently truncating.

`lower_session_read` gains `kind=` and refuses window coordinates
alongside an
evidence kind. `run_read_hooks` becomes lowering + dispatch + render; it
never
opens an archive and never branches on daemon presence — which executor
answers
is the kernel's decision, recorded in the result's own authority. A
refusal is
classed exactly as the transcript path classes its own (`UsageError` for
an
ordinary refusal, `ClickException` for
`daemon_required`/`result_too_large`), so
it exits non-zero naming itself rather than rendering as an empty
summary.

`cli/messages.py::run_hooks` is deleted. `read_views/messages.py`
survives
because `messages` and `raw` still live there; it goes when the last of
its
views migrates.

**Behaviour change, stated plainly:** a missing session under `read
--view hooks`
now exits non-zero with a typed refusal instead of exiting zero after a
notice.
This is the operator's 2026-09-14 ruling applied — a read that could not
be
served must never read as an empty result — and it makes `hooks`
consistent with
the transcript path, which already refuses an unresolvable reference.

## Golden bytes

`scripts/golden_find_bytes.py` at `890a2921e` (master) vs this head:
**37 goldens (13 skipped), byte-identical** (`cmp` clean). The
documented `find`
surface is untouched.

As noted in #5160, the non-empty companion cases the brief attributes to
S4/S6/S7's author are not on master and not in #5156/#5157/#5158's file
lists,
so the documented aggregates are all the harness offers. The three-way
parity
test below is the non-vacuous evidence for this change.

## Layering

`docs/plans/layering-surface-baseline.json`: **273 before, 273 after.**
`devtools gate layering` passed, `count=0`, `baselined_count=230`.

The view now reaches `cli.lowering` + `cli.operation_kernel` instead of
`polylogue.api`, so no baselined surface→substrate edge was added; the
facade edge it drops belongs to `cli/messages.py`, which keeps other
users of
it until `messages`/`raw` migrate.

## Verification

```
devtools test tests/unit/operations/test_read_operation_declarations.py
devtools test: PASSED exit=0 diagnosis=pytest_passed

devtools test tests/unit/operations/test_session_read_parity.py
devtools test: PASSED exit=0 diagnosis=pytest_passed

devtools test tests/unit/cli/test_messages.py tests/unit/cli/test_query_verbs_runtime.py \
  tests/unit/cli/test_query_set_read.py tests/unit/cli/test_read_view_classification.py
devtools test: PASSED exit=0 diagnosis=pytest_passed

devtools verify --quick        # all gates ok
devtools gate layering         # count=0
devtools render all --check    # exit 0, zero "out of sync"
```

**Read parity (the gap the design names for S8).**
`tests/unit/operations/test_session_read_parity.py` runs the same
`session.read`
over three genuinely distinct routes on one seeded archive with hook
events
attached, and compares the bodies:

- the **daemon** route, over the real UDS listener
(`running_daemon_operations`),
  including envelope validation;
- the **direct** route, the in-process handler over a pinned reader;
- the **API** route, `Polylogue.get_hook_event_summary_for_session` —
the facade
  MCP and the Python API already use.

All three agree on the hooks body; a second test holds the transcript
window
across daemon and direct, so the `kind` discriminator is shown not to
have
changed the default read.

**Broad run.** `devtools test tests/unit/cli tests/unit/operations`
reports 9
failures. All 9 were reproduced at `890a2921e` (master):

- 4 × `test_plain_cli_snapshots.py` — the known re-recording owned
elsewhere;
-
`test_interaction_oracles.py::test_completion_script_parses_in_each_installed_real_shell`,

`test_query_expression.py::…test_descriptor_runtime_transform_units_reject_aggregate_pipeline`,
  2 × `test_archive_maintenance_cli.py`, and

`test_mutation_actuators.py::…test_a_session_absent_from_the_index_is_still_tombstoned`
  — confirmed red on master by a separate run at that commit.

Zero regressions attributable to this change.

Anti-vacuity is named per test. The load-bearing ones: answering the
hooks kind
from the transcript branch, letting the daemon and direct routes use
different
readers, relaxing either result validator, or swallowing the refusal and
printing an empty body each turn a test red.

## Closure

`devtools schema closure` — every touched file reports `out`:

- `polylogue/operations/read_contracts.py` → out
- `polylogue/operations/daemon_reads.py` → out
- `polylogue/cli/lowering.py` → out
- `polylogue/cli/read_views/messages.py` → out
- `polylogue/cli/messages.py` → out
- `tests/unit/operations/test_session_read_parity.py` → out
- `tests/unit/operations/test_read_operation_declarations.py` → out
- `tests/unit/cli/test_messages.py` → out

No rebuild-boundary constraint.

## Residuals

- `SessionReadKind` is `{"transcript", "hooks"}`. The other five
evidence
  families (`events`, `file-edits`, `agent-policies`, `web-content`,
`effective_context`) each need a **sync reader on `ArchiveStore` that
does not
exist yet** — only `hook_event_summary_for_session` was already there;
the
rest are async repository methods. That substrate work is what each of
those
  family PRs has to do first, and it is why `hooks` went first.
- `messages` and `raw` still route through `cli/messages.py`, so
  `read_views/messages.py` is not deleted by this PR.
- The API facade's `get_hook_event_summary_for_session` is retained: MCP
and the
Python API are its remaining consumers, and S8 does not own their
migration.
- `hooks` declares no view-specific options, so no option ownership
moved.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Sinity added a commit that referenced this pull request Sep 14, 2026
## Summary

Commits the non-empty golden harness I built for the CLI unification
migration and cited as evidence in #5156, #5157 and #5158, so the next
steps can re-run it instead of re-deriving it. Adds a `TESTING.md`
pointer to both harnesses.

## What gap this closes

`scripts/golden_find_bytes.py` replays every documented `polylogue find`
invocation in `docs/cli-reference.md`. That is the right acceptance
evidence for "the documented surface did not change", and it is weaker
than it looks on its own.

**On the seeded `cli-mixed` corpus, the documented examples that
exercise the interesting code paths land on empty selections.** The
aggregate examples (`analyze count`, `analyze by ...`) and the
`id:`-scoped examples all match nothing. A change can therefore pass
37/37 documented goldens without a single aggregate row, ranked hit,
page boundary or attached-unit projection ever being rendered — so
aggregates, projections, `--sample` and `--latest` need non-empty
coverage before the documented set proves anything about them.

That is not a hypothesis. Measured on this branch, by perturbing the
list envelope to report `"total": 0` on every page:

| harness | invocations | differing |
| --- | --- | --- |
| `golden_find_bytes.py` (documented) | 37 | **0** |
| `golden_nonempty_bytes.py` (this PR) | 22 | 2 |

A regression that zeroes the total on every list page is completely
invisible to the documented set.

## Solution

`scripts/golden_nonempty_bytes.py`, a companion built on the same
machinery — same immutable seeded workload, same frozen clock, same
in-process `Runner`, same recorded shape (exit code + exact
stdout/stderr bytes). The two are one pair.

Its 22 cases are **hand-picked, not extracted**, and that is the point:
the documentation does not contain invocations that return rows, which
is the gap itself. Each case names one thing the documented set leaves
unproven:

- list pages in all five output formats
(`markdown`/`json`/`ndjson`/`csv`/`yaml`) — the row renderer's
per-format branches
- `--limit` and `--limit`+`--offset` — page boundary, `total`,
`next_offset`
- `--fields` — row projection
- `analyze count`, `analyze by origin`, `analyze by day` — aggregate
envelopes with rows in them, text and JSON
- a ranked search in text, JSON and CSV — hit rows, ranks, snippets
- `--origin` — a filter that actually narrows
- `--sort` / `--sort --reverse` — ordering
- `messages where role:assistant` — the unit-row renderer
- `--sample` — the sampling window
- `with messages` — the attached-unit projection fold

17 of the 22 return rows; the rest exercise formats or filters that
legitimately come back empty and still pin their bytes.

The `CASES` tuple is documented as append-only where possible: removing
a case removes coverage, and the keys are the comparison identity.

## Usage

Deliberately the same shape as S3's harness, so a migration step runs
both:

```bash
uv run python scripts/golden_find_bytes.py BEFORE.json
uv run python scripts/golden_nonempty_bytes.py BEFORE-NONEMPTY.json
# ... make the change ...
uv run python scripts/golden_find_bytes.py AFTER.json
uv run python scripts/golden_nonempty_bytes.py AFTER-NONEMPTY.json --compare BEFORE-NONEMPTY.json
```

`--compare` is the one thing the documented harness does not provide,
and it exists because I needed it three times: it exits nonzero when any
case changed and normalizes the three authority fields that vary per run
on an unmodified checkout — `run_id` (a fresh UUID), `generation_id`
(carries the archive clone's inode) and `archive_epoch` (derived from
it). Everything else is compared byte-for-byte. Without that
normalization one case (`find messages where role:assistant --format
json`) reports a false difference on every run.

## Verification

```
uv run python scripts/golden_nonempty_bytes.py A.json
  wrote 22 cases (17 exit 0 with output)

uv run python scripts/golden_nonempty_bytes.py B.json --compare A.json
  22 compared, 0 differing, 0 changed overall        exit=0
```

Anti-vacuity, run as described above: with `"total": 0` forced into the
list envelope, `--compare` reports `22 compared, 2 differing` and
**exits 1**, while the documented harness reports 0 differing across all
37. The perturbation was reverted and the clean compare re-confirmed at
`exit=0` before committing.

```
devtools verify --quick     → exit 0, all 17 gates ok
devtools gate layering      → exit 0, 0 violations, 273 baseline entries (unchanged)
devtools render all --check → exit 0, grep "out of sync": 0 hits
devtools schema closure scripts/golden_nonempty_bytes.py → out
```

No product code is touched: the diff is one new script plus a
`TESTING.md` section. Nothing from #5156/#5157/#5158 is folded in — this
branch is cut from `master` at `890a2921e`.

## Note on discoverability

Neither harness was referenced in any tracked document before this PR.
That is the actual reason the companion was re-derived by hand rather
than re-run: there was nowhere to find it. The new `TESTING.md` section
documents both, states that the pair is not optional, and gives the
`"total": 0` example as the concrete reason.

## Residuals

- The cases are pinned to the `cli-mixed` workload. A workload change
re-bases every golden; that is inherited from the documented harness and
is why both record the workload name in their output.
- `golden_find_bytes.py` still records only — it has no `--compare`, so
its consumers diff by hand. I did not add one here to keep this PR to
the gap the coordinator named; lifting `--compare` into a shared helper
is a reasonable follow-up.
- The companion covers the root query surface only. `read` views,
`continue` and the mutation ceremony have no golden-bytes coverage in
either harness.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Sinity added a commit that referenced this pull request Sep 15, 2026
## Summary

Three pagination tests error before reaching any assertion because a
`patch()` target still names a symbol #5156 deleted. Replaces #5174,
which was closed after #5173 independently landed the product half of
the same fix.

## Evidence

Receipt `.cache/verify/runs/20260914T233651Z-all-207009-89ddea6b`
(`verify_all`, job 1699, 22,540 selected, 29 failed).

**Caveat on that receipt:** its `run.json` records `git_head:
f7964ac` — the tip of branch
`rebase-5165`, *not* `master` and not an ancestor of it — and
`final_git_head: 724d175`. The shared checkout advanced across 7
merged PRs during the run, so it is not evidence of a frozen tree. I
re-ran all 29 node ids at true `master` HEAD: 17 reproduce, 12 do not.
These 3 are among the 17, and still reproduce at `4105e3698`.

## Per-failure classification

| Failure | Classification | Cause |
| --- | --- | --- |
|
`test_archive_query::TestDaemonSearchEnvelopeHonestPagination::test_clamped_page_reports_the_next_offset`
| **stale test** | `patch("polylogue.cli.archive_query._emit_rows")` —
#5156 moved it to `cli/render/rows.py` as public `emit_rows` |
| `…::test_final_page_reports_no_next_offset` | **stale test** | same |
| `…::test_limit_reports_what_the_daemon_applied` | **stale test** |
same |

## Problem

#5156 moved the CLI row renderers out of `archive_query` into
`cli/render/rows.py` and made them public. This file's *imports* were
retargeted at the time; the `patch()` dotted string was not. A patch
target is a string, so nothing failed at collection — instead `mock`
raised `AttributeError` inside the context manager, before any assertion
ran.

`emit_session_search_page` calls `emit_rows` from its own module
namespace, so `polylogue.cli.render.rows.emit_rows` is the seam that
actually intercepts it.

#5173 fixed the other half of this same rename —
`CLI_OPERATION_BINDINGS` still naming
`archive_query:_emit_daemon_list_payload`,
`:_emit_daemon_search_payload` and `:_emit_rows`, none of which
resolved. I had that product fix in #5174; #5173 landed the identical
change first (as `_RENDER_ROWS`), so #5174 was closed as conflicting and
this PR carries only the remaining test half. After it, there is no
reference to `archive_query._emit_rows` left in the tree.

## Solution

One line: patch `polylogue.cli.render.rows.emit_rows`.

## Anti-vacuity

The three tests keep the conditions stated in their own docstrings —
hard-code `next_offset` to `None`, or echo the requested `limit` instead
of the one the daemon applied, and they go red. They could not go red
**for any reason** while the patch target was wrong, since they errored
before the assertions. That is what this restores, and it is why the fix
is worth making rather than deleting the tests: the behaviour they cover
(a daemon-proxied clamped page must not present itself as complete) is
not covered elsewhere — the golden-parity suite seeds a corpus smaller
than its own `--limit` and never reaches a clamped page, as the class
docstring notes.

## Verification

```
devtools test tests/unit/cli/test_archive_query.py tests/unit/operations/test_cli_operation_binding_registry.py
devtools test: PASSED exit=0 diagnosis=pytest_passed receipt=.cache/verify/runs/20260915T015359Z-focused-test-338452-90aec230/run.json
```

The binding registry file is included to confirm #5173's half and this
half agree at the current head.

## Schema closure

`tests/unit/cli/test_archive_query.py` — **out** of the derived
schema-identity closure. Test-only change; no product file touched. Does
not need to land before an archive rebuild.

## Residuals

None. This is the last stale reference to the pre-#5156 renderer names.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK

Co-authored-by: Claude Opus 5 (1M context) <[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