Skip to content

fix(schemas): exempt message_role fields from privacy threshold, wire detect_drift into audit (#800) - #921

Merged
Sinity merged 1 commit into
masterfrom
feature/fix/schema-regen-800
May 7, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/fix/schema-regen-800

Conversation

@Sinity

@Sinity Sinity commented May 7, 2026

Copy link
Copy Markdown
Owner

Summary

Three targeted fixes building on PR #887 (pipeline reordering):

  1. message_role fields exempt from privacy threshold: When a field has
    x-polylogue-semantic-role="message_role", the cross-conversation privacy
    threshold (min_conversation_count=3) is bypassed (uses min=1). This
    preserves protocol-level record type tokens that were being suppressed.

  2. detect_drift() wired into devtools schema-audit --check-drift: New
    check_schema_drift() audit check loads samples from the archive DB and runs
    detect_drift() against committed schemas.

  3. Tests: TestStructuralRoleExemption verifies that message_role values
    survive min_conversation_count=3 while 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 called
by any audit tool.

Solution

7 files changed:

  • field_annotations.py: _STRUCTURAL_ROLE_VALUES + effective_min_conv logic
  • checks.py: New check_schema_drift() function (78 lines)
  • workflow.py: db_path parameter threaded through audit flow
  • models.py: check_drift + db_path fields on SchemaAuditRequest
  • inference.py: Wires db_path through audit_schemas()
  • schema_audit.py: --check-drift flag
  • test_schema_privacy.py: TestStructuralRoleExemption (2 tests)

Verification

pytest tests/unit/core/test_schema_privacy.py -x -q     # 102 passed
ruff check <touched files>                              # All checks passed
mypy --strict <touched files>                           # Success: no issues found
devtools schema-audit --provider claude-code --check-drift  # PASS

What's the gap

Copilot AI review requested due to automatic review settings May 7, 2026 16:09
@coderabbitai

coderabbitai Bot commented May 7, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Rate limit exceeded

@Sinity has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 57 minutes and 33 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: 12c57464-e119-491a-8159-8594da685b9f

📥 Commits

Reviewing files that changed from the base of the PR and between 537a01f and e84c519.

📒 Files selected for processing (7)
  • devtools/schema_audit.py
  • polylogue/schemas/audit/checks.py
  • polylogue/schemas/audit/workflow.py
  • polylogue/schemas/generation/field_annotations.py
  • polylogue/schemas/operator/inference.py
  • polylogue/schemas/operator/models.py
  • tests/unit/core/test_schema_privacy.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/fix/schema-regen-800

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.

… 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]>
@Sinity
Sinity force-pushed the feature/fix/schema-regen-800 branch from acc63b7 to e84c519 Compare May 7, 2026 16:11
@Sinity
Sinity merged commit 7054cd9 into master May 7, 2026
2 checks passed
@Sinity
Sinity deleted the feature/fix/schema-regen-800 branch May 7, 2026 16:12

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

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

Comment thread polylogue/ui/tui/screens/browser.py Resolved

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 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 emitting x-polylogue-values.
  • Add --check-drift to devtools schema-audit, loading DB samples and running detect_drift() against committed schemas.
  • Refactor TUI screens and shell completions to use ArchiveOperations instead 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.

Comment on lines +225 to +229
def check_schema_drift(
schema: Mapping[str, object] | SchemaNode,
*,
db_path: Path | None = None,
provider: str = "",
Comment on lines +282 to +287
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],
Comment on lines +232 to +236
"""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.
Sinity added a commit that referenced this pull request May 7, 2026
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
Sinity added a commit that referenced this pull request May 7, 2026
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
Sinity added a commit that referenced this pull request May 7, 2026
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
Sinity added a commit that referenced this pull request May 7, 2026
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
Sinity added a commit that referenced this pull request May 7, 2026
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
Sinity added a commit that referenced this pull request May 7, 2026
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
Sinity added a commit that referenced this pull request May 7, 2026
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
Sinity added a commit that referenced this pull request May 7, 2026
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
@Sinity

Sinity commented Oct 1, 2026

Copy link
Copy Markdown
Owner Author

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.

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