Skip to content

fix: Let MCP name any transcript window, not only the first page - #5184

Merged
Sinity merged 2 commits into
masterfrom
fix/mcp-transcript-window
Sep 15, 2026
Merged

Sinity merged 2 commits into
masterfrom
fix/mcp-transcript-window

Conversation

@Sinity

@Sinity Sinity commented Sep 15, 2026

Copy link
Copy Markdown
Owner

Summary

MCP read(view="messages") hard-coded offset=0. A client asking for messages 2–4 silently received 0–2. Found by building the cross-surface differential that polylogue-vclez asks for.

Problem

polylogue-vclez requires that the same request return equal ids, rank, content, provenance, totals and continuing windows through the Python API, CLI, MCP and HTTP. The session-summary request was already held to that by the oracle-backed differential in tests/infra/surface_differential.py. The transcript-window request had no cross-surface differential at all — and the surfaces had genuinely drifted.

polylogue/mcp/server_cutover.py read() had no offset parameter, passed a literal offset=0 into get_messages_paginated, echoed a literal offset=0 back in the payload, and refused continuations for every view except topology. The window was therefore inexpressible over MCP beyond the first page, and — worse than an error — a narrowed request returned the wrong rows with a payload claiming offset=0, so a caller could not detect it.

Solution

read() accepts offset, applies it to the messages view, and echoes the real window back. The messages view continues by message-offset:<n>, mirroring the decimal form the topology view already used (node-offset:<n>), so no surface mints a continuation token another surface cannot read. offset also now feeds topology's existing node_offset instead of its own hard-coded zero. A negative offset is refused typed rather than silently clamped.

tests/integration/test_transcript_window_differential.py holds API/CLI/MCP/HTTP to one answer (ids in order, plus total) for the same (ref, limit, offset), and proves consecutive windows tile the transcript with no overlap and no gap.

docs/design/transcript-window-responsibility.md records the before/after responsibility map vclez asks for, including an honest negative: nothing was deleted or relocated, because two owners still exist. session.read/_session_read_payload (CLI only) and Polylogue.get_messages_paginated (Python API, MCP, HTTP) are not interchangeable today — the latter exposes message_role/message_type/material_origin filters the former lacks, and only the former runs inside QueryExecutionContext. Collapsing them changes the webui payload that /api/sessions/:id/messages serves, so it needs its own task.

Verification

devtools test tests/integration/test_transcript_window_differential.py   → PASSED exit 0
devtools test tests/unit/surfaces/test_read_contract.py tests/unit/cli/test_query_expression.py \
  tests/unit/cli/test_query_exec_laws.py tests/unit/archive/query/test_continuation_surface_parity.py \
  tests/unit/mcp/test_read_messages_view.py                             → PASSED exit 0
devtools gate layering        → passed, violations: 0, baselined_count: 226 unchanged
devtools render all --check   → exit 0, no "out of sync"
devtools verify --quick       → exit 0, all 17 gates ok

Anti-vacuity, executed: restoring window_offset = 0 on the MCP branch fails two of the three differential tests (devtools test: FAILED exit=1); restoring the fix returns them to green.

Schema-identity closure: no changed file is inside it. Verified with devtools schema closure: polylogue/mcp/server_cutover.py → out. The fix deliberately reuses the existing offset field rather than adding next_offset/continuation to SessionMessagesResponsePayload, because polylogue/surfaces/payloads.py, archive/query/expression.py and archive/query/transaction.py are all IN the closure. So this carries no pre-rebuild landing-order constraint.

Residuals

  • Rank and provenance equality for the transcript window are not asserted — the window is position-ordered and the four envelopes carry different provenance shapes. Needs the two owners unified first.
  • Typed outcomes for growth / deep anchor / oversized body / unavailable insight / stale generation / cancellation / transport loss are unsatisfied for the transcript window: only the CLI route has snapshot-bound continuation with epoch validation; the other three resume by re-asking an offset. Stale-generation parity is proven for the query-units request only.
  • Consequently the snapshot-binding mutation is uncovered — three of four surfaces have no snapshot binding on this route.
  • plan_execution.py was left alone deliberately: list_for_plan is the live repository-runtime-store path and carries the typed near:id: refusal, so it is not superseded.

🤖 Generated with Claude Code

https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK

Sinity and others added 2 commits September 15, 2026 15:15
The MCP `read(view="messages")` branch hard-coded `offset=0` and the tool
signature carried no `offset` parameter at all, while the Python API, the CLI
`read --view messages` verb and the HTTP `/api/sessions/:id/messages` route
all window by limit+offset. A client asking MCP for messages 2..4 silently
received messages 0..2, and any continuation was refused outright.

`read` now takes `offset` and continues the messages view by the same decimal
form the topology view already uses (`message-offset:<n>`), so no surface
mints a token another cannot read. `offset` also feeds the topology view's
existing `node_offset`, and a negative offset is refused typed.

tests/integration/test_transcript_window_differential.py holds all four
surfaces to one answer for the same (ref, limit, offset), and proves the
windows tile the transcript without overlap or gap. Anti-vacuity: restoring
`offset=0` on the MCP branch was run and turns two of the three tests red.

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

States, per surface, which executor answers a one-session message window,
what the MCP change did and did not relocate, and the two owners that still
remain (`session.read` vs `get_messages_paginated`) with the concrete
consequences: only the CLI resumes under epoch validation, and only that
route runs inside QueryExecutionContext.

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 51 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: 84a73373-1aa0-440a-a5a9-468527487035

📥 Commits

Reviewing files that changed from the base of the PR and between b8375e1 and 1f72364.

📒 Files selected for processing (4)
  • docs/design/README.md
  • docs/design/transcript-window-responsibility.md
  • polylogue/mcp/server_cutover.py
  • tests/integration/test_transcript_window_differential.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-15T13:21:04.352022Z 1f72364 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 34cdcc6 into master Sep 15, 2026
3 checks passed
@Sinity
Sinity deleted the fix/mcp-transcript-window branch September 15, 2026 13:22
Sinity added a commit that referenced this pull request Sep 15, 2026
…pus (#5196)

Two independent settled decisions, one commit each.

## A — retire `polylogue/api/contracts/` (polylogue-aq2l5)

Ruled and authorized on the bead. The package shipped as a contract
spine enforced through shadow adapters; **those adapters were deleted
two days later** (#1329), leaving `TUIReadSurface` as the only
implementor — and #5182 deleted the TUI. `a7xr.13` had already deleted
the mirrored write-surface half, recording the finding that shadow
adapters verify copies rather than surfaces, and the plan "execute f94
first, then nothing in read_surface needs keeping".

Verified before deleting, not trusted from the brief: every
`api.contracts` hit is inside the package; `assert_implements` has 11
hits, all internal, zero call sites; each exported Protocol name
searched individually returns zero external hits; `TUIReadSurface` zero
hits anywhere. `ArchiveReadCapability` is unaffected — it lives in
`api/archive_reads.py:17` and the deleted `contracts/__init__.py:38` was
a pass-through re-export.

Replacement in place: operation-identity parity
(`polylogue/api/parity.py`, gate `api-parity`) plus behavioral
differentials — including the one in #5184 that caught the MCP
`offset=0` defect no name-based check could.

**Correction to the ruling's expectation**: it predicted the layering
baseline would shrink. It did not — 226 before, 226 after.
`docs/plans/layering-surface-baseline.json` has no entry for any
`api/contracts/*` file, and `polylogue/api` → `polylogue/daemon` is not
a disallow pair in `layering.yaml`, so the removed `read_surface.py:31`
import never counted. The bound held; the number did not move.

## B — declare the corpus schedule (polylogue-yk0zz want 4)

`schedule = "*-*-* 03:00"` added to `[operations.verify_all]`. `cache`,
`checkout`, `pool` untouched — they are load-bearing for the dedupe
property. `verify.yml`'s header comment corrected: it claimed a nightly
agentctl `verify_all` schedule that was never declared.
`concurrency.cancel-in-progress: true` deliberately unchanged.

Key spelling cross-checked against the live precedent
(`/realm/project/sinnix/.agentctl/project.toml` `[operations.census]`).
`agentctl schedule apply` was **not** run — that mutates live host state
and is the coordinator's.

## Verification

```
devtools verify --quick (after each part) → EXIT 0, all 19 gates
devtools test tests/unit/api tests/unit/core/test_facade_api.py → EXIT 0
devtools render all --check → EXIT 0, 0 occurrences of "out of sync"
```

All five changed files confirmed **out** of the schema-identity closure.

## Residual

`agentctl schedule apply` still needs running after this lands; want 4
closes only once the timer is listed and one scheduled run has a result.
`agentctl schedule` exposes only `apply` — no read-only list verb — so
the descriptor's acceptance of the value is unproven until then.

🤖 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
…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]>
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