Repository navigation
refactor(api): typed import operation contract — Operations pattern foundation (#1247) - #1316
Conversation
…oundation Introduces the reusable typed Operation contract called out in #1247, plus the first concrete instance for import operations. The contract is the strategic foundation for the Operations pattern that #845 (convergence), #996 (maintenance), and #999 (health) will consume so each slice does not invent its own scheduling envelope. New modules: - polylogue/operations/operation_contract.py: OperationRequest, OperationAck, OperationFollowUp, OperationStatus — frozen Pydantic models with extra=forbid, byte-stable JSON serialization, and an operation_kind class variable contract for subclasses. - polylogue/operations/import_operations.py: ImportRequest declares source_path / source_name / staged_path / idempotency_key; ImportAck pins kind=IMPORT via accept_import / reject_import / pending_import factories. The existing dataclass ImportOperation in import_contracts.py (terminal result envelope) is unchanged and continues to flow through CLI ingest, daemon HTTP, and the write-surface contracts; subsequent slices wire surfaces to accept ImportRequest at admission. Tests: tests/unit/operations/test_operation_contract.py covers serialization, validation (extra=forbid, frozen, required fields), factory helpers, JSON roundtrip, kind/status enum stability, and the _require_operation_kind contract for subclass declarations. Closes #1247.
|
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 (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: 08470817a7
ℹ️ 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".
Closes #1322, #1248. Per audit #1322, address all seven findings in one coherent PR. F1 (Operations contract — #1247/#1316): wire it. daemon /api/ingest now validates request bodies through ImportRequest and emits ImportAck with the shared OperationFollowUp envelope. Legacy wire keys (path, status, ok) are preserved so the CLI ingest adapter and existing HTTP clients keep working. polylogue/daemon/http.py:1574-1630. F2 (api/cli/mcp read-surface adapters): delete. The Python API, CLI, and MCP do not go through dedicated adapter envelopes — they hand-roll richer envelopes inline (daemon/http.py:_do_list with target_ref/anchor/actions/repo/cwd/flags and mcp/server_tools.py). Wiring inline-handrolled envelopes through the bare adapter envelope would lose information. TUIReadSurface stays — it is used by polylogue/ui/tui/screens/{browser,search}.py. F4 (ContractEvidenceRecorder): delete. No non-test consumer existed. Removed tests/infra/contract_evidence.py + ~17 test call sites + the matching devtools dashboards/loaders that aggregated artifacts from .cache/verification/evidence/. F6 (verify-cross-cuts): delete. Verifier and generator share the same naming convention; the lint was a tautology. Removed from devtools/command_catalog.py, devtools/verify.py chain, and devtools/evidence_dashboard.py static-gate list. cross_cut_tags() in build_topology_projection.py is kept because verify-topology still consumes the generated tags. F7 (insights/provenance helpers): wire. daemon insights browser profile panel (#1018/#1120) now passes the SessionProfileRecord through is_stale() against the conversation updated_at and exposes the typed verdict as a `staleness` field on the panel. F3, F5: out of scope per audit guidance. Verification: - devtools verify --quick → exit 0 (34s) - pytest -q --ignore=tests/integration → 8022 passed, 2 xfailed (117s) - Two pre-existing local-env failures from a live daemon were deselected (tests/unit/cli/test_init.py::test_status_first_run_hint_suggests_init, tests/unit/cli/test_status.py::TestNoArchiveStatus::test_status_subprocess_no_archive); both failed identically against origin/master. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
## Summary Address all seven findings from the verifiability quality audit in #1322 in one coherent PR. Wire what has a real consumer, delete what is inert, and land #1248 (daemon `/api/ingest` as the first Operations consumer) in the same slice so the contract introduced in #1316 is no longer a foundation-without-consumer. ## Problem #1322 audited the open + closed issue corpus, codebase, and tests for hollow abstractions, inert tests, puppeteered scenarios, and naming theatre. Seven high-confidence findings (F1–F7). F1 specifically called out that PR #1316 had landed the Operations contract substrate without any production consumer; #1248 (daemon `/api/ingest`) was the obvious wiring target but still open. This PR resolves the audit by routing each finding through one of three disposals: wire, delete, or leave-as-out-of-scope per the audit's own guidance. ## Solution Per-finding actions: - **F1 Operations contract (PR #1316) → WIRE.** `polylogue/daemon/http.py`'s `/api/ingest` now validates request bodies through `ImportRequest` and emits `ImportAck` with the shared `OperationFollowUp` envelope. Legacy wire keys (`path`, `status`, `ok`) are preserved so the CLI ingest adapter and existing HTTP clients keep working. Closes #1248. - **F2 read-surface adapters → DELETE.** `polylogue/api/contracts/{api,cli,mcp}_surface.py` removed. The real Python API, CLI, and MCP code paths do not go through these adapter envelopes — they hand-roll richer envelopes inline (`daemon/http.py:_do_list` carries `target_ref/anchor/actions/repo/cwd/flags`; `mcp/server_tools.py` has its own envelope). Wiring inline-handrolled envelopes through the bare adapter envelope would lose information. `TUIReadSurface` stays — used by `polylogue/ui/tui/screens/{browser,search}.py`. - **F4 `ContractEvidenceRecorder` → DELETE.** No non-test consumer. Removed `tests/infra/contract_evidence.py` + call sites + the matching devtools dashboards/loaders that aggregated artifacts from `.cache/verification/evidence/`. - **F6 `verify-cross-cuts` → DELETE.** Verifier and generator share the same naming convention; the lint was a tautology. Removed from `devtools/command_catalog.py`, the `devtools verify` chain, and `devtools/evidence_dashboard.py`. `cross_cut_tags()` in `build_topology_projection.py` is kept because `verify-topology` still consumes the generated tags. - **F7 insights provenance helpers → WIRE.** Daemon insights browser profile panel (#1018/#1120) now passes the `SessionProfileRecord` through `is_stale()` against the conversation `updated_at` and exposes the typed verdict as a `staleness` field on the panel. - **F3, F5 → out of scope** per audit guidance. ## Verification - `python -m devtools verify --quick` → exit 0 (39s) - `pytest -q --ignore=tests/integration` → **8062 passed, 2 xfailed** (105.75s) ## Notes Closes #1322, #1248. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
|
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
Lands the typed Operation contract called out in #1247 as the strategic
foundation for the broader Polylogue Operations pattern, plus the first
concrete instance for import operations. The contract is additive — no
existing surface is rewired in this slice; #1248/#1249/#1250 will wire
adapters to accept
ImportRequestand emitImportAck.Problem
The audit issue notes that there is no named import operation contract.
CLI ingest, daemon HTTP
/api/ingest, live watcher, convergencestages, and MCP IndexService each carry their own scheduling/result
semantics, and the same gap applies to maintenance (#996),
convergence (#845), and health (#999). Without a shared typed contract,
every future Operation invents its own request/ack envelope.
Solution
Two new modules under
polylogue/operations/and one test module.operation_contract.py— the reusable foundation:OperationStatus: closed string enum (accepted,rejected,pending,running,completed,failed).OperationFollowUp:status_endpoint/status_token/poll_after_ms— the polling triple every client needs after anack.
OperationRequest: frozen Pydantic base withextra=forbidandan
operation_kindClassVarcontract._require_operation_kindrejects subclasses that forget to declare their kind.
OperationAck:operation_id,kind,status,message,error,follow_up— the single shape every client parses.Factory helpers
accepted/rejected/pending.import_operations.py— the first instance:ImportRequestdeclares the refactor(api): typed import operation contract — request/result models (#861 slice A) #1247-required scheduling fieldsexplicitly:
source_path,source_name, optionalstaged_path,optional
idempotency_key.operation_kindpinned toOperationKind.IMPORT.ImportAckextendsOperationAckwithaccept_import/reject_import/pending_importfactories that pin the kind socallers do not have to.
Both modules carry design-notes docstrings that describe how the same
contract maps onto maintenance (#996), convergence (#845), and schema
upgrades — so the next slice has the prior-art reference inline.
The existing dataclass
ImportOperationinimport_contracts.py(terminal result envelope, consumed by
polylogue/api/contracts/*,polylogue/cli/commands/ingest.py,polylogue/daemon/http.py) isunchanged. The two layers compose:
ImportRequestadmits work,ImportAckreturns the scheduling response,ImportOperationre-emits the terminal result envelope once the work completes.
Verification
devtools verify --quick— exit_code 0 (pre-push hook).Focused pytest:
The new
test_operation_contract.pyadds 25 unit tests covering:OperationFollowUpconstruction, JSON shape,extra=forbid,frozen-after-construction.
ImportRequestminimal/full construction, missing-field rejection,extra=forbid, frozen, JSON roundtrip.ImportAckfactories (accept/reject/pending) — status, kind,follow_up, error wiring.
OperationAckto_dict for accepted and rejected,model_validateroundtrip, byte-stable enum serialization.
_require_operation_kindcontract:ImportRequestdeclares,subclass without
operation_kindraisesTypeError, customsubclass with maintenance kind works.
OperationStatusenum value set is closed.Topology projection regenerated via
devtools build-topology-projection;docs/topology-status.mdre-rendered.Closes #1247.