Skip to content

fix: close audit gaps — MCP isError, ingestion events, pins wiring (#786, #774, #777) - #797

Merged
Sinity merged 1 commit into
masterfrom
feature/fix/audit-gap-closures
May 4, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/fix/audit-gap-closures

Conversation

@Sinity

@Sinity Sinity commented May 4, 2026 •

Copy link
Copy Markdown
Owner

Fix 3 gaps found by adversarial audit: MCP _safe_call now raises PolylogueError so FastMCP sets isError=True; emit ingestion_batch events from ingest pipeline; thread pins through annotation call chain.

Summary by CodeRabbit

  • New Features

    • Added pin-based constraint support for schema generation workflows.
    • Introduced daemon event tracking for batch ingestion metrics (timing and summary data).
  • Bug Fixes

    • Improved error handling and exception propagation in safe-call operations.
  • Tests

    • Updated tests to align with new error handling behavior.

, #774, #777)

- #786: _safe_call now raises PolylogueError on failure so FastMCP sets
  isError=True with proper integer JSON-RPC error codes.
- #774: Emit ingestion_batch daemon events after each batch completes
  in process_ingest_batch, with throughput and record count metadata.
- #777: Thread pins parameter through the full annotation call chain
  (schema_builder -> support -> semantic_relations -> select_best_roles).
  Load pins.json for each provider during schema generation.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
Copilot AI review requested due to automatic review settings May 4, 2026 03:07
@Sinity
Sinity merged commit f9c8cf8 into master May 4, 2026
@Sinity
Sinity deleted the feature/fix/audit-gap-closures branch May 4, 2026 03:07
@coderabbitai

coderabbitai Bot commented May 4, 2026 •

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: d6753499-818f-4eb9-a255-44f581de2325

📥 Commits

Reviewing files that changed from the base of the PR and between 1c4e35e and 27e9de3.

📒 Files selected for processing (7)
  • polylogue/mcp/server_support.py
  • polylogue/pipeline/services/ingest_batch/_core.py
  • polylogue/schemas/generation/schema_builder.py
  • polylogue/schemas/generation/semantic_relations.py
  • polylogue/schemas/generation/support.py
  • tests/unit/mcp/test_mcp_edge_cases.py
  • tests/unit/security/test_mcp_security.py

📝 Walkthrough

Walkthrough

This pull request makes three independent changes: refactoring error handling in MCP safe-call wrappers to raise exceptions instead of returning JSON payloads, adding pin-based constraint support to the schema generation pipeline, and emitting daemon events for batch ingestion metrics.

Changes

MCP Error Handling Refactor

Layer / File(s) Summary
Core Exception Behavior
polylogue/mcp/server_support.py
_safe_call and _async_safe_call now re-raise PolylogueError unchanged and wrap other exceptions by logging and raising a new PolylogueError, instead of returning JSON-formatted error payloads.
Tests
tests/unit/mcp/test_mcp_edge_cases.py, tests/unit/security/test_mcp_security.py
Updated assertions to expect PolylogueError exceptions rather than parsed JSON responses; verify exception messages contain original type information and no raw traceback text.

Schema Generation Pin Support

Layer / File(s) Summary
Pin Loading Helper
polylogue/schemas/generation/schema_builder.py
New _load_pins_safe() loads pins from provider, filters to "reject" actions keyed by path with role sets, returns empty dict on error.
Parameter Threading
polylogue/schemas/generation/semantic_relations.py, polylogue/schemas/generation/support.py
Updated function signatures to accept optional pins: dict[str, set[str]] | None parameter and thread it to select_best_roles().
Integration
polylogue/schemas/generation/schema_builder.py
Updated generate_schema_from_samples() to accept optional provider parameter; conditionally loads pins and passes them through annotation pipeline in both cluster and sample generation paths.

Batch Ingestion Daemon Events

Layer / File(s) Summary
Event Emission
polylogue/pipeline/services/ingest_batch/_core.py
Added best-effort daemon event emission in process_ingest_batch after slow-batch logging, emitting "ingestion_batch" event with timing and summary metrics; exceptions during emission are suppressed.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~35 minutes

Poem

A carrot stack of pins and flows,
Where errors now in exceptions grow,
Events drift through batches fast,
While schemas remember their cast. 🐰✨

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/fix/audit-gap-closures

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
Review rate limit: 0/1 reviews remaining, refill in 60 minutes.

Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI 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.

Pull request overview

Closes audit gaps across MCP error signaling, ingest telemetry, and schema pin propagation to ensure safer MCP responses, better daemon observability, and consistent schema annotation behavior.

Changes:

  • MCP _safe_call / _async_safe_call now raise PolylogueError so FastMCP can mark responses with isError=True.
  • Ingest pipeline emits ingestion_batch daemon events with batch summary metrics.
  • Schema generation threads pin data into semantic-role selection (via pins passed through generation/annotation layers).

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
tests/unit/security/test_mcp_security.py Updates MCP safety tests to expect raised PolylogueError instead of JSON error strings.
tests/unit/mcp/test_mcp_edge_cases.py Updates MCP edge-case tests to expect raised PolylogueError and checks for no traceback in surfaced error text.
polylogue/mcp/server_support.py Changes _safe_call / _async_safe_call to raise PolylogueError on unexpected exceptions.
polylogue/pipeline/services/ingest_batch/_core.py Emits ingestion_batch daemon events after processing batches.
polylogue/schemas/generation/schema_builder.py Loads pins and passes them into semantic-role annotation during schema generation.
polylogue/schemas/generation/support.py Extends annotation support wrapper to accept and forward pins.
polylogue/schemas/generation/semantic_relations.py Extends semantic+relational annotation to accept pins and pass them to role selection.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +934 to +935
except Exception:
pass
Comment on lines +30 to +36
def _load_pins_safe(provider: str) -> dict[str, set[str]]:
try:
pins = load_pins(provider)
rejected: dict[str, set[str]] = {}
for pin in pins.pins:
if pin.action == "reject":
rejected.setdefault(pin.path, set()).add(pin.role)
except Exception as exc:
logger.exception("MCP tool %s failed", fn_name)
return _json_payload(_exception_error_payload(fn_name, exc), exclude_none=True)
raise PolylogueError(f"{fn_name}: {type(exc).__name__}: {exc}") from exc

with pytest.raises(PolylogueError) as exc:
_safe_call("test_tool", failing)
assert "Traceback" not in str(exc.value)
Comment on lines +919 to +933
try:
from polylogue.daemon.events import emit_daemon_event

emit_daemon_event(
"ingestion_batch",
payload={
"elapsed_s": round(batch_summary.elapsed_s, 2),
"records": batch_summary.raw_record_count,
"blob_mb": round(batch_summary.total_blob_mb, 1),
"conversations": batch_summary.total_convos,
"messages": batch_summary.total_msgs,
"changed_conversations": len(batch_summary.changed_conversation_ids),
"workers": batch_summary.worker_count,
},
)
Comment on lines +33 to +37
rejected: dict[str, set[str]] = {}
for pin in pins.pins:
if pin.action == "reject":
rejected.setdefault(pin.path, set()).add(pin.role)
return rejected
Comment on lines +31 to +39
try:
pins = load_pins(provider)
rejected: dict[str, set[str]] = {}
for pin in pins.pins:
if pin.action == "reject":
rejected.setdefault(pin.path, set()).add(pin.role)
return rejected
except Exception:
return {}
Sinity added a commit that referenced this pull request May 7, 2026
, #774, #777) (#797)

Fix 3 gaps found by adversarial audit: MCP _safe_call now raises
PolylogueError so FastMCP sets isError=True; emit ingestion_batch events
from ingest pipeline; thread pins through annotation call chain.

Co-authored-by: Claude Opus 4.7 <[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.

2 participants