Skip to content

feat(api): expose annotation batch import - #2782

Merged
Sinity merged 4 commits into
masterfrom
feature/fanout/api-parity
Jul 12, 2026
Merged

Sinity merged 4 commits into
masterfrom
feature/fanout/api-parity

Conversation

@Sinity

@Sinity Sinity commented Jul 12, 2026 •

Copy link
Copy Markdown
Owner

Summary

This PR audits the Python facade against the current CLI and MCP operation
surface, fixes the confirmed typed annotation-batch import gap, and records the
remaining work as proposals rather than claiming unimplemented governance.

Problem

Polylogue lacked import_annotation_batch, although both CLI and MCP exposed
the bounded shared operation. The library therefore required callers to bypass
the promised facade. The audit also found that the existing parity manifest
cannot govern semantic operation bindings or API documentation drift.

Solution

  • Add Polylogue.import_annotation_batch(request, *, registry=None).
  • Use the active archive root for the shared importer, matching facade reads
    when db_path and configured archive_root differ.
  • Add a real-route API test covering schema validation, evidence resolution,
    candidate persistence, and the split-root write boundary.

Capability matrix

A dash means no equivalent implementation was found in that surface. It is not
an intention claim without a governed binding. Operation names are source-audit
identifiers; they must become a checked-in generated manifest in the follow-up.

Shared archive/query/read

Operation CLI MCP Python API Status
session search/list/read find / read search, list_sessions, archive_get_session search, list_sessions, get_session aligned
messages read --view messages get_messages get_messages_paginated, bulk_get_messages aligned
raw artifacts read --view raw raw_artifacts get_raw_artifacts_for_session aligned
session tree/topology — get_session_tree, get_session_topology same MCP/API-only navigation reads
logical session — get_logical_session same MCP/API-only read pull
neighbors/correlation read --view neighbors/correlation neighbor_candidates, correlate_* same aligned
unit DSL / observed events find … then read query_units query_units aligned
explain/completions/facets find --explain, config query-completions, facets matching tools matching methods aligned
stats/readiness status, analyze, ops status stats, readiness_check stats, health_check domain-aligned; presentation differs
context image/preamble read --view context-image, continue build_context_image, compose_context_preamble context_image_payload, context_preamble_payload aligned
import explanation import --explain explain_import explain_import aligned

User state and annotations

Operation family CLI MCP Python API Status
tags / marks mark list/add/remove, bulk_tag_sessions matching list/add/remove/bulk methods aligned
annotations read, mark, delete list_annotations, save_annotation, delete_annotation matching methods aligned
typed annotation batch annotations import import_annotation_batch import_annotation_batch fixed here
typed annotation join annotations join join_typed_annotations same aligned
assertion candidates mark candidates * — list/judge/review methods CLI/API workflow; MCP excludes broad review writes
metadata / saved views read, mark, delete matching tools matching methods aligned
recall packs / workspaces continue, dashboard, delete matching tools matching methods aligned
corrections — record/list/clear tools record/list/clear methods intentional agent/API feedback path
blackboard agents *, agents handoff list/post tools list/post methods aligned

Insights, index, and maintenance

Operation family CLI MCP Python API Status
insight readers analyze insights * profiles, work-events, phases, threads, tags, coverage matching get/list methods aligned
costs / usage / debt analyze insights *, analyze usage costs, rollups, timeline, debt, usage matching list/report methods aligned
analysis analyze pace/turns, continue latency, stuck, workflow, abandoned, resume, postmortem, pathology matching methods aligned
insight rigor/rebuild/export ops insights * rigor audit, rebuild audit/rebuild/export methods CLI/API export is intentional
session tool timing aggregate analyze tools session_tool_timing — deferred: split-tier typed contract required
index / embeddings ops maintenance, ops embed * rebuild/update/status/preflight matching methods aligned where safely exposed
parse / configured sources import — parse_file, parse_sources intentional local/daemon API
guarded maintenance ops maintenance * maintenance wrappers — intentional operator-only guardrails
delete session delete delete_session delete_session_safe aligned; confirmation differs

Explicit surface-specific inventory

CLI-only interaction, credentials, lifecycle, backup, reset, GC, and destructive
maintenance commands remain terminal guardrails. MCP-only prompts/resources and
role-gated maintenance wrappers are agent-protocol concerns. Python lifecycle,
raw cursor/write primitives, repository vectors, and SessionFilter are
lower-level library mechanics rather than CLI/MCP capability promises.

Bead acceptance-criteria status

  • Generated, committed capability matrix: deferred. This PR body is a
    review artifact, not a rendered checked-in source of truth.
  • Every drifted row fixed or intentionally documented: deferred. This PR
    fixes annotation-batch import; governed bindings and absences still need the
    follow-up manifest.
  • API-doc symbol check wired into verification: deferred to the documentation
    and devtools proposal.
  • docs/library-api.md accurate against the facade: deferred; it does not
    yet list this new method.

Follow-up proposals

  1. Govern semantic operation IDs in a manifest with per-surface bindings and
    explicit intentional absences; render and drift-check the matrix. Unknown or
    unbound live entries must fail.
  2. Define a canonical typed, tier-safe session-tool-timing contract, then bind
    facade and MCP through it.
  3. Add signature-, asyncness-, and section-aware library API documentation
    verification to the docs/devtools surface, including mutation-sensitive tests.
  4. Consolidate MCP direct ArchiveStore reads behind the facade where DTO
    semantics already match.

Verification

  • TMPDIR=/realm/tmp POLYLOGUE_PYTEST_BASETEMP_ROOT=/realm/tmp/polylogue-pytest nix develop --command devtools test tests/unit/api/test_facade_contracts.py::test_facade_import_annotation_batch_persists_candidate_provenance
    • 1 passed in 11.11s
  • Push hook: devtools verify --quick
    • static/generated gate passed before the current test-only commit.

Anti-vacuity: the test drives the real facade, importer, custom schema registry,
live ref resolver, and user.db writer. Removing facade delegation, enum
validation, live evidence-ref resolution, or active-root persistence makes an
assertion fail.

Ref polylogue-9e5.16.

Problem: annotation-batch import was available through CLI and MCP but Python callers had to bypass the documented facade and import the product operation directly.\n\nWhat changed: bind the shared import operation to Polylogue and cover the real schema, live-reference, and user-tier persistence route.\n\nRef polylogue-9e5.16.\n\nCo-Authored-By: Claude <[email protected]>
@coderabbitai

coderabbitai Bot commented Jul 12, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

@Sinity, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 8 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: ad2f7a2f-8de1-4dfe-b554-f640c9200743

📥 Commits

Reviewing files that changed from the base of the PR and between 901825e and 3771946.

📒 Files selected for processing (2)
  • polylogue/api/archive.py
  • tests/unit/api/test_facade_contracts.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/fanout/api-parity

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.

@Sinity
Sinity marked this pull request as ready for review July 12, 2026 21:27

@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: 62cc332758

ℹ️ 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".

Comment thread polylogue/api/archive.py Outdated
Comment on lines +1847 to +1848
return await import_annotation_batch(cast("Polylogue", self), request)
return await import_annotation_batch(cast("Polylogue", self), request, registry=registry)

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 Honor active archive root when importing annotations

When a Polylogue is opened with db_path pointing at a different archive root than archive_root (a supported mode in this facade), this delegation passes self straight to the importer. The importer persists to Path(poly.archive_root) / "user.db", while resolve_ref and the rest of the archive facade resolve/read against _active_archive_root(self.config), so the import can validate against the active archive but write the batch/assertions into the configured root instead. In that setup the call reports success, but subsequent API reads against the active archive will not see the imported annotations.

Useful? React with 👍 / 👎.

Sinity added 2 commits July 12, 2026 23:50
Problem: a facade opened with a db path under a different archive root validated annotation references against the active archive but persisted user state under the configured root.\n\nWhat changed: bind the importer to the facade's active archive root while retaining real facade reference resolution, and cover the split-root route.\n\nRef polylogue-9e5.16.\n\nCo-Authored-By: Claude <[email protected]>
Problem: the facade import test asserted only an admitted candidate, so it\ncould not prove schema and live-reference rejection.\n\nWhat changed: include invalid enum and unresolved evidence rows in the real\nfacade route, then assert both failure causes and partial persistence.\n\nRef polylogue-9e5.16.
@Sinity

Sinity commented Jul 12, 2026

Copy link
Copy Markdown
Owner Author

Adversarial review iteration 1

Findings and fixes:

  • Fixed a real test-coverage gap in a1e505788: the production-route facade test now includes an invalid enum and unresolved evidence ref, and asserts both rejection errors. It still proves delegation and that the active DB root, rather than configured root, receives the user.db write.
  • Source review corrected the matrix evidence: the CLI raw-artifact route is read --view raw; there are no read --view tree or read --view topology profiles. These two are MCP/API-only navigation reads, not evidence of a missing Python binding.
  • The remaining bead criteria are not silently claimed as complete: a checked-in governed matrix, API-doc verifier, and docs/library-api.md update remain deferred outside this lane’s owned polylogue/api/ and tests/unit/api/ paths. The PR body’s follow-up proposals describe the needed matrix governance and documentation work.

Verification:

  • TMPDIR=/realm/tmp POLYLOGUE_PYTEST_BASETEMP_ROOT=/realm/tmp/polylogue-pytest nix develop --command devtools test tests/unit/api/test_facade_contracts.py::test_facade_import_annotation_batch_persists_candidate_provenance
    • 1 passed in 11.11s

What survived scrutiny:

  • The active-root adapter is necessary and is exercised by a split configured/archive-root test.
  • The previous inline active-root review finding is fixed by 13274c048.
  • The prior GitHub Actions init-only failures match the known account-billing infrastructure pattern and were not treated as code failures.

Ref polylogue-9e5.16.

Problem: the facade's default registry branch was not exercised.\n\nWhat changed: import a candidate through the production delegation schema\nwithout a registry argument, proving the importer default remains selected.\n\nRef polylogue-9e5.16.
@Sinity

Sinity commented Jul 12, 2026

Copy link
Copy Markdown
Owner Author

Adversarial review iteration 2

Finding fixed:

  • 3771946b2 adds a separate real-route test for the registry is None branch. It imports a valid candidate through the registered production delegation.discourse@v1 schema without supplying registry=. Forwarding None instead of omitting the importer keyword now fails this test.
  • Restored the PR body after the failed editor pipeline, with required Summary/Problem/Solution/Verification sections, the capability matrix, deferred acceptance-criteria status, and proposals.

Verification:

  • TMPDIR=/realm/tmp POLYLOGUE_PYTEST_BASETEMP_ROOT=/realm/tmp/polylogue-pytest nix develop --command devtools test tests/unit/api/test_facade_contracts.py::test_facade_import_annotation_batch_persists_candidate_provenance tests/unit/api/test_facade_contracts.py::test_facade_import_annotation_batch_uses_default_registry
    • 2 passed in 10.11s
  • Push hook: devtools verify --quick completed its static/generated gates before the remote update.

What survived scrutiny:

  • The split-root adapter, custom-registry validation/evidence failures, and default production-registry branch are now separately covered.
  • Bead-level generated-matrix, doc-verifier, and library-api.md criteria remain deferred and are explicitly marked that way in the restored PR body.

Ref polylogue-9e5.16.

@Sinity

Sinity commented Jul 12, 2026

Copy link
Copy Markdown
Owner Author

Adversarial review iteration 3 — zero new findings

Completed the required hostile pass: fetched origin, reviewed git diff origin/master...HEAD, re-read polylogue-9e5.16 including rejection notes, and checked PR body plus all review comments. The only substantive inline review is the already-fixed active-root defect; CodeRabbit remains rate-limited; the known GitHub Actions init-only billing failure pattern was ignored as directed.

A fresh independent cold reviewer reported: No legitimate gaps found.

No code change was required in this iteration. The API route remains covered by the split-root custom-registry validation/evidence test and the default production-registry test.

Ref polylogue-9e5.16.

@Sinity

Sinity commented Jul 12, 2026

Copy link
Copy Markdown
Owner Author

Final acceptance-criteria matrix for polylogue-9e5.16

Acceptance criterion Status Evidence / destination
Capability matrix generated and committed as rendered doc Deferred-to-bead polylogue-s1kr owns a semantic-ID manifest, renderer, and drift check. This PR body is a review artifact only.
Every drifted row fixed or intentionally documented Deferred-to-bead This PR fixes annotation-batch-import; polylogue-s1kr must govern all remaining bindings and intentional absences. session-tool-timing remains deferred pending its split-tier typed contract.
API-doc symbol check wired into verify Deferred-to-bead polylogue-s1kr owns signature, asyncness, and non-empty-section verification wired into devtools.
docs/library-api.md accurate against live facade Deferred-to-bead polylogue-s1kr owns the documentation update, including import_annotation_batch.

No criterion is misframed. The tractable in-lane runtime gap is satisfied by commits 62cc33275, 13274c048, a1e505788, and 3771946b2; this PR intentionally does not claim to close the bead.

Ref polylogue-9e5.16. Ref polylogue-s1kr.

@Sinity
Sinity merged commit 52b77aa into master Jul 12, 2026
3 of 14 checks passed
@Sinity
Sinity deleted the feature/fanout/api-parity branch July 12, 2026 23:37
Sinity added a commit that referenced this pull request Jul 13, 2026
…800,2781

2ilz (origin-interop, PR #2794), 3v1.1 (capture-hardening, PR #2785), and
qqyg (hooks-capture, PR #2781) fully satisfied — closed. 9e5.16 (api-parity,
PR #2782), 57rp/5k5l (capture-hardening, PR #2785), and 7fj (beads-ingest,
PR #2800) partially satisfied — noted with disposition, left open.

Co-Authored-By: Claude <[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.

1 participant