Skip to content

feat(storage): preserve raw AISTUDIO capture mode (#2794) - #2794

Merged
Sinity merged 6 commits into
masterfrom
feature/fanout/origin-interop
Jul 12, 2026
Merged

Sinity merged 6 commits into
masterfrom
feature/fanout/origin-interop

Conversation

@Sinity

@Sinity Sinity commented Jul 12, 2026 •

Copy link
Copy Markdown
Owner

Summary

Persist the acquisition-time provider for raw captures that share the public aistudio-drive origin.

Problem

GEMINI exports and live Google Drive captures are structurally identical after parsing and both collapse to aistudio-drive; the existing raw tier retained only that origin, making their provider fiber irrecoverable on source-tier reads.

Solution

  • Class: additive durable source.db change, v7 to v8; raw_sessions.capture_mode is nullable so historic captures remain explicitly unknown.
  • Add migration 008_raw_session_capture_mode.sql. Acquisition constructors preserve configured capture mode separately from the shape-detected parser provider.
  • Full live-batch writes thread that explicit mode into ArchiveStore; a configured Drive source therefore persists DRIVE even when its chunked-prompt bytes select GEMINI for parsing.
  • Planning-state reads, raw revision replay, compact source envelopes, and the public raw-artifact route feed the persisted mode into the existing origin-fiber resolver, returning Provider.DRIVE for live Drive rather than the GEMINI canonical fallback.
  • No index-tier delta: this is source-evidence provenance, read from source.db rather than duplicated into rebuildable index state.
  • A content-identical GEMINI and DRIVE acquisition shares one content-addressed raw row; the scalar field retains the first known mode. Modeling both events is tracked in polylogue-buns; this PR does not claim to solve that many-to-one case.

Verification

  • env POLYLOGUE_PYTEST_BASETEMP_ROOT=/realm/tmp/polylogue-pytest nix develop --command devtools test tests/unit/core -k 'source or origin' — 114 passed.
  • env POLYLOGUE_PYTEST_BASETEMP_ROOT=/realm/tmp/polylogue-pytest nix develop --command devtools test tests/unit/pipeline/test_hermes_raw_identity.py tests/unit/sources/test_live_batch_support.py -k 'drive_acquisition or full_drive_capture or raw_identity' — 4 passed.
  • env POLYLOGUE_PYTEST_BASETEMP_ROOT=/realm/tmp/polylogue-pytest nix develop --command devtools test tests/unit/storage/test_raw.py tests/unit/storage/test_raw_revision_authority.py tests/unit/api/test_facade_contracts.py -k 'capture_mode or raw_revision_material or raw_artifact' — 8 passed.
  • Pre-push devtools verify --quick completed before pushing 2ce500267.

Anti-vacuity: the regressions exercise the real acquisition-record constructor, full live-batch → ArchiveStore source write, both SQLite source-tier writers, and source-tier readers. Removing configured-mode threading causes the Drive fixture to persist GEMINI; reintroducing fallback inference in either writer, or ignoring persisted capture mode, changes the real retrieved provider or turns a historical NULL into GEMINI and fails the tests.

Acceptance criteria

  • Durable nullable field and verified source-tier migration: satisfied.
  • Future unambiguous GEMINI/DRIVE raw captures retain and recover their acquisition provider across production source-tier routes: satisfied.
  • Historic captures are not backfilled by guesswork: satisfied for capture_mode; legacy provider compatibility projections retain their existing canonical fallback.
  • Multiple acquisition modes for a byte-identical raw identity: deferred to polylogue-buns.

Adversarial review notes

  • Iteration 1: found and fixed legacy-NULL duplicate backfill, blob-backed writer propagation, async first-known preservation, and three missed source-tier reader routes (1338306be, d259fbdc8, 12a965b7c). Identified the content-identical multi-acquisition limitation and filed polylogue-buns.
  • Iteration 2: fixed a real NULL-to-GEMINI round-trip corruption in both raw writers; acquisition paths now mark explicit provenance and the compact source envelope exposes it (2176e3ec0). Updated the stale storage-boundary documentation.
  • Iteration 3: corrected the live Drive acquisition path, which had stamped the shape-detected GEMINI parser provider instead of configured DRIVE capture provenance (2ce500267).

Ref polylogue-2ilz

Problem: GEMINI exports and live Drive captures share the public\naistudio-drive origin, which previously lost their acquisition-time\nprovider once raw evidence was persisted.\n\nWhat changed: source.db v8 adds nullable raw_sessions.capture_mode,\nwith an additive durable migration. All raw writers persist the known\nprovider and raw reads use it to disambiguate the existing origin fiber.\nHistorical captures remain NULL/unknown.\n\nRef polylogue-2ilz\n\nCo-Authored-By: Claude <[email protected]>
@coderabbitai

coderabbitai Bot commented Jul 12, 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: 57 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: 1480969d-a6d9-46d4-809a-38db3eba8da9

📥 Commits

Reviewing files that changed from the base of the PR and between 901825e and 2ce5002.

📒 Files selected for processing (19)
  • polylogue/core/sources.py
  • polylogue/pipeline/services/acquisition_records.py
  • polylogue/sources/live/batch.py
  • polylogue/storage/runtime/raw/records.py
  • polylogue/storage/sqlite/archive_tiers/archive.py
  • polylogue/storage/sqlite/archive_tiers/source.py
  • polylogue/storage/sqlite/archive_tiers/source_write.py
  • polylogue/storage/sqlite/async_sqlite_raw.py
  • polylogue/storage/sqlite/migrations/source/008_raw_session_capture_mode.sql
  • polylogue/storage/sqlite/queries/mappers_archive.py
  • polylogue/storage/sqlite/queries/raw_reads.py
  • polylogue/storage/sqlite/queries/raw_writes.py
  • tests/unit/api/test_facade_contracts.py
  • tests/unit/pipeline/test_hermes_raw_identity.py
  • tests/unit/sources/test_live_batch_support.py
  • tests/unit/storage/test_archive_tiers_source_write.py
  • tests/unit/storage/test_durable_migrations.py
  • tests/unit/storage/test_raw.py
  • tests/unit/storage/test_raw_revision_authority.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/fanout/origin-interop

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.

@Sinity Sinity changed the title feat(storage): preserve raw AISTUDIO capture mode feat(storage): preserve raw AISTUDIO capture mode (#2794) Jul 12, 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: f8243ba0f7

ℹ️ 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 and others added 3 commits July 13, 2026 00:05
Review fixes: backfill capture_mode only when the duplicate legacy row
has NULL, and carry capture mode through the blob-backed parsed-session
write route.

Verified: 3 focused tests passed.

Co-Authored-By: Claude <[email protected]>
Keep the first non-null raw capture mode when an async writer refreshes\nthe same raw ID. A later canonical fallback must not overwrite durable\nlive-Drive evidence.\n\nRef polylogue-2ilz\n\nCo-Authored-By: Claude <[email protected]>
Thread capture_mode through planning-state reads, raw revision replay, and\nthe public raw-artifact route so every source-tier reader preserves the\nDrive/GEMINI fiber member.\n\nRef polylogue-2ilz\n\nCo-Authored-By: Claude <[email protected]>
@Sinity

Sinity commented Jul 12, 2026

Copy link
Copy Markdown
Owner Author

Adversarial iteration 1 summary:

Findings and fixes:

  • Real: duplicate legacy rows could retain NULL provenance; blob-backed parsed writes omitted capture mode. Fixed in 1338306be with raw-payload and blob-backed duplicate regression coverage.
  • Real: async refresh could overwrite known DRIVE provenance with a later GEMINI fallback. Fixed in d259fbdc8; repeat-write test proves first-known mode remains DRIVE.
  • Real: planning-state reads, raw revision replay, and the public raw-artifact route omitted capture mode. Fixed in 12a965b7c; six focused real-route tests pass.
  • Real model limitation: a content-addressed raw ID can represent byte-identical captures observed through both mechanisms; one scalar field cannot encode both. Filed polylogue-buns and narrowed the PR claim accordingly.

What survived scrutiny: durable v8 migration, fresh DDL, known-provider persistence, legacy NULL preservation, and source-tier recovery for unambiguous raw identities.

Verification: focused route suite 6 passed; local and pre-push quick gates passed. GitHub Actions initialization failures remain the known account-billing infrastructure pattern.

Problem: hydrated pre-v8 raw rows expose a canonical provider for compatibility,
but both raw writers treated that projection as acquisition evidence and wrote
it back to the nullable durable field.

What changed: acquisition constructors now explicitly stamp capture mode; raw
writers persist only that explicit field and preserve legacy NULLs on a
read-save round trip. The compact source envelope exposes the durable mode,
and provider-origin documentation records the source/index boundary.

Compatibility: existing historical NULL rows remain unknown. New acquisition
records carry their known provider before origin collapse.

Ref polylogue-2ilz
@Sinity

Sinity commented Jul 12, 2026

Copy link
Copy Markdown
Owner Author

Adversarial iteration 2 summary:

Findings and fixes:

  • Real: a hydrated historic capture_mode = NULL row carries GEMINI as a legacy compatibility projection. Both source-tier raw writers incorrectly treated that projection as new acquisition evidence and rewrote the durable field. Fixed in 2176e3ec0: only acquisition paths stamp capture_mode; hydrated NULL remains NULL through either writer's real read-save path.
  • Real: acquisition constructors did not consistently assert capture mode before the origin collapse. make_raw_record and both live-batch record constructors now carry their known provider explicitly.
  • Exposure gap: ArchiveRawSessionEnvelope omitted the durable field. It now includes capture_mode.
  • Documentation gap: provider_from_origin still said no storage tier preserved acquisition provenance. It now distinguishes source-tier capture evidence from collapsed index rows and historic NULLs.

What survived scrutiny: source v8 remains additive and durable-only; unambiguous fresh captures recover GEMINI versus DRIVE; historical provenance stays unknown rather than guessed; the explicit multi-acquisition limitation remains tracked by polylogue-buns.

Verification: tests/unit/storage/test_raw.py capture-mode selection 5 passed; storage/acquisition selection 8 passed; required core source/origin selection 114 passed; pre-push quick gate completed before push. Tests used POLYLOGUE_PYTEST_BASETEMP_ROOT=/realm/tmp/polylogue-pytest.

Problem: live acquisition used the shape-detected parser provider for the new
capture field. A configured Drive source with a chunked-prompt payload is
correctly parsed as GEMINI, but must retain DRIVE as acquisition provenance.

What changed: archive raw-write APIs accept an explicit capture mode; the full
live-batch route passes the configured source mode independently from its
parser provider. Static record construction likewise favors a configured mode
before a payload hint.

Ref polylogue-2ilz
@Sinity

Sinity commented Jul 12, 2026

Copy link
Copy Markdown
Owner Author

Adversarial iteration 3 summary:

Finding and fix:

  • Real P1: the full live-batch route selected GEMINI from chunked-prompt shape detection and then used that parser provider as capture_mode, losing the configured Drive acquisition mechanism. 2ce500267 keeps parser selection and capture provenance separate: raw-write APIs take an explicit mode, full batch passes the record's acquisition mode, and record construction prefers a configured source mode over a payload hint.

Verification:

  • A real configured WatchSource(name='drive') with the ambiguous chunked-prompt fixture runs through full live batch → ArchiveStore and persists capture_mode='drive' (4 focused source/acquisition tests passed).
  • Source-tier capture/revision/artifact routes remain green (8 tests).
  • The PR's remaining scalar collision limitation is unchanged and explicitly deferred to polylogue-buns.

What survived scrutiny: durable v8 migration, historical NULL handling, unambiguous source-tier recovery, and no index-tier bump.

@Sinity

Sinity commented Jul 12, 2026

Copy link
Copy Markdown
Owner Author

Adversarial iteration 4 summary — zero new legitimate findings.

Scrutiny covered the full branch diff, polylogue-2ilz and its notes, current PR body/comments/inline review threads, and raw-write callers. The final review confirmed:

  • configured Drive acquisition remains distinct from chunked-prompt GEMINI parser detection and reaches the source writer as record.capture_mode;
  • sync and async raw writers only enrich an existing NULL from explicit acquisition evidence, while a hydrated historic NULL remains NULL;
  • source-tier planning, revision, envelope, and raw-artifact reads use the persisted mode; legacy NULL retains only the documented canonical compatibility projection;
  • the source v8 migration is nullable, additive, and durable-tier-only; and
  • byte-identical multi-acquisition ambiguity remains explicitly deferred to polylogue-buns.

No code change was needed this iteration. GitHub Actions init-only failures remain the known billing infrastructure condition.

@Sinity

Sinity commented Jul 12, 2026

Copy link
Copy Markdown
Owner Author

Final polylogue-2ilz acceptance matrix:

Acceptance item Status Evidence
Add durable per-capture provider evidence before Origin collapse satisfied Nullable source.db.raw_sessions.capture_mode, v8 durable migration, explicit acquisition-mode threading.
Distinguish GEMINI export from live Drive for future unambiguous captures satisfied Full configured-Drive chunked-prompt regression persists drive; source-tier reads resolve Provider.DRIVE.
Keep pre-migration provenance unknown rather than inventing it satisfied Historic capture_mode=NULL survives both real writer read-save routes; compatibility projection remains documented separately.
Preserve both modes for byte-identical captures sharing one raw ID deferred to polylogue-buns A scalar source row truthfully represents only one known acquisition mode; the follow-up owns the required multimap/ambiguous read contract.

Anti-vacuity: the relevant tests exercise production acquisition construction, full live batch → archive source writes, real SQLite writers/readers, and durable migration behavior. Removing explicit capture-mode propagation, restoring writer fallback inference, or dropping reader hints changes a real persisted/retrieved provider and fails them.

Ref polylogue-2ilz

@Sinity
Sinity merged commit 1256485 into master Jul 12, 2026
3 of 15 checks passed
@Sinity
Sinity deleted the feature/fanout/origin-interop branch July 12, 2026 23:36
Sinity added a commit that referenced this pull request Jul 13, 2026
…800,2781

2ilz (origin-interop, PR #2794), 3v1.1 (capture-hardening, PR #2785), and
qqyg (hooks-capture, PR #2781) fully satisfied — closed. 9e5.16 (api-parity,
PR #2782), 57rp/5k5l (capture-hardening, PR #2785), and 7fj (beads-ingest,
PR #2800) partially satisfied — noted with disposition, left open.

Co-Authored-By: Claude <[email protected]>
Sinity added a commit that referenced this pull request Jul 13, 2026
…2810)

## Summary

Repairs 3 failing source-tier durable migration tests on `master`,
introduced
by an incomplete fix-forward during merge-conductor rebase work on PR
#2800.

## Problem

PR #2794 (origin-interop) claimed source-tier migration slot `008` for
`capture_mode`. PR #2800 (beads-ingest) also numbered its own migration
`008`, requiring a rebase to renumber it to `009` (and preserve the
`capture_mode` column through the copy-forward rebuild it performs). The
test-file edits accompanying that rebase were made to the working tree
*after* the rebase commit but never actually `git add`ed/committed, so
PR #2800 merged without them. `master` currently fails:

- `test_source_tier_v2_migrates_to_v3_dropping_pending_blob_refs`
-
`test_source_tier_v3_adds_publication_reservations_with_verified_backup_receipt`
- `test_source_tier_v7_expands_origin_checks_with_verified_backup`

## Solution

- Updated the two `applied_versions`/`to_version` literal assertions to
  include migration `9` (was pinned to the old 8-step chain).
- `test_source_tier_v7_expands_origin_checks_with_verified_backup`
relied on
the `workspace_env` fixture's `ArchiveStore` pre-creating `source.db` at
  the *current* schema (already including `capture_mode`, since
`CREATE TABLE IF NOT EXISTS` silently no-ops against it) before the
test's
  own stripped-down "v7" DDL ever ran. Under a forced `PRAGMA
user_version=7` stamp, migration 8's `ALTER TABLE ADD COLUMN
capture_mode`
  then hit a real `duplicate column name` error. Added
`db_path.unlink(missing_ok=True)` before the `executescript`, matching
the
  pattern `_create_source_v1` already uses in the same file for the same
  fixture.

## Verification

- `devtools test tests/unit/storage/test_durable_migrations.py` — 33
passed.
- `devtools verify --quick` — 15/15 checks green.

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.

  • 75.F097 / P2: refuted at the checked revision: The reproduction starts from capture_mode=NULL rows produced by migrating a pre-v8 source.db. AGENTS.md:74-77 excludes those predecessor databases from fresh-v1 migration/readback, so a compatibility backfill for their raw-id conflicts is not an admitted runtime requirement.
  • 75.F098 / P2: fixed-already at the checked revision: The old blob-and-parsed helper is absent, and its parsed-admission replacement explicitly supplies capture_mode=session.source_name at polylogue/storage/sqlite/archive_tiers/revision_governance.py:4752. The grouped raw-plus-parsed route supplies the same field at :4935, preserving the Drive/AI Studio family member rather than storing NULL provenance.

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