Skip to content

fix(demo): converge daemon import --demo path with direct seeder - #3179

Merged
Sinity merged 8 commits into
masterfrom
feature/fix/demo-daemon-import-parity
Jul 20, 2026
Merged

Sinity merged 8 commits into
masterfrom
feature/fix/demo-daemon-import-parity

Conversation

@Sinity

@Sinity Sinity commented Jul 19, 2026

Copy link
Copy Markdown
Owner

Summary

polylogue import --demo --wait (the live-daemon path) diverged from polylogue demo seed (the direct one-shot path) on the exact same fixture world: a different AI Studio session identity, missing provider-usage/embedding/repo demo enrichments, and a stale success banner / integration test asserting a 3-session/19-message world that predates the current 16-session demo corpus. This blocked publishing the README quickstart, which promises the two paths converge.

Ref polylogue-z1c6

Problem

Reproduced both paths against isolated scratch archive roots (a real polylogued run subprocess for the daemon path, fully isolated HOME/XDG_*/POLYLOGUE_* env — no operator config, no live Drive/network access) and diffed sessions/messages row-for-row. Three independent, separately-verified divergences:

  1. Identity bug: aistudio-drive:demo-00 (direct seed) vs aistudio-drive:demo-00-0 (daemon). The daemon's revision_backfill._parse_one decodes raw bytes through list(_iter_json_stream(...)) — a list-shaped stream reader — even for a plain single-JSON-document file, while the direct seeder keeps the bare dict. That incidental list-wrapping trips _lower_drive_like_payload's _looks_like_chunked_session_list branch, which (unlike its sibling fallthrough loop) always appends -{index} regardless of list length.
  2. Missing enrichment: the daemon path never ran the four demo-only augmentation steps (_inject_demo_session_usage, _materialize_session_insights, _inject_demo_session_repos, _seed_demo_embeddings) that seed_demo_archive calls inline — so provider_usage_messages, synthetic_message_embedding_rows, embedding_status_rows, and the postmortem repo/cost facts were permanently absent from the daemon-produced archive.
  3. Stale banner/test: the CLI success banner hardcoded sessions=3 messages=19, and tests/integration/test_demo_daemon_convergence.py asserted the same stale 3-session world — both predate the current 16-session demo corpus.

A fourth, deeper divergence was root-caused but not fixed here: one specific multi-material session (a direct ChatGPT export coalescing with its paired browser-capture variants) can nondeterministically lose 0-2 messages on the daemon path, because the daemon's incremental raw-materialization census (classify_raw_revision_cohort) can isolate-accept one competing raw as an "unambiguous singleton baseline" before its true siblings are discovered on a later tick, and a later membership-classification pass is then blocked from correcting it by an existing-head safety guard. This is a genuine architectural issue in the revision-authority subsystem, not a quick fix, and non-goal per this investigation's own findings (the "never choose between branches" conservatism for genuinely ambiguous data must not be weakened). Filed as polylogue-52l2 with full root-cause detail, a suggested approach, and a related pre-existing (unrelated to this PR, confirmed by direct comparison against unmodified master) flake in the direct-seed path's own construct checks.

Solution

  • polylogue/sources/dispatch.py: apply the same len(payloads) == 1 guard the sibling branch already uses in _lower_drive_like_payload, so a single-session wrapped payload keeps its bare fallback id.
  • polylogue/archive/session_revision_membership.py + polylogue/sources/revision_backfill.py: wire MembershipRevision.browser_snapshot_fidelity/provider_message_ids/provider_attachment_ids from the parser's own ingest flags (previously never populated, making the whole dom/native precedence branch dead code), and add _direct_export_precedence so a genuine non-browser-capture revision always outranks browser-capture-only siblings.
  • polylogue/storage/sqlite/archive_tiers/ingest_precedence.py: mirror the same direct-export-always-wins rule in the older/simpler browser_capture_precedence heuristic used by the non-revision-authority ingest path.
  • polylogue/demo/seed.py: extract the four demo-only augmentation steps into apply_demo_post_ingest_augmentation() (idempotent), exported from polylogue.demo.
  • polylogue/cli/commands/import_command.py: call the shared augmentation after daemon convergence (same place --with-overlays already runs client-side), derive the success banner's sessions=N messages=M from the real verifier result instead of a hardcoded placeholder, and split the wait-loop's semantic check (verify_demo_archive(check_constructs=False)) from the final full check so waiting on base ingest convergence doesn't deadlock against constructs only the augmentation stage can satisfy.
  • polylogue/demo/verify.py: add the check_constructs parameter enabling the above.
  • Tests: unit regressions for each fix (dispatch identity, membership-classification precedence, ingest-flag wiring, augmentation idempotency/parity), plus a rewritten tests/integration/test_demo_daemon_convergence.py against the current 16-session DEMO_SESSION_IDS world that asserts the fixed regressions and tolerates (with an explicit, bounded, documented assertion) the one still-open construct/message-count gap tracked in polylogue-52l2.

Verification

  • mypy on every touched file — clean (Success: no issues found in 13 source files).
  • ruff format --check / ruff check — clean.
  • devtools test tests/unit/sources/test_dispatch_payloads.py tests/unit/archive/test_session_revision_membership.py tests/unit/sources/test_revision_backfill.py tests/unit/demo/test_demo_seed_verify.py — 64 passed, 3 pre-existing failures classified below.
  • pytest tests/integration/test_demo_daemon_convergence.py -q -p no:randomly --timeout=280 — 1 passed (real polylogued run subprocess, real import --demo --wait).
  • devtools verify --quick — exit 0 (format, lint, mypy, render-all-check, topology/layering/manifests/doc-commands/etc.).
  • Pre-existing failure classified, not caused by this PR: tests/unit/demo/test_demo_seed_verify.py::test_seed_demo_archive_creates_ready_queryable_archive / test_demo_verify_reports_missing_overlays / test_demo_verify_can_skip_daemon_source_path_leak_posture flake (~40-60% failure rate across repeated -p no:randomly runs) on source_outage_interval_events/capture_gap_events construct checks in the direct seeder path. Confirmed by temporarily restoring the pre-change ingest_precedence.py from git show HEAD and re-running the same test 6x — identical flake rate with or without this PR's changes. Root cause not isolated (file-walk order is already deterministically sorted, ruled out); documented as an addendum to polylogue-52l2.

Acceptance criteria (from polylogue-z1c6)

  • Session/message identity converges for the AI Studio session and all provider-usage/embedding/repo enrichments: satisfied.
  • Success banner and integration test assert the current canonical world: satisfied.
  • Full 37-construct parity + polylogue demo verify passing against the daemon-produced archive: not satisfied for one multi-material session's 3 constructs, tracked in polylogue-52l2 with the exact root cause and a suggested fix. Bead left open per the investigation's own scope decision (not silently closed).

@coderabbitai

coderabbitai Bot commented Jul 19, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

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

Next review available in: 17 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

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 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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: eb339dde-9dd3-4bb0-98f5-35e0e7bfc217

📥 Commits

Reviewing files that changed from the base of the PR and between cd5c12c and 83be7d0.

📒 Files selected for processing (18)
  • polylogue/archive/ingest_flags.py
  • polylogue/archive/session_revision_membership.py
  • polylogue/cli/commands/import_command.py
  • polylogue/demo/__init__.py
  • polylogue/demo/seed.py
  • polylogue/demo/verify.py
  • polylogue/pipeline/services/ingest_batch/_core.py
  • polylogue/sources/dispatch.py
  • polylogue/sources/revision_backfill.py
  • polylogue/storage/sqlite/archive_tiers/archive.py
  • polylogue/storage/sqlite/archive_tiers/ingest_precedence.py
  • tests/integration/test_demo_daemon_convergence.py
  • tests/unit/archive/test_session_revision_membership.py
  • tests/unit/demo/test_demo_seed_verify.py
  • tests/unit/pipeline/test_ingest_batch.py
  • tests/unit/sources/test_dispatch_payloads.py
  • tests/unit/sources/test_revision_backfill.py
  • tests/unit/storage/test_archive_tiers_archive.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/fix/demo-daemon-import-parity

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.

@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: 8b41bf52c9

ℹ️ 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".

Sinity added 8 commits July 20, 2026 01:55
Problem: polylogue import --demo --wait produced aistudio-drive:demo-00-0
instead of aistudio-drive:demo-00 -- a divergence from `polylogue demo
seed` on the exact same fixture (Ref polylogue-z1c6). The daemon's
revision-authority replay path decodes raw bytes through
list(_iter_json_stream(...)) (a list-shaped stream reader) even for a
plain single-document .json file, while the direct seeder keeps the bare
dict. That incidental list-wrapping tripped
_lower_drive_like_payload's `_looks_like_chunked_session_list` branch,
which (unlike its sibling fallthrough loop a few lines below) always
appended `-{index}` to the fallback id regardless of list length.

Solution: apply the same `len(payloads) == 1` guard the sibling branch
already uses, so a single-session wrapped payload keeps its bare
fallback id -- matching the identical bare-dict payload's identity.

Verification: devtools test tests/unit/sources/test_dispatch_payloads.py
-- 21 passed.
…census

Problem: session_revision_membership.classify_membership_revisions already
implements dom/native/direct-export precedence via
MembershipRevision.browser_snapshot_fidelity, but
revision_backfill.py's only call site
(`MembershipRevision(raw_id, projection, session.updated_at)`) never
populated browser_snapshot_fidelity, provider_message_ids, or
provider_attachment_ids -- every census-time MembershipRevision carried
browser_snapshot_fidelity=None regardless of the parsed session's actual
ingest flags, making that entire precedence branch dead code in
production (Ref polylogue-z1c6).

Solution: add `_browser_snapshot_fidelity()` deriving "dom"/"native"/None
from the parser's own ingest flags (DOM_FALLBACK_INGEST_FLAG,
NATIVE_BROWSER_CAPTURE_INGEST_FLAG, COMPACT_BROWSER_CAPTURE_INGEST_FLAG)
and thread it (plus message/attachment provider ids) into the
MembershipRevision construction. Also add
`_direct_export_precedence()` to classify_membership_revisions: a
genuine non-browser-capture revision (fidelity=None) now unconditionally
outranks dom/native browser-capture siblings when it is the sole
non-browser candidate, mirroring the equivalent rule already added to
`ingest_precedence.browser_capture_precedence` in this same change -- a
browser capture backfills a session before its direct export arrives, it
never competes with the export once it does.

Verification: devtools test tests/unit/archive/test_session_revision_membership.py
tests/unit/sources/test_revision_backfill.py -- 22 passed. mypy clean.

Note: this fix is necessary but not sufficient for full daemon/direct-seed
parity on multi-material sessions -- a separate, deeper incremental-census
ordering issue (classify_raw_revision_cohort can isolate-accept a raw
before its true siblings are discovered) still causes nondeterministic
outcomes for exactly one demo session. Tracked as polylogue-52l2.
…head

Problem: browser_capture_precedence's only path for a genuine
non-browser-capture arrival against a browser-capture-established
session fell through to provider-timestamp freshness, which is order
dependent: a browser capture's own capture timestamp is frequently later
than the underlying conversation's real updated_at (the capture can
happen well after the last message was sent), so a live daemon ingesting
a batch of newly staged files with no cross-file ordering guarantee can
process the capture before its paired direct export and then
permanently treat the (correct, richer) direct export as "stale"
(Ref polylogue-z1c6).

Solution: when the existing session was established only by a browser
capture (dom-fallback or native-payload) and the incoming raw carries
neither flag, always replace -- independent of message count or
timestamp comparison. A single-writer replay that always processes the
direct export first never observes the bug; this makes the outcome
order-independent for both paths.

Verification: confirmed by direct comparison against the pre-fix
ingest_precedence.py (git show HEAD) that pre-existing flakiness in
tests/unit/demo/test_demo_seed_verify.py's
source_outage_interval_events/capture_gap_events construct checks (~50%
failure rate over 6 repeated runs, tests/unit/demo/test_demo_seed_verify.py::test_demo_verify_reports_missing_overlays)
reproduces identically with and without this change -- it is a
pre-existing, order-dependent bug unrelated to this fix (recorded in the
polylogue-52l2 follow-up, not fixed here). devtools test
tests/unit/sources/test_dispatch_payloads.py
tests/unit/archive/test_session_revision_membership.py
tests/unit/sources/test_revision_backfill.py -- 55 passed. mypy clean.
Problem: `polylogue demo seed` inline-called four demo-only enrichment
steps after ingest (provider usage injection, session-insight
materialization, canonical repo name, synthetic message embeddings), but
`polylogue import --demo --wait` never called them at all -- the daemon
path converged sessions/messages but permanently lacked
provider_usage_messages, synthetic_message_embedding_rows,
embedding_status_rows, and the postmortem repo/cost facts (Ref
polylogue-z1c6). The CLI success banner also hardcoded a stale
"sessions=3 messages=19" that predates the current 16-session demo
world.

Solution: extract the four steps into
`apply_demo_post_ingest_augmentation()` (idempotent -- UPDATE / INSERT
... ON CONFLICT throughout), export it from polylogue.demo, and call it
from both `seed_demo_archive()` and `import_command.py`'s `--wait` flow
(the same place `--with-overlays` already runs client-side after daemon
convergence). Add `verify_demo_archive(check_constructs=False)` so the
convergence-wait loop can block on base session/message identity without
also requiring the augmentation-only constructs it hasn't run yet --
fixing the chicken-and-egg deadlock that would otherwise make --wait
time out forever. The success banner now derives its
`sessions=N messages=M` line from the real verifier result.

Verification: devtools test tests/unit/demo/test_demo_seed_verify.py --
9 passed (one new test seeds via parse_sources_archive directly, skipping
seed_demo_archive's inline calls, then applies the shared augmentation
standalone and calls it twice to prove idempotency). mypy clean.
Problem: test_demo_daemon_convergence.py still asserted the stale
3-session/19-message demo world (a hardcoded EXPECTED_DEMO_SESSIONS
tuple and `_message_count(archive_root) == 19`) and staged-directory
contents ("chatgpt", "claude-code", "codex" only) -- both predate the
16-session demo corpus and would fail unconditionally against it (Ref
polylogue-z1c6).

Solution: rewrite against `polylogue.scenarios.DEMO_SESSION_IDS` (the
canonical, currently-16 session identity set) and the current 6-source
staged layout. Assert the specific regressions this investigation fixed:
the `aistudio-drive` session's native id is the bare "demo-00" (not
"demo-00-0"), and the daemon path now materializes provider usage cost
via the shared post-ingest augmentation stage. The CLI's own final
`--wait` verification can still legitimately fail on exactly three
known-gap constructs (capture_gap_events, browser_capture_raw_variants,
source_outage_interval_events) tracked in polylogue-52l2 -- a genuine,
deeper incremental-census ordering bug in
polylogue/sources/revision_backfill.py that this investigation
root-caused but did not fix (see the module docstring); the test accepts
either a clean success banner or exactly that known failure shape, and
still fails loudly on any other/unexpected construct failure. The one
affected session's message count is asserted as a bounded range (1-3)
rather than an exact value, since the daemon path resolves it
nondeterministically today.

Verification: pytest tests/integration/test_demo_daemon_convergence.py -q
-p no:randomly --timeout=280 -- 1 passed (10s). mypy clean. Not run
through devtools test (integration tests are excluded from the default
testmon selection); run directly via pytest per TESTING.md.
Problem: PR review on #3179 found the direct-export-precedence rule this
PR added was one-sided. It handled "existing established by a browser
capture, incoming is a genuine export" (unconditional replace), but not
the mirror: a native browser capture arriving AFTER a direct export was
already stored, carrying >= as many messages as that export, fell through
to ``incoming_owns_browser_merge``'s native-payload leg and replaced the
authoritative export -- order-dependent, symmetric to the bug this PR
already fixed in the other direction. Separately, both precedence-flag
derivations (archive.py's ArchiveStore facade and
ingest_batch/_core.py's worker write path) only checked
NATIVE_BROWSER_CAPTURE_INGEST_FLAG, but claude browser parsing also emits
COMPACT_BROWSER_CAPTURE_INGEST_FLAG for the compact capture shape
(browser_capture.py's `_is_compact_native_capture`) -- a compact capture
was silently classified as a genuine, non-browser-capture export, so a
real direct export arriving afterward could be rejected by timestamp
freshness instead of forcibly replacing it.

Solution:
- ingest_precedence.py: add the mirror rule
  (`incoming_is_browser_capture and not existing_is_browser_capture ->
  skip`) so a genuine export, once established, resists every later
  browser-capture arrival unconditionally -- matching the existing rule's
  guarantee in the other direction.
- ingest_flags.py: add `NATIVE_BROWSER_CAPTURE_FLAGS` (both native-payload
  flags) as the one place that enumerates "this session carries native
  browser-capture provenance"; `session_has_parser_ingest_flag` and
  `_incoming_has_ingest_flag` now accept a flag or a sequence of flags (an
  `IN (...)` query / `any()` check) instead of exactly one.
- archive.py + ingest_batch/_core.py: both native-payload derivations use
  `NATIVE_BROWSER_CAPTURE_FLAGS` instead of the single NATIVE flag.

This changes the intentional policy encoded by the pre-existing
`test_archive_tiers_archive_facade_native_browser_precedence_matrix` /
`test_write_session_native_browser_precedence_matrix` parametrized
suites, which asserted a competing "richer/tied content wins, ties favor
native" policy for the exact cases this fix targets (a plain export tied
or weaker than an established native capture used to lose; it now always
wins, and vice versa) -- updated both matrices' expectations plus the
three-arrival tests, and added a new
`test_archive_tiers_archive_facade_export_vs_native_precedence_is_order_independent`
parametrized test that runs both arrival orders back-to-back and asserts
they converge to a byte-identical final transcript, directly proving the
order-independence claim rather than relying on eyeballing separate
before/after rows.

Verification: devtools test tests/unit/storage/test_archive_tiers_archive.py
tests/unit/pipeline/test_ingest_batch.py -- 158 passed. Two pre-existing,
unrelated failures classified and left untouched: the already-documented
source_outage_interval_events/capture_gap_events direct-seed flake
(polylogue-52l2 addendum), and
test_exact_session_action_count_bounds_pairing_before_global_ranking (an
environment-sensitive SQLite VM-step threshold check unrelated to
browser-capture precedence -- confirmed via `git diff HEAD` that this
change touches only an import rename and a boolean derivation in a
function this test never calls). mypy clean, ruff clean.
…races

Problem: PR review on #3179 flagged that with a live daemon,
apply_demo_post_ingest_augmentation's one-shot injection can race the
daemon's own insight-materialization convergence stage: if that stage
recomputes session_profiles from a pre-injection snapshot after this
function's own rebuild_session_insights_sync call, the injected
usage/cost is silently overwritten with zeros even though the injection
itself succeeded moments earlier. Confirmed live (a real
`polylogued run` + `import --demo --wait`): total_cost_usd read back as
0.0 on one run despite messages.input_tokens/output_tokens being
correctly injected.

Solution: apply_demo_post_ingest_augmentation now bounds a small
self-heal loop (`_AUGMENTATION_SETTLE_ATTEMPTS`, a short beat apart):
after running the four idempotent enrichment steps, it verifies the
injected Claude Code usage actually survived materialization
(`_demo_usage_has_settled`) and, if not, re-applies the whole sequence.
A no-daemon caller (the direct seeder) always settles on the first
attempt, so this adds no observable cost there. The CLI
(`import_command.py`) needed no change -- it already calls the shared
function exactly once; the self-heal now lives where the demo-specific
knowledge already is, rather than duplicating a retry loop at the call
site.

The integration test's own manual re-apply-and-poll loop (added while
diagnosing this race) is now redundant given the production function
self-heals; simplified to a single read-back.

Verification: devtools test tests/unit/demo/test_demo_seed_verify.py --
9 passed. pytest tests/integration/test_demo_daemon_convergence.py -q -p
no:randomly --timeout=280 -- 1 passed (real daemon, real --wait).
mypy clean.
Problem: master's #3182 (rebased onto this branch) added gemini-cli,
antigravity, and hermes origins to the demo fixture world, adding three
new staged directories. This test's staged-directory assertion hardcoded
the pre-#3182 six-directory list, so it failed unconditionally against
the current demo world -- the exact class of staleness this PR's own
integration-test rewrite was meant to fix.

Solution: derive the expected staged-directory set from
demo_source_specs() (the same source of truth demo_source_specs()
already provides for materialize_demo_source()) instead of a literal
list, mirroring the DEMO_SESSION_IDS approach already used for session
identity -- a future demo-corpus addition changes source specs and this
assertion together, by construction.

Verification: pytest tests/integration/test_demo_daemon_convergence.py -q
-p no:randomly --timeout=280 -- 1 passed (real daemon, real --wait, full
current 9-origin demo world). mypy clean. devtools verify --quick exit 0.
@Sinity
Sinity force-pushed the feature/fix/demo-daemon-import-parity branch from 8b41bf5 to 83be7d0 Compare July 20, 2026 00:01
@Sinity

Sinity commented Jul 20, 2026

Copy link
Copy Markdown
Owner Author

Addressed all three review findings:

P1 #1 (order-independence): added the mirror rule to browser_capture_precedence (incoming_is_browser_capture and not existing_is_browser_capture -> skip), symmetric to the rule this PR already had. This changed the intentional policy encoded by the pre-existing test_archive_tiers_archive_facade_native_browser_precedence_matrix / test_write_session_native_browser_precedence_matrix suites (they asserted a "richer/tied content wins, ties favor native" policy for exactly the cases this fix targets), so I updated both matrices' expectations plus the three-arrival tests, and added a new parametrized test (test_archive_tiers_archive_facade_export_vs_native_precedence_is_order_independent) that runs both arrival orders back-to-back and asserts they converge to a byte-identical final transcript — proving order-independence directly instead of relying on eyeballing separate before/after rows.

P1 #2 (compact flag): added NATIVE_BROWSER_CAPTURE_FLAGS (both NATIVE_BROWSER_CAPTURE_INGEST_FLAG and COMPACT_BROWSER_CAPTURE_INGEST_FLAG) as the one place enumerating "native browser-capture provenance"; session_has_parser_ingest_flag/_incoming_has_ingest_flag now accept a flag or sequence of flags. Both callers (archive.py, ingest_batch/_core.py) updated.

P2 #3 (augmentation race): picked the "make it idempotently reasserted" option — apply_demo_post_ingest_augmentation now bounds a small self-heal loop (checks whether the injected usage survived materialization, re-applies if not, a few times a short beat apart). No CLI change needed since the self-heal lives in the shared function the CLI already calls once. Confirmed live (real polylogued run + import --demo --wait) that total_cost_usd reads back correctly now.

Verification: devtools test tests/unit/storage/test_archive_tiers_archive.py tests/unit/pipeline/test_ingest_batch.py tests/unit/sources/test_dispatch_payloads.py tests/unit/archive/test_session_revision_membership.py tests/unit/sources/test_revision_backfill.py tests/unit/demo/test_demo_seed_verify.py — 159 passed, 1 pre-existing/unrelated failure (test_exact_session_action_count_bounds_pairing_before_global_ranking, an environment-sensitive SQLite VM-step threshold check confirmed via git diff HEAD to be untouched by this change). pytest tests/integration/test_demo_daemon_convergence.py -q -p no:randomly --timeout=280 — 1 passed (real daemon). devtools verify --quick — exit 0. mypy clean, ruff clean.

Rebased onto current master (picked up #3182's gemini-cli/antigravity/hermes demo origins along the way; updated the integration test's staged-directory assertion to derive from demo_source_specs() instead of a hardcoded list so it doesn't go stale again).

@Sinity
Sinity merged commit b473d92 into master Jul 20, 2026
3 checks passed
@Sinity
Sinity deleted the feature/fix/demo-daemon-import-parity branch July 20, 2026 00:06
Sinity added a commit that referenced this pull request Jul 20, 2026
Sinity added a commit that referenced this pull request Jul 20, 2026
## Summary

Revises the README (and touches devtools' VHS tape generator,
docs/installation.md, docs/mcp-reference.md) per the maintainer's
2026-07-19 critique captured in `polylogue-93cp`: badge ordering, a
broken hero image, a wrong Homebrew claim, several over-specified
defensive caveats, a philosophically-framed evidence-model section with
unverified claims, and a stale/imprecise MCP roles sentence.

## Problem

The maintainer found the README "unimpressive": badges in an arbitrary
order, a low-quality hero terminal image (malformed shell prompt, GIF
compression artifacts), a Homebrew install sentence that (if true) would
make that install route useless since the daemon is essential, an
over-specified per-origin fidelity matrix, an off-topic
ambient-desktop-timeline disclaimer, internal registry-classification
caveats that belong in tracked beads instead of public hedging, and an
"evidence model" section written as philosophy rather than
schema/data-modelling, with claims (context compiler, judgment flow)
that needed verifying against source rather than assuming.

## Solution

- **Badges**: reordered to PyPI, Python, Homebrew, CI, CodeQL, docs. The
Python badge (3.11+) already matched pyproject's `requires-python =
">=3.11"` — no change needed there.
- **Hero image**: root-caused the bad render. `devtools/visual_vhs.py`
generated tapes without pinning `Set Shell`/`Set FontFamily`, so the
committed PNG depended on whichever shell/dotfiles were active when it
was captured — it had literally leaked an unexpanded bash prompt-escape
sequence (`\[\]> \[\]`) into the image. The PNG was also a manually
ffmpeg-extracted frame from an already 256-color GIF (visible
compression artifacts on glyph edges). Fixed by pinning `Set Shell
"bash"` + `Set FontFamily "DejaVu Sans Mono"` on every generated tape,
forcing a deterministic `PS1='> '` inside the evidence-receipt tape's
hidden setup block, and switching to VHS's native `Screenshot` command
for a full-quality capture instead of a GIF-frame extraction.
Regenerated all four tapes + the committed PNG, and **visually reviewed
the final committed image myself** (clean `> ` prompt, no artifacts,
real `polylogue demo receipts --compact --no-seed` output). Rewrote the
caption, which previously claimed a `devtools lab policy
demo-tour-freshness` check applied to this image — that gate actually
only verifies the unrelated `demo tour` example, and the recipe-sync
check it did correctly cite (`visual-tapes --check`) proves recipe-sync,
not visual quality.
- **Homebrew**: inspected
`nix/homebrew-tap-template/Formula/polylogue.rb` — it uses
`virtualenv_install_with_resources` over the same `pyproject.toml`
`[project.scripts]` entry points as pipx/uv (`polylogue`, `polylogued`,
`polylogue-mcp`, `plg`, `plog`, `polylogue-hook`), and the formula's own
`test do` block asserts `polylogued --help` / `polylogue-mcp --help`.
Homebrew already ships all three console scripts — the README's claim
that only Python/Nix do was simply wrong. Fixed the README sentence and
expanded `docs/installation.md`'s Homebrew paragraph to say so
explicitly.
- **Cut over-specification**: replaced the 8-row per-origin
fidelity-boundary table and the "only 5 of 8 origins populate the demo"
paragraph in "What it captures" with one confident sentence plus a link
to `docs/provider-origin-identity.md`; removed the
ambient-desktop-timeline disclaimer paragraph (and its grep command) and
the grok-export/browser-capture registry-classification caveats from
Limitations (tracked as feature beads instead of public hedging).
- **"Why the evidence model matters" → "Modelling decisions"**: rewrote
all four subsections in a plain schema/data-modelling register. Verified
each claim against source before keeping it:
`polylogue/context/compiler.py` genuinely records selected evidence,
typed omissions (`ContextOmissionReason`), caveats, and lossiness;
`AssertionStatus` (ACCEPTED/REJECTED/DEFERRED/SUPERSEDED) and the
`polylogue judge` CLI command are real and wired end-to-end through
`storage/sqlite/archive_tiers/user_write.py`. Reworded away from "human
reviews every candidate" toward the actual mechanism: candidates land
with `context_policy_json` defaulting to `{"inject": false}` (verified
in `storage/sqlite/archive_tiers/user.py`), and injection is
policy-controlled, not a universal review ceremony.
- **MCP sentence**: reworded to configuration terms (read-only by
default; write access is an explicit config opt-in) and corrected the
stale "104 tools / 66 exposed" figures. Live introspection
(`build_server(role=...).list_tools()` per role) shows the registry has
consolidated to **10 top-level operation-dispatcher tools**: `read` role
exposes 6 (`status`, `read`, `get`, `query`, `explain`, `context`),
`write` adds 2 (`write`, `run`), `review` adds `judge`, `admin` adds
`maintenance`. Fixed the same stale figures in `docs/mcp-reference.md`,
whose generated tool-index block already showed 10 but whose
hand-written prose header still said "~100 tools" (self-contradictory
doc, now fixed).

## Not in scope / follow-ups

- `CLAUDE.md` still cites the old "103 tools" MCP figure in two places
(Surfaces section + MCP gotchas). Filed `polylogue-f8r2` to fix it, and
`tests/infra/mcp.py`'s comment, separately from this docs-only PR.
- Did **not** adopt the external res-04 draft's two-terminal
daemon-based quickstart (`polylogue import --demo --wait`). That path's
construct parity with `polylogue demo seed` is still being repaired
under `polylogue-z1c6`, which **is still open** as of opening this PR
(PR #3179 is up but not merged). Kept the existing `demo receipts`/`demo
tour` quickstart, which uses the direct-seed path and is unaffected by
that bug — re-verified this session that it still produces the claimed
structural verdict.
- Read the res-04 positioning draft
(`.agent/handoffs/external-agent-campaigns/2026-07-17-gpt-pro-wave-2/results/res-04/r01/extracted/REPORT.md`)
as input; adopted its category framing intent and provider-table
trimming direction, but kept the existing README structure and section
order rather than the full rewrite, since the existing structure was
already sound and a smaller, targeted diff is easier to verify against
source.

## Verification

- `devtools test tests/unit/devtools/test_visual_vhs.py
tests/unit/devtools/test_render_visual_tapes.py` — 23 passed.
- `devtools render visual-tapes --check` — 4 tape specs generate
cleanly, 4 committed tapes match their generated spec output.
- `devtools render all --check` — exit 0, no "out of sync" lines
(grepped explicitly; public-claims, docs-surface, mcp-equivalence,
mcp-tool-index, pages all "sync OK").
- `devtools verify --quick` — exit 0 (16/16 steps), also ran
automatically and passed on `git push` via the pre-push hook.
- Manually viewed the final committed
`docs/examples/visual-tapes/evidence-receipt.png` with an image-reading
tool before committing.

Ref polylogue-93cp
Sinity added a commit that referenced this pull request Jul 20, 2026
)

Ref polylogue-93cp demo program (runbook category A).

## Summary
Refreshes the deterministic basic-usage walkthrough artifacts against
current master — first refresh since #3178 (transcript crash fix), #3179
(import parity), #3182 (all-origins seeding) landed.

## Problem
Committed walkthrough outputs predated three merged changes that alter
demo-visible behavior: corpus grew 16→19 sessions / 62→71 messages
across 8 origins, index schema v40→v42, embeddings v3→v4, and the MCP
surface consolidation (#3056) renamed the tools the MCP walkthrough
exercises.

## Solution
Re-ran every walkthrough recorded command against a fresh scratch seed:
1-4 (find/read/search/resume) byte-identical — surface stability
demonstrated; 5/8 (cost, status/debt) refreshed with expected
corpus-growth deltas; 7 (MCP round-trip) refactored onto the query/read
dispatchers preserving the search→summary pattern; README stamp + schema
refs updated. Cold-reader gate re-answered from directory contents
alone. Produced by a Haiku lane; branch harvested by coordinator.

## Verification
Each walkthrough re-executed against a fresh `polylogue demo seed` in a
scratch root; diffs classified per-artifact (table in lane report);
`devtools verify --quick` 16/16 green.

Co-authored-by: Claude <[email protected]>
Sinity added a commit that referenced this pull request Jul 29, 2026
…owser-wins

Problem: three coalescing tests on master asserted a browser-capture
title should outrank a coexisting direct/GDPR export title
(test_browser_capture_raw_payload_coalesces_with_chatgpt_export x2
parametrizations, test_browser_capture_raw_payload_coalesces_with_claude_ai_export).
All three failed on a clean origin/master checkout, order-independently.

Investigation established this is a stale test contract, not a
regression: #3179 (b473d92, polylogue-z1c6) intentionally added a
"direct export always wins" mirror rule to
browser_capture_precedence() in
polylogue/storage/sqlite/archive_tiers/ingest_precedence.py, so a
browser capture can never shadow a genuine export once it arrives
(only backfill ahead of one). That PR predates these three tests'
last edit and updated the sibling proof
test_archive_tiers_archive_facade_export_vs_native_precedence_is_order_independent
in tests/unit/storage/test_archive_tiers_archive.py (already asserting
export-wins) but missed these three in test_browser_capture.py.

Live-archive check (read-only, /realm/db/polylogue): 0 sessions
currently have raw_sessions rows with more than one distinct
capture_mode for the same (origin, native_id), so no live session's
title is affected either way -- production has been export-wins all
along, only the tests were stale.

What changed: updated the three title assertions to the current,
intentional rule and added a comment citing the precedence function,
#3179/polylogue-z1c6, and the sibling order-independence test.

Ref polylogue-lrdh

Verification:
  devtools test tests/unit/sources/test_browser_capture.py -k coalesces  -> 3 passed
  devtools test tests/unit/sources/test_browser_capture.py               -> full file green
  devtools test tests/unit/storage/test_archive_tiers_archive.py -k precedence -> 13 passed
  devtools verify --quick                                                -> exit_code 0

Co-Authored-By: Claude <[email protected]>
Sinity added a commit that referenced this pull request Jul 29, 2026
Problem: `devtools test tests/unit/cli/test_import.py -k demo_wait` had
two red tests reporting the entire ~40-construct demo corpus at zero
(0/19 sessions, 0/31 messages). This looked like the demo seeder itself
was broken, but bisecting to b473d92 (#3179, 2026-07-20) showed the
production `import --demo --wait` flow changed to run
`apply_demo_post_ingest_augmentation` and the real `_verify_demo_now`
unconditionally after the wait step (previously `_verify_demo_now` only
ran on the `--with-overlays` branch, and the success banner printed a
hardcoded `sessions=3 messages=19`). tests/unit/cli/test_import.py was
never updated for that call-sequence change, so both tests let the real
augmentation/verifier hit the empty per-test archive (urlopen and the
daemon wait are mocked; no real ingest ever runs in these unit tests) —
one crashed on `no such table: sessions`, the other correctly reported
the archive as empty.

Also fixed a pre-existing, unrelated staleness in
`test_import_demo_materializes_fixture_world_before_daemon_request`:
its expected source-directory listing and JSON fixture count predate
the gemini-cli/antigravity/hermes demo origins added in #3182/#2674,
so it asserted 6 directories where 9 now exist and 4 fixture files
where 7 now exist.

What changed:
- test_import_demo_wait_verifies_after_daemon_acceptance: mock
  `apply_demo_post_ingest_augmentation` and `_verify_demo_now`
  (matching the with-overlays test's existing pattern), assert the
  call sequence daemon -> wait -> augment -> verify, and assert the
  banner against the fake DemoVerifyResult's counts instead of hitting
  the real (unseeded) archive.
- test_import_demo_wait_with_overlays_seeds_after_convergence: add the
  missing `apply_demo_post_ingest_augmentation` mock the production
  code already calls unconditionally; update the expected event order
  to daemon -> wait-base -> augment -> seed-overlays -> verify-overlays.
- test_import_demo_materializes_fixture_world_before_daemon_request:
  update the expected directory listing (+antigravity, +gemini-cli,
  +hermes) and fixture-file count (4 -> 7) to match the current demo
  corpus.

This is a test-only fix: no production seeder, daemon, or storage code
changed. The declared demo-construct contract (`polylogue/demo/constructs.py`)
is untouched and still enforced end-to-end by
tests/unit/demo/test_demo_seed_verify.py and
tests/integration/test_demo_daemon_convergence.py; nothing here weakens
what those constructs require.

Verification:
- `devtools test tests/unit/cli/test_import.py -k demo_wait` -> 2 passed
- `devtools test tests/unit/cli/test_import.py` -> 19 passed
- `devtools verify --quick` -> exit 0

Co-Authored-By: Claude <[email protected]>
Sinity added a commit that referenced this pull request Jul 30, 2026
…e-revision keys (#3396)

## Summary

Fixes a proven silent fidelity downgrade: two raws of the same physical
document, censused under different `raw_sessions.logical_source_key`
values, were each independently accepted as a byte-proven singleton
baseline and raced to materialize the same `(origin, native_id)` session
with no comparison ever happening between them.

## Problem

Read-only queries against the live 99 GB archive (`/realm/db/polylogue`)
and the blob store, cross-checked against production parser code, showed
5 aistudio-drive sessions
(`Implementing-066bb070/13ced1c8/37edfeb3/845dd573/d4d7fbab`) with
attachments reporting `unfetched` despite the bytes existing in the blob
store:

- Each affected document has two raws at the SAME `source_path` — a bare
  and an attachment-enriched Drive re-acquisition — but with DIFFERENT
`raw_sessions.logical_source_key` values (`"...4c69"` vs `"...4c69-0"`).
- `raw_authority_parser_census` proves the `-0` suffix was produced by
the
  pre-#3179/z1c6 `dispatch.py` bug (`_lower_drive_like_payload`'s
  `_looks_like_chunked_session_list` branch always appended `-{index}`
  regardless of list length, fixed 2026-07-20 in b473d92). Reparsing
  both raw blobs with the CURRENT parser gives the identical, correct,
  unsuffixed identity for both — verified directly against the real
  blobs.
- `raw_authority_parser_census`'s quiescence gate only checks the
  `parser_fingerprint` STRING (unchanged across the fix), so the stale,
  buggy identity was never re-derived.
- `ArchiveStore.classify_raw_revision_cohort` classifies a byte-revision
  key in isolation. Neither raw's key ever surfaces the other as a
  sibling (`raw_membership_retired_full_revision_siblings` only matches
  the EXACT key), so each was accepted as a trivial one-member "chain" —
  no `raw_session_memberships` row was ever created for either raw, so
  neither ever reached the ambiguous-decision machinery. Both then raced
  to write the shared `(origin, native_id)` session row; the smaller,
  attachment-unfetched raw happened to write last.

## Solution

- `ArchiveStore.classify_raw_revision_cohort` gains an opt-in
  `check_source_path_identity_split` guard: refuse unconditional
  singleton acceptance when another `'full'` raw shares this raw's
  `source_path` under a DIFFERENT (or already-retired) key, folding both
  into membership governance instead, where the real content-based
  classifier (`classify_membership_revisions`) weighs them jointly.
  **Opt-in only** — the live watcher (`sources/live/batch.py`) does NOT
  set it: a watched path can legitimately be atomically replaced with a
  different session's content, which must not be quarantined as
  "divergent evidence" (proven by
`test_full_ingest_does_not_advance_cursor_across_same_size_replacement`
  et al., which regressed under an unconditional guard). Only
  `revision_backfill.py`'s offline backfill/rebuild replay loop — the
  path that actually produced this defect — opts in.
- `revision_backfill.py`'s retire-to-membership-governance fallback now
  buckets `membership_candidates`/`membership_keys` by the identity the
  retirement reparse actually recomputes, not the stale outer-loop key
  either raw was originally censused under. Without this, two
  same-document raws retired from different stale keys would land in
  SEPARATE membership cohorts and each be accepted as an independent
  singleton — reproducing the exact defect one layer down (confirmed
  empirically: reverting just this half makes `replayed_logical_sources`
  come back as `1` instead of `0`).

## Non-goals / follow-up

- The live archive's 5 already-downgraded sessions are NOT repaired by
  this PR (code-only fix, per scope; live remediation is a separate,
  explicitly out-of-scope lane).
- `polylogue-9dxn` (filed by a parallel lane) addresses the sibling
  problem — a persisted `ambiguous` verdict has no classifier-version
  column and is treated as terminal forever, so a classifier fix like
  `polylogue-bu1i`'s is inert on existing data. That fix does not, by
  itself, heal this defect: 9dxn's proposed quiescence gate stays
  permissive for any KNOWN fingerprint (to avoid forcing a blanket
  re-census), so a stale-but-`complete` (not `ambiguous`) census receipt
  like the one that caused this bug would stay "already observed"
  forever even after a fingerprint bump. This PR's guard is independent
  of fingerprint versioning and closes the general case regardless of
  how two same-document raws ended up under different keys.
- Filed `polylogue-eqnv` with the full evidence chain and the
  relationship to `polylogue-9dxn`/`polylogue-bu1i`/`polylogue-7ilr`.

## Verification

- `devtools test tests/unit/storage/test_revision_replay.py
  tests/unit/sources/test_revision_backfill.py
  tests/unit/sources/test_live_watcher.py
  tests/unit/sources/test_live_batch_support.py` — 235 passed (one
  unrelated pre-existing timing flake in
  `test_end_to_end_hidden_root_file_creation_triggers_ingest`, confirmed
  to reproduce on `master` without this change, in isolation, and
  disappear on repeated reruns of the same combined selection with this
  change applied — classified as pre-existing/flaky, not caused by this
  PR).
- `devtools verify --quick` — exit 0 (also ran automatically via the
  pre-push hook).
- `mypy polylogue/storage/sqlite/archive_tiers/archive.py
  polylogue/sources/revision_backfill.py` — `Success: no issues found in
  2 source files`.
- Anti-vacuity: reverting `archive.py`'s guard (via `git stash`) makes

`test_same_source_path_full_siblings_under_different_keys_are_not_independently_accepted`
  fail (`accepted_raw_ids` becomes non-empty instead of `()`). Reverting
  `revision_backfill.py`'s fresh-key bucketing alone makes
  `test_stale_pre_fix_identity_split_folds_into_one_ambiguous_cohort`
  fail (`replayed_logical_sources == 1` instead of `0`). Both confirmed
  by direct revert + rerun, restored afterward.

Ref polylogue-eqnv, polylogue-bu1i, polylogue-7ilr, polylogue-9dxn

Co-Authored-By: Claude <[email protected]>

Co-authored-by: Claude <[email protected]>
@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.

  • 61.F020 / P2: fixed-already at the checked revision: Daemon ingest now awaits profile convergence at polylogue/operations/daemon_ingest.py:1072 before the terminal receipt is completed. polylogue/operations/machine_receipts.py:398 reports degraded rather than completed when convergence is unfinished, so the import wait succeeds only after the profile stage preceding augmentation has settled.

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

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

  • 74.F069 / P1: fixed-already at the checked revision: Both precedence callers now test NATIVE_BROWSER_CAPTURE_FLAGS for stored and incoming material, including polylogue/pipeline/services/ingest_batch/_core.py:1504-1508 and revision_governance.py:623. That tuple explicitly includes compact and native captures at polylogue/archive/ingest_flags.py:17, so compact captures are no longer mistaken for direct exports.
  • 74.F070 / P1: fixed-already at the checked revision: The inverse precedence case is now explicit at polylogue/storage/sqlite/archive_tiers/ingest_precedence.py:151-152: an incoming browser capture is skipped when the existing session is a direct export. Larger capture message counts cannot reach the later replacement rules in that case.

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