Repository navigation
fix(schemas): exempt message_role fields from privacy threshold, wire detect_drift into audit (#800) - #921
Conversation
|
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 (7)
✨ 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 |
… detect_drift into audit (#800) - Add _STRUCTURAL_ROLE_VALUES set in field_annotations.py: when a field has x-polylogue-semantic-role="message_role", bypass the cross-conversation privacy threshold (min_conversation_count=3), using min=1 instead. This preserves protocol-level tokens like record types that were being suppressed. - Add check_schema_drift() audit check that loads live samples from the archive DB and runs detect_drift() against committed schemas. - Wire --check-drift flag into devtools schema-audit to surface drift from committed schema packages. - Add TestStructuralRoleExemption with two tests verifying that message_role field values survive min_conversation_count=3 while non-role fields are still correctly filtered. Co-Authored-By: Claude Opus 4.7 <[email protected]>
acc63b7 to
e84c519
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: acc63b7ed1
ℹ️ 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".
| return [] | ||
|
|
||
| async def _query(ops: _ArchiveOperations) -> list[CompletionItem]: | ||
| conversations = await ops.list_conversations(limit=100) |
There was a problem hiding this comment.
Query conversation completions before applying hard cap
This now fetches only the first 100 conversations and then filters in Python, so archives with more than 100 conversations can no longer complete older IDs/titles even when they match the user’s prefix. The previous SQL path filtered at the database level before applying the completion limit, so matching rows outside a recency window were still discoverable; with ops.list_conversations(limit=100) they are silently excluded.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Pull request overview
This PR addresses schema-generation and audit correctness by preserving structural message_role enum values under strict privacy thresholds, and by wiring live-data drift detection into the schema audit tooling. It also refactors the Textual TUI and some CLI completion paths to route reads through ArchiveOperations rather than direct repository/SQL access.
Changes:
- Exempt
x-polylogue-semantic-role="message_role"fields from the cross-conversation privacy threshold when emittingx-polylogue-values. - Add
--check-drifttodevtools schema-audit, loading DB samples and runningdetect_drift()against committed schemas. - Refactor TUI screens and shell completions to use
ArchiveOperationsinstead of calling repository/SQL methods directly; update the async facade to delegate raw-artifact reads through operations.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/core/test_schema_privacy.py | Adds regression tests proving message_role values survive min_conversation_count=3 while non-role enums are filtered. |
| polylogue/schemas/generation/field_annotations.py | Implements the structural-role exemption by lowering effective min_conversation_count for message_role. |
| polylogue/schemas/audit/checks.py | Adds check_schema_drift() (DB sample load + detect_drift() aggregation) and exports it. |
| polylogue/schemas/audit/workflow.py | Threads db_path through audit workflow and conditionally runs drift checks. |
| polylogue/schemas/operator/models.py | Extends SchemaAuditRequest with check_drift and db_path. |
| polylogue/schemas/operator/inference.py | Wires db_path into audit invocation when check_drift is enabled. |
| devtools/schema_audit.py | Adds --check-drift flag and populates SchemaAuditRequest using config db_path. |
| polylogue/ui/tui/screens/base.py | Switches TUI base container injection from repository to ArchiveOperations. |
| polylogue/ui/tui/app.py | Plumbs ArchiveOperations into TUI screens via app constructor. |
| polylogue/ui/tui/screens/dashboard.py | Routes dashboard stats through ArchiveOperations.storage_stats(). |
| polylogue/ui/tui/screens/browser.py | Routes listing/stats through ArchiveOperations (notably list_conversations). |
| polylogue/ui/tui/screens/search.py | Routes search through ArchiveOperations.search() and adjusts error handling. |
| polylogue/cli/commands/dashboard.py | Updates dashboard CLI to pass env.operations into the TUI app. |
| polylogue/cli/shell_completion_values.py | Switches conversation/tag completions to ArchiveOperations via asyncio.run. |
| polylogue/api/archive.py | Delegates raw-artifact retrieval through ArchiveOperations instead of private backend connections. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| def check_schema_drift( | ||
| schema: Mapping[str, object] | SchemaNode, | ||
| *, | ||
| db_path: Path | None = None, | ||
| provider: str = "", |
| unique_drift = list(dict.fromkeys(all_drift)) | ||
| return CheckResult( | ||
| name="schema_drift", | ||
| status=OutcomeStatus.WARNING, | ||
| summary=f"Schema drift detected: {len(unique_drift)} unexpected field(s) in live data", | ||
| details=unique_drift[:50], |
| """Check whether committed schema has drifted from live archive data. | ||
|
|
||
| Loads samples from the database and runs detect_drift() against the | ||
| committed schema. Reports fields present in live data but missing from | ||
| the schema. |
Two-line ordering fix in `polylogue/schemas/generation/schema_builder.py`. The schema-generation pipeline applied the cross-conversation privacy threshold before semantic-role annotation, so values that should have been protected by the `x-polylogue-semantic-role="message_role"` exemption (record types like `attachment`, `system`, `permission-mode`) were dropped before the annotator could mark them as structural. Reorders the steps so semantic-role classification runs first. PR #921 builds on this with the structural-role exemption logic. Refs #800
Closes the remaining schema-audit gap from #800. PR #921 landed the structural-role exemption and `detect_drift()` wiring; the staleness check still had no audit-side caller. - `polylogue/schemas/audit/checks.py`: adds `check_schema_staleness()` reading the committed package manifest dates against the live archive observations. - `polylogue/schemas/audit/workflow.py`: `audit_provider()` invokes the new check inline so `devtools schema-audit` surfaces stale schemas as part of its normal report. Refs #800
Direct, no-PR. Local repair after PR #921 landed: the `__all__` list in `polylogue/schemas/audit/checks.py` still exported `check_schema_drift` from the pre-rename name, but the function landed as `check_schema_drift` only in the new audit module, leaving an import-time `AttributeError` for anyone doing `from ... import *`. Removes the stale entry. Refs #800
Three targeted fixes building on PR #887's schema-pipeline reordering: 1. Fields tagged `x-polylogue-semantic-role="message_role"` now bypass the cross-conversation privacy threshold (`min_conversation_count=3` becomes 1) so structural protocol record-type tokens like `attachment`, `custom-title`, `file-history-snapshot`, `last-prompt`, `permission-mode`, `queue-operation`, `system` survive schema generation. 2. `detect_drift()` is now wired into `devtools schema-audit --check-drift` via a new `check_schema_drift()` audit check that loads samples from the archive DB and runs drift detection against committed schemas. The function existed but no audit tool ever called it. 3. `tests/unit/core/test_schema_privacy.py`: `TestStructuralRoleExemption` proves `message_role` values survive `min=3` while non-role fields stay filtered. End-to-end schema regeneration from live data and full schema-promote remain blocked on the blob-store work in #818. Refs #800
Two-line ordering fix in `polylogue/schemas/generation/schema_builder.py`. The schema-generation pipeline applied the cross-conversation privacy threshold before semantic-role annotation, so values that should have been protected by the `x-polylogue-semantic-role="message_role"` exemption (record types like `attachment`, `system`, `permission-mode`) were dropped before the annotator could mark them as structural. Reorders the steps so semantic-role classification runs first. PR #921 builds on this with the structural-role exemption logic. Refs #800
Closes the remaining schema-audit gap from #800. PR #921 landed the structural-role exemption and `detect_drift()` wiring; the staleness check still had no audit-side caller. - `polylogue/schemas/audit/checks.py`: adds `check_schema_staleness()` reading the committed package manifest dates against the live archive observations. - `polylogue/schemas/audit/workflow.py`: `audit_provider()` invokes the new check inline so `devtools schema-audit` surfaces stale schemas as part of its normal report. Refs #800
Direct, no-PR. Local repair after PR #921 landed: the `__all__` list in `polylogue/schemas/audit/checks.py` still exported `check_schema_drift` from the pre-rename name, but the function landed as `check_schema_drift` only in the new audit module, leaving an import-time `AttributeError` for anyone doing `from ... import *`. Removes the stale entry. Refs #800
Three targeted fixes building on PR #887's schema-pipeline reordering: 1. Fields tagged `x-polylogue-semantic-role="message_role"` now bypass the cross-conversation privacy threshold (`min_conversation_count=3` becomes 1) so structural protocol record-type tokens like `attachment`, `custom-title`, `file-history-snapshot`, `last-prompt`, `permission-mode`, `queue-operation`, `system` survive schema generation. 2. `detect_drift()` is now wired into `devtools schema-audit --check-drift` via a new `check_schema_drift()` audit check that loads samples from the archive DB and runs drift detection against committed schemas. The function existed but no audit tool ever called it. 3. `tests/unit/core/test_schema_privacy.py`: `TestStructuralRoleExemption` proves `message_role` values survive `min=3` while non-role fields stay filtered. End-to-end schema regeneration from live data and full schema-promote remain blocked on the blob-store work in #818. Refs #800
|
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
Three targeted fixes building on PR #887 (pipeline reordering):
message_role fields exempt from privacy threshold: When a field has
x-polylogue-semantic-role="message_role", the cross-conversation privacythreshold (
min_conversation_count=3) is bypassed (usesmin=1). Thispreserves protocol-level record type tokens that were being suppressed.
detect_drift()wired intodevtools schema-audit --check-drift: Newcheck_schema_drift()audit check loads samples from the archive DB and runsdetect_drift()against committed schemas.Tests:
TestStructuralRoleExemptionverifies thatmessage_rolevaluessurvive
min_conversation_count=3while non-role fields are correctly filtered.Problem
The #800 audit found that Claude Code record type values were suppressed from
committed schemas because the privacy threshold treated structural protocol-level
tokens identically to user content.
detect_drift()existed but was never calledby any audit tool.
Solution
7 files changed:
field_annotations.py:_STRUCTURAL_ROLE_VALUES+effective_min_convlogicchecks.py: Newcheck_schema_drift()function (78 lines)workflow.py:db_pathparameter threaded through audit flowmodels.py:check_drift+db_pathfields onSchemaAuditRequestinference.py: Wiresdb_paththroughaudit_schemas()schema_audit.py:--check-driftflagtest_schema_privacy.py:TestStructuralRoleExemption(2 tests)Verification
What's the gap