Skip to content

fix: Let the read operation own continuation, totals and failure exits - #5222

Merged
Sinity merged 3 commits into
masterfrom
feat/cli-read-ownership-unit
Sep 18, 2026
Merged

Sinity merged 3 commits into
masterfrom
feat/cli-read-ownership-unit

Conversation

@Sinity

@Sinity Sinity commented Sep 16, 2026

Copy link
Copy Markdown
Owner

Summary

Five CLI read beads. The common defect is a surface deciding something it was
not entitled to decide — inventing a total, re-deriving a continuation, or
mapping every failure onto the empty-result exit code.

Per bead

w3s0q (P0) — a completion walk that stopped after one page. Reproduced at
head: the cli.query list payload carried no next_offset at all, so
session_rows.query_complete_session_ids ended its walk after the first page.
New daemon_reads.page_next_offset decides continuation once for both the list
and ranked payloads. Carried as a sibling field on QueryResult (like
attached_units/total_unit) rather than added to SessionListResponse /
SearchEnvelope, which are in the closure — the same reasoning ijbwq used for
reusing offset. tests/unit/cli/test_complete_selection_pagination.py seeds 7
sessions with the walk page at 3 and proves all 7 ids resolve. The pre-existing
test in test_select.py fed the loop hand-written pages that already carried
next_offset, which is why it never saw this.

jfabc — a fabricated total. _page_envelope did
payload.get("total") or len(rows), so an unknown total silently became the
current page size. A None total now stays null in JSON/YAML, and next_offset
is read from the payload instead of re-derived from the fabricated total. The
bare screen prints the authority the result carries
(query_session_rows_with_authority), not "direct" if daemon_disabled else "daemon".

jtrtj — read failures exited 2. Exit 2 is the empty-result code, so a
transport loss was indistinguishable from an empty scope. render/outcome gains
exit_for_read_failure: 1 for transport/deadline/invalid-request/unavailable,
130 for cancellation, never 2, no usage banner, with call id + deadline_ms +
a remedy line, plus a parseable machine document for --format json (needed
because machine_main re-raises a bare non-zero SystemExit).
OperationFailedError/OperationCancelledError now carry request_id.

ry6g5 — an echo and SystemExit(1) where a typed refusal belongs.
archive_query's missing-index path now raises the same
ArchiveTierUnavailableError the storage layer raises. read --all is
deliberately excluded: browse mode over a nonexistent archive has a correct
empty answer.

dutav — a table that claimed ten session.read projections. Only hooks is
one. test_read_view_execution_routes.py proves each row by dispatching it with
daemon_only=True and comparing recorded kernel operations against the
declaration. The honest state gets a name (in-process) and a shrink-only
ratchet IN_PROCESS_READ_VIEWS. Third mirror found: READ_PRESETS was
hand-written and had lost lineage and effective_context; it is now generated
from archive.viewport.read_view_choices().

Executed mutation

Declared events as a session-read-projection over session.read. 2 of 24 red:

AssertionError: events declares ('session.read',) but reached no operation
  assert ()
AssertionError: declared session.read projections the operation does not serve: {'events'}
  assert {'events', 'hooks'} <= {'hooks', 'transcript'}

Reverted; the registry is byte-identical to the committed version.

Closure

devtools schema closure on all eleven changed product files — all OUT. The
sibling-field design is what kept surfaces/payloads.py untouched. No
pre-rebuild landing-order constraint.

Verification

  • devtools verify --quick → exit 0, every gate ok
  • devtools gate layering → passed, 0 violations
  • devtools test tests/unit/devtools/test_command_catalog.py → passed
    (test_top_level_command_surface_is_the_folded_twelve not weakened)
  • devtools test tests/unit/cli/ tests/integration/test_transcript_window_differential.py tests/unit/archive/query/test_continuation_surface_parity.py
    → exit 1, 15 failed of 3136, all inherited. Proven by checking the tree
    out at e56edbea2 and running the same two files: the same 15 node ids fail.
    13 are stale test_plain_cli_snapshots fixtures showing different seeded
    data; 2 are test_click_app read-views asserting raw's options without
    continuation. Both named integration/parity suites passed.

Residuals

  • vclez is not satisfied, only advanced. Stale-generation, cancellation,
    transport loss and oversized body now reach typed distinct CLI terminals.
    Still open: the summary-half four-surface differential (no equivalent of the
    transcript differential exists for a summary request), typed outcomes for
    active growth / deep transcript anchor / unavailable insight, and criterion
    4's before/after responsibility map. Children vclez.5–.8 unchanged.
  • vbsc0.1 is not satisfied. Its criteria are an architectural rewrite —
    delete archive_query.py's query-execution paths, move CLI-only predicates
    into archive/query/expression.py, which is IN the closure. Its blocking
    dependency dutav is now done, leaving vclez as its only open blocker.
  • The 15 inherited failures are real and pre-existing on master; they need their
    own bead.
  • jtrtj's AC2 names a PTY test; this one is CliRunner-based against the real
    find route — it asserts exit code and banner absence but is not a PTY.
  • Four tests asserted the behavior these beads call wrong and were retargeted,
    not deleted: test_messages ×2 and test_query_exec_laws's vector-backend
    test all asserted click.UsageError (exit 2 for a non-empty condition — the
    exact conflation jtrtj removes), and
    test_documented_query_corpus._assert_typed_outcome pinned exit 2 for every
    non-zero typed terminal. test_archive_query's clamped-page test moved from
    "the renderer computes continuation" to "the renderer reports the operation's
    continuation", with a new sibling proving the renderer never invents one.
  • _execute_directly's locally built invalid_request /
    embedding_retrieval_not_ready envelopes carry no request_id, so those
    refusals name no call id.

Downstream unblocked

dpm6o (P0, all three blockers done), 5vps8 (P0) and i3i5k (P0 epic) via
w3s0q.

🤖 Generated with Claude Code

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 16, 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: 74263362-0b38-4020-a3de-e090f82005dd

📥 Commits

Reviewing files that changed from the base of the PR and between 89618f9 and 20f7114.

📒 Files selected for processing (20)
  • polylogue/cli/archive_query.py
  • polylogue/cli/click_app.py
  • polylogue/cli/operation_kernel.py
  • polylogue/cli/read_view_registry.py
  • polylogue/cli/read_views/messages.py
  • polylogue/cli/render/outcome.py
  • polylogue/cli/render/rows.py
  • polylogue/cli/session_rows.py
  • polylogue/operations/daemon_protocol.py
  • polylogue/operations/daemon_reads.py
  • polylogue/surfaces/read_contract.py
  • tests/unit/cli/test_archive_query.py
  • tests/unit/cli/test_complete_selection_pagination.py
  • tests/unit/cli/test_documented_query_corpus.py
  • tests/unit/cli/test_messages.py
  • tests/unit/cli/test_query_exec_laws.py
  • tests/unit/cli/test_read_failure_exit_codes.py
  • tests/unit/cli/test_read_provenance_and_refusals.py
  • tests/unit/cli/test_read_view_classification.py
  • tests/unit/cli/test_read_view_execution_routes.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 16, 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-16T02:33:44.931457Z 16d4bfd 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 added a commit that referenced this pull request Sep 16, 2026
## Summary

Seventeen worker branches, each resolving a theme of small known-fix
beads, integrated into one candidate: 472 files, +20,406 / −12,166, 80
commits (worker commits plus integration merges and eight cross-branch
reconciliations). Every fixed bead carries one regression test that
names its anti-vacuity condition.

## Problem

The reindex campaign's closure held ~150 open beads whose fix was
already known and small, spread across parsers, storage, daemon,
surfaces, devtools and the test harness. Working them one PR at a time
serialised on review and on the pytest slot. Bead status was stale in
both directions: several dozen were already fixed at head, and a handful
of premises were refuted on inspection.

## Solution

Per theme (branch → beads):

- batch3-identity: ig9tt irtix(1) 3ad8j(1,3) vabba zj8ns t1vl6 prwmd
d9t8u asp4b(6) dhkuu(B) l3zva ddvpi m8yd5; 9193q already at head
- batch3-devtools: uy1a5 7o5zj gcy1 8ykm 1bkl g31s zmlcn wbuf v6xh b1vr1
lafc4 d0kj acsmu hohj7 ga8vn c4a1o rxfo c2qsm t4l2q n6gnd 59qy ww6mj
5pv1p; already at head: b0vbz qai7u e4qyw 8errr v0t3r
- batch3-daemon: ia88n(a) c1dx2 s4tkf 7z8do 7viwp 0ye6q jyzfs uwxir
lbsh9 umca4 ji49p 7mkgv 5a6xc dvhe7 8374p o90gu 3zvsd 9z2gy hprg0 s4135
ho6m7 a03p0 6u8do; pinned at head: lr47v 8ifs 3ahdg f7bf9 liwst
- batch4-harness: xbg9e o733y m3018(code half) 016xl(root cause:
schema-closure import walk memoized on disk, 10.4→4.1 s per process);
already at head: 3z1bj yichs csex1(AC1) ehva4
- batch1-parsers: 8t9bj 6d7fx q5j3o 670mf sfu70 foi1h utv49 4mbya w54q3
1wom1 l0cnu gzxhi; pua53 at head
- batch1-surfaces: o6oct g88v4 xtcdz i6p4x onbz3 vgxkk e9y76 nfr2u 4vjfd
45pkf l9u58 zu08l; at head: kjy0a oil1q m1s98 c0ay0 9qpx4
- batch1-storage: nd2tb lyymm 3sic0(a–e) ebjar nszyu h9xx0 pv8xp wr0oe
lezv0 5qrip lyqzg crcst; at head: bl132 4hys5 gzh7n son7n qczu5
- batch4-ingest: f7pdm dznyt 3ijaa swicx(3/4) m5djs av5j1(2) 9k62p roaof
3r36h; l8tdh at head
- batch4-identity2: s9w0h e2e25 8u1p 3vsoj xnk51 31zag ro922 t37k9 07rfc
sqy57 h92sm khkup 8k10u 56jc6
- B6 excision: 14ucm q4f6d aix14 9lrqs p1naz (+ unrecorded otlp_spans
reach); at head: bhhsa si5kj
- B7 vocabulary: z3sv hjvow bwh3h 7k3n0 exxly j1vs ir1wn grdt
mjupn(part) jglh(part); a2jir at head
- B8 daemon: zbzxs tjtua 5lfcr z5bu7 h8l96 w17k1 oa9w8 (+ duplicate
ISOLATED_TIER_WRITE_PROFILE); iwmt at head
- B9 ingest: 0ck6i zxpgj fkqxx(half) payqy xj7ru v85tn sifoy erf3; at
head: h0nor ip0nq re4es
- B10 CLI/API: 1c6j fawr7 lxdwy t83q(residual) lb15e(part) 01fe(origin
class); at head: 1kavq v1mnm i58iu pd63j qwgi mon2f 395j
- B11 tests/devtools: vwdj zphcj p9evo 6ou1q 7ui0g nlush b7c7m 4ayqx
thqg2 8xvlf(part) + one real daemon saturation red; at head: vl7ra mnkfh
7y23g vhelw f3p8c mhy6z
- B12 security: 97o2z xv0pf n61h5 4fbgw tztk 81v76 1oa7o; xtawb refuted
at head
- B13 campaign: k00uq cois9 xrba4 1ifhp; 4x38n at head

Integration reconciliations (own commits on this branch): the shared
SQLite introspection helper moved to
`polylogue/core/sqlite_introspection.py` (its storage home grew the
surface→substrate ratchet for two daemon modules); the hook-drain cursor
read guards on the carriers table instead of swallowing every
`sqlite3.Error`; the audit `principal_surface` CHECK stays hand-written
(durable DDL is not enum-generated) and is pinned to the literal by
value set; the codex record-skip log is a structured event; `--limit`
refuses non-positive and clamps to the ceiling; the raw-discovery sweep
keeps the held-page cursor inside the arrival/sweep lanes; the prefetch
timeout cancels unstarted, discards finished-unread and attaches the
discard to still-running workers; generated surfaces re-rendered;
writer-module census, schema-closure and degradation baselines refreshed
for the deleted and added modules.

Beads skipped by workers are listed in the worker reports and stay open
with their reason noted; none was closed without a fix at head.

## Closure and rebuild

Dozens of files in this candidate are IN the derived-schema identity
closure (parsers, write.py, archive_tiers specs, core enums/timestamps,
sources, excision). The identity moves; this lands before the fresh
rebuild starts and never during one. Content also changes for ChatGPT
thought summaries, Gemini subagent origin, Codex world_state keys,
Hermes profile keys, Grok session identity (content-derived, message-id
namespace `grok`), tool_path/search_text widening for FTS, and the hash
framing in `_hash_bytes` (length-prefixed) — all pre-wipe by design.

## Verification

- `agentctl job start --workspace /realm/worktrees/polylogue-integ
polylogue verify_quick` → job 2459 **succeeded** (all 21 gates ok)
- `agentctl job start --workspace /realm/worktrees/polylogue-integ
polylogue pytest_focused -- <162 touched test files>` → job 2460: 5,795
passed / 13 failed (all cross-batch interactions, reconciled in
5f123c6 and 2da4406); re-test of the 13 files → jobs 2467+2470
**succeeded** (594 and 89 tests, all passed); quick gate re-run after
reconciliation → job 2471 **succeeded**
- Each worker branch additionally ran its own focused selections and,
for most, `devtools verify --quick` green before integration (receipts
in the worker worktrees).

## Residuals

- 15 test failures inherited on master (13 `test_plain_cli_snapshots`
fixtures, 2 `test_click_app` read-view assertions) are owned by the peer
session's 2206 fix and are not touched here.
-
`test_codex_state_live_ingest.py::test_codex_goal_materials_do_not_cross_supersede_source_roots`
fails at base 342cf9e (inherited, unrelated).
- Operator decisions surfaced by workers, left open: b5xfk (contradicts
the #4614 subdirectory contract), bwu75 (member-level disposition row
needs a source migration), 4xhzs (no converger stage resumes accepted
machine requests), om8dh, ew7ti, fxtbj, gzmd4, qut1/l6v61, v8dz.
- pw5jd stays open: its classifier is landed by #5222 (jtrtj) instead.
- Corpus-scale receipts (memory.peak under the pytest slice at width 4,
controller peak ≤600 MiB) were not produced; the width change is
arithmetic plus unit tests.

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

https://claude.ai/code/session_01Sx3uCnEiY7MXtLt4FDEYfw

---------

Co-authored-by: Claude Fable 5.1 <[email protected]>
Sinity and others added 3 commits September 16, 2026 08:50
Four CLI read defects the 2026-09-15 grok audit found, all in the seam
between a declared operation and the surface that renders it.

polylogue-w3s0q (P0): the `cli.query` list payload carried no `next_offset`,
so `session_rows.query_complete_session_ids` ended its walk after one page
and `select`/`mark`/`delete --all` acted on the first 500 matches while the
operator asked for every match -- the exact #1873 regression that loop
exists to prevent. `daemon_reads.page_next_offset` now decides continuation
once for both the list and ranked pages. It is carried as a sibling field in
`QueryResult`, alongside `attached_units` and `total_unit` and for the same
reason: `SessionListResponse`/`SearchEnvelope` forbid extras and live in the
derived-schema closure, which a CLI-facing field must not move.

polylogue-jfabc: `render/rows._page_envelope` substituted `len(rows)` for an
operation's honest `None` total, turning a vector lane's deliberate "no
archive-wide cardinality" into a confident count, and re-derived
`next_offset` from it. The renderer now reports both as the operation
decided them. The bare landing screen named "(daemon)" from the absence of
`--no-daemon`, although the kernel falls back to the in-process reader when
no socket answers; it now reads the authority the result carries.

polylogue-jtrtj: every typed read failure that was not
daemon_required/result_too_large became a `click.UsageError`, which exits 2
-- the *empty* status -- behind Click's usage banner. Transport loss, a
missed deadline, a cancellation and a refused request were therefore
indistinguishable by exit status from "matched nothing". `render/outcome`
now owns one read-failure terminal: 1 for a failure, 130 for a cancellation,
never 2, with the call id, the deadline and a remedy in the message, and a
parseable document for `--format json`.

polylogue-ry6g5: a fresh archive root produced two refusal texts and two
machine contracts depending on which verb asked, because `find` echoed its
own wording past `machine_errors`. It now raises the same typed
`ArchiveTierUnavailableError` the storage layer raises.

Closure: `devtools schema closure` reports every changed file OUT.

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

polylogue-dutav. `cli/read_view_registry.py` declared ten views as
`session-read-projection` over `session.read`. Only `hooks` is one:
`daemon_reads._session_read_payload` answers `transcript` itself and
delegates every other kind to `_SESSION_EVIDENCE_READERS`, which holds
`hooks` alone and raises for anything else. `summary`/`transcript` are
`cli.query` renderers; `dialogue`, `messages`, `raw`, `events`,
`effective_context`, `file-edits`, `agent-policies` and `web-content` read
the archive in this process through the Python API facade. `neighbors` was
declared a `cli.query` renderer while calling
`polylogue.neighbor_candidates` directly, and `temporal`/`chronicle` use
`run_archive_read_sync`/`list_summaries`.

The reason the table could be this wrong is that
`_validate_read_view_classification` checked it only against itself. It is
now checked against the kernel: `test_read_view_execution_routes.py`
dispatches every view with the daemon absent and `daemon_only=True` and
compares the operations that actually reach
`cli.operation_kernel.dispatch` with the operations the row declares, so a
row can neither claim an operation it does not execute nor execute one it
does not declare.

The honest state gets a name -- execution kind `in-process` -- and a
shrink-only ratchet, `IN_PROCESS_READ_VIEWS`: a view may leave it by moving
onto a declared operation, never join it. This records what S8/S9 still owe
instead of hiding it behind a classification that reads as finished.

Third mirror: `surfaces/read_contract.READ_PRESETS` was a hand-written list
that had silently lost `lineage` and `effective_context`, and nothing
compared it with the view declaration. It is now generated from
`archive.viewport.read_view_choices()` -- the declaration
`cli.read_view_registry` already validates against -- so the drift is
impossible rather than merely detectable.

Executed mutation: declaring `events` as a `session.read` projection turns
`test_each_view_executes_the_route_it_declares[events]` and
`test_session_read_projections_name_a_kind_the_operation_actually_serves`
red (2 of 24), with "events declares ('session.read',) but reached no
operation".

Closure: `devtools schema closure` reports both changed modules OUT.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK
`devtools verify --quick` rejected an unused `type: ignore` and an
untyped row list in the polylogue-jfabc tests. Same assertions, typed.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK
@Sinity
Sinity force-pushed the feat/cli-read-ownership-unit branch from 16d4bfd to 20f7114 Compare September 16, 2026 08:56
@Sinity
Sinity merged commit 9d2d477 into master Sep 18, 2026
3 checks passed
@Sinity
Sinity deleted the feat/cli-read-ownership-unit branch September 18, 2026 20:35
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