Skip to content

feat(demo): add deterministic archive seed commands (#2196) - #2208

Merged
Sinity merged 4 commits into
masterfrom
feature/refactor/demo-verifiability-2196
Jun 20, 2026
Merged

Sinity merged 4 commits into
masterfrom
feature/refactor/demo-verifiability-2196

Conversation

@Sinity

@Sinity Sinity commented Jun 20, 2026 •

Copy link
Copy Markdown
Owner

Summary

Adds a product demo namespace that can seed, verify, and describe a deterministic Polylogue archive without relying on showcase internals. The demo archive is created synchronously from the existing synthetic corpus fixture and can optionally include assertion-backed user overlays.

Problem

#2196 needs a demo/verifiability surface that operators and future visual/demo work can invoke directly. The existing demo corpus helpers were useful, but the archive-ready path was split between import internals and verification-lab/showcase assumptions, so there was no compact command that seeded a ready-to-query archive and proved the expected archive facts.

Solution

  • Added polylogue.demo models, seed, verify, and script helpers.
  • Added polylogue demo seed, polylogue demo verify, and polylogue demo script.
  • Reused the same demo source materialization from import --demo instead of keeping separate fixture-writing logic in the import command.
  • Added semantic verification for session/message counts, known demo IDs, queryability, optional overlay claims, and raw-path hygiene.
  • Added focused CLI/demo tests and refreshed generated docs, topology projections, help snapshots, and showcase help baselines for the new visible demo command.

This does not implement a daemon-backed import --demo --wait path; the new seed command is intentionally the synchronous operator/demo path for this phase.

Verification

  • nix develop --command devtools test tests/unit/demo/test_demo_seed_verify.py tests/unit/cli/test_demo_command.py tests/unit/cli/test_import.py -q -> 16 passed
  • nix develop --command devtools test tests/unit/cli/test_help_contract.py tests/unit/cli/test_plain_cli_snapshots.py -q -> 225 passed, 9 snapshots passed
  • nix develop --command devtools test tests/unit/storage/test_no_string_interpolated_sql.py tests/unit/demo/test_demo_seed_verify.py tests/unit/cli/test_demo_command.py tests/unit/cli/test_import.py -q -> 18 passed
  • nix develop --command devtools test tests/unit/cli/test_terminal_snapshots.py::TestHelpOutput::test_help_output_snapshot tests/unit/cli/test_terminal_snapshots.py::TestTerminalDimensions::test_help_at_narrow_width tests/unit/cli/test_terminal_snapshots.py::TestTerminalDimensions::test_help_at_wide_width tests/unit/cli/test_help_snapshots.py::test_root_help_snapshot -q -> 4 passed, 4 snapshots passed
  • nix develop --command devtools lab scenario verify-baselines -> 106 exercises, all baselines match
  • nix develop --command devtools verify --quick -> exit_code 0
  • nix develop --command devtools verify --seed-testmon --skip-slow -> 11,628 passed, exit_code 0

Sinity added 2 commits June 20, 2026 05:12
Problem: #2196 needs demo and visual verification to move out of the old showcase/QA catalog path. The deterministic demo fixture world existed, but it was only reachable through internal tests or daemon import scheduling, so an operator could not create a ready-to-query demo archive synchronously.\n\nWhat changed: add a polylogue.demo product module that materializes the existing fixture world, ingests it directly into an archive file set, optionally seeds deterministic overlays, verifies semantic archive facts, and renders a copy-pastable demo script. Register a root polylogue demo command with seed, verify, and script subcommands, and reuse the same source materialization from import --demo.\n\nVerification: devtools test tests/unit/storage/test_no_string_interpolated_sql.py tests/unit/demo/test_demo_seed_verify.py tests/unit/cli/test_demo_command.py tests/unit/cli/test_import.py -q passed (18 passed). devtools test tests/unit/cli/test_help_contract.py tests/unit/cli/test_plain_cli_snapshots.py -q passed (225 passed). devtools verify --quick passed.
@coderabbitai

coderabbitai Bot commented Jun 20, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

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

More reviews will be available in 43 minutes and 31 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

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 credits.

🚦 How do rate limits work?

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

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, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 34f1c496-fa91-4478-a0ac-cc8cab0220f6

📥 Commits

Reviewing files that changed from the base of the PR and between 3782f5e and 57a4e32.

📒 Files selected for processing (8)
  • polylogue/demo/models.py
  • polylogue/demo/seed.py
  • polylogue/demo/verify.py
  • tests/baselines/showcase/help-demo-script.txt
  • tests/baselines/showcase/help-demo-seed.txt
  • tests/baselines/showcase/help-demo-verify.txt
  • tests/baselines/showcase/help-demo.txt
  • tests/baselines/showcase/help-main.txt
📝 Walkthrough

Walkthrough

Adds a new polylogue/demo/ package with models.py (result dataclasses), seed.py (deterministic corpus materialization and archive ingestion), verify.py (SQLite-based semantic verification), and script.py (bash script renderer). Wires these as a demo CLI command group (seed, verify, script) registered in the root Click application, and refactors import_command to delegate demo materialization to the new package.

Changes

Demo Archive Package and CLI

Layer / File(s) Summary
DemoSeedResult and DemoVerifyResult data contracts
polylogue/demo/models.py, polylogue/demo/__init__.py
Defines frozen dataclasses DemoSeedResult and DemoVerifyResult with to_payload() serialization and exposes them through the polylogue.demo package __all__.
Demo source materialization and archive seeding
polylogue/demo/seed.py
Implements DEMO_SOURCE_DIRNAME, _pushd, materialize_demo_source, demo_source_specs, and seed_demo_archive to write and ingest three fixed demo corpus sources (chatgpt, claude-code, codex) into an archive root.
Demo archive semantic verification
polylogue/demo/verify.py
Implements verify_demo_archive with SQLite helpers that validate session/message counts, query hits for "pytest", overlay presence, and absence of absolute raw-source-path leaks.
Bash script renderer
polylogue/demo/script.py
Implements render_demo_script which validates the shell parameter and returns a copy-pastable bash script that seeds, verifies, and queries the demo archive.
CLI command group and import_command refactor
polylogue/cli/commands/demo.py, polylogue/cli/click_command_registration.py, polylogue/cli/commands/import_command.py
Adds demo_command Click group with seed, verify, and script subcommands; registers it in _SHORT_HELP, _GROUP_ATTRS, and ROOT_COMMANDS; replaces inline demo-source construction in import_command with a call to polylogue.demo.materialize_demo_source.
Tests, snapshots, and generated docs
tests/unit/demo/test_demo_seed_verify.py, tests/unit/cli/test_demo_command.py, tests/unit/cli/__snapshots__/..., docs/cli-reference.md, docs/plans/topology-target.yaml, docs/topology-status.md, docs/test-quality-workflows.md
Adds async unit tests for seed/verify logic and CLI runner tests for all three subcommands; updates help snapshots for all terminal widths; updates CLI reference, topology target/status, and scenario projection counts.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant demo_command as demo CLI group
  participant seed_demo_archive
  participant verify_demo_archive
  participant render_demo_script
  participant SQLite as Archive SQLite DBs

  User->>demo_command: polylogue demo seed [--json] [--with-overlays]
  demo_command->>seed_demo_archive: asyncio.run(seed_demo_archive(root, force, with_overlays))
  seed_demo_archive-->>demo_command: DemoSeedResult
  demo_command-->>User: JSON payload or formatted console lines

  User->>demo_command: polylogue demo verify [--require-overlays]
  demo_command->>verify_demo_archive: verify_demo_archive(root, require_overlays)
  verify_demo_archive->>SQLite: query index.db / source.db / user.db
  SQLite-->>verify_demo_archive: counts, paths, overlay rows
  verify_demo_archive-->>demo_command: DemoVerifyResult
  demo_command-->>User: status output (or ClickException on failure)

  User->>demo_command: polylogue demo script [--shell bash]
  demo_command->>render_demo_script: render_demo_script(root, shell)
  render_demo_script-->>demo_command: bash script string
  demo_command-->>User: printed script (no trailing newline)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

  • refactor(verifiability): replace showcase QA with demo-driven CLI and visual tests #2196: This PR directly implements the demo seed, demo verify, and demo script CLI subcommands and the polylogue/demo/ package structure described in issue #2196 as the replacement for showcase QA with demo-driven CLI commands.
  • Sinity/polylogue#1837: The polylogue/demo/ package and CLI commands introduced here supply the demo-mode seeding and verification described in issue #1837 as requirements for powering the README and CLI without devtools.
  • Sinity/polylogue#1808: The refactored import_command._materialize_demo_source delegates to polylogue.demo.materialize_demo_source, which implements the underlying demo archive infrastructure that issue #1808's import --demo path depends on.

Possibly related PRs

  • Sinity/polylogue#455: This PR adds polylogue/demo/ entries to docs/plans/topology-target.yaml and updates docs/topology-status.md, both of which are outputs managed by the topology dashboard tooling introduced in that PR.
  • Sinity/polylogue#1376: Both PRs extend polylogue/cli/click_command_registration.py (_SHORT_HELP, _GROUP_ATTRS, ROOT_COMMANDS) and docs/cli-reference.md to register a new top-level CLI command.
  • Sinity/polylogue#680: Both PRs modify ROOT_COMMANDS in polylogue/cli/click_command_registration.py to change the set of top-level subcommands.

Suggested labels

type:refactor, area:cli, area:qa

Poem

🐇 Hop hop, a demo to plant and grow,
Three sources seeded in a row!
seed, then verify, then script to share,
A bash scroll printed with bunny care.
The archive checked — no leaks, all clear —
The demo world is finally here! 🌱

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 47.83% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The PR title 'feat(demo): add deterministic archive seed commands' clearly and specifically summarizes the main change—adding new demo command functionality for seeding deterministic archives.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The pull request description includes all required sections: Summary, Problem, Solution, Verification, and Changelog consideration. The description clearly explains the changes, rationale, and provides comprehensive verification results.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/refactor/demo-verifiability-2196

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.

github-actions Bot pushed a commit that referenced this pull request Jun 20, 2026

@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: 3782f5e879

ℹ️ 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/demo/seed.py Resolved
Comment thread polylogue/demo/verify.py Resolved

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 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 `@polylogue/demo/seed.py`:
- Around line 21-28: The _pushd context manager uses os.chdir() to mutate global
process state, which creates a concurrency hazard when called from async
contexts like seed_demo_archive because interleaved async calls will interfere
with each other's working directories. Refactor demo_source_specs to accept a
source_root parameter and return absolute Source paths instead of relative ones,
then remove the _pushd call from seed_demo_archive and pass the required
source_root to demo_source_specs. Finally, delete the now-unused _pushd helper
function and remove the os import statement that is no longer needed.
🪄 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: a68f90d7-b324-41bb-954a-caac3542f949

📥 Commits

Reviewing files that changed from the base of the PR and between 088d620 and 3782f5e.

📒 Files selected for processing (16)
  • docs/cli-reference.md
  • docs/plans/topology-target.yaml
  • docs/test-quality-workflows.md
  • docs/topology-status.md
  • polylogue/cli/click_command_registration.py
  • polylogue/cli/commands/demo.py
  • polylogue/cli/commands/import_command.py
  • polylogue/demo/__init__.py
  • polylogue/demo/models.py
  • polylogue/demo/script.py
  • polylogue/demo/seed.py
  • polylogue/demo/verify.py
  • tests/unit/cli/__snapshots__/test_help_snapshots.ambr
  • tests/unit/cli/__snapshots__/test_terminal_snapshots.ambr
  • tests/unit/cli/test_demo_command.py
  • tests/unit/demo/test_demo_seed_verify.py

Comment thread polylogue/demo/seed.py
Comment on lines +21 to +28
@contextmanager
def _pushd(path: Path) -> Iterator[None]:
previous = Path.cwd()
os.chdir(path)
try:
yield
finally:
os.chdir(previous)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | 🏗️ Heavy lift

Concurrency hazard: os.chdir in async context.

The _pushd context manager mutates global process state (os.chdir), which is unsafe when used inside an async function like seed_demo_archive (line 66). If multiple seed_demo_archive calls are interleaved on the same thread (typical in asyncio), their working directories can interfere, causing one call to execute parse_sources_archive from the wrong directory.

🔄 Recommended fix: pass absolute paths instead of relying on cwd

Refactor demo_source_specs to accept source_root and return absolute Source paths, then remove the _pushd call:

-def demo_source_specs(source_root: Path) -> list[Source]:
+def demo_source_specs(source_root: Path) -> list[Source]:
     """Return relative source specs for the materialized demo world."""
 
     return [
-        Source(name="chatgpt", path=Path("chatgpt")),
-        Source(name="claude-code", path=Path("claude-code")),
-        Source(name="codex", path=Path("codex")),
+        Source(name="chatgpt", path=source_root / "chatgpt"),
+        Source(name="claude-code", path=source_root / "claude-code"),
+        Source(name="codex", path=source_root / "codex"),
     ]

Then remove the _pushd call in seed_demo_archive:

     source_root = materialize_demo_source(archive_root, force=force)
-    with _pushd(source_root):
-        result = await parse_sources_archive(archive_root, demo_source_specs(source_root))
+    result = await parse_sources_archive(archive_root, demo_source_specs(source_root))

And remove the now-unused _pushd helper and its os import.

🤖 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 `@polylogue/demo/seed.py` around lines 21 - 28, The _pushd context manager uses
os.chdir() to mutate global process state, which creates a concurrency hazard
when called from async contexts like seed_demo_archive because interleaved async
calls will interfere with each other's working directories. Refactor
demo_source_specs to accept a source_root parameter and return absolute Source
paths instead of relative ones, then remove the _pushd call from
seed_demo_archive and pass the required source_root to demo_source_specs.
Finally, delete the now-unused _pushd helper function and remove the os import
statement that is no longer needed.

@Sinity
Sinity merged commit c7cedbb into master Jun 20, 2026
14 checks passed
@Sinity
Sinity deleted the feature/refactor/demo-verifiability-2196 branch June 20, 2026 03:45
@Sinity

Sinity commented Sep 30, 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.

  • 65.F050 / P2: fixed-already at the checked revision: ArchiveStore.open_existing now sets initialize=not read_only at polylogue/storage/sqlite/archive_tiers/archive.py:1200, so the verification reader cannot bootstrap a missing source tier. The demo verifier reads source.db through a read-only connection at polylogue/demo/verify.py:66 and 88 within the error boundary at line 158, preventing the missing-file false pass described here.

Only the rows listed above are dispositioned. Held findings remain open.

@Sinity

Sinity commented Sep 30, 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.

  • 64.F026 / P1: fixed-already at the checked revision: _guard_demo_seed_target refuses an unowned root containing real content even with force or an explicit root at polylogue/demo/seed.py:248-250. The seed path invokes this guard at line 1710 before ownership recording, self-healing or ingestion.

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.

1 participant