Repository navigation
feat(devtools): add read-only real-archive slice screening harness - #2885
Conversation
Problem: polylogue-212.11 (shared deterministic proof world) needs to extend beyond the fully-synthetic Incident 14:32 corpus with a real, representative slice of the operator's own archive, per explicit operator direction. That requires a privacy-vetting step that must be human-gated, not autonomous — nothing should land in a shared fixture without an operator reading it first. What changed: added `devtools demo real-slice-screen` (devtools/proof_world_real_slice.py), a read-only harness that opens a real archive via `Polylogue.get_session()` (read_only=True by default), flattens each candidate session's message text + block payloads, and screens it against secret/credential patterns (AWS keys, bearer tokens, private-key blocks, JWTs, Slack tokens, generic key=value assignments) and PII-adjacent patterns (email, home paths, IPv4), with a small allowlist for common test placeholders ([email protected], 127.0.0.1, ...). It writes a markdown report + per-session transcripts + a JSON manifest to an arbitrary output directory and never writes into `polylogue/scenarios/` itself - promoting anything to a shared fixture stays a separate, explicit, human step. Registered in devtools/command_catalog.py (category "workspace"); docs/devtools.md regenerated via `devtools render devtools-reference`. Verification: devtools test tests/unit/devtools/test_proof_world_real_slice.py tests/unit/devtools/test_command_catalog.py -> 19 passed devtools verify --quick -> exit_code 0 (ruff format/check, mypy --strict, render all --check, topology/layering/closure-matrix/manifests/ci-workflows/doc-commands/ test-infra-currency/test-clock-hygiene/pytest-timeout-overrides/ degrade-loudly all ok) Anti-vacuity: test_screen_session_reads_real_archive_and_flags_planted_secret exercises the real production dependency (`Polylogue.get_session` against a SessionBuilder-seeded archive, not a mock) and fails if `scan_text`'s secret pattern set is emptied or `screen_session` stops calling it. Ref polylogue-212.11. Co-Authored-By: Claude <[email protected]>
|
Warning Review limit reached
Next review available in: 50 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the 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 configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughAdds a read-only CLI tool that extracts archive sessions, detects secrets and PII, redacts secrets in screening samples, writes transcripts and reports, registers the command, documents it, and validates the workflow with unit and integration tests. ChangesReal archive slice screening
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Operator
participant main
participant PolylogueArchive
participant OutputFiles
Operator->>main: provide archive root and session selectors
main->>PolylogueArchive: load selected sessions read-only
PolylogueArchive-->>main: session content
main->>OutputFiles: write transcripts, manifest, and screening report
main-->>Operator: print summary and return verdict-based exit code
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ 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: 05c32073c1
ℹ️ 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".
…l-slice screener Problem: reviewer found three correctness bugs in the privacy-sensitive real-archive screening harness (devtools/proof_world_real_slice.py, polylogue-212.11): 1. The PII allowlist check used substring containment instead of exact match, so `[email protected]` and `127.0.0.123` were both marked `all_allowlisted=True` (they contain `[email protected]`/`127.0.0.1` as substrings) and silently downgraded the session verdict to `clean`, suppressing the human-review signal for real-looking PII. Flagged independently by the Codex PR bot. 2. Transcript filenames were built via naive `/`/`:` replacement with no collision handling, so two distinct session ids differing only in punctuation placement (e.g. `origin:a:b` vs `origin:a_b`) could normalize to the same filename and silently overwrite one operator-facing transcript. Flagged independently by the Codex PR bot. 3. The module/`scan_text` docstring claimed samples were truncated "to keep the report itself from becoming a leak surface," but the snippet window always fully contained the matched text, so any secret-pattern hit (AWS key, bearer token, etc.) was written verbatim into SCREENING_REPORT.md/manifest.json — a real gap between claimed and actual behavior on a security-sensitive surface. What changed: - `_ALLOWLIST_VALUES` (renamed from `_ALLOWLIST_SUBSTRINGS`) is now checked via exact `match.group(0) in _ALLOWLIST_VALUES`, never substring containment. - New `_safe_transcript_filename()` appends a sha256 digest of the original (unsanitized) session id to the sanitized stem, making filename collisions between distinct session ids infeasible; `main()` additionally tracks claimed filenames and raises loudly instead of silently overwriting in the unreachable case of a hash collision. - `_snippet()` now takes a `redact` flag; secret-kind hits redact the matched substring itself (`<redacted:Nch>`) while keeping surrounding context, so SCREENING_REPORT.md/manifest.json never embed a raw secret value. PII-kind hits keep the real matched text verbatim, since a human reviewer needs it to judge placeholder vs. genuine data. Module docstring updated to describe this split accurately and to note `--out` has no built-in guard against a tracked path. Verification: - `devtools test tests/unit/devtools/test_proof_world_real_slice.py` -> 19 passed (5 new regression tests: substring-allowlist bypass, secret redaction in samples, PII text preserved in samples, filename disambiguation for punctuation-variant ids, filename determinism; plus a strengthened assertion on the existing planted-secret e2e test that the raw key never appears in report-facing samples). - `devtools verify --quick` -> exit 0 (format, lint, mypy, render-all, topology/layering/closure-matrix, doc-commands, and remaining lab checks all green). Ref polylogue-212.11.
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@devtools/proof_world_real_slice.py`:
- Around line 211-236: Update screen_sessions to open a single
Polylogue(archive_root=archive_root) context and process every session_id
through that shared instance, instead of repeatedly calling screen_session.
Preserve screen_session’s existing per-id signature and direct behavior for
callers and tests; factor or reuse the session-screening logic as needed while
retaining the same missing-session handling and result/transcript output.
- Around line 199-208: Replace the Any parameter in _flatten_session_text with
the appropriate typed Session type, importing or referencing it only under
TYPE_CHECKING so runtime behavior and the existing lazy Polylogue import remain
unchanged. Preserve the current message text and structured-block flattening
logic while ensuring mypy can validate messages, text, and blocks attribute
access.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 50bc75ce-f646-4719-8874-5b8ee3680e84
📒 Files selected for processing (4)
devtools/command_catalog.pydevtools/proof_world_real_slice.pydocs/devtools.mdtests/unit/devtools/test_proof_world_real_slice.py
| def _flatten_session_text(session: Any) -> str: | ||
| """Flatten every message's text and structured blocks to one string.""" | ||
|
|
||
| parts: list[str] = [] | ||
| for message in session.messages: | ||
| if message.text: | ||
| parts.append(message.text) | ||
| if message.blocks: | ||
| parts.append(json.dumps(message.blocks, default=str)) | ||
| return "\n".join(parts) |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win
Prefer a typed Session parameter over Any.
_flatten_session_text types session as Any, losing mypy's ability to check .messages, .text, and .blocks attribute access. Since this file already lazy-imports Polylogue to avoid a heavy top-level import, the real type can still be attached under TYPE_CHECKING without a runtime cost. As per coding guidelines, "Use strict typing: mypy --strict is the primary verification net, and code changes must preserve type correctness."
♻️ Proposed typing fix
from __future__ import annotations
import argparse
import hashlib
import json
import re
import sys
from dataclasses import dataclass, field
from pathlib import Path
-from typing import Any
+from typing import TYPE_CHECKING, Any
+
+if TYPE_CHECKING:
+ from polylogue.api import Session
@@
-def _flatten_session_text(session: Any) -> str:
+def _flatten_session_text(session: "Session") -> str:📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| def _flatten_session_text(session: Any) -> str: | |
| """Flatten every message's text and structured blocks to one string.""" | |
| parts: list[str] = [] | |
| for message in session.messages: | |
| if message.text: | |
| parts.append(message.text) | |
| if message.blocks: | |
| parts.append(json.dumps(message.blocks, default=str)) | |
| return "\n".join(parts) | |
| from typing import TYPE_CHECKING, Any | |
| if TYPE_CHECKING: | |
| from polylogue.api import Session | |
| def _flatten_session_text(session: "Session") -> str: | |
| """Flatten every message's text and structured blocks to one string.""" | |
| parts: list[str] = [] | |
| for message in session.messages: | |
| if message.text: | |
| parts.append(message.text) | |
| if message.blocks: | |
| parts.append(json.dumps(message.blocks, default=str)) | |
| return "\n".join(parts) |
🧰 Tools
🪛 ast-grep (0.44.1)
[info] 206-206: use jsonify instead of json.dumps for JSON output
Context: json.dumps(message.blocks, default=str)
Note: [CWE-116] Improper Encoding or Escaping of Output.
(use-jsonify)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@devtools/proof_world_real_slice.py` around lines 199 - 208, Replace the Any
parameter in _flatten_session_text with the appropriate typed Session type,
importing or referencing it only under TYPE_CHECKING so runtime behavior and the
existing lazy Polylogue import remain unchanged. Preserve the current message
text and structured-block flattening logic while ensuring mypy can validate
messages, text, and blocks attribute access.
Source: Coding guidelines
Problem: PR #2885's CodeRabbit review flagged two issues in the polylogue-212.11 real-archive privacy screening harness (devtools/proof_world_real_slice.py): 1. screen_sessions() called screen_session() per id, so a batch of N session ids opened and closed the archive tiers N times instead of once. 2. _flatten_session_text() took a bare Any parameter instead of a real type. What changed: - screen_sessions() now opens one Polylogue(archive_root=...) instance and reuses it across every id via a new _screen_session_with(poly, session_id) helper; screen_session() keeps its existing two-arg signature for callers/tests by opening its own scoped instance and delegating to the same helper. - _flatten_session_text() takes a _SessionLike Protocol (structural, read-only @Property members) instead of Any. A plain-attribute Protocol was tried first but rejected by mypy's invariant attribute check (Message.blocks: list[dict[str, object]] vs a bare blocks: object attribute); read-only @Property members make the check covariant, so both the real Session/Message domain models and the tests' duck-typed _FakeSession/_FakeMessage doubles satisfy it structurally without subclassing the domain model. - Added test_screen_sessions_opens_the_archive_once_for_the_whole_batch, which counts real Polylogue.__aenter__ calls while driving the actual screening path against a seeded archive. Anti-vacuity: reverting screen_sessions to the per-id screen_session() loop makes this test fail (2 opens instead of 1), verified locally before restoring the fix. Verification: devtools test tests/unit/devtools/test_proof_world_real_slice.py -> 20 passed devtools verify --quick -> exit_code 0 Ref polylogue-212.11. Co-Authored-By: Claude <[email protected]>
|
Addressed both CodeRabbit findings from the a97b09d review pass in dfd0190:
Verification: |
|
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. |
Move all three Sinex wire dependency pins directly from `f2951e51` to qualified merged `c8a5e4b1` (Sinex PR #2886), including its source-retirement and sealed-repair fixes and immutable common `v0.5.20` pin. Update the four corresponding lock sources together. Polylogue's Nix package consumes this Cargo lock; there is no separate Sinex flake input. The preserved formatting/boundaries push hook passed (devkit 2450). Locked metadata resolution passed (job 1520), verifying model/macros/protocol/transport all resolve exactly to `c8a5e4b1eb7f9f6724d7d1da4ea8fe4c73722687`. Their complete crate trees, including manifests, are byte-identical at the old pin, prior native witness `99cbdf3c`, and this merged revision. Registry dependency constraints are unchanged; Polylogue already pins common `v0.5.20`. The existing ordinary producer/wire witness is job 1478 on SX `99cbdf3c` and PL `199659e682`. It predates the sealed-store repair, so this update does not claim a new native daemon/store replay. Upstream PR #2885 owns its daemon/store repair controls; PR #2886 owns the locked API masking controls. Root's coalesced paired qualification follows these pins. No Rust source, harness, schema, or package build is added here.
Summary
Adds
devtools demo real-slice-screen, a read-only extraction + privacyscreening harness for candidate real-archive session slices, plus the
harness's own test coverage. This is the "harness/fixture machinery" half of
polylogue-212.11's real-archive-data extension; the actual candidate slice
and its privacy write-up are a separate, deliberately-unmerged artifact (see
Verification below) awaiting operator spot-check before any real content is
folded into
polylogue/scenarios/.Problem
polylogue-212.11 ("one shared deterministic proof world for all flagship
demos") has already landed 37 declared constructs on a fully-synthetic
Incident 14:32 corpus (PRs #2662, #2674). Per explicit operator direction,
the shared proof world should also draw on a real, representative slice of
the operator's own archive (
/realm/db/polylogue) rather than stayingsynthetic-only — "the point is representative data, not full determinism."
That requires a privacy-vetting step. The bead's own instructions are
explicit that this step must not be autonomous: a candidate slice has to
be pulled, screened, and handed to the operator as a flagged, reviewable
artifact before it becomes a permanent shared fixture. This PR ships the
reusable machinery for that step; it does not itself promote any real
content into the product tree.
Solution
devtools/proof_world_real_slice.py— given one or more session ids(or a refs file) and a real archive root, opens the archive read-only via
Polylogue.get_session()(the API'sArchiveStore.open_existing(..., read_only=True)default — never mutates the source archive), flattenseach session's message text + structured block payloads to plain text, and
runs a pattern screen:
key=value/key: valuecredential assignments, bearer tokens,BEGIN ... PRIVATE KEYblocks, OpenAI-stylesk-...keys, Slacktokens, SSH public keys, JWT-shaped strings.
/home/<user>paths, IPv4addresses — with a small allowlist for common test placeholders
(
[email protected],127.0.0.1,0.0.0.0, ...) so the report isn'tdominated by noise from ordinary test fixtures.
flagged; any non-allowlisted PII hit (with nosecret hit) ->
review; otherwiseclean.SCREENING_REPORT.md(per-session verdict + truncated matchsamples),
manifest.json, and per-sessiontranscripts/*.txtto anarbitrary output directory. It never writes into
polylogue/scenarios/or any other product fixture path — promoting a slice stays a distinct,
explicit, human-gated step.
devtools demo real-slice-screenindevtools/command_catalog.py(categoryworkspace);docs/devtools.mdregenerated via
devtools render devtools-reference.tests/unit/devtools/test_proof_world_real_slice.py: pure-functioncoverage of the pattern scanner and verdict logic (including the
allowlist), the text-flattening helper, report rendering, CLI argument
handling, and an end-to-end read path against a
SessionBuilder-seededarchive that plants a real AWS-key-shaped string and asserts it is both
read back correctly and flagged.
What this PR does not do
I ran the harness against 5 candidate sessions from the operator's own
archive (their own dev-work sessions on this very repository — flaky-test
hunting, pipeline-idempotency test design, and two issue implementations)
and wrote up the result (0 flagged, 3 "review" — all traced to test
placeholders/loopback IPs/the operator's own home path in their own
tool-output truncation messages, not third-party data — 2 fully clean) as
a distinct, gitignored artifact under
.agent/scratch/real-slice-vetting-2026-07-14/(OPERATOR-SUMMARY.md,SCREENING_REPORT.md,manifest.json,transcripts/). That directory isnot part of this diff —
.agent/scratch/*is gitignored — and is leftin place for a quick operator spot-check per the task's explicit
instruction that this step "should NOT be treated as fully autonomous."
(parser v1/v2 dual interpretation, typed cross-source 14:32 event hooks)
are unaffected by this PR and remain open follow-up scope on
polylogue-212.11 — see the bead's own notes history (PRs feat(demo): one-command receipts proof, enforced public-claims gate, corpus v2 #2662/feat(demo): Incident 14:32 constructs — source outage, cross-material duplicate, compaction omission #2674/feat(demo): measure completion claims against tool outcomes #2795).
store; the harness reads normalized message text via the
PolylogueAPI.If/when the slice is approved, a follow-up should decide whether real
parser-replay fidelity (raw bytes) or the normalized text is the right
fixture-generator input — that decision is out of scope here.
Verification
Anti-vacuity:
test_screen_session_reads_real_archive_and_flags_planted_secretdrives the real production path (
Polylogue.get_sessionagainst aSessionBuilder-seeded archive, not a mock/stub) and fails ifscan_text'ssecret-pattern set is emptied, or if
screen_sessionstops calling it.Ref polylogue-212.11.
Summary by CodeRabbit
New Features
Documentation
Tests