Skip to content

feat: Answer the transcript window from one bound execution route - #5202

Merged
Sinity merged 3 commits into
masterfrom
feat/one-transcript-window-route
Sep 15, 2026
Merged

Sinity merged 3 commits into
masterfrom
feat/one-transcript-window-route

Conversation

@Sinity

@Sinity Sinity commented Sep 15, 2026

Copy link
Copy Markdown
Owner

Summary

"Window one session's messages" had four implementations across the surfaces. They now share one route with snapshot binding, epoch validation and a single continuation vocabulary. Delivers polylogue-ijbwq, which unblocks polylogue-vclez and the CLI chain behind it.

Correcting the bead's premise

The bead named two owners. At head there were four: _session_read_payload (CLI session-document read), Polylogue.get_messages_paginated (Python API, MCP, HTTP DB branch, and the CLI's read --view messages, which does not go through session.read), _do_archive_get_messages (HTTP web-reader branch via read_session_page), and execute_session_operation(SessionRead) — which already wrapped get_messages_paginated in a QueryTransaction with epoch validation. That last one was the production shape of the wanted route; the work was making every surface reach it.

Solution

New polylogue/operations/transcript_window.py owns window arithmetic, snapshot binding (epoch read before and after the storage read), epoch validation on resume, and one QueryContinuation token stamped session-owner-v1 — the token sessions.read already minted, so this is one vocabulary rather than a new dialect.

Surfaces reaching it: Polylogue.read_transcript_window (+ sync mirror), CLI run_messages, MCP read(view="messages"), both HTTP branches, and execute_session_operation(SessionRead). get_messages_paginated survives as the storage read inside the route and is no longer a window owner.

The filter set is preserved rather than dropped: message_role / message_type / material_origin are now fields of SessionRead, so they are part of the token's request identity — a continuation minted for a filtered read cannot resume an unfiltered one. The CLI gained read --view messages --continuation (appended last, per the positional-shift rule) so it can consume the token it mints. Every surface refuses a stale token typed: query_continuation_stale on API/CLI/MCP, HTTP 409.

What was deliberately NOT collapsed

Each surface keeps its row projection, with evidence. The HTTP web reader's _archive_message_payload serves source_session_id and inherited_prefix (lineage-prefix provenance) plus the stored per-message word_count; polylogue/archive/message/models.py has no source_session_id field and its word_count is text-derived. Collapsing the projections would have silently dropped those. The reader is therefore a declared parameter of the one route (Reader/SyncReader), which still owns the window on both.

session.read also stays, serving the CLI's session-document read (whole-session body with blocks) — a different product, not a second transcript window.

The webui hazard the bead flagged

The webui does not consume /api/sessions/:id/messages — webui/src/lib/api.ts fetches /api/sessions/:id/read?view=messages, parsed by webui/src/contracts/session-read.ts. That route dispatches to the same two payload builders, so it was still in scope. Both builders' payload fields are byte-identical, with only next_offset and continuation added; semantic_entries, semantic_cards and semantic_card_suppressed placement are computed exactly as before. Additive for that consumer, and no webui file was touched.

Verification

devtools verify --quick → all 19 gates ok, exit 0
devtools gate layering  → violations 0, baseline not widened
devtools test tests/integration/test_transcript_window_differential.py \
  tests/unit/archive/query/test_continuation_surface_parity.py \
  tests/unit/operations/test_transcript_window_route.py tests/unit/cli/test_messages.py \
  tests/unit/mcp/test_read_messages_view.py tests/unit/mcp/test_session_owner_operations.py \
  tests/unit/core/test_sync_surface_runtime.py tests/unit/daemon/test_web_reader.py → 189 passed, exit 0

Re-verified after rebase onto current master (which fixed two unrelated reds): the same selection → exit 0, verify --quick → exit 0.

New and extended tests: rank+provenance equality across four surfaces (position, identity_source, material_origin, message_type, parent_message_id, variant_index, is_active_leaf), asserting transcript-relative rank ["2","3"] rather than page-relative; every surface mints a snapshot-bound continuation decoding to the same transaction; the same token resumes identically on all four; a token issued before a write is refused identically by all four; plus an AST census of the route.

Anti-vacuity, both executed. Re-splitting the route (MCP back to its own offset arithmetic) → 4 failed, 9 passed, including the census naming the offending call site. Dropping snapshot binding on exactly one surface → 1 failed, 8 passed, http minted no snapshot-bound continuation. Both reverted from byte-identical backups.

⚠ Landing order

polylogue/surfaces/payloads.py is IN the schema-identity closure — adding next_offset/continuation to SessionMessagesResponsePayload was unavoidable, since CLI and MCP could not otherwise carry the token. It is isolated in its own commit and must land before a fresh rebuild starts. Every other changed file is out.

Residual

vclez's criterion 2 is now satisfied for stale generation, cancellation-capable execution and transport refusal on the transcript window. Growth, deep anchor, oversized body and unavailable insight remain vclez's own scope and were not this bead's wanted outcome.

🤖 Generated with Claude Code

https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK

Sinity and others added 3 commits September 15, 2026 19:18
Adds next_offset and continuation to SessionMessagesResponsePayload so the
CLI and MCP message-row surfaces can carry the snapshot-bound continuation
that only the CLI session-document route could mint before.

surfaces/payloads.py is IN the derived schema-identity closure
(`devtools schema closure polylogue/surfaces/payloads.py` reports IN), so
this edit moves the identity and the archive must reconverge. It is isolated
in its own commit for that reason and must land before a fresh rebuild
starts, never during one.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK
Two owners answered "messages [offset, offset + limit) of this session" and
were not interchangeable: the session.read declared operation (CLI only, the
only one inside QueryExecutionContext) and Polylogue.get_messages_paginated
(Python API, MCP, HTTP). Only the first bound a snapshot; the other three
resumed by re-asking an offset, which a write landing between pages shifts.

polylogue/operations/transcript_window.py is now the one route. It owns the
window arithmetic, the snapshot binding (epoch read before and after the
storage read), epoch validation on resume, and one opaque QueryContinuation
token -- the same token the sessions.read operation already minted, so a
token issued on any surface resumes on every other. get_messages_paginated
remains as the storage read inside it and is no longer a window owner.

The selection vocabulary is preserved rather than dropped: message_role,
message_type and material_origin are fields of the SessionRead request, so
they are part of the token's request identity.

Each surface keeps its own row projection. That is deliberate: the HTTP web
reader answers with composed archive rows carrying source_session_id /
inherited_prefix and the stored per-message word_count, which the domain
Message model does not represent. Collapsing that would drop real fields.
The webui consumer (/api/sessions/:id/read?view=messages) sees only additive
next_offset and continuation keys.

The CLI gains `read --view messages --continuation` so it can consume the
token it mints, and every surface refuses a stale token typed
(query_continuation_stale; HTTP 409).

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK
The MCP facade mock, the CLI messages fake API and the Polylogue facade
contract census all named get_messages_paginated, which is now the storage
read inside the one route rather than the route itself. The doubles mirror
read_transcript_window so they exercise the production shape, and
read_transcript_window is classified alongside the read it wraps.

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 15, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 10 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: 2a8c9e96-9f8c-46cf-a8f8-6da0c39b104f

📥 Commits

Reviewing files that changed from the base of the PR and between 81140e2 and 4d4e49b.

📒 Files selected for processing (24)
  • docs/api-parity.md
  • docs/design/transcript-window-responsibility.md
  • docs/schemas/cli-output/session-messages-response.schema.json
  • polylogue/api/archive.py
  • polylogue/api/parity.py
  • polylogue/api/sync/sessions.py
  • polylogue/cli/messages.py
  • polylogue/cli/query_verbs.py
  • polylogue/cli/read_view_registry.py
  • polylogue/cli/read_views/base.py
  • polylogue/cli/read_views/messages.py
  • polylogue/daemon/http.py
  • polylogue/mcp/server_cutover.py
  • polylogue/operations/session_contracts.py
  • polylogue/operations/session_reads.py
  • polylogue/operations/transcript_window.py
  • polylogue/surfaces/payloads.py
  • tests/infra/mcp.py
  • tests/integration/test_transcript_window_differential.py
  • tests/unit/api/test_facade_contracts.py
  • tests/unit/archive/query/test_continuation_surface_parity.py
  • tests/unit/cli/test_messages.py
  • tests/unit/mcp/test_read_messages_view.py
  • tests/unit/operations/test_transcript_window_route.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 15, 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-15T17:36:06.934836Z 4d4e49b 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 fa490f1 into master Sep 15, 2026
3 checks passed
@Sinity
Sinity deleted the feat/one-transcript-window-route branch September 15, 2026 17:31
Sinity added a commit that referenced this pull request Sep 15, 2026
…5209)

Two beads, one commit each. Both replace restated facts with derived
ones, because a restated fact in a generated manual is what drifted in
the first place.

## polylogue-4u79w — the manual prescribed a flow the handler rejects

**The manual was wrong, not the handler.** Evidence, rather than a
preference:

- The declaration owns the contract: the `maintenance` `_ToolRow`
(`mcp/declarations/registry.py:256-273`) states "rebuild_insights and
recovery_adjudicate require confirm=true and fail closed without it",
and both the handler (`server_cutover.py:2718-2745`) and
`_dispatch_maintenance` implement exactly that.
- No preview/dry-run exists anywhere in the operation `Literal`, the
dispatcher, or `AuditRepository`. `recovery_status` already *is* the
read-only inspection route the prose wanted.
- **polylogue-2x6xu already adjudicated `preview` as phantom**, removing
the `dry_run` argument and the `operation="preview"` example from the
generated contract. The prose was the last surviving remnant, not a
competing intent. Growing the handler a preview operation would have
invented a declared operation and a target-algebra entry to satisfy
stale text.

The fix is not a reword: the gate is declared once as `ConfirmationGate`
on the maintenance contract and the manual sentence is **rendered** from
it, with the `operation` argument carrying derived `enum_values`. The
remaining preview vocabulary the same defect left behind is purged too —
the capability-table row, the "stale destructive preview" recovery
bullet, a regeneration-checklist item, and a stale
`semantic:"preview-bound confirmation"` example query.

**Anti-vacuity, executed twice**: adding `"preview"` to the handler's
`Literal` failed both the declared-gate and manual-prose tests;
restoring the hand-written prose line in place of the derived sentence
failed. Both reverted.

**Inherited failure fixed forward**:
`test_generated_contract_arguments_match_the_live_mcp_signatures` was
already red at base — `read: live but undocumented ['offset']`, from
#5184/#5202 adding the parameter. The `read` contract now documents it.

## polylogue-nysan — "ten-tool surface" against twelve declared

The count is now **derived**: `ALL_DECLARED_TOOLS` comes from
`MCP_TOOL_DECLARATIONS`, and the manual renders both its table rows and
its spelled count word from that set. Every literal count is gone —
renderer (5 sites), `spec.py` docstring and four `ClientDelivery`
deltas, `registry.py` docstring, `declared_tool_names`' own
"twelve-tool" docstring, `tests/infra/mcp.py`,
`verify_agent_integration.py`, `cli/commands/agent.py`, and the
`test_assets_and_cli` assertions.

`record_work_event` and `emit_decision` gained real manual contracts
with live-signature-exact arguments; `MCPToolDeclaration` now carries
`result_semantics` so a tool with no target transaction can still be
described, and a new test keeps "outside the target algebra" distinct
from "not a tool".

**Anti-vacuity, executed**: adding a 13th `_ToolRow` made `devtools
render agent-manual --check` exit 1, failing closed with
`missing=['probe_thirteenth']`; after adding its contract the manual
rendered `## The thirteen tools` and "thirteen tools, of which six are
available by default". Reverted.

`docs/atlas/mcp.md`'s DISCREPANCIES section documented both of these
bugs and is now false — rewritten with re-resolved anchors.

## Verification

```
devtools test tests/unit/agent_integration/test_manual_contract.py → PASSED exit 0
devtools test tests/unit/agent_integration/ tests/unit/mcp/        → PASSED exit 0
devtools render agent-manual --check → exit 0
devtools render all --check → exit 0, 0 "out of sync"
devtools verify --quick → exit 0, 21/21 gates
devtools gate atlas → ok
```

Every changed source file is **out** of the schema-identity closure. No
devtools root verb added.

## ⚠ Overlaps operator work — do not lose it

A branch `docs/mcp-tool-count` exists with **no commits ahead of
master**; the actual work is parked in `stash@{0}`
("mcp-tool-count-wip", authored by Sinity 2026-09-14) on the same topic
as nysan. That stash was **not** touched, popped, or inspected beyond
`git stash list` — it is operator WIP and the shared stash stack is
unsafe to pop. This PR likely supersedes it, but that is the operator's
call to confirm before dropping it.

## Residual

`## Normal invocations` still renders worked examples for the six
default read tools only; the privileged four-plus-two are covered by the
table, capability section and contract JSON. Extending worked examples
to privileged tools is a separate judgment call, deliberately not made
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 16, 2026
Job 2206, the first nightly full-corpus `verify_all`, failed with 27 tests red.
Fifteen were deterministic and stale; this commit is those fifteen. They
reproduce in isolation at the base commit (15 failed, 96 passed in 9.96s) with
node ids matching 2206 exactly, so none of them is pool contention.

`tests/unit/cli/test_click_app.py` asserted raw's options as
`["full", "limit", "offset"]`. #5202 added `continuation` to
`MESSAGE_READ_VIEW_OPTION_NAMES`, so the product is right and the assertion was
stale in two places.

`test_plain_cli_snapshots.ambr` is regenerated. The drift is genuine fixture
data, not the ephemeral state this file's docstring warns about:

- The seeded corpus now draws titles from
  `polylogue/schemas/synthetic/demo_themes.py` instead of `synthetic-N`
  placeholders. Checked before committing, because realistic titles in a
  tracked baseline is the shape a private-data leak would take; these are
  authored in-repo fixtures.
- `total_messages` moves 10 to 13. Verified against the seeded artifact rather
  than accepted from the diff: 8 + 5 messages across two sessions, every row
  `identity_source=native` with `content_occurrence=0`. A message-count drift is
  also what a content-identity collision or a lineage-recomposition bug would
  look like, and regenerating over one of those would pin the bug permanently.
- `summed_wall_duration_ms` now redacts to `<HASH>` where the old baseline
  pinned a literal duration. The old baseline was doing what the docstring
  forbids; the regeneration removes a latent flake.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK
Sinity added a commit that referenced this pull request Sep 18, 2026
## Summary

Job 2206 — the first nightly full-corpus `verify_all`, which fired at
03:00 as
declared in #5196 — failed with **27 tests red**. Fifteen were
deterministic and
stale. This PR is those fifteen.

They reproduce in isolation at the base commit (`15 failed, 96 passed in
9.96s`)
with node ids matching 2206 exactly, so none of them is pool contention.

## The two assertion fixes

`tests/unit/cli/test_click_app.py` asserted raw's options as
`["full", "limit", "offset"]`. **#5202 added `continuation`** to
`MESSAGE_READ_VIEW_OPTION_NAMES`. The product is right; the assertion
was stale
in two places.

## The thirteen snapshots

Regenerated. The drift is genuine fixture data, not the ephemeral state
this
file's docstring warns about — which is why each change was checked
before
committing rather than after a green:

- The seeded corpus now draws titles from
  `polylogue/schemas/synthetic/demo_themes.py` instead of `synthetic-N`
placeholders. Verified, because realistic conversation titles appearing
in a
tracked baseline is exactly the shape a private-data leak would take.
These
  are authored in-repo fixtures.
- `total_messages` moves 10 → 13. Verified against the seeded artifact,
not
  accepted from the diff: 8 + 5 messages across two sessions, every row
`identity_source=native` with `content_occurrence=0`. A message-count
drift is
also what a content-identity collision or a lineage-recomposition bug
looks
like, and regenerating over one of those would pin the bug permanently.
- `summed_wall_duration_ms` now redacts to `<HASH>` where the old
baseline
pinned a literal duration. The old baseline was doing what the docstring
  forbids; the regeneration removes a latent flake.

## Verification

`devtools test` over the four affected files through the declared
`pytest_focused` operation (job 2463): **199 passed, 4 failed**. All
four
failures are the pre-existing wire-support ones described below —
untouched by
this PR and red on master independently.

## Not in this PR: the wire-support gap

The other twelve 2206 failures split into ~7 load-shaped daemon timeouts
(still
needing isolated evidence) and 5 real wire-support failures that are
**one
design gap**, not a test bug:

`build_wire_support_receipt` synthesizes **one session document per
provider**
and validates it against **every element in every package**. That was
harmless
while each provider declared one element kind. It is not any more —
chatgpt v4
now declares `export_asset` and `export_asset_index` beside
`session_document`
(#5215), and claude-code declares nine kinds across v1–v3
(`agent_transcript`,
`session_index`, `workflow_journal`, `coordinator_session_stream`,
`agent_sidecar_meta`, …). Every element is declared `supported=True`.

The symptoms are all consequences of that: the missing `'number'` in a
type
union is `export_asset_index`'s `additionalProperties`, which has no
reason to
admit a float `create_time` because `create_time` is not a field it
models; and
the conservation "losses" at `$.body (message_body)` and `$.id
(session_title)`
are a session document parsed under an asset schema, which loses every
session
field by construction. **The chatgpt parser is not dropping content and
the
committed schemas are not wrong.**

The fix is per-element wire synthesis — a feature, not a red-fix. Filing
it
rather than forcing it: a filter that merely skips non-document elements
breaks
`test_every_catalog_provider_has_an_explicit_route_and_receipt_counts`,
which
requires an entry for every catalog element. I tried that and it was
wrong.

🤖 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