Repository navigation
refactor(ingest): define shared import operation contracts (#861) - #883
Conversation
Add typed ImportOperation, RawFailureSample, and bounded_failure_samples to polylogue/operations/import_contracts.py. Daemon HTTP ingest handler now returns ImportOperation.pending() instead of a hand-shaped dict. Add IMPORT and MAINTENANCE to OperationKind enum. Refs #861 #852 Co-Authored-By: Claude Opus 4.7 <[email protected]>
|
Warning Rate limit exceeded
To continue reviewing without waiting, purchase usage credits 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 (6)
✨ 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 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d3479c216a
ℹ️ 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".
| source_path=s.get("source_path"), | ||
| error_class=s.get("error_class"), | ||
| redacted_text=s.get("redacted_text"), | ||
| attempt_count=int(s.get("attempt_count", 1)), |
There was a problem hiding this comment.
Guard attempt_count parsing against non-numeric inputs
ImportOperation.from_dict currently coerces each sample's attempt_count using int(...) without error handling. If any producer sends attempt_count as null, an empty string, or another non-numeric value (which is plausible for cross-surface JSON contracts), this raises and aborts deserialization of the entire operation payload instead of falling back to the default count. Since this method is intended as a shared adapter boundary, one malformed sample should not make the whole response unusable.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Pull request overview
This PR introduces a shared, typed contract for “import” and “maintenance” operation results so that CLI ingest, daemon HTTP ingest scheduling, live watcher, and MCP maintenance can converge on one payload/model shape rather than hand-rolled dicts.
Changes:
- Added
IMPORTandMAINTENANCEto theOperationKindenum. - Introduced
polylogue/operations/import_contracts.pywithImportOperation,RawFailureSample, andbounded_failure_samples. - Updated daemon
/api/ingesthandler to returnImportOperation.pending(...).to_dict()and updated topology docs to include the new module.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| polylogue/operations/specs.py | Extends OperationKind with import/maintenance kinds. |
| polylogue/operations/import_contracts.py | Adds typed operation envelope + bounded failure sample helpers. |
| polylogue/operations/init.py | Re-exports the new import contract types/helpers from polylogue.operations. |
| polylogue/daemon/http.py | Switches /api/ingest response to the new ImportOperation contract. |
| docs/topology-status.md | Updates generated topology counts after adding the new module. |
| docs/plans/topology-target.yaml | Adds the new operations module to the topology target plan. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| samples = [ | ||
| RawFailureSample( | ||
| raw_id=str(s.get("raw_id", "")), | ||
| source_path=s.get("source_path"), | ||
| error_class=s.get("error_class"), | ||
| redacted_text=s.get("redacted_text"), | ||
| attempt_count=int(s.get("attempt_count", 1)), | ||
| ) |
| def bounded_failure_samples( | ||
| failures: dict[str, str], | ||
| *, | ||
| source_path: str | None = None, | ||
| max_samples: int = 50, | ||
| ) -> list[RawFailureSample]: | ||
| """Convert a raw_id→error dict into bounded, typed failure samples.""" | ||
| samples: list[RawFailureSample] = [] | ||
| for raw_id, error_text in failures.items(): | ||
| if len(samples) >= max_samples: | ||
| break | ||
| error_class: str | None = None | ||
| redacted: str | None = None | ||
| if error_text: | ||
| # Derive a short error class from the first line | ||
| first_line = error_text.split("\n")[0].strip() | ||
| error_class = first_line[:120] + "..." if len(first_line) > 120 else first_line | ||
| redacted = error_text[:500] if len(error_text) > 500 else error_text | ||
| samples.append( | ||
| RawFailureSample( | ||
| raw_id=raw_id, | ||
| source_path=source_path, | ||
| error_class=error_class, | ||
| redacted_text=redacted, | ||
| ) | ||
| ) | ||
| return samples |
Closes the contract slice of #861. CLI ingest, daemon HTTP, live watcher, and MCP maintenance each used hand-shaped dicts: daemon HTTP returned `{"ok": True, ...}`, CLI deserialized raw JSON, MCP had its own mutation shapes. - `polylogue/operations/__init__.py`: adds `IMPORT` and `MAINTENANCE` to `OperationKind`. - `polylogue/operations/import_contracts.py` (new): typed `ImportOperation`, `RawFailureSample` (shared with #844), and `bounded_failure_samples()`. `ImportOperation` exposes `pending()`, `to_dict()`, and `from_dict()` so every entrypoint can produce / consume the same envelope. - `polylogue/operations/specs.py`: registers the new specs alongside the existing read/mutation entries. - `polylogue/daemon/http.py`: `_handle_ingest()` now returns `ImportOperation.pending().to_dict()` instead of the ad-hoc dict. Refs #844, #861
Three small slices for the user-facing CLI, the import- contract migration, and storage FK invariants. - #825 (bare CLI status): `polylogue/cli/click_app.py` wires bare `polylogue` (no subcommand) to `show_fast_status()` so the no-arg invocation matches the `polylogue status` command, satisfying #825's fast-feel acceptance criterion. - #861 (import contract): `polylogue/cli/commands/ingest.py` parses incoming JSON through `ImportOperation.from_dict()` instead of bespoke kwargs, sharing the typed contract from PR #883 with daemon HTTP and the live watcher. - #881 (FK regression): `tests/unit/storage/test_backend.py` adds a `parent_message_id` FK regression test pinning the `NO ACTION` policy from PR #881. Refs #825, #861, #881
Adds the per-entrypoint inventory called for by #861's import and maintenance operation contracts. Without it, future PRs had to rediscover which surface owned which path: CLI ingest, daemon HTTP, the live watcher, and MCP maintenance each had different expectations. - `polylogue/operations/import_contracts.py` gains a per-entrypoint table classifying each path as CANONICAL, ADAPTER, LOW_LEVEL, or NOT_YET_ADAPTED so the typed `ImportOperation` contract from PR #883 has a published inventory of its consumers. Refs #861
Closes the contract slice of #861. CLI ingest, daemon HTTP, live watcher, and MCP maintenance each used hand-shaped dicts: daemon HTTP returned `{"ok": True, ...}`, CLI deserialized raw JSON, MCP had its own mutation shapes. - `polylogue/operations/__init__.py`: adds `IMPORT` and `MAINTENANCE` to `OperationKind`. - `polylogue/operations/import_contracts.py` (new): typed `ImportOperation`, `RawFailureSample` (shared with #844), and `bounded_failure_samples()`. `ImportOperation` exposes `pending()`, `to_dict()`, and `from_dict()` so every entrypoint can produce / consume the same envelope. - `polylogue/operations/specs.py`: registers the new specs alongside the existing read/mutation entries. - `polylogue/daemon/http.py`: `_handle_ingest()` now returns `ImportOperation.pending().to_dict()` instead of the ad-hoc dict. Refs #844, #861
Three small slices for the user-facing CLI, the import- contract migration, and storage FK invariants. - #825 (bare CLI status): `polylogue/cli/click_app.py` wires bare `polylogue` (no subcommand) to `show_fast_status()` so the no-arg invocation matches the `polylogue status` command, satisfying #825's fast-feel acceptance criterion. - #861 (import contract): `polylogue/cli/commands/ingest.py` parses incoming JSON through `ImportOperation.from_dict()` instead of bespoke kwargs, sharing the typed contract from PR #883 with daemon HTTP and the live watcher. - #881 (FK regression): `tests/unit/storage/test_backend.py` adds a `parent_message_id` FK regression test pinning the `NO ACTION` policy from PR #881. Refs #825, #861, #881
Adds the per-entrypoint inventory called for by #861's import and maintenance operation contracts. Without it, future PRs had to rediscover which surface owned which path: CLI ingest, daemon HTTP, the live watcher, and MCP maintenance each had different expectations. - `polylogue/operations/import_contracts.py` gains a per-entrypoint table classifying each path as CANONICAL, ADAPTER, LOW_LEVEL, or NOT_YET_ADAPTED so the typed `ImportOperation` contract from PR #883 has a published inventory of its consumers. Refs #861
Summary
Defines typed
ImportOperation,RawFailureSample, andbounded_failure_samplescontracts shared by CLI ingest, daemon HTTP, live watcher, and MCP maintenance.Problem
Multiple write/import paths used hand-shaped dicts with no shared contract: daemon HTTP returned
{"ok": True, ...}, CLI deserialized raw JSON, MCP had its own mutation shapes.Solution
IMPORTandMAINTENANCEtoOperationKindenumpolylogue/operations/import_contracts.pywith typed models_handle_ingest()now returnsImportOperation.pending().to_dict()RawFailureSamplewith bounded error reporting (shared with fix(daemon): surface raw validation and parse failures in ingest/status #844)Verification
devtools verify --quick— all 14 gates passedRefs #861 #852