Repository navigation
refactor(api): formalize shared write-surface contracts (#861) - #1107
Conversation
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the 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 configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (8)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Mirror of #859/#1099 for the write/import/maintenance side of polylogue. Introduces a typed Protocol family in `polylogue/api/contracts/write_surface.py` covering ingest scheduling, maintenance backfills, FTS index maintenance, tag mutations, and conversation delete, plus three adapter modules (api/cli/mcp_write_surface.py) with import-time `assert_implements` pins so any signature drift fails `mypy --strict`. Adds `tests/unit/api/test_write_surface_contracts.py` covering static conformance (every adapter implements every protocol) and runtime envelope parity (TagMutationResult, BackfillOperation, ImportOperation shapes match across API/CLI/MCP for tag mutation, dry-run maintenance, and missing-path ingest). Refs #861
576aed4 to
ea38980
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 576aed4ce2
ℹ️ 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".
|
Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.
Only the rows listed above are dispositioned. Held findings remain open. |
Summary
Mirror of #859/#1099 for the write/import/maintenance side. Defines a typed
Protocolfamily inpolylogue/api/contracts/write_surface.pyand threeadapter modules (api/cli/mcp_write_surface.py) with import-time
assert_implementspins so any signature drift failsmypy --strict. Addsruntime envelope-parity contract tests.
Problem
#859 landed read-surface protocol contracts (
ConversationListSurface,ReadSurface, etc.) so CLI, MCP, daemon HTTP, and Python API adapters cannotdrift apart on read semantics. The write/import/maintenance side had no
equivalent contract: CLI ingest stages into
archive_root/inboxand POSTs tothe daemon, MCP maintenance instantiates
IndexService-adjacent helpers whileCLI maintenance routes through
execute_backfill, andPolylogue.parse_file/
parse_sourcesbypass the operation boundary entirely. There was no namedoperation contract telling agents which behavior is canonical or which
adapters are allowed to do direct pipeline/service work — exactly the gap
called out in #861.
Solution
polylogue/api/contracts/write_surface.py(new) — five@runtime_checkableProtocols plus a composite:IngestSurface.ingest_path(path) -> ImportOperation— typed importenvelope with
operation_id/status/ boundedraw_failure_samples.Adapters that cannot reach the daemon must surface
status="failed"witha populated
errorfield rather than silently downgrading to "scheduled".MaintenanceSurface.run_maintenance(targets, *, dry_run) -> BackfillOperation— delegates to the shared
execute_backfillplanner so adapters share thesame target vocabulary (
MAINTENANCE_TARGET_NAMES).IndexMaintenanceSurface.rebuild_index() / update_index(ids)— routesthrough
ArchiveOperationsand the sharedindexingfree functions.TagMutationSurface.add_tag / remove_tag -> TagMutationResult— write-sidecounterpart to the read-side
ConversationTagsSurface.ConversationDeleteSurface.delete_conversation(id) -> bool.WriteSurfacefor callers that want the full union.Three adapter modules —
api_write_surface.py,cli_write_surface.py,mcp_write_surface.py— each carryassert_implements(Adapter, Protocol)calls at module scope (the same mechanism used by the read-surface family).
The CLI/MCP adapters take an optional
polyloguefacade for tag/deletemutations so they do not own a parallel runtime.
Tests in
tests/unit/api/test_write_surface_contracts.pycover:issubclass, plus the compositeWriteSurface.TagMutationResultoutcome vocabulary(
added→no_op→removed→not_presentacross API/CLI/MCP),BackfillOperationenvelope shape from dry-run maintenance, andImportOperationtruthfulness for a missing path (status="failed"withpopulated
error). Each test records boundedcontract_evidence.Non-goals (deferred):
adapters — that is the broader surgery refactor(ingest): define shared import and maintenance operation contracts #861 calls for. This PR formalizes
the contract surface that the rewiring will land against, and proves
envelope shapes match across the existing implementations.
Polylogue.parse_file/parse_sourcesare kept as low-level pipelinehelpers; this is documented in the protocol docstrings and in
import_contracts.py. TheAPIWriteSurface.ingest_pathadapter wrapsthem with a typed
ImportOperationenvelope so callers see one shape.Verification
Ref #861