Skip to content

refactor(ingest): define shared import operation contracts (#861) - #883

Merged
Sinity merged 1 commit into
masterfrom
feature/refactor/import-contracts-861
May 7, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/refactor/import-contracts-861

Conversation

@Sinity

@Sinity Sinity commented May 7, 2026

Copy link
Copy Markdown
Owner

Summary

Defines typed ImportOperation, RawFailureSample, and bounded_failure_samples contracts 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

Verification

  • devtools verify --quick — all 14 gates passed
  • 5 files, +151/-10
  • Topology projection updated

Refs #861 #852

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]>
Copilot AI review requested due to automatic review settings May 7, 2026 07:02
@Sinity
Sinity merged commit 73c7824 into master May 7, 2026
@Sinity
Sinity deleted the feature/refactor/import-contracts-861 branch May 7, 2026 07:02
@coderabbitai

coderabbitai Bot commented May 7, 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 45 minutes and 38 seconds before requesting another review.

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 @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: d97223ba-2291-47d5-a758-bf5e8d705c07

📥 Commits

Reviewing files that changed from the base of the PR and between 9246930 and d3479c2.

📒 Files selected for processing (6)
  • docs/plans/topology-target.yaml
  • docs/topology-status.md
  • polylogue/daemon/http.py
  • polylogue/operations/__init__.py
  • polylogue/operations/import_contracts.py
  • polylogue/operations/specs.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/refactor/import-contracts-861

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.

@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: 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)),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

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

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 IMPORT and MAINTENANCE to the OperationKind enum.
  • Introduced polylogue/operations/import_contracts.py with ImportOperation, RawFailureSample, and bounded_failure_samples.
  • Updated daemon /api/ingest handler to return ImportOperation.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.

Comment on lines +86 to +93
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)),
)
Comment on lines +27 to +53
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
Sinity added a commit that referenced this pull request May 7, 2026
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
Sinity added a commit that referenced this pull request May 7, 2026
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
Sinity added a commit that referenced this pull request May 7, 2026
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
Sinity added a commit that referenced this pull request May 7, 2026
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
Sinity added a commit that referenced this pull request May 7, 2026
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
Sinity added a commit that referenced this pull request May 7, 2026
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
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