Repository navigation
fix: give Drive re-acquisition real revision lineage - #3639
Conversation
Ref polylogue-sp72 Problem: Drive re-acquisition (sources/drive/__init__.py) backfills live-fetched attachment bytes into cached Drive JSON on every ingest pass, minting a new raw_id for the SAME logical session whenever the bytes change. That new raw is written through _write_session (the generic ingest_batch write path used by every non-tailed-watcher provider), which only ever compares content-hash/freshness -- it never computes logical_source_key or calls the revision-governance cohort classifier the way the governed "live" batch path does for tailed origins. Confirmed live: every one of 157 duplicate aistudio-drive raw pairs carries revision_kind='unknown', logical_source_key=NULL, revision_authority='quarantined' -- no predecessor/baseline linkage. Solution: add _bind_drive_revision_lineage + a minimal _DriveRevisionGovernanceAdapter (satisfying RawRevisionGovernanceHost structurally, per revision_governance.py's existing protocol) in pipeline/services/ingest_batch/_core.py. Called unconditionally at the top of _write_session for every raw reaching that path (mirroring live/batch.py's own precedent of binding before the write decision, so even a raw _write_session ultimately skips as stale/duplicate still gets lineage recorded). Gated on Provider.GEMINI, not Provider.DRIVE: every real config/test fixture configures Drive acquisition as Source(name="gemini", folder=...), and iter_drive_raw_data's provider_hint = Provider.from_string(source.name) means a parsed Drive session's source_name is actually Provider.GEMINI (both map to the same Origin.AISTUDIO_DRIVE). Mirrors raw_membership_raw_ids's guard against double-governing an identity already owned by membership-census governance. Non-fatal best-effort: any failure (including classify_raw_revision_cohort's writable-blob-publisher requirement) is logged and swallowed, never breaking the write itself. Does not replay the classifier's plan -- _write_session's own freshness/content-hash comparison (plus the #3453 attachment-coverage tie-break, left in place) still solely decides what lands in `sessions`. Verification: - devtools test tests/unit/pipeline/test_ingest_batch.py -- 66 passed, including the new test_write_session_binds_drive_revision_lineage (confirmed red against the pre-fix code: both raws' logical_source_key came back NULL; confirmed green after re-applying the fix). - .venv/bin/mypy polylogue/pipeline/services/ingest_batch/_core.py -- Success: no issues found in 1 source file. - .venv/bin/ruff format / ruff check -- clean. Scope notes: sources/drive/__init__.py untouched (design resolves this entirely post-parse, matching live/batch.py); no other provider is wired into this governance path; the #3453 tie-break is left in place unchanged (a genuine, still-useful safety net for callers this fix doesn't reach, e.g. _write_session paths without a source_conn/blob_publisher). Cleanup of the 157 already-contaminated raw_sessions rows is out of scope (retroactive durable-tier cleanup needs its own explicit-consent process). Co-Authored-By: Claude <[email protected]>
|
Warning Review limit reached
Next review available in: 30 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. 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 (2)
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 |
PR #3645 (vp2ky, split classify_raw_revision_cohort into _for_rebuild_repair/_for_live_watch variants) and PR #3639 (sp72, Drive revision lineage) landed within minutes of each other; sp72's new call site in _core.py still referenced the removed name, breaking every polylogue CLI invocation on master (ImportError). Use _for_live_watch, matching the actual live-tailed-watcher call sites (sources/live/append_ingest.py, sources/live/batch.py) and sp72's own stated intent ('the same governance the live tailed-watcher path already uses'). Co-Authored-By: Claude <[email protected]>
…eak (#3656) ## Summary Drive revision-lineage bookkeeping (added in #3639 for polylogue-sp72) computed a `RevisionReplayPlan` but discarded it, so the #3453 freshness-tie safety net still solely decided whether a governed Drive revision landed even when governance had already proven the winner. This closes that gap for the cases governance CAN prove, and adds an honest end-to-end test through the real `iter_drive_raw_data` acquisition path that documents a real residual limitation. ## Problem `_bind_drive_revision_lineage` (`polylogue/pipeline/services/ingest_batch/_core.py`, added in #3639) calls `classify_raw_revision_cohort_for_live_watch` to bind real lineage (`logical_source_key`/`predecessor_raw_id`/`revision_authority`) for Drive re-acquisitions, but never used the returned `RevisionReplayPlan`. The #3453 tie-break (`_incoming_write_regresses_attachment_coverage`) — which fires when two raws share an identical content-derived timestamp but differ in acquired-attachment coverage — kept deciding the outcome on its own heuristic even in cases where governance had already independently proven which raw is the legitimate accepted-chain successor. No existing test exercised the exact tie shape (identical message timestamps + differing attachment coverage) together with lineage governance, so this gap had no red/green evidence either way (confirmed: adding the test first and reverting the fix produces `assert False is True`). Separately, while building an honest test through the real `iter_drive_raw_data` acquisition path (not a hand-crafted byte-append fixture), I found that `_inject_live_drive_attachment_bytes`'s live-attachment backfill re-serializes the WHOLE JSON document (injecting resolved bytes into a nested dict), not a byte-append at the document's end. The second raw is therefore NOT a byte-prefix superset of the first (`not second_bytes.startswith(first_bytes)`, verified). `classify_raw_revision_cohort`'s classifier (`archive/revision_authority.py`) is strictly byte-prefix based, so this realistic shape still lands `revision_authority='quarantined'` with no `predecessor_raw_id` — same as before #3639 for this shape. What #3639 genuinely changed: both raws now carry a non-NULL `logical_source_key` and `revision_kind='full'` (never `'unknown'`), so a future consumer — or a classifier upgraded to recognize JSON-structural supersets, not just byte-literal ones — can still find and arbitrate the cohort. ## Solution - `_bind_drive_revision_lineage` now returns the `RevisionReplayPlan` it computes (`None` on any early-return or swallowed failure) instead of discarding it. - `_write_session` captures `drive_revision_proven_winner` (true when `payload.raw_id` is in the plan's `accepted_chain`) and skips the #3453 tie-break only when governance has proven this exact raw is the legitimate successor. The heuristic remains the deciding factor for every ungoverned case (no `source_conn`/`blob_publisher`, non-Gemini identity, or a classification failure) — this is a strict narrowing of when the safety net applies, never an unconditional bypass. - New tests in `tests/unit/pipeline/test_ingest_batch.py`: - `test_write_session_drive_lineage_proven_winner_bypasses_freshness_tie` — byte-append fixture (same shape as #3639's own lineage test), identical timestamps, an attachment-coverage regression that the old tie-break would have blocked; asserts the write lands anyway. - `test_write_session_freshness_tie_regression_without_lineage_still_blocks` — negative control: the identical regression shape, but no `source_conn` (so no governance evidence); asserts the safety net still blocks it. - New test in `tests/unit/sources/test_drive_ops.py`: - `test_iter_drive_raw_data_two_revision_fixture_gets_real_lineage` — threads two genuine `iter_drive_raw_data` passes (attachment fetch fails, then succeeds) through `ArchiveStore.write_raw_payload` + `parse_payload` + `_write_session`, the real production path. Asserts both raws get `logical_source_key` populated and `revision_kind='full'`, and documents (via an explicit assertion + docstring) that `predecessor_raw_id` is NOT established for this realistic non-append shape. ## Scope notes / deferred Per the bead's own notes ("absorbed by polylogue-1fijp ... individual fix remains legitimate if 1fijp stalls"): - Full closure of AC1's literal "predecessor-linked, not quarantined" wording for the realistic mid-document JSON mutation shape needs a JSON-structural-diff-aware classifier, not a byte-prefix one — materially larger scope, correctly deferred to polylogue-1fijp's raw-admission-chokepoint rewrite. This PR's bypass is real and tested for whatever cases DO produce a genuine byte-prefix relationship. - The 157 already-contaminated `aistudio-drive` raw pairs need a live re-measure after deploy — not attempted here (retroactive durable-tier cleanup needs its own explicit-consent process per this repo's schema regime). ## Verification - `devtools test -k drive` — 281 passed, 1 failed (`tests/integration/test_blob_lifecycle_e2e.py::TestOrphanedBlobsCatalogRouting::test_catalog_resolution_drives_end_to_end_cleanup`), confirmed pre-existing/unrelated by reproducing identically with `git stash` before this change applied. - `devtools test tests/unit/pipeline/test_ingest_batch.py` — 68 passed. - Red-first: temporarily reverted the `not drive_revision_proven_winner` guard and reran `test_write_session_drive_lineage_proven_winner_bypasses_freshness_tie` — failed with `assert False is True`; reapplied and reran green. - `mypy polylogue/pipeline/services/ingest_batch/_core.py tests/unit/sources/test_drive_ops.py tests/unit/pipeline/test_ingest_batch.py` — `Success: no issues found in 3 source files`. - `devtools verify --quick` — `exit_code: 0`. Ref polylogue-sp72 Co-Authored-By: Claude <[email protected]> Co-authored-by: Claude <[email protected]>
Summary
Drive re-acquisition now gets real revision lineage (
logical_source_key/predecessor_raw_id/ a non-quarantinedrevision_authority) via the same byte-prefix revision-governance classifier the "live" tailed-watcher batch path already uses, instead of being invisible to it entirely.Problem
iter_drive_raw_data(polylogue/sources/drive/__init__.py) backfills live-fetched attachment bytes into cached Drive JSON on every ingest pass. When the bytes change, it mints a brand-newraw_idfor the SAME logical session. That raw is written through_write_session(polylogue/pipeline/services/ingest_batch/_core.py), the generic ingest_batch write path used by every non-tailed-watcher provider, which only ever compares content-hash and freshness timestamps -- it never computeslogical_source_keyor calls the revision-governance cohort classifier the way the governed "live" batch path does for tailed origins (sources/live/batch.py,sources/live/append_ingest.py). Confirmed live: every one of 157 duplicateaistudio-driveraw pairs carriedrevision_kind='unknown',logical_source_key=NULL,revision_authority='quarantined'-- no predecessor/baseline linkage at all. PR #3453 added a narrow tie-break in_write_session(_incoming_write_regresses_attachment_coverage) that stops a richer revision from being clobbered by a poorer one on a freshness tie, but its own docstring names this missing-lineage gap directly as the real, unaddressed cause.Solution
_bind_drive_revision_lineageand a minimal_DriveRevisionGovernanceAdaptertopolylogue/pipeline/services/ingest_batch/_core.py. The adapter satisfiesRawRevisionGovernanceHost(storage/sqlite/archive_tiers/revision_governance.py) structurally -- every function in thebind_raw_revision/classify_raw_revision_cohortcall graph only touches_ensure_source_conn()and (insideclassify_raw_revision_cohort)_blob_publisher, so the adapter implements the rest of the Protocol (_conn,commit,_preacquire_attachment_blobs,_write_counts,_skipped_counts) as typed stubs/placeholders never actually exercised by this call path._bind_drive_revision_lineageis called unconditionally at the top of_write_session, before any of its skip-path early returns -- mirroringlive/batch.py's own precedent of binding lineage before the write decision is made, so a raw_write_sessionultimately skips as stale/duplicate still gets its lineage recorded (useful for future arbitration/rebuild consumers, e.g. polylogue-x1gd). It guards against double-governing an identity already owned by membership-census governance viaraw_membership_raw_ids, same aslive/batch.py.Provider.DRIVE, but every real config and test fixture configures Drive acquisition asSource(name="gemini", folder=...), anditer_drive_raw_data'sprovider_hint = Provider.from_string(source.name)means a parsed Drive session'ssource_nameis actuallyProvider.GEMINIon the wire (bothProvider.GEMINIandProvider.DRIVEmap to the sameOrigin.AISTUDIO_DRIVE, seecore/sources.py). Gated on the value actually observed, not the enum member whose name reads "Drive".classify_raw_revision_cohortrequiring a writable blob publisher) is logged (drive_revision_lineage_bind_failed) and swallowed, never breaking the session write._write_session's own freshness/content-hash comparison, plus the fix(pipeline): stop attachment fetches from losing a freshness tie #3453 attachment-coverage tie-break (left in place, unchanged), still solely decides what actually lands insessionsfrom this call site.Verification
devtools test tests/unit/pipeline/test_ingest_batch.py-- 66 passed, including newtest_write_session_binds_drive_revision_lineage. Confirmed red-first: temporarily reverted the production call and re-ran the new test -- it failed withassert None == 'gemini:drive-lineage-tie'(both raws'logical_source_keycame back NULL). Re-applied the fix and reran green..venv/bin/mypy polylogue/pipeline/services/ingest_batch/_core.py--Success: no issues found in 1 source file.devtools verify --quick--exit_code: 0(ruff format/check, mypy, render all --check, layering, closure-matrix, schema roundtrip, manifests, ci-workflows, doc-commands, docs-coverage, test-infra-currency, pytest-timeout-overrides, degrade-loudly, hash-boundary-census, schema-versioning, classifier-fingerprints, demo-tour-freshness, raw-payload-hash-purity, position-derived-identity, raw-authority-frontier-executability, schema-promotion-audit allok).Scope notes / deferred
sources/drive/__init__.pyuntouched -- the fix resolves entirely post-parse in the write path, matchinglive/batch.py's own precedent; no acquire-side change was needed._incoming_write_regresses_attachment_coveragetie-break is left in place unchanged, as a safety net for any_write_sessioncall site without asource_conn/blob_publisher(e.g. tests, or a future caller).raw_sessionsrows is explicitly out of scope -- retroactive durable-tier cleanup needs its own explicit-consent process per this repo's schema regime.Ref polylogue-sp72