Skip to content

refactor: contract CLI and MCP read surfaces - #248

Merged
Sinity merged 1 commit into
masterfrom
feature/refactor/surface-contraction
Apr 20, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/refactor/surface-contraction

Conversation

@Sinity

@Sinity Sinity commented Apr 20, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • contract CLI, MCP, and TUI read paths around explicit repository and archive-operation surfaces
  • remove direct .queries and backend reach-through from the affected surfaces
  • align CLI and MCP tests with the narrowed injection seams

Problem

The renewed substrate was still leaking implementation details into higher-level surfaces. CLI helpers, MCP resources/tools, and the TUI were reaching through repo.queries and backend connections instead of depending on explicit read-side contracts. That kept surface code coupled to repository internals and made the MCP seam brittle in tests.

Ref #245

Solution

  • flatten the relevant protocols in polylogue/protocols.py so surface code depends on direct read/query methods instead of nested .queries
  • add repository and ArchiveOperations delegates for the surfaced read/stat methods
  • rewire CLI query helpers, MCP resources/prompts/tools, and the TUI base app to use those narrower contracts
  • keep a stable _get_repo() seam in polylogue.mcp.server while exposing narrower callbacks for query, tag, backend, and archive-operation access
  • update CLI embed/query tests and MCP server-surface/tool-contract tests to match the new seams

Verification

  • pytest -q tests/unit/cli/test_query_exec.py tests/unit/cli/test_query_exec_laws.py tests/unit/cli/test_query_fmt.py tests/unit/cli/test_run.py -k 'query or embed'
  • pytest -q tests/unit/mcp tests/unit/ui -k 'tool or resource or prompt or mutation or maintenance or browser or dashboard or search or app'
  • pytest -q tests/unit/cli/test_embed.py tests/unit/cli/test_query_exec.py tests/unit/cli/test_query_exec_laws.py tests/unit/mcp/test_server_surfaces.py tests/unit/mcp/test_tool_contracts.py
  • devtools verify

@coderabbitai

coderabbitai Bot commented Apr 20, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@Sinity has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 16 minutes and 19 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 16 minutes and 19 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: b47f260f-a080-4567-8263-3c6fc14e2215

📥 Commits

Reviewing files that changed from the base of the PR and between 583abbe and b156a12.

📒 Files selected for processing (25)
  • polylogue/cli/embed_runtime.py
  • polylogue/cli/query.py
  • polylogue/cli/query_actions.py
  • polylogue/cli/query_output.py
  • polylogue/cli/query_semantic.py
  • polylogue/cli/query_stats.py
  • polylogue/mcp/server.py
  • polylogue/mcp/server_maintenance_tools.py
  • polylogue/mcp/server_mutation_tools.py
  • polylogue/mcp/server_product_tools.py
  • polylogue/mcp/server_prompts.py
  • polylogue/mcp/server_resources.py
  • polylogue/mcp/server_support.py
  • polylogue/mcp/server_tools.py
  • polylogue/operations/archive.py
  • polylogue/protocols.py
  • polylogue/storage/repository_archive_conversations.py
  • polylogue/storage/repository_archive_queries.py
  • polylogue/ui/tui/app.py
  • polylogue/ui/tui/screens/base.py
  • tests/unit/cli/test_embed.py
  • tests/unit/cli/test_query_exec.py
  • tests/unit/cli/test_query_exec_laws.py
  • tests/unit/mcp/test_server_surfaces.py
  • tests/unit/mcp/test_tool_contracts.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/refactor/surface-contraction

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 and usage tips.

@Sinity
Sinity merged commit b45c11e into master Apr 20, 2026
12 checks passed
@Sinity
Sinity deleted the feature/refactor/surface-contraction branch April 20, 2026 04:46

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b156a12181

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

"""Stream conversation messages to stdout without buffering."""
conv_record = await repo.queries.get_conversation(conversation_id)
if not conv_record:
projection = await repo.get_render_projection(conversation_id)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Avoid eager render projection in streaming path

stream_conversation now fetches get_render_projection(...) before streaming, but the default repository implementation of that projection loads all messages and attachments eagerly. In --stream mode this duplicates work because messages are then read again via iter_messages(...), which can significantly increase latency and memory usage (and potentially fail) for large conversations or small message_limit values.

Useful? React with 👍 / 👎.

Comment thread polylogue/mcp/server_prompts.py Resolved
Sinity added a commit that referenced this pull request Apr 22, 2026
## Summary
- contract CLI, MCP, and TUI read paths around explicit repository and archive-operation surfaces
- remove direct `.queries` and backend reach-through from the affected surfaces
- align CLI and MCP tests with the narrowed injection seams

## Problem
The renewed substrate was still leaking implementation details into higher-level surfaces. CLI helpers, MCP resources/tools, and the TUI were reaching through `repo.queries` and backend connections instead of depending on explicit read-side contracts. That kept surface code coupled to repository internals and made the MCP seam brittle in tests.

Ref #245

## Solution
- flatten the relevant protocols in `polylogue/protocols.py` so surface code depends on direct read/query methods instead of nested `.queries`
- add repository and `ArchiveOperations` delegates for the surfaced read/stat methods
- rewire CLI query helpers, MCP resources/prompts/tools, and the TUI base app to use those narrower contracts
- keep a stable `_get_repo()` seam in `polylogue.mcp.server` while exposing narrower callbacks for query, tag, backend, and archive-operation access
- update CLI embed/query tests and MCP server-surface/tool-contract tests to match the new seams

## Verification
- `pytest -q tests/unit/cli/test_query_exec.py tests/unit/cli/test_query_exec_laws.py tests/unit/cli/test_query_fmt.py tests/unit/cli/test_run.py -k 'query or embed'`
- `pytest -q tests/unit/mcp tests/unit/ui -k 'tool or resource or prompt or mutation or maintenance or browser or dashboard or search or app'`
- `pytest -q tests/unit/cli/test_embed.py tests/unit/cli/test_query_exec.py tests/unit/cli/test_query_exec_laws.py tests/unit/mcp/test_server_surfaces.py tests/unit/mcp/test_tool_contracts.py`
- `devtools verify`
Sinity added a commit that referenced this pull request Apr 22, 2026
The renewed substrate was leaking implementation details into
higher-level surfaces. CLI helpers, MCP resources/tools, and the TUI
were reaching through `repo.queries` and backend connections
instead of depending on explicit read-side contracts. That kept
surface code coupled to repository internals and made the MCP seam
brittle in tests.

Flattens the relevant protocols in `protocols.py` so surface code
depends on direct read/query methods instead of nested `.queries`.
Adds repository and `ArchiveOperations` delegates for the surfaced
read/stat methods. Rewires CLI query helpers, MCP resources /
prompts / tools, and the TUI base app to use those narrower
contracts. Keeps a stable `_get_repo()` seam in `mcp.server` while
exposing narrower callbacks for query, tag, backend, and archive-
operation access. Updates CLI embed/query tests and MCP server-
surface/tool-contract tests to match the new seams.

Verification: focused pytest over cli query/embed, mcp, ui, and
surface/tool-contract suites; devtools verify green.

Ref #245
Sinity added a commit that referenced this pull request Apr 22, 2026
The renewed substrate was leaking implementation details into
higher-level surfaces. CLI helpers, MCP resources/tools, and the TUI
were reaching through `repo.queries` and backend connections
instead of depending on explicit read-side contracts. That kept
surface code coupled to repository internals and made the MCP seam
brittle in tests.

Flattens the relevant protocols in `protocols.py` so surface code
depends on direct read/query methods instead of nested `.queries`.
Adds repository and `ArchiveOperations` delegates for the surfaced
read/stat methods. Rewires CLI query helpers, MCP resources /
prompts / tools, and the TUI base app to use those narrower
contracts. Keeps a stable `_get_repo()` seam in `mcp.server` while
exposing narrower callbacks for query, tag, backend, and archive-
operation access. Updates CLI embed/query tests and MCP server-
surface/tool-contract tests to match the new seams.

Verification: focused pytest over cli query/embed, mcp, ui, and
surface/tool-contract suites; devtools verify green.

Ref #245
Sinity added a commit that referenced this pull request Apr 22, 2026
The renewed substrate was leaking implementation details into
higher-level surfaces. CLI helpers, MCP resources/tools, and the TUI
were reaching through `repo.queries` and backend connections
instead of depending on explicit read-side contracts. That kept
surface code coupled to repository internals and made the MCP seam
brittle in tests.

Flattens the relevant protocols in `protocols.py` so surface code
depends on direct read/query methods instead of nested `.queries`.
Adds repository and `ArchiveOperations` delegates for the surfaced
read/stat methods. Rewires CLI query helpers, MCP resources /
prompts / tools, and the TUI base app to use those narrower
contracts. Keeps a stable `_get_repo()` seam in `mcp.server` while
exposing narrower callbacks for query, tag, backend, and archive-
operation access. Updates CLI embed/query tests and MCP server-
surface/tool-contract tests to match the new seams.

Verification: focused pytest over cli query/embed, mcp, ui, and
surface/tool-contract suites; devtools verify green.

Ref #245
@Sinity
Sinity requested review from Copilot and removed request for Copilot May 1, 2026 00:43
@Sinity

Sinity commented Oct 1, 2026

Copy link
Copy Markdown
Owner Author

Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.

  • 69.F030 / P2: fixed-already at the checked revision: polylogue/mcp/server_prompts.py:243 resolves a supplied session token before loading its prompt page. KeyError and ValueError become the missing-session result at lines 245-246, so valid unique prefixes are no longer passed as unresolved exact IDs.

Only the rows listed above are dispositioned. Held findings remain open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant