Repository navigation
fix(demo): refuse default-root collision and harden self-heal ownership - #3516
Conversation
Problem: `polylogue demo seed`/`demo tour` are the documented private-data-free onboarding path (CLAUDE.md, TESTING.md), but both failed on first try (polylogue-3ycw): 1. `demo seed` against a demo archive left over from an older schema version raised `RuntimeError: index.db schema version N is not the current index tier version M; move it aside and rebuild the archive root` with no path named and no self-heal, even though a demo archive is entirely synthetic, disposable fixture data that this same command regenerates every run. 2. `demo tour` failed its own 30s "first result" latency budget (70.9s measured) even though each of the 4 narrated CLI steps individually took only 4.6-5.3s: `first_result_s` was measured from the tour's very start, so it silently included one-time seed+verify archive-construction time rather than actual query latency. Solution: - `polylogue/demo/seed.py`: add `_archive_root_is_demo_owned()`, which treats the presence of the demo fixture source directory (`demo-fixture-world-source`, written only by `materialize_demo_source`, never by the live daemon) as proof a root's tier databases hold only synthetic content. `_self_heal_stale_demo_archive_tiers()` then moves aside (`<file>.stale-<ts>`) and rebuilds any tier whose on-disk schema version predates the current code, but ONLY when that ownership check passes -- a stale-schema *foreign* root (e.g. an operator forgot `--root` and the default `archive_root()` resolved to the configured production archive) is never auto-rebuilt, it still raises loudly. - `polylogue/storage/sqlite/archive_tiers/bootstrap.py`: the (still-raised, for non-demo-owned roots) `RuntimeError` now names the full path and an explicit rebuild command instead of just the bare filename. - `polylogue/demo/tour.py`: rebase `first_result_s`'s clock to start after the one-time seed+verify setup completes, so the budget measures actual query latency instead of cold-start archive construction. - `polylogue/demo/models.py`, `polylogue/cli/commands/demo.py`: surface `healed_tiers` on `DemoSeedResult`/the CLI `seed` command output. Verification: - Reproduced fresh: `POLYLOGUE_ARCHIVE_ROOT=<scratch> polylogue demo seed` succeeds cleanly; rolling `index.db`'s `PRAGMA user_version` back on that same (demo-owned) archive and re-running `demo seed` now self-heals (`healed_tiers: ["index.db"]`, `index.db.stale-<ts>` backup written) instead of raising. `polylogue demo tour --out-dir <scratch>` passes: "First result: 2.680s / Full tour: 19.651s". - `devtools test tests/unit/demo/ tests/unit/cli/test_demo_command.py tests/unit/storage/test_index_fast_forward_executor.py` -- 59 passed. - New tests: `test_seed_demo_archive_self_heals_a_stale_schema_on_a_demo_owned_root` and `test_seed_demo_archive_never_self_heals_a_non_demo_owned_root` (tests/unit/demo/test_demo_seed_verify.py), and `test_first_result_budget_excludes_one_time_archive_setup` (tests/unit/demo/test_demo_tour_timing.py, new file). Anti-vacuity confirmed by hand: reverting the `tour.py` timer rebase makes the new tour test fail with `first_result_s=9.5s` against a shrunk 6s budget and a "first result exceeded" problem; the self-heal tests exercise the real `polylogue.demo.seed.seed_demo_archive` production entry point. - `devtools verify --quick`: exit 0 (ruff format/check, mypy --strict, render all --check, layering/closure-matrix/schema-versioning lanes). Ref polylogue-3ycw Co-Authored-By: Claude <[email protected]>
…ership Problem: 'polylogue demo seed' with no --root/POLYLOGUE_ARCHIVE_ROOT override resolves through the same archive_root()/polylogue.toml chain the live daemon uses -- on a real operator machine this default can silently resolve to the live production archive. demo seed ADDS synthetic sessions rather than refusing to run against existing content, so the collision seeds fixture rows directly into a real archive (polylogue-o3a1t). Separately, a review of PR #3515's self-heal gate (_archive_root_is_demo_owned()) found it trusts DEMO_SOURCE_DIRNAME's mere presence as proof of "safe to move aside and rebuild on a schema mismatch". That marker only proves a demo seed touched a root at some point, not that the root's tiers are exclusively synthetic -- so the default-root collision above (or a --force override) leaves the marker permanently on a MIXED-content root, and any later schema drift on that real archive would satisfy the gate and authorize moving aside source.db or the irreplaceable user.db (assertions/corrections/saved queries) (polylogue-wyvio). Solution: - polylogue/demo/seed.py: add _guard_demo_seed_target(), which raises DemoSeedTargetUnsafeError naming the resolved path when the root is not demo-owned, already holds real ingested sessions, and neither an explicit root nor --force was given. A brand-new/empty root is unaffected -- there is nothing there to protect. - Replace the marker-based _archive_root_is_demo_owned() with a manifest-backed version: _record_demo_ownership_if_undetermined() writes a permanent demo-archive-ownership.json on the FIRST call that ever touches a root, recording whether it held real content at that exact moment. Self-heal now trusts only this manifest, so a root that ever held real content (even via --force) can never regain self-heal eligibility by being reseeded later -- its schema mismatches keep raising loudly instead. - polylogue/cli/commands/demo.py, polylogue/demo/tour.py: thread explicit_root through every seed_demo_archive() call site so an operator-provided --root/POLYLOGUE_ARCHIVE_ROOT is never second-guessed (the cloud/CI explicit-root lane keeps working with zero friction). Verification: - Reproduced via the real CLI in a scratch fixture (not /realm/db/polylogue): a synthetic non-demo archive with one real session, resolved as the DEFAULT root through a scratch polylogue.toml with no --root/env override, made 'polylogue demo seed' exit 1 with the guard's message naming the resolved path. The same archive via explicit --root or POLYLOGUE_ARCHIVE_ROOT seeded successfully with no friction (20 sessions = 19 demo + 1 real), matching the required CI/cloud-lane behavior. A genuinely fresh/empty root via the same default-resolution path seeded cleanly (19 sessions, exit 0). - devtools test tests/unit/demo/ tests/unit/cli/test_demo_command.py tests/unit/storage/test_index_fast_forward_executor.py -- 63 passed. New/changed tests in tests/unit/demo/test_demo_seed_verify.py: test_seed_demo_archive_refuses_the_default_root_collision, test_seed_demo_archive_explicit_root_bypasses_the_collision_guard, test_seed_demo_archive_never_self_heals_a_root_that_held_real_content, test_seed_demo_archive_grants_self_heal_to_a_genuinely_fresh_root. ANTI-VACUITY: all four exercise the real polylogue.demo.seed.seed_demo_archive entry point (no test-local reimplementation). Deleting the _guard_demo_seed_target call makes the first test fail by seeding successfully instead of raising; reverting _archive_root_is_demo_owned to trust DEMO_SOURCE_DIRNAME alone makes the third test fail (the second seed call self-heals instead of raising). - devtools verify --quick: exit 0 (ruff format/check, mypy --strict, render all --check, layering/closure-matrix/schema-versioning lanes). AC matrix (polylogue-o3a1t): - Refuse default-root collision against real content: satisfied. - Preserve default resolution for fresh/empty roots: satisfied. - CI/cloud explicit-root lane unaffected: satisfied. AC matrix (polylogue-wyvio): - Self-heal gate no longer trusts marker persistence alone: satisfied. - A root that held real content at first touch can never regain self-heal eligibility: satisfied. - Fixed in the same lane/branch as polylogue-o3a1t: satisfied. This branch also incorporates PR #3515's self-heal commit (d81f668, cherry-picked) as its starting point, since #3515 was still open and this fix hardens the exact gate it introduces; #3515 and this PR should be reconciled at merge time rather than landed independently. Ref polylogue-o3a1t Ref polylogue-wyvio Co-Authored-By: Claude <[email protected]>
|
Warning Review limit reached
Next review available in: 19 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 Plus Run ID: 📒 Files selected for processing (9)
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: 84f13685a9
ℹ️ 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".
…socket and demo-hardening findings Merged PR #3511 (polylogue-3b607) and PR #3512 (polylogue-373yt), closed both. Filed polylogue-kadx3 (P0: daemon UDS socket path not archive-scoped, found live during PR #3517 perf work) and polylogue-dl6af (3 new review findings on PR #3516's demo self-heal guard). Closed PR #3515 as superseded by #3516.
Problem: three CodeRabbit findings on PR #3516 (the self-heal ownership guard for `demo seed`) surfaced gaps that would still let self-heal silently move aside real durable archive content. 1. `demo_only: true` in the ownership manifest was permanent proof of exclusive demo ownership even after the same root later accumulated real content through normal use, so a later schema-drift self-heal would move aside the now-real `source.db`/`user.db`. 2. A missing or unreadable `index.db` was classified as "0 sessions", which could record `demo_only: true` even when the durable tiers (`source.db`, `user.db`) held real content -- `index.db` is the explicitly rebuildable tier and can legitimately be absent (e.g. after `polylogue ops reset --index`). 3. `POLYLOGUE_ARCHIVE_ROOT=""` was treated as an explicit root override by the CLI's collision-guard check, but `archive_root()` itself treats empty/whitespace as unset and falls back to the ambient default -- so a blank env var silently bypassed the guard while landing in the live fallback archive. What changed: - `polylogue/demo/seed.py`: `_archive_root_has_real_content` now checks `source.db`'s `raw_sessions` and `user.db`'s `assertions` directly, treating an unreadable tier as unsafe (not empty) and only falling back to the index count once durable tiers independently prove freshness (gap 2). `_guard_demo_seed_target` now uses this tier-aware predicate instead of the index-only session count. `_archive_root_is_demo_owned` now revalidates the manifest's `demo_only: true` bit against a `demo_session_ids` baseline recorded after every completed demo-only seed (`_refresh_demo_ownership_session_ids`); any current session id outside that baseline means real content arrived since, so self-heal refuses (gap 1). - `polylogue/cli/commands/demo.py`: `_root_is_explicit` now strips `POLYLOGUE_ARCHIVE_ROOT` and checks truthiness instead of mere `os.environ` membership, mirroring `archive_root()`'s own emptiness rule (gap 3); `receipts_command` now reuses the same helper instead of a duplicate inline check with the same bug. Verification: - `devtools test tests/unit/demo/ tests/unit/cli/test_demo_command.py` -> 59 passed. - Anti-vacuity: reverted each of the three fixes individually and confirmed its new regression test fails on the unfixed code (collision guard doesn't fire / manifest records `demo_only: true` over real durable content / self-heal proceeds without raising), then restored the fix and reconfirmed green. - `devtools verify --quick` -> exit 0 (ruff format/check, mypy --strict, render all --check, layering, schema-versioning policy, etc., all ok). Ref polylogue-dl6af, polylogue-o3a1t, polylogue-wyvio
Merged PR #3516 (demo self-heal ownership hardening), closed polylogue-o3a1t/wyvio/dl6af. Filed 3 beads from a devtools structural audit: dead schema-fast-forward one-offs (polylogue-s9irb), bead-loader duplication across 6+ files (polylogue-2ux5m), and an unregistered benchmark command (polylogue-fjg91).
|
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. |
|
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
polylogue demo seedshares its default archive-root resolution(
archive_root()/polylogue.toml) with the live daemon, so with no--root/POLYLOGUE_ARCHIVE_ROOToverride it can silently seed syntheticfixture content into a real production archive. Separately, the self-heal
gate added by PR #3515 (
_archive_root_is_demo_owned()) only proved "a demoseed touched this root at some point", not "this root is exclusively
synthetic" — so a root that ever received demo content via that same
collision (or a deliberate
--force) could later have a schema mismatchauthorize moving aside real, potentially irreplaceable
user.dbdata. ThisPR closes both.
Problem
demo seedadds demo sessions rather than refusingto run against existing content. An operator or agent who forgets
--rootgets ambient resolution through
polylogue.toml/XDG defaults — on a realmachine this can be the live archive.
DEMO_SOURCE_DIRNAME's mere presence as proof a root's tiers are safe tomove aside and rebuild on a schema mismatch. That marker persists
unconditionally, including on a root that already held real content when
first seeded, so a later schema drift on that mixed-content root could
authorize moving aside
source.db/user.db(durable, irreplaceableassertions/corrections/saved queries), not just the rebuildable
index.db.Both stem from the same root cause (demo seed sharing
archive_root()withthe live daemon) and are fixed together per the review finding on #3515.
Solution
polylogue/demo/seed.py:_guard_demo_seed_target()raisesDemoSeedTargetUnsafeError(namingthe resolved path and session count) when the root is not demo-owned,
already holds real ingested sessions, and neither an explicit root nor
--forcewas given. A brand-new/empty root is unaffected._archive_root_is_demo_owned()with amanifest-backed version.
_record_demo_ownership_if_undetermined()writes a permanent
demo-archive-ownership.jsonthe first time a rootis ever touched, recording whether it held real content at that exact
moment. Self-heal now trusts only this manifest — a root that ever held
real content (even via
--force) can never regain self-healeligibility by being reseeded later; its schema mismatches keep raising
loudly instead of silently rebuilding.
polylogue/cli/commands/demo.py,polylogue/demo/tour.py: threadexplicit_rootthrough everyseed_demo_archive()call site, computed as--root is not None or POLYLOGUE_ARCHIVE_ROOT in os.environ, so thecloud/CI explicit-root lane keeps working with zero friction.
Design choice: option 1 from the brief (refuse + require explicit
consent) rather than moving the default off
archive_root()entirely —this preserves today's zero-friction default for fresh/empty environments
(CI, cloud sandboxes, a brand-new operator machine) while gating only the
genuinely dangerous case.
Branch note: this branch starts from PR #3515's self-heal commit
(
d81f66870, cherry-picked cleanly onto currentmaster) since #3515 wasstill open at review time and this PR hardens the exact gate it introduces.
#3515 and this PR should be reconciled at merge time (either merge this one
instead of #3515, or merge #3515 first and rebase this one — they touch the
same functions).
Verification
Reproduced via the real CLI in scratch fixtures under
/realm/tmp/(nevertouching
/realm/db/polylogue):default root via a scratch
polylogue.tomlwith no--root/envoverride →
polylogue demo seedexits 1 with the guard's message namingthe resolved path and session count.
--root→ seeds successfully,session_count 20 (19 demo + 1 real), no friction.
POLYLOGUE_ARCHIVE_ROOT(thecloud/CI lane) → seeds successfully, session_count 20, no friction.
cleanly, session_count 19, exit 0.
Automated:
devtools test tests/unit/demo/ tests/unit/cli/test_demo_command.py tests/unit/storage/test_index_fast_forward_executor.py— 63 passed.devtools verify --quick— exit 0 (ruff format/check, mypy --strict, render all --check, layering/closure-matrix/schema-versioning lanes).New/changed tests in
tests/unit/demo/test_demo_seed_verify.py:test_seed_demo_archive_refuses_the_default_root_collisiontest_seed_demo_archive_explicit_root_bypasses_the_collision_guardtest_seed_demo_archive_never_self_heals_a_root_that_held_real_contenttest_seed_demo_archive_grants_self_heal_to_a_genuinely_fresh_rootAnti-vacuity: all four exercise the real
polylogue.demo.seed.seed_demo_archiveproduction entry point (notest-local reimplementation). Deleting the
_guard_demo_seed_targetcallmakes the first test fail by seeding successfully instead of raising.
Reverting
_archive_root_is_demo_ownedto trustDEMO_SOURCE_DIRNAMEalonemakes the third test fail (the second seed call self-heals instead of
raising the schema-mismatch error).
AC matrix
polylogue-o3a1t (default-root collision):
POLYLOGUE_ARCHIVE_ROOT) lane unaffected — satisfied.polylogue-wyvio (self-heal gate hardening):
Ref polylogue-o3a1t
Ref polylogue-wyvio